Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit d90e349

Browse files
danielkaxisTigge
authored andcommitted
feat(slider): add disabled property to tick labels
-Forwards disabled property from slider to tick labels -Changes tick label color
1 parent 5c68a26 commit d90e349

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

packages/core/src/Slider/Tick.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'
2-
import styled from 'styled-components'
2+
import styled, { css } from 'styled-components'
33

44
import { spacing, opacity, shape } from '../designparams'
55
import { Typography } from '../Typography'
@@ -84,6 +84,7 @@ const BaseLabel = styled.div.attrs<{
8484
}))<{
8585
readonly center: number
8686
readonly width: number
87+
readonly disabled: boolean
8788
}>`
8889
position: absolute;
8990
cursor: pointer;
@@ -92,6 +93,20 @@ const BaseLabel = styled.div.attrs<{
9293
background-color: ${({ theme }) => theme.color.element11(opacity[24])};
9394
transform: scaleX(1);
9495
}
96+
97+
${({ disabled }) =>
98+
disabled
99+
? css`
100+
pointer-events: none;
101+
opacity: ${opacity[48]};
102+
`
103+
: undefined};
104+
`
105+
106+
const Label = styled(Typography).attrs({
107+
variant: 'explanatory-text',
108+
})`
109+
color: ${({ theme }) => theme.color.text04()};
95110
`
96111

97112
export const TickMarker: React.FC<Omit<Tick, 'label'>> = ({
@@ -113,6 +128,10 @@ interface TickLabelProps {
113128
* Label for the tickMarker, eg. `°`
114129
*/
115130
readonly label?: string
131+
/**
132+
* If `true`, the tick label will be disabled
133+
*/
134+
readonly disabled?: boolean
116135
/**
117136
* Executes JavaScript when clicking the value.
118137
*/
@@ -124,6 +143,7 @@ export const TickLabel: React.FC<TickLabelProps> = ({
124143
label,
125144
value,
126145
handleChange,
146+
disabled = false,
127147
}) => {
128148
const [width, setWidth] = useState<number>(0)
129149
const el = useRef<HTMLDivElement | null>(null)
@@ -145,12 +165,10 @@ export const TickLabel: React.FC<TickLabelProps> = ({
145165
}, [])
146166

147167
return (
148-
<BaseLabel ref={el} center={position} width={width}>
168+
<BaseLabel ref={el} center={position} width={width} disabled={disabled}>
149169
<LabelContainer onClick={handleClick}>
150170
<BoxHalo width={width}></BoxHalo>
151-
<Typography variant="explanatory-text">
152-
{label === undefined ? value : label}
153-
</Typography>
171+
<Label>{label === undefined ? value : label}</Label>
154172
</LabelContainer>
155173
</BaseLabel>
156174
)

packages/core/src/Slider/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ export const Slider: React.FC<SliderProps> = ({
575575
{hasTickLabels ? (
576576
<TickLabelContainer>
577577
{tickLabels.map(({ key, ...tickLabel }) => (
578-
<TickLabel key={key} {...tickLabel} />
578+
<TickLabel key={key} disabled={disabled} {...tickLabel} />
579579
))}
580580
</TickLabelContainer>
581581
) : null}

0 commit comments

Comments
 (0)