Skip to content

Commit 5b62c61

Browse files
committed
refactor: CSwitch refactor
- change outline prop to variant, - add square shape
1 parent 22b911b commit 5b62c61

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/components/switch/CSwitch.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ export default {
2323
inheritAttrs: false,
2424
props: {
2525
color: String,
26-
outline: {
27-
type: [Boolean, String],
28-
default: undefined,
29-
validator: value => [false, true, '', 'alt'].includes(value)
26+
variant: {
27+
type: String,
28+
validator: value => ['', 'outline', 'opposite', '3d'].includes(value)
3029
},
3130
size: {
3231
type: String,
3332
validator: value => ['','lg', 'sm'].includes(value)
3433
},
3534
shape: {
3635
type: String,
37-
validator: value => ['','3d', 'pill'].includes(value)
36+
validator: value => ['','pill', 'square'].includes(value)
3837
},
3938
checked: Boolean,
4039
value: {
@@ -64,14 +63,15 @@ export default {
6463
},
6564
computed: {
6665
classList () {
67-
const outlineString = this.outline ? '-outline' : ''
68-
const outlinedAltString = this.outline === 'alt' ? '-alt' : ''
66+
const havePrefix = ['opposite', 'outline'].includes(this.variant)
67+
const colorPrefix = havePrefix ? `-${this.variant}` : ''
6968
return [
7069
'c-switch form-check-label',
71-
`c-switch${outlineString}-${this.color}${outlinedAltString}`,
7270
{
7371
[`c-switch-${this.size}`]: this.size,
7472
[`c-switch-${this.shape}`]: this.shape,
73+
'c-switch-3d': this.variant === '3d',
74+
[`c-switch${colorPrefix}-${this.color}`]: this.color,
7575
'c-switch-label': this.labelOn || this.labelOff
7676
}
7777
]

src/components/switch/tests/CSwitch.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const customWrapper = mount(Component, {
2020
color: 'info',
2121
outline: 'alt',
2222
size: 'lg',
23-
shape:'3d',
23+
shape: 'pill',
2424
name:'myName',
2525
id:'myId',
2626
checked: true,

src/components/switch/tests/__snapshots__/CSwitch.spec.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`CSwitch renders correctly 1`] = `
44
<label
5-
class="c-switch form-check-label c-switch-undefined"
5+
class="c-switch form-check-label"
66
>
77
<input
88
class="c-switch-input form-check-input"
@@ -18,14 +18,15 @@ exports[`CSwitch renders correctly 1`] = `
1818

1919
exports[`CSwitch renders correctly 2`] = `
2020
<label
21-
class="c-switch form-check-label c-switch-outline-info-alt c-switch-lg c-switch-3d"
21+
class="c-switch form-check-label c-switch-lg c-switch-pill c-switch-info"
2222
>
2323
<input
2424
class="c-switch-input form-check-input"
2525
dataoff="dataOff"
2626
dataon="dataOn"
2727
id="myId"
2828
name="myName"
29+
outline="alt"
2930
required="required"
3031
type="checkbox"
3132
value="checked"

0 commit comments

Comments
 (0)