Skip to content

Commit

Permalink
feat(dot-style): add marks dot classname
Browse files Browse the repository at this point in the history
  • Loading branch information
howiepu committed Aug 31, 2022
1 parent 5924005 commit 57ea9b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Steps/Dot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import SliderContext from '../context';
export interface DotProps {
prefixCls: string;
value: number;
marksValue: number[];
style?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
activeStyle?: React.CSSProperties | ((dotValue: number) => React.CSSProperties);
}

export default function Dot(props: DotProps) {
const { prefixCls, value, style, activeStyle } = props;
const { prefixCls, marksValue, value, style, activeStyle } = props;
const { min, max, direction, included, includedStart, includedEnd } =
React.useContext(SliderContext);

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

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

return (
<span
className={classNames(dotClassName, {
[`${dotClassName}-active`]: active,
})}
className={classNames(
dotClassName,
{
[`${dotClassName}-active`]: active,
},
{
[marksDotClassName]: marksDot,
},
)}
style={mergedStyle}
/>
);
Expand Down
7 changes: 7 additions & 0 deletions src/Steps/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import type { InternalMarkObj } from '../Marks';
import type { DotProps } from './Dot';
import SliderContext from '../context';
import Dot from './Dot';

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

const marksValueRef = React.useRef<DotProps['marksValue']>([]);

const stepDots = React.useMemo(() => {
const dotSet = new Set<number>();

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

//Fill marksValue
marksValueRef.current = Array.from(dotSet);

// Fill dots
if (dots && step !== null) {
let current = min;
Expand All @@ -40,6 +46,7 @@ export default function Steps(props: StepsProps) {
{stepDots.map((dotValue) => (
<Dot
prefixCls={prefixCls}
marksValue={marksValueRef.current}
key={dotValue}
value={dotValue}
style={style}
Expand Down

0 comments on commit 57ea9b9

Please sign in to comment.