Skip to content

Commit

Permalink
feat: 修复 slider 样式问题 (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin committed Nov 14, 2022
1 parent ea31a27 commit 1f22b40
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 44 deletions.
50 changes: 25 additions & 25 deletions src/slider/hooks/useSliderMark.tsx
Expand Up @@ -66,32 +66,32 @@ export const useSliderMark = (config: Ref<useSliderMarkProps>) => {
});

const renderMask = (onChangeFn?: (point: number) => void): VNode => {
if (markList.value.length) {
return (
<div>
<div>
{markList.value.map((item, index) => (
<div
class={`${name}__stop ${name}__mark-stop`}
style={getStopStyle(item.position, config.value.vertical)}
key={index}
/>
))}
</div>
<div class={`${name}__mark`}>
{markList.value.map((item, key) => (
<TSliderMark
mark={item.mark as any}
point={item.point}
key={key}
style={getStopStyle(item.position, config.value.vertical)}
onClickMarkPoint={onChangeFn}
/>
))}
</div>
if (!markList.value.length) return null;

return (
<div>
<div class={`${name}__stops`}>
{markList.value.map((item, index) => (
<div
class={`${name}__stop ${name}__mark-stop`}
style={getStopStyle(item.position, config.value.vertical)}
key={index}
/>
))}
</div>
);
}
<div class={`${name}__mark`}>
{markList.value.map((item, key) => (
<TSliderMark
mark={item.mark as any}
point={item.point}
key={key}
style={getStopStyle(item.position, config.value.vertical)}
onClickMarkPoint={onChangeFn}
/>
))}
</div>
</div>
);
};

return renderMask;
Expand Down
12 changes: 4 additions & 8 deletions src/slider/slider.tsx
Expand Up @@ -18,7 +18,7 @@ import { useFormDisabled } from '../form/hooks';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig';
import { useSliderMark } from './hooks/useSliderMark';
import { useSliderInput } from './hooks/useSliderInput';
import { formatSlderValue, getStopStyle } from './util/common';
import { formatSliderValue, getStopStyle } from './util/common';
import { sliderPropsInjectKey } from './util/constants';
import useVModel from '../hooks/useVModel';

Expand All @@ -45,12 +45,8 @@ export default defineComponent({
const firstButtonRef = ref<SliderButtonType>();
const secondButtonRef = ref<SliderButtonType>();

// const sliderState = reactive({
// // TODO: 该属性应该是暴露出来的api供用户配置才对
// showSteps: true,
// });
const firstValue = ref(formatSlderValue(sliderValue.value, 'first'));
const secondValue = ref(formatSlderValue(sliderValue.value, 'second'));
const firstValue = ref(formatSliderValue(sliderValue.value, 'first'));
const secondValue = ref(formatSliderValue(sliderValue.value, 'second'));
const dragging = ref(false);
const sliderSize = ref(1);

Expand Down Expand Up @@ -413,7 +409,7 @@ export default defineComponent({
/>
)}
{props.showStep && (
<div>
<div class={`${COMPONENT_NAME.value}__stops`}>
{steps.value.map((item, key) => (
<div class={`${COMPONENT_NAME.value}__stop`} key={key} style={getStopStyle(item, vertical.value)} />
))}
Expand Down
2 changes: 1 addition & 1 deletion src/slider/util/common.ts
Expand Up @@ -15,7 +15,7 @@ export const getStopStyle = (position: number, isVertical: boolean) => {
* @param type 第一个滑块or第二个滑块值
* @returns {number}
*/
export const formatSlderValue = (val: number | number[], type: 'first' | 'second') => {
export const formatSliderValue = (val: number | number[], type: 'first' | 'second') => {
if (type === 'first') {
if (val instanceof Array) {
return val[0];
Expand Down
28 changes: 21 additions & 7 deletions test/snap/__snapshots__/csr.test.js.snap
Expand Up @@ -105392,7 +105392,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/marks.vue 1`] = `
<!---->
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -105532,7 +105534,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/marks.vue 1`] = `
</div>
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -105655,7 +105659,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/marks.vue 1`] = `
<!---->
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -105764,7 +105770,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/min-and-max.vue 1`]
<!---->
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -105856,7 +105864,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/min-and-max.vue 1`]
</div>
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -106190,7 +106200,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/vertical-marks.vue 1
<!---->
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down Expand Up @@ -106336,7 +106348,9 @@ exports[`csr snapshot test > csr test ./src/slider/_example/vertical-marks.vue 1
</div>
<!---->
<div>
<div>
<div
class="t-slider__stops"
>

<div
class="t-slider__stop t-slider__mark-stop"
Expand Down

0 comments on commit 1f22b40

Please sign in to comment.