Skip to content

Commit fa4da7f

Browse files
committed
chore: add kebab-case folders again
1 parent 0ac391d commit fa4da7f

File tree

98 files changed

+5275
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+5275
-0
lines changed

src/components/progress/CProgress.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div class="progress" :style="{ height }">
3+
<slot>
4+
<CProgressBar :value="value"/>
5+
</slot>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import CProgressBar from './CProgressBar'
11+
import props from './progress-props'
12+
13+
export default {
14+
name:'CProgress',
15+
components: { CProgressBar },
16+
props,
17+
provide () {
18+
const progress = {}
19+
Object.defineProperty(progress, 'props', {
20+
get: () => this._props
21+
})
22+
return { progress }
23+
}
24+
}
25+
</script>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div
3+
:class="progressBarClasses"
4+
:style="progressBarStyles"
5+
role="progressbar"
6+
aria-valuemin="0"
7+
:aria-valuemax="props.max.toString()"
8+
:aria-valuenow="computedValue"
9+
>
10+
<slot>{{ text }}</slot>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import props from './progress-props'
16+
export default {
17+
name: 'CProgressBar',
18+
props,
19+
inject: {
20+
progress: {
21+
default: undefined
22+
}
23+
},
24+
computed: {
25+
directlyDeclaredProps () {
26+
return Object.keys(this.$options.propsData)
27+
},
28+
injectedProps () {
29+
return this.progress && this.progress.props ? this.progress.props : {}
30+
},
31+
props () {
32+
return Object.keys(props).reduce((computedProps, key) => {
33+
const propIsDirectlyDeclared = this.directlyDeclaredProps.includes(key)
34+
const parentPropExists = this.injectedProps[key] !== undefined
35+
const propIsInherited = parentPropExists && !propIsDirectlyDeclared
36+
computedProps[key] = propIsInherited ? this.injectedProps[key] : this[key]
37+
return computedProps
38+
}, {})
39+
},
40+
progressBarClasses () {
41+
return [
42+
'progress-bar',
43+
{
44+
[`bg-${this.props.color}`]: this.props.color,
45+
'progress-bar-striped': this.props.striped || this.props.animated,
46+
'progress-bar-animated': this.props.animated
47+
}
48+
]
49+
},
50+
51+
progressBarStyles () {
52+
return { width: `${(100 * (this.props.value / this.props.max))}%` }
53+
},
54+
progressValue () {
55+
const p = Math.pow(10, this.props.precision)
56+
return Math.round((100 * p * this.props.value) / this.props.max) / p
57+
},
58+
computedValue () {
59+
return this.props.value.toFixed(props.precision)
60+
},
61+
text () {
62+
if (this.props.showPercentage) {
63+
return this.progressValue + '%'
64+
} else if (this.props.showValue) {
65+
return this.computedValue
66+
}
67+
}
68+
}
69+
}
70+
</script>

