index
int64 0
0
| repo_id
stringlengths 16
181
| file_path
stringlengths 28
270
| content
stringlengths 1
11.6M
| __index_level_0__
int64 0
10k
|
---|---|---|---|---|
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingHooks.js | import * as React from 'react';
import clsx from 'clsx';
import { useSwitch } from '@mui/base/useSwitch';
import { styled } from '@mui/system';
const SwitchRoot = styled('span')`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
&.Switch-disabled {
opacity: 0.4;
cursor: not-allowed;
}
&.Switch-checked {
background: #007fff;
}
`;
const SwitchInput = styled('input')`
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
`;
const SwitchThumb = styled('span')`
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
&.Switch-focusVisible {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
&.Switch-checked {
left: 14px;
top: 3px;
background-color: #fff;
}
`;
function Switch(props) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);
const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};
return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchThumb className={clsx(stateClasses)} />
<SwitchInput {...getInputProps()} aria-label={props['aria-label']} />
</SwitchRoot>
);
}
export default function StylingHooks() {
return <Switch aria-label="Demo switch" />;
}
| 600 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingHooks.tsx | import * as React from 'react';
import clsx from 'clsx';
import { useSwitch, UseSwitchParameters } from '@mui/base/useSwitch';
import { styled } from '@mui/system';
const SwitchRoot = styled('span')`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
&.Switch-disabled {
opacity: 0.4;
cursor: not-allowed;
}
&.Switch-checked {
background: #007fff;
}
`;
const SwitchInput = styled('input')`
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
`;
const SwitchThumb = styled('span')`
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
&.Switch-focusVisible {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
&.Switch-checked {
left: 14px;
top: 3px;
background-color: #fff;
}
`;
function Switch(props: UseSwitchParameters & { 'aria-label'?: string }) {
const { getInputProps, checked, disabled, focusVisible } = useSwitch(props);
const stateClasses = {
'Switch-checked': checked,
'Switch-disabled': disabled,
'Switch-focusVisible': focusVisible,
};
return (
<SwitchRoot className={clsx(stateClasses)}>
<SwitchThumb className={clsx(stateClasses)} />
<SwitchInput {...getInputProps()} aria-label={props['aria-label']} />
</SwitchRoot>
);
}
export default function StylingHooks() {
return <Switch aria-label="Demo switch" />;
}
| 601 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingHooks.tsx.preview | <Switch aria-label="Demo switch" /> | 602 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlots.js | import * as React from 'react';
import { styled } from '@mui/system';
import { Switch, switchClasses } from '@mui/base/Switch';
const SwitchRoot = styled('span')`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
&.${switchClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}
&.${switchClasses.checked} {
background: #007fff;
}
`;
const SwitchThumb = styled('span')`
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
.${switchClasses.focusVisible} & {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
.${switchClasses.checked} > & {
left: 14px;
top: 3px;
background-color: #fff;
}
`;
const SwitchInput = styled('input')`
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
`;
export default function StylingSlots() {
return (
<Switch slots={{ root: SwitchRoot, thumb: SwitchThumb, input: SwitchInput }} />
);
}
| 603 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlots.tsx | import * as React from 'react';
import { styled } from '@mui/system';
import { Switch, switchClasses } from '@mui/base/Switch';
const SwitchRoot = styled('span')`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
&.${switchClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}
&.${switchClasses.checked} {
background: #007fff;
}
`;
const SwitchThumb = styled('span')`
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
.${switchClasses.focusVisible} & {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
.${switchClasses.checked} > & {
left: 14px;
top: 3px;
background-color: #fff;
}
`;
const SwitchInput = styled('input')`
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
`;
export default function StylingSlots() {
return (
<Switch slots={{ root: SwitchRoot, thumb: SwitchThumb, input: SwitchInput }} />
);
}
| 604 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlots.tsx.preview | <Switch slots={{ root: SwitchRoot, thumb: SwitchThumb, input: SwitchInput }} /> | 605 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlotsSingleComponent.js | import * as React from 'react';
import { styled } from '@mui/system';
import { Switch as BaseSwitch, switchClasses } from '@mui/base/Switch';
const Switch = styled(BaseSwitch)`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
& .${switchClasses.thumb} {
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
}
& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
&.${switchClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}
&.${switchClasses.checked} {
background: #007fff;
& .${switchClasses.thumb} {
left: 14px;
top: 3px;
background-color: #fff;
}
}
&.${switchClasses.focusVisible} .${switchClasses.thumb} {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
`;
export default function StylingSlotsSingleComponent() {
return <Switch />;
}
| 606 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlotsSingleComponent.tsx | import * as React from 'react';
import { styled } from '@mui/system';
import { Switch as BaseSwitch, switchClasses } from '@mui/base/Switch';
const Switch = styled(BaseSwitch)`
font-size: 0;
position: relative;
display: inline-block;
width: 32px;
height: 20px;
background: #b3c3d3;
border-radius: 10px;
margin: 10px;
cursor: pointer;
& .${switchClasses.thumb} {
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
position: relative;
transition: all 200ms ease;
}
& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
&.${switchClasses.disabled} {
opacity: 0.4;
cursor: not-allowed;
}
&.${switchClasses.checked} {
background: #007fff;
& .${switchClasses.thumb} {
left: 14px;
top: 3px;
background-color: #fff;
}
}
&.${switchClasses.focusVisible} .${switchClasses.thumb} {
background-color: rgb(255 255 255 / 1);
box-shadow: 0 0 1px 8px rgb(0 0 0 / 0.25);
}
`;
export default function StylingSlotsSingleComponent() {
return <Switch />;
}
| 607 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/StylingSlotsSingleComponent.tsx.preview | <Switch /> | 608 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/customization/customization.md | # Customizing Base UI components
<p class="description">There are several ways to customize Base UI components, from applying custom CSS rules to building fully custom components using hooks.</p>
With Base UI, you have the freedom to decide how much you want to customize a component's structure and style.
## Styling the components
This section reviews several methods of customization that are available: applying custom CSS rules, overriding default subcomponent slots, customizing the slot props, and using hooks to build fully custom components.
### Which option to choose?
The multitude of options can be overwhelming, especially if you're new to Base UI.
How to decide which one to use, then?
The first decision to make is whether to use unstyled components or hooks.
Hooks are better suited for making component libraries that can be further customized.
For example, our own Joy UI is implemented using hooks from Base UI.
Hooks also serve as the basis for several Material UI components, and future versions of the library will use them even more extensively.
If you don't need to make your component library customizable (for instance, by exposing `slotProps`), then the unstyled components may be a better option thanks to their simplicity.
After choosing unstyled components, there is one more decision to make: how to style them.
The answer depends on the styling solution used in the project:
#### Plain CSS, Sass, Less
...or anything else that compiles to CSS:
You can either [style the components using the built-in classes](#applying-custom-css-rules) or [specify your own classes](#customizing-slot-props) and reference them in your stylesheets.
#### CSS Modules
When working with [CSS Modules](https://github.com/css-modules/css-modules), the simplest approach is to [specify custom classes using `slotProps`](#customizing-slot-props), as shown below:
```tsx
import clsx from 'clsx';
import { Switch as BaseSwitch, SwitchOwnerState } from '@mui/base/Switch';
import classes from './styles.module.css';
export default function Switch(props) {
const slotProps = {
root: (ownerState: SwitchOwnerState) => ({
className: clsx(classes.root, {
[classes.checked]: ownerState.checked,
[classes.disabled]: ownerState.disabled,
}),
}),
thumb: { className: classes.thumb },
track: { className: classes.track },
input: { className: classes.input },
};
return <BaseSwitch {...props} slotProps={slotProps} />;
}
```
In this example we're using the [clsx](https://www.npmjs.com/package/clsx) utility to reduce the effort needed to apply class names conditionally.
#### Tailwind CSS
Use [`slotProps`](#customizing-slot-props) to apply custom styles using [Tailwind CSS](https://tailwindcss.com/), as shown below:
```tsx
import { Switch as BaseSwitch, SwitchOwnerState } from '@mui/base/Switch';
export default function Switch(props) {
const slotProps = {
root: (ownerState: SwitchOwnerState) => ({
className: `inline-block w-8 h-5 rounded-full cursor-pointer relative ${
ownerState.checked ? 'bg-cyan-500' : 'bg-zinc-400'
}`,
}),
thumb: (ownerState: SwitchOwnerState) => ({
className: `bg-white block w-3.5 h-3.5 rounded-full relative top-[3px] ${
ownerState.checked ? 'left-[3px]' : 'left-[14px]'
}`,
}),
input: { className: 'absolute w-full h-full inset-0 opacity-0 z-10 m-0' },
};
return <BaseSwitch {...props} slotProps={slotProps} />;
}
```
See our [Working with Tailwind CSS guide](/base-ui/guides/working-with-tailwind-css/) for more information about integrating Base UI and Tailwind CSS.
#### Styled components
If you use a CSS-in-JS solution with a styled-components-like API (such as [MUI System](/system/getting-started/) or [Emotion](https://emotion.sh/docs/introduction)), the best method is to provide the styled subcomponents using the [`slots` prop](#overriding-subcomponent-slots), as shown in the [demo below](#overriding-subcomponent-slots).
Alternatively, you can wrap the whole unstyled component in a `styled` utility and target the individual subcomponents using CSS classes:
{{"demo": "StylingSlotsSingleComponent.js", "defaultCodeOpen": true}}
---
### Applying custom CSS rules
If you're happy with the default structure of a component's rendered HTML, you can apply custom styles to the component's classes.
Each component has its own set of classes.
Some classes are **static**, which is to say that they are always present on the component.
Others are applied **conditionally**—like `Mui-disabled`, for example, which is only present when a component is disabled.
Each component's API documentation lists all classes that the component uses.
Additionally, you can import a `[componentName]Classes` object that describes all the classes a given component uses, as the following demo illustrates:
{{"demo": "StylingCustomCss.js", "defaultCodeOpen": true}}
If you don't use these classes, you can clean up the DOM by disabling them.
See [Disabling default CSS classes](#disabling-default-css-classes) for instructions.
### Overriding subcomponent slots
If you want to make changes to a component's rendered HTML structure, you can override the default subcomponents ("slots") using the `slots` and/or `component` prop—see ["Shared props" on the Base Usage page](/base-ui/getting-started/usage/#shared-props) for more details.
The following demo uses [Switch](/base-ui/react-switch/) to show how to create a styled component by applying styles to three of its subcomponent slots: `root`, `thumb`, and `input`.
Note that although this demo uses [MUI System](/system/styled/) as a styling solution, you are free to choose any alternative.
{{"demo": "StylingSlots.js"}}
The components you pass in the `slots` prop receive the `ownerState` prop from the top-level component (the "owner").
By convention, it contains all props passed to the owner, merged with its rendering state.
For example:
```jsx
<Switch slots={{ thumb: MyCustomThumb }} data-foo="42" />
```
In this case, `MyCustomThumb` component receives the `ownerState` object with the following data:
```ts
{
checked: boolean;
disabled: boolean;
focusVisible: boolean;
readOnly: boolean;
'data-foo': string;
}
```
You can use this object to style your component.
:::warning
When inserting a component from a third-party library into a slot, you may encounter this warning: `"React does not recognize the ownerState prop on a DOM element."`
This is because the custom component isn't prepared to receive the `ownerState` like a built-in library component would be.
:::
If you need to use the `ownerState` to propagate some props to a third-party component, you must create a custom wrapper for this purpose.
But if you don't need the `ownerState` and just want to resolve the error, you can use the `prepareForSlot` utility:
{{"demo": "PrepareForSlot.js", "defaultCodeOpen": true}}
### Customizing slot props
Use the `slotProps` prop to customize the inner component props.
The most common use case is setting a class name, but you can set any prop, including event handlers.
The following example shows how to add a custom class to two of the Switch's slots:
```tsx
function Switch(props: SwitchProps) {
const slotProps: SwitchProps['slotProps'] = {
thumb: {
className: 'my-thumb',
},
track: {
className: 'my-track',
},
};
return <Switch {...props} slotProps={slotProps} />;
}
```
The `switch:thumb` and `switch:class` are added unconditionally—they will always be present on the Switch component.
You may need to apply a class only when a component is in a particular state.
A good example is adding `on` and `off` classes to a Switch based on its checked state, as shown in the demo below:
{{"demo": "SlotPropsCallback.js", "defaultCodeOpen": true}}
Here, instead of an object with props, the root slot receives a callback function.
Its only parameter is `ownerState`, which is an object that describes the state of the "owner component"—the Switch in this case.
The `ownerState` holds all the props of the owner component (with defaults applied where applicable) and is augmented with the internal state of the component.
In the case of the Select, the additional information includes the `checked`, `disabled`, `focusVisible`, and `readOnly` boolean fields.
### Creating custom components using hooks
If you need complete control over a component's rendered HTML structure, you can build it with hooks.
Hooks give you access to the _logic_ that a component uses, but without any default structure.
See ["Components vs. hooks" on the Base Usage page](/base-ui/getting-started/usage/#components-vs-hooks) for more details.
Hooks return the current state of the component (e.g. `checked`, `disabled`, `open`, etc.) and provide functions that return props you can apply to your fully custom components.
In the case of [Switch](/base-ui/react-switch/), the component is accompanied by the `useSwitch` hook which gives you all of the functionality without any structure.
It returns the following object:
```ts
{
checked: Readonly<boolean>;
disabled: Readonly<boolean>;
readOnly: Readonly<boolean>;
focusVisible: Readonly<boolean>;
getInputProps: (otherProps?: object) => SwitchInputProps;
}
```
The `checked`, `disabled`, `readOnly`, and `focusVisible` fields represent the state of the switch.
Use them to apply styling to your HTML elements.
The `getInputProps` function can be used to get the props to place on an HTML `<input>` to make the switch accessible.
{{"demo": "StylingHooks.js", "defaultCodeOpen": true}}
## Disabling default CSS classes
If you don't need the built-in classes on components, you may disable them.
This will clean up the DOM and can be useful especially if you apply your own classes or style components using a CSS-in-JS solution.
To do this, wrap your components in a ClassNameConfigurator component (imported from `@mui/base/utils`):
```tsx
<ClassNameConfigurator disableDefaultClasses>
<Button>I'm classless!</Button>
</ClassNameConfigurator>
```
Inspect the elements in the following demo to see the difference:
{{"demo": "DisabledDefaultClasses.js"}}
| 609 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/overview/overview.md | ---
title: Overview
---
# Base UI - Overview
<p class="description">Base UI is a library of headless ("unstyled") React UI components and low-level hooks.</p>
## Introduction
Base UI is a library of unstyled React UI components and hooks.
These components were extracted from [Material UI](/material-ui/), and are now available as a standalone package.
They feature the same robust engineering but without implementing Material Design.
Base UI includes prebuilt components with production-ready functionality, along with low-level hooks for transferring that functionality to other components.
With Base UI, you can rapidly build on top of our foundational components using any styling solution you choose—no need to override any default style engine or theme.
:::info
Base UI is currently in beta.
We're adding new components and features regularly, and you're welcome to contribute!
Look for the [`package: base-ui`](https://github.com/mui/material-ui/labels/package%3A%20base-ui) label on open issues and pull requests in the `mui/material-ui` repository on GitHub to see what other community members are working on, and feel free to submit your own.
:::
## Advantages of Base UI
- **Ship faster:** Base UI gives you the foundational building blocks you need to assemble a sleek and sophisticated user interface in a fraction of the time that it would take to do it all from scratch.
- **You own the CSS:** unlike Material UI, which uses Emotion as a default style engine, Base UI has no built-in styling solution.
This means you have complete control over your app's CSS.
- **Accessibility:** Base UI components are built with accessibility in mind.
We do our best to make all components screen reader-friendly, and offer suggestions for optimizing accessibility throughout our documentation.
## Base UI vs. Material UI
Base UI features many of the same components as [Material UI](/material-ui/getting-started/), but without the Material Design implementation.
Base UI is not packaged with any default theme or built-in style engine.
This makes it a great choice if you need complete control over how your app's CSS is implemented.
You could think of Base UI as the "skeletal" or "headless" version of Material UI—in fact, future versions of Material UI (starting with v6) will use these components and hooks for their foundational structure.
| 610 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButton.js | import * as React from 'react';
import { Button } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import Stack from '@mui/material/Stack';
export default function BaseButton() {
const { getRootProps } = useButton({});
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<button type="button" {...getRootProps()}>
useButton
</button>
</Stack>
);
}
| 611 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButton.tsx | import * as React from 'react';
import { Button } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import Stack from '@mui/material/Stack';
export default function BaseButton() {
const { getRootProps } = useButton({});
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<button type="button" {...getRootProps()}>
useButton
</button>
</Stack>
);
}
| 612 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButton.tsx.preview | <Button>Button</Button>
<button type="button" {...getRootProps()}>
useButton
</button> | 613 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonMuiSystem.js | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import { styled, alpha } from '@mui/system';
import Stack from '@mui/material/Stack';
function getStyles({ theme }) {
return `
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: #fff;
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
border-color: ${
theme.palette.mode === 'dark'
? 'rgba(240, 246, 252, 0.1)'
: 'rgba(31, 35, 40, 0.15)'
};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent, 0 0 transparent'
: '0 1px 0 rgba(27, 31, 36, 0.1)'
};
margin-left: 16px !important;
text-align: center !important;
&:hover {
transition-duration: 80ms;
}
&:active {
transition: none;
}
&:disabled {
cursor: not-allowed;
box-shadow: none;
}
&:hover:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#2ea043' : '#2c974b'};
}
&:active:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#298e46'};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent'
: 'rgba(0, 45, 17, 0.2) 0px 1px 0px inset'
}
}
&.${buttonClasses.disabled} {
color: ${
theme.palette.mode === 'dark' ? alpha('#fff', 0.5) : alpha('#fff', 0.5)
};
background-color: ${
theme.palette.mode === 'dark' ? alpha('#196c2e', 0.6) : alpha('#196c2e', 0.6)
};
}
`;
}
/*
* The style function argument is completely identical for the unstyled component
* and the hook, though each have different pro and cons.
* More about unstyled components vs hooks here: https://mui.com/base-ui/getting-started/usage/#components-vs-hooks
*/
const GitHubButtonComponent = styled(Button)(getStyles);
const GitHubButtonHook = styled('button')(getStyles);
export default function BaseButtonMuiSystem() {
const { getRootProps } = useButton({});
return (
<Stack spacing={2} direction="row">
<GitHubButtonComponent>Create Repository</GitHubButtonComponent>
<GitHubButtonHook type="button" {...getRootProps()}>
Create Repository
</GitHubButtonHook>
</Stack>
);
}
| 614 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonMuiSystem.tsx | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import { styled, alpha, Theme } from '@mui/system';
import Stack from '@mui/material/Stack';
function getStyles({ theme }: { theme: Theme }) {
return `
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: #fff;
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
border-color: ${
theme.palette.mode === 'dark'
? 'rgba(240, 246, 252, 0.1)'
: 'rgba(31, 35, 40, 0.15)'
};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent, 0 0 transparent'
: '0 1px 0 rgba(27, 31, 36, 0.1)'
};
margin-left: 16px !important;
text-align: center !important;
&:hover {
transition-duration: 80ms;
}
&:active {
transition: none;
}
&:disabled {
cursor: not-allowed;
box-shadow: none;
}
&:hover:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#2ea043' : '#2c974b'};
}
&:active:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#298e46'};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent'
: 'rgba(0, 45, 17, 0.2) 0px 1px 0px inset'
}
}
&.${buttonClasses.disabled} {
color: ${
theme.palette.mode === 'dark' ? alpha('#fff', 0.5) : alpha('#fff', 0.5)
};
background-color: ${
theme.palette.mode === 'dark' ? alpha('#196c2e', 0.6) : alpha('#196c2e', 0.6)
};
}
`;
}
/*
* The style function argument is completely identical for the unstyled component
* and the hook, though each have different pro and cons.
* More about unstyled components vs hooks here: https://mui.com/base-ui/getting-started/usage/#components-vs-hooks
*/
const GitHubButtonComponent = styled(Button)(getStyles);
const GitHubButtonHook = styled('button')(getStyles);
export default function BaseButtonMuiSystem() {
const { getRootProps } = useButton({});
return (
<Stack spacing={2} direction="row">
<GitHubButtonComponent>Create Repository</GitHubButtonComponent>
<GitHubButtonHook type="button" {...getRootProps()}>
Create Repository
</GitHubButtonHook>
</Stack>
);
}
| 615 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonMuiSystem.tsx.preview | <GitHubButtonComponent>Create Repository</GitHubButtonComponent>
<GitHubButtonHook type="button" {...getRootProps()}>
Create Repository
</GitHubButtonHook> | 616 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonPlainCss.js | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import Stack from '@mui/material/Stack';
// .mode-dark is provided by the MUI docs site
const css = `
.demo {
--btn-text: #fff;
--btn-bg: #1f883d;
--btn-hover: #2c974b;
--btn-active-bg: #298e46;
--btn-active-box-shadow: inset 0px 1px 0px rgba(0, 45, 17, 0.2);
--btn-disabled: rgba(255, 255, 255, 0.8);
--btn-disabled-bg: rgb(148, 211, 162);
}
.mode-dark .demo {
--btn-bg: #238636;
--btn-hover: #2ea043;
--btn-active-bg: #238636;
--btn-active-box-shadow: 0 0 transparent;
--btn-disabled: rgba(255, 255, 255, 0.5);
--btn-disabled-bg: rgba(25, 108, 46, 0.6);
}
.github-button {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans,
Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: var(--btn-text);
background-color: var(--btn-bg);
border-color: rgba(240, 246, 252, 0.1);
box-shadow: 0 0 transparent, 0 0 transparent;
margin-left: 16px !important;
text-align: center !important;
}
.github-button:hover {
transition-duration: 80ms;
}
.github-button:active {
transition: none;
}
.github-button:hover:not(.${buttonClasses.disabled}) {
color: var(--btn-text);
background-color: var(--btn-hover);
}
.github-button:active:not(.${buttonClasses.disabled}) {
background-color: var(--btn-active-bg);
box-shadow: var(--btn-active-box-shadow);
}
.github-button.${buttonClasses.disabled} {
cursor: not-allowed;
box-shadow: none;
color: var(--btn-disabled);
background-color: var(--btn-disabled-bg);
}
`;
export default function BaseButtonPlainCss() {
const { getRootProps } = useButton({});
return (
<React.Fragment>
<style type="text/css">{css}</style>
<Stack spacing={2} direction="row" className="demo">
<Button className="github-button">Create Repository</Button>
<button type="button" {...getRootProps()} className="github-button">
Create Repository
</button>
</Stack>
</React.Fragment>
);
}
| 617 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonPlainCss.tsx | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { useButton } from '@mui/base/useButton';
import Stack from '@mui/material/Stack';
// .mode-dark is provided by the MUI docs site
const css = `
.demo {
--btn-text: #fff;
--btn-bg: #1f883d;
--btn-hover: #2c974b;
--btn-active-bg: #298e46;
--btn-active-box-shadow: inset 0px 1px 0px rgba(0, 45, 17, 0.2);
--btn-disabled: rgba(255, 255, 255, 0.8);
--btn-disabled-bg: rgb(148, 211, 162);
}
.mode-dark .demo {
--btn-bg: #238636;
--btn-hover: #2ea043;
--btn-active-bg: #238636;
--btn-active-box-shadow: 0 0 transparent;
--btn-disabled: rgba(255, 255, 255, 0.5);
--btn-disabled-bg: rgba(25, 108, 46, 0.6);
}
.github-button {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans,
Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: var(--btn-text);
background-color: var(--btn-bg);
border-color: rgba(240, 246, 252, 0.1);
box-shadow: 0 0 transparent, 0 0 transparent;
margin-left: 16px !important;
text-align: center !important;
}
.github-button:hover {
transition-duration: 80ms;
}
.github-button:active {
transition: none;
}
.github-button:hover:not(.${buttonClasses.disabled}) {
color: var(--btn-text);
background-color: var(--btn-hover);
}
.github-button:active:not(.${buttonClasses.disabled}) {
background-color: var(--btn-active-bg);
box-shadow: var(--btn-active-box-shadow);
}
.github-button.${buttonClasses.disabled} {
cursor: not-allowed;
box-shadow: none;
color: var(--btn-disabled);
background-color: var(--btn-disabled-bg);
}
`;
export default function BaseButtonPlainCss() {
const { getRootProps } = useButton({});
return (
<React.Fragment>
<style type="text/css">{css}</style>
<Stack spacing={2} direction="row" className="demo">
<Button className="github-button">Create Repository</Button>
<button type="button" {...getRootProps()} className="github-button">
Create Repository
</button>
</Stack>
</React.Fragment>
);
}
| 618 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonPlainCss.tsx.preview | <React.Fragment>
<style type="text/css">{css}</style>
<Stack spacing={2} direction="row" className="demo">
<Button className="github-button">Create Repository</Button>
<button type="button" {...getRootProps()} className="github-button">
Create Repository
</button>
</Stack>
</React.Fragment> | 619 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/BaseButtonTailwind.js | import * as React from 'react';
import { useTheme } from '@mui/material/styles';
export default function BaseButtonTailwind() {
const theme = useTheme();
const sandboxId =
theme.palette.mode === 'dark'
? 'baseui-cra-tailwind-example-dark-f6dc9z'
: 'baseui-cra-tailwind-example-light-43zxqe';
return (
<iframe
title="codesandbox"
src={`https://codesandbox.io/embed/${sandboxId}?fontsize=12&view=preview`}
style={{
width: '100%',
height: 350,
border: 0,
}}
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
/>
);
}
| 620 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/Tutorial.js | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { styled, alpha } from '@mui/system';
const CustomButton = styled(Button)(
({ theme }) => `
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: #fff;
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
border-color: ${
theme.palette.mode === 'dark'
? 'rgba(240, 246, 252, 0.1)'
: 'rgba(31, 35, 40, 0.15)'
};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent, 0 0 transparent'
: '0 1px 0 rgba(27, 31, 36, 0.1)'
};
margin-left: 16px !important;
text-align: center !important;
&:hover {
transition-duration: 80ms;
}
&:active {
transition: none;
}
&:disabled {
cursor: not-allowed;
box-shadow: none;
}
&:hover:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#2ea043' : '#2c974b'};
}
&:active:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#298e46'};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent'
: 'rgba(0, 45, 17, 0.2) 0px 1px 0px inset'
}
}
&.${buttonClasses.disabled} {
color: ${
theme.palette.mode === 'dark' ? alpha('#fff', 0.5) : alpha('#fff', 0.5)
};
background-color: ${
theme.palette.mode === 'dark' ? alpha('#196c2e', 0.6) : alpha('#196c2e', 0.6)
};
}
`,
);
export default function Tutorial() {
return (
<div style={{ marginTop: 16, paddingTop: 16, paddingBottom: 16 }}>
<CustomButton>Create Repository</CustomButton>
</div>
);
}
| 621 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/Tutorial.tsx | import * as React from 'react';
import { Button, buttonClasses } from '@mui/base/Button';
import { styled, alpha } from '@mui/system';
const CustomButton = styled(Button)(
({ theme }) => `
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
word-wrap: break-word;
box-sizing: border-box;
text-decoration: none;
position: relative;
display: inline-block;
padding: 5px 16px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
user-select: none;
border: 1px solid;
border-radius: 6px;
appearance: none;
transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
transition-property: color, background-color, box-shadow, border-color;
color: #fff;
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
border-color: ${
theme.palette.mode === 'dark'
? 'rgba(240, 246, 252, 0.1)'
: 'rgba(31, 35, 40, 0.15)'
};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent, 0 0 transparent'
: '0 1px 0 rgba(27, 31, 36, 0.1)'
};
margin-left: 16px !important;
text-align: center !important;
&:hover {
transition-duration: 80ms;
}
&:active {
transition: none;
}
&:disabled {
cursor: not-allowed;
box-shadow: none;
}
&:hover:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#2ea043' : '#2c974b'};
}
&:active:not(.${buttonClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#298e46'};
box-shadow: ${
theme.palette.mode === 'dark'
? '0 0 transparent'
: 'rgba(0, 45, 17, 0.2) 0px 1px 0px inset'
}
}
&.${buttonClasses.disabled} {
color: ${
theme.palette.mode === 'dark' ? alpha('#fff', 0.5) : alpha('#fff', 0.5)
};
background-color: ${
theme.palette.mode === 'dark' ? alpha('#196c2e', 0.6) : alpha('#196c2e', 0.6)
};
}
`,
);
export default function Tutorial() {
return (
<div style={{ marginTop: 16, paddingTop: 16, paddingBottom: 16 }}>
<CustomButton>Create Repository</CustomButton>
</div>
);
}
| 622 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/Tutorial.tsx.preview | <CustomButton>Create Repository</CustomButton> | 623 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/quickstart/quickstart.md | # Quickstart
<p class="description">Get started with Base UI, a library of headless ("unstyled") React UI components and low-level hooks.</p>
:::info
If you're using Next.js 13.4 or later, check out the [Next.js App Router guide](/base-ui/guides/next-js-app-router/).
:::
## Installation
`@mui/base` is completely standalone – run one of the following commands to add Base UI to your React project:
<codeblock storageKey="package-manager">
```bash npm
npm install @mui/base
```
```bash yarn
yarn add @mui/base
```
```bash pnpm
pnpm add @mui/base
```
</codeblock>
### Peer dependencies
<!-- #react-peer-version -->
Please note that [react](https://www.npmjs.com/package/react) and [react-dom](https://www.npmjs.com/package/react-dom) are peer dependencies too:
```json
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
},
```
## Implementing a Button
This is a quick tutorial that goes through the basics of using and styling Base UI components by replicating a button from GitHub's UI, using their [Primer design system](https://primer.style/components/button) as a reference.
{{"demo": "Tutorial.js", "defaultCodeOpen": false, "hideToolbar": true}}
### Components and hooks
Base UI provides a `<Button />` component and a `useButton` hook.
Both can be used to build a button, and each has its own benefits and trade-offs—see [Components vs. hooks](/base-ui/getting-started/usage/#components-vs-hooks) for details.
The code snippets below demonstrate the basic implementation of each:
#### Button component
```tsx
import * as React from 'react';
import { Button } from '@mui/base/Button';
export default function App() {
return <Button>Click Me</Button>;
}
```
#### useButton hook
```tsx
import * as React from 'react';
import { useButton } from '@mui/base/useButton';
export default function App() {
const { getRootProps } = useButton();
return (
<button type="button" {...getRootProps()}>
Click Me
</button>
);
}
```
Base UI comes with no styles or styling solution—here's what the Button component looks like out of the box:
{{"demo": "BaseButton.js", "defaultCodeOpen": false}}
You can use any styling method of your choice to make fully customizable components for your app. See [Customization](/base-ui/getting-started/customization/) for more details on customization strategies.
Here are some styling examples:
### Styling with CSS
Pass a `className` prop and use it as a styling hook:
```css
/* styles.css */
.btn {
background-color: #1f883d;
/* the rest of the styles */
}
```
```tsx
/* App.js */
<Button className="btn">Create Repository</Button>
```
Base UI components like the Button come with a classes object (e.g. `buttonClasses`) that provides class hooks for styling a particular state.
```css
/* To style the disabled state: */
.${buttonClasses.disabled} { /* ".MuiButton-disabled" */
cursor: not-allowed;
}
```
The demo below shows how to create the Primer button using plain CSS with Base UI's Button component and `useButton` hook:
{{"demo": "BaseButtonPlainCss.js", "defaultCodeOpen": false}}
### Styling with Tailwind CSS
After installing Tailwind CSS, pass its utility classes to `className`, as shown below:
```tsx
<Button className="bg-green-600 rounded-md py-1 px-4...">Create Repository</Button>
```
The demo below shows how to build the Primer button using Tailwind CSS:
{{"demo": "BaseButtonTailwind.js", "hideToolbar": true, "bg": "inline"}}
### Styling with MUI System
[MUI System](/system/getting-started/) is a small set of CSS utilities that provide a styled-components-like API for building out designs that adhere to a theme.
MUI System's core utility is a [`styled` function](/system/styled/) that's equivalent to the `styled()` function in emotion and styled-components.
Interpolations or arguments that are functions called by `styled` receive the `theme` from an upper `ThemeProvider`.
```tsx
import * as React from 'react';
import { ThemeProvider } from '@emotion/react';
import { styled } from '@mui/system';
import { Button } from '@mui/base/Button';
const theme = {
palette: {
primary: 'green',
text: '#fff',
},
};
const GitHubButton = styled(Button)(
({ theme }) => `
background-color: ${theme.palette.primary /* => 'green' */};
${/* ... the rest of the styles */}
`,
);
export default function App() {
return (
<ThemeProvider theme={theme}>
<GitHubButton>Create Repository</GitHubButton>
</ThemeProvider>
);
}
```
Most of the demos in the Base UI docs are styled with MUI System in this way.
You can inspect the `theme` object used on this site in your browser console, or explore the default structure in the Material UI [Default theme](/material-ui/customization/default-theme/) documentation.
The demos below show how to create the Primer button using MUI System:
#### Button Component with MUI System
```tsx
import * as React from 'react';
import { Button } from '@mui/base/Button';
import { styled } from '@mui/system';
const GitHubButton = styled(Button)(
({ theme }) => `
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
${/* ... the rest of the styles */}
`,
);
export default function App() {
return (
<GitHubButton>Create Repository</GitHubButton>
);
}
```
#### useButton hook with MUI System
```tsx
import * as React from 'react';
import { useButton } from '@mui/base/useButton';
import { styled } from '@mui/system';
const GitHubButton = styled('button')(
({ theme }) => `
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
${/* ... the rest of the styles */}
`,
);
export default function App() {
const { getRootProps } = useButton(/* props*/);
return (
<GitHubButton type="button" {...getRootProps()}>
Create Repository
</GitHubButton>
);
}
```
### Using the sx prop
MUI System supports the [`sx` prop](/system/getting-started/the-sx-prop/), which provides a quick way to apply ad-hoc styles using theme-aware values to any component created with `styled`.
```tsx
const GitHubButton = styled(Button)(
({ theme }) => `
background-color: ${theme.palette.mode === 'dark' ? '#238636' : '#1f883d'};
margin: 0;
`,
);
export default function App() {
return (
<GitHubButton sx={{ m: 2 /* => margin: 16px */ }}>
Create Repository
</GitHubButton>
);
}
```
The demo below shows how to build the Primer button using MUI System along with the `sx` prop:
{{"demo": "BaseButtonMuiSystem.js", "defaultCodeOpen": false}}
Read the [MUI System Usage](/system/getting-started/usage/) doc for further details.
| 624 |
0 | petrpan-code/mui/material-ui/docs/data/base/getting-started | petrpan-code/mui/material-ui/docs/data/base/getting-started/usage/usage.md | # Usage
<p class="description">Learn the basics of working with Base UI components.</p>
## Responsive meta tag
Base UI is a _mobile-first_ component library—we write code for mobile devices first, and then scale up the components as necessary using CSS media queries.
To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your `<head>` element:
```html
<meta name="viewport" content="initial-scale=1, width=device-width" />
```
## Shared props
Base components are self-supporting and fully functional in isolation.
Each component has its own unique API, but all _non-utility_ components accept the following shared props:
### slots
The `slots` prop is an object that lets you override any interior subcomponents—known as **slots**—of the base component itself.
:::info
Each component contains a root slot, and other appropriate slots based on the nature of the component.
For example, the Base UI Badge contains two slots:
- `root`: the container element that wraps the children.
- `badge`: the badge element itself.
:::
You can use the `slots` prop to override default slots with either custom components or HTML elements.
For example, the Base UI Badge component renders a `<span>` by default.
The code snippet below shows how to override this by assigning a `<div>` to the root slot:
```jsx
<Badge slots={{ root: 'div' }} />
```
### slotProps
The `slotProps` prop is an object that contains the props for all slots within a component.
You can use it to define additional custom props for a component's interior elements.
For example, the code snippet below shows how to add a custom CSS class to the badge slot of the Base UI Badge component:
```jsx
<Badge slotProps={{ badge: { className: 'my-badge' } }} />
```
All additional props placed on the primary component are also propagated into the root slot (just as if they were placed in `slotProps.root`).
These two examples are equivalent:
```jsx
<Badge id="badge1">
```
```jsx
<Badge slotProps={{ root: { id: 'badge1' } }}>
```
:::warning
If both `slotProps.root` and additional props have the same keys but different values, the `slotProps.root` props will take precedence.
This does not apply to classes or the `style` prop—they will be merged instead.
:::
### Best practices
If you are customizing a component like the [Button](/base-ui/react-button/) that only has a root slot, you may prefer to use the more succinct `component` prop instead of `slots`.
Overriding with `component` lets you apply the attributes of that element directly to the root.
For instance, if you replace the Button root with an `<li>` tag, you can add the `<li>` attribute `value` directly to the component.
If you did the same with `slots.root`, you would need to place this attribute on the `slotProps.root` object in order to avoid a TypeScript error.
## Components vs. hooks
Base UI includes two kinds of building blocks: **components** and **hooks**.
:::info
Hooks encapsulate _logic_; components provide _structure_.
:::
Many Base components are implemented with the help of hooks.
(Visit the [React documentation on hooks](https://legacy.reactjs.org/docs/hooks-intro.html) to get up to speed on this concept.)
You can use components or hooks—or a combination thereof—when building custom components.
In general, we recommend that you begin building with the component, and if you find that you are too limited by the customization options available, then consider refactoring your component to use the corresponding hook instead.
Each option has its own trade-offs:
### Components
#### Pros
- Usually require less code to implement
- Equipped with accessibility features by default
#### Cons
- Less control over the structure of the rendered HTML
### Hooks
#### Pros
- Complete control over rendered HTML structure
#### Cons
- Usually require more code to implement
- Extra steps necessary to make the resulting component accessible
Details on usage of hooks can be found in their corresponding component docs.
| 625 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/next-js-app-router/next-js-app-router.md | # Next.js App Router
<p class="description">Learn how to use Base UI with the Next.js App Router.</p>
## Example
Starting fresh on a new App Router-based project?
Jump right into the code with [this example: Base UI - Next.js App Router with Tailwind CSS in TypeScript](https://github.com/mui/material-ui/tree/master/examples/base-ui-nextjs-tailwind-ts).
## Next.js and React Server Components
The Next.js App Router implements React Server Components, [an upcoming feature for React](https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md).
To support the App Router, the components and hooks from Base UI that need access to browser APIs are exported with the `"use client"` directive.
:::warning
React Server Components should not be conflated with the concept of server-side rendering (SSR).
So-called Client Components are still server-rendered to HTML.
For more details, see [this explanation](https://github.com/reactwg/server-components/discussions/4) of Client Components and SSR from the React Working Group.
:::
## Setting up Base UI with the App Router
Base UI gives you the freedom to choose your own styling solution, so setting up a Next.js App Router project largely depends on what you choose.
This guide covers Tailwind CSS, Emotion, and other CSS-in-JS solutions like styled-components.
### Tailwind CSS
Follow the [Tailwind CSS guide on working with Next.js](https://tailwindcss.com/docs/guides/nextjs), and be sure to add the `app` directory and other directories to `tailwind.config.js`, as shown below:
```js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
'./src/components/**/*.{js,ts,jsx,tsx,mdx}'
// or if not using the `src` directory:
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
};
```
Refer to this [example repo](https://github.com/mui/material-ui/tree/master/examples/base-ui-nextjs-tailwind-ts) for a full working demo of a Next.js 13 app using Base UI and Tailwind CSS.
### Emotion
If you're using Emotion, or something Emotion-based like MUI System, create a custom `ThemeRegistry` component that combines the Emotion `CacheProvider`, the Material UI `ThemeProvider`, and the `useServerInsertedHTML` hook from `next/navigation` as follows:
```tsx
// app/ThemeRegistry.tsx
'use client';
import createCache from '@emotion/cache';
import { useServerInsertedHTML } from 'next/navigation';
import { CacheProvider, ThemeProvider } from '@emotion/react';
import theme from '/path/to/your/theme';
// This implementation is from emotion-js
// https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319747902
export default function ThemeRegistry(props) {
const { options, children } = props;
const [{ cache, flush }] = React.useState(() => {
const cache = createCache(options);
cache.compat = true;
const prevInsert = cache.insert;
let inserted: string[] = [];
cache.insert = (...args) => {
const serialized = args[1];
if (cache.inserted[serialized.name] === undefined) {
inserted.push(serialized.name);
}
return prevInsert(...args);
};
const flush = () => {
const prevInserted = inserted;
inserted = [];
return prevInserted;
};
return { cache, flush };
});
useServerInsertedHTML(() => {
const names = flush();
if (names.length === 0) {
return null;
}
let styles = '';
for (const name of names) {
styles += cache.inserted[name];
}
return (
<style
key={cache.key}
data-emotion={`${cache.key} ${names.join(' ')}`}
dangerouslySetInnerHTML={{
__html: styles,
}}
/>
);
});
return (
<CacheProvider value={cache}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</CacheProvider>
);
}
// app/layout.js
export default function RootLayout(props) {
const { children } = props;
return (
<html lang="en">
<body>
<ThemeRegistry options={{ key: 'mui' }}>{children}</ThemeRegistry>
</body>
</html>
);
}
```
If you need to further override theme styles (e.g. using CSS modules), Emotion provides the `prepend: true` option for `createCache` to reverse the injection order, so custom styles can override the theme without using `!important`.
Currently, `prepend` does not work reliably with the App Router, but you can work around it by wrapping Emotion styles in a CSS `@layer` with a modification to the snippet above:
```diff
useServerInsertedHTML(() => {
const names = flush();
if (names.length === 0) {
return null;
}
let styles = '';
for (const name of names) {
styles += cache.inserted[name];
}
return (
<style
key={cache.key}
data-emotion={`${cache.key} ${names.join(' ')}`}
dangerouslySetInnerHTML={{
- __html: styles,
+ __html: options.prepend ? `@layer emotion {${styles}}` : styles,
}}
/>
);
});
```
### Other CSS-in-JS libraries
To use Next.js with Base UI and styled-components or other CSS-in-JS solutions, follow the [Next.js doc on CSS-in-JS](https://nextjs.org/docs/app/building-your-application/styling/css-in-js).
## Customization
### Using callbacks for slot props
A common customization method in Base UI is to pass a callback to slots in `slotProps` in order to apply dynamic props. For example, you might want to change the background color by applying a different class when a Button is disabled:
```tsx
// page.tsx
export default function Page() {
return (
<React.Fragment>
{/* Next.js won't render this button without 'use-client'*/}
<Button
slotProps={{
root: (ownerState: ButtonOwnerState) => ({
className: ownerState.disabled ? 'bg-gray-400' : 'bg-blue-400',
}),
}}
>
Submit
</Button>
{/* Next.js can render this */}
<Button
slotProps={{
root: {
className: 'bg-gray-400',
},
}}
>
Return
</Button>
</React.Fragment>
);
}
```
Unfortunately, **this does not work in a Server Component** since function props are [non-serializable](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#passing-props-from-server-to-client-components-serialization).
Instead, the Next.js team recommend moving components like these ["down the tree"](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#moving-client-components-down-the-tree) to avoid this issue and improve overall performance.
| 626 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingInternalSlot.js | import * as React from 'react';
import { Select } from '@mui/base/Select';
import { Option } from '@mui/base/Option';
export default function OverridingInternalSlot() {
return (
<Select slots={{ listbox: 'ol' }} defaultValue="First option">
<Option value="First option">First option</Option>
<Option value="Second option">Second option</Option>
</Select>
);
}
| 627 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingInternalSlot.tsx | import * as React from 'react';
import { Select } from '@mui/base/Select';
import { Option } from '@mui/base/Option';
export default function OverridingInternalSlot() {
return (
<Select slots={{ listbox: 'ol' }} defaultValue="First option">
<Option value="First option">First option</Option>
<Option value="Second option">Second option</Option>
</Select>
);
}
| 628 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingInternalSlot.tsx.preview | <Select slots={{ listbox: 'ol' }} defaultValue="First option">
<Option value="First option">First option</Option>
<Option value="Second option">Second option</Option>
</Select> | 629 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingRootSlot.js | import * as React from 'react';
import { Button } from '@mui/base/Button';
export default function OverridingRootSlot() {
return <Button slots={{ root: 'div' }}>Button</Button>;
}
| 630 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingRootSlot.tsx | import * as React from 'react';
import { Button } from '@mui/base/Button';
export default function OverridingRootSlot() {
return <Button slots={{ root: 'div' }}>Button</Button>;
}
| 631 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/OverridingRootSlot.tsx.preview | <Button slots={{ root: 'div' }}>Button</Button> | 632 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/overriding-component-structure/overriding-component-structure.md | # Overriding component structure
<p class="description">Learn how to override the default DOM structure of Base UI components.</p>
Base UI components are designed to suit the widest possible range of use cases, but you may occasionally need to change how a component's structure is rendered in the DOM.
To understand how to do this, it helps to have an accurate mental model of MUI components.
## The mental model
A component's structure is determined by the elements that fill that component's **slots**.
Slots are most commonly filled by HTML tags, but may also be filled by React components.
All components contain a root slot that defines their primary node in the DOM tree; more complex components also contain additional interior slots named after the elements they represent.
All _non-utility_ Base UI components accept [the `slots` prop](#the-slots-prop) for overriding their rendered HTML structure.
Additionally, you can pass custom props to [interior slots](#interior-slots) using `slotProps`.
## The root slot
The root slot represents the component's outermost element.
For simpler components, the root slot is often filled by the native HTML element that the component is intended to replace.
For example, the [Button's](/base-ui/react-button/) root slot is a `<button>` element.
This component _only_ has a root slot; more complex components may have additional interior slots.
## Interior slots
Complex components are composed of one or more interior slots in addition to the root.
These slots are often (but not necessarily) nested within the root.
For example, the [Slider](/base-ui/react-slider/) is composed of a root `<span>` that houses several interior slots named for the elements they represent: track, thumb, rail, and so on.
### The slots prop
Use the `slots` prop to replace the elements in a component's slots, including the root.
The example below shows how to override the listbox slot in the [Select](/base-ui/react-select/) component—a `<ul>` by default—with an `<ol>`:
{{"demo": "OverridingInternalSlot.js"}}
### The slotProps prop
The `slotProps` prop is an object that contains the props for all slots within a component.
You can use it to define additional custom props to pass to a component's interior slots.
For example, the code snippet below shows how to add a custom CSS class to the badge slot of the [Badge](/base-ui/react-badge/) component:
```jsx
<Badge slotProps={{ badge: { className: 'my-badge' } }} />
```
All additional props placed on the primary component are also propagated into the root slot (just as if they were placed in `slotProps.root`).
These two examples are equivalent:
```jsx
<Badge id="badge1">
```
```jsx
<Badge slotProps={{ root: { id: 'badge1' } }}>
```
:::warning
If both `slotProps.root` and additional props have the same keys but different values, the `slotProps.root` props will take precedence.
This does not apply to classes or the `style` prop—they will be merged instead.
:::
## Best practices
Be mindful of your rendered DOM structure when overriding the slots of more complex components.
You can easily break the rules of semantic and accessible HTML if you deviate too far from the default structure—for instance, by unintentionally nesting block-level elements inside of inline elements.
| 633 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/working-with-tailwind-css/PlayerFinal.js | import * as React from 'react';
export default function PlayerFinal() {
return (
<iframe
title="codesandbox"
src="https://codesandbox.io/embed/working-with-tailwind-css-dhmf8w?hidenavigation=1&fontsize=14&view=preview"
style={{
width: '100%',
height: 400,
border: 0,
}}
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
/>
);
}
| 634 |
0 | petrpan-code/mui/material-ui/docs/data/base/guides | petrpan-code/mui/material-ui/docs/data/base/guides/working-with-tailwind-css/working-with-tailwind-css.md | # Working with Tailwind CSS
<p class="description">Learn how to style Base UI components with Tailwind CSS.</p>
## Getting started
The goal of this guide is to teach you how to style Base UI components using Tailwind CSS while building an interactive and accessible app.
### Prerequisites
This guide assumes that you have a basic working knowledge of the following:
- Tailwind CSS
- TypeScript in React
- building React UI components
We will not be covering these topics in detail here.
The end result of this guide is an interactive media player interface.
Here's what it will look like in the end:
{{"demo": "PlayerFinal.js", "hideToolbar": true, "bg": true}}
:::info
All credits go to the Tailwind Labs team for designing this component, found on the [Tailwind CSS website](https://tailwindcss.com/).
:::
## Setting up the project
We'll use [`create-react-app` with TypeScript](https://create-react-app.dev/docs/adding-typescript/#installation) for this guide.
After you have created the project, follow the instructions given on the [Tailwind CSS installation page](https://tailwindcss.com/docs/guides/create-react-app) in order to configure `tailwind`.
Next, install `@mui/base` in the project:
```bash
npm install @mui/base
```
## Adding the player markup
Now, create a file called `Player.tsx` and add the markup below, which includes Tailwind CSS classes:
**Player.tsx**
```tsx
import * as React from 'react';
const Player = React.forwardRef(function Player(
props: { className?: string },
ref: React.ForwardedRef<HTMLDivElement>,
) {
const { className = '', ...other } = props;
return (
<div
className={`max-w-[600px] max-h-[240px] m-auto ${className}`}
{...other}
ref={ref}
>
<div className="bg-white border-slate-100 dark:bg-slate-800 dark:border-slate-500 border-b rounded-t-xl p-4 pb-6 sm:p-10 sm:pb-8 lg:p-6 xl:p-10 xl:pb-8 space-y-6 sm:space-y-8 lg:space-y-6 xl:space-y-8">
<div className="flex items-center space-x-4">
<img
src="https://mui.com/static/base-ui/with-tailwind-css/full-stack-radio.png"
alt=""
width="88"
height="88"
className="flex-none rounded-lg bg-slate-100"
loading="lazy"
/>
<div className="min-w-0 flex-auto space-y-1 font-semibold">
<p className="text-cyan-500 dark:text-cyan-400 text-sm leading-6">
<abbr title="Episode">Ep.</abbr> 128
</p>
<h2 className="text-slate-500 dark:text-slate-400 text-sm leading-6 truncate">
Scaling CSS at Heroku with Utility Classes
</h2>
<p className="text-slate-900 dark:text-slate-50 text-lg">
Full Stack Radio
</p>
</div>
</div>
<div className="space-y-2">
<div className="relative">
<div className="bg-slate-100 dark:bg-slate-700 rounded-full overflow-hidden">
<div
className="bg-cyan-500 dark:bg-cyan-400 w-1/2 h-2"
role="progressbar"
aria-label="music progress"
aria-valuenow={1456}
aria-valuemin={0}
aria-valuemax={4550}
></div>
</div>
<div className="ring-cyan-500 dark:ring-cyan-400 ring-2 absolute left-1/2 top-1/2 w-4 h-4 -mt-2 -ml-2 flex items-center justify-center bg-white rounded-full shadow">
<div className="w-1.5 h-1.5 bg-cyan-500 dark:bg-cyan-400 rounded-full ring-1 ring-inset ring-slate-900/5"></div>
</div>
</div>
<div className="flex justify-between text-sm leading-6 font-medium tabular-nums">
<div className="text-cyan-500 dark:text-slate-100">24:16</div>
<div className="text-slate-500 dark:text-slate-400">75:50</div>
</div>
</div>
</div>
<div className="bg-slate-50 text-slate-500 dark:bg-slate-600 dark:text-slate-200 rounded-b-xl flex items-center">
<div className="flex-auto flex items-center justify-evenly">
<button type="button" aria-label="Add to favorites">
<svg width="24" height="24">
<path
d="M7 6.931C7 5.865 7.853 5 8.905 5h6.19C16.147 5 17 5.865 17 6.931V19l-5-4-5 4V6.931Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
<button
type="button"
className="hidden sm:block lg:hidden xl:block"
aria-label="Previous"
>
<svg width="24" height="24" fill="none">
<path
d="m10 12 8-6v12l-8-6Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M6 6v12"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
<button type="button" aria-label="Rewind 10 seconds">
<svg width="24" height="24" fill="none">
<path
d="M6.492 16.95c2.861 2.733 7.5 2.733 10.362 0 2.861-2.734 2.861-7.166 0-9.9-2.862-2.733-7.501-2.733-10.362 0A7.096 7.096 0 0 0 5.5 8.226"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M5 5v3.111c0 .491.398.889.889.889H9"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
</div>
<button
type="button"
className="bg-white text-slate-900 dark:bg-slate-100 dark:text-slate-700 flex-none -my-2 mx-auto w-20 h-20 rounded-full ring-1 ring-slate-900/5 shadow-md flex items-center justify-center"
aria-label="Pause"
>
<svg width="30" height="32" fill="currentColor">
<rect x="6" y="4" width="4" height="24" rx="2" />
<rect x="20" y="4" width="4" height="24" rx="2" />
</svg>
</button>
<div className="flex-auto flex items-center justify-evenly">
<button type="button" aria-label="Skip 10 seconds">
<svg width="24" height="24" fill="none">
<path
d="M17.509 16.95c-2.862 2.733-7.501 2.733-10.363 0-2.861-2.734-2.861-7.166 0-9.9 2.862-2.733 7.501-2.733 10.363 0 .38.365.711.759.991 1.176"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M19 5v3.111c0 .491-.398.889-.889.889H15"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
<button
type="button"
className="hidden sm:block lg:hidden xl:block"
aria-label="Next"
>
<svg width="24" height="24" fill="none">
<path
d="M14 12 6 6v12l8-6Z"
fill="currentColor"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M18 6v12"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
<button
type="button"
className="rounded-lg text-xs leading-6 font-semibold px-2 ring-2 ring-inset ring-slate-500 text-slate-500 dark:text-slate-100 dark:ring-0 dark:bg-slate-500"
>
1x
</button>
</div>
</div>
</div>
);
});
export default Player;
```
Next, add the `Player` component to the `App.tsx` file.
**App.tsx**
```tsx
import * as React from 'react';
import Player from './Player';
function App() {
return <Player />;
}
export default App;
```
You should now see the player rendered on the page, but the component is not yet interactive—that's what we'll cover in the next step.
## Adding an interactive slider component
### Create the Slider component
Let's start by giving life to the slider with the Slider component from Base UI.
First, create a new file called `Slider.tsx`.
Copy and paste the code below into the file:
**Slider.tsx**
```tsx
import * as React from 'react';
import {
Slider as BaseSlider,
SliderThumbSlotProps,
SliderProps,
} from '@mui/base/Slider';
const Slider = React.forwardRef(function Slider(
props: SliderProps,
ref: React.ForwardedRef<HTMLSpanElement>,
) {
return (
<BaseSlider
{...props}
ref={ref}
slotProps={{
thumb: {
className:
'ring-cyan-500 dark:ring-cyan-400 ring-2 w-4 h-4 -mt-1 -ml-2 flex items-center justify-center bg-white rounded-full shadow absolute',
},
root: { className: 'w-full relative inline-block h-2 cursor-pointer' },
rail: {
className:
'bg-slate-100 dark:bg-slate-700 h-2 w-full rounded-full block absolute',
},
track: {
className: 'bg-cyan-500 dark:bg-cyan-400 h-2 absolute rounded-full',
},
}}
/>
);
});
export default Slider;
```
To assign specific Tailwind CSS utility classes for each part of the component, we're using `slotProps`.
Most of them were copied from the original markup with small adjustments now that it is interactive.
### Add the slider to the player
Let's add the `Slider` into the `Player` component now:
**Player.tsx**
```diff
--- a/src/Player.tsx
+++ b/src/Player.tsx
@@ -1,4 +1,5 @@
import * as React from 'react';
+import Slider from './Slider';
const Player = React.forwardRef(function Player(props: { className?: string }, ref: React.ForwardedRef<HTMLDivElement>) {
const { className = '', ...other } = props;
@@ -21,12 +22,7 @@ const Player = React.forwardRef(function Player(props: { className?: string }, r
</div>
<div className="space-y-2">
<div className="relative">
- <div className="bg-slate-100 dark:bg-slate-700 rounded-full overflow-hidden">
- <div className="bg-cyan-500 dark:bg-cyan-400 w-1/2 h-2" role="progressbar" aria-label="music progress" aria-valuenow={1456} aria-valuemin={0} aria-valuemax={4550}></div>
- </div>
- <div className="ring-cyan-500 dark:ring-cyan-400 ring-2 absolute left-1/2 top-1/2 w-4 h-4 -mt-2 -ml-2 flex items-center justify-center bg-white rounded-full shadow">
- <div className="w-1.5 h-1.5 bg-cyan-500 dark:bg-cyan-400 rounded-full ring-1 ring-inset ring-slate-900/5"></div>
- </div>
+ <Slider step={50} defaultValue={1456} max={4550} min={0} />
</div>
<div className="flex justify-between text-sm leading-6 font-medium tabular-nums">
<div className="text-cyan-500 dark:text-slate-100">24:16</div>
```
You should see this:
<img src="/static/base-ui/with-tailwind-css/player-slider.png" alt="Screenshot of the media player used as example in the guide, designed by the Tailwind Labs team" style="margin-top: 8px; margin-bottom: 8px;" width="1490" height="760" />
### Customize the slider thumb
Even though the slider is now interactive, it still does not look exactly like the original design.
This is because we haven't defined the element that represents the dot inside the thumb.
To do this, it's not enough to just use classes for the thumb—we need also to render a custom component that gets passed in the `slots` prop of the `Slider`:
**Slider.tsx**
```diff
--- a/src/Slider.tsx
+++ b/src/Slider.tsx
@@ -1,6 +1,17 @@
import * as React from 'react';
import { Slider as BaseSlider, SliderThumbSlotProps, SliderProps } from '@mui/base/Slider';
+const Thumb = React.forwardRef(function Thumb(
+ props: SliderThumbSlotProps,
+ ref: React.ForwardedRef<HTMLSpanElement>,
+) {
+ const { ownerState, className = '', children, ...other } = props;
+ return (<span className={`${className} ring-cyan-500 dark:ring-cyan-400 ring-2 w-4 h-4 -mt-1 -ml-2 flex items-center justify-center bg-white rounded-full shadow absolute`} {...other} ref={ref}>
+ <span className="w-1.5 h-1.5 bg-cyan-500 dark:bg-cyan-400 rounded-full ring-1 ring-inset ring-slate-900/5"></span>
+ {children}
+ </span>);
+});
+
const Slider = React.forwardRef(function Slider(
props: SliderProps,
ref: React.ForwardedRef<HTMLSpanElement>,
@@ -8,9 +19,11 @@ const Slider = React.forwardRef(function Slider(
return (<BaseSlider
{...props}
ref={ref}
+ slots={{
+ thumb: Thumb,
+ }}
slotProps={{
root: { className: 'w-full relative inline-block h-2 cursor-pointer' },
- thumb: { className: 'ring-cyan-500 dark:ring-cyan-400 ring-2 w-4 h-4 -mt-1 -ml-2 flex items-center justify-center bg-white rounded-full shadow absolute' },
rail: { className: 'bg-slate-100 dark:bg-slate-700 h-2 w-full rounded-full block absolute' },
track: { className: 'bg-cyan-500 dark:bg-cyan-400 h-2 absolute rounded-full' }
}}
```
After refreshing the page, you should see the thumb looking identical to the design now.
The code above creates a custom component with all the classes and props necessary to serve as the thumb.
Since we want to have an additional dot inside the thumb, we need to add new element in the markup of the thumb: a `<span>`.
Note that after the thumb, we are still rendering the `children` passed via props.
This is important because the `children` in this case contain a hidden `<input>` element which makes the thumb accessible.
This is just one example, but this pattern of building custom components for each slot is possible with all Base UI components.
:::warning
When building custom components for the slots, always propagate the props sent from the owner component on the root element.
This is necessary because the props contain event handlers and aria properties required to make the component accessible.
:::
Additionally, each of the slots receives an `ownerState` object, which contains the props and state of the owner component.
This is useful if you want to style the component based on some internal state.
## Adding a custom focus selector to the buttons
To finish this guide off, let's see how you can add custom styles based on a component's internal state.
We'll create a custom Button component that uses the `focusVisible` state from the Base UI Button to apply a cyan ring around it.
This is what it'll look like:
<img src="/static/base-ui/with-tailwind-css/player-buttons.png" alt="Screenshot of a button used as example in the guide, designed by the Tailwind Labs team" style="margin-top: 8px; margin-bottom: 8px;" width="1490" height="760" />
Create a `Button.tsx` file and copy the following code:
**Button.tsx**
```tsx
import * as React from 'react';
import {
Button as BaseButton,
ButtonOwnerState,
ButtonProps,
} from '@mui/base/Button';
const Button = React.forwardRef(function Button(
props: ButtonProps,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
return (
<BaseButton
{...props}
slotProps={{
root: (state: ButtonOwnerState) => ({
className: `hover:text-cyan-500 transition-colors ${
state.focusVisible ? 'outline-0 ring-2 ring-cyan-500' : ''
}`,
}),
}}
ref={ref}
/>
);
});
export default Button;
```
Note that we're using a callback for the `root` element inside `slotProps`.
This allows us to conditionally apply utility classes if `focusVisible` is true.
Now, let's replace all buttons in the initial markup with the new custom `Button` component.
**Player.tsx**
```diff
--- a/src/Player.tsx
+++ b/src/Player.tsx
@@ -1,4 +1,5 @@
import * as React from 'react';
+import Button from './Button';
import Slider from './Slider';
const Player = React.forwardRef(function Player(props: { className?: string }, ref: React.ForwardedRef<HTMLDivElement>) {
@@ -32,46 +33,46 @@ const Player = React.forwardRef(function Player(props: { className?: string }, r
</div>
<div className="bg-slate-50 text-slate-500 dark:bg-slate-600 dark:text-slate-200 rounded-b-xl flex items-center"> <div className="flex-auto flex items-center justify-evenly">
- <button type="button" aria-label="Add to favorites">
+ <Button aria-label="Add to favorites">
<svg width="24" height="24">
<path d="M7 6.931C7 5.865 7.853 5 8.905 5h6.19C16.147 5 17 5.865 17 6.931V19l-5-4-5 4V6.931Z" fill="currentColor" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
- </button>
- <button type="button" className="hidden sm:block lg:hidden xl:block" aria-label="Previous">
+ </Button>
+ <Button className="hidden sm:block lg:hidden xl:block" aria-label="Previous">
<svg width="24" height="24" fill="none">
<path d="m10 12 8-6v12l-8-6Z" fill="currentColor" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
<path d="M6 6v12" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
- </button>
- <button type="button" aria-label="Rewind 10 seconds">
+ </Button>
+ <Button aria-label="Rewind 10 seconds">
<svg width="24" height="24" fill="none">
<path d="M6.492 16.95c2.861 2.733 7.5 2.733 10.362 0 2.861-2.734 2.861-7.166 0-9.9-2.862-2.733-7.501-2.733-10.362 0A7.096 7.096 0 0 0 5.5 8.226" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
<path d="M5 5v3.111c0 .491.398.889.889.889H9" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
- </button>
+ </Button>
</div>
- <button type="button" className="bg-white text-slate-900 dark:bg-slate-100 dark:text-slate-700 flex-none -my-2 mx-auto w-20 h-20 rounded-full ring-1 ring-slate-900/5 shadow-md flex items-center justify-center" aria-label="Pause">
+ <Button className="bg-white text-slate-900 dark:bg-slate-100 dark:text-slate-700 flex-none -my-2 mx-auto w-20 h-20 rounded-full border-2 border-slate-900/5 shadow-md flex items-center justify-center" aria-label="Pause">
<svg width="30" height="32" fill="currentColor">
<rect x="6" y="4" width="4" height="24" rx="2" />
<rect x="20" y="4" width="4" height="24" rx="2" />
</svg>
- </button>
+ </Button>
<div className="flex-auto flex items-center justify-evenly">
- <button type="button" aria-label="Skip 10 seconds">
+ <Button aria-label="Skip 10 seconds">
<svg width="24" height="24" fill="none">
<path d="M17.509 16.95c-2.862 2.733-7.501 2.733-10.363 0-2.861-2.734-2.861-7.166 0-9.9 2.862-2.733 7.501-2.733 10.363 0 .38.365.711.759.991 1.176" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
<path d="M19 5v3.111c0 .491-.398.889-.889.889H15" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
- </button>
- <button type="button" className="hidden sm:block lg:hidden xl:block" aria-label="Next">
+ </Button>
+ <Button className="hidden sm:block lg:hidden xl:block" aria-label="Next">
<svg width="24" height="24" fill="none">
<path d="M14 12 6 6v12l8-6Z" fill="currentColor" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
<path d="M18 6v12" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
- </button>
- <button type="button" className="rounded-lg text-xs leading-6 font-semibold px-2 ring-2 ring-inset ring-slate-500 text-slate-500 dark:text-slate-100 dark:ring-0 dark:bg-slate-500">
+ </Button>
+ <Button className="rounded-lg text-xs leading-6 font-semibold px-2 border-2 border-slate-500 text-slate-500 dark:text-slate-100 dark:ring-0 dark:bg-slate-500 hover:ring-cyan-500">
1x
- </button>
+ </Button>
</div>
</div>
</div>
```
Some classes were slightly changed on some buttons so we have a consistent focus indicator.
## What we learned
These are the things we covered in this guide:
✅ How to use Tailwind CSS utility classes to style Base UI components, using the `slotProps` prop for targeting specific slots within the component.\
✅ How to create custom components for specific slots in more complex customization scenarios.
We used the `component` prop to pass them into the parent component.\
✅ How to apply conditional styling based on the owner component's state using a callback as value for the `slotProps` prop.
Get all the code used in this guide in the [Base UI with Tailwind CSS](https://codesandbox.io/s/working-with-tailwind-css-dhmf8w) example project.
| 635 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/docs-infra/pages.ts | import type { MuiPage } from 'docs/src/MuiPage';
const pages: readonly MuiPage[] = [
{
pathname: '/experiments/docs/writing',
title: 'Writing',
children: [
{ pathname: '/experiments/docs/headers' },
{ pathname: '/experiments/docs/markdown' },
],
},
{
pathname: '/experiments/docs/components',
children: [
{ pathname: '/experiments/docs/callouts' },
{ pathname: '/experiments/docs/codeblock' },
{ pathname: '/experiments/docs/demos' },
{ pathname: '/experiments/docs/data-grid-premium', title: 'API DataGridPremium' },
],
},
{
pathname: '/experiments/docs/main-parent',
title: 'Main parent',
children: [
{
pathname: '/experiments/docs/first-level-child-1',
title: 'First-level child 1',
},
{
pathname: '/experiments/docs/first-level-child-2',
title: 'First-level child 2',
children: [
{ pathname: '/experiments/docs/second-level-child', title: 'Second-level child' },
{ pathname: '/experiments/docs/subheader-divider', subheader: 'Subheader divider' },
{
pathname: '/experiments/docs/api/data-grid-group',
title: 'Second-level child parent',
children: [
{ pathname: '/experiments/docs/third-level-child', title: 'Third-level child' },
{
pathname: '/experiments/docs/api/data-grid-components-group',
subheader: 'Subheader divider',
children: [
{
pathname: '/experiments/docs/api/data-grid/data-grid',
title: 'Fourth-level child',
},
],
},
],
},
],
},
],
},
{
pathname: '/x/react-data-grid-group',
title: 'Data Grid',
children: [
{ pathname: '/x/react-data-grid', title: 'Overview' },
{ pathname: '/x/react-data-grid/demo' },
{ pathname: '/x/react-data-grid/getting-started' },
{ pathname: '/x/react-data-grid/layout' },
{
pathname: '/x/react-data-grid/columns',
children: [
{ pathname: '/x/react-data-grid/column-definition' },
{ pathname: '/x/react-data-grid/column-dimensions' },
{ pathname: '/x/react-data-grid/column-visibility' },
{ pathname: '/x/react-data-grid/column-header' },
{ pathname: '/x/react-data-grid/column-menu' },
{ pathname: '/x/react-data-grid/column-spanning' },
{ pathname: '/x/react-data-grid/column-groups' },
{ pathname: '/x/react-data-grid/column-ordering', plan: 'pro' },
{ pathname: '/x/react-data-grid/column-pinning', plan: 'pro' },
],
},
{
pathname: '/x/react-data-grid/rows',
children: [
{ pathname: '/x/react-data-grid/row-definition' },
{ pathname: '/x/react-data-grid/row-updates' },
{ pathname: '/x/react-data-grid/row-height' },
{ pathname: '/x/react-data-grid/row-spanning', title: 'Row spanning 🚧' },
{ pathname: '/x/react-data-grid/master-detail', plan: 'pro' },
{ pathname: '/x/react-data-grid/row-ordering', plan: 'pro' },
{ pathname: '/x/react-data-grid/row-pinning', plan: 'pro' },
{ pathname: '/x/react-data-grid/row-recipes', title: 'Recipes' },
],
},
{ pathname: '/x/react-data-grid/editing' },
{ pathname: '/x/react-data-grid/clipboard', title: 'Copy and paste', newFeature: true },
{ pathname: '/x/react-data-grid/performance' },
{
pathname: '/x/react-data-grid-group-pivot',
title: 'Group & Pivot',
children: [
{ pathname: '/x/react-data-grid/tree-data', plan: 'pro' },
{ pathname: '/x/react-data-grid/row-grouping', plan: 'premium' },
{ pathname: '/x/react-data-grid/aggregation', title: 'Aggregation', plan: 'premium' },
{ pathname: '/x/react-data-grid/pivoting', title: 'Pivoting 🚧', plan: 'premium' },
],
},
{
title: 'Recipes',
pathname: '/x/react-data-grid/recipes',
children: [
{ pathname: '/x/react-data-grid/recipes-editing', title: 'Editing' },
{ pathname: '/x/react-data-grid/recipes-row-grouping', title: 'Row grouping' },
],
},
{
pathname: '/x/api/data-grid-group',
title: 'API Reference',
children: [
{ pathname: '/x/api/data-grid', title: 'Index' },
{
pathname: '/x/api/data-grid-interfaces-group',
subheader: 'Interfaces',
children: [
{ pathname: '/x/api/data-grid/grid-api', title: 'GridApi' },
{ pathname: '/x/api/data-grid/grid-cell-params', title: 'GridCellParams' },
{ pathname: '/x/api/data-grid/grid-col-def', title: 'GridColDef' },
{
pathname: '/x/api/data-grid/grid-single-select-col-def',
title: 'GridSingleSelectColDef',
},
{ pathname: '/x/api/data-grid/grid-actions-col-def', title: 'GridActionsColDef' },
{
pathname: '/x/api/data-grid/grid-export-state-params',
title: 'GridExportStateParams',
},
{ pathname: '/x/api/data-grid/grid-filter-item', title: 'GridFilterItem' },
{ pathname: '/x/api/data-grid/grid-filter-model', title: 'GridFilterModel' },
{ pathname: '/x/api/data-grid/grid-filter-operator', title: 'GridFilterOperator' },
{
pathname: '/x/api/data-grid/grid-row-class-name-params',
title: 'GridRowClassNameParams',
},
{ pathname: '/x/api/data-grid/grid-row-params', title: 'GridRowParams' },
{
pathname: '/x/api/data-grid/grid-row-spacing-params',
title: 'GridRowSpacingParams',
},
{
pathname: '/x/api/data-grid/grid-aggregation-function',
title: 'GridAggregationFunction',
},
{
pathname: '/x/api/data-grid/grid-csv-export-options',
title: 'GridCsvExportOptions',
},
{
pathname: '/x/api/data-grid/grid-print-export-options',
title: 'GridPrintExportOptions',
},
{
pathname: '/x/api/data-grid/grid-excel-export-options',
title: 'GridExcelExportOptions',
},
],
},
],
},
],
},
{
pathname: '/x/migration-group',
title: 'Migration',
children: [
{
pathname: '/x/migration-v6',
subheader: 'Upgrade to v6',
children: [
{ pathname: '/x/migration/migration-data-grid-v5', title: 'Breaking changes: Data Grid' },
{
pathname: '/x/migration/migration-pickers-v5',
title: 'Breaking changes: Date and Time Pickers',
},
],
},
{
pathname: '/x/migration-earlier',
subheader: 'Earlier versions',
children: [
{
pathname: '/x/migration/migration-pickers-lab',
title: 'Migration from lab to v5 (Date and Time Pickers)',
},
{
pathname: '/x/migration/migration-data-grid-v4',
title: 'Migration from v4 to v5 (Data Grid)',
},
],
},
],
},
];
export default pages;
| 636 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/docs/pages.ts | import type { MuiPage } from 'docs/src/MuiPage';
import standardNavIcons from 'docs/src/modules/components/AppNavIcons';
const pages: readonly MuiPage[] = [
{ pathname: '/versions' },
{
pathname: 'https://mui.com/store/',
title: 'Templates',
icon: standardNavIcons.ReaderIcon,
linkProps: {
'data-ga-event-category': 'store',
'data-ga-event-action': 'click',
'data-ga-event-label': 'sidenav',
},
},
{ pathname: '/blog', title: 'Blog', icon: standardNavIcons.BookIcon },
];
export default pages;
| 637 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/joy/pages.ts | import type { MuiPage } from 'docs/src/MuiPage';
import pagesApi from 'docs/data/joy/pagesApi';
const pages: readonly MuiPage[] = [
{
pathname: '/joy-ui/getting-started-group',
title: 'Getting started',
children: [
{ pathname: '/joy-ui/getting-started', title: 'Overview' },
{ pathname: '/joy-ui/getting-started/installation' },
{ pathname: '/joy-ui/getting-started/usage' },
{ pathname: '/joy-ui/getting-started/tutorial' },
{ pathname: '/joy-ui/getting-started/templates' },
{ pathname: '/joy-ui/getting-started/roadmap' },
{
pathname: '/joy-ui/main-features',
subheader: 'main-features',
children: [
{ pathname: '/joy-ui/main-features/global-variants' },
{ pathname: '/joy-ui/main-features/color-inversion' },
{ pathname: '/joy-ui/main-features/automatic-adjustment' },
{ pathname: '/joy-ui/main-features/dark-mode-optimization' },
],
},
],
},
{
pathname: '/joy-ui/react-',
title: 'Components',
children: [
{
pathname: '/joy-ui/components/inputs',
subheader: 'inputs',
children: [
{ pathname: '/joy-ui/react-autocomplete' },
{ pathname: '/joy-ui/react-button' },
{ pathname: '/joy-ui/react-button-group', title: 'Button Group' },
{ pathname: '/joy-ui/react-checkbox' },
{ pathname: '/joy-ui/react-input' },
{ pathname: '/joy-ui/react-radio-button', title: 'Radio Button' },
{ pathname: '/joy-ui/react-select' },
{ pathname: '/joy-ui/react-slider' },
{ pathname: '/joy-ui/react-switch' },
{ pathname: '/joy-ui/react-textarea' },
{ pathname: '/joy-ui/react-text-field', title: 'Text Field' },
{
pathname: '/joy-ui/react-toggle-button-group',
title: 'Toggle Button Group',
newFeature: true,
},
],
},
{
pathname: '/joy-ui/components/data-display',
subheader: 'data-display',
children: [
{ pathname: '/joy-ui/react-aspect-ratio', title: 'Aspect Ratio' },
{ pathname: '/joy-ui/react-avatar' },
{ pathname: '/joy-ui/react-badge' },
{ pathname: '/joy-ui/react-chip' },
{ pathname: '/joy-ui/react-divider' },
{ pathname: '/joy-ui/react-list' },
{ pathname: '/joy-ui/react-table' },
{ pathname: '/joy-ui/react-tooltip' },
{ pathname: '/joy-ui/react-typography' },
],
},
{
pathname: '/joy-ui/components/feedback',
subheader: 'feedback',
children: [
{ pathname: '/joy-ui/react-alert' },
{ pathname: '/joy-ui/react-circular-progress', title: 'Circular Progress' },
{ pathname: '/joy-ui/react-linear-progress', title: 'Linear Progress' },
{ pathname: '/joy-ui/react-modal' },
{ pathname: '/joy-ui/react-skeleton', newFeature: true },
{ pathname: '/joy-ui/react-snackbar', newFeature: true },
],
},
{
pathname: '/joy-ui/components/surfaces',
subheader: 'surfaces',
children: [
{ pathname: '/joy-ui/react-accordion', newFeature: true },
{ pathname: '/joy-ui/react-card' },
{ pathname: '/joy-ui/react-sheet' },
],
},
{
pathname: '/joy-ui/components/navigation',
subheader: 'navigation',
children: [
{ pathname: '/joy-ui/react-breadcrumbs' },
{ pathname: '/joy-ui/react-drawer', newFeature: true },
{ pathname: '/joy-ui/react-link' },
{ pathname: '/joy-ui/react-menu' },
{ pathname: '/joy-ui/react-stepper', newFeature: true },
{ pathname: '/joy-ui/react-tabs' },
],
},
{
pathname: '/joy-ui/components/layout',
subheader: 'layout',
children: [
{ pathname: '/joy-ui/react-box' },
{ pathname: '/joy-ui/react-grid' },
{ pathname: '/joy-ui/react-stack' },
],
},
{
pathname: '/joy-ui/components/utils',
subheader: 'utils',
children: [{ pathname: '/joy-ui/react-css-baseline', title: 'CSS Baseline' }],
},
],
},
{
title: 'APIs',
pathname: '/joy-ui/api',
children: pagesApi,
},
{
pathname: '/joy-ui/customization',
children: [
{ pathname: '/joy-ui/customization/approaches' },
{
pathname: '/joy-ui/customization/theme',
subheader: 'Theme',
children: [
{ pathname: '/joy-ui/customization/theme-colors', title: 'Colors' },
{ pathname: '/joy-ui/customization/theme-shadow', title: 'Shadow' },
{ pathname: '/joy-ui/customization/theme-typography', title: 'Typography' },
{ pathname: '/joy-ui/customization/themed-components', title: 'Components' },
],
},
{
pathname: '/joy-ui/customization/guides',
subheader: 'Guides',
children: [
{ pathname: '/joy-ui/customization/dark-mode' },
{ pathname: '/joy-ui/customization/using-css-variables', title: 'Using CSS variables' },
{
pathname: '/joy-ui/customization/creating-themed-components',
title: 'Creating themed components',
},
{
pathname: '/joy-ui/customization/overriding-component-structure',
title: 'Overriding the component structure',
},
],
},
{
subheader: 'Tools',
pathname: '/joy-ui/customization/tool',
children: [
{ pathname: '/joy-ui/customization/default-theme-viewer' },
{ pathname: '/joy-ui/customization/theme-builder' },
],
},
],
},
{
pathname: '/joy-ui/integrations',
title: 'Integrations',
children: [
{
pathname: '/joy-ui/integrations/next-js-app-router',
title: 'Next.js App Router',
},
{
pathname: '/joy-ui/integrations/material-ui',
title: 'Usage with Material UI',
},
{
pathname: '/joy-ui/integrations/icon-libraries',
title: 'Using other icon libraries',
},
],
},
{
pathname: '/joy-ui/migration',
title: 'Migration',
children: [
{
pathname: '/joy-ui/migration/migrating-default-theme',
title: 'Migrating the default theme',
},
],
},
];
export default pages;
| 638 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/joy/pagesApi.js | module.exports = [
{ pathname: '/joy-ui/api/accordion' },
{ pathname: '/joy-ui/api/accordion-details' },
{ pathname: '/joy-ui/api/accordion-group' },
{ pathname: '/joy-ui/api/accordion-summary' },
{ pathname: '/joy-ui/api/alert' },
{ pathname: '/joy-ui/api/aspect-ratio' },
{ pathname: '/joy-ui/api/autocomplete' },
{ pathname: '/joy-ui/api/autocomplete-listbox' },
{ pathname: '/joy-ui/api/autocomplete-option' },
{ pathname: '/joy-ui/api/avatar' },
{ pathname: '/joy-ui/api/avatar-group' },
{ pathname: '/joy-ui/api/badge' },
{ pathname: '/joy-ui/api/box' },
{ pathname: '/joy-ui/api/breadcrumbs' },
{ pathname: '/joy-ui/api/button' },
{ pathname: '/joy-ui/api/button-group' },
{ pathname: '/joy-ui/api/card' },
{ pathname: '/joy-ui/api/card-actions' },
{ pathname: '/joy-ui/api/card-content' },
{ pathname: '/joy-ui/api/card-cover' },
{ pathname: '/joy-ui/api/card-overflow' },
{ pathname: '/joy-ui/api/checkbox' },
{ pathname: '/joy-ui/api/chip' },
{ pathname: '/joy-ui/api/chip-delete' },
{ pathname: '/joy-ui/api/circular-progress' },
{ pathname: '/joy-ui/api/css-baseline' },
{ pathname: '/joy-ui/api/dialog-actions' },
{ pathname: '/joy-ui/api/dialog-content' },
{ pathname: '/joy-ui/api/dialog-title' },
{ pathname: '/joy-ui/api/divider' },
{ pathname: '/joy-ui/api/drawer' },
{ pathname: '/joy-ui/api/form-control' },
{ pathname: '/joy-ui/api/form-helper-text' },
{ pathname: '/joy-ui/api/form-label' },
{ pathname: '/joy-ui/api/grid' },
{ pathname: '/joy-ui/api/icon-button' },
{ pathname: '/joy-ui/api/input' },
{ pathname: '/joy-ui/api/linear-progress' },
{ pathname: '/joy-ui/api/link' },
{ pathname: '/joy-ui/api/list' },
{ pathname: '/joy-ui/api/list-divider' },
{ pathname: '/joy-ui/api/list-item' },
{ pathname: '/joy-ui/api/list-item-button' },
{ pathname: '/joy-ui/api/list-item-content' },
{ pathname: '/joy-ui/api/list-item-decorator' },
{ pathname: '/joy-ui/api/list-subheader' },
{ pathname: '/joy-ui/api/menu' },
{ pathname: '/joy-ui/api/menu-button' },
{ pathname: '/joy-ui/api/menu-item' },
{ pathname: '/joy-ui/api/menu-list' },
{ pathname: '/joy-ui/api/modal' },
{ pathname: '/joy-ui/api/modal-close' },
{ pathname: '/joy-ui/api/modal-dialog' },
{ pathname: '/joy-ui/api/modal-overflow' },
{ pathname: '/joy-ui/api/option' },
{ pathname: '/joy-ui/api/radio' },
{ pathname: '/joy-ui/api/radio-group' },
{ pathname: '/joy-ui/api/scoped-css-baseline' },
{ pathname: '/joy-ui/api/select' },
{ pathname: '/joy-ui/api/sheet' },
{ pathname: '/joy-ui/api/skeleton' },
{ pathname: '/joy-ui/api/slider' },
{ pathname: '/joy-ui/api/snackbar' },
{ pathname: '/joy-ui/api/stack' },
{ pathname: '/joy-ui/api/step' },
{ pathname: '/joy-ui/api/step-button' },
{ pathname: '/joy-ui/api/step-indicator' },
{ pathname: '/joy-ui/api/stepper' },
{ pathname: '/joy-ui/api/svg-icon' },
{ pathname: '/joy-ui/api/switch' },
{ pathname: '/joy-ui/api/tab' },
{ pathname: '/joy-ui/api/table' },
{ pathname: '/joy-ui/api/tab-list' },
{ pathname: '/joy-ui/api/tab-panel' },
{ pathname: '/joy-ui/api/tabs' },
{ pathname: '/joy-ui/api/textarea' },
{ pathname: '/joy-ui/api/toggle-button-group' },
{ pathname: '/joy-ui/api/tooltip' },
{ pathname: '/joy-ui/api/typography' },
];
| 639 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionBasic.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionBasic() {
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 640 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionBasic.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionBasic() {
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 641 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionControlled.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionControlled() {
const [index, setIndex] = React.useState(0);
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion
expanded={index === 0}
onChange={(event, expanded) => {
setIndex(expanded ? 0 : null);
}}
>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion
expanded={index === 1}
onChange={(event, expanded) => {
setIndex(expanded ? 1 : null);
}}
>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion
expanded={index === 2}
onChange={(event, expanded) => {
setIndex(expanded ? 2 : null);
}}
>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 642 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionControlled.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionControlled() {
const [index, setIndex] = React.useState<number | null>(0);
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion
expanded={index === 0}
onChange={(event, expanded) => {
setIndex(expanded ? 0 : null);
}}
>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion
expanded={index === 1}
onChange={(event, expanded) => {
setIndex(expanded ? 1 : null);
}}
>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion
expanded={index === 2}
onChange={(event, expanded) => {
setIndex(expanded ? 2 : null);
}}
>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 643 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionDepthPanel.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails, {
accordionDetailsClasses,
} from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
export default function AccordionDepthPanel() {
return (
<AccordionGroup
variant="outlined"
transition="0.2s"
sx={{
maxWidth: 400,
borderRadius: 'lg',
[`& .${accordionSummaryClasses.button}:hover`]: {
bgcolor: 'transparent',
},
[`& .${accordionDetailsClasses.content}`]: {
boxShadow: (theme) => `inset 0 1px ${theme.vars.palette.divider}`,
[`&.${accordionDetailsClasses.expanded}`]: {
paddingBlock: '0.75rem',
},
},
}}
>
<Accordion defaultExpanded>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 644 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionDepthPanel.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails, {
accordionDetailsClasses,
} from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
export default function AccordionDepthPanel() {
return (
<AccordionGroup
variant="outlined"
transition="0.2s"
sx={{
maxWidth: 400,
borderRadius: 'lg',
[`& .${accordionSummaryClasses.button}:hover`]: {
bgcolor: 'transparent',
},
[`& .${accordionDetailsClasses.content}`]: {
boxShadow: (theme) => `inset 0 1px ${theme.vars.palette.divider}`,
[`&.${accordionDetailsClasses.expanded}`]: {
paddingBlock: '0.75rem',
},
},
}}
>
<Accordion defaultExpanded>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails variant="soft">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 645 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionDisabled.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionDisabled() {
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion disabled>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion disabled>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion expanded disabled>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 646 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionDisabled.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionDisabled() {
return (
<AccordionGroup sx={{ maxWidth: 400 }}>
<Accordion disabled>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion disabled>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion expanded disabled>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 647 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionFilter.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails, {
accordionDetailsClasses,
} from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
import Switch from '@mui/joy/Switch';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import Avatar from '@mui/joy/Avatar';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import ListItemContent from '@mui/joy/ListItemContent';
import AirplanemodeActiveRoundedIcon from '@mui/icons-material/AirplanemodeActiveRounded';
import WifiRoundedIcon from '@mui/icons-material/WifiRounded';
import BluetoothRoundedIcon from '@mui/icons-material/BluetoothRounded';
import TapAndPlayRoundedIcon from '@mui/icons-material/TapAndPlayRounded';
import EditNotificationsRoundedIcon from '@mui/icons-material/EditNotificationsRounded';
import AdUnitsRoundedIcon from '@mui/icons-material/AdUnitsRounded';
import MessageRoundedIcon from '@mui/icons-material/MessageRounded';
import EmailRoundedIcon from '@mui/icons-material/EmailRounded';
import AccessibilityNewRoundedIcon from '@mui/icons-material/AccessibilityNewRounded';
import ZoomInRoundedIcon from '@mui/icons-material/ZoomInRounded';
import SpatialTrackingRoundedIcon from '@mui/icons-material/SpatialTrackingRounded';
import SettingsVoiceRoundedIcon from '@mui/icons-material/SettingsVoiceRounded';
export default function AccordionFilter() {
return (
<AccordionGroup
variant="plain"
transition="0.2s"
sx={{
maxWidth: 400,
borderRadius: 'md',
[`& .${accordionDetailsClasses.content}.${accordionDetailsClasses.expanded}`]:
{
paddingBlock: '1rem',
},
[`& .${accordionSummaryClasses.button}`]: {
paddingBlock: '1rem',
},
}}
>
<Accordion>
<AccordionSummary>
<Avatar color="primary">
<TapAndPlayRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Connections</Typography>
<Typography level="body-sm">
Activate or deactivate your connections
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<AirplanemodeActiveRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Airplane Mode</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<WifiRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Wi-Fi</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<BluetoothRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Bluetooth</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>
<Avatar color="success">
<EditNotificationsRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Notifications</Typography>
<Typography level="body-sm">
Enable or disable your notifications
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<EmailRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>E-mail</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<MessageRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Messages</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<AdUnitsRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Push</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>
<Avatar color="danger">
<AccessibilityNewRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Accessibility</Typography>
<Typography level="body-sm">
Toggle your accessibility settings
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<ZoomInRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Zoom</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<SpatialTrackingRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Audio Descriptions</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<SettingsVoiceRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Voice Control</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 648 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionFilter.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails, {
accordionDetailsClasses,
} from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
import Switch from '@mui/joy/Switch';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import Avatar from '@mui/joy/Avatar';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import ListItemContent from '@mui/joy/ListItemContent';
import AirplanemodeActiveRoundedIcon from '@mui/icons-material/AirplanemodeActiveRounded';
import WifiRoundedIcon from '@mui/icons-material/WifiRounded';
import BluetoothRoundedIcon from '@mui/icons-material/BluetoothRounded';
import TapAndPlayRoundedIcon from '@mui/icons-material/TapAndPlayRounded';
import EditNotificationsRoundedIcon from '@mui/icons-material/EditNotificationsRounded';
import AdUnitsRoundedIcon from '@mui/icons-material/AdUnitsRounded';
import MessageRoundedIcon from '@mui/icons-material/MessageRounded';
import EmailRoundedIcon from '@mui/icons-material/EmailRounded';
import AccessibilityNewRoundedIcon from '@mui/icons-material/AccessibilityNewRounded';
import ZoomInRoundedIcon from '@mui/icons-material/ZoomInRounded';
import SpatialTrackingRoundedIcon from '@mui/icons-material/SpatialTrackingRounded';
import SettingsVoiceRoundedIcon from '@mui/icons-material/SettingsVoiceRounded';
export default function AccordionFilter() {
return (
<AccordionGroup
variant="plain"
transition="0.2s"
sx={{
maxWidth: 400,
borderRadius: 'md',
[`& .${accordionDetailsClasses.content}.${accordionDetailsClasses.expanded}`]:
{
paddingBlock: '1rem',
},
[`& .${accordionSummaryClasses.button}`]: {
paddingBlock: '1rem',
},
}}
>
<Accordion>
<AccordionSummary>
<Avatar color="primary">
<TapAndPlayRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Connections</Typography>
<Typography level="body-sm">
Activate or deactivate your connections
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<AirplanemodeActiveRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Airplane Mode</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<WifiRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Wi-Fi</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<BluetoothRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Bluetooth</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>
<Avatar color="success">
<EditNotificationsRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Notifications</Typography>
<Typography level="body-sm">
Enable or disable your notifications
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<EmailRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>E-mail</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<MessageRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Messages</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<AdUnitsRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Push</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>
<Avatar color="danger">
<AccessibilityNewRoundedIcon />
</Avatar>
<ListItemContent>
<Typography level="title-md">Accessibility</Typography>
<Typography level="body-sm">
Toggle your accessibility settings
</Typography>
</ListItemContent>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={1.5}>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<ZoomInRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Zoom</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<SpatialTrackingRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Audio Descriptions</FormLabel>
<Switch size="sm" />
</FormControl>
<FormControl orientation="horizontal" sx={{ gap: 1 }}>
<SettingsVoiceRoundedIcon fontSize="xl2" sx={{ mx: 1 }} />
<FormLabel>Voice Control</FormLabel>
<Switch size="sm" />
</FormControl>
</Stack>
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 649 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionIndicator.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
import AddIcon from '@mui/icons-material/Add';
export default function AccordionIndicator() {
return (
<AccordionGroup
sx={{
maxWidth: 400,
[`& .${accordionSummaryClasses.indicator}`]: {
transition: '0.2s',
},
[`& [aria-expanded="true"] .${accordionSummaryClasses.indicator}`]: {
transform: 'rotate(45deg)',
},
}}
>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 650 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionIndicator.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary, {
accordionSummaryClasses,
} from '@mui/joy/AccordionSummary';
import AddIcon from '@mui/icons-material/Add';
export default function AccordionIndicator() {
return (
<AccordionGroup
sx={{
maxWidth: 400,
[`& .${accordionSummaryClasses.indicator}`]: {
transition: '0.2s',
},
[`& [aria-expanded="true"] .${accordionSummaryClasses.indicator}`]: {
transform: 'rotate(45deg)',
},
}}
>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary indicator={<AddIcon />}>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 651 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionNoDivider.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionNoDivider() {
return (
<AccordionGroup disableDivider sx={{ maxWidth: 400 }}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 652 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionNoDivider.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionNoDivider() {
return (
<AccordionGroup disableDivider sx={{ maxWidth: 400 }}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 653 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionSizes.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
import Button from '@mui/joy/Button';
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup';
import Stack from '@mui/joy/Stack';
export default function AccordionSizes() {
const [size, setSize] = React.useState('md');
return (
<Stack spacing={2} sx={{ maxWidth: 400, flex: 1 }}>
<ToggleButtonGroup
size="sm"
buttonFlex={1}
value={size}
onChange={(event, newValue) => setSize(newValue || size)}
>
<Button value="sm">Small</Button>
<Button value="md">Medium</Button>
<Button value="lg">Large</Button>
</ToggleButtonGroup>
<AccordionGroup size={size}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
</Stack>
);
}
| 654 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionSizes.tsx | import * as React from 'react';
import AccordionGroup, { AccordionGroupProps } from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
import Button from '@mui/joy/Button';
import ToggleButtonGroup from '@mui/joy/ToggleButtonGroup';
import Stack from '@mui/joy/Stack';
export default function AccordionSizes() {
const [size, setSize] = React.useState<AccordionGroupProps['size']>('md');
return (
<Stack spacing={2} sx={{ maxWidth: 400, flex: 1 }}>
<ToggleButtonGroup
size="sm"
buttonFlex={1}
value={size}
onChange={(event, newValue) => setSize(newValue || size)}
>
<Button value="sm">Small</Button>
<Button value="md">Medium</Button>
<Button value="lg">Large</Button>
</ToggleButtonGroup>
<AccordionGroup size={size}>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
</Stack>
);
}
| 655 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionStylingExpansion.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion, { accordionClasses } from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionStylingExpansion() {
return (
<AccordionGroup
sx={{
maxWidth: 400,
[`& .${accordionClasses.root}`]: {
marginTop: '0.5rem',
transition: '0.2s ease',
'& button:not([aria-expanded="true"])': {
transition: '0.2s ease',
paddingBottom: '0.625rem',
},
'& button:hover': {
background: 'transparent',
},
},
[`& .${accordionClasses.root}.${accordionClasses.expanded}`]: {
bgcolor: 'background.level1',
borderRadius: 'md',
borderBottom: '1px solid',
borderColor: 'background.level2',
},
'& [aria-expanded="true"]': {
boxShadow: (theme) => `inset 0 -1px 0 ${theme.vars.palette.divider}`,
},
}}
>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 656 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionStylingExpansion.tsx | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion, { accordionClasses } from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
export default function AccordionStylingExpansion() {
return (
<AccordionGroup
sx={{
maxWidth: 400,
[`& .${accordionClasses.root}`]: {
marginTop: '0.5rem',
transition: '0.2s ease',
'& button:not([aria-expanded="true"])': {
transition: '0.2s ease',
paddingBottom: '0.625rem',
},
'& button:hover': {
background: 'transparent',
},
},
[`& .${accordionClasses.root}.${accordionClasses.expanded}`]: {
bgcolor: 'background.level1',
borderRadius: 'md',
borderBottom: '1px solid',
borderColor: 'background.level2',
},
'& [aria-expanded="true"]': {
boxShadow: (theme) => `inset 0 -1px 0 ${theme.vars.palette.divider}`,
},
}}
>
<Accordion>
<AccordionSummary>First accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Second accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>Third accordion</AccordionSummary>
<AccordionDetails>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
| 657 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionTransition.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
import BrandingProvider from 'docs/src/BrandingProvider';
export default function AccordionTransition() {
const [transition, setTransition] = React.useState('0.2s ease');
return (
<Stack alignItems="center" spacing={2} sx={{ flex: 1 }}>
<RadioGroup
orientation="horizontal"
value={transition}
onChange={(event) => {
setTransition(event.target.value);
}}
>
<Radio value="0.2s ease" label="Easing" />
<Radio value="mix" label="Mix" />
</RadioGroup>
<AccordionGroup
transition={
transition === 'mix'
? {
initial: '0.3s ease-out',
expanded: '0.2s ease',
}
: transition
}
sx={{ maxWidth: 400 }}
>
<Accordion>
<AccordionSummary>📖 How to animate the panel?</AccordionSummary>
<AccordionDetails>
<Typography>
The AccordionGroup supports the <code>transition</code> prop to
customize the animation of the panel. You can provide a <b>string</b>{' '}
value or an <b>object</b> to fine tune the animation at the initial and
expanded states.
</Typography>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>🤔 Does it work with dynamic height?</AccordionSummary>
<AccordionDetails>
<Typography>
Absolutely yes! an by the way, it is <b>pure CSS</b>.
</Typography>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary>🪄 What kind of magic this is?</AccordionSummary>
<AccordionDetails>
<Typography>
The panel is a <b>CSS Grid</b> which can be transitioned by the{' '}
<code>grid-template-rows</code> property.
</Typography>
</AccordionDetails>
</Accordion>
</AccordionGroup>
<Box sx={{ width: '100%' }}>
<BrandingProvider>
<HighlightedCode
code={`<AccordionGroup transition=${
transition === 'mix'
? `{{
initial: "0.3s ease-out",
expanded: "0.2s ease",
}}`
: `"${transition}"`
}>`}
language="jsx"
/>
</BrandingProvider>
</Box>
</Stack>
);
}
| 658 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/AccordionUsage.js | import * as React from 'react';
import AccordionGroup from '@mui/joy/AccordionGroup';
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionSummary from '@mui/joy/AccordionSummary';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function AccordionUsage() {
return (
<JoyUsageDemo
componentName="AccordionGroup"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'plain',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'disabled',
knob: 'switch',
defaultValue: false,
codeBlockDisplay: false,
},
{
propName: 'children',
defaultValue: `$children`,
},
]}
getCodeBlock={(code, props) =>
code.replace(
'$children',
`<Accordion${props.disabled ? ' disabled' : ''}${
props.variant === 'solid'
? ` variant=${props.variant} color=${props.color}`
: ''
}>
<AccordionSummary${
props.variant === 'solid'
? ` variant=${props.variant} color=${props.color}`
: ''
}>Title</AccordionSummary>
<AccordionDetails${
props.variant === 'solid'
? ` variant=${props.variant} color=${props.color}`
: ''
}>Content</AccordionDetails>
</Accordion>`,
)
}
renderDemo={({ disabled, ...props }) => (
<AccordionGroup
{...props}
sx={{ width: 300, maxWidth: '100%', alignSelf: 'flex-start', mb: 3 }}
>
<Accordion
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
disabled={disabled}
>
<AccordionSummary
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
First Header
</AccordionSummary>
<AccordionDetails
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
Content of the first accordion.
</AccordionDetails>
</Accordion>
<Accordion
disabled={disabled}
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
<AccordionSummary
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
Second Header
</AccordionSummary>
<AccordionDetails
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
Content of the second accordion.
</AccordionDetails>
</Accordion>
<Accordion
disabled={disabled}
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
<AccordionSummary
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
Third Header
</AccordionSummary>
<AccordionDetails
{...(props.variant === 'solid' && {
variant: 'solid',
color: props.color,
})}
>
Content of the third accordion.
</AccordionDetails>
</Accordion>
</AccordionGroup>
)}
/>
);
}
| 659 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/accordion/accordion.md | ---
productId: joy-ui
title: React Accordion component
components: Accordion, AccordionDetails, AccordionGroup, AccordionSummary
githubLabel: 'component: accordion'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/accordion/
---
# Accordion
<p class="description">Accordions let users show and hide sections of related content on a page.</p>
## Introduction
Joy UI provides four accordion-related components:
- [`AccordionGroup`](#basic-usage): A container that groups multiple accordions. It **does not** control the state of each accordion.
- [`Accordion`](#basic-usage): A component that contains the expansion logic and send to AccordionSummary and AccordionDetails.
- [`AccordionSummary`](#basic-usage): A header of the accordion which contain a button that triggers the expansion.
- [`AccordionDetails`](#basic-usage): A wrapper for the accordion details.
{{"demo": "AccordionUsage.js", "hideToolbar": true, "bg": "gradient"}}
## Basics
```jsx
import Accordion from '@mui/joy/Accordion';
import AccordionDetails from '@mui/joy/AccordionDetails';
import AccordionGroup from '@mui/joy/AccordionGroup';
import AccordionSummary from '@mui/joy/AccordionSummary';
```
{{"demo": "AccordionBasic.js"}}
## Customization
### Sizes
The AccordionGroup component comes in three sizes: `sm`, `md` (default), and `lg`.
{{"demo": "AccordionSizes.js"}}
:::info
To learn how to add custom sizes to the component, check out [Themed components—Extend sizes](/joy-ui/customization/themed-components/#extend-sizes).
:::
### Controlled accordion
Use the `expanded` prop to control the expansion state of the accordion and listen to the expansion event via `onChange` prop.
{{"demo": "AccordionControlled.js"}}
### Disabled
Use the `disabled` prop to disable the accordion trigger.
{{"demo": "AccordionDisabled.js"}}
:::info
Note: the `disabled` prop only disables the accordion trigger, not the accordion content.
:::
### Removing divider
Use `disableDivider` prop on the Accordion Group component to hide the divider between accordions.
{{"demo": "AccordionNoDivider.js"}}
:::info
**Good to know**: the reason that ListDivider can be used is because the accordion family reuses styles from the [List](/joy-ui/react-list/) family.
:::
### Animating the expansion
Use `transition` prop to animate the expansion. The value can be a **string** if you want the transition to be the same for initial and expanded states, or an **object** if you want to customize the transition for each state.
The object value can contain the following keys:
- `initial`: the transition when the accordion is closed
- `expanded`: the transition when the accordion is open
{{"demo": "AccordionTransition.js", "hideToolbar": true}}
### Indicator
Use `indicator` prop to customize the indicator of the accordion.
{{"demo": "AccordionIndicator.js"}}
### Styling on expansion
Use `sx` prop on the AccordionGroup to style all the accordions at once.
{{"demo": "AccordionStylingExpansion.js"}}
## Common examples
### Depth panel
This example shows how to customize the accordion to create lines and depth to make it look more realistic.
{{"demo": "AccordionDepthPanel.js"}}
### User settings
This example shows how to customize the accordion and craft diverse compositions using additional components.
{{"demo": "AccordionFilter.js"}}
## Accessibility
The built-in accessibility of the accordion follows [WAI-ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/).
- The accordion summary has a root slot (`div`) that can be changed, for example using `h3`, based on the hierarchy of the accordion.
- The accordion summary contains a button with `aria-expanded` and `aria-controls` attributes.
- The accordion details contains a div with `role="region"` and `aria-labelledby` attributes.
| 660 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertBasic.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertBasic() {
return (
<Box sx={{ width: '100%' }}>
<Alert>This is a basic Alert.</Alert>
</Box>
);
}
| 661 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertBasic.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertBasic() {
return (
<Box sx={{ width: '100%' }}>
<Alert>This is a basic Alert.</Alert>
</Box>
);
}
| 662 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertBasic.tsx.preview | <Alert>This is a basic Alert.</Alert> | 663 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertColors.js | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import Stack from '@mui/joy/Stack';
import Box from '@mui/joy/Box';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';
import Typography from '@mui/joy/Typography';
export default function AlertColors() {
const [variant, setVariant] = React.useState('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
}}
>
<Stack spacing={1} sx={{ width: '100%', maxWidth: 400 }}>
<Alert variant={variant} color="primary">
Primary
</Alert>
<Alert variant={variant} color="neutral">
Neutral
</Alert>
<Alert variant={variant} color="danger">
Danger
</Alert>
<Alert variant={variant} color="success">
Success
</Alert>
<Alert variant={variant} color="warning">
Warning
</Alert>
</Stack>
<Sheet sx={{ pl: 4, ml: 3, borderLeft: '1px solid', borderColor: 'divider' }}>
<Typography
level="body-sm"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
| 664 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertColors.tsx | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import Stack from '@mui/joy/Stack';
import Box from '@mui/joy/Box';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';
import { VariantProp } from '@mui/joy/styles';
import Typography from '@mui/joy/Typography';
export default function AlertColors() {
const [variant, setVariant] = React.useState<VariantProp>('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
}}
>
<Stack spacing={1} sx={{ width: '100%', maxWidth: 400 }}>
<Alert variant={variant} color="primary">
Primary
</Alert>
<Alert variant={variant} color="neutral">
Neutral
</Alert>
<Alert variant={variant} color="danger">
Danger
</Alert>
<Alert variant={variant} color="success">
Success
</Alert>
<Alert variant={variant} color="warning">
Warning
</Alert>
</Stack>
<Sheet sx={{ pl: 4, ml: 3, borderLeft: '1px solid', borderColor: 'divider' }}>
<Typography
level="body-sm"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value as VariantProp)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
| 665 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertInvertedColors.js | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import AspectRatio from '@mui/joy/AspectRatio';
import IconButton from '@mui/joy/IconButton';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import CircularProgress from '@mui/joy/CircularProgress';
import LinearProgress from '@mui/joy/LinearProgress';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import Check from '@mui/icons-material/Check';
import Close from '@mui/icons-material/Close';
import Warning from '@mui/icons-material/Warning';
export default function AlertInvertedColors() {
return (
<Stack spacing={2} sx={{ maxWidth: 400 }}>
<Alert
size="lg"
color="success"
variant="solid"
invertedColors
startDecorator={
<AspectRatio
variant="solid"
ratio="1"
sx={{
minWidth: 40,
borderRadius: '50%',
boxShadow: '0 2px 12px 0 rgb(0 0 0/0.2)',
}}
>
<div>
<Check fontSize="xl2" />
</div>
</AspectRatio>
}
endDecorator={
<IconButton
variant="plain"
sx={{
'--IconButton-size': '32px',
transform: 'translate(0.5rem, -0.5rem)',
}}
>
<Close />
</IconButton>
}
sx={{ alignItems: 'flex-start', overflow: 'hidden' }}
>
<div>
<Typography level="title-lg">Success</Typography>
<Typography level="body-sm">
Success is walking from failure to failure with no loss of enthusiam.
</Typography>
</div>
<LinearProgress
variant="solid"
color="success"
value={40}
sx={{
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
borderRadius: 0,
}}
/>
</Alert>
<Alert
variant="soft"
color="danger"
invertedColors
startDecorator={
<CircularProgress size="lg" color="danger">
<Warning />
</CircularProgress>
}
sx={{ alignItems: 'flex-start', gap: '1rem' }}
>
<Box sx={{ flex: 1 }}>
<Typography level="title-md">Lost connection</Typography>
<Typography level="body-md">
Please verify your network connection and try again.
</Typography>
<Box sx={{ mt: 2, display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button variant="outlined" size="sm">
Open network settings
</Button>
<Button variant="solid" size="sm">
Try again
</Button>
</Box>
</Box>
</Alert>
</Stack>
);
}
| 666 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertInvertedColors.tsx | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import AspectRatio from '@mui/joy/AspectRatio';
import IconButton from '@mui/joy/IconButton';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import CircularProgress from '@mui/joy/CircularProgress';
import LinearProgress from '@mui/joy/LinearProgress';
import Stack from '@mui/joy/Stack';
import Typography from '@mui/joy/Typography';
import Check from '@mui/icons-material/Check';
import Close from '@mui/icons-material/Close';
import Warning from '@mui/icons-material/Warning';
export default function AlertInvertedColors() {
return (
<Stack spacing={2} sx={{ maxWidth: 400 }}>
<Alert
size="lg"
color="success"
variant="solid"
invertedColors
startDecorator={
<AspectRatio
variant="solid"
ratio="1"
sx={{
minWidth: 40,
borderRadius: '50%',
boxShadow: '0 2px 12px 0 rgb(0 0 0/0.2)',
}}
>
<div>
<Check fontSize="xl2" />
</div>
</AspectRatio>
}
endDecorator={
<IconButton
variant="plain"
sx={{
'--IconButton-size': '32px',
transform: 'translate(0.5rem, -0.5rem)',
}}
>
<Close />
</IconButton>
}
sx={{ alignItems: 'flex-start', overflow: 'hidden' }}
>
<div>
<Typography level="title-lg">Success</Typography>
<Typography level="body-sm">
Success is walking from failure to failure with no loss of enthusiam.
</Typography>
</div>
<LinearProgress
variant="solid"
color="success"
value={40}
sx={{
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
borderRadius: 0,
}}
/>
</Alert>
<Alert
variant="soft"
color="danger"
invertedColors
startDecorator={
<CircularProgress size="lg" color="danger">
<Warning />
</CircularProgress>
}
sx={{ alignItems: 'flex-start', gap: '1rem' }}
>
<Box sx={{ flex: 1 }}>
<Typography level="title-md">Lost connection</Typography>
<Typography level="body-md">
Please verify your network connection and try again.
</Typography>
<Box sx={{ mt: 2, display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
<Button variant="outlined" size="sm">
Open network settings
</Button>
<Button variant="solid" size="sm">
Try again
</Button>
</Box>
</Box>
</Alert>
</Stack>
);
}
| 667 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertSizes.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert size="sm">This is a small Alert.</Alert>
<Alert size="md">This is a medium Alert.</Alert>
<Alert size="lg">This is a large Alert.</Alert>
</Box>
);
}
| 668 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertSizes.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert size="sm">This is a small Alert.</Alert>
<Alert size="md">This is a medium Alert.</Alert>
<Alert size="lg">This is a large Alert.</Alert>
</Box>
);
}
| 669 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertSizes.tsx.preview | <Alert size="sm">This is a small Alert.</Alert>
<Alert size="md">This is a medium Alert.</Alert>
<Alert size="lg">This is a large Alert.</Alert> | 670 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertUsage.js | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function AlertUsage() {
return (
<JoyUsageDemo
componentName="Alert"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'soft',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
]}
renderDemo={(props) => (
<Alert {...props}>This is a Joy UI Alert — check it out!</Alert>
)}
/>
);
}
| 671 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertVariants.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert variant="solid">This is an Alert using the solid variant.</Alert>
<Alert variant="soft">This is an Alert using the soft variant.</Alert>
<Alert variant="outlined">This is an Alert using the outlined variant.</Alert>
<Alert variant="plain">This is an Alert using the plain variant.</Alert>
</Box>
);
}
| 672 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertVariants.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
export default function AlertVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert variant="solid">This is an Alert using the solid variant.</Alert>
<Alert variant="soft">This is an Alert using the soft variant.</Alert>
<Alert variant="outlined">This is an Alert using the outlined variant.</Alert>
<Alert variant="plain">This is an Alert using the plain variant.</Alert>
</Box>
);
}
| 673 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertVariants.tsx.preview | <Alert variant="solid">This is an Alert using the solid variant.</Alert>
<Alert variant="soft">This is an Alert using the soft variant.</Alert>
<Alert variant="outlined">This is an Alert using the outlined variant.</Alert>
<Alert variant="plain">This is an Alert using the plain variant.</Alert> | 674 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertVariousStates.js | import InfoIcon from '@mui/icons-material/Info';
import WarningIcon from '@mui/icons-material/Warning';
import ReportIcon from '@mui/icons-material/Report';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
export default function AlertVariousStates() {
const items = [
{ title: 'Success', color: 'success', icon: <CheckCircleIcon /> },
{ title: 'Warning', color: 'warning', icon: <WarningIcon /> },
{ title: 'Error', color: 'danger', icon: <ReportIcon /> },
{ title: 'Neutral', color: 'neutral', icon: <InfoIcon /> },
];
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
{items.map(({ title, color, icon }) => (
<Alert
key={title}
sx={{ alignItems: 'flex-start' }}
startDecorator={icon}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<div>
<div>{title}</div>
<Typography level="body-sm" color={color}>
This is a time-sensitive {title} Alert.
</Typography>
</div>
</Alert>
))}
</Box>
);
}
| 675 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertVariousStates.tsx | import InfoIcon from '@mui/icons-material/Info';
import WarningIcon from '@mui/icons-material/Warning';
import ReportIcon from '@mui/icons-material/Report';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Typography from '@mui/joy/Typography';
import { ColorPaletteProp } from '@mui/joy/styles';
export default function AlertVariousStates() {
const items: {
title: string;
color: ColorPaletteProp;
icon: React.ReactElement;
}[] = [
{ title: 'Success', color: 'success', icon: <CheckCircleIcon /> },
{ title: 'Warning', color: 'warning', icon: <WarningIcon /> },
{ title: 'Error', color: 'danger', icon: <ReportIcon /> },
{ title: 'Neutral', color: 'neutral', icon: <InfoIcon /> },
];
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
{items.map(({ title, color, icon }) => (
<Alert
key={title}
sx={{ alignItems: 'flex-start' }}
startDecorator={icon}
variant="soft"
color={color}
endDecorator={
<IconButton variant="soft" color={color}>
<CloseRoundedIcon />
</IconButton>
}
>
<div>
<div>{title}</div>
<Typography level="body-sm" color={color}>
This is a time-sensitive {title} Alert.
</Typography>
</div>
</Alert>
))}
</Box>
);
}
| 676 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertWithDangerState.js | import WarningIcon from '@mui/icons-material/Warning';
import CloseIcon from '@mui/icons-material/Close';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Button from '@mui/joy/Button';
export default function AlertWithDangerState() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert
startDecorator={<WarningIcon />}
variant="soft"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="soft" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
<Alert
startDecorator={<WarningIcon />}
variant="solid"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="solid" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
<Alert
startDecorator={<WarningIcon />}
variant="outlined"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="plain" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
</Box>
);
}
| 677 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertWithDangerState.tsx | import WarningIcon from '@mui/icons-material/Warning';
import CloseIcon from '@mui/icons-material/Close';
import * as React from 'react';
import Box from '@mui/joy/Box';
import Alert from '@mui/joy/Alert';
import IconButton from '@mui/joy/IconButton';
import Button from '@mui/joy/Button';
export default function AlertWithDangerState() {
return (
<Box sx={{ display: 'flex', gap: 2, width: '100%', flexDirection: 'column' }}>
<Alert
startDecorator={<WarningIcon />}
variant="soft"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="soft" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
<Alert
startDecorator={<WarningIcon />}
variant="solid"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="solid" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="solid" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
<Alert
startDecorator={<WarningIcon />}
variant="outlined"
color="danger"
endDecorator={
<React.Fragment>
<Button variant="plain" color="danger" sx={{ mr: 1 }}>
Undo
</Button>
<IconButton variant="soft" size="sm" color="danger">
<CloseIcon />
</IconButton>
</React.Fragment>
}
>
This file was successfully deleted
</Alert>
</Box>
);
}
| 678 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertWithDecorators.js | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import IconButton from '@mui/joy/IconButton';
import PlaylistAddCheckCircleRoundedIcon from '@mui/icons-material/PlaylistAddCheckCircleRounded';
import AccountCircleRoundedIcon from '@mui/icons-material/AccountCircleRounded';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
export default function AlertWithDecorators() {
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, width: '100%' }}>
<Alert
variant="soft"
color="success"
startDecorator={<PlaylistAddCheckCircleRoundedIcon />}
endDecorator={
<Button size="sm" variant="solid" color="success">
Close
</Button>
}
>
Your message was sent successfully.
</Alert>
<Alert
variant="outlined"
color="neutral"
startDecorator={<AccountCircleRoundedIcon />}
endDecorator={
<IconButton variant="plain" size="sm" color="neutral">
<CloseRoundedIcon />
</IconButton>
}
>
Your account was updated.
</Alert>
</Box>
);
}
| 679 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/AlertWithDecorators.tsx | import * as React from 'react';
import Alert from '@mui/joy/Alert';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import IconButton from '@mui/joy/IconButton';
import PlaylistAddCheckCircleRoundedIcon from '@mui/icons-material/PlaylistAddCheckCircleRounded';
import AccountCircleRoundedIcon from '@mui/icons-material/AccountCircleRounded';
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
export default function AlertWithDecorators() {
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, width: '100%' }}>
<Alert
variant="soft"
color="success"
startDecorator={<PlaylistAddCheckCircleRoundedIcon />}
endDecorator={
<Button size="sm" variant="solid" color="success">
Close
</Button>
}
>
Your message was sent successfully.
</Alert>
<Alert
variant="outlined"
color="neutral"
startDecorator={<AccountCircleRoundedIcon />}
endDecorator={
<IconButton variant="plain" size="sm" color="neutral">
<CloseRoundedIcon />
</IconButton>
}
>
Your account was updated.
</Alert>
</Box>
);
}
| 680 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/alert/alert.md | ---
productId: joy-ui
title: React Alert component
components: Alert
githubLabel: 'component: alert'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/alert/
---
# Alert
<p class="description">Alerts display brief messages for the user without interrupting their use of the app.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
The Alert component can be used to provide important and potentially time-sensitive information in a way that does not interfere with the user's tasks. (Source: [ARIA APG](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).)
{{"demo": "AlertUsage.js", "hideToolbar": true, "bg": "gradient"}}
:::info
Alerts should not be confused with alert _dialogs_ ([ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/)), which _are_ intended to interrupt the user to obtain a response.
Use the Joy UI [Modal](https://mui.com/joy-ui/react-modal/) if you need the behavior of a dialog.
:::
## Basics
```jsx
import Alert from '@mui/joy/Alert';
```
The Alert component wraps around its content, and stretches to fill its enclosing container, as shown below:
{{"demo": "AlertBasic.js"}}
## Customization
### Variants
The Alert component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `solid`, `soft` (default), `outlined`, and `plain`.
{{"demo": "AlertVariants.js"}}
:::info
To learn how to add your own variants, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants).
Note that you lose the global variants when you add custom variants.
:::
### Sizes
The Alert component comes in three sizes: `sm`, `md` (default), and `lg`:
{{"demo": "AlertSizes.js"}}
:::info
To learn how to add custom sizes to the component, check out [Themed components—Extend sizes](/joy-ui/customization/themed-components/#extend-sizes).
:::
### Colors
Every palette included in the theme is available via the `color` prop.
The demo below shows how the values for the `color` prop are affected by the global variants:
{{"demo": "AlertColors.js"}}
### Decorators
Use the `startDecorator` and `endDecorator` props to append actions and icons to either side of the Alert:
{{"demo": "AlertWithDecorators.js"}}
### Inverted colors
The Alert component supports Joy UI's [color inversion](/joy-ui/main-features/color-inversion/) by using `invertedColors` prop.
{{"demo": "AlertInvertedColors.js"}}
## Common examples
### Various states
{{"demo": "AlertVariousStates.js"}}
### Danger alerts
{{"demo": "AlertWithDangerState.js"}}
## Accessibility
Here are some factors to consider to ensure that your Alert is accessible:
- Because alerts are not intended to interfere with the use of the app, your Alert component should _never_ affect the keyboard focus.
- If an alert contains an action, that action must have a `tabindex` of `0` so it can be reached by keyboard-only users.
- Essential alerts should not disappear automatically—[timed interactions](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits-no-exceptions.html) can make your app inaccessible to users who need extra time to understand or locate the alert.
- Alerts that occur too frequently can [inhibit the usability](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits-postponed.html) of your app.
- Dynamically rendered alerts are announced by screen readers; alerts that are already present on the page when it loads are _not_ announced.
- Color does not add meaning to the UI for users who require assistive technology. You must ensure that any information conveyed through color is also denoted in other ways, such as within the text of the alert itself, or with additional hidden text that's read by screen readers.
## Anatomy
The Alert component is composed of a single root `<div>` element with its `role` set to `alert`:
```html
<div role="alert" class="MuiAlert-root">
<!-- Alert contents -->
</div>
```
| 681 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/BasicRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
export default function BasicRatio() {
return (
<AspectRatio sx={{ width: 300 }}>
<Typography level="h2" component="div">
16/9
</Typography>
</AspectRatio>
);
}
| 682 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/BasicRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
export default function BasicRatio() {
return (
<AspectRatio sx={{ width: 300 }}>
<Typography level="h2" component="div">
16/9
</Typography>
</AspectRatio>
);
}
| 683 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/BasicRatio.tsx.preview | <AspectRatio sx={{ width: 300 }}>
<Typography level="h2" component="div">
16/9
</Typography>
</AspectRatio> | 684 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CarouselRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Typography from '@mui/joy/Typography';
import Card from '@mui/joy/Card';
const data = [
{
src: 'https://images.unsplash.com/photo-1502657877623-f66bf489d236',
title: 'Night view',
description: '4.21M views',
},
{
src: 'https://images.unsplash.com/photo-1527549993586-dff825b37782',
title: 'Lake view',
description: '4.74M views',
},
{
src: 'https://images.unsplash.com/photo-1532614338840-ab30cf10ed36',
title: 'Mountain view',
description: '3.98M views',
},
];
export default function CarouselRatio() {
return (
<Box
sx={{
display: 'flex',
gap: 1,
py: 1,
overflow: 'auto',
width: 343,
scrollSnapType: 'x mandatory',
'& > *': {
scrollSnapAlign: 'center',
},
'::-webkit-scrollbar': { display: 'none' },
}}
>
{data.map((item) => (
<Card orientation="horizontal" size="sm" key={item.title} variant="outlined">
<AspectRatio ratio="1" sx={{ minWidth: 60 }}>
<img
srcSet={`${item.src}?h=120&fit=crop&auto=format&dpr=2 2x`}
src={`${item.src}?h=120&fit=crop&auto=format`}
alt={item.title}
/>
</AspectRatio>
<Box sx={{ whiteSpace: 'nowrap', mx: 1 }}>
<Typography level="title-md">{item.title}</Typography>
<Typography level="body-sm">{item.description}</Typography>
</Box>
</Card>
))}
</Box>
);
}
| 685 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CarouselRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Typography from '@mui/joy/Typography';
import Card from '@mui/joy/Card';
const data = [
{
src: 'https://images.unsplash.com/photo-1502657877623-f66bf489d236',
title: 'Night view',
description: '4.21M views',
},
{
src: 'https://images.unsplash.com/photo-1527549993586-dff825b37782',
title: 'Lake view',
description: '4.74M views',
},
{
src: 'https://images.unsplash.com/photo-1532614338840-ab30cf10ed36',
title: 'Mountain view',
description: '3.98M views',
},
];
export default function CarouselRatio() {
return (
<Box
sx={{
display: 'flex',
gap: 1,
py: 1,
overflow: 'auto',
width: 343,
scrollSnapType: 'x mandatory',
'& > *': {
scrollSnapAlign: 'center',
},
'::-webkit-scrollbar': { display: 'none' },
}}
>
{data.map((item) => (
<Card orientation="horizontal" size="sm" key={item.title} variant="outlined">
<AspectRatio ratio="1" sx={{ minWidth: 60 }}>
<img
srcSet={`${item.src}?h=120&fit=crop&auto=format&dpr=2 2x`}
src={`${item.src}?h=120&fit=crop&auto=format`}
alt={item.title}
/>
</AspectRatio>
<Box sx={{ whiteSpace: 'nowrap', mx: 1 }}>
<Typography level="title-md">{item.title}</Typography>
<Typography level="body-sm">{item.description}</Typography>
</Box>
</Card>
))}
</Box>
);
}
| 686 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CarouselRatio.tsx.preview | {data.map((item) => (
<Card orientation="horizontal" size="sm" key={item.title} variant="outlined">
<AspectRatio ratio="1" sx={{ minWidth: 60 }}>
<img
srcSet={`${item.src}?h=120&fit=crop&auto=format&dpr=2 2x`}
src={`${item.src}?h=120&fit=crop&auto=format`}
alt={item.title}
/>
</AspectRatio>
<Box sx={{ whiteSpace: 'nowrap', mx: 1 }}>
<Typography level="title-md">{item.title}</Typography>
<Typography level="body-sm">{item.description}</Typography>
</Box>
</Card>
))} | 687 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CustomRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
export default function CustomRatio() {
return (
<AspectRatio
variant="outlined"
ratio="4/3"
sx={{
width: 300,
bgcolor: 'background.level2',
borderRadius: 'md',
}}
>
<Typography level="h2" component="div">
4/3
</Typography>
</AspectRatio>
);
}
| 688 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CustomRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
export default function CustomRatio() {
return (
<AspectRatio
variant="outlined"
ratio="4/3"
sx={{
width: 300,
bgcolor: 'background.level2',
borderRadius: 'md',
}}
>
<Typography level="h2" component="div">
4/3
</Typography>
</AspectRatio>
);
}
| 689 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/CustomRatio.tsx.preview | <AspectRatio
variant="outlined"
ratio="4/3"
sx={{
width: 300,
bgcolor: 'background.level2',
borderRadius: 'md',
}}
>
<Typography level="h2" component="div">
4/3
</Typography>
</AspectRatio> | 690 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/FlexAspectRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Button from '@mui/joy/Button';
import Card from '@mui/joy/Card';
import CardContent from '@mui/joy/CardContent';
import CardActions from '@mui/joy/CardActions';
import Typography from '@mui/joy/Typography';
import Stack from '@mui/joy/Stack';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Switch from '@mui/joy/Switch';
export default function FlexAspectRatio() {
const [flex, setFlex] = React.useState(false);
return (
<Stack spacing={2} alignItems="center">
<FormControl orientation="horizontal">
<FormLabel>Flex</FormLabel>
<Switch checked={flex} onChange={(event) => setFlex(event.target.checked)} />
</FormControl>
<Card
orientation="horizontal"
variant="outlined"
sx={{ boxShadow: 'none', resize: 'horizontal', overflow: 'auto' }}
>
<AspectRatio ratio="21/9" flex={flex} sx={{ flexBasis: 200 }}>
<Typography level="h1" component="div">
21 / 9
</Typography>
</AspectRatio>
<CardContent>
<Typography level="body-xs">20 APR 2023</Typography>
<Typography level="title-lg" component="div">
Widget Title
</Typography>
<Typography level="body-lg">
Lorem ipsum is placeholder text commonly used in the graphic.
</Typography>
<CardActions buttonFlex="none">
<Button variant="outlined" color="neutral" size="sm">
See details
</Button>
<Button variant="solid" color="neutral" size="sm">
Learn more
</Button>
</CardActions>
</CardContent>
</Card>
</Stack>
);
}
| 691 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/FlexAspectRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Button from '@mui/joy/Button';
import Card from '@mui/joy/Card';
import CardContent from '@mui/joy/CardContent';
import CardActions from '@mui/joy/CardActions';
import Typography from '@mui/joy/Typography';
import Stack from '@mui/joy/Stack';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Switch from '@mui/joy/Switch';
export default function FlexAspectRatio() {
const [flex, setFlex] = React.useState(false);
return (
<Stack spacing={2} alignItems="center">
<FormControl orientation="horizontal">
<FormLabel>Flex</FormLabel>
<Switch checked={flex} onChange={(event) => setFlex(event.target.checked)} />
</FormControl>
<Card
orientation="horizontal"
variant="outlined"
sx={{ boxShadow: 'none', resize: 'horizontal', overflow: 'auto' }}
>
<AspectRatio ratio="21/9" flex={flex} sx={{ flexBasis: 200 }}>
<Typography level="h1" component="div">
21 / 9
</Typography>
</AspectRatio>
<CardContent>
<Typography level="body-xs">20 APR 2023</Typography>
<Typography level="title-lg" component="div">
Widget Title
</Typography>
<Typography level="body-lg">
Lorem ipsum is placeholder text commonly used in the graphic.
</Typography>
<CardActions buttonFlex="none">
<Button variant="outlined" color="neutral" size="sm">
See details
</Button>
<Button variant="solid" color="neutral" size="sm">
Learn more
</Button>
</CardActions>
</CardContent>
</Card>
</Stack>
);
}
| 692 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/FlexRowRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Card from '@mui/joy/Card';
import Typography from '@mui/joy/Typography';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
export default function FlexRowRatio() {
const [flexBasis, setFlexBasis] = React.useState(200);
return (
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Card
variant="outlined"
size="sm"
orientation="horizontal"
sx={{ gap: 2, minWidth: 300 }}
>
<AspectRatio
sx={{
flexBasis: flexBasis ? `${flexBasis}px` : undefined,
overflow: 'auto',
}}
>
<img
src="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800"
srcSet="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800&dpr=2 2x"
alt=""
/>
</AspectRatio>
<div>
<Typography level="title-sm">Yosemite National Park</Typography>
<Typography level="body-sm">California, USA</Typography>
</div>
</Card>
<br />
<FormControl sx={{ mx: 'auto', width: '100%' }}>
<FormLabel>flexBasis</FormLabel>
<Input
variant="outlined"
type="number"
placeholder="number"
value={flexBasis}
endDecorator="px"
onChange={(event) => setFlexBasis(event.target.valueAsNumber)}
/>
</FormControl>
</Box>
);
}
| 693 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/FlexRowRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Card from '@mui/joy/Card';
import Typography from '@mui/joy/Typography';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
export default function FlexRowRatio() {
const [flexBasis, setFlexBasis] = React.useState(200);
return (
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Card
variant="outlined"
size="sm"
orientation="horizontal"
sx={{ gap: 2, minWidth: 300 }}
>
<AspectRatio
sx={{
flexBasis: flexBasis ? `${flexBasis}px` : undefined,
overflow: 'auto',
}}
>
<img
src="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800"
srcSet="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800&dpr=2 2x"
alt=""
/>
</AspectRatio>
<div>
<Typography level="title-sm">Yosemite National Park</Typography>
<Typography level="body-sm">California, USA</Typography>
</div>
</Card>
<br />
<FormControl sx={{ mx: 'auto', width: '100%' }}>
<FormLabel>flexBasis</FormLabel>
<Input
variant="outlined"
type="number"
placeholder="number"
value={flexBasis}
endDecorator="px"
onChange={(event) => setFlexBasis(event.target.valueAsNumber)}
/>
</FormControl>
</Box>
);
}
| 694 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/IconWrapper.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Stack from '@mui/joy/Stack';
import Favorite from '@mui/icons-material/Favorite';
export default function IconWrapper() {
return (
<Stack direction="row" spacing={2}>
<AspectRatio ratio="1" variant="solid" color="primary" sx={{ minWidth: 40 }}>
{/* an extra div is required to make the icon center */}
<div>
<Favorite />
</div>
</AspectRatio>
<AspectRatio
ratio="1"
variant="outlined"
color="success"
sx={{ minWidth: 40, borderRadius: 'sm' }}
>
<div>
<Favorite />
</div>
</AspectRatio>
<AspectRatio
ratio="1"
variant="soft"
color="danger"
sx={{ minWidth: 40, borderRadius: '50%' }}
>
<div>
<Favorite />
</div>
</AspectRatio>
</Stack>
);
}
| 695 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/IconWrapper.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Stack from '@mui/joy/Stack';
import Favorite from '@mui/icons-material/Favorite';
export default function IconWrapper() {
return (
<Stack direction="row" spacing={2}>
<AspectRatio ratio="1" variant="solid" color="primary" sx={{ minWidth: 40 }}>
{/* an extra div is required to make the icon center */}
<div>
<Favorite />
</div>
</AspectRatio>
<AspectRatio
ratio="1"
variant="outlined"
color="success"
sx={{ minWidth: 40, borderRadius: 'sm' }}
>
<div>
<Favorite />
</div>
</AspectRatio>
<AspectRatio
ratio="1"
variant="soft"
color="danger"
sx={{ minWidth: 40, borderRadius: '50%' }}
>
<div>
<Favorite />
</div>
</AspectRatio>
</Stack>
);
}
| 696 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/ListStackRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
import Card from '@mui/joy/Card';
import List from '@mui/joy/List';
import ListDivider from '@mui/joy/ListDivider';
import ListItem from '@mui/joy/ListItem';
import ListItemContent from '@mui/joy/ListItemContent';
import ListItemButton from '@mui/joy/ListItemButton';
const data = [
{
src: 'https://images.unsplash.com/photo-1502657877623-f66bf489d236',
title: 'Night view',
description: '4.21M views',
},
{
src: 'https://images.unsplash.com/photo-1527549993586-dff825b37782',
title: 'Lake view',
description: '4.74M views',
},
{
src: 'https://images.unsplash.com/photo-1532614338840-ab30cf10ed36',
title: 'Mountain view',
description: '3.98M views',
},
];
export default function ListStackRatio() {
return (
<Card variant="outlined" sx={{ width: 300, p: 0 }}>
<List sx={{ py: 'var(--ListDivider-gap)' }}>
{data.map((item, index) => (
<React.Fragment key={item.title}>
<ListItem>
<ListItemButton sx={{ gap: 2 }}>
<AspectRatio sx={{ flexBasis: 120 }}>
<img
srcSet={`${item.src}?w=120&fit=crop&auto=format&dpr=2 2x`}
src={`${item.src}?w=120&fit=crop&auto=format`}
alt={item.title}
/>
</AspectRatio>
<ListItemContent>
<Typography fontWeight="md">{item.title}</Typography>
<Typography level="body-sm">{item.description}</Typography>
</ListItemContent>
</ListItemButton>
</ListItem>
{index !== data.length - 1 && <ListDivider />}
</React.Fragment>
))}
</List>
</Card>
);
}
| 697 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/ListStackRatio.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Typography from '@mui/joy/Typography';
import Card from '@mui/joy/Card';
import List from '@mui/joy/List';
import ListDivider from '@mui/joy/ListDivider';
import ListItem from '@mui/joy/ListItem';
import ListItemContent from '@mui/joy/ListItemContent';
import ListItemButton from '@mui/joy/ListItemButton';
const data = [
{
src: 'https://images.unsplash.com/photo-1502657877623-f66bf489d236',
title: 'Night view',
description: '4.21M views',
},
{
src: 'https://images.unsplash.com/photo-1527549993586-dff825b37782',
title: 'Lake view',
description: '4.74M views',
},
{
src: 'https://images.unsplash.com/photo-1532614338840-ab30cf10ed36',
title: 'Mountain view',
description: '3.98M views',
},
];
export default function ListStackRatio() {
return (
<Card variant="outlined" sx={{ width: 300, p: 0 }}>
<List sx={{ py: 'var(--ListDivider-gap)' }}>
{data.map((item, index) => (
<React.Fragment key={item.title}>
<ListItem>
<ListItemButton sx={{ gap: 2 }}>
<AspectRatio sx={{ flexBasis: 120 }}>
<img
srcSet={`${item.src}?w=120&fit=crop&auto=format&dpr=2 2x`}
src={`${item.src}?w=120&fit=crop&auto=format`}
alt={item.title}
/>
</AspectRatio>
<ListItemContent>
<Typography fontWeight="md">{item.title}</Typography>
<Typography level="body-sm">{item.description}</Typography>
</ListItemContent>
</ListItemButton>
</ListItem>
{index !== data.length - 1 && <ListDivider />}
</React.Fragment>
))}
</List>
</Card>
);
}
| 698 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/aspect-ratio/MediaRatio.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
export default function MediaRatio() {
return (
<Box sx={{ width: 300, borderRadius: 'sm', p: 1 }}>
<AspectRatio objectFit="contain">
<img
src="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800"
srcSet="https://images.unsplash.com/photo-1502657877623-f66bf489d236?auto=format&fit=crop&w=800&dpr=2 2x"
alt="A beautiful landscape."
/>
</AspectRatio>
</Box>
);
}
| 699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.