Skip to content

Commit

Permalink
Remove useSliderContext from demos
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Sep 27, 2024
1 parent 6ba2983 commit 6f8e65f
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 130 deletions.
21 changes: 12 additions & 9 deletions docs/data/components/slider/RtlSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ export default function RtlSlider() {
direction="rtl"
className={classes.slider}
>
<Label id="VolumeSliderLabel" className={classes.label}>
<Label
id="VolumeSliderLabel"
htmlFor=":slider-thumb-input-rtl:"
className={classes.label}
>
Volume (RTL)
</Label>
<Slider.Output className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
<Slider.Thumb className={classes.thumb} />
<Slider.Thumb
className={classes.thumb}
inputId=":slider-thumb-input-rtl:"
/>
</Slider.Track>
</Slider.Control>
</Slider.Root>
Expand All @@ -32,17 +39,13 @@ export default function RtlSlider() {
}

function Label(props) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = Slider.useSliderContext();
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

Label.propTypes = {
htmlFor: PropTypes.string,
id: PropTypes.string,
};

Expand Down
22 changes: 12 additions & 10 deletions docs/data/components/slider/RtlSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@ export default function RtlSlider() {
direction="rtl"
className={classes.slider}
>
<Label id="VolumeSliderLabel" className={classes.label}>
<Label
id="VolumeSliderLabel"
htmlFor=":slider-thumb-input-rtl:"
className={classes.label}
>
Volume (RTL)
</Label>
<Slider.Output className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
<Slider.Thumb className={classes.thumb} />
<Slider.Thumb
className={classes.thumb}
inputId=":slider-thumb-input-rtl:"
/>
</Slider.Track>
</Slider.Control>
</Slider.Root>
</div>
);
}