src/components/progress/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CProgress from './CProgress'
2+
import CProgressBar from './CProgressBar'
3+
4+
export {
5+
CProgress,
6+
CProgressBar
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
height: String,
3+
// These props can be inherited via the child CProgressBar(s)
4+
color: String,
5+
striped: Boolean,
6+
animated: Boolean,
7+
precision: {
8+
type: Number,
9+
default: 0
10+
},
11+
showPercentage: Boolean,
12+
showValue: Boolean,
13+
max: {
14+
type: Number,
15+
default: 100
16+
},
17+
value: {
18+
type: Number,
19+
default: 0
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { mount } from '@vue/test-utils'
2+
import Component from '../CProgress'
3+
4+
const ComponentName = 'CProgress'
5+
const defaultWrapper = mount(Component)
6+
const customWrapper = mount(Component, {
7+
propsData: {
8+
color: 'black',
9+
value: 20
10+
},
11+
attrs: {
12+
class: 'test'
13+
}
14+
})
15+
16+
17+
18+
describe(ComponentName, () => {
19+
it('has a name', () => {
20+
expect(Component.name).toMatch(ComponentName)
21+
})
22+
it('renders correctly', () => {
23+
expect(defaultWrapper.element).toMatchSnapshot()
24+
})
25+
it('renders correctly', () => {
26+
expect(customWrapper.element).toMatchSnapshot()
27+
})
28+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { mount } from '@vue/test-utils'
2+
import Component from '../CProgressBar'
3+
4+
const ComponentName = 'CProgressBar'
5+
const defaultWrapper = mount(Component)
6+
7+
const customWrapper = mount(Component,{
8+
propsData: {
9+
color: 'success',
10+
value: 50,
11+
striped: true,
12+
showValue: true,
13+
max: 200
14+
},
15+
slots: {
16+
default: '234'
17+
}
18+
})
19+
20+
describe(ComponentName, () => {
21+
it('has a name', () => {
22+
expect(Component.name).toMatch(ComponentName)
23+
})
24+
it('renders correctly', () => {
25+
expect(defaultWrapper.element).toMatchSnapshot()
26+
})
27+
it('renders correctly', () => {
28+
expect(customWrapper.element).toMatchSnapshot()
29+
})
30+
it('renders progress correctly', () => {
31+
expect(customWrapper.vm.text).toBe('50')
32+
customWrapper.setProps({ showPercentage: true })
33+
expect(customWrapper.vm.text).toBe('25%')
34+
})
35+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CProgress renders correctly 1`] = `
4+
<div
5+
class="progress"
6+
>
7+
<div
8+
aria-valuemax="100"
9+
aria-valuemin="0"
10+
aria-valuenow="0"
11+
class="progress-bar"
12+
role="progressbar"
13+
style="width: 0%;"
14+
>
15+
16+
</div>
17+
</div>
18+
`;
19+
20+
exports[`CProgress renders correctly 2`] = `
21+
<div
22+
class="test"
23+
>
24+
<div
25+
aria-valuemax="100"
26+
aria-valuemin="0"
27+
aria-valuenow="20"
28+
class="progress-bar bg-black"
29+
role="progressbar"
30+
style="width: 20%;"
31+
>
32+
33+
</div>
34+
</div>
35+
`;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CProgressBar renders correctly 1`] = `
4+
<div
5+
aria-valuemax="100"
6+
aria-valuemin="0"
7+
aria-valuenow="0"
8+
class="progress-bar"
9+
role="progressbar"
10+
style="width: 0%;"
11+
>
12+
13+
</div>
14+
`;
15+
16+
exports[`CProgressBar renders correctly 2`] = `
17+
<div
18+
aria-valuemax="200"
19+
aria-valuemin="0"
20+
aria-valuenow="50"
21+
class="progress-bar bg-success progress-bar-striped"
22+
role="progressbar"
23+
style="width: 25%;"
24+
>
25+
234
26+
</div>
27+
`;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<script>
2+
// this component is a refector of vue-perfect-scrollbar component https://github.com/lecion/vue-perfect-scrollbar
3+
import PerfectScrollbar from 'perfect-scrollbar'
4+
5+
export default {
6+
name: 'CScrollbar',
7+
props: {
8+
settings: {
9+
type: Object,
10+
default () {
11+
return {}
12+
},
13+
},
14+
switcher: {
15+
type: Boolean,
16+
default: true,
17+
},
18+
tag: {
19+
type: String,
20+
default: 'div',
21+
}
22+
},
23+
24+
watch: {
25+
switcher (val) {
26+
if (!val) {
27+
this.__uninit()
28+
} else {
29+
this.__init()
30+
}
31+
}
32+
},
33+
34+
mounted () {
35+
if (!this.$isServer && this.switcher) {
36+
this.__init()
37+
}
38+
},
39+
40+
updated () {
41+
this.$nextTick(this.__update)
42+
},
43+
44+
beforeDestroy () {
45+
this.__uninit()
46+
},
47+
48+
methods: {
49+
__init() {
50+
if (!this._ps_bar) {
51+
this.__createPerfectScrollbar()
52+
}
53+
},
54+
55+
__createPerfectScrollbar() {
56+
this._ps_bar = new PerfectScrollbar(this.$el, this.settings)
57+
},
58+
59+
__uninit() {
60+
if (this._ps_bar) {
61+
this._ps_bar.destroy()
62+
this._ps_bar = null
63+
}
64+
},
65+
__update() {
66+
if (this._ps_bar) {
67+
this._ps_bar.update()
68+
}
69+
}
70+
},
71+
72+
render (h) {
73+
return h(
74+
this.tag,
75+
{ style: 'position: relative' },
76+
this.$slots.default
77+
)
78+
}
79+
}
80+
</script>
81+
82+
<style src="perfect-scrollbar/css/perfect-scrollbar.css"></style>

src/components/scrollbar/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import CScrollbar from './CScrollbar'
2+
3+
export {
4+
CScrollbar
5+
}

0 commit comments

Comments
 (0)