Skip to content

Commit

Permalink
refactor(slider): fix bem
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Apr 6, 2022
1 parent ea062e8 commit 26c56a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
16 changes: 3 additions & 13 deletions packages/varlet-ui/src/slider/Slider.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<template>
<div :class="n()">
<div
:class="classes(
n('block'),
[isDisabled, n('--disabled')],
[errorMessage, n('--error')]
)"
:class="classes(n('block'), [isDisabled, n('--disabled')], [errorMessage, n('--error')])"
:style="{
height: thumbSize === undefined ? thumbSize : `${3 * toNumber(thumbSize)}px`,
margin: thumbSize === undefined ? thumbSize : `0 ${toNumber(thumbSize) / 2}px`,
Expand Down Expand Up @@ -46,20 +42,14 @@
}"
></div>
<div
:class="classes(
n('thumb-ripple'),
[thumbsProps[item.enumValue].active, n('thumb-ripple-active')]
)"
:class="classes(n('thumb-ripple'), [thumbsProps[item.enumValue].active, n('thumb-ripple--active')])"
:style="{
background: thumbColor,
...getRippleSize(item),
}"
></div>
<div
:class="classes(
n('thumb-label'),
[showLabel(item.enumValue), n('thumb-label-active')]
)"
:class="classes(n('thumb-label'), [showLabel(item.enumValue), n('thumb-label--active')])"
:style="{
background: labelColor,
color: labelTextColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ exports[`test slider example 1`] = `
<div class=\\"var-slider__thumb\\" style=\\"left: 24%;\\">
<div class=\\"var-slider__thumb-block\\"></div>
<div class=\\"var-slider__thumb-ripple\\"></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label-active\\"><span>24</span></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label--active\\"><span>24</span></div>
</div>
<div class=\\"var-slider__thumb\\" style=\\"left: 50%;\\">
<div class=\\"var-slider__thumb-block\\"></div>
<div class=\\"var-slider__thumb-ripple\\"></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label-active\\"><span>50</span></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label--active\\"><span>50</span></div>
</div>
</div>
<transition-stub class=\\"var-slider__form\\" var-slider-cover=\\"\\">
Expand Down Expand Up @@ -207,7 +207,7 @@ exports[`test slider example 1`] = `
<div class=\\"var-slider__thumb\\" style=\\"left: 50%;\\">
<div class=\\"var-slider__thumb-block\\"></div>
<div class=\\"var-slider__thumb-ripple\\"></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label-active\\"><span>50</span></div>
<div class=\\"var-slider__thumb-label var-slider__thumb-label--active\\"><span>50</span></div>
</div>
</div>
<transition-stub class=\\"var-slider__form\\" var-slider-cover=\\"\\">
Expand Down
16 changes: 8 additions & 8 deletions packages/varlet-ui/src/slider/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,35 @@ test('test slider labelVisible prop', async () => {
})

const el = wrapper.find('.var-slider__thumb-label')
expect(el.classes()).not.toContain('var-slider__thumb-label-active')
expect(el.classes()).not.toContain('var-slider__thumb-label--active')

await trigger(el, 'touchstart', 0, 0)
await trigger(el, 'touchmove', 0, 0)

expect(el.classes()).toContain('var-slider__thumb-label-active')
expect(el.classes()).toContain('var-slider__thumb-label--active')

await trigger(el, 'touchend', 0, 0)

expect(el.classes()).not.toContain('var-slider__thumb-label-active')
expect(el.classes()).not.toContain('var-slider__thumb-label--active')

await wrapper.setData({ visible: 'never' })

expect(el.classes()).not.toContain('var-slider__thumb-label-active')
expect(el.classes()).not.toContain('var-slider__thumb-label--active')

await trigger(el, 'touchstart', 0, 0)
await trigger(el, 'touchmove', 0, 0)
expect(el.classes()).not.toContain('var-slider__thumb-label-active')
expect(el.classes()).not.toContain('var-slider__thumb-label--active')

await wrapper.setData({ visible: 'always' })

expect(el.classes()).toContain('var-slider__thumb-label-active')
expect(el.classes()).toContain('var-slider__thumb-label--active')

await trigger(el, 'touchstart', 0, 0)
await trigger(el, 'touchmove', 0, 0)
expect(el.classes()).toContain('var-slider__thumb-label-active')
expect(el.classes()).toContain('var-slider__thumb-label--active')

await trigger(el, 'touchend', 0, 0)
expect(el.classes()).toContain('var-slider__thumb-label-active')
expect(el.classes()).toContain('var-slider__thumb-label--active')
})

test('test step prop', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/slider/slider.less
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
background: var(--slider-thumb-ripple-background);
transition: 0.3s var(--cubic-bezier);

&-active {
&--active {
width: 36px;
height: 36px;
}
Expand Down Expand Up @@ -107,7 +107,7 @@
transform: rotate(-45deg);
}

&-active {
&--active {
transform: translateY(-50%) translateX(-50%) rotate(45deg) scale(1);
}
}
Expand Down

0 comments on commit 26c56a3

Please sign in to comment.