diff --git a/docs/data/joy/components/autocomplete/autocomplete.md b/docs/data/joy/components/autocomplete/autocomplete.md index 38ad1ba96c0aee..76752ae8c694ce 100644 --- a/docs/data/joy/components/autocomplete/autocomplete.md +++ b/docs/data/joy/components/autocomplete/autocomplete.md @@ -265,6 +265,12 @@ const filterOptions = (options, { inputValue }) => matchSorter(options, inputVal ; ``` +## CSS variables playground + +The Autocomplete component reuses CSS variables from the Input component to give you the consistent customization experience. + +{{"demo": "AutocompleteVariables.js", "hideToolbar": true, "bg": "gradient"}} + ## Common examples ### Hint @@ -307,12 +313,6 @@ If you would like to prevent the default key handler behavior, you can set the e /> ``` -## CSS Variables - -The Autocomplete component reuses CSS variables from the Input component to give you the consistent customization experience. - -{{"demo": "AutocompleteVariables.js", "hideToolbar": true}} - ## Limitations ### autocomplete/autofill diff --git a/docs/data/joy/components/avatar/avatar.md b/docs/data/joy/components/avatar/avatar.md index 6df65dc0e89519..ff869e3294c58e 100644 --- a/docs/data/joy/components/avatar/avatar.md +++ b/docs/data/joy/components/avatar/avatar.md @@ -131,12 +131,12 @@ Combine the Avatar component with the [Badge](/joy-ui/react-badge/) to visually {{"demo": "BadgeAvatars.js"}} -## CSS variable playground +## CSS variables playground Play around with the CSS variables available to the Avatar component to see how the design changes. You can use these to customize the component with both the `sx` prop and the theme. -{{"demo": "AvatarGroupVariables.js", "hideToolbar": true }} +{{"demo": "AvatarGroupVariables.js", "hideToolbar": true, "bg": "gradient"}} ## Anatomy diff --git a/docs/data/joy/components/breadcrumbs/breadcrumbs.md b/docs/data/joy/components/breadcrumbs/breadcrumbs.md index d9c17584ac3e36..42bf40566b8e99 100644 --- a/docs/data/joy/components/breadcrumbs/breadcrumbs.md +++ b/docs/data/joy/components/breadcrumbs/breadcrumbs.md @@ -65,6 +65,13 @@ The demo below shows how to add an icon to the Link with `startDecorator` and ch {{"demo": "BreadcrumbsWithIcon.js"}} +## CSS variables playground + +Play around with the CSS variables available to the Breadcrumbs component to see how the design changes. +You can use these to customize the component with both the `sx` prop and the theme. + +{{"demo": "BreadcrumbsVariables.js", "hideToolbar": true, "bg": "gradient"}} + ## Common examples ### Condensed Breadcrumbs @@ -84,13 +91,6 @@ As an alternative to the behavior of the condensed demo above, consider adding a {{"demo": "BreadcrumbsWithMenu.js"}} -## CSS variable playground - -Play around with the CSS variables available to the Breadcrumbs component to see how the design changes. -You can use these to customize the component with both the `sx` prop and the theme. - -{{"demo": "BreadcrumbsVariables.js", "hideToolbar": true}} - ## Accessibility (WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/breadcrumb/) diff --git a/docs/data/joy/components/button/button.md b/docs/data/joy/components/button/button.md index 5a96aa7fdd6ddf..68f90d24210ad8 100644 --- a/docs/data/joy/components/button/button.md +++ b/docs/data/joy/components/button/button.md @@ -124,18 +124,18 @@ Use the Icon Button component for a square button to house an icon with no text {{"demo": "IconButtons.js"}} -## CSS variable playground +## CSS variables playground Play around with the CSS variables available to the Button and Icon Button components to see how the design changes. You can use these to customize the components with both the `sx` prop and the theme. ### Button -{{"demo": "ButtonVariables.js", "hideToolbar": true}} +{{"demo": "ButtonVariables.js", "hideToolbar": true, "bg": "gradient"}} ### Icon Button -{{"demo": "IconButtonVariables.js", "hideToolbar": true}} +{{"demo": "IconButtonVariables.js", "hideToolbar": true, "bg": "gradient"}} ## Accessibility diff --git a/docs/data/joy/components/card/CardVariables.js b/docs/data/joy/components/card/CardVariables.js index b9ec0bce435847..ceb5c13c73c526 100644 --- a/docs/data/joy/components/card/CardVariables.js +++ b/docs/data/joy/components/card/CardVariables.js @@ -1,239 +1,45 @@ import * as React from 'react'; -import AspectRatio from '@mui/joy/AspectRatio'; -import Box from '@mui/joy/Box'; import Button from '@mui/joy/Button'; -import Sheet from '@mui/joy/Sheet'; import Card from '@mui/joy/Card'; import CardActions from '@mui/joy/CardActions'; -import CardCover from '@mui/joy/CardCover'; import CardContent from '@mui/joy/CardContent'; -import CardOverflow from '@mui/joy/CardOverflow'; -import CircularProgress from '@mui/joy/CircularProgress'; import IconButton from '@mui/joy/IconButton'; -import Link from '@mui/joy/Link'; -import FormControl from '@mui/joy/FormControl'; -import FormLabel from '@mui/joy/FormLabel'; -import FormHelperText from '@mui/joy/FormHelperText'; -import Input from '@mui/joy/Input'; import Typography from '@mui/joy/Typography'; import BookmarkBorderIcon from '@mui/icons-material/BookmarkBorder'; -import BrandingProvider from 'docs/src/BrandingProvider'; -import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; - -function formatSx(sx) { - const lines = Object.keys(sx); - if (!lines.length) { - return ''; - } - if (lines.length === 1) { - return ` sx={${JSON.stringify(sx) - .replace('{', '{ ') - .replace('}', ' }') - .replace(':', ': ')}}`; - } - return ` sx={${JSON.stringify(sx, null, 2)}}`; -} - -const vars = [ - { - var: '--Card-padding', - defaultValue: '16px', - type: 'number', - }, - { - var: '--Card-radius', - defaultValue: '12px', - type: 'number', - }, -]; +import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo'; export default function CardVariables() { - const [sx, setSx] = React.useState({}); return ( - - + ]} + renderDemo={(sx) => ( - - - - - - div': { - '--variant-borderWidth': '2px', - borderColor: 'background.surface', - }, - }} - > - - - - - Card title - - - A very very long description. + Card title + An interesting description. - - - + + + - - - - - - - - 70% - - - - - Card title - - - Long description. - - - - - - - - - - - CSS variables - - {vars.map((data) => ( - - - {data.var} - - px} - type={data.type} - sx={{ - maxWidth: 160, - '& .JoyInput-root': { '--Input-paddingInline': '0.5rem' }, - }} - onChange={(event) => { - const { value } = event.target; - setSx((prevSx) => { - if (!value) { - const newSx = { ...prevSx }; - // @ts-ignore - delete newSx[data.var]; - return newSx; - } - return { - ...prevSx, - [data.var]: `${value}px`, - }; - }); - }} - /> - {data.defaultValue ? ( - {`Default as ${data.defaultValue}`} - ) : null} - - ))} - - - - `} - language="jsx" - sx={{ display: { xs: 'none', md: 'initial' } }} - /> - - + )} + /> ); } diff --git a/docs/data/joy/components/card/card.md b/docs/data/joy/components/card/card.md index d662e0537217d5..dbeb0e268ce96f 100644 --- a/docs/data/joy/components/card/card.md +++ b/docs/data/joy/components/card/card.md @@ -158,18 +158,18 @@ Learn more about this and other best practices for accessible cards in the [Incl {{"demo": "InteractiveCard.js"}} -## CSS variable playground +## CSS variables playground Play around with the CSS variables available to the Card component to see how the design changes. You can use these to customize the component with both the `sx` prop and the theme. +{{"demo": "CardVariables.js", "hideToolbar": true, "bg": "gradient"}} + :::success If you need to adjust a Card's padding or border radius, it's preferable to do so using these variables rather than plain CSS properties. This is because the variables are also used to calculate a proper radius for the Card's children, to prevent a mismatch between their relative proportions. ::: -{{"demo": "CardVariables.js" , "hideToolbar": true}} - ## Common examples ### Bio card diff --git a/docs/data/joy/components/chip/chip.md b/docs/data/joy/components/chip/chip.md index 927221d9482d8c..4c97d6960da9c9 100644 --- a/docs/data/joy/components/chip/chip.md +++ b/docs/data/joy/components/chip/chip.md @@ -91,10 +91,10 @@ Use checkboxes when you want to enable multiple selection. {{"demo": "CheckboxChip.js"}} -## CSS variables +## CSS variables playground Play around with all the CSS variables available in the slider component to see how the design changes. You can use those to customize the component on both the `sx` prop and the theme. -{{"demo": "ChipVariables.js", "hideToolbar": true}} +{{"demo": "ChipVariables.js", "hideToolbar": true, "bg": "gradient"}} diff --git a/docs/data/joy/components/circular-progress/circular-progress.md b/docs/data/joy/components/circular-progress/circular-progress.md index e2c8d640a77a79..1e3d4e7113575d 100644 --- a/docs/data/joy/components/circular-progress/circular-progress.md +++ b/docs/data/joy/components/circular-progress/circular-progress.md @@ -86,12 +86,12 @@ The size of the Circular Progress is controlled by a button, an icon button, or {{"demo": "CircularProgressButton.js"}} -## CSS variable playground +## CSS variables playground Play around with all the CSS variables available on the component to see how the design changes. You can use these to customize the component with both the `sx` prop and the theme. -{{"demo": "CircularProgressVariables.js", "hideToolbar": true}} +{{"demo": "CircularProgressVariables.js", "hideToolbar": true, "bg": "gradient"}} ## Accessibility diff --git a/docs/data/joy/components/input/input.md b/docs/data/joy/components/input/input.md index 7d54391dc628de..88acb10f5b9225 100644 --- a/docs/data/joy/components/input/input.md +++ b/docs/data/joy/components/input/input.md @@ -133,6 +133,13 @@ These props may include HTML attributes such as `ref`, `min`, `max`, and `autoco {{"demo": "InputSlotProps.js"}} +## CSS variables playground + +Play around with the CSS variables available to the Input component to see how the design changes. +You can use these to customize the component with both the `sx` prop and the theme. + +{{"demo": "InputVariables.js", "hideToolbar": true, "bg": "gradient"}} + ## Common examples ### Focus outline @@ -180,13 +187,6 @@ The demos below illustrate how to do this with two popular libraries. {{"demo": "InputReactNumberFormat.js"}} -## CSS variable playground - -Play around with the CSS variables available to the Input component to see how the design changes. -You can use these to customize the component with both the `sx` prop and the theme. - -{{"demo": "InputVariables.js", "hideToolbar": true}} - ## Accessibility All inputs should have a descriptive label linked to help users understand its purpose. diff --git a/docs/data/joy/components/linear-progress/linear-progress.md b/docs/data/joy/components/linear-progress/linear-progress.md index 42ae936e575a51..f243a8819a2cbe 100644 --- a/docs/data/joy/components/linear-progress/linear-progress.md +++ b/docs/data/joy/components/linear-progress/linear-progress.md @@ -69,13 +69,13 @@ Provides a number to `thickness` prop to control the bar's stroke width. {{"demo": "LinearProgressThickness.js"}} -## CSS variables +## CSS variables playground Play around with all the CSS variables available on the component to see how the design changes. You can use those to customize the component on both the `sx` prop and the theme. -{{"demo": "LinearProgressVariables.js", "hideToolbar": true}} +{{"demo": "LinearProgressVariables.js", "hideToolbar": true, "bg": "gradient"}} ## Common examples diff --git a/docs/data/joy/components/list/list.md b/docs/data/joy/components/list/list.md index 2cdcc82b373d56..5ebd9217aa5757 100644 --- a/docs/data/joy/components/list/list.md +++ b/docs/data/joy/components/list/list.md @@ -177,13 +177,13 @@ A selected `ListItemButton` does not apply `:hover` and `:active` global variant {{"demo": "SelectedList.js"}} -## CSS variables +## CSS variables playground Play around with all the CSS variables available in the list component to see how the design changes. You can use those to customize the component on both the `sx` prop and the theme. -{{"demo": "ListVariables.js", "hideToolbar": true}} +{{"demo": "ListVariables.js", "hideToolbar": true, "bg": "gradient"}} ## Common examples diff --git a/docs/data/joy/components/slider/slider.md b/docs/data/joy/components/slider/slider.md index 4182a35688ff22..f71ab2254d3e47 100644 --- a/docs/data/joy/components/slider/slider.md +++ b/docs/data/joy/components/slider/slider.md @@ -75,10 +75,10 @@ You can either invert it by assigning `inverted` to the `track` prop or remove i {{"demo": "TrackFalseSlider.js"}} -## CSS variables +## CSS variables playground Play around with all the CSS variables available in the slider component to see how the design changes. You can use those to customize the component on both the `sx` prop and the theme. -{{"demo": "SliderVariables.js", "hideToolbar": true}} +{{"demo": "SliderVariables.js", "hideToolbar": true, "bg": "gradient"}} diff --git a/docs/data/joy/components/switch/SwitchVariables.js b/docs/data/joy/components/switch/SwitchVariables.js index e071a2a924550d..bd7d4c3fd880b2 100644 --- a/docs/data/joy/components/switch/SwitchVariables.js +++ b/docs/data/joy/components/switch/SwitchVariables.js @@ -10,7 +10,7 @@ export default function SwitchVariables() { data={[ { var: '--Switch-gap', defaultValue: '8px' }, [ - 'track', + 'Track', [ { var: '--Switch-trackRadius', defaultValue: '16px' }, { var: '--Switch-trackWidth', defaultValue: '48px' }, @@ -19,7 +19,7 @@ export default function SwitchVariables() { { defaultOpen: true }, ], [ - 'thumb', + 'Thumb', [ { var: '--Switch-thumbSize', defaultValue: '16px' }, { var: '--Switch-thumbRadius' }, diff --git a/docs/data/joy/components/switch/switch.md b/docs/data/joy/components/switch/switch.md index de709590f85a6d..2f4f058c6e7d40 100644 --- a/docs/data/joy/components/switch/switch.md +++ b/docs/data/joy/components/switch/switch.md @@ -82,34 +82,13 @@ Similarly to the above, target the thumb's children to display icons inside of i {{"demo": "ExampleThumbChild.js"}} -## CSS Variables +## CSS variables playground Play around with all the CSS variables available in the switch component to see how the design changes. You can use those to customize the component on both the `sx` prop and the theme. -{{"demo": "SwitchVariables.js"}} - -## Accessibility - -Here are a few tips to make sure you have an accessible switch component: - -- The `Switch` will render with the `checkbox` role as opposed to `switch`. - This is mainly because the latter isn't widely supported yet. - However, if you believe your audience will support it, make sure to test with assistive technology. - Use the `slotProps` prop to change the role: - - ```jsx - - ``` - -- Every form control component should have proper labels. - This includes radio buttons, checkboxes, and switches. - In most cases, this is done using the `