Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add JS toggle to slider component label #39418

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ export const Track = styled.div`
height: var(--ads-v2-spaces-4);
width: 100%;
`;

export const LabelWrapper = styled.div`
display: flex;
align-items: center;
gap: var(--ads-v2-spaces-3);
`;
19 changes: 15 additions & 4 deletions app/client/packages/design-system/ads/src/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { VisuallyHidden } from "@react-aria/visually-hidden";
import { useNumberFormatter } from "@react-aria/i18n";
import type { AriaSliderProps } from "@react-types/slider";
import { Text } from "../Text";
// Removed FlexWrapper import as we're using LabelWrapper from Slider.styles.tsx
import { ToggleComponentToJsonHandler } from "components/editorComponents/form/ToggleComponentToJson";
import { SliderFocusVisibleClassName } from "./Slider.constants";
import {
StyledSlider,
Expand All @@ -15,6 +17,7 @@ import {
FilledRail,
Track,
TrackContainer,
LabelWrapper,
} from "./Slider.styles";
import type { SliderProps } from "./Slider.types";

Expand Down Expand Up @@ -67,10 +70,18 @@ export function Slider(props: SliderProps) {
<StyledSlider {...groupProps} disabled={props.isDisabled}>
<SliderLabel>
{props.label && (
// @ts-expect-error incompatible types for Text and labelProps
<Text renderAs="label" {...labelProps}>
{props.label}
</Text>
<LabelWrapper>
{/* @ts-expect-error incompatible types for Text and labelProps */}
<Text renderAs="label" {...labelProps}>
{props.label}
</Text>
{props.configProperty && props.formName && (
<ToggleComponentToJsonHandler
configProperty={props.configProperty}
formName={props.formName}
/>
)}
</LabelWrapper>
)}
{/*@ts-expect-error incompatible types for Text and outputProps**/}
<Text {...outputProps}>{getDisplayValue()}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export interface SliderProps
formatOptions?: Intl.NumberFormatOptions;
/** A function that returns the content to display as the value's label. Overrides default formatted number. */
getValueLabel?: (value: number) => string;
/** Property path for JS toggle */
configProperty?: string;
/** Form name for JS toggle */
formName?: string;
}
Loading