Skip to content

Commit c1c83ad

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

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Steps/Dot.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ 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 { min, max, direction, included, includedStart, includedEnd } =
16-
React.useContext(SliderContext);
15+
const { prefixCls, marksValue, value, style, activeStyle } = props;
16+
const { min, max, direction, included, includedStart, includedEnd } = React.useContext(
17+
SliderContext,
18+
);
1719

1820
const dotClassName = `${prefixCls}-dot`;
21+
const marksDotClassName = `${prefixCls}-marks-dot`;
1922
const active = included && includedStart <= value && value <= includedEnd;
23+
const marksDot = marksValue.indexOf(value) >= 0;
2024

2125
// ============================ Offset ============================
2226
let mergedStyle = {
@@ -33,9 +37,15 @@ export default function Dot(props: DotProps) {
3337

3438
return (
3539
<span
36-
className={classNames(dotClassName, {
37-
[`${dotClassName}-active`]: active,
38-
})}
40+
className={classNames(
41+
dotClassName,
42+
{
43+
[`${dotClassName}-active`]: active,
44+
},
45+
{
46+
[marksDotClassName]: marksDot,
47+
},
48+
)}
3949
style={mergedStyle}
4050
/>
4151
);

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)