Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into docs/select-props…
Browse files Browse the repository at this point in the history
…-override
  • Loading branch information
mj12albert committed Dec 12, 2024
2 parents 38a9cd9 + 4087bb1 commit 5b94f19
Show file tree
Hide file tree
Showing 49 changed files with 377 additions and 173 deletions.
4 changes: 2 additions & 2 deletions docs/data/components/slider/RangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function RangeSlider() {
<span id="ControlledRangeLabel" className={classes.label}>
Controlled Range
</span>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand All @@ -49,7 +49,7 @@ export default function RangeSlider() {
<span id="UncontrolledRangeLabel" className={classes.label}>
Uncontrolled Range
</span>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
4 changes: 2 additions & 2 deletions docs/data/components/slider/RangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function RangeSlider() {
<span id="ControlledRangeLabel" className={classes.label}>
Controlled Range
</span>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand All @@ -49,7 +49,7 @@ export default function RangeSlider() {
<span id="UncontrolledRangeLabel" className={classes.label}>
Uncontrolled Range
</span>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/slider/RtlSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function RtlSlider() {
>
Volume (RTL)
</Label>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/slider/RtlSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function RtlSlider() {
>
Volume (RTL)
</Label>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function UnstyledSliderIntroduction() {
>
Volume
</Label>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function UnstyledSliderIntroduction() {
>
Volume
</Label>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Slider = styled(BaseSlider.Root)`
gap: 1rem;
`;

const SliderOutput = styled(BaseSlider.Output)`
const SliderOutput = styled(BaseSlider.Value)`
text-align: right;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Slider = styled(BaseSlider.Root)`
gap: 1rem;
`;

const SliderOutput = styled(BaseSlider.Output)`
const SliderOutput = styled(BaseSlider.Value)`
text-align: right;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Slider.propTypes = {

const SliderOutput = React.forwardRef(function SliderOutput(props, ref) {
return (
<BaseSlider.Output
<BaseSlider.Value
{...props}
ref={ref}
className={(state) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ const Slider = React.forwardRef(function Slider(
});

const SliderOutput = React.forwardRef(function SliderOutput(
props: BaseSlider.Output.Props,
props: BaseSlider.Value.Props,
ref: React.ForwardedRef<HTMLOutputElement>,
) {
return (
<BaseSlider.Output
<BaseSlider.Value
{...props}
ref={ref}
className={(state) =>
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/slider/VerticalSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function VerticalSlider() {
/>
</Slider.Track>
</Slider.Control>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
</Slider.Root>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion docs/data/components/slider/VerticalSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function VerticalSlider() {
/>
</Slider.Track>
</Slider.Control>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
</Slider.Root>
</div>
);
Expand Down
18 changes: 9 additions & 9 deletions docs/data/components/slider/slider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
productId: base-ui
title: React Slider components
description: The Slider component provides users with an input for a one or more numerical values within a given range.
components: SliderRoot, SliderOutput, SliderControl, SliderTrack, SliderThumb, SliderIndicator
hooks: useSliderRoot, useSliderOutput, useSliderControl, useSliderThumb, useSliderIndicator
components: SliderRoot, SliderValue, SliderControl, SliderTrack, SliderThumb, SliderIndicator
hooks: useSliderRoot, useSliderValue, useSliderControl, useSliderThumb, useSliderIndicator
githubLabel: 'component: slider'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/
packageName: '@base-ui-components/react'
Expand All @@ -26,15 +26,15 @@ packageName: '@base-ui-components/react'
Sliders are implemented using a collection of related components:

- `<Slider.Root />` is a top-level component that wraps the other components.
- `<Slider.Output />` renders the value of the slider.
- `<Slider.Value />` renders the value of the slider.
- `<Slider.Control />` renders the click/touch area that contains the track and thumb.
- `<Slider.Track />` renders the visible rail on the `Control` along which the thumb(s) can be moved.
- `<Slider.Indicator />` renders the filled portion of the track which represents the value(s).
- `<Slider.Thumb />` renders the element that can be moved along the track to change the value.

```tsx
<Slider.Root>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -54,7 +54,7 @@ When Slider is uncontrolled, the `defaultValue` prop sets the initial value of t
function App() {
return (
<Slider.Root defaultValue={50}>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -78,7 +78,7 @@ function App() {
const [value, setValue] = useState(50);
return (
<Slider.Root value={value} onValueChange={setValue}>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -98,7 +98,7 @@ The `min` and `max` props can be used to restrict the value(s) within a range.

```tsx
<Slider.Root min={1} max={9}>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -114,7 +114,7 @@ The `step` prop snaps each value to multiples of the given number. In the below

```tsx
<Slider.Root step={4} defaultValue={3}>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -132,7 +132,7 @@ To let users set the start and end of a range on a Slider, provide an array of v

```tsx
<Slider.Root defaultValue={[45, 70]}>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/generated/slider-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"default": "false",
"description": "Whether the component should ignore user interaction."
},
"format": {
"type": "Intl.NumberFormatOptions",
"description": "Options to format the input value."
},
"largeStep": {
"type": "number",
"default": "10",
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/generated/slider-thumb.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"description": "Accepts a function which returns a string value that provides a user-friendly name for the input associated with the thumb"
},
"getAriaValueText": {
"type": "function(value: number, index: number) => string",
"type": "function(formattedValue: string, value: number, index: number) => string",
"description": "Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.\nThis is important for screen reader users."
},
"render": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "SliderOutput",
"name": "SliderValue",
"description": "Displays the current value of the slider as text.\nRenders an `<output>` element.",
"props": {
"className": {
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/overrides/slider-root.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "SliderRoot",
"props": {
"format": {
"type": "Intl.NumberFormatOptions"
},
"onValueChange": {
"type": "(value, event, activeThumbIndex) => void"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function App() {
onValueChange={(newValue) => setVal1(newValue as number)}
onValueCommitted={(newValue) => setVal2(newValue as number)}
>
<Slider.Output className={classes.output} />
<Slider.Value className={classes.output} />
<Slider.Control className={classes.control}>
<Slider.Track className={classes.track}>
<Slider.Indicator className={classes.indicator} />
Expand Down
56 changes: 56 additions & 0 deletions docs/src/app/(private)/experiments/slider-format.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use client';
import * as React from 'react';
import { useTheme } from '@mui/system';
import { Slider } from '@base-ui-components/react/slider';
import c from './slider.module.css';

export default function UnstyledSliderIntroduction() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div
className={isDarkMode ? 'dark' : ''}
style={{ display: 'flex', flexDirection: 'column', gap: '4rem', width: 320 }}
>
<Slider.Root
className={c.slider}
defaultValue={[50, 75]}
aria-labelledby="BudgetSliderLabel"
format={{
style: 'currency',
currency: 'USD',
currencyDisplay: 'name',
}}
>
<Label
id="BudgetSliderLabel"
htmlFor=":slider-thumb-input:"
className={c.label}
>
Budget
</Label>
<Slider.Value className={c.output}>
{(_, values) => `$${values[0].toFixed(2)} - ${values[1].toFixed(2)} USD`}
</Slider.Value>
<Slider.Control className={c.control}>
<Slider.Track className={c.track}>
<Slider.Indicator className={c.indicator} />
<Slider.Thumb className={c.thumb} inputId="thumb1" />
<Slider.Thumb className={c.thumb} inputId="thumb2" />
</Slider.Track>
</Slider.Control>
</Slider.Root>
</div>
);
}

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

return <label id={id} htmlFor={htmlFor} {...otherProps} />;
}

function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
2 changes: 1 addition & 1 deletion docs/src/app/(private)/experiments/slider.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
position: relative;
-webkit-tap-highlight-color: transparent;
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-columns: 1fr auto;
gap: 1rem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Import the component and place its parts the following way:
import { Slider } from '@base-ui-components/react/slider';

<Slider.Root>
<Slider.Output />
<Slider.Value />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
Expand All @@ -26,4 +26,4 @@ import { Slider } from '@base-ui-components/react/slider';
</Slider.Root>;
```

<Reference component="Slider" parts="Root, Output, Control, Track, Indicator, Thumb" />
<Reference component="Slider" parts="Root, Value, Control, Track, Indicator, Thumb" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.Switch {
position: relative;
display: flex;
appearance: none;
border: 0;
Expand Down Expand Up @@ -48,6 +49,17 @@
box-shadow: none;
}
}

&:focus-visible {
&::before {
content: '';
inset: 0;
position: absolute;
border-radius: inherit;
outline: 2px solid var(--color-blue);
outline-offset: 2px;
}
}
}

.Thumb {
Expand All @@ -57,10 +69,6 @@
background-color: white;
transition: translate 150ms ease;

&:focus-visible {
outline: 2px solid var(--color-blue);
}

&[data-checked] {
translate: 1rem 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function ExampleSwitch() {
return (
<Switch.Root
defaultChecked
className="flex h-6 w-10 rounded-full bg-gradient-to-r from-gray-700 from-35% to-gray-200 to-65% bg-[length:6.5rem_100%] bg-[100%_0%] bg-no-repeat p-px shadow-[inset_0_1.5px_2px] shadow-gray-200 outline -outline-offset-1 outline-gray-200 transition-[background-position,box-shadow] duration-[125ms] ease-[cubic-bezier(0.26,0.75,0.38,0.45)] active:bg-gray-100 data-[checked]:bg-[0%_0%] data-[checked]:active:bg-gray-500 dark:from-gray-500 dark:shadow-black/75 dark:outline-white/15 dark:data-[checked]:shadow-none"
className="relative flex h-6 w-10 rounded-full bg-gradient-to-r from-gray-700 from-35% to-gray-200 to-65% bg-[length:6.5rem_100%] bg-[100%_0%] bg-no-repeat p-px shadow-[inset_0_1.5px_2px] shadow-gray-200 outline -outline-offset-1 outline-gray-200 transition-[background-position,box-shadow] duration-[125ms] ease-[cubic-bezier(0.26,0.75,0.38,0.45)] before:absolute before:rounded-full before:outline-offset-2 before:outline-blue-800 focus-visible:before:inset-0 focus-visible:before:outline-2 active:bg-gray-100 data-[checked]:bg-[0%_0%] data-[checked]:active:bg-gray-500 dark:from-gray-500 dark:shadow-black/75 dark:outline-white/15 dark:data-[checked]:shadow-none"
>
<Switch.Thumb className="aspect-square h-full rounded-full bg-white shadow-[0_0_1px_1px,0_1px_1px,1px_2px_4px_-1px] shadow-gray-100 transition-transform duration-150 data-[checked]:translate-x-4 dark:shadow-black/25" />
</Switch.Root>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/app/(public)/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

body {
min-width: 360px;
min-width: 320px;
line-height: 1.5;
background-color: var(--color-background);
color: var(--color-foreground);
Expand Down
1 change: 1 addition & 0 deletions docs/src/components/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.Header {
@apply text-sm;
position: absolute;
left: 0;
top: 0;
height: var(--header-height);
width: 100%;
Expand Down
Loading

0 comments on commit 5b94f19

Please sign in to comment.