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/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/switch/SwitchUsage.js | import * as React from 'react';
import Switch from '@mui/joy/Switch';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function SwitchUsage() {
const [checked, setChecked] = React.useState(false);
return (
<JoyUsageDemo
componentName="Switch"
data={[
{
propName: 'variant',
knob: 'radio',
options: ['plain', 'outlined', 'soft', 'solid'],
defaultValue: 'solid',
},
{
formLabel: 'Checked color',
propName: 'color',
knob: 'color',
defaultValue: 'primary',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{ propName: 'disabled', knob: 'switch' },
]}
renderDemo={(props) => (
<Switch
{...props}
color={checked ? props.color : undefined}
checked={checked}
onChange={(event) => setChecked(event.target.checked)}
/>
)}
/>
);
}
| 1,600 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/switch/SwitchVariables.js | import * as React from 'react';
import Switch from '@mui/joy/Switch';
import Typography from '@mui/joy/Typography';
import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo';
export default function SwitchVariables() {
return (
<JoyVariablesDemo
componentName="Switch"
data={[
{ var: '--Switch-gap', defaultValue: '8px' },
[
'Track',
[
{ var: '--Switch-trackRadius', defaultValue: '16px' },
{ var: '--Switch-trackWidth', defaultValue: '48px' },
{ var: '--Switch-trackHeight', defaultValue: '24px' },
],
{ defaultOpen: true },
],
[
'Thumb',
[
{ var: '--Switch-thumbSize', defaultValue: '16px' },
{ var: '--Switch-thumbRadius' },
{ var: '--Switch-thumbWidth' },
{ var: '--Switch-thumbOffset' },
],
],
]}
renderDemo={(sx) => (
<Switch
sx={sx}
startDecorator={<Typography>Off</Typography>}
endDecorator={<Typography>On</Typography>}
/>
)}
/>
);
}
| 1,601 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/switch/switch.md | ---
productId: joy-ui
title: React Switch component
components: Switch
githubLabel: 'component: switch'
unstyled: /base-ui/react-switch/
---
# Switch
<p class="description">Switches toggle the state of a single setting on or off.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
Switches are very commonly used for adjusting settings on mobile.
The option that the switch controls, as well as the state it's in,
should be made clear from the corresponding inline label.
{{"demo": "SwitchUsage.js", "hideToolbar": true, "bg": "gradient"}}
## Component
After [installation](/joy-ui/getting-started/installation/), you can start building with this component using the following basic elements:
```jsx
import Switch from '@mui/joy/Switch';
export default function MyApp() {
return <Switch />;
}
```
### Controlled
To create a controlled switch, use the `checked` and `onChange` props.
:::info
- A component is **controlled** when it's managed by its parent using props.
- A component is **uncontrolled** when it's managed by its own local state.
Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components).
:::
{{"demo": "SwitchControlled.js"}}
:::info
By default, the color of the switch changes from `neutral` to `primary` when it is checked unless you specify the `color` prop directly to the component.
:::
### Label
When a `Switch` is used together with `FormControl` and `FormLabel`, the switch is labelled automatically. You can also use `FormHelperText` to include a description to the switch as well.
{{"demo": "SwitchControl.js"}}
An alternative way is to place the `Switch` component inside a label element. The `Typography` is used in this case to leverage the typography scale from the theme.
{{"demo": "SwitchLabel.js"}}
### Decorators
To insert icon decorators, use the `startDecorator` and/or `endDecorator` props.
{{"demo": "SwitchDecorators.js"}}
### Track child
Target the track's children using the `slotProps` prop to display a text inside of it.
{{"demo": "ExampleTrackChild.js"}}
:::warning
The track text **should not** be used to label the switch, you should use [proper methods](#label) to achieve it.
:::
### Thumb child
Similarly to the above, target the thumb's children to display icons inside of it.
{{"demo": "ExampleThumbChild.js"}}
## CSS variables playground
Play around with all the CSS variables available in the switch component to see how the design changes.
You can use those to customize the component on both the `sx` prop and the theme.
{{"demo": "SwitchVariables.js", "hideToolbar": true, "bg": "gradient"}}
## Common examples
### Fluent UI
Here's how you'd customize Joy UI's Switch to make it look like [Microsoft's Fluent UI](https://developer.microsoft.com/en-us/fluentui#/controls/web/toggle):
- Unchecked state: `outlined` variant and `neutral` color.
- Checked state: `solid` variant and `primary` color.
{{"demo": "ExampleFluentSwitch.js"}}
### iOS
Note how we've used the `:active` pseudo-class to replicate the small thumb size increase, which happens when you press and hold the switch.
{{"demo": "ExampleIosSwitch.js"}}
### Strapi
{{"demo": "ExampleStrapiSwitch.js"}}
### Chakra UI
{{"demo": "ExampleChakraSwitch.js"}}
### Tailwind UI
{{"demo": "ExampleTailwindSwitch.js"}}
### Mantine
{{"demo": "ExampleMantineSwitch.js"}}
## Accessibility
Here are a few tips to make sure you have an accessible switch component:
- The `Switch` will render with the `checkbox` role as opposed to `switch`.
This is mainly because the latter isn't widely supported yet.
However, if you believe your audience will support it, make sure to test with assistive technology.
Use the `slotProps` prop to change the role:
```jsx
<Switch slotProps={{ input: { role: 'switch' } }}>
```
- Every form control component should have proper labels.
This includes radio buttons, checkboxes, and switches.
In most cases, this is done using the `<label>` element.
- If a label can't be applied, make sure to add an attribute (e.g. `aria-label`, `aria-labelledby`, `title`) to the input slot inside the `slotProps` prop.
```jsx
<Switch value="checkedA" slotProps={{ 'aria-label': 'Switch A' }} />
```
| 1,602 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/BasicTable.js | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function BasicTable() {
return (
<Table aria-label="basic table">
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Frozen yoghurt</td>
<td>159</td>
<td>6</td>
<td>24</td>
<td>4</td>
</tr>
<tr>
<td>Ice cream sandwich</td>
<td>237</td>
<td>9</td>
<td>37</td>
<td>4.3</td>
</tr>
<tr>
<td>Eclair</td>
<td>262</td>
<td>16</td>
<td>24</td>
<td>6</td>
</tr>
<tr>
<td>Cupcake</td>
<td>305</td>
<td>3.7</td>
<td>67</td>
<td>4.3</td>
</tr>
<tr>
<td>Gingerbread</td>
<td>356</td>
<td>16</td>
<td>49</td>
<td>3.9</td>
</tr>
</tbody>
</Table>
);
}
| 1,603 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/BasicTable.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function BasicTable() {
return (
<Table aria-label="basic table">
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Frozen yoghurt</td>
<td>159</td>
<td>6</td>
<td>24</td>
<td>4</td>
</tr>
<tr>
<td>Ice cream sandwich</td>
<td>237</td>
<td>9</td>
<td>37</td>
<td>4.3</td>
</tr>
<tr>
<td>Eclair</td>
<td>262</td>
<td>16</td>
<td>24</td>
<td>6</td>
</tr>
<tr>
<td>Cupcake</td>
<td>305</td>
<td>3.7</td>
<td>67</td>
<td>4.3</td>
</tr>
<tr>
<td>Gingerbread</td>
<td>356</td>
<td>16</td>
<td>49</td>
<td>3.9</td>
</tr>
</tbody>
</Table>
);
}
| 1,604 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableAlignment.js | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableAlignment() {
return (
<Table sx={{ '& tr > *:not(:first-child)': { textAlign: 'right' } }}>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,605 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableAlignment.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableAlignment() {
return (
<Table sx={{ '& tr > *:not(:first-child)': { textAlign: 'right' } }}>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,606 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableBorder.js | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableBorder() {
const [borderAxis, setBorderAxis] = React.useState('xBetween');
return (
<div>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Border axis:</FormLabel>
<Select
size="sm"
value={borderAxis}
onChange={(event, newValue) => setBorderAxis(newValue)}
>
{['xBetween', 'x', 'yBetween', 'y', 'bothBetween', 'both', 'none'].map(
(axis) => (
<Option key={axis} value={axis}>
{axis}
</Option>
),
)}
</Select>
</FormControl>
<Table borderAxis={borderAxis}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,607 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableBorder.tsx | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Table, { TableProps } from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableBorder() {
const [borderAxis, setBorderAxis] =
React.useState<TableProps['borderAxis']>('xBetween');
return (
<div>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Border axis:</FormLabel>
<Select
size="sm"
value={borderAxis}
onChange={(event, newValue) => setBorderAxis(newValue!)}
>
{['xBetween', 'x', 'yBetween', 'y', 'bothBetween', 'both', 'none'].map(
(axis) => (
<Option key={axis} value={axis}>
{axis}
</Option>
),
)}
</Select>
</FormControl>
<Table borderAxis={borderAxis}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,608 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableCaption.js | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableCaption() {
return (
<Table>
<caption>A caption should be a summary of the table.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Menu</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,609 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableCaption.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableCaption() {
return (
<Table>
<caption>A caption should be a summary of the table.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Menu</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,610 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableCollapsibleRow.js | import * as React from 'react';
import PropTypes from 'prop-types';
import IconButton from '@mui/joy/IconButton';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
function createData(name, calories, fat, carbs, protein, price) {
return {
name,
calories,
fat,
carbs,
protein,
price,
history: [
{
date: '2020-01-05',
customerId: '11091700',
amount: 3,
},
{
date: '2020-01-02',
customerId: 'Anonymous',
amount: 1,
},
],
};
}
function Row(props) {
const { row } = props;
const [open, setOpen] = React.useState(props.initialOpen || false);
return (
<React.Fragment>
<tr>
<td>
<IconButton
aria-label="expand row"
variant="plain"
color="neutral"
size="sm"
onClick={() => setOpen(!open)}
>
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>
</td>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
<tr>
<td style={{ height: 0, padding: 0 }} colSpan={6}>
{open && (
<Sheet
variant="soft"
sx={{ p: 1, pl: 6, boxShadow: 'inset 0 3px 6px 0 rgba(0 0 0 / 0.08)' }}
>
<Typography level="body-lg" component="div">
History
</Typography>
<Table
borderAxis="bothBetween"
size="sm"
aria-label="purchases"
sx={{
'& > thead > tr > th:nth-child(n + 3), & > tbody > tr > td:nth-child(n + 3)':
{ textAlign: 'right' },
'--TableCell-paddingX': '0.5rem',
}}
>
<thead>
<tr>
<th>Date</th>
<th>Customer</th>
<th>Amount</th>
<th>Total price ($)</th>
</tr>
</thead>
<tbody>
{row.history.map((historyRow) => (
<tr key={historyRow.date}>
<th scope="row">{historyRow.date}</th>
<td>{historyRow.customerId}</td>
<td>{historyRow.amount}</td>
<td>
{Math.round(historyRow.amount * row.price * 100) / 100}
</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
)}
</td>
</tr>
</React.Fragment>
);
}
Row.propTypes = {
initialOpen: PropTypes.bool,
row: PropTypes.shape({
calories: PropTypes.number.isRequired,
carbs: PropTypes.number.isRequired,
fat: PropTypes.number.isRequired,
history: PropTypes.arrayOf(
PropTypes.shape({
amount: PropTypes.number.isRequired,
customerId: PropTypes.string.isRequired,
date: PropTypes.string.isRequired,
}),
).isRequired,
name: PropTypes.string.isRequired,
price: PropTypes.number.isRequired,
protein: PropTypes.number.isRequired,
}).isRequired,
};
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0, 3.99),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3, 4.99),
createData('Eclair', 262, 16.0, 24, 6.0, 3.79),
createData('Cupcake', 305, 3.7, 67, 4.3, 2.5),
createData('Gingerbread', 356, 16.0, 49, 3.9, 1.5),
];
export default function TableCollapsibleRow() {
return (
<Sheet>
<Table
aria-label="collapsible table"
sx={{
'& > thead > tr > th:nth-child(n + 3), & > tbody > tr > td:nth-child(n + 3)':
{ textAlign: 'right' },
'& > tbody > tr:nth-child(odd) > td, & > tbody > tr:nth-child(odd) > th[scope="row"]':
{
borderBottom: 0,
},
}}
>
<thead>
<tr>
<th style={{ width: 40 }} aria-label="empty" />
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row, index) => (
<Row key={row.name} row={row} initialOpen={index === 0} />
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,611 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableCollapsibleRow.tsx | import * as React from 'react';
import IconButton from '@mui/joy/IconButton';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
price: number,
) {
return {
name,
calories,
fat,
carbs,
protein,
price,
history: [
{
date: '2020-01-05',
customerId: '11091700',
amount: 3,
},
{
date: '2020-01-02',
customerId: 'Anonymous',
amount: 1,
},
],
};
}
function Row(props: { row: ReturnType<typeof createData>; initialOpen?: boolean }) {
const { row } = props;
const [open, setOpen] = React.useState(props.initialOpen || false);
return (
<React.Fragment>
<tr>
<td>
<IconButton
aria-label="expand row"
variant="plain"
color="neutral"
size="sm"
onClick={() => setOpen(!open)}
>
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>
</td>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
<tr>
<td style={{ height: 0, padding: 0 }} colSpan={6}>
{open && (
<Sheet
variant="soft"
sx={{ p: 1, pl: 6, boxShadow: 'inset 0 3px 6px 0 rgba(0 0 0 / 0.08)' }}
>
<Typography level="body-lg" component="div">
History
</Typography>
<Table
borderAxis="bothBetween"
size="sm"
aria-label="purchases"
sx={{
'& > thead > tr > th:nth-child(n + 3), & > tbody > tr > td:nth-child(n + 3)':
{ textAlign: 'right' },
'--TableCell-paddingX': '0.5rem',
}}
>
<thead>
<tr>
<th>Date</th>
<th>Customer</th>
<th>Amount</th>
<th>Total price ($)</th>
</tr>
</thead>
<tbody>
{row.history.map((historyRow) => (
<tr key={historyRow.date}>
<th scope="row">{historyRow.date}</th>
<td>{historyRow.customerId}</td>
<td>{historyRow.amount}</td>
<td>
{Math.round(historyRow.amount * row.price * 100) / 100}
</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
)}
</td>
</tr>
</React.Fragment>
);
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0, 3.99),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3, 4.99),
createData('Eclair', 262, 16.0, 24, 6.0, 3.79),
createData('Cupcake', 305, 3.7, 67, 4.3, 2.5),
createData('Gingerbread', 356, 16.0, 49, 3.9, 1.5),
];
export default function TableCollapsibleRow() {
return (
<Sheet>
<Table
aria-label="collapsible table"
sx={{
'& > thead > tr > th:nth-child(n + 3), & > tbody > tr > td:nth-child(n + 3)':
{ textAlign: 'right' },
'& > tbody > tr:nth-child(odd) > td, & > tbody > tr:nth-child(odd) > th[scope="row"]':
{
borderBottom: 0,
},
}}
>
<thead>
<tr>
<th style={{ width: 40 }} aria-label="empty" />
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row, index) => (
<Row key={row.name} row={row} initialOpen={index === 0} />
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,612 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableColumnPinning.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
];
export default function TableColumnPinning() {
return (
<Box sx={{ width: '100%' }}>
<Typography level="body-sm" textAlign="center" sx={{ pb: 2 }}>
← Scroll direction →
</Typography>
<Sheet
variant="outlined"
sx={{
'--TableCell-height': '40px',
// the number is the amount of the header rows.
'--TableHeader-height': 'calc(1 * var(--TableCell-height))',
'--Table-firstColumnWidth': '80px',
'--Table-lastColumnWidth': '144px',
// background needs to have transparency to show the scrolling shadows
'--TableRow-stripeBackground': 'rgba(0 0 0 / 0.04)',
'--TableRow-hoverBackground': 'rgba(0 0 0 / 0.08)',
overflow: 'auto',
background: (theme) =>
`linear-gradient(to right, ${theme.vars.palette.background.surface} 30%, rgba(255, 255, 255, 0)),
linear-gradient(to right, rgba(255, 255, 255, 0), ${theme.vars.palette.background.surface} 70%) 0 100%,
radial-gradient(
farthest-side at 0 50%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
),
radial-gradient(
farthest-side at 100% 50%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
)
0 100%`,
backgroundSize:
'40px calc(100% - var(--TableCell-height)), 40px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height))',
backgroundRepeat: 'no-repeat',
backgroundAttachment: 'local, local, scroll, scroll',
backgroundPosition:
'var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height), var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height)',
backgroundColor: 'background.surface',
}}
>
<Table
borderAxis="bothBetween"
stripe="odd"
hoverRow
sx={{
'& tr > *:first-child': {
position: 'sticky',
left: 0,
boxShadow: '1px 0 var(--TableCell-borderColor)',
bgcolor: 'background.surface',
},
'& tr > *:last-child': {
position: 'sticky',
right: 0,
bgcolor: 'var(--TableCell-headBackground)',
},
}}
>
<thead>
<tr>
<th style={{ width: 'var(--Table-firstColumnWidth)' }}>Row</th>
<th style={{ width: 200 }}>Calories</th>
<th style={{ width: 200 }}>Fat (g)</th>
<th style={{ width: 200 }}>Carbs (g)</th>
<th style={{ width: 200 }}>Protein (g)</th>
<th
aria-label="last"
style={{ width: 'var(--Table-lastColumnWidth)' }}
/>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
<td>
<Box sx={{ display: 'flex', gap: 1 }}>
<Button size="sm" variant="plain" color="neutral">
Edit
</Button>
<Button size="sm" variant="soft" color="danger">
Delete
</Button>
</Box>
</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
</Box>
);
}
| 1,613 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableColumnPinning.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
];
export default function TableColumnPinning() {
return (
<Box sx={{ width: '100%' }}>
<Typography level="body-sm" textAlign="center" sx={{ pb: 2 }}>
← Scroll direction →
</Typography>
<Sheet
variant="outlined"
sx={{
'--TableCell-height': '40px',
// the number is the amount of the header rows.
'--TableHeader-height': 'calc(1 * var(--TableCell-height))',
'--Table-firstColumnWidth': '80px',
'--Table-lastColumnWidth': '144px',
// background needs to have transparency to show the scrolling shadows
'--TableRow-stripeBackground': 'rgba(0 0 0 / 0.04)',
'--TableRow-hoverBackground': 'rgba(0 0 0 / 0.08)',
overflow: 'auto',
background: (
theme,
) => `linear-gradient(to right, ${theme.vars.palette.background.surface} 30%, rgba(255, 255, 255, 0)),
linear-gradient(to right, rgba(255, 255, 255, 0), ${theme.vars.palette.background.surface} 70%) 0 100%,
radial-gradient(
farthest-side at 0 50%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
),
radial-gradient(
farthest-side at 100% 50%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
)
0 100%`,
backgroundSize:
'40px calc(100% - var(--TableCell-height)), 40px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height))',
backgroundRepeat: 'no-repeat',
backgroundAttachment: 'local, local, scroll, scroll',
backgroundPosition:
'var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height), var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height)',
backgroundColor: 'background.surface',
}}
>
<Table
borderAxis="bothBetween"
stripe="odd"
hoverRow
sx={{
'& tr > *:first-child': {
position: 'sticky',
left: 0,
boxShadow: '1px 0 var(--TableCell-borderColor)',
bgcolor: 'background.surface',
},
'& tr > *:last-child': {
position: 'sticky',
right: 0,
bgcolor: 'var(--TableCell-headBackground)',
},
}}
>
<thead>
<tr>
<th style={{ width: 'var(--Table-firstColumnWidth)' }}>Row</th>
<th style={{ width: 200 }}>Calories</th>
<th style={{ width: 200 }}>Fat (g)</th>
<th style={{ width: 200 }}>Carbs (g)</th>
<th style={{ width: 200 }}>Protein (g)</th>
<th
aria-label="last"
style={{ width: 'var(--Table-lastColumnWidth)' }}
/>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
<td>
<Box sx={{ display: 'flex', gap: 1 }}>
<Button size="sm" variant="plain" color="neutral">
Edit
</Button>
<Button size="sm" variant="soft" color="danger">
Delete
</Button>
</Box>
</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
</Box>
);
}
| 1,614 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableColumnWidth.js | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableColumnWidth() {
return (
<Table sx={{ '& thead th:nth-child(1)': { width: '40%' } }}>
<thead>
<tr>
<th>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,615 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableColumnWidth.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableColumnWidth() {
return (
<Table sx={{ '& thead th:nth-child(1)': { width: '40%' } }}>
<thead>
<tr>
<th>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,616 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableFooter.js | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableFooter() {
return (
<Table borderAxis="both">
<caption>A caption should be a summary of the table.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Menu</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td>1,319</td>
<td>50.7</td>
<td>201</td>
<td>22.5</td>
</tr>
</tfoot>
</Table>
);
}
| 1,617 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableFooter.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableFooter() {
return (
<Table borderAxis="both">
<caption>A caption should be a summary of the table.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Menu</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td>1,319</td>
<td>50.7</td>
<td>201</td>
<td>22.5</td>
</tr>
</tfoot>
</Table>
);
}
| 1,618 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableGlobalVariant.js | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function TableGlobalVariant() {
return (
<Table
stickyHeader
sx={(theme) => ({
'& tr > *:first-child': { bgcolor: 'success.softBg' },
'& th[scope="col"]': theme.variants.solid.neutral,
'& td': theme.variants.soft.neutral,
})}
>
<caption>Alien football stars</caption>
<tbody>
<tr>
<th scope="col">Player</th>
<th scope="col">Gloobles</th>
<th scope="col">Za'taak</th>
</tr>
<tr>
<th scope="row">TR-7</th>
<td>7</td>
<td>4,569</td>
</tr>
<tr>
<th scope="row">Khiresh Odo</th>
<td>7</td>
<td>7,223</td>
</tr>
<tr>
<th scope="row">Mia Oolong</th>
<td>9</td>
<td>6,219</td>
</tr>
</tbody>
</Table>
);
}
| 1,619 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableGlobalVariant.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function TableGlobalVariant() {
return (
<Table
stickyHeader
sx={(theme) => ({
'& tr > *:first-child': { bgcolor: 'success.softBg' },
'& th[scope="col"]': theme.variants.solid.neutral,
'& td': theme.variants.soft.neutral,
})}
>
<caption>Alien football stars</caption>
<tbody>
<tr>
<th scope="col">Player</th>
<th scope="col">Gloobles</th>
<th scope="col">Za'taak</th>
</tr>
<tr>
<th scope="row">TR-7</th>
<td>7</td>
<td>4,569</td>
</tr>
<tr>
<th scope="row">Khiresh Odo</th>
<td>7</td>
<td>7,223</td>
</tr>
<tr>
<th scope="row">Mia Oolong</th>
<td>9</td>
<td>6,219</td>
</tr>
</tbody>
</Table>
);
}
| 1,620 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableHover.js | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableHover() {
return (
<Table hoverRow>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,621 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableHover.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableHover() {
return (
<Table hoverRow>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
);
}
| 1,622 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableRowColumnSpan.js | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function TableRowColumnSpan() {
return (
<Table borderAxis="both">
<thead>
<tr>
<th rowSpan={2}>Name</th>
<th rowSpan={2}>ID</th>
<th colSpan={2} style={{ textAlign: 'center' }}>
Membership Dates
</th>
<th rowSpan={2}>Balance</th>
</tr>
<tr>
<th>Joined</th>
<th style={{ borderRightWidth: 0 }}>Canceled</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Margaret Nguyen</th>
<td>427311</td>
<td>
<time dateTime="2010-06-03">June 3, 2010</time>
</td>
<td>n/a</td>
<td>0.00</td>
</tr>
<tr>
<th scope="row">Edvard Galinski</th>
<td>533175</td>
<td>
<time dateTime="2011-01-13">January 13, 2011</time>
</td>
<td>
<time dateTime="2017-04-08">April 8, 2017</time>
</td>
<td>37.00</td>
</tr>
<tr>
<th scope="row">Hoshi Nakamura</th>
<td>601942</td>
<td>
<time dateTime="2012-07-23">July 23, 2012</time>
</td>
<td>n/a</td>
<td>15.00</td>
</tr>
</tbody>
</Table>
);
}
| 1,623 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableRowColumnSpan.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
export default function TableRowColumnSpan() {
return (
<Table borderAxis="both">
<thead>
<tr>
<th rowSpan={2}>Name</th>
<th rowSpan={2}>ID</th>
<th colSpan={2} style={{ textAlign: 'center' }}>
Membership Dates
</th>
<th rowSpan={2}>Balance</th>
</tr>
<tr>
<th>Joined</th>
<th style={{ borderRightWidth: 0 }}>Canceled</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Margaret Nguyen</th>
<td>427311</td>
<td>
<time dateTime="2010-06-03">June 3, 2010</time>
</td>
<td>n/a</td>
<td>0.00</td>
</tr>
<tr>
<th scope="row">Edvard Galinski</th>
<td>533175</td>
<td>
<time dateTime="2011-01-13">January 13, 2011</time>
</td>
<td>
<time dateTime="2017-04-08">April 8, 2017</time>
</td>
<td>37.00</td>
</tr>
<tr>
<th scope="row">Hoshi Nakamura</th>
<td>601942</td>
<td>
<time dateTime="2012-07-23">July 23, 2012</time>
</td>
<td>n/a</td>
<td>15.00</td>
</tr>
</tbody>
</Table>
);
}
| 1,624 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableRowHead.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableRowHead() {
return (
<Sheet variant="outlined">
<Table variant="soft" borderAxis="bothBetween">
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,625 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableRowHead.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableRowHead() {
return (
<Sheet variant="outlined">
<Table variant="soft" borderAxis="bothBetween">
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<th scope="row">{row.name}</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,626 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableScrollingShadows.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
createData('5', 356, 16.0, 49, 3.9),
createData('6', 159, 6.0, 24, 4.0),
createData('7', 237, 9.0, 37, 4.3),
createData('8', 262, 16.0, 24, 6.0),
createData('9', 305, 3.7, 67, 4.3),
createData('10', 356, 16.0, 49, 3.9),
];
export default function TableScrollingShadows() {
return (
<div>
<Typography level="body-sm" textAlign="center" sx={{ mb: 2 }}>
The table body is scrollable.
</Typography>
<Sheet
sx={{
'--TableCell-height': '40px',
// the number is the amount of the header rows.
'--TableHeader-height': 'calc(1 * var(--TableCell-height))',
height: 200,
overflow: 'auto',
background: (theme) =>
`linear-gradient(${theme.vars.palette.background.surface} 30%, rgba(255, 255, 255, 0)),
linear-gradient(rgba(255, 255, 255, 0), ${theme.vars.palette.background.surface} 70%) 0 100%,
radial-gradient(
farthest-side at 50% 0,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
),
radial-gradient(
farthest-side at 50% 100%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
)
0 100%`,
backgroundSize: '100% 40px, 100% 40px, 100% 14px, 100% 14px',
backgroundRepeat: 'no-repeat',
backgroundAttachment: 'local, local, scroll, scroll',
backgroundPosition:
'0 var(--TableHeader-height), 0 100%, 0 var(--TableHeader-height), 0 100%',
backgroundColor: 'background.surface',
}}
>
<Table stickyHeader>
<thead>
<tr>
<th>Row</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
</div>
);
}
| 1,627 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableScrollingShadows.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
createData('5', 356, 16.0, 49, 3.9),
createData('6', 159, 6.0, 24, 4.0),
createData('7', 237, 9.0, 37, 4.3),
createData('8', 262, 16.0, 24, 6.0),
createData('9', 305, 3.7, 67, 4.3),
createData('10', 356, 16.0, 49, 3.9),
];
export default function TableScrollingShadows() {
return (
<div>
<Typography level="body-sm" textAlign="center" sx={{ mb: 2 }}>
The table body is scrollable.
</Typography>
<Sheet
sx={{
'--TableCell-height': '40px',
// the number is the amount of the header rows.
'--TableHeader-height': 'calc(1 * var(--TableCell-height))',
height: 200,
overflow: 'auto',
background: (
theme,
) => `linear-gradient(${theme.vars.palette.background.surface} 30%, rgba(255, 255, 255, 0)),
linear-gradient(rgba(255, 255, 255, 0), ${theme.vars.palette.background.surface} 70%) 0 100%,
radial-gradient(
farthest-side at 50% 0,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
),
radial-gradient(
farthest-side at 50% 100%,
rgba(0, 0, 0, 0.12),
rgba(0, 0, 0, 0)
)
0 100%`,
backgroundSize: '100% 40px, 100% 40px, 100% 14px, 100% 14px',
backgroundRepeat: 'no-repeat',
backgroundAttachment: 'local, local, scroll, scroll',
backgroundPosition:
'0 var(--TableHeader-height), 0 100%, 0 var(--TableHeader-height), 0 100%',
backgroundColor: 'background.surface',
}}
>
<Table stickyHeader>
<thead>
<tr>
<th>Row</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
</div>
);
}
| 1,628 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSheet.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSheet() {
return (
<Sheet variant="soft" sx={{ pt: 1, borderRadius: 'sm' }}>
<Table
stripe="odd"
hoverRow
sx={{ captionSide: 'top', '& tbody': { bgcolor: 'background.surface' } }}
>
<caption>Nutrition of your favorite menus.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,629 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSheet.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSheet() {
return (
<Sheet variant="soft" sx={{ pt: 1, borderRadius: 'sm' }}>
<Table
stripe="odd"
hoverRow
sx={{ captionSide: 'top', '& tbody': { bgcolor: 'background.surface' } }}
>
<caption>Nutrition of your favorite menus.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,630 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSheetColorInversion.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSheetColorInversion() {
return (
<Sheet
variant="solid"
color="primary"
invertedColors
sx={{
pt: 1,
borderRadius: 'sm',
transition: '0.3s',
background: (theme) =>
`linear-gradient(45deg, ${theme.vars.palette.primary[500]}, ${theme.vars.palette.primary[400]})`,
'& tr:last-child': {
'& td:first-child': {
borderBottomLeftRadius: '8px',
},
'& td:last-child': {
borderBottomRightRadius: '8px',
},
},
}}
>
<Table stripe="odd" hoverRow>
<caption>Nutrition of your favorite menus.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,631 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSheetColorInversion.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSheetColorInversion() {
return (
<Sheet
variant="solid"
color="primary"
invertedColors
sx={{
pt: 1,
borderRadius: 'sm',
transition: '0.3s',
background: (theme) =>
`linear-gradient(45deg, ${theme.vars.palette.primary[500]}, ${theme.vars.palette.primary[400]})`,
'& tr:last-child': {
'& td:first-child': {
borderBottomLeftRadius: '8px',
},
'& td:last-child': {
borderBottomRightRadius: '8px',
},
},
}}
>
<Table stripe="odd" hoverRow>
<caption>Nutrition of your favorite menus.</caption>
<thead>
<tr>
<th style={{ width: '40%' }}>Column width (40%)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,632 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSizes.js | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSizes() {
const [size, setSize] = React.useState('md');
return (
<div>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Size:</FormLabel>
<RadioGroup
orientation="horizontal"
value={size}
onChange={(event) => setSize(event.target.value)}
>
<Radio label="sm" value="sm" />
<Radio label="md" value="md" />
<Radio label="lg" value="lg" />
</RadioGroup>
</FormControl>
<Table aria-label="table sizes" size={size}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,633 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSizes.tsx | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table, { TableProps } from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableSizes() {
const [size, setSize] = React.useState<TableProps['size']>('md');
return (
<div>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Size:</FormLabel>
<RadioGroup
orientation="horizontal"
value={size}
onChange={(event) => setSize(event.target.value as typeof size)}
>
<Radio label="sm" value="sm" />
<Radio label="md" value="md" />
<Radio label="lg" value="lg" />
</RadioGroup>
</FormControl>
<Table aria-label="table sizes" size={size}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,634 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSortAndSelection.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Box from '@mui/joy/Box';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import IconButton from '@mui/joy/IconButton';
import Link from '@mui/joy/Link';
import Tooltip from '@mui/joy/Tooltip';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import DeleteIcon from '@mui/icons-material/Delete';
import FilterListIcon from '@mui/icons-material/FilterList';
import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import { visuallyHidden } from '@mui/utils';
function createData(name, calories, fat, carbs, protein) {
return {
name,
calories,
fat,
carbs,
protein,
};
}
const rows = [
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Donut', 452, 25.0, 51, 4.9),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Gingerbread', 356, 16.0, 49, 3.9),
createData('Honeycomb', 408, 3.2, 87, 6.5),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Jelly Bean', 375, 0.0, 94, 0.0),
createData('KitKat', 518, 26.0, 65, 7.0),
createData('Lollipop', 392, 0.2, 98, 0.0),
createData('Marshmallow', 318, 0, 81, 2.0),
createData('Nougat', 360, 19.0, 9, 37.0),
createData('Oreo', 437, 18.0, 63, 4.0),
];
function labelDisplayedRows({ from, to, count }) {
return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
}
function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
function getComparator(order, orderBy) {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
// Since 2020 all major browsers ensure sort stability with Array.prototype.sort().
// stableSort() brings sort stability to non-modern browsers (notably IE11). If you
// only support modern browsers you can replace stableSort(exampleArray, exampleComparator)
// with exampleArray.slice().sort(exampleComparator)
function stableSort(array, comparator) {
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) {
return order;
}
return a[1] - b[1];
});
return stabilizedThis.map((el) => el[0]);
}
const headCells = [
{
id: 'name',
numeric: false,
disablePadding: true,
label: 'Dessert (100g serving)',
},
{
id: 'calories',
numeric: true,
disablePadding: false,
label: 'Calories',
},
{
id: 'fat',
numeric: true,
disablePadding: false,
label: 'Fat (g)',
},
{
id: 'carbs',
numeric: true,
disablePadding: false,
label: 'Carbs (g)',
},
{
id: 'protein',
numeric: true,
disablePadding: false,
label: 'Protein (g)',
},
];
function EnhancedTableHead(props) {
const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } =
props;
const createSortHandler = (property) => (event) => {
onRequestSort(event, property);
};
return (
<thead>
<tr>
<th>
<Checkbox
indeterminate={numSelected > 0 && numSelected < rowCount}
checked={rowCount > 0 && numSelected === rowCount}
onChange={onSelectAllClick}
slotProps={{
input: {
'aria-label': 'select all desserts',
},
}}
sx={{ verticalAlign: 'sub' }}
/>
</th>
{headCells.map((headCell) => {
const active = orderBy === headCell.id;
return (
<th
key={headCell.id}
aria-sort={
active ? { asc: 'ascending', desc: 'descending' }[order] : undefined
}
>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link
underline="none"
color="neutral"
textColor={active ? 'primary.plainColor' : undefined}
component="button"
onClick={createSortHandler(headCell.id)}
fontWeight="lg"
startDecorator={
headCell.numeric ? (
<ArrowDownwardIcon sx={{ opacity: active ? 1 : 0 }} />
) : null
}
endDecorator={
!headCell.numeric ? (
<ArrowDownwardIcon sx={{ opacity: active ? 1 : 0 }} />
) : null
}
sx={{
'& svg': {
transition: '0.2s',
transform:
active && order === 'desc' ? 'rotate(0deg)' : 'rotate(180deg)',
},
'&:hover': { '& svg': { opacity: 1 } },
}}
>
{headCell.label}
{active ? (
<Box component="span" sx={visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</Box>
) : null}
</Link>
</th>
);
})}
</tr>
</thead>
);
}
EnhancedTableHead.propTypes = {
numSelected: PropTypes.number.isRequired,
onRequestSort: PropTypes.func.isRequired,
onSelectAllClick: PropTypes.func.isRequired,
order: PropTypes.oneOf(['asc', 'desc']).isRequired,
orderBy: PropTypes.string.isRequired,
rowCount: PropTypes.number.isRequired,
};
function EnhancedTableToolbar(props) {
const { numSelected } = props;
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
py: 1,
pl: { sm: 2 },
pr: { xs: 1, sm: 1 },
...(numSelected > 0 && {
bgcolor: 'background.level1',
}),
borderTopLeftRadius: 'var(--unstable_actionRadius)',
borderTopRightRadius: 'var(--unstable_actionRadius)',
}}
>
{numSelected > 0 ? (
<Typography sx={{ flex: '1 1 100%' }} component="div">
{numSelected} selected
</Typography>
) : (
<Typography
level="body-lg"
sx={{ flex: '1 1 100%' }}
id="tableTitle"
component="div"
>
Nutrition
</Typography>
)}
{numSelected > 0 ? (
<Tooltip title="Delete">
<IconButton size="sm" color="danger" variant="solid">
<DeleteIcon />
</IconButton>
</Tooltip>
) : (
<Tooltip title="Filter list">
<IconButton size="sm" variant="outlined" color="neutral">
<FilterListIcon />
</IconButton>
</Tooltip>
)}
</Box>
);
}
EnhancedTableToolbar.propTypes = {
numSelected: PropTypes.number.isRequired,
};
export default function TableSortAndSelection() {
const [order, setOrder] = React.useState('asc');
const [orderBy, setOrderBy] = React.useState('calories');
const [selected, setSelected] = React.useState([]);
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(5);
const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};
const handleSelectAllClick = (event) => {
if (event.target.checked) {
const newSelected = rows.map((n) => n.name);
setSelected(newSelected);
return;
}
setSelected([]);
};
const handleClick = (event, name) => {
const selectedIndex = selected.indexOf(name);
let newSelected = [];
if (selectedIndex === -1) {
newSelected = newSelected.concat(selected, name);
} else if (selectedIndex === 0) {
newSelected = newSelected.concat(selected.slice(1));
} else if (selectedIndex === selected.length - 1) {
newSelected = newSelected.concat(selected.slice(0, -1));
} else if (selectedIndex > 0) {
newSelected = newSelected.concat(
selected.slice(0, selectedIndex),
selected.slice(selectedIndex + 1),
);
}
setSelected(newSelected);
};
const handleChangePage = (newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event, newValue) => {
setRowsPerPage(parseInt(newValue.toString(), 10));
setPage(0);
};
const getLabelDisplayedRowsTo = () => {
if (rows.length === -1) {
return (page + 1) * rowsPerPage;
}
return rowsPerPage === -1
? rows.length
: Math.min(rows.length, (page + 1) * rowsPerPage);
};
const isSelected = (name) => selected.indexOf(name) !== -1;
// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
return (
<Sheet
variant="outlined"
sx={{ width: '100%', boxShadow: 'sm', borderRadius: 'sm' }}
>
<EnhancedTableToolbar numSelected={selected.length} />
<Table
aria-labelledby="tableTitle"
hoverRow
sx={{
'--TableCell-headBackground': 'transparent',
'--TableCell-selectedBackground': (theme) =>
theme.vars.palette.success.softBg,
'& thead th:nth-child(1)': {
width: '40px',
},
'& thead th:nth-child(2)': {
width: '30%',
},
'& tr > *:nth-child(n+3)': { textAlign: 'right' },
}}
>
<EnhancedTableHead
numSelected={selected.length}
order={order}
orderBy={orderBy}
onSelectAllClick={handleSelectAllClick}
onRequestSort={handleRequestSort}
rowCount={rows.length}
/>
<tbody>
{stableSort(rows, getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row, index) => {
const isItemSelected = isSelected(row.name);
const labelId = `enhanced-table-checkbox-${index}`;
return (
<tr
onClick={(event) => handleClick(event, row.name)}
role="checkbox"
aria-checked={isItemSelected}
tabIndex={-1}
key={row.name}
// selected={isItemSelected}
style={
isItemSelected
? {
'--TableCell-dataBackground':
'var(--TableCell-selectedBackground)',
'--TableCell-headBackground':
'var(--TableCell-selectedBackground)',
}
: {}
}
>
<th scope="row">
<Checkbox
checked={isItemSelected}
slotProps={{
input: {
'aria-labelledby': labelId,
},
}}
sx={{ verticalAlign: 'top' }}
/>
</th>
<th id={labelId} scope="row">
{row.name}
</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
);
})}
{emptyRows > 0 && (
<tr
style={{
height: `calc(${emptyRows} * 40px)`,
'--TableRow-hoverBackground': 'transparent',
}}
>
<td colSpan={6} aria-hidden />
</tr>
)}
</tbody>
<tfoot>
<tr>
<td colSpan={6}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 2,
justifyContent: 'flex-end',
}}
>
<FormControl orientation="horizontal" size="sm">
<FormLabel>Rows per page:</FormLabel>
<Select onChange={handleChangeRowsPerPage} value={rowsPerPage}>
<Option value={5}>5</Option>
<Option value={10}>10</Option>
<Option value={25}>25</Option>
</Select>
</FormControl>
<Typography textAlign="center" sx={{ minWidth: 80 }}>
{labelDisplayedRows({
from: rows.length === 0 ? 0 : page * rowsPerPage + 1,
to: getLabelDisplayedRowsTo(),
count: rows.length === -1 ? -1 : rows.length,
})}
</Typography>
<Box sx={{ display: 'flex', gap: 1 }}>
<IconButton
size="sm"
color="neutral"
variant="outlined"
disabled={page === 0}
onClick={() => handleChangePage(page - 1)}
sx={{ bgcolor: 'background.surface' }}
>
<KeyboardArrowLeftIcon />
</IconButton>
<IconButton
size="sm"
color="neutral"
variant="outlined"
disabled={
rows.length !== -1
? page >= Math.ceil(rows.length / rowsPerPage) - 1
: false
}
onClick={() => handleChangePage(page + 1)}
sx={{ bgcolor: 'background.surface' }}
>
<KeyboardArrowRightIcon />
</IconButton>
</Box>
</Box>
</td>
</tr>
</tfoot>
</Table>
</Sheet>
);
}
| 1,635 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableSortAndSelection.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import IconButton from '@mui/joy/IconButton';
import Link from '@mui/joy/Link';
import Tooltip from '@mui/joy/Tooltip';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import DeleteIcon from '@mui/icons-material/Delete';
import FilterListIcon from '@mui/icons-material/FilterList';
import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import { visuallyHidden } from '@mui/utils';
interface Data {
calories: number;
carbs: number;
fat: number;
name: string;
protein: number;
}
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
): Data {
return {
name,
calories,
fat,
carbs,
protein,
};
}
const rows = [
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Donut', 452, 25.0, 51, 4.9),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Gingerbread', 356, 16.0, 49, 3.9),
createData('Honeycomb', 408, 3.2, 87, 6.5),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Jelly Bean', 375, 0.0, 94, 0.0),
createData('KitKat', 518, 26.0, 65, 7.0),
createData('Lollipop', 392, 0.2, 98, 0.0),
createData('Marshmallow', 318, 0, 81, 2.0),
createData('Nougat', 360, 19.0, 9, 37.0),
createData('Oreo', 437, 18.0, 63, 4.0),
];
function labelDisplayedRows({
from,
to,
count,
}: {
from: number;
to: number;
count: number;
}) {
return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
}
function descendingComparator<T>(a: T, b: T, orderBy: keyof T) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
type Order = 'asc' | 'desc';
function getComparator<Key extends keyof any>(
order: Order,
orderBy: Key,
): (
a: { [key in Key]: number | string },
b: { [key in Key]: number | string },
) => number {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
// Since 2020 all major browsers ensure sort stability with Array.prototype.sort().
// stableSort() brings sort stability to non-modern browsers (notably IE11). If you
// only support modern browsers you can replace stableSort(exampleArray, exampleComparator)
// with exampleArray.slice().sort(exampleComparator)
function stableSort<T>(array: readonly T[], comparator: (a: T, b: T) => number) {
const stabilizedThis = array.map((el, index) => [el, index] as [T, number]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) {
return order;
}
return a[1] - b[1];
});
return stabilizedThis.map((el) => el[0]);
}
interface HeadCell {
disablePadding: boolean;
id: keyof Data;
label: string;
numeric: boolean;
}
const headCells: readonly HeadCell[] = [
{
id: 'name',
numeric: false,
disablePadding: true,
label: 'Dessert (100g serving)',
},
{
id: 'calories',
numeric: true,
disablePadding: false,
label: 'Calories',
},
{
id: 'fat',
numeric: true,
disablePadding: false,
label: 'Fat (g)',
},
{
id: 'carbs',
numeric: true,
disablePadding: false,
label: 'Carbs (g)',
},
{
id: 'protein',
numeric: true,
disablePadding: false,
label: 'Protein (g)',
},
];
interface EnhancedTableProps {
numSelected: number;
onRequestSort: (event: React.MouseEvent<unknown>, property: keyof Data) => void;
onSelectAllClick: (event: React.ChangeEvent<HTMLInputElement>) => void;
order: Order;
orderBy: string;
rowCount: number;
}
function EnhancedTableHead(props: EnhancedTableProps) {
const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } =
props;
const createSortHandler =
(property: keyof Data) => (event: React.MouseEvent<unknown>) => {
onRequestSort(event, property);
};
return (
<thead>
<tr>
<th>
<Checkbox
indeterminate={numSelected > 0 && numSelected < rowCount}
checked={rowCount > 0 && numSelected === rowCount}
onChange={onSelectAllClick}
slotProps={{
input: {
'aria-label': 'select all desserts',
},
}}
sx={{ verticalAlign: 'sub' }}
/>
</th>
{headCells.map((headCell) => {
const active = orderBy === headCell.id;
return (
<th
key={headCell.id}
aria-sort={
active
? ({ asc: 'ascending', desc: 'descending' } as const)[order]
: undefined
}
>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link
underline="none"
color="neutral"
textColor={active ? 'primary.plainColor' : undefined}
component="button"
onClick={createSortHandler(headCell.id)}
fontWeight="lg"
startDecorator={
headCell.numeric ? (
<ArrowDownwardIcon sx={{ opacity: active ? 1 : 0 }} />
) : null
}
endDecorator={
!headCell.numeric ? (
<ArrowDownwardIcon sx={{ opacity: active ? 1 : 0 }} />
) : null
}
sx={{
'& svg': {
transition: '0.2s',
transform:
active && order === 'desc' ? 'rotate(0deg)' : 'rotate(180deg)',
},
'&:hover': { '& svg': { opacity: 1 } },
}}
>
{headCell.label}
{active ? (
<Box component="span" sx={visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</Box>
) : null}
</Link>
</th>
);
})}
</tr>
</thead>
);
}
interface EnhancedTableToolbarProps {
numSelected: number;
}
function EnhancedTableToolbar(props: EnhancedTableToolbarProps) {
const { numSelected } = props;
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
py: 1,
pl: { sm: 2 },
pr: { xs: 1, sm: 1 },
...(numSelected > 0 && {
bgcolor: 'background.level1',
}),
borderTopLeftRadius: 'var(--unstable_actionRadius)',
borderTopRightRadius: 'var(--unstable_actionRadius)',
}}
>
{numSelected > 0 ? (
<Typography sx={{ flex: '1 1 100%' }} component="div">
{numSelected} selected
</Typography>
) : (
<Typography
level="body-lg"
sx={{ flex: '1 1 100%' }}
id="tableTitle"
component="div"
>
Nutrition
</Typography>
)}
{numSelected > 0 ? (
<Tooltip title="Delete">
<IconButton size="sm" color="danger" variant="solid">
<DeleteIcon />
</IconButton>
</Tooltip>
) : (
<Tooltip title="Filter list">
<IconButton size="sm" variant="outlined" color="neutral">
<FilterListIcon />
</IconButton>
</Tooltip>
)}
</Box>
);
}
export default function TableSortAndSelection() {
const [order, setOrder] = React.useState<Order>('asc');
const [orderBy, setOrderBy] = React.useState<keyof Data>('calories');
const [selected, setSelected] = React.useState<readonly string[]>([]);
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(5);
const handleRequestSort = (
event: React.MouseEvent<unknown>,
property: keyof Data,
) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};
const handleSelectAllClick = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.checked) {
const newSelected = rows.map((n) => n.name);
setSelected(newSelected);
return;
}
setSelected([]);
};
const handleClick = (event: React.MouseEvent<unknown>, name: string) => {
const selectedIndex = selected.indexOf(name);
let newSelected: readonly string[] = [];
if (selectedIndex === -1) {
newSelected = newSelected.concat(selected, name);
} else if (selectedIndex === 0) {
newSelected = newSelected.concat(selected.slice(1));
} else if (selectedIndex === selected.length - 1) {
newSelected = newSelected.concat(selected.slice(0, -1));
} else if (selectedIndex > 0) {
newSelected = newSelected.concat(
selected.slice(0, selectedIndex),
selected.slice(selectedIndex + 1),
);
}
setSelected(newSelected);
};
const handleChangePage = (newPage: number) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event: any, newValue: number | null) => {
setRowsPerPage(parseInt(newValue!.toString(), 10));
setPage(0);
};
const getLabelDisplayedRowsTo = () => {
if (rows.length === -1) {
return (page + 1) * rowsPerPage;
}
return rowsPerPage === -1
? rows.length
: Math.min(rows.length, (page + 1) * rowsPerPage);
};
const isSelected = (name: string) => selected.indexOf(name) !== -1;
// Avoid a layout jump when reaching the last page with empty rows.
const emptyRows =
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
return (
<Sheet
variant="outlined"
sx={{ width: '100%', boxShadow: 'sm', borderRadius: 'sm' }}
>
<EnhancedTableToolbar numSelected={selected.length} />
<Table
aria-labelledby="tableTitle"
hoverRow
sx={{
'--TableCell-headBackground': 'transparent',
'--TableCell-selectedBackground': (theme) =>
theme.vars.palette.success.softBg,
'& thead th:nth-child(1)': {
width: '40px',
},
'& thead th:nth-child(2)': {
width: '30%',
},
'& tr > *:nth-child(n+3)': { textAlign: 'right' },
}}
>
<EnhancedTableHead
numSelected={selected.length}
order={order}
orderBy={orderBy}
onSelectAllClick={handleSelectAllClick}
onRequestSort={handleRequestSort}
rowCount={rows.length}
/>
<tbody>
{stableSort(rows, getComparator(order, orderBy))
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row, index) => {
const isItemSelected = isSelected(row.name);
const labelId = `enhanced-table-checkbox-${index}`;
return (
<tr
onClick={(event) => handleClick(event, row.name)}
role="checkbox"
aria-checked={isItemSelected}
tabIndex={-1}
key={row.name}
// selected={isItemSelected}
style={
isItemSelected
? ({
'--TableCell-dataBackground':
'var(--TableCell-selectedBackground)',
'--TableCell-headBackground':
'var(--TableCell-selectedBackground)',
} as React.CSSProperties)
: {}
}
>
<th scope="row">
<Checkbox
checked={isItemSelected}
slotProps={{
input: {
'aria-labelledby': labelId,
},
}}
sx={{ verticalAlign: 'top' }}
/>
</th>
<th id={labelId} scope="row">
{row.name}
</th>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
);
})}
{emptyRows > 0 && (
<tr
style={
{
height: `calc(${emptyRows} * 40px)`,
'--TableRow-hoverBackground': 'transparent',
} as React.CSSProperties
}
>
<td colSpan={6} aria-hidden />
</tr>
)}
</tbody>
<tfoot>
<tr>
<td colSpan={6}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 2,
justifyContent: 'flex-end',
}}
>
<FormControl orientation="horizontal" size="sm">
<FormLabel>Rows per page:</FormLabel>
<Select onChange={handleChangeRowsPerPage} value={rowsPerPage}>
<Option value={5}>5</Option>
<Option value={10}>10</Option>
<Option value={25}>25</Option>
</Select>
</FormControl>
<Typography textAlign="center" sx={{ minWidth: 80 }}>
{labelDisplayedRows({
from: rows.length === 0 ? 0 : page * rowsPerPage + 1,
to: getLabelDisplayedRowsTo(),
count: rows.length === -1 ? -1 : rows.length,
})}
</Typography>
<Box sx={{ display: 'flex', gap: 1 }}>
<IconButton
size="sm"
color="neutral"
variant="outlined"
disabled={page === 0}
onClick={() => handleChangePage(page - 1)}
sx={{ bgcolor: 'background.surface' }}
>
<KeyboardArrowLeftIcon />
</IconButton>
<IconButton
size="sm"
color="neutral"
variant="outlined"
disabled={
rows.length !== -1
? page >= Math.ceil(rows.length / rowsPerPage) - 1
: false
}
onClick={() => handleChangePage(page + 1)}
sx={{ bgcolor: 'background.surface' }}
>
<KeyboardArrowRightIcon />
</IconButton>
</Box>
</Box>
</td>
</tr>
</tfoot>
</Table>
</Sheet>
);
}
| 1,636 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableStickyHeader.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
createData('5', 356, 16.0, 49, 3.9),
createData('6', 159, 6.0, 24, 4.0),
createData('7', 237, 9.0, 37, 4.3),
createData('8', 262, 16.0, 24, 6.0),
createData('9', 305, 3.7, 67, 4.3),
createData('10', 356, 16.0, 49, 3.9),
];
function sum(column) {
return rows.reduce((acc, row) => acc + row[column], 0);
}
export default function TableStickyHeader() {
return (
<div>
<Typography level="body-sm" textAlign="center" sx={{ mb: 2 }}>
The table body is scrollable.
</Typography>
<Sheet sx={{ height: 300, overflow: 'auto' }}>
<Table
aria-label="table with sticky header"
stickyHeader
stickyFooter
stripe="odd"
hoverRow
>
<thead>
<tr>
<th>Row</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td>{sum('calories').toFixed(2)}</td>
<td>{sum('fat').toFixed(2)}</td>
<td>{sum('carbs').toFixed(2)}</td>
<td>{sum('protein').toFixed(2)}</td>
</tr>
<tr>
<td colSpan={5} style={{ textAlign: 'center' }}>
{sum('calories') + sum('fat') + sum('carbs') + sum('protein')} Kcal
</td>
</tr>
</tfoot>
</Table>
</Sheet>
</div>
);
}
| 1,637 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableStickyHeader.tsx | import * as React from 'react';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('1', 159, 6.0, 24, 4.0),
createData('2', 237, 9.0, 37, 4.3),
createData('3', 262, 16.0, 24, 6.0),
createData('4', 305, 3.7, 67, 4.3),
createData('5', 356, 16.0, 49, 3.9),
createData('6', 159, 6.0, 24, 4.0),
createData('7', 237, 9.0, 37, 4.3),
createData('8', 262, 16.0, 24, 6.0),
createData('9', 305, 3.7, 67, 4.3),
createData('10', 356, 16.0, 49, 3.9),
];
function sum(column: 'calories' | 'fat' | 'carbs' | 'protein') {
return rows.reduce((acc, row) => acc + row[column], 0);
}
export default function TableStickyHeader() {
return (
<div>
<Typography level="body-sm" textAlign="center" sx={{ mb: 2 }}>
The table body is scrollable.
</Typography>
<Sheet sx={{ height: 300, overflow: 'auto' }}>
<Table
aria-label="table with sticky header"
stickyHeader
stickyFooter
stripe="odd"
hoverRow
>
<thead>
<tr>
<th>Row</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td>{sum('calories').toFixed(2)}</td>
<td>{sum('fat').toFixed(2)}</td>
<td>{sum('carbs').toFixed(2)}</td>
<td>{sum('protein').toFixed(2)}</td>
</tr>
<tr>
<td colSpan={5} style={{ textAlign: 'center' }}>
{sum('calories') + sum('fat') + sum('carbs') + sum('protein')} Kcal
</td>
</tr>
</tfoot>
</Table>
</Sheet>
</div>
);
}
| 1,638 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableStripe.js | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableStripe() {
const [stripe, setStripe] = React.useState('odd');
return (
<Sheet>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Stripe:</FormLabel>
<RadioGroup
orientation="horizontal"
value={stripe}
onChange={(event) => setStripe(event.target.value)}
>
<Radio label="odd" value="odd" />
<Radio label="even" value="even" />
</RadioGroup>
</FormControl>
<Table aria-label="striped table" stripe={stripe}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,639 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableStripe.tsx | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableStripe() {
const [stripe, setStripe] = React.useState('odd');
return (
<Sheet>
<FormControl orientation="horizontal" sx={{ mb: 2, ml: 1 }}>
<FormLabel>Stripe:</FormLabel>
<RadioGroup
orientation="horizontal"
value={stripe}
onChange={(event) => setStripe(event.target.value)}
>
<Radio label="odd" value="odd" />
<Radio label="even" value="even" />
</RadioGroup>
</FormControl>
<Table aria-label="striped table" stripe={stripe}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</Sheet>
);
}
| 1,640 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableTextEllipsis.js | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Link from '@mui/joy/Link';
export default function TableTextEllipsis() {
return (
<Table
aria-label="table with ellipsis texts"
noWrap
sx={{ mx: 'auto', width: 400 }}
>
<thead>
<tr>
<th>Name</th>
<th style={{ width: '60%' }}>
Description (you should see a part of this message)
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
<Avatar src="/static/images/avatar/1.jpg" />
<Box sx={{ minWidth: 0 }}>
<Typography noWrap fontWeight="lg">
Morty D Ardiousdellois Addami
</Typography>
<Typography noWrap level="body-sm">
Writer, Youtuber
</Typography>
</Box>
</Box>
</td>
<td>
Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at
velit. Vivamus vel nulla eget eros elementum pellentesque. Quisque porta
volutpat erat. Quisque erat eros, viverra eget, congue eget, semper
rutrum, nulla.
</td>
</tr>
<tr>
<td>Joseph Morriso</td>
<td>
<Typography noWrap>
<Link href="#text-ellipsis" startDecorator="ℹ️">
In eleifend quam a odio
</Link>
. Suspendisse potenti in hac habitasse platea dictumst.
</Typography>
</td>
</tr>
</tbody>
</Table>
);
}
| 1,641 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableTextEllipsis.tsx | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Table from '@mui/joy/Table';
import Typography from '@mui/joy/Typography';
import Link from '@mui/joy/Link';
export default function TableTextEllipsis() {
return (
<Table
aria-label="table with ellipsis texts"
noWrap
sx={{ mx: 'auto', width: 400 }}
>
<thead>
<tr>
<th>Name</th>
<th style={{ width: '60%' }}>
Description (you should see a part of this message)
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
<Avatar src="/static/images/avatar/1.jpg" />
<Box sx={{ minWidth: 0 }}>
<Typography noWrap fontWeight="lg">
Morty D Ardiousdellois Addami
</Typography>
<Typography noWrap level="body-sm">
Writer, Youtuber
</Typography>
</Box>
</Box>
</td>
<td>
Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at
velit. Vivamus vel nulla eget eros elementum pellentesque. Quisque porta
volutpat erat. Quisque erat eros, viverra eget, congue eget, semper
rutrum, nulla.
</td>
</tr>
<tr>
<td>Joseph Morriso</td>
<td>
<Typography noWrap>
<Link href="#text-ellipsis" startDecorator="ℹ️">
In eleifend quam a odio
</Link>
. Suspendisse potenti in hac habitasse platea dictumst.
</Typography>
</td>
</tr>
</tbody>
</Table>
);
}
| 1,642 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableUsage.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
import Typography from '@mui/joy/Typography';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function TableUsage() {
return (
<JoyUsageDemo
componentName="Table"
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: 'borderAxis',
knob: 'select',
options: ['xBetween', 'x', 'yBetween', 'y', 'bothBetween', 'both', 'none'],
defaultValue: 'xBetween',
},
{
propName: 'stickyHeader',
knob: 'switch',
defaultValue: false,
},
{
propName: 'stickyFooter',
knob: 'switch',
defaultValue: false,
},
{
propName: 'stripe',
knob: 'radio',
options: ['undefined', 'odd', 'even'],
},
]}
getCodeBlock={(code) => `<Sheet>
${code}
</Sheet>`}
renderDemo={(props) => (
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<Typography
level="body-xs"
justifyContent="center"
textAlign="center"
sx={{ mb: 2 }}
>
The table is scrollable.
</Typography>
<Sheet variant="outlined" sx={{ p: 2, borderRadius: 'sm' }}>
<Sheet
sx={{
height: 200,
overflow: 'auto',
borderRadius: 0,
}}
>
<Table {...props}>
<thead>
<tr>
<th style={{ width: 64 }}>ID</th>
<th>Job Title</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Doctor</td>
<td>Chris Johnson</td>
</tr>
<tr>
<td>2</td>
<td>Electrician</td>
<td>Joseph Morris</td>
</tr>
<tr>
<td>3</td>
<td>Operator</td>
<td>Aiden Moreno</td>
</tr>
<tr>
<td>4</td>
<td>Baker</td>
<td>Mike Simmons</td>
</tr>
<tr>
<td>5</td>
<td>Clerk</td>
<td>Enoch Addison</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td colSpan={2} style={{ textAlign: 'center' }}>
4 people
</td>
</tr>
</tfoot>
</Table>
</Sheet>
</Sheet>
</Box>
)}
/>
);
}
| 1,643 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableVariables.js | import * as React from 'react';
import Table from '@mui/joy/Table';
import Sheet from '@mui/joy/Sheet';
import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo';
export default function TableVariables() {
return (
<JoyVariablesDemo
componentName="Table"
data={[
{
var: '--Table-headerUnderlineThickness',
defaultValue: '2px',
},
{
var: '--TableCell-height',
defaultValue: '40px',
},
{
var: '--TableCell-paddingX',
defaultValue: '8px',
},
{
var: '--TableCell-paddingY',
defaultValue: '6px',
},
]}
renderDemo={(sx) => (
<Sheet variant="outlined" sx={{ width: 300, boxShadow: 'sm' }}>
<Table borderAxis="bothBetween" sx={sx}>
<thead>
<tr>
<th>Name</th>
<th style={{ width: '60%' }}>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>Adam</td>
<td>Developer</td>
</tr>
<tr>
<td>Joseph</td>
<td>Manager</td>
</tr>
</tbody>
</Table>
</Sheet>
)}
/>
);
}
| 1,644 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableVariants.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table from '@mui/joy/Table';
function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableVariants() {
const [variant, setVariant] = React.useState('plain');
const [color, setColor] = React.useState('neutral');
return (
<div>
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
gap: 1,
mb: 2,
ml: 1,
}}
>
<FormControl orientation="horizontal">
<FormLabel>Variant:</FormLabel>
<RadioGroup
orientation="horizontal"
value={variant}
onChange={(event) => setVariant(event.target.value)}
>
<Radio label="plain" value="plain" />
<Radio label="outlined" value="outlined" />
<Radio label="soft" value="soft" />
<Radio label="solid" value="solid" />
</RadioGroup>
</FormControl>
<FormControl orientation="horizontal">
<FormLabel>Color: </FormLabel>
<Select
size="sm"
value={color}
onChange={(event, newValue) => setColor(newValue)}
>
{['neutral', 'primary', 'danger', 'success', 'warning'].map((item) => (
<Option key={item} value={item}>
{item}
</Option>
))}
</Select>
</FormControl>
</Box>
<Table aria-label="table variants" variant={variant} color={color}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,645 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/TableVariants.tsx | import * as React from 'react';
import { VariantProp, ColorPaletteProp } from '@mui/joy/styles';
import Box from '@mui/joy/Box';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Table from '@mui/joy/Table';
function createData(
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
) {
return { name, calories, fat, carbs, protein };
}
const rows = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
export default function TableVariants() {
const [variant, setVariant] = React.useState<VariantProp>('plain');
const [color, setColor] = React.useState<ColorPaletteProp>('neutral');
return (
<div>
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
gap: 1,
mb: 2,
ml: 1,
}}
>
<FormControl orientation="horizontal">
<FormLabel>Variant:</FormLabel>
<RadioGroup
orientation="horizontal"
value={variant}
onChange={(event) => setVariant(event.target.value as typeof variant)}
>
<Radio label="plain" value="plain" />
<Radio label="outlined" value="outlined" />
<Radio label="soft" value="soft" />
<Radio label="solid" value="solid" />
</RadioGroup>
</FormControl>
<FormControl orientation="horizontal">
<FormLabel>Color: </FormLabel>
<Select
size="sm"
value={color}
onChange={(event, newValue) => setColor(newValue as typeof color)}
>
{['neutral', 'primary', 'danger', 'success', 'warning'].map((item) => (
<Option key={item} value={item}>
{item}
</Option>
))}
</Select>
</FormControl>
</Box>
<Table aria-label="table variants" variant={variant} color={color}>
<thead>
<tr>
<th style={{ width: '40%' }}>Dessert (100g serving)</th>
<th>Calories</th>
<th>Fat (g)</th>
<th>Carbs (g)</th>
<th>Protein (g)</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.calories}</td>
<td>{row.fat}</td>
<td>{row.carbs}</td>
<td>{row.protein}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}
| 1,646 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/table/table.md | ---
productId: joy-ui
title: React Table component
components: Table
githubLabel: 'component: table'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/table/
---
# Table
<p class="description">Tables display sets of data organized in rows and columns.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
The Joy UI Table component lets you use plain HTML structure to assemble a table in JSX.
{{"demo": "TableUsage.js", "hideToolbar": true, "bg": "gradient"}}
## Basics
Joy UI Table will apply the styles based on a table structure using `<thead>`, `<tbody>`, and `<tfoot>` elements.
```jsx
import Table from '@mui/joy/Table';
```
{{"demo": "BasicTable.js"}}
:::info
By default, **header** cells (`<th>`) contain the `surface` background color, whereas **data** cells (`<td>`) have no background.
:::
## Customization
### Column width
Use the `sx` prop to target the header and provide the width as a number or percentage.
Columns that don't have an explicit width will spread equally to fill the rest of the area.
{{"demo": "TableColumnWidth.js"}}
:::info
The Table component uses a [`fixed`](https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout) layout to let you control the width of each column.
To learn more about why we take this approach, check out this article from Chris Coyier on [Fixed Table Layouts](https://css-tricks.com/fixing-tables-long-strings/).
:::
#### Inline style
An alternative way of controlling the column's width is to use [inline styles](https://react.dev/learn/javascript-in-jsx-with-curly-braces#using-double-curlies-css-and-other-objects-in-jsx) on the `<th>` element:
```js
<thead>
<tr>
<th style={{ width: '40%' }}>Column 1</th>
<th style={{ width: '64px' }}>Column 2</th>
</tr>
</thead>
```
### Alignment
Use the `sx` prop to target columns with the appropriate CSS selector and apply the [`text-align`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align) property.
```js
// target cells that are not the first in their respective rows.
<Table sx={{ '& tr > *:not(:first-child)': { textAlign: 'right' } }}>
```
{{"demo": "TableAlignment.js"}}
### Variants
Table supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `plain` (default), `outlined`, `soft`, and `solid`.
{{"demo": "TableVariants.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 component comes in three sizes: `sm`, `md` (default), and `lg`.
{{"demo": "TableSizes.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).
:::
### Stripe
To create contrast between rows, use the `stripe` prop with `odd` or `even` values.
{{"demo": "TableStripe.js"}}
:::success
The `stripe` prop supports complex arguments with the [`:nth-child()`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#syntax) CSS selector.
For example, you can use `3n` as a value to create stripes on row numbers three, six, nine, and so on:
```js
<Table stripe="3n">
```
:::
### Hover
To highlight a row of the table body when hovering over it, set the `hoverRow` prop to true.
{{"demo": "TableHover.js"}}
### Border
Use the `borderAxis` prop to control the border appearance.
{{"demo": "TableBorder.js"}}
#### Adding custom borders
Customize the table theme based on `borderAxis` prop using the [`extendTheme()`](/joy-ui/customization/themed-components/#change-styles-based-on-props) function.
```js
import { CssVarsProvider, extendTheme } from '@mui/joy/styles';
const theme = extendTheme({
components: {
JoyTable: {
styleOverrides: {
root: ({ ownerState }) => ({
...(ownerState.borderAxis === 'header' && {
// this example applies borders between <thead> and <tbody>
'& thead th:not([colspan])': {
borderBottom: '2px solid var(--TableCell-borderColor)',
},
}),
});
}
}
}
})
<CssVarsProvider theme={theme}>…</CssVarsProvider>
```
For TypeScript, you have to add the new values via module augmentation:
```ts
// this could be any file that's included in your tsconfig.json
declare module '@mui/joy/Table' {
interface TablePropsBorderAxisOverrides {
header: true;
}
}
```
### Sticky header and footer
Set the `stickyHeader` to true to always stick the header at the top as users scroll the table.
Set the `stickyFooter` to true to always stick the footer at the bottom of the table.
:::success
For `stickyHeader` and `stickyFooter` to work correctly, the Table must be a child of a fixed-height element with overflow `auto` (or `scroll`).
We recommend wrapping your Table with [Sheet](/joy-ui/react-sheet/) for this purpose.
See [usage with Sheet](#usage-with-sheet) to learn more.
:::
{{"demo": "TableStickyHeader.js"}}
### Caption
Add a caption to summarize the contents of a Table by inserting a `<caption>` element as the Table's first child.
{{"demo": "TableCaption.js"}}
:::success
To display a caption at the bottom of the Table, set the [caption side](https://developer.mozilla.org/en-US/docs/Web/CSS/caption-side) to `bottom`:
```js
<Table sx={{ captionSide: 'bottom' }}>
```
:::
### Footer
Use [`<tfoot>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot) to add a footer to the Table.
{{"demo": "TableFooter.js"}}
### Row head
Set `scope="row"` to `<th>` elements inside `<tbody>` to apply the same style as column headers.
The demo below illustrates a common use case: setting the first column to match the header styles.
{{"demo": "TableRowHead.js"}}
### Row and column span
Use `rowSpan` and `columnSpan` to expand a cell across multiple rows or columns.
{{"demo": "TableRowColumnSpan.js"}}
:::warning
Note that the CSS cannot figure out how apply borders on every corner without duplicating some.
There are two workarounds:
1. Manually remove the right border for a specific cell:
```js
// In this example, we remove the border from
// the right side of the header cell to avoid duplication.
<th style={{ borderRightWidth: 0 }}>Canceled</th>
```
2. Set Table's the border collapse to `collapse`:
```js
<Table sx={{ borderCollapse: 'collapse' }}>
// Note that this will change the behavior when `stickyHeader` is true:
// the bottom border of the sticky header will not "stick".
```
:::
### Text ellipsis
To truncate the text, set `noWrap` to true.
The header cells always truncate the text to keep the header's height predictable.
{{"demo": "TableTextEllipsis.js"}}
## CSS variables playground
Play around with the CSS variables available to the Table component to see how the design changes.
You can use these to customize the components with both the `sx` prop and the theme.
{{"demo": "TableVariables.js", "hideToolbar": true, "bg": "gradient"}}
## Usage with Sheet
import Sheet from `@mui/joy/Sheet`
When Table becomes a child of [Sheet](/joy-ui/react-sheet/) component, the table header background is inherited from the Sheet.
{{"demo": "TableSheet.js"}}
### Color inversion
When [color inversion](/joy-ui/main-features/color-inversion/) is enabled, the Table's styles will adapt based on its [variant](#variants).
{{"demo": "TableSheetColorInversion.js"}}
## Common examples
### Sort and selection
Use form components such as [Button](/joy-ui/react-button/), [Select](/joy-ui/react-select/) and [Switch](/joy-ui/react-switch/) to create sort and selection features.
{{"demo": "TableSortAndSelection.js"}}
### First and last column pinning
{{"demo": "TableColumnPinning.js"}}
### Collapsible row
{{"demo": "TableCollapsibleRow.js"}}
### Applying global variants
Use `theme.variants.*` to apply global variant styles to the Table.
{{"demo": "TableGlobalVariant.js"}}
### Scrolling shadows
Inspired by this article from Lea Verou on [CSS scrolling shadows](https://lea.verou.me/blog/2012/04/background-attachment-local/), the shadows appear and hide when scrolling on the Table.
{{"demo": "TableScrollingShadows.js"}}
| 1,647 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabDisabled.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabDisabled() {
return (
<Tabs aria-label="Disabled tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab disabled>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
);
}
| 1,648 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabDisabled.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabDisabled() {
return (
<Tabs aria-label="Disabled tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab disabled>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
);
}
| 1,649 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabDisabled.tsx.preview | <Tabs aria-label="Disabled tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab disabled>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs> | 1,650 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBasic.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsBasic() {
return (
<Tabs aria-label="Basic tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
<TabPanel value={0}>
<b>First</b> tab panel
</TabPanel>
<TabPanel value={1}>
<b>Second</b> tab panel
</TabPanel>
<TabPanel value={2}>
<b>Third</b> tab panel
</TabPanel>
</Tabs>
);
}
| 1,651 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBasic.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsBasic() {
return (
<Tabs aria-label="Basic tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
<TabPanel value={0}>
<b>First</b> tab panel
</TabPanel>
<TabPanel value={1}>
<b>Second</b> tab panel
</TabPanel>
<TabPanel value={2}>
<b>Third</b> tab panel
</TabPanel>
</Tabs>
);
}
| 1,652 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBasic.tsx.preview | <Tabs aria-label="Basic tabs" defaultValue={0}>
<TabList>
<Tab>First tab</Tab>
<Tab>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
<TabPanel value={0}>
<b>First</b> tab panel
</TabPanel>
<TabPanel value={1}>
<b>Second</b> tab panel
</TabPanel>
<TabPanel value={2}>
<b>Third</b> tab panel
</TabPanel>
</Tabs> | 1,653 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBottomNavExample.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import HomeRoundedIcon from '@mui/icons-material/HomeRounded';
import FavoriteBorder from '@mui/icons-material/FavoriteBorder';
import Search from '@mui/icons-material/Search';
import Person from '@mui/icons-material/Person';
export default function TabsBottomNavExample() {
const [index, setIndex] = React.useState(0);
const colors = ['primary', 'danger', 'success', 'warning'];
return (
<Box
sx={{
flexGrow: 1,
m: -3,
p: 4,
borderTopLeftRadius: '12px',
borderTopRightRadius: '12px',
bgcolor: `${colors[index]}.500`,
}}
>
<Tabs
size="lg"
aria-label="Bottom Navigation"
value={index}
onChange={(event, value) => setIndex(value)}
sx={(theme) => ({
p: 1,
borderRadius: 16,
maxWidth: 400,
mx: 'auto',
boxShadow: theme.shadow.sm,
'--joy-shadowChannel': theme.vars.palette[colors[index]].darkChannel,
[`& .${tabClasses.root}`]: {
py: 1,
flex: 1,
transition: '0.3s',
fontWeight: 'md',
fontSize: 'md',
[`&:not(.${tabClasses.selected}):not(:hover)`]: {
opacity: 0.7,
},
},
})}
>
<TabList
variant="plain"
size="sm"
disableUnderline
sx={{ borderRadius: 'lg', p: 0 }}
>
<Tab
disableIndicator
orientation="vertical"
{...(index === 0 && { color: colors[0] })}
>
<ListItemDecorator>
<HomeRoundedIcon />
</ListItemDecorator>
Home
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 1 && { color: colors[1] })}
>
<ListItemDecorator>
<FavoriteBorder />
</ListItemDecorator>
Likes
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 2 && { color: colors[2] })}
>
<ListItemDecorator>
<Search />
</ListItemDecorator>
Search
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 3 && { color: colors[3] })}
>
<ListItemDecorator>
<Person />
</ListItemDecorator>
Profile
</Tab>
</TabList>
</Tabs>
</Box>
);
}
| 1,654 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBottomNavExample.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import HomeRoundedIcon from '@mui/icons-material/HomeRounded';
import FavoriteBorder from '@mui/icons-material/FavoriteBorder';
import Search from '@mui/icons-material/Search';
import Person from '@mui/icons-material/Person';
export default function TabsBottomNavExample() {
const [index, setIndex] = React.useState(0);
const colors = ['primary', 'danger', 'success', 'warning'] as const;
return (
<Box
sx={{
flexGrow: 1,
m: -3,
p: 4,
borderTopLeftRadius: '12px',
borderTopRightRadius: '12px',
bgcolor: `${colors[index]}.500`,
}}
>
<Tabs
size="lg"
aria-label="Bottom Navigation"
value={index}
onChange={(event, value) => setIndex(value as number)}
sx={(theme) => ({
p: 1,
borderRadius: 16,
maxWidth: 400,
mx: 'auto',
boxShadow: theme.shadow.sm,
'--joy-shadowChannel': theme.vars.palette[colors[index]].darkChannel,
[`& .${tabClasses.root}`]: {
py: 1,
flex: 1,
transition: '0.3s',
fontWeight: 'md',
fontSize: 'md',
[`&:not(.${tabClasses.selected}):not(:hover)`]: {
opacity: 0.7,
},
},
})}
>
<TabList
variant="plain"
size="sm"
disableUnderline
sx={{ borderRadius: 'lg', p: 0 }}
>
<Tab
disableIndicator
orientation="vertical"
{...(index === 0 && { color: colors[0] })}
>
<ListItemDecorator>
<HomeRoundedIcon />
</ListItemDecorator>
Home
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 1 && { color: colors[1] })}
>
<ListItemDecorator>
<FavoriteBorder />
</ListItemDecorator>
Likes
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 2 && { color: colors[2] })}
>
<ListItemDecorator>
<Search />
</ListItemDecorator>
Search
</Tab>
<Tab
disableIndicator
orientation="vertical"
{...(index === 3 && { color: colors[3] })}
>
<ListItemDecorator>
<Person />
</ListItemDecorator>
Profile
</Tab>
</TabList>
</Tabs>
</Box>
);
}
| 1,655 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBrowserExample.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import SvgIcon from '@mui/joy/SvgIcon';
export default function TabsBrowserExample() {
const [index, setIndex] = React.useState(0);
return (
<Tabs
aria-label="tabs"
value={index}
onChange={(event, newValue) => setIndex(newValue)}
>
<TabList
variant="soft"
sx={{
[`& .${tabClasses.root}`]: {
'&[aria-selected="true"]': {
bgcolor: 'background.surface',
borderColor: 'divider',
'&::before': {
content: '""',
display: 'block',
position: 'absolute',
height: 2,
bottom: -2,
left: 0,
right: 0,
bgcolor: 'background.surface',
},
},
},
}}
>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<GoogleIcon />
</ListItemDecorator>
Google Search
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<TwitterIcon />
</ListItemDecorator>
Twitter
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<DribbbleIcon />
</ListItemDecorator>
Dribbble
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<ReactIcon />
</ListItemDecorator>
React
</Tab>
</TabList>
</Tabs>
);
}
function GoogleIcon() {
return (
<SvgIcon>
<svg
xmlns="http://www.w3.org/2000/svg"
width="705.6"
height="720"
viewBox="0 0 186.69 190.5"
fill="currentColor"
>
<g transform="translate(1184.583 765.171)">
<path
clipPath="none"
mask="none"
d="M-1089.333-687.239v36.888h51.262c-2.251 11.863-9.006 21.908-19.137 28.662l30.913 23.986c18.011-16.625 28.402-41.044 28.402-70.052 0-6.754-.606-13.249-1.732-19.483z"
fill="#4285f4"
/>
<path
clipPath="none"
mask="none"
d="M-1142.714-651.791l-6.972 5.337-24.679 19.223h0c15.673 31.086 47.796 52.561 85.03 52.561 25.717 0 47.278-8.486 63.038-23.033l-30.913-23.986c-8.486 5.715-19.31 9.179-32.125 9.179-24.765 0-45.806-16.712-53.34-39.226z"
fill="#34a853"
/>
<path
clipPath="none"
mask="none"
d="M-1174.365-712.61c-6.494 12.815-10.217 27.276-10.217 42.689s3.723 29.874 10.217 42.689c0 .086 31.693-24.592 31.693-24.592-1.905-5.715-3.031-11.776-3.031-18.098s1.126-12.383 3.031-18.098z"
fill="#fbbc05"
/>
<path
d="M-1089.333-727.244c14.028 0 26.497 4.849 36.455 14.201l27.276-27.276c-16.539-15.413-38.013-24.852-63.731-24.852-37.234 0-69.359 21.388-85.032 52.561l31.692 24.592c7.533-22.514 28.575-39.226 53.34-39.226z"
fill="#ea4335"
clipPath="none"
mask="none"
/>
</g>
</svg>
</SvgIcon>
);
}
function TwitterIcon() {
return (
<SvgIcon>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 248 204">
<path
fill="#1d9bf0"
d="M221.95 51.29c.15 2.17.15 4.34.15 6.53 0 66.73-50.8 143.69-143.69 143.69v-.04c-27.44.04-54.31-7.82-77.41-22.64 3.99.48 8 .72 12.02.73 22.74.02 44.83-7.61 62.72-21.66-21.61-.41-40.56-14.5-47.18-35.07 7.57 1.46 15.37 1.16 22.8-.87-23.56-4.76-40.51-25.46-40.51-49.5v-.64c7.02 3.91 14.88 6.08 22.92 6.32C11.58 63.31 4.74 33.79 18.14 10.71c25.64 31.55 63.47 50.73 104.08 52.76-4.07-17.54 1.49-35.92 14.61-48.25 20.34-19.12 52.33-18.14 71.45 2.19 11.31-2.23 22.15-6.38 32.07-12.26-3.77 11.69-11.66 21.62-22.2 27.93 10.01-1.18 19.79-3.86 29-7.95-6.78 10.16-15.32 19.01-25.2 26.16z"
/>
</svg>
</SvgIcon>
);
}
function DribbbleIcon() {
return (
<SvgIcon>
<svg
xmlns="http://www.w3.org/2000/svg"
height="800px"
width="800px"
version="1.1"
id="Layer_1"
viewBox="0 0 291.32 291.32"
fill="#EA4C89"
>
<g>
<path d="M145.66,0.001C65.21,0.001,0,65.22,0,145.661S65.21,291.32,145.66,291.32 s145.66-65.219,145.66-145.66S226.109,0.001,145.66,0.001z M241.239,70.5c15.658,19.883,25.245,44.717,26,71.746 c-32.682-5.726-60.867-5.899-85.22-2.039c-3.086-7.083-6.263-13.965-9.522-20.629C198.616,108.836,222.04,93.168,241.239,70.5z M224.479,53.094c-17.151,20.82-38.682,35.149-63.043,44.9c-15.595-28.895-31.635-52.975-44.453-70.554 c9.204-2.249,18.79-3.45,28.668-3.45C175.72,23.98,203.231,34.968,224.479,53.094z M93.359,35.824 c12.39,16.541,28.877,40.502,45,69.88c-34.175,9.386-72.402,11.917-111.093,12.026C35.805,81.534,60.512,51.528,93.359,35.824z M23.997,145.65l0.1-3.933h0.655c43.352,0,86.394-2.84,124.985-14.211c2.877,5.854,5.708,11.862,8.476,18.044 c-50.771,14.885-82.425,48.295-104.119,80.085C35.377,204.252,23.997,176.258,23.997,145.65z M71.828,242.26 c20.538-30.934,49.16-61.541,95.735-74.396c10.879,27.876,19.755,58.3,24.453,90.254c-14.293,5.936-29.942,9.213-46.347,9.213 C117.911,267.331,92.312,257.982,71.828,242.26z M214.393,245.993c-4.98-29.196-13.137-57.044-22.96-82.862 c21.285-2.704,45.755-2.048,74.122,3.168C259.884,199.271,240.93,227.758,214.393,245.993z" />
</g>
</svg>
</SvgIcon>
);
}
function ReactIcon() {
return (
<SvgIcon htmlColor="#087ea4">
<svg
width="100%"
height="100%"
viewBox="-10.5 -9.45 21 18.9"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="0" cy="0" r="2" fill="currentColor" />
<g stroke="currentColor" strokeWidth="1" fill="none">
<ellipse rx="10" ry="4.5" />
<ellipse rx="10" ry="4.5" transform="rotate(60)" />
<ellipse rx="10" ry="4.5" transform="rotate(120)" />
</g>
</svg>
</SvgIcon>
);
}
| 1,656 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsBrowserExample.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import SvgIcon from '@mui/joy/SvgIcon';
export default function TabsBrowserExample() {
const [index, setIndex] = React.useState(0);
return (
<Tabs
aria-label="tabs"
value={index}
onChange={(event, newValue) => setIndex(newValue as number)}
>
<TabList
variant="soft"
sx={{
[`& .${tabClasses.root}`]: {
'&[aria-selected="true"]': {
bgcolor: 'background.surface',
borderColor: 'divider',
'&::before': {
content: '""',
display: 'block',
position: 'absolute',
height: 2,
bottom: -2,
left: 0,
right: 0,
bgcolor: 'background.surface',
},
},
},
}}
>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<GoogleIcon />
</ListItemDecorator>
Google Search
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<TwitterIcon />
</ListItemDecorator>
Twitter
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<DribbbleIcon />
</ListItemDecorator>
Dribbble
</Tab>
<Tab indicatorPlacement="top">
<ListItemDecorator>
<ReactIcon />
</ListItemDecorator>
React
</Tab>
</TabList>
</Tabs>
);
}
function GoogleIcon() {
return (
<SvgIcon>
<svg
xmlns="http://www.w3.org/2000/svg"
width="705.6"
height="720"
viewBox="0 0 186.69 190.5"
fill="currentColor"
>
<g transform="translate(1184.583 765.171)">
<path
clipPath="none"
mask="none"
d="M-1089.333-687.239v36.888h51.262c-2.251 11.863-9.006 21.908-19.137 28.662l30.913 23.986c18.011-16.625 28.402-41.044 28.402-70.052 0-6.754-.606-13.249-1.732-19.483z"
fill="#4285f4"
/>
<path
clipPath="none"
mask="none"
d="M-1142.714-651.791l-6.972 5.337-24.679 19.223h0c15.673 31.086 47.796 52.561 85.03 52.561 25.717 0 47.278-8.486 63.038-23.033l-30.913-23.986c-8.486 5.715-19.31 9.179-32.125 9.179-24.765 0-45.806-16.712-53.34-39.226z"
fill="#34a853"
/>
<path
clipPath="none"
mask="none"
d="M-1174.365-712.61c-6.494 12.815-10.217 27.276-10.217 42.689s3.723 29.874 10.217 42.689c0 .086 31.693-24.592 31.693-24.592-1.905-5.715-3.031-11.776-3.031-18.098s1.126-12.383 3.031-18.098z"
fill="#fbbc05"
/>
<path
d="M-1089.333-727.244c14.028 0 26.497 4.849 36.455 14.201l27.276-27.276c-16.539-15.413-38.013-24.852-63.731-24.852-37.234 0-69.359 21.388-85.032 52.561l31.692 24.592c7.533-22.514 28.575-39.226 53.34-39.226z"
fill="#ea4335"
clipPath="none"
mask="none"
/>
</g>
</svg>
</SvgIcon>
);
}
function TwitterIcon() {
return (
<SvgIcon>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 248 204">
<path
fill="#1d9bf0"
d="M221.95 51.29c.15 2.17.15 4.34.15 6.53 0 66.73-50.8 143.69-143.69 143.69v-.04c-27.44.04-54.31-7.82-77.41-22.64 3.99.48 8 .72 12.02.73 22.74.02 44.83-7.61 62.72-21.66-21.61-.41-40.56-14.5-47.18-35.07 7.57 1.46 15.37 1.16 22.8-.87-23.56-4.76-40.51-25.46-40.51-49.5v-.64c7.02 3.91 14.88 6.08 22.92 6.32C11.58 63.31 4.74 33.79 18.14 10.71c25.64 31.55 63.47 50.73 104.08 52.76-4.07-17.54 1.49-35.92 14.61-48.25 20.34-19.12 52.33-18.14 71.45 2.19 11.31-2.23 22.15-6.38 32.07-12.26-3.77 11.69-11.66 21.62-22.2 27.93 10.01-1.18 19.79-3.86 29-7.95-6.78 10.16-15.32 19.01-25.2 26.16z"
/>
</svg>
</SvgIcon>
);
}
function DribbbleIcon() {
return (
<SvgIcon>
<svg
xmlns="http://www.w3.org/2000/svg"
height="800px"
width="800px"
version="1.1"
id="Layer_1"
viewBox="0 0 291.32 291.32"
fill="#EA4C89"
>
<g>
<path d="M145.66,0.001C65.21,0.001,0,65.22,0,145.661S65.21,291.32,145.66,291.32 s145.66-65.219,145.66-145.66S226.109,0.001,145.66,0.001z M241.239,70.5c15.658,19.883,25.245,44.717,26,71.746 c-32.682-5.726-60.867-5.899-85.22-2.039c-3.086-7.083-6.263-13.965-9.522-20.629C198.616,108.836,222.04,93.168,241.239,70.5z M224.479,53.094c-17.151,20.82-38.682,35.149-63.043,44.9c-15.595-28.895-31.635-52.975-44.453-70.554 c9.204-2.249,18.79-3.45,28.668-3.45C175.72,23.98,203.231,34.968,224.479,53.094z M93.359,35.824 c12.39,16.541,28.877,40.502,45,69.88c-34.175,9.386-72.402,11.917-111.093,12.026C35.805,81.534,60.512,51.528,93.359,35.824z M23.997,145.65l0.1-3.933h0.655c43.352,0,86.394-2.84,124.985-14.211c2.877,5.854,5.708,11.862,8.476,18.044 c-50.771,14.885-82.425,48.295-104.119,80.085C35.377,204.252,23.997,176.258,23.997,145.65z M71.828,242.26 c20.538-30.934,49.16-61.541,95.735-74.396c10.879,27.876,19.755,58.3,24.453,90.254c-14.293,5.936-29.942,9.213-46.347,9.213 C117.911,267.331,92.312,257.982,71.828,242.26z M214.393,245.993c-4.98-29.196-13.137-57.044-22.96-82.862 c21.285-2.704,45.755-2.048,74.122,3.168C259.884,199.271,240.93,227.758,214.393,245.993z" />
</g>
</svg>
</SvgIcon>
);
}
function ReactIcon() {
return (
<SvgIcon htmlColor="#087ea4">
<svg
width="100%"
height="100%"
viewBox="-10.5 -9.45 21 18.9"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="0" cy="0" r="2" fill="currentColor" />
<g stroke="currentColor" strokeWidth="1" fill="none">
<ellipse rx="10" ry="4.5" />
<ellipse rx="10" ry="4.5" transform="rotate(60)" />
<ellipse rx="10" ry="4.5" transform="rotate(120)" />
</g>
</svg>
</SvgIcon>
);
}
| 1,657 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsFlex.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import Stack from '@mui/joy/Stack';
export default function TabsFlex() {
return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Tabs aria-label="Flex one tabs">
<TabList tabFlex={1}>
<Tab>First tab</Tab>
<Tab
sx={{
wordBreak: 'break-word',
}}
>
Example of a very long tab label
</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
<Tabs aria-label="Flex auto tabs">
<TabList tabFlex="auto">
<Tab>First tab</Tab>
<Tab>Example of a very long tab label</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
</Stack>
);
}
| 1,658 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsFlex.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import Stack from '@mui/joy/Stack';
export default function TabsFlex() {
return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Tabs aria-label="Flex one tabs">
<TabList tabFlex={1}>
<Tab>First tab</Tab>
<Tab
sx={{
wordBreak: 'break-word',
}}
>
Example of a very long tab label
</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
<Tabs aria-label="Flex auto tabs">
<TabList tabFlex="auto">
<Tab>First tab</Tab>
<Tab>Example of a very long tab label</Tab>
<Tab>Third tab</Tab>
</TabList>
</Tabs>
</Stack>
);
}
| 1,659 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsFlexPlacement.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsFlexPlacement() {
const [direction, setDirection] = React.useState('column');
const [placement, setPlacement] = React.useState('bottom');
return (
<Box sx={{ display: 'grid', gridTemplateColumns: '180px 140px', gap: 1.5 }}>
<FormControl>
<FormLabel>Flex direction</FormLabel>
<Select
value={direction}
onChange={(event, newValue) => setDirection(newValue)}
>
<Option value="column">Column</Option>
<Option value="column-reverse">Column Reverse</Option>
<Option value="row">Row</Option>
<Option value="row-reverse">Row Reverse</Option>
</Select>
</FormControl>
<FormControl>
<FormLabel>Placement</FormLabel>
<Select
value={placement}
onChange={(event, newValue) => setPlacement(newValue)}
>
<Option value="top">top</Option>
<Option value="bottom">bottom</Option>
<Option value="left">left</Option>
<Option value="right">right</Option>
</Select>
</FormControl>
<Tabs
variant="outlined"
orientation={direction.startsWith('row') ? 'vertical' : 'horizontal'}
aria-label="Placement indicator tabs"
defaultValue="a"
sx={{
gridColumn: '1/-1',
height: 180,
flexDirection: direction,
}}
>
<TabList underlinePlacement={placement}>
<Tab indicatorPlacement={placement} value="a">
Tab A
</Tab>
<Tab indicatorPlacement={placement} value="b">
Tab B
</Tab>
<Tab indicatorPlacement={placement} value="c">
Tab C
</Tab>
</TabList>
<TabPanel value="a">Content of Tab A</TabPanel>
<TabPanel value="b">Content of Tab B</TabPanel>
<TabPanel value="c">Content of Tab C</TabPanel>
</Tabs>
</Box>
);
}
| 1,660 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsFlexPlacement.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsFlexPlacement() {
const [direction, setDirection] = React.useState<
'row' | 'column' | 'row-reverse' | 'column-reverse'
>('column');
const [placement, setPlacement] = React.useState<
'top' | 'bottom' | 'left' | 'right'
>('bottom');
return (
<Box sx={{ display: 'grid', gridTemplateColumns: '180px 140px', gap: 1.5 }}>
<FormControl>
<FormLabel>Flex direction</FormLabel>
<Select
value={direction}
onChange={(event, newValue) => setDirection(newValue!)}
>
<Option value="column">Column</Option>
<Option value="column-reverse">Column Reverse</Option>
<Option value="row">Row</Option>
<Option value="row-reverse">Row Reverse</Option>
</Select>
</FormControl>
<FormControl>
<FormLabel>Placement</FormLabel>
<Select
value={placement}
onChange={(event, newValue) => setPlacement(newValue!)}
>
<Option value="top">top</Option>
<Option value="bottom">bottom</Option>
<Option value="left">left</Option>
<Option value="right">right</Option>
</Select>
</FormControl>
<Tabs
variant="outlined"
orientation={direction.startsWith('row') ? 'vertical' : 'horizontal'}
aria-label="Placement indicator tabs"
defaultValue="a"
sx={{
gridColumn: '1/-1',
height: 180,
flexDirection: direction,
}}
>
<TabList underlinePlacement={placement}>
<Tab indicatorPlacement={placement} value="a">
Tab A
</Tab>
<Tab indicatorPlacement={placement} value="b">
Tab B
</Tab>
<Tab indicatorPlacement={placement} value="c">
Tab C
</Tab>
</TabList>
<TabPanel value="a">Content of Tab A</TabPanel>
<TabPanel value="b">Content of Tab B</TabPanel>
<TabPanel value="c">Content of Tab C</TabPanel>
</Tabs>
</Box>
);
}
| 1,661 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIcon.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
export default function TabsIcon() {
return (
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList>
<Tab>
<PhoneIcon />
</Tab>
<Tab>
<FavoriteIcon />
</Tab>
<Tab>
<PersonPinIcon />
</Tab>
</TabList>
</Tabs>
);
}
| 1,662 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIcon.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
export default function TabsIcon() {
return (
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList>
<Tab>
<PhoneIcon />
</Tab>
<Tab>
<FavoriteIcon />
</Tab>
<Tab>
<PersonPinIcon />
</Tab>
</TabList>
</Tabs>
);
}
| 1,663 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIcon.tsx.preview | <Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList>
<Tab>
<PhoneIcon />
</Tab>
<Tab>
<FavoriteIcon />
</Tab>
<Tab>
<PersonPinIcon />
</Tab>
</TabList>
</Tabs> | 1,664 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIconWithText.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Stack from '@mui/joy/Stack';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
export default function TabsIconWithText() {
return (
<Stack spacing={2}>
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList>
<Tab>
<ListItemDecorator>
<PhoneIcon />
</ListItemDecorator>
Recents
</Tab>
<Tab>
<ListItemDecorator>
<FavoriteIcon />
</ListItemDecorator>
Favorite
</Tab>
<Tab>
<ListItemDecorator>
<PersonPinIcon />
</ListItemDecorator>
Nearby
</Tab>
</TabList>
</Tabs>
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList tabFlex="auto">
<Tab orientation="vertical">
<ListItemDecorator>
<PhoneIcon />
</ListItemDecorator>
Recents
</Tab>
<Tab orientation="vertical">
<ListItemDecorator>
<FavoriteIcon />
</ListItemDecorator>
Favorite
</Tab>
<Tab orientation="vertical">
<ListItemDecorator>
<PersonPinIcon />
</ListItemDecorator>
Nearby
</Tab>
</TabList>
</Tabs>
</Stack>
);
}
| 1,665 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIconWithText.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import Stack from '@mui/joy/Stack';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
export default function TabsIconWithText() {
return (
<Stack spacing={2}>
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList>
<Tab>
<ListItemDecorator>
<PhoneIcon />
</ListItemDecorator>
Recents
</Tab>
<Tab>
<ListItemDecorator>
<FavoriteIcon />
</ListItemDecorator>
Favorite
</Tab>
<Tab>
<ListItemDecorator>
<PersonPinIcon />
</ListItemDecorator>
Nearby
</Tab>
</TabList>
</Tabs>
<Tabs aria-label="Icon tabs" defaultValue={0}>
<TabList tabFlex="auto">
<Tab orientation="vertical">
<ListItemDecorator>
<PhoneIcon />
</ListItemDecorator>
Recents
</Tab>
<Tab orientation="vertical">
<ListItemDecorator>
<FavoriteIcon />
</ListItemDecorator>
Favorite
</Tab>
<Tab orientation="vertical">
<ListItemDecorator>
<PersonPinIcon />
</ListItemDecorator>
Nearby
</Tab>
</TabList>
</Tabs>
</Stack>
);
}
| 1,666 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIndicatorPlacement.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsIndicatorPlacement() {
return (
<Tabs defaultValue="top">
<TabList underlinePlacement="bottom">
<Tab value="top" indicatorPlacement="top">
Top
</Tab>
<Tab value="right" indicatorPlacement="right">
Right
</Tab>
<Tab value="bottom" indicatorPlacement="bottom">
Bottom
</Tab>
<Tab value="left" indicatorPlacement="left">
Left
</Tab>
</TabList>
<TabPanel value="top">
IndicatorPlacement <b>Top</b>
</TabPanel>
<TabPanel value="right">
IndicatorPlacement <b>Right</b>
</TabPanel>
<TabPanel value="bottom">
IndicatorPlacement <b>Bottom</b>
</TabPanel>
<TabPanel value="left">
IndicatorPlacement <b>Left</b>
</TabPanel>
</Tabs>
);
}
| 1,667 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsIndicatorPlacement.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsIndicatorPlacement() {
return (
<Tabs defaultValue="top">
<TabList underlinePlacement="bottom">
<Tab value="top" indicatorPlacement="top">
Top
</Tab>
<Tab value="right" indicatorPlacement="right">
Right
</Tab>
<Tab value="bottom" indicatorPlacement="bottom">
Bottom
</Tab>
<Tab value="left" indicatorPlacement="left">
Left
</Tab>
</TabList>
<TabPanel value="top">
IndicatorPlacement <b>Top</b>
</TabPanel>
<TabPanel value="right">
IndicatorPlacement <b>Right</b>
</TabPanel>
<TabPanel value="bottom">
IndicatorPlacement <b>Bottom</b>
</TabPanel>
<TabPanel value="left">
IndicatorPlacement <b>Left</b>
</TabPanel>
</Tabs>
);
}
| 1,668 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsPageExample.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsPageExample() {
const [index, setIndex] = React.useState(0);
return (
<Box
sx={{
flexGrow: 1,
m: -2,
overflowX: 'hidden',
}}
>
<Tabs
aria-label="Pipeline"
value={index}
onChange={(event, value) => setIndex(value)}
>
<TabList
sx={{
pt: 1,
justifyContent: 'center',
[`&& .${tabClasses.root}`]: {
flex: 'initial',
bgcolor: 'transparent',
'&:hover': {
bgcolor: 'transparent',
},
[`&.${tabClasses.selected}`]: {
color: 'primary.plainColor',
'&::after': {
height: 2,
borderTopLeftRadius: 3,
borderTopRightRadius: 3,
bgcolor: 'primary.500',
},
},
},
}}
>
<Tab indicatorInset>
Deals{' '}
<Chip
size="sm"
variant="soft"
color={index === 0 ? 'primary' : 'neutral'}
>
14
</Chip>
</Tab>
<Tab indicatorInset>
Library{' '}
<Chip
size="sm"
variant="soft"
color={index === 1 ? 'primary' : 'neutral'}
>
20
</Chip>
</Tab>
<Tab indicatorInset>
Products{' '}
<Chip
size="sm"
variant="soft"
color={index === 2 ? 'primary' : 'neutral'}
>
8
</Chip>
</Tab>
</TabList>
<Box
sx={(theme) => ({
'--bg': theme.vars.palette.background.surface,
background: 'var(--bg)',
boxShadow: '0 0 0 100vmax var(--bg)',
clipPath: 'inset(0 -100vmax)',
})}
>
<TabPanel value={0}>Deals</TabPanel>
<TabPanel value={1}>Library</TabPanel>
<TabPanel value={2}>Products</TabPanel>
</Box>
</Tabs>
</Box>
);
}
| 1,669 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsPageExample.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsPageExample() {
const [index, setIndex] = React.useState(0);
return (
<Box
sx={{
flexGrow: 1,
m: -2,
overflowX: 'hidden',
}}
>
<Tabs
aria-label="Pipeline"
value={index}
onChange={(event, value) => setIndex(value as number)}
>
<TabList
sx={{
pt: 1,
justifyContent: 'center',
[`&& .${tabClasses.root}`]: {
flex: 'initial',
bgcolor: 'transparent',
'&:hover': {
bgcolor: 'transparent',
},
[`&.${tabClasses.selected}`]: {
color: 'primary.plainColor',
'&::after': {
height: 2,
borderTopLeftRadius: 3,
borderTopRightRadius: 3,
bgcolor: 'primary.500',
},
},
},
}}
>
<Tab indicatorInset>
Deals{' '}
<Chip
size="sm"
variant="soft"
color={index === 0 ? 'primary' : 'neutral'}
>
14
</Chip>
</Tab>
<Tab indicatorInset>
Library{' '}
<Chip
size="sm"
variant="soft"
color={index === 1 ? 'primary' : 'neutral'}
>
20
</Chip>
</Tab>
<Tab indicatorInset>
Products{' '}
<Chip
size="sm"
variant="soft"
color={index === 2 ? 'primary' : 'neutral'}
>
8
</Chip>
</Tab>
</TabList>
<Box
sx={(theme) => ({
'--bg': theme.vars.palette.background.surface,
background: 'var(--bg)',
boxShadow: '0 0 0 100vmax var(--bg)',
clipPath: 'inset(0 -100vmax)',
})}
>
<TabPanel value={0}>Deals</TabPanel>
<TabPanel value={1}>Library</TabPanel>
<TabPanel value={2}>Products</TabPanel>
</Box>
</Tabs>
</Box>
);
}
| 1,670 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsPricingExample.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
import Typography from '@mui/joy/Typography';
export default function TabsPricingExample() {
return (
<Tabs
variant="outlined"
aria-label="Pricing plan"
defaultValue={0}
sx={{
width: 343,
borderRadius: 'lg',
boxShadow: 'sm',
overflow: 'auto',
}}
>
<TabList
disableUnderline
tabFlex={1}
sx={{
[`& .${tabClasses.root}`]: {
fontSize: 'sm',
fontWeight: 'lg',
[`&[aria-selected="true"]`]: {
color: 'primary.500',
bgcolor: 'background.surface',
},
[`&.${tabClasses.focusVisible}`]: {
outlineOffset: '-4px',
},
},
}}
>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Community
</Tab>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Pro
</Tab>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Premium
</Tab>
</TabList>
<TabPanel value={0}>
<Typography level="inherit">
Get started with the industry-standard React UI library, MIT-licensed.
</Typography>
<Typography textColor="success.400" fontSize="xl3" fontWeight="xl" mt={1}>
$0{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
- Free forever
</Typography>
</Typography>
</TabPanel>
<TabPanel value={1}>
<Typography level="inherit">
Best for professional developers building enterprise or data-rich
applications.
</Typography>
<Typography textColor="primary.400" fontSize="xl3" fontWeight="xl" mt={1}>
$15{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
/ dev / month
</Typography>
</Typography>
</TabPanel>
<TabPanel value={2}>
<Typography level="inherit">
The most advanced features for data-rich applications, as well as the
highest priority for support.
</Typography>
<Typography textColor="primary.400" fontSize="xl3" fontWeight="xl" mt={1}>
<Typography
fontSize="xl"
borderRadius="sm"
px={0.5}
mr={0.5}
sx={(theme) => ({
...theme.variants.soft.danger,
color: 'danger.400',
verticalAlign: 'text-top',
textDecoration: 'line-through',
})}
>
$49
</Typography>
$37*{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
/ dev / month
</Typography>
</Typography>
</TabPanel>
</Tabs>
);
}
| 1,671 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsPricingExample.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
import Typography from '@mui/joy/Typography';
export default function TabsPricingExample() {
return (
<Tabs
variant="outlined"
aria-label="Pricing plan"
defaultValue={0}
sx={{
width: 343,
borderRadius: 'lg',
boxShadow: 'sm',
overflow: 'auto',
}}
>
<TabList
disableUnderline
tabFlex={1}
sx={{
[`& .${tabClasses.root}`]: {
fontSize: 'sm',
fontWeight: 'lg',
[`&[aria-selected="true"]`]: {
color: 'primary.500',
bgcolor: 'background.surface',
},
[`&.${tabClasses.focusVisible}`]: {
outlineOffset: '-4px',
},
},
}}
>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Community
</Tab>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Pro
</Tab>
<Tab disableIndicator variant="soft" sx={{ flexGrow: 1 }}>
Premium
</Tab>
</TabList>
<TabPanel value={0}>
<Typography level="inherit">
Get started with the industry-standard React UI library, MIT-licensed.
</Typography>
<Typography textColor="success.400" fontSize="xl3" fontWeight="xl" mt={1}>
$0{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
- Free forever
</Typography>
</Typography>
</TabPanel>
<TabPanel value={1}>
<Typography level="inherit">
Best for professional developers building enterprise or data-rich
applications.
</Typography>
<Typography textColor="primary.400" fontSize="xl3" fontWeight="xl" mt={1}>
$15{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
/ dev / month
</Typography>
</Typography>
</TabPanel>
<TabPanel value={2}>
<Typography level="inherit">
The most advanced features for data-rich applications, as well as the
highest priority for support.
</Typography>
<Typography textColor="primary.400" fontSize="xl3" fontWeight="xl" mt={1}>
<Typography
fontSize="xl"
borderRadius="sm"
px={0.5}
mr={0.5}
sx={(theme) => ({
...theme.variants.soft.danger,
color: 'danger.400',
verticalAlign: 'text-top',
textDecoration: 'line-through',
})}
>
$49
</Typography>
$37*{' '}
<Typography fontSize="sm" textColor="text.secondary" fontWeight="md">
/ dev / month
</Typography>
</Typography>
</TabPanel>
</Tabs>
);
}
| 1,672 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsScrollable.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabsScrollable() {
return (
<Tabs aria-label="Scrollable tabs" defaultValue={0} sx={{ width: 400 }}>
<TabList
sx={{
overflow: 'auto',
scrollSnapType: 'x mandatory',
'&::-webkit-scrollbar': { display: 'none' },
}}
>
{[...Array(20)].map((_, index) => (
<Tab key={index} sx={{ flex: 'none', scrollSnapAlign: 'start' }}>
Tab #{index + 1}
</Tab>
))}
</TabList>
</Tabs>
);
}
| 1,673 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsScrollable.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabsScrollable() {
return (
<Tabs aria-label="Scrollable tabs" defaultValue={0} sx={{ width: 400 }}>
<TabList
sx={{
overflow: 'auto',
scrollSnapType: 'x mandatory',
'&::-webkit-scrollbar': { display: 'none' },
}}
>
{[...Array(20)].map((_, index) => (
<Tab key={index} sx={{ flex: 'none', scrollSnapAlign: 'start' }}>
Tab #{index + 1}
</Tab>
))}
</TabList>
</Tabs>
);
}
| 1,674 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsScrollable.tsx.preview | <Tabs aria-label="Scrollable tabs" defaultValue={0} sx={{ width: 400 }}>
<TabList
sx={{
overflow: 'auto',
scrollSnapType: 'x mandatory',
'&::-webkit-scrollbar': { display: 'none' },
}}
>
{[...Array(20)].map((_, index) => (
<Tab key={index} sx={{ flex: 'none', scrollSnapAlign: 'start' }}>
Tab #{index + 1}
</Tab>
))}
</TabList>
</Tabs> | 1,675 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsSegmentedControls.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
export default function TabsSegmentedControls() {
return (
<Tabs aria-label="tabs" defaultValue={0} sx={{ bgcolor: 'transparent' }}>
<TabList
disableUnderline
sx={{
p: 0.5,
gap: 0.5,
borderRadius: 'xl',
bgcolor: 'background.level1',
[`& .${tabClasses.root}[aria-selected="true"]`]: {
boxShadow: 'sm',
bgcolor: 'background.surface',
},
}}
>
<Tab disableIndicator>Feature</Tab>
<Tab disableIndicator>Specifications</Tab>
<Tab disableIndicator>Review</Tab>
<Tab disableIndicator>Support</Tab>
</TabList>
</Tabs>
);
}
| 1,676 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsSegmentedControls.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab, { tabClasses } from '@mui/joy/Tab';
export default function TabsSegmentedControls() {
return (
<Tabs aria-label="tabs" defaultValue={0} sx={{ bgcolor: 'transparent' }}>
<TabList
disableUnderline
sx={{
p: 0.5,
gap: 0.5,
borderRadius: 'xl',
bgcolor: 'background.level1',
[`& .${tabClasses.root}[aria-selected="true"]`]: {
boxShadow: 'sm',
bgcolor: 'background.surface',
},
}}
>
<Tab disableIndicator>Feature</Tab>
<Tab disableIndicator>Specifications</Tab>
<Tab disableIndicator>Review</Tab>
<Tab disableIndicator>Support</Tab>
</TabList>
</Tabs>
);
}
| 1,677 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsSticky.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabsSticky() {
const [sticky, setSticky] = React.useState('top');
const items = [
<TabList
key="tablist"
sticky={sticky}
variant="soft"
underlinePlacement={{ top: 'bottom', bottom: 'top' }[sticky]}
>
<Tab indicatorPlacement={{ top: 'bottom', bottom: 'top' }[sticky]} value="top">
Sticky top
</Tab>
<Tab
indicatorPlacement={{ top: 'bottom', bottom: 'top' }[sticky]}
value="bottom"
>
Sticky bottom
</Tab>
</TabList>,
<div key="tabpanel">
{[...new Array(50)].map((_, index) => (
<div key={index}>Long content</div>
))}
</div>,
];
return (
<Tabs
aria-label="Sticky tabs"
value={sticky}
onChange={(event, newValue) => setSticky(newValue)}
sx={{
p: 1,
maxHeight: 200,
overflowY: 'auto',
}}
>
{sticky === 'top' ? items : items.reverse()}
</Tabs>
);
}
| 1,678 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsUnderlinePlacement.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsUnderlinePlacement() {
const [placement, setPlacement] = React.useState('top');
return (
<Tabs
variant="plain"
aria-label="Placement indicator tabs"
value={placement}
onChange={(event, newValue) => setPlacement(newValue)}
>
<TabList underlinePlacement={placement}>
<Tab disableIndicator value="top">
Top
</Tab>
<Tab disableIndicator value="right">
Right
</Tab>
<Tab disableIndicator value="bottom">
Bottom
</Tab>
<Tab disableIndicator value="left">
Left
</Tab>
</TabList>
<TabPanel value="top">
underlinePlacement <b>Top</b>
</TabPanel>
<TabPanel value="bottom">
underlinePlacement <b>Bottom</b>
</TabPanel>
<TabPanel value="left">
underlinePlacement <b>Left</b>
</TabPanel>
<TabPanel value="right">
underlinePlacement <b>Right</b>
</TabPanel>
</Tabs>
);
}
| 1,679 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsUnderlinePlacement.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsUnderlinePlacement() {
const [placement, setPlacement] = React.useState<
'top' | 'bottom' | 'left' | 'right'
>('top');
return (
<Tabs
variant="plain"
aria-label="Placement indicator tabs"
value={placement}
onChange={(event, newValue) => setPlacement(newValue as typeof placement)}
>
<TabList underlinePlacement={placement}>
<Tab disableIndicator value="top">
Top
</Tab>
<Tab disableIndicator value="right">
Right
</Tab>
<Tab disableIndicator value="bottom">
Bottom
</Tab>
<Tab disableIndicator value="left">
Left
</Tab>
</TabList>
<TabPanel value="top">
underlinePlacement <b>Top</b>
</TabPanel>
<TabPanel value="bottom">
underlinePlacement <b>Bottom</b>
</TabPanel>
<TabPanel value="left">
underlinePlacement <b>Left</b>
</TabPanel>
<TabPanel value="right">
underlinePlacement <b>Right</b>
</TabPanel>
</Tabs>
);
}
| 1,680 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsUsage.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
import Apps from '@mui/icons-material/Apps';
export default function TabsUsage() {
const [index, setIndex] = React.useState(0);
return (
<JoyUsageDemo
componentName="Tabs"
data={[
{
formLabel: 'Selected tab variant',
propName: 'variant',
knob: 'radio',
defaultValue: 'plain',
options: ['plain', 'outlined', 'soft', 'solid'],
codeBlockDisplay: false,
},
{
formLabel: 'Selected tab color',
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
codeBlockDisplay: false,
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'orientation',
knob: 'radio',
options: ['horizontal', 'vertical'],
defaultValue: 'horizontal',
},
{
formLabel: 'Disable TabList underline',
propName: 'disableUnderline',
knob: 'switch',
defaultValue: false,
codeBlockDisplay: false,
},
{
formLabel: 'Tab indicator inset',
propName: 'indicatorInset',
knob: 'switch',
defaultValue: false,
codeBlockDisplay: false,
},
{
formLabel: 'Disable Tab indicator',
propName: 'disableIndicator',
knob: 'switch',
defaultValue: false,
codeBlockDisplay: false,
},
{
propName: 'children',
defaultValue: '$children',
},
]}
getCodeBlock={(code, props) =>
code.replace(
'$children',
`<TabList${props.disableUnderline ? ` disableUnderline` : ''}>
<Tab${
props.variant
? `
variant="${props.variant}"`
: ''
}${
props.color
? `
color="${props.color}"`
: ''
}${
props.disableIndicator
? `
disableIndicator`
: ''
}${
props.indicatorInset
? `
indicatorInset`
: ''
}>...</Tab>
</TabList>
<TabPanel>...</TabPanel>`,
)
}
renderDemo={({
color,
variant,
disableUnderline,
indicatorInset,
disableIndicator,
...props
}) => (
<Tabs {...props} value={index} onChange={(event, value) => setIndex(value)}>
<TabList disableUnderline={disableUnderline}>
<Tab
indicatorInset={indicatorInset}
disableIndicator={disableIndicator}
{...(index === 0 && { color, variant })}
>
<Apps />
Tab A
</Tab>
<Tab
indicatorInset={indicatorInset}
disableIndicator={disableIndicator}
{...(index === 1 && { color, variant })}
>
Tab B
</Tab>
<Tab
indicatorInset={indicatorInset}
disableIndicator={disableIndicator}
{...(index === 2 && { color, variant })}
>
Tab C
</Tab>
</TabList>
<TabPanel value={0}>Content of Tab A</TabPanel>
<TabPanel value={1}>Content of Tab B</TabPanel>
<TabPanel value={2}>Content of Tab C</TabPanel>
</Tabs>
)}
/>
);
}
| 1,681 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsVariables.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo';
export default function TabsVariables() {
return (
<JoyVariablesDemo
componentName="Tabs"
childrenAccepted
data={[
{
var: '--Tabs-spacing',
defaultValue: '16px',
helperText: "Controls TabList's gap and TabPanel's padding.",
},
{
var: '--Tab-indicatorThickness',
defaultValue: '2px',
},
{
var: '--Tab-indicatorSize',
defaultValue: '0px',
},
{
var: '--Tab-indicatorRadius',
defaultValue: '0px',
},
]}
renderDemo={(sx) => (
<Tabs sx={sx} defaultValue={0}>
<TabList>
<Tab>Tab A</Tab>
<Tab>Tab B</Tab>
<Tab>Tab C</Tab>
</TabList>
<TabPanel value={0}>Tab A content</TabPanel>
<TabPanel value={1}>Tab B content</TabPanel>
<TabPanel value={2}>Tab C content</TabPanel>
</Tabs>
)}
/>
);
}
| 1,682 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsVariants.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabsVariants() {
const [index, setIndex] = React.useState(0);
return (
<Box sx={{ display: 'flex', gap: 2, flexDirection: 'column' }}>
<Tabs
aria-label="Plain tabs"
value={index}
onChange={(event, value) => setIndex(value)}
>
<TabList variant="plain">
<Tab variant={index === 0 ? 'outlined' : 'plain'}>First tab</Tab>
<Tab variant={index === 1 ? 'outlined' : 'plain'}>Second tab</Tab>
<Tab variant={index === 2 ? 'outlined' : 'plain'}>Third tab</Tab>
</TabList>
</Tabs>
<Tabs
aria-label="Outlined tabs"
value={index}
onChange={(event, value) => setIndex(value)}
>
<TabList variant="outlined" disableUnderline>
<Tab
variant={index === 0 ? 'soft' : 'plain'}
color={index === 0 ? 'success' : 'neutral'}
>
First tab
</Tab>
<Tab
variant={index === 1 ? 'soft' : 'plain'}
color={index === 1 ? 'warning' : 'neutral'}
>
Second tab
</Tab>
<Tab
variant={index === 2 ? 'soft' : 'plain'}
color={index === 2 ? 'danger' : 'neutral'}
>
Third tab
</Tab>
</TabList>
</Tabs>
<Tabs
aria-label="Soft tabs"
value={index}
onChange={(event, value) => setIndex(value)}
>
<TabList variant="soft">
<Tab
variant={index === 0 ? 'solid' : 'plain'}
color={index === 0 ? 'primary' : 'neutral'}
>
First tab
</Tab>
<Tab
variant={index === 1 ? 'solid' : 'plain'}
color={index === 1 ? 'primary' : 'neutral'}
>
Second tab
</Tab>
<Tab
variant={index === 2 ? 'solid' : 'plain'}
color={index === 2 ? 'primary' : 'neutral'}
>
Third tab
</Tab>
</TabList>
</Tabs>
</Box>
);
}
| 1,683 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsVariants.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
export default function TabsVariants() {
const [index, setIndex] = React.useState(0);
return (
<Box sx={{ display: 'flex', gap: 2, flexDirection: 'column' }}>
<Tabs
aria-label="Plain tabs"
value={index}
onChange={(event, value) => setIndex(value as number)}
>
<TabList variant="plain">
<Tab variant={index === 0 ? 'outlined' : 'plain'}>First tab</Tab>
<Tab variant={index === 1 ? 'outlined' : 'plain'}>Second tab</Tab>
<Tab variant={index === 2 ? 'outlined' : 'plain'}>Third tab</Tab>
</TabList>
</Tabs>
<Tabs
aria-label="Outlined tabs"
value={index}
onChange={(event, value) => setIndex(value as number)}
>
<TabList variant="outlined" disableUnderline>
<Tab
variant={index === 0 ? 'soft' : 'plain'}
color={index === 0 ? 'success' : 'neutral'}
>
First tab
</Tab>
<Tab
variant={index === 1 ? 'soft' : 'plain'}
color={index === 1 ? 'warning' : 'neutral'}
>
Second tab
</Tab>
<Tab
variant={index === 2 ? 'soft' : 'plain'}
color={index === 2 ? 'danger' : 'neutral'}
>
Third tab
</Tab>
</TabList>
</Tabs>
<Tabs
aria-label="Soft tabs"
value={index}
onChange={(event, value) => setIndex(value as number)}
>
<TabList variant="soft">
<Tab
variant={index === 0 ? 'solid' : 'plain'}
color={index === 0 ? 'primary' : 'neutral'}
>
First tab
</Tab>
<Tab
variant={index === 1 ? 'solid' : 'plain'}
color={index === 1 ? 'primary' : 'neutral'}
>
Second tab
</Tab>
<Tab
variant={index === 2 ? 'solid' : 'plain'}
color={index === 2 ? 'primary' : 'neutral'}
>
Third tab
</Tab>
</TabList>
</Tabs>
</Box>
);
}
| 1,684 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsVertical.js | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsVertical() {
return (
<Tabs
aria-label="Vertical tabs"
orientation="vertical"
sx={{ minWidth: 300, height: 160 }}
>
<TabList>
<Tab>First tab</Tab>
<Tab>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
<TabPanel value={0}>
<b>First</b> tab panel
</TabPanel>
<TabPanel value={1}>
<b>Second</b> tab panel
</TabPanel>
<TabPanel value={2}>
<b>Third</b> tab panel
</TabPanel>
</Tabs>
);
}
| 1,685 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/TabsVertical.tsx | import * as React from 'react';
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
import TabPanel from '@mui/joy/TabPanel';
export default function TabsVertical() {
return (
<Tabs
aria-label="Vertical tabs"
orientation="vertical"
sx={{ minWidth: 300, height: 160 }}
>
<TabList>
<Tab>First tab</Tab>
<Tab>Second tab</Tab>
<Tab>Third tab</Tab>
</TabList>
<TabPanel value={0}>
<b>First</b> tab panel
</TabPanel>
<TabPanel value={1}>
<b>Second</b> tab panel
</TabPanel>
<TabPanel value={2}>
<b>Third</b> tab panel
</TabPanel>
</Tabs>
);
}
| 1,686 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/tabs/tabs.md | ---
productId: joy-ui
title: React Tabs component
components: Tab, TabList, TabPanel, Tabs
githubLabel: 'component: tabs'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/tabs/
unstyled: /base-ui/react-tabs/
---
# Tabs
<p class="description">Tabs make it easy to explore and switch between different views.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
Joy UI provides four tabs-related components:
- `Tabs`: A context provider that synchronizes the selected `Tab` with the corresponding `TabPanel`.
- `TabList`: A container that consists of `Tab` items.
- `Tab`: A button to toggle a selected tab.
- `TabPanel`: A pane that displays on the screen when its value matches with the selected tab.
{{"demo": "TabsUsage.js", "hideToolbar": true, "bg": "gradient"}}
## Basics
```jsx
import Tabs from '@mui/joy/Tabs';
import TabList from '@mui/joy/TabList';
import Tab from '@mui/joy/Tab';
```
The Joy UI set of Tabs components follows the [WAI ARIA design pattern guidelines](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/).
Use the `value` prop on the Tab Panel and the `defaultValue` prop on the Tabs component to target the selected tab.
{{"demo": "TabsBasic.js"}}
### Disabled tab
Use the `disabled` prop to disable interaction and focus.
{{"demo": "TabDisabled.js"}}
## Customization
### Variants
The `<TabList />` and `<Tab />` components accept the global `variant` prop values.
:::info
When a Tab is selected, it _won't_ apply globally defined `:hover` and `:active` styles.
:::
{{"demo": "TabsVariants.js"}}
:::warning
To learn how to add more variants to the component, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants).
:::
### Vertical
Use the `orientation="vertical"` prop on the `<Tabs />` component to make it vertical.
Keyboard navigation using arrow keys adapts automatically.
{{"demo": "TabsVertical.js"}}
### Indicator placement
Use the `underlinePlacement` prop on the Tab List component to change the placement of the underline border on the Tabs.
{{"demo": "TabsUnderlinePlacement.js"}}
Control the selected Tab indicator independently using the `indicatorPlacement` prop.
{{"demo": "TabsIndicatorPlacement.js"}}
Depending on the placement of the underline and the selected indicator, you may need to change the flex direction of the Tabs component.
{{"demo": "TabsFlexPlacement.js"}}
### Sticky
Use the `sticky` prop to anchor the Tab List component at the top or bottom.
This is ideal for use cases that involve longer content.
{{"demo": "TabsSticky.js"}}
### Tab flex
Use the `tabFlex` prop on the Tab List component to make the Tab elements fill the available space, as shown in the example below.
- In the first demo, the Tab elements fill the available space using `tabFlex={1}`.
- In the second demo, the Tab elements fill the available space equally using `tabFlex="auto"`, but the width of each respective element is based on its content.
{{"demo": "TabsFlex.js"}}
:::info
The value of the `tabFlex` prop can be any [valid CSS flex value](https://developer.mozilla.org/en-US/docs/Web/CSS/flex).
:::
### Icon
Since the Tab List component uses the same style as the [List](/joy-ui/react-list/) component, you can use the icon directly as a child, or use List Item Decorator with text.
{{"demo": "TabsIcon.js"}}
{{"demo": "TabsIconWithText.js"}}
### Scrollable tabs
Add the `overflow: auto` property to the Tab List component to make the tabs scrollable.
Polish it further by hiding the scrollbar with `'&::-webkit-scrollbar': { display: 'none' }`, and snapping the scroll to the edge of the Tab List component with [CSS scroll snap properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_scroll_snap).
{{"demo": "TabsScrollable.js"}}
## CSS variables playground
Play around with all the CSS variables available in the slider component to see how the design changes.
You can use those to customize the component on both the `sx` prop and the theme.
{{"demo": "TabsVariables.js", "hideToolbar": true, "bg": "gradient"}}
## Common examples
### Segmented controls
To mimic the segmented controls of iOS, add a border-radius to the Tab List component and set the selected Tab background to `background.surface`.
{{"demo": "TabsSegmentedControls.js"}}
### Browser tabs
In this example, the Tab's variant prop is set to `outlined` and the indicator is moved to the top via `indicatorPlacement="top"`.
The borders are then set to `transparent` based on the selected state.
{{"demo": "TabsBrowserExample.js"}}
### Pricing tabs
This example removes the background of the selected Tab by targeting the `aria-selected="true"` attribute.
{{"demo": "TabsPricingExample.js"}}
### Centered tabs
To center the Tab components in the Tab List, add the `flex: initial` property to override the default `flex-grow` behavior.
Then, on the list, add `justifyContent: center`.
{{"demo": "TabsPageExample.js"}}
### Mobile bottom navigation
In this example, each Tab is painted with a color from the theme when selected.
{{"demo": "TabsBottomNavExample.js"}}
## Accessibility
To ensure proper accessibility, the [ARIA Authoring Practices Guide](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/#wai-aria-roles-states-and-properties-22) recommends associating a label with the Tabs component.
There are two options to accomplish this:
### Using the id attribute
Add a text element close to the tabs with the `id` attribute.
Then add the `aria-labelledby` attribute to the Tabs component.
Make sure to use meaningful labels for both.
```js
<Typography id="tabs-accessibility-label">Meaningful label</Typography>
<Tabs aria-labelledby="tabs-accessibility-label">...</Tabs>
```
### Using aria-label
If a text element does not accompany your Tabs component, use the `aria-label` attribute directly to make it readable by screen readers.
```js
<Tabs aria-label="Meaningful label">...</Tabs>
```
| 1,687 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/text-field/text-field.md | ---
productId: joy-ui
title: React Text Field component
githubLabel: 'component: text field'
---
# Text Field
<p class="description">Text fields let users enter and edit text.</p>
:::warning
**TextField** component has been removed in [`@mui/[email protected]`](https://github.com/mui/material-ui/releases/tag/v5.11.5). We recommend using [`Input`](/joy-ui/react-input/), `FormControl` and `FormLabel` instead.
To learn more why it has been removed, visit the [RFC](https://github.com/mui/material-ui/issues/34176).
:::
## Migration
### Codemod
Run this [codemod](https://github.com/mui/material-ui/blob/master/packages/mui-codemod/README.md#joy-text-field-to-input) in your project's terminal:
```bash
npx @mui/codemod v5.0.0/joy-text-field-to-input <path>
```
It will go through all files under `<path>` and replace `<TextField />` with the `<Input />` composition.
### Manual
Replace the `TextField` with composition:
```diff
-import TextField from '@mui/joy/TextField';
+import FormControl from '@mui/joy/FormControl';
+import FormLabel from '@mui/joy/FormLabel';
+import FormHelperText from '@mui/joy/FormHelperText';
+import Input from '@mui/joy/Input';
-<TextField
- id="Id"
- label="Label"
- placeholder="Placeholder"
- helperText="Help!"
- name="Name"
- type="tel"
- autoComplete="on"
- autoFocus
- error
- required
- fullWidth
- defaultValue="DefaultValue"
- size="sm"
- color="primary"
- variant="outlined"
-/>
+<FormControl
+ id="Id"
+ required
+ size="sm"
+ color="primary">
+ <FormLabel>
+ Label
+ </FormLabel>
+ <Input
+ placeholder="Placeholder"
+ name="Name"
+ type="tel"
+ autoComplete="on"
+ autoFocus
+ error
+ fullWidth
+ defaultValue="DefaultValue"
+ variant="outlined" />
+ <FormHelperText>
+ Help!
+ </FormHelperText>
+</FormControl>
```
| 1,688 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/ExampleTextareaComment.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Textarea from '@mui/joy/Textarea';
import IconButton from '@mui/joy/IconButton';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import FormatBold from '@mui/icons-material/FormatBold';
import FormatItalic from '@mui/icons-material/FormatItalic';
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown';
import Check from '@mui/icons-material/Check';
export default function ExampleTextareaComment() {
const [italic, setItalic] = React.useState(false);
const [fontWeight, setFontWeight] = React.useState('normal');
const [anchorEl, setAnchorEl] = React.useState(null);
return (
<FormControl>
<FormLabel>Your comment</FormLabel>
<Textarea
placeholder="Type something here…"
minRows={3}
endDecorator={
<Box
sx={{
display: 'flex',
gap: 'var(--Textarea-paddingBlock)',
pt: 'var(--Textarea-paddingBlock)',
borderTop: '1px solid',
borderColor: 'divider',
flex: 'auto',
}}
>
<IconButton
variant="plain"
color="neutral"
onClick={(event) => setAnchorEl(event.currentTarget)}
>
<FormatBold />
<KeyboardArrowDown fontSize="md" />
</IconButton>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
size="sm"
placement="bottom-start"
sx={{ '--ListItemDecorator-size': '24px' }}
>
{['200', 'normal', 'bold'].map((weight) => (
<MenuItem
key={weight}
selected={fontWeight === weight}
onClick={() => {
setFontWeight(weight);
setAnchorEl(null);
}}
sx={{ fontWeight: weight }}
>
<ListItemDecorator>
{fontWeight === weight && <Check fontSize="sm" />}
</ListItemDecorator>
{weight === '200' ? 'lighter' : weight}
</MenuItem>
))}
</Menu>
<IconButton
variant={italic ? 'soft' : 'plain'}
color={italic ? 'primary' : 'neutral'}
aria-pressed={italic}
onClick={() => setItalic((bool) => !bool)}
>
<FormatItalic />
</IconButton>
<Button sx={{ ml: 'auto' }}>Send</Button>
</Box>
}
sx={{
minWidth: 300,
fontWeight,
fontStyle: italic ? 'italic' : 'initial',
}}
/>
</FormControl>
);
}
| 1,689 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/ExampleTextareaComment.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Textarea from '@mui/joy/Textarea';
import IconButton from '@mui/joy/IconButton';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import FormatBold from '@mui/icons-material/FormatBold';
import FormatItalic from '@mui/icons-material/FormatItalic';
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown';
import Check from '@mui/icons-material/Check';
export default function ExampleTextareaComment() {
const [italic, setItalic] = React.useState(false);
const [fontWeight, setFontWeight] = React.useState('normal');
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
return (
<FormControl>
<FormLabel>Your comment</FormLabel>
<Textarea
placeholder="Type something here…"
minRows={3}
endDecorator={
<Box
sx={{
display: 'flex',
gap: 'var(--Textarea-paddingBlock)',
pt: 'var(--Textarea-paddingBlock)',
borderTop: '1px solid',
borderColor: 'divider',
flex: 'auto',
}}
>
<IconButton
variant="plain"
color="neutral"
onClick={(event) => setAnchorEl(event.currentTarget)}
>
<FormatBold />
<KeyboardArrowDown fontSize="md" />
</IconButton>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
size="sm"
placement="bottom-start"
sx={{ '--ListItemDecorator-size': '24px' }}
>
{['200', 'normal', 'bold'].map((weight) => (
<MenuItem
key={weight}
selected={fontWeight === weight}
onClick={() => {
setFontWeight(weight);
setAnchorEl(null);
}}
sx={{ fontWeight: weight }}
>
<ListItemDecorator>
{fontWeight === weight && <Check fontSize="sm" />}
</ListItemDecorator>
{weight === '200' ? 'lighter' : weight}
</MenuItem>
))}
</Menu>
<IconButton
variant={italic ? 'soft' : 'plain'}
color={italic ? 'primary' : 'neutral'}
aria-pressed={italic}
onClick={() => setItalic((bool) => !bool)}
>
<FormatItalic />
</IconButton>
<Button sx={{ ml: 'auto' }}>Send</Button>
</Box>
}
sx={{
minWidth: 300,
fontWeight,
fontStyle: italic ? 'italic' : 'initial',
}}
/>
</FormControl>
);
}
| 1,690 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FloatingLabelTextarea.js | import * as React from 'react';
import { TextareaAutosize } from '@mui/base/TextareaAutosize';
import { styled } from '@mui/joy/styles';
import Textarea from '@mui/joy/Textarea';
const StyledTextarea = styled(TextareaAutosize)({
resize: 'none',
border: 'none', // remove the native textarea border
minWidth: 0, // remove the native textarea width
outline: 0, // remove the native textarea outline
padding: 0, // remove the native textarea padding
paddingBlockStart: '1em',
paddingInlineEnd: `var(--Textarea-paddingInline)`,
flex: 'auto',
alignSelf: 'stretch',
color: 'inherit',
backgroundColor: 'transparent',
fontFamily: 'inherit',
fontSize: 'inherit',
fontStyle: 'inherit',
fontWeight: 'inherit',
lineHeight: 'inherit',
'&::placeholder': {
opacity: 0,
transition: '0.1s ease-out',
},
'&:focus::placeholder': {
opacity: 1,
},
// specific to TextareaAutosize, cannot use '&:focus ~ label'
'&:focus + textarea + label, &:not(:placeholder-shown) + textarea + label': {
top: '0.5rem',
fontSize: '0.75rem',
},
'&:focus + textarea + label': {
color: 'var(--Textarea-focusedHighlight)',
},
});
const StyledLabel = styled('label')(({ theme }) => ({
position: 'absolute',
lineHeight: 1,
top: 'calc((var(--Textarea-minHeight) - 1em) / 2)',
color: theme.vars.palette.text.tertiary,
fontWeight: theme.vars.fontWeight.md,
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
}));
const InnerTextarea = React.forwardRef(function InnerTextarea(props, ref) {
const id = React.useId();
return (
<React.Fragment>
<StyledTextarea minRows={2} {...props} ref={ref} id={id} />
<StyledLabel htmlFor={id}>Label</StyledLabel>
</React.Fragment>
);
});
export default function FloatingLabelTextarea() {
return (
<Textarea
slots={{ textarea: InnerTextarea }}
slotProps={{ textarea: { placeholder: 'A placeholder' } }}
sx={{ borderRadius: '6px' }}
/>
);
}
| 1,691 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FloatingLabelTextarea.tsx | import * as React from 'react';
import { TextareaAutosize } from '@mui/base/TextareaAutosize';
import { styled } from '@mui/joy/styles';
import Textarea from '@mui/joy/Textarea';
const StyledTextarea = styled(TextareaAutosize)({
resize: 'none',
border: 'none', // remove the native textarea border
minWidth: 0, // remove the native textarea width
outline: 0, // remove the native textarea outline
padding: 0, // remove the native textarea padding
paddingBlockStart: '1em',
paddingInlineEnd: `var(--Textarea-paddingInline)`,
flex: 'auto',
alignSelf: 'stretch',
color: 'inherit',
backgroundColor: 'transparent',
fontFamily: 'inherit',
fontSize: 'inherit',
fontStyle: 'inherit',
fontWeight: 'inherit',
lineHeight: 'inherit',
'&::placeholder': {
opacity: 0,
transition: '0.1s ease-out',
},
'&:focus::placeholder': {
opacity: 1,
},
// specific to TextareaAutosize, cannot use '&:focus ~ label'
'&:focus + textarea + label, &:not(:placeholder-shown) + textarea + label': {
top: '0.5rem',
fontSize: '0.75rem',
},
'&:focus + textarea + label': {
color: 'var(--Textarea-focusedHighlight)',
},
});
const StyledLabel = styled('label')(({ theme }) => ({
position: 'absolute',
lineHeight: 1,
top: 'calc((var(--Textarea-minHeight) - 1em) / 2)',
color: theme.vars.palette.text.tertiary,
fontWeight: theme.vars.fontWeight.md,
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
}));
const InnerTextarea = React.forwardRef<
HTMLTextAreaElement,
JSX.IntrinsicElements['textarea']
>(function InnerTextarea(props, ref) {
const id = React.useId();
return (
<React.Fragment>
<StyledTextarea minRows={2} {...props} ref={ref} id={id} />
<StyledLabel htmlFor={id}>Label</StyledLabel>
</React.Fragment>
);
});
export default function FloatingLabelTextarea() {
return (
<Textarea
slots={{ textarea: InnerTextarea }}
slotProps={{ textarea: { placeholder: 'A placeholder' } }}
sx={{ borderRadius: '6px' }}
/>
);
}
| 1,692 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FloatingLabelTextarea.tsx.preview | <Textarea
slots={{ textarea: InnerTextarea }}
slotProps={{ textarea: { placeholder: 'A placeholder' } }}
sx={{ borderRadius: '6px' }}
/> | 1,693 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusOutlineTextarea.js | import * as React from 'react';
import Textarea from '@mui/joy/Textarea';
export default function FocusOutlineTextarea() {
return (
<Textarea
placeholder="Type in here…"
minRows={2}
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Textarea-focusedHighlight)',
outlineOffset: '2px',
},
}}
/>
);
}
| 1,694 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusOutlineTextarea.tsx | import * as React from 'react';
import Textarea from '@mui/joy/Textarea';
export default function FocusOutlineTextarea() {
return (
<Textarea
placeholder="Type in here…"
minRows={2}
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Textarea-focusedHighlight)',
outlineOffset: '2px',
},
}}
/>
);
}
| 1,695 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusOutlineTextarea.tsx.preview | <Textarea
placeholder="Type in here…"
minRows={2}
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Textarea-focusedHighlight)',
outlineOffset: '2px',
},
}}
/> | 1,696 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusedRingTextarea.js | import * as React from 'react';
import Textarea from '@mui/joy/Textarea';
export default function FocusedRingTextarea() {
return (
<Textarea
placeholder="Bootstrap"
minRows={2}
sx={{
'--Textarea-focusedInset': 'var(--any, )',
'--Textarea-focusedThickness': '0.25rem',
'--Textarea-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/>
);
}
| 1,697 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusedRingTextarea.tsx | import * as React from 'react';
import Textarea from '@mui/joy/Textarea';
export default function FocusedRingTextarea() {
return (
<Textarea
placeholder="Bootstrap"
minRows={2}
sx={{
'--Textarea-focusedInset': 'var(--any, )',
'--Textarea-focusedThickness': '0.25rem',
'--Textarea-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/>
);
}
| 1,698 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/textarea/FocusedRingTextarea.tsx.preview | <Textarea
placeholder="Bootstrap"
minRows={2}
sx={{
'--Textarea-focusedInset': 'var(--any, )',
'--Textarea-focusedThickness': '0.25rem',
'--Textarea-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/> | 1,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.