Skip to content

Commit 57ea9b9

Browse files
committed
feat(dot-style): add marks dot classname
1 parent 5924005 commit 57ea9b9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Steps/Dot.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import SliderContext from '../context';
66
export interface DotProps {
77
prefixCls: string;
88
value: number;
9+
marksValue: number[];
910
style?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
1011
activeStyle?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
1112
}
1213

1314
export default function Dot(props: DotProps) {
14-
const { prefixCls, value, style, activeStyle } = props;
15+
const { prefixCls, marksValue, value, style, activeStyle } = props;
1516
const { min, max, direction, included, includedStart, includedEnd } =
1617
React.useContext(SliderContext);
1718

1819
const dotClassName = `${prefixCls}-dot`;
20+
const marksDotClassName = `${prefixCls}-marks-dot`;
1921
const active = included && includedStart <= value && value <= includedEnd;
22+
const marksDot = marksValue.includes(value);
2023

2124
// ============================ Offset ============================
2225
let mergedStyle = {
@@ -33,9 +36,15 @@ export default function Dot(props: DotProps) {
3336

3437
return (
3538
<span
36-
className={classNames(dotClassName, {
37-
[`${dotClassName}-active`]: active,
38-
})}
39+
className={classNames(
40+
dotClassName,
41+
{
42+
[`${dotClassName}-active`]: active,
43+
},
44+
{
45+
[marksDotClassName]: marksDot,
46+
},
47+
)}
3948
style={mergedStyle}
4049
/>
4150
);

src/Steps/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import type { InternalMarkObj } from '../Marks';
3+
import type { DotProps } from './Dot';
34
import SliderContext from '../context';
45
import Dot from './Dot';
56

@@ -15,6 +16,8 @@ export default function Steps(props: StepsProps) {
1516
const { prefixCls, marks, dots, style, activeStyle } = props;
1617
const { min, max, step } = React.useContext(SliderContext);
1718

19+
const marksValueRef = React.useRef<DotProps['marksValue']>([]);
20+
1821
const stepDots = React.useMemo(() => {
1922
const dotSet = new Set<number>();
2023

@@ -23,6 +26,9 @@ export default function Steps(props: StepsProps) {
2326
dotSet.add(mark.value);
2427
});
2528

29+
//Fill marksValue
30+
marksValueRef.current = Array.from(dotSet);
31+
2632
// Fill dots
2733
if (dots && step !== null) {
2834
let current = min;
@@ -40,6 +46,7 @@ export default function Steps(props: StepsProps) {
4046
{stepDots.map((dotValue) => (
4147
<Dot
4248
prefixCls={prefixCls}
49+
marksValue={marksValueRef.current}
4350
key={dotValue}
4451
value={dotValue}
4552
style={style}

0 commit comments

Comments
 (0)