function Label(props: React.HTMLAttributes<HTMLLabelElement>) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = Slider.useSliderContext();
function Label(props: React.LabelHTMLAttributes<HTMLLabelElement>) {
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

function useIsDarkMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ export default function UnstyledSliderIntroduction() {
defaultValue={50}
aria-labelledby="VolumeSliderLabel"
>
<Label id="VolumeSliderLabel" className={classes.label}>
<Label
id="VolumeSliderLabel"
htmlFor=":slider-thumb-input:"
className={classes.label}
>
Volume
</Label>
<Slider.Output className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
<Slider.Thumb className={classes.thumb} />
<Slider.Thumb className={classes.thumb} inputId=":slider-thumb-input:" />
</Slider.Track>
</Slider.Control>
</Slider.Root>
Expand All @@ -34,17 +38,13 @@ export default function UnstyledSliderIntroduction() {
}

function Label(props) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = Slider.useSliderContext();
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

Label.propTypes = {
htmlFor: PropTypes.string,
id: PropTypes.string,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,29 @@ export default function UnstyledSliderIntroduction() {
defaultValue={50}
aria-labelledby="VolumeSliderLabel"
>
<Label id="VolumeSliderLabel" className={classes.label}>
<Label
id="VolumeSliderLabel"
htmlFor=":slider-thumb-input:"
className={classes.label}
>
Volume
</Label>
<Slider.Output className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
<Slider.Thumb className={classes.thumb} />
<Slider.Thumb className={classes.thumb} inputId=":slider-thumb-input:" />
</Slider.Track>
</Slider.Control>
</Slider.Root>
</div>
);
}

function Label(props: React.HTMLAttributes<HTMLLabelElement>) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = Slider.useSliderContext();
function Label(props: React.LabelHTMLAttributes<HTMLLabelElement>) {
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

function useIsDarkMode() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export default function UnstyledSliderIntroduction() {
sx={{ display: 'flex', flexDirection: 'column', gap: '4rem', width: 320 }}
>
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
<SliderIndicator />
<SliderThumb />
<SliderThumb inputId=":slider-thumb-input:" />
</SliderTrack>
</SliderControl>
</Slider>
Expand All @@ -27,17 +29,13 @@ export default function UnstyledSliderIntroduction() {
}

function BaseLabel(props) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = BaseSlider.useSliderContext();
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

BaseLabel.propTypes = {
htmlFor: PropTypes.string,
id: PropTypes.string,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@ export default function UnstyledSliderIntroduction() {
sx={{ display: 'flex', flexDirection: 'column', gap: '4rem', width: 320 }}
>
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
<SliderIndicator />
<SliderThumb />
<SliderThumb inputId=":slider-thumb-input:" />
</SliderTrack>
</SliderControl>
</Slider>
</Box>
);
}

function BaseLabel(props: React.HTMLAttributes<HTMLLabelElement>) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = BaseSlider.useSliderContext();
function BaseLabel(props: React.LabelHTMLAttributes<HTMLLabelElement>) {
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

const grey = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
<SliderIndicator />
<SliderThumb />
<SliderThumb inputId=":slider-thumb-input:" />
</SliderTrack>
</SliderControl>
</Slider>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export default function UnstyledSliderIntroduction() {
style={{ display: 'flex', flexDirection: 'column', gap: '4rem', width: 320 }}
>
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
Expand Down Expand Up @@ -184,21 +186,12 @@ SliderIndicator.propTypes = {
};

function Label(props) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = BaseSlider.useSliderContext();
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label
id={id}
htmlFor={htmlFor}
className={classNames('font-bold', disabled && 'text-gray-500')}
{...otherProps}
/>
);
return <label id={id} htmlFor={htmlFor} className="font-bold" {...otherProps} />;
}

Label.propTypes = {
htmlFor: PropTypes.string,
id: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default function UnstyledSliderIntroduction() {
style={{ display: 'flex', flexDirection: 'column', gap: '4rem', width: 320 }}
>
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
Expand Down Expand Up @@ -158,18 +160,8 @@ const SliderIndicator = React.forwardRef(function SliderIndicator(
);
});

function Label(props: React.HTMLAttributes<HTMLLabelElement>) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = BaseSlider.useSliderContext();
function Label(props: React.LabelHTMLAttributes<HTMLLabelElement>) {
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label
id={id}
htmlFor={htmlFor}
className={classNames('font-bold', disabled && 'text-gray-500')}
{...otherProps}
/>
);
return <label id={id} htmlFor={htmlFor} className="font-bold" {...otherProps} />;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Slider defaultValue={50} aria-labelledby="VolumeSliderLabel">
<Label id="VolumeSliderLabel">Volume</Label>
<Label id="VolumeSliderLabel" htmlFor=":slider-thumb-input:">
Volume
</Label>
<SliderOutput />
<SliderControl>
<SliderTrack>
Expand Down
21 changes: 12 additions & 9 deletions docs/data/components/slider/VerticalSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ export default function VerticalSlider() {
aria-labelledby="VolumeSliderLabel"
className={classes.slider}
>
<Label id="VolumeSliderLabel" className={classes.label}>
<Label
id="VolumeSliderLabel"
htmlFor=":slider-thumb-input-vertical:"
className={classes.label}
>
Volume
</Label>
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
<Slider.Thumb className={classes.thumb} />
<Slider.Thumb
className={classes.thumb}
inputId=":slider-thumb-input-vertical:"
/>
</Slider.Track>
</Slider.Control>
<Slider.Output className={classes.output} />
Expand All @@ -32,17 +39,13 @@ export default function VerticalSlider() {
}

function Label(props) {
const { id, ...otherProps } = props;
const { inputIdMap, disabled } = Slider.useSliderContext();
const { id, htmlFor, ...otherProps } = props;

const htmlFor = inputIdMap.get(0);

return (
<label id={id} htmlFor={htmlFor} data-disabled={disabled} {...otherProps} />
);
return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

Label.propTypes = {
htmlFor: PropTypes.string,
id: PropTypes.string,
};

Expand Down
Loading

0 comments on commit 6f8e65f

Please sign in to comment.