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/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/EnhancedTable.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { alpha } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TablePagination from '@mui/material/TablePagination';
import TableRow from '@mui/material/TableRow';
import TableSortLabel from '@mui/material/TableSortLabel';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
import Checkbox from '@mui/material/Checkbox';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
import DeleteIcon from '@mui/icons-material/Delete';
import FilterListIcon from '@mui/icons-material/FilterList';
import { visuallyHidden } from '@mui/utils';
function createData(id, name, calories, fat, carbs, protein) {
return {
id,
name,
calories,
fat,
carbs,
protein,
};
}
const rows = [
createData(1, 'Cupcake', 305, 3.7, 67, 4.3),
createData(2, 'Donut', 452, 25.0, 51, 4.9),
createData(3, 'Eclair', 262, 16.0, 24, 6.0),
createData(4, 'Frozen yoghurt', 159, 6.0, 24, 4.0),
createData(5, 'Gingerbread', 356, 16.0, 49, 3.9),
createData(6, 'Honeycomb', 408, 3.2, 87, 6.5),
createData(7, 'Ice cream sandwich', 237, 9.0, 37, 4.3),
createData(8, 'Jelly Bean', 375, 0.0, 94, 0.0),
createData(9, 'KitKat', 518, 26.0, 65, 7.0),
createData(10, 'Lollipop', 392, 0.2, 98, 0.0),
createData(11, 'Marshmallow', 318, 0, 81, 2.0),
createData(12, 'Nougat', 360, 19.0, 9, 37.0),
createData(13, 'Oreo', 437, 18.0, 63, 4.0),
];
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 (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
color="primary"
indeterminate={numSelected > 0 && numSelected < rowCount}
checked={rowCount > 0 && numSelected === rowCount}
onChange={onSelectAllClick}
inputProps={{
'aria-label': 'select all desserts',
}}
/>
</TableCell>
{headCells.map((headCell) => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'normal'}
sortDirection={orderBy === headCell.id ? order : false}
>
<TableSortLabel
active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
{orderBy === headCell.id ? (
<Box component="span" sx={visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</Box>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
);
}
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 (
<Toolbar
sx={{
pl: { sm: 2 },
pr: { xs: 1, sm: 1 },
...(numSelected > 0 && {
bgcolor: (theme) =>
alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity),
}),
}}
>
{numSelected > 0 ? (
<Typography
sx={{ flex: '1 1 100%' }}
color="inherit"
variant="subtitle1"
component="div"
>
{numSelected} selected
</Typography>
) : (
<Typography
sx={{ flex: '1 1 100%' }}
variant="h6"
id="tableTitle"
component="div"
>
Nutrition
</Typography>
)}
{numSelected > 0 ? (
<Tooltip title="Delete">
<IconButton>
<DeleteIcon />
</IconButton>
</Tooltip>
) : (
<Tooltip title="Filter list">
<IconButton>
<FilterListIcon />
</IconButton>
</Tooltip>
)}
</Toolbar>
);
}
EnhancedTableToolbar.propTypes = {
numSelected: PropTypes.number.isRequired,
};
export default function EnhancedTable() {
const [order, setOrder] = React.useState('asc');
const [orderBy, setOrderBy] = React.useState('calories');
const [selected, setSelected] = React.useState([]);
const [page, setPage] = React.useState(0);
const [dense, setDense] = React.useState(false);
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.id);
setSelected(newSelected);
return;
}
setSelected([]);
};
const handleClick = (event, id) => {
const selectedIndex = selected.indexOf(id);
let newSelected = [];
if (selectedIndex === -1) {
newSelected = newSelected.concat(selected, id);
} 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 = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};
const handleChangeDense = (event) => {
setDense(event.target.checked);
};
const isSelected = (id) => selected.indexOf(id) !== -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;
const visibleRows = React.useMemo(
() =>
stableSort(rows, getComparator(order, orderBy)).slice(
page * rowsPerPage,
page * rowsPerPage + rowsPerPage,
),
[order, orderBy, page, rowsPerPage],
);
return (
<Box sx={{ width: '100%' }}>
<Paper sx={{ width: '100%', mb: 2 }}>
<EnhancedTableToolbar numSelected={selected.length} />
<TableContainer>
<Table
sx={{ minWidth: 750 }}
aria-labelledby="tableTitle"
size={dense ? 'small' : 'medium'}
>
<EnhancedTableHead
numSelected={selected.length}
order={order}
orderBy={orderBy}
onSelectAllClick={handleSelectAllClick}
onRequestSort={handleRequestSort}
rowCount={rows.length}
/>
<TableBody>
{visibleRows.map((row, index) => {
const isItemSelected = isSelected(row.id);
const labelId = `enhanced-table-checkbox-${index}`;
return (
<TableRow
hover
onClick={(event) => handleClick(event, row.id)}
role="checkbox"
aria-checked={isItemSelected}
tabIndex={-1}
key={row.id}
selected={isItemSelected}
sx={{ cursor: 'pointer' }}
>
<TableCell padding="checkbox">
<Checkbox
color="primary"
checked={isItemSelected}
inputProps={{
'aria-labelledby': labelId,
}}
/>
</TableCell>
<TableCell
component="th"
id={labelId}
scope="row"
padding="none"
>
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
);
})}
{emptyRows > 0 && (
<TableRow
style={{
height: (dense ? 33 : 53) * emptyRows,
}}
>
<TableCell colSpan={6} />
</TableRow>
)}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[5, 10, 25]}
component="div"
count={rows.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</Paper>
<FormControlLabel
control={<Switch checked={dense} onChange={handleChangeDense} />}
label="Dense padding"
/>
</Box>
);
}
| 3,100 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/EnhancedTable.tsx | import * as React from 'react';
import { alpha } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TablePagination from '@mui/material/TablePagination';
import TableRow from '@mui/material/TableRow';
import TableSortLabel from '@mui/material/TableSortLabel';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
import Checkbox from '@mui/material/Checkbox';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
import DeleteIcon from '@mui/icons-material/Delete';
import FilterListIcon from '@mui/icons-material/FilterList';
import { visuallyHidden } from '@mui/utils';
interface Data {
id: number;
calories: number;
carbs: number;
fat: number;
name: string;
protein: number;
}
function createData(
id: number,
name: string,
calories: number,
fat: number,
carbs: number,
protein: number,
): Data {
return {
id,
name,
calories,
fat,
carbs,
protein,
};
}
const rows = [
createData(1, 'Cupcake', 305, 3.7, 67, 4.3),
createData(2, 'Donut', 452, 25.0, 51, 4.9),
createData(3, 'Eclair', 262, 16.0, 24, 6.0),
createData(4, 'Frozen yoghurt', 159, 6.0, 24, 4.0),
createData(5, 'Gingerbread', 356, 16.0, 49, 3.9),
createData(6, 'Honeycomb', 408, 3.2, 87, 6.5),
createData(7, 'Ice cream sandwich', 237, 9.0, 37, 4.3),
createData(8, 'Jelly Bean', 375, 0.0, 94, 0.0),
createData(9, 'KitKat', 518, 26.0, 65, 7.0),
createData(10, 'Lollipop', 392, 0.2, 98, 0.0),
createData(11, 'Marshmallow', 318, 0, 81, 2.0),
createData(12, 'Nougat', 360, 19.0, 9, 37.0),
createData(13, 'Oreo', 437, 18.0, 63, 4.0),
];
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 (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
color="primary"
indeterminate={numSelected > 0 && numSelected < rowCount}
checked={rowCount > 0 && numSelected === rowCount}
onChange={onSelectAllClick}
inputProps={{
'aria-label': 'select all desserts',
}}
/>
</TableCell>
{headCells.map((headCell) => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'normal'}
sortDirection={orderBy === headCell.id ? order : false}
>
<TableSortLabel
active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
{orderBy === headCell.id ? (
<Box component="span" sx={visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</Box>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
);
}
interface EnhancedTableToolbarProps {
numSelected: number;
}
function EnhancedTableToolbar(props: EnhancedTableToolbarProps) {
const { numSelected } = props;
return (
<Toolbar
sx={{
pl: { sm: 2 },
pr: { xs: 1, sm: 1 },
...(numSelected > 0 && {
bgcolor: (theme) =>
alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity),
}),
}}
>
{numSelected > 0 ? (
<Typography
sx={{ flex: '1 1 100%' }}
color="inherit"
variant="subtitle1"
component="div"
>
{numSelected} selected
</Typography>
) : (
<Typography
sx={{ flex: '1 1 100%' }}
variant="h6"
id="tableTitle"
component="div"
>
Nutrition
</Typography>
)}
{numSelected > 0 ? (
<Tooltip title="Delete">
<IconButton>
<DeleteIcon />
</IconButton>
</Tooltip>
) : (
<Tooltip title="Filter list">
<IconButton>
<FilterListIcon />
</IconButton>
</Tooltip>
)}
</Toolbar>
);
}
export default function EnhancedTable() {
const [order, setOrder] = React.useState<Order>('asc');
const [orderBy, setOrderBy] = React.useState<keyof Data>('calories');
const [selected, setSelected] = React.useState<readonly number[]>([]);
const [page, setPage] = React.useState(0);
const [dense, setDense] = React.useState(false);
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.id);
setSelected(newSelected);
return;
}
setSelected([]);
};
const handleClick = (event: React.MouseEvent<unknown>, id: number) => {
const selectedIndex = selected.indexOf(id);
let newSelected: readonly number[] = [];
if (selectedIndex === -1) {
newSelected = newSelected.concat(selected, id);
} 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 = (event: unknown, newPage: number) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};
const handleChangeDense = (event: React.ChangeEvent<HTMLInputElement>) => {
setDense(event.target.checked);
};
const isSelected = (id: number) => selected.indexOf(id) !== -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;
const visibleRows = React.useMemo(
() =>
stableSort(rows, getComparator(order, orderBy)).slice(
page * rowsPerPage,
page * rowsPerPage + rowsPerPage,
),
[order, orderBy, page, rowsPerPage],
);
return (
<Box sx={{ width: '100%' }}>
<Paper sx={{ width: '100%', mb: 2 }}>
<EnhancedTableToolbar numSelected={selected.length} />
<TableContainer>
<Table
sx={{ minWidth: 750 }}
aria-labelledby="tableTitle"
size={dense ? 'small' : 'medium'}
>
<EnhancedTableHead
numSelected={selected.length}
order={order}
orderBy={orderBy}
onSelectAllClick={handleSelectAllClick}
onRequestSort={handleRequestSort}
rowCount={rows.length}
/>
<TableBody>
{visibleRows.map((row, index) => {
const isItemSelected = isSelected(row.id);
const labelId = `enhanced-table-checkbox-${index}`;
return (
<TableRow
hover
onClick={(event) => handleClick(event, row.id)}
role="checkbox"
aria-checked={isItemSelected}
tabIndex={-1}
key={row.id}
selected={isItemSelected}
sx={{ cursor: 'pointer' }}
>
<TableCell padding="checkbox">
<Checkbox
color="primary"
checked={isItemSelected}
inputProps={{
'aria-labelledby': labelId,
}}
/>
</TableCell>
<TableCell
component="th"
id={labelId}
scope="row"
padding="none"
>
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
);
})}
{emptyRows > 0 && (
<TableRow
style={{
height: (dense ? 33 : 53) * emptyRows,
}}
>
<TableCell colSpan={6} />
</TableRow>
)}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[5, 10, 25]}
component="div"
count={rows.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</Paper>
<FormControlLabel
control={<Switch checked={dense} onChange={handleChangeDense} />}
label="Dense padding"
/>
</Box>
);
}
| 3,101 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/ReactVirtualizedTable.js | import * as React from 'react';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
import { TableVirtuoso } from 'react-virtuoso';
const sample = [
['Frozen yoghurt', 159, 6.0, 24, 4.0],
['Ice cream sandwich', 237, 9.0, 37, 4.3],
['Eclair', 262, 16.0, 24, 6.0],
['Cupcake', 305, 3.7, 67, 4.3],
['Gingerbread', 356, 16.0, 49, 3.9],
];
function createData(id, dessert, calories, fat, carbs, protein) {
return { id, dessert, calories, fat, carbs, protein };
}
const columns = [
{
width: 200,
label: 'Dessert',
dataKey: 'dessert',
},
{
width: 120,
label: 'Calories\u00A0(g)',
dataKey: 'calories',
numeric: true,
},
{
width: 120,
label: 'Fat\u00A0(g)',
dataKey: 'fat',
numeric: true,
},
{
width: 120,
label: 'Carbs\u00A0(g)',
dataKey: 'carbs',
numeric: true,
},
{
width: 120,
label: 'Protein\u00A0(g)',
dataKey: 'protein',
numeric: true,
},
];
const rows = Array.from({ length: 200 }, (_, index) => {
const randomSelection = sample[Math.floor(Math.random() * sample.length)];
return createData(index, ...randomSelection);
});
const VirtuosoTableComponents = {
Scroller: React.forwardRef((props, ref) => (
<TableContainer component={Paper} {...props} ref={ref} />
)),
Table: (props) => (
<Table {...props} sx={{ borderCollapse: 'separate', tableLayout: 'fixed' }} />
),
TableHead,
TableRow: ({ item: _item, ...props }) => <TableRow {...props} />,
TableBody: React.forwardRef((props, ref) => <TableBody {...props} ref={ref} />),
};
function fixedHeaderContent() {
return (
<TableRow>
{columns.map((column) => (
<TableCell
key={column.dataKey}
variant="head"
align={column.numeric || false ? 'right' : 'left'}
style={{ width: column.width }}
sx={{
backgroundColor: 'background.paper',
}}
>
{column.label}
</TableCell>
))}
</TableRow>
);
}
function rowContent(_index, row) {
return (
<React.Fragment>
{columns.map((column) => (
<TableCell
key={column.dataKey}
align={column.numeric || false ? 'right' : 'left'}
>
{row[column.dataKey]}
</TableCell>
))}
</React.Fragment>
);
}
export default function ReactVirtualizedTable() {
return (
<Paper style={{ height: 400, width: '100%' }}>
<TableVirtuoso
data={rows}
components={VirtuosoTableComponents}
fixedHeaderContent={fixedHeaderContent}
itemContent={rowContent}
/>
</Paper>
);
}
| 3,102 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/ReactVirtualizedTable.tsx | import * as React from 'react';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
import { TableVirtuoso, TableComponents } from 'react-virtuoso';
interface Data {
calories: number;
carbs: number;
dessert: string;
fat: number;
id: number;
protein: number;
}
interface ColumnData {
dataKey: keyof Data;
label: string;
numeric?: boolean;
width: number;
}
type Sample = [string, number, number, number, number];
const sample: readonly Sample[] = [
['Frozen yoghurt', 159, 6.0, 24, 4.0],
['Ice cream sandwich', 237, 9.0, 37, 4.3],
['Eclair', 262, 16.0, 24, 6.0],
['Cupcake', 305, 3.7, 67, 4.3],
['Gingerbread', 356, 16.0, 49, 3.9],
];
function createData(
id: number,
dessert: string,
calories: number,
fat: number,
carbs: number,
protein: number,
): Data {
return { id, dessert, calories, fat, carbs, protein };
}
const columns: ColumnData[] = [
{
width: 200,
label: 'Dessert',
dataKey: 'dessert',
},
{
width: 120,
label: 'Calories\u00A0(g)',
dataKey: 'calories',
numeric: true,
},
{
width: 120,
label: 'Fat\u00A0(g)',
dataKey: 'fat',
numeric: true,
},
{
width: 120,
label: 'Carbs\u00A0(g)',
dataKey: 'carbs',
numeric: true,
},
{
width: 120,
label: 'Protein\u00A0(g)',
dataKey: 'protein',
numeric: true,
},
];
const rows: Data[] = Array.from({ length: 200 }, (_, index) => {
const randomSelection = sample[Math.floor(Math.random() * sample.length)];
return createData(index, ...randomSelection);
});
const VirtuosoTableComponents: TableComponents<Data> = {
Scroller: React.forwardRef<HTMLDivElement>((props, ref) => (
<TableContainer component={Paper} {...props} ref={ref} />
)),
Table: (props) => (
<Table {...props} sx={{ borderCollapse: 'separate', tableLayout: 'fixed' }} />
),
TableHead,
TableRow: ({ item: _item, ...props }) => <TableRow {...props} />,
TableBody: React.forwardRef<HTMLTableSectionElement>((props, ref) => (
<TableBody {...props} ref={ref} />
)),
};
function fixedHeaderContent() {
return (
<TableRow>
{columns.map((column) => (
<TableCell
key={column.dataKey}
variant="head"
align={column.numeric || false ? 'right' : 'left'}
style={{ width: column.width }}
sx={{
backgroundColor: 'background.paper',
}}
>
{column.label}
</TableCell>
))}
</TableRow>
);
}
function rowContent(_index: number, row: Data) {
return (
<React.Fragment>
{columns.map((column) => (
<TableCell
key={column.dataKey}
align={column.numeric || false ? 'right' : 'left'}
>
{row[column.dataKey]}
</TableCell>
))}
</React.Fragment>
);
}
export default function ReactVirtualizedTable() {
return (
<Paper style={{ height: 400, width: '100%' }}>
<TableVirtuoso
data={rows}
components={VirtuosoTableComponents}
fixedHeaderContent={fixedHeaderContent}
itemContent={rowContent}
/>
</Paper>
);
}
| 3,103 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/ReactVirtualizedTable.tsx.preview | <Paper style={{ height: 400, width: '100%' }}>
<TableVirtuoso
data={rows}
components={VirtuosoTableComponents}
fixedHeaderContent={fixedHeaderContent}
itemContent={rowContent}
/>
</Paper> | 3,104 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/SpanningTable.js | import * as React from 'react';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
const TAX_RATE = 0.07;
function ccyFormat(num) {
return `${num.toFixed(2)}`;
}
function priceRow(qty, unit) {
return qty * unit;
}
function createRow(desc, qty, unit) {
const price = priceRow(qty, unit);
return { desc, qty, unit, price };
}
function subtotal(items) {
return items.map(({ price }) => price).reduce((sum, i) => sum + i, 0);
}
const rows = [
createRow('Paperclips (Box)', 100, 1.15),
createRow('Paper (Case)', 10, 45.99),
createRow('Waste Basket', 2, 17.99),
];
const invoiceSubtotal = subtotal(rows);
const invoiceTaxes = TAX_RATE * invoiceSubtotal;
const invoiceTotal = invoiceTaxes + invoiceSubtotal;
export default function SpanningTable() {
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 700 }} aria-label="spanning table">
<TableHead>
<TableRow>
<TableCell align="center" colSpan={3}>
Details
</TableCell>
<TableCell align="right">Price</TableCell>
</TableRow>
<TableRow>
<TableCell>Desc</TableCell>
<TableCell align="right">Qty.</TableCell>
<TableCell align="right">Unit</TableCell>
<TableCell align="right">Sum</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow key={row.desc}>
<TableCell>{row.desc}</TableCell>
<TableCell align="right">{row.qty}</TableCell>
<TableCell align="right">{row.unit}</TableCell>
<TableCell align="right">{ccyFormat(row.price)}</TableCell>
</TableRow>
))}
<TableRow>
<TableCell rowSpan={3} />
<TableCell colSpan={2}>Subtotal</TableCell>
<TableCell align="right">{ccyFormat(invoiceSubtotal)}</TableCell>
</TableRow>
<TableRow>
<TableCell>Tax</TableCell>
<TableCell align="right">{`${(TAX_RATE * 100).toFixed(0)} %`}</TableCell>
<TableCell align="right">{ccyFormat(invoiceTaxes)}</TableCell>
</TableRow>
<TableRow>
<TableCell colSpan={2}>Total</TableCell>
<TableCell align="right">{ccyFormat(invoiceTotal)}</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
);
}
| 3,105 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/SpanningTable.tsx | import * as React from 'react';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper';
const TAX_RATE = 0.07;
function ccyFormat(num: number) {
return `${num.toFixed(2)}`;
}
function priceRow(qty: number, unit: number) {
return qty * unit;
}
function createRow(desc: string, qty: number, unit: number) {
const price = priceRow(qty, unit);
return { desc, qty, unit, price };
}
interface Row {
desc: string;
qty: number;
unit: number;
price: number;
}
function subtotal(items: readonly Row[]) {
return items.map(({ price }) => price).reduce((sum, i) => sum + i, 0);
}
const rows = [
createRow('Paperclips (Box)', 100, 1.15),
createRow('Paper (Case)', 10, 45.99),
createRow('Waste Basket', 2, 17.99),
];
const invoiceSubtotal = subtotal(rows);
const invoiceTaxes = TAX_RATE * invoiceSubtotal;
const invoiceTotal = invoiceTaxes + invoiceSubtotal;
export default function SpanningTable() {
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 700 }} aria-label="spanning table">
<TableHead>
<TableRow>
<TableCell align="center" colSpan={3}>
Details
</TableCell>
<TableCell align="right">Price</TableCell>
</TableRow>
<TableRow>
<TableCell>Desc</TableCell>
<TableCell align="right">Qty.</TableCell>
<TableCell align="right">Unit</TableCell>
<TableCell align="right">Sum</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow key={row.desc}>
<TableCell>{row.desc}</TableCell>
<TableCell align="right">{row.qty}</TableCell>
<TableCell align="right">{row.unit}</TableCell>
<TableCell align="right">{ccyFormat(row.price)}</TableCell>
</TableRow>
))}
<TableRow>
<TableCell rowSpan={3} />
<TableCell colSpan={2}>Subtotal</TableCell>
<TableCell align="right">{ccyFormat(invoiceSubtotal)}</TableCell>
</TableRow>
<TableRow>
<TableCell>Tax</TableCell>
<TableCell align="right">{`${(TAX_RATE * 100).toFixed(0)} %`}</TableCell>
<TableCell align="right">{ccyFormat(invoiceTaxes)}</TableCell>
</TableRow>
<TableRow>
<TableCell colSpan={2}>Total</TableCell>
<TableCell align="right">{ccyFormat(invoiceTotal)}</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
);
}
| 3,106 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/StickyHeadTable.js | import * as React from 'react';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TablePagination from '@mui/material/TablePagination';
import TableRow from '@mui/material/TableRow';
const columns = [
{ id: 'name', label: 'Name', minWidth: 170 },
{ id: 'code', label: 'ISO\u00a0Code', minWidth: 100 },
{
id: 'population',
label: 'Population',
minWidth: 170,
align: 'right',
format: (value) => value.toLocaleString('en-US'),
},
{
id: 'size',
label: 'Size\u00a0(km\u00b2)',
minWidth: 170,
align: 'right',
format: (value) => value.toLocaleString('en-US'),
},
{
id: 'density',
label: 'Density',
minWidth: 170,
align: 'right',
format: (value) => value.toFixed(2),
},
];
function createData(name, code, population, size) {
const density = population / size;
return { name, code, population, size, density };
}
const rows = [
createData('India', 'IN', 1324171354, 3287263),
createData('China', 'CN', 1403500365, 9596961),
createData('Italy', 'IT', 60483973, 301340),
createData('United States', 'US', 327167434, 9833520),
createData('Canada', 'CA', 37602103, 9984670),
createData('Australia', 'AU', 25475400, 7692024),
createData('Germany', 'DE', 83019200, 357578),
createData('Ireland', 'IE', 4857000, 70273),
createData('Mexico', 'MX', 126577691, 1972550),
createData('Japan', 'JP', 126317000, 377973),
createData('France', 'FR', 67022000, 640679),
createData('United Kingdom', 'GB', 67545757, 242495),
createData('Russia', 'RU', 146793744, 17098246),
createData('Nigeria', 'NG', 200962417, 923768),
createData('Brazil', 'BR', 210147125, 8515767),
];
export default function StickyHeadTable() {
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(10);
const handleChangePage = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(+event.target.value);
setPage(0);
};
return (
<Paper sx={{ width: '100%', overflow: 'hidden' }}>
<TableContainer sx={{ maxHeight: 440 }}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{columns.map((column) => (
<TableCell
key={column.id}
align={column.align}
style={{ minWidth: column.minWidth }}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row) => {
return (
<TableRow hover role="checkbox" tabIndex={-1} key={row.code}>
{columns.map((column) => {
const value = row[column.id];
return (
<TableCell key={column.id} align={column.align}>
{column.format && typeof value === 'number'
? column.format(value)
: value}
</TableCell>
);
})}
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[10, 25, 100]}
component="div"
count={rows.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</Paper>
);
}
| 3,107 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/StickyHeadTable.tsx | import * as React from 'react';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TablePagination from '@mui/material/TablePagination';
import TableRow from '@mui/material/TableRow';
interface Column {
id: 'name' | 'code' | 'population' | 'size' | 'density';
label: string;
minWidth?: number;
align?: 'right';
format?: (value: number) => string;
}
const columns: readonly Column[] = [
{ id: 'name', label: 'Name', minWidth: 170 },
{ id: 'code', label: 'ISO\u00a0Code', minWidth: 100 },
{
id: 'population',
label: 'Population',
minWidth: 170,
align: 'right',
format: (value: number) => value.toLocaleString('en-US'),
},
{
id: 'size',
label: 'Size\u00a0(km\u00b2)',
minWidth: 170,
align: 'right',
format: (value: number) => value.toLocaleString('en-US'),
},
{
id: 'density',
label: 'Density',
minWidth: 170,
align: 'right',
format: (value: number) => value.toFixed(2),
},
];
interface Data {
name: string;
code: string;
population: number;
size: number;
density: number;
}
function createData(
name: string,
code: string,
population: number,
size: number,
): Data {
const density = population / size;
return { name, code, population, size, density };
}
const rows = [
createData('India', 'IN', 1324171354, 3287263),
createData('China', 'CN', 1403500365, 9596961),
createData('Italy', 'IT', 60483973, 301340),
createData('United States', 'US', 327167434, 9833520),
createData('Canada', 'CA', 37602103, 9984670),
createData('Australia', 'AU', 25475400, 7692024),
createData('Germany', 'DE', 83019200, 357578),
createData('Ireland', 'IE', 4857000, 70273),
createData('Mexico', 'MX', 126577691, 1972550),
createData('Japan', 'JP', 126317000, 377973),
createData('France', 'FR', 67022000, 640679),
createData('United Kingdom', 'GB', 67545757, 242495),
createData('Russia', 'RU', 146793744, 17098246),
createData('Nigeria', 'NG', 200962417, 923768),
createData('Brazil', 'BR', 210147125, 8515767),
];
export default function StickyHeadTable() {
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(10);
const handleChangePage = (event: unknown, newPage: number) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
setRowsPerPage(+event.target.value);
setPage(0);
};
return (
<Paper sx={{ width: '100%', overflow: 'hidden' }}>
<TableContainer sx={{ maxHeight: 440 }}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{columns.map((column) => (
<TableCell
key={column.id}
align={column.align}
style={{ minWidth: column.minWidth }}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row) => {
return (
<TableRow hover role="checkbox" tabIndex={-1} key={row.code}>
{columns.map((column) => {
const value = row[column.id];
return (
<TableCell key={column.id} align={column.align}>
{column.format && typeof value === 'number'
? column.format(value)
: value}
</TableCell>
);
})}
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[10, 25, 100]}
component="div"
count={rows.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</Paper>
);
}
| 3,108 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/table/table.md | ---
productId: material-ui
title: React Table component
components: Table, TableBody, TableCell, TableContainer, TableFooter, TableHead, TablePagination, TableRow, TableSortLabel
githubLabel: 'component: table'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/table/
materialDesign: https://m2.material.io/components/data-tables
---
# Table
<p class="description">Tables display sets of data. They can be fully customized.</p>
Tables display information in a way that's easy to scan, so that users can look for patterns and insights. They can be embedded in primary content, such as cards. They can include:
- A corresponding visualization
- Navigation
- Tools to query and manipulate data
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Basic table
A simple example with no frills.
{{"demo": "BasicTable.js", "bg": true}}
## Data table
The `Table` component has a close mapping to the native `<table>` elements.
This constraint makes building rich data tables challenging.
The [`DataGrid` component](/x/react-data-grid/) is designed for use-cases that are focused on handling large amounts of tabular data.
While it comes with a more rigid structure, in exchange, you gain more powerful features.
{{"demo": "DataTable.js", "bg": "inline"}}
## Dense table
A simple example of a dense table with no frills.
{{"demo": "DenseTable.js", "bg": true}}
## Sorting & selecting
This example demonstrates the use of `Checkbox` and clickable rows for selection, with a custom `Toolbar`. It uses the `TableSortLabel` component to help style column headings.
The Table has been given a fixed width to demonstrate horizontal scrolling. In order to prevent the pagination controls from scrolling, the TablePagination component is used outside of the Table. (The ['Custom Table Pagination Action' example](#custom-pagination-actions) below shows the pagination within the TableFooter.)
{{"demo": "EnhancedTable.js", "bg": true}}
## Customization
Here is an example of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedTables.js", "bg": true}}
### Custom pagination options
It's possible to customize the options shown in the "Rows per page" select using the `rowsPerPageOptions` prop.
You should either provide an array of:
- **numbers**, each number will be used for the option's label and value.
```jsx
<TablePagination rowsPerPageOptions={[10, 50]} />
```
- **objects**, the `value` and `label` keys will be used respectively for the value and label of the option (useful for language strings such as 'All').
```jsx
<TablePagination rowsPerPageOptions={[10, 50, { value: -1, label: 'All' }]} />
```
### Custom pagination actions
The `ActionsComponent` prop of the `TablePagination` component allows the implementation of custom actions.
{{"demo": "CustomPaginationActionsTable.js", "bg": true}}
## Sticky header
Here is an example of a table with scrollable rows and fixed column headers.
It leverages the `stickyHeader` prop.
(⚠️ no IE 11 support)
{{"demo": "StickyHeadTable.js", "bg": true}}
## Column grouping
You can group column headers by rendering multiple table rows inside a table head:
```jsx
<TableHead>
<TableRow />
<TableRow />
</TableHead>
```
{{"demo": "ColumnGroupingTable.js", "bg": true}}
## Collapsible table
An example of a table with expandable rows, revealing more information.
It utilizes the [`Collapse`](/material-ui/api/collapse/) component.
{{"demo": "CollapsibleTable.js", "bg": true}}
## Spanning table
A simple example with spanning rows & columns.
{{"demo": "SpanningTable.js", "bg": true}}
## Virtualized table
In the following example, we demonstrate how to use [react-virtuoso](https://github.com/petyosi/react-virtuoso) with the `Table` component.
It renders 200 rows and can easily handle more.
Virtualization helps with performance issues.
{{"demo": "ReactVirtualizedTable.js", "bg": true}}
## Accessibility
(WAI tutorial: <https://www.w3.org/WAI/tutorials/tables/>)
### Caption
A caption functions like a heading for a table. Most screen readers announce the content of captions. Captions help users to find a table and understand what it's about and decide if they want to read it.
{{"demo": "AccessibleTable.js", "bg": true}}
## Unstyled
If you would like to use an unstyled Table, you can use the primitive HTML elements and enhance the table with the TablePaginationUnstyled component.
See the demos in the [unstyled table pagination docs](/base-ui/react-table-pagination/)
| 3,109 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs1.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function AccessibleTabs1() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where selection follows focus"
selectionFollowsFocus
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,110 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs1.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function AccessibleTabs1() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where selection follows focus"
selectionFollowsFocus
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,111 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs1.tsx.preview | <Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where selection follows focus"
selectionFollowsFocus
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs> | 3,112 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs2.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function AccessibleTabs2() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where each tab needs to be selected manually"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,113 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs2.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function AccessibleTabs2() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where each tab needs to be selected manually"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,114 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/AccessibleTabs2.tsx.preview | <Tabs
onChange={handleChange}
value={value}
aria-label="Tabs where each tab needs to be selected manually"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs> | 3,115 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/BasicTabs.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function CustomTabPanel(props) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
CustomTabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired,
};
function a11yProps(index) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
}
export default function BasicTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</Box>
<CustomTabPanel value={value} index={0}>
Item One
</CustomTabPanel>
<CustomTabPanel value={value} index={1}>
Item Two
</CustomTabPanel>
<CustomTabPanel value={value} index={2}>
Item Three
</CustomTabPanel>
</Box>
);
}
| 3,116 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/BasicTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
interface TabPanelProps {
children?: React.ReactNode;
index: number;
value: number;
}
function CustomTabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index: number) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
}
export default function BasicTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</Box>
<CustomTabPanel value={value} index={0}>
Item One
</CustomTabPanel>
<CustomTabPanel value={value} index={1}>
Item Two
</CustomTabPanel>
<CustomTabPanel value={value} index={2}>
Item Three
</CustomTabPanel>
</Box>
);
}
| 3,117 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/BasicTabs.tsx.preview | <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</Box>
<CustomTabPanel value={value} index={0}>
Item One
</CustomTabPanel>
<CustomTabPanel value={value} index={1}>
Item Two
</CustomTabPanel>
<CustomTabPanel value={value} index={2}>
Item Three
</CustomTabPanel> | 3,118 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/CenteredTabs.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function CenteredTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%', bgcolor: 'background.paper' }}>
<Tabs value={value} onChange={handleChange} centered>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,119 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/CenteredTabs.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function CenteredTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%', bgcolor: 'background.paper' }}>
<Tabs value={value} onChange={handleChange} centered>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</Box>
);
}
| 3,120 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/CenteredTabs.tsx.preview | <Tabs value={value} onChange={handleChange} centered>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs> | 3,121 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ColorTabs.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ColorTabs() {
const [value, setValue] = React.useState('one');
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
value={value}
onChange={handleChange}
textColor="secondary"
indicatorColor="secondary"
aria-label="secondary tabs example"
>
<Tab value="one" label="Item One" />
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs>
</Box>
);
}
| 3,122 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ColorTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ColorTabs() {
const [value, setValue] = React.useState('one');
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
value={value}
onChange={handleChange}
textColor="secondary"
indicatorColor="secondary"
aria-label="secondary tabs example"
>
<Tab value="one" label="Item One" />
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs>
</Box>
);
}
| 3,123 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ColorTabs.tsx.preview | <Tabs
value={value}
onChange={handleChange}
textColor="secondary"
indicatorColor="secondary"
aria-label="secondary tabs example"
>
<Tab value="one" label="Item One" />
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs> | 3,124 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/CustomizedTabs.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
const AntTabs = styled(Tabs)({
borderBottom: '1px solid #e8e8e8',
'& .MuiTabs-indicator': {
backgroundColor: '#1890ff',
},
});
const AntTab = styled((props) => <Tab disableRipple {...props} />)(({ theme }) => ({
textTransform: 'none',
minWidth: 0,
[theme.breakpoints.up('sm')]: {
minWidth: 0,
},
fontWeight: theme.typography.fontWeightRegular,
marginRight: theme.spacing(1),
color: 'rgba(0, 0, 0, 0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:hover': {
color: '#40a9ff',
opacity: 1,
},
'&.Mui-selected': {
color: '#1890ff',
fontWeight: theme.typography.fontWeightMedium,
},
'&.Mui-focusVisible': {
backgroundColor: '#d1eaff',
},
}));
const StyledTabs = styled((props) => (
<Tabs
{...props}
TabIndicatorProps={{ children: <span className="MuiTabs-indicatorSpan" /> }}
/>
))({
'& .MuiTabs-indicator': {
display: 'flex',
justifyContent: 'center',
backgroundColor: 'transparent',
},
'& .MuiTabs-indicatorSpan': {
maxWidth: 40,
width: '100%',
backgroundColor: '#635ee7',
},
});
const StyledTab = styled((props) => <Tab disableRipple {...props} />)(
({ theme }) => ({
textTransform: 'none',
fontWeight: theme.typography.fontWeightRegular,
fontSize: theme.typography.pxToRem(15),
marginRight: theme.spacing(1),
color: 'rgba(255, 255, 255, 0.7)',
'&.Mui-selected': {
color: '#fff',
},
'&.Mui-focusVisible': {
backgroundColor: 'rgba(100, 95, 228, 0.32)',
},
}),
);
export default function CustomizedTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ bgcolor: '#fff' }}>
<AntTabs value={value} onChange={handleChange} aria-label="ant example">
<AntTab label="Tab 1" />
<AntTab label="Tab 2" />
<AntTab label="Tab 3" />
</AntTabs>
<Box sx={{ p: 3 }} />
</Box>
<Box sx={{ bgcolor: '#2e1534' }}>
<StyledTabs
value={value}
onChange={handleChange}
aria-label="styled tabs example"
>
<StyledTab label="Workflows" />
<StyledTab label="Datasets" />
<StyledTab label="Connections" />
</StyledTabs>
<Box sx={{ p: 3 }} />
</Box>
</Box>
);
}
| 3,125 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/CustomizedTabs.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
const AntTabs = styled(Tabs)({
borderBottom: '1px solid #e8e8e8',
'& .MuiTabs-indicator': {
backgroundColor: '#1890ff',
},
});
const AntTab = styled((props: StyledTabProps) => <Tab disableRipple {...props} />)(
({ theme }) => ({
textTransform: 'none',
minWidth: 0,
[theme.breakpoints.up('sm')]: {
minWidth: 0,
},
fontWeight: theme.typography.fontWeightRegular,
marginRight: theme.spacing(1),
color: 'rgba(0, 0, 0, 0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:hover': {
color: '#40a9ff',
opacity: 1,
},
'&.Mui-selected': {
color: '#1890ff',
fontWeight: theme.typography.fontWeightMedium,
},
'&.Mui-focusVisible': {
backgroundColor: '#d1eaff',
},
}),
);
interface StyledTabsProps {
children?: React.ReactNode;
value: number;
onChange: (event: React.SyntheticEvent, newValue: number) => void;
}
const StyledTabs = styled((props: StyledTabsProps) => (
<Tabs
{...props}
TabIndicatorProps={{ children: <span className="MuiTabs-indicatorSpan" /> }}
/>
))({
'& .MuiTabs-indicator': {
display: 'flex',
justifyContent: 'center',
backgroundColor: 'transparent',
},
'& .MuiTabs-indicatorSpan': {
maxWidth: 40,
width: '100%',
backgroundColor: '#635ee7',
},
});
interface StyledTabProps {
label: string;
}
const StyledTab = styled((props: StyledTabProps) => (
<Tab disableRipple {...props} />
))(({ theme }) => ({
textTransform: 'none',
fontWeight: theme.typography.fontWeightRegular,
fontSize: theme.typography.pxToRem(15),
marginRight: theme.spacing(1),
color: 'rgba(255, 255, 255, 0.7)',
'&.Mui-selected': {
color: '#fff',
},
'&.Mui-focusVisible': {
backgroundColor: 'rgba(100, 95, 228, 0.32)',
},
}));
export default function CustomizedTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ bgcolor: '#fff' }}>
<AntTabs value={value} onChange={handleChange} aria-label="ant example">
<AntTab label="Tab 1" />
<AntTab label="Tab 2" />
<AntTab label="Tab 3" />
</AntTabs>
<Box sx={{ p: 3 }} />
</Box>
<Box sx={{ bgcolor: '#2e1534' }}>
<StyledTabs
value={value}
onChange={handleChange}
aria-label="styled tabs example"
>
<StyledTab label="Workflows" />
<StyledTab label="Datasets" />
<StyledTab label="Connections" />
</StyledTabs>
<Box sx={{ p: 3 }} />
</Box>
</Box>
);
}
| 3,126 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/DisabledTabs.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function DisabledTabs() {
const [value, setValue] = React.useState(2);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="disabled tabs example">
<Tab label="Active" />
<Tab label="Disabled" disabled />
<Tab label="Active" />
</Tabs>
);
}
| 3,127 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/DisabledTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function DisabledTabs() {
const [value, setValue] = React.useState(2);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="disabled tabs example">
<Tab label="Active" />
<Tab label="Disabled" disabled />
<Tab label="Active" />
</Tabs>
);
}
| 3,128 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/DisabledTabs.tsx.preview | <Tabs value={value} onChange={handleChange} aria-label="disabled tabs example">
<Tab label="Active" />
<Tab label="Disabled" disabled />
<Tab label="Active" />
</Tabs> | 3,129 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/FullWidthTabs.js | import * as React from 'react';
import PropTypes from 'prop-types';
import SwipeableViews from 'react-swipeable-views';
import { useTheme } from '@mui/material/styles';
import AppBar from '@mui/material/AppBar';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`full-width-tabpanel-${index}`}
aria-labelledby={`full-width-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired,
};
function a11yProps(index) {
return {
id: `full-width-tab-${index}`,
'aria-controls': `full-width-tabpanel-${index}`,
};
}
export default function FullWidthTabs() {
const theme = useTheme();
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
const handleChangeIndex = (index) => {
setValue(index);
};
return (
<Box sx={{ bgcolor: 'background.paper', width: 500 }}>
<AppBar position="static">
<Tabs
value={value}
onChange={handleChange}
indicatorColor="secondary"
textColor="inherit"
variant="fullWidth"
aria-label="full width tabs example"
>
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</AppBar>
<SwipeableViews
axis={theme.direction === 'rtl' ? 'x-reverse' : 'x'}
index={value}
onChangeIndex={handleChangeIndex}
>
<TabPanel value={value} index={0} dir={theme.direction}>
Item One
</TabPanel>
<TabPanel value={value} index={1} dir={theme.direction}>
Item Two
</TabPanel>
<TabPanel value={value} index={2} dir={theme.direction}>
Item Three
</TabPanel>
</SwipeableViews>
</Box>
);
}
| 3,130 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/FullWidthTabs.tsx | import * as React from 'react';
import SwipeableViews from 'react-swipeable-views';
import { useTheme } from '@mui/material/styles';
import AppBar from '@mui/material/AppBar';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
interface TabPanelProps {
children?: React.ReactNode;
dir?: string;
index: number;
value: number;
}
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`full-width-tabpanel-${index}`}
aria-labelledby={`full-width-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index: number) {
return {
id: `full-width-tab-${index}`,
'aria-controls': `full-width-tabpanel-${index}`,
};
}
export default function FullWidthTabs() {
const theme = useTheme();
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
const handleChangeIndex = (index: number) => {
setValue(index);
};
return (
<Box sx={{ bgcolor: 'background.paper', width: 500 }}>
<AppBar position="static">
<Tabs
value={value}
onChange={handleChange}
indicatorColor="secondary"
textColor="inherit"
variant="fullWidth"
aria-label="full width tabs example"
>
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
</AppBar>
<SwipeableViews
axis={theme.direction === 'rtl' ? 'x-reverse' : 'x'}
index={value}
onChangeIndex={handleChangeIndex}
>
<TabPanel value={value} index={0} dir={theme.direction}>
Item One
</TabPanel>
<TabPanel value={value} index={1} dir={theme.direction}>
Item Two
</TabPanel>
<TabPanel value={value} index={2} dir={theme.direction}>
Item Three
</TabPanel>
</SwipeableViews>
</Box>
);
}
| 3,131 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconLabelTabs.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/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 IconLabelTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="icon label tabs example">
<Tab icon={<PhoneIcon />} label="RECENTS" />
<Tab icon={<FavoriteIcon />} label="FAVORITES" />
<Tab icon={<PersonPinIcon />} label="NEARBY" />
</Tabs>
);
}
| 3,132 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconLabelTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/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 IconLabelTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="icon label tabs example">
<Tab icon={<PhoneIcon />} label="RECENTS" />
<Tab icon={<FavoriteIcon />} label="FAVORITES" />
<Tab icon={<PersonPinIcon />} label="NEARBY" />
</Tabs>
);
}
| 3,133 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconLabelTabs.tsx.preview | <Tabs value={value} onChange={handleChange} aria-label="icon label tabs example">
<Tab icon={<PhoneIcon />} label="RECENTS" />
<Tab icon={<FavoriteIcon />} label="FAVORITES" />
<Tab icon={<PersonPinIcon />} label="NEARBY" />
</Tabs> | 3,134 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconPositionTabs.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
import PhoneMissedIcon from '@mui/icons-material/PhoneMissed';
export default function IconPositionTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs
value={value}
onChange={handleChange}
aria-label="icon position tabs example"
>
<Tab icon={<PhoneIcon />} label="top" />
<Tab icon={<PhoneMissedIcon />} iconPosition="start" label="start" />
<Tab icon={<FavoriteIcon />} iconPosition="end" label="end" />
<Tab icon={<PersonPinIcon />} iconPosition="bottom" label="bottom" />
</Tabs>
);
}
| 3,135 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconPositionTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import PhoneIcon from '@mui/icons-material/Phone';
import FavoriteIcon from '@mui/icons-material/Favorite';
import PersonPinIcon from '@mui/icons-material/PersonPin';
import PhoneMissedIcon from '@mui/icons-material/PhoneMissed';
export default function IconPositionTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Tabs
value={value}
onChange={handleChange}
aria-label="icon position tabs example"
>
<Tab icon={<PhoneIcon />} label="top" />
<Tab icon={<PhoneMissedIcon />} iconPosition="start" label="start" />
<Tab icon={<FavoriteIcon />} iconPosition="end" label="end" />
<Tab icon={<PersonPinIcon />} iconPosition="bottom" label="bottom" />
</Tabs>
);
}
| 3,136 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconPositionTabs.tsx.preview | <Tabs
value={value}
onChange={handleChange}
aria-label="icon position tabs example"
>
<Tab icon={<PhoneIcon />} label="top" />
<Tab icon={<PhoneMissedIcon />} iconPosition="start" label="start" />
<Tab icon={<FavoriteIcon />} iconPosition="end" label="end" />
<Tab icon={<PersonPinIcon />} iconPosition="bottom" label="bottom" />
</Tabs> | 3,137 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconTabs.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/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 IconTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="icon tabs example">
<Tab icon={<PhoneIcon />} aria-label="phone" />
<Tab icon={<FavoriteIcon />} aria-label="favorite" />
<Tab icon={<PersonPinIcon />} aria-label="person" />
</Tabs>
);
}
| 3,138 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/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 IconTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Tabs value={value} onChange={handleChange} aria-label="icon tabs example">
<Tab icon={<PhoneIcon />} aria-label="phone" />
<Tab icon={<FavoriteIcon />} aria-label="favorite" />
<Tab icon={<PersonPinIcon />} aria-label="person" />
</Tabs>
);
}
| 3,139 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/IconTabs.tsx.preview | <Tabs value={value} onChange={handleChange} aria-label="icon tabs example">
<Tab icon={<PhoneIcon />} aria-label="phone" />
<Tab icon={<FavoriteIcon />} aria-label="favorite" />
<Tab icon={<PersonPinIcon />} aria-label="person" />
</Tabs> | 3,140 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/LabTabs.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Tab from '@mui/material/Tab';
import TabContext from '@mui/lab/TabContext';
import TabList from '@mui/lab/TabList';
import TabPanel from '@mui/lab/TabPanel';
export default function LabTabs() {
const [value, setValue] = React.useState('1');
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%', typography: 'body1' }}>
<TabContext value={value}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<TabList onChange={handleChange} aria-label="lab API tabs example">
<Tab label="Item One" value="1" />
<Tab label="Item Two" value="2" />
<Tab label="Item Three" value="3" />
</TabList>
</Box>
<TabPanel value="1">Item One</TabPanel>
<TabPanel value="2">Item Two</TabPanel>
<TabPanel value="3">Item Three</TabPanel>
</TabContext>
</Box>
);
}
| 3,141 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/LabTabs.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Tab from '@mui/material/Tab';
import TabContext from '@mui/lab/TabContext';
import TabList from '@mui/lab/TabList';
import TabPanel from '@mui/lab/TabPanel';
export default function LabTabs() {
const [value, setValue] = React.useState('1');
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%', typography: 'body1' }}>
<TabContext value={value}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<TabList onChange={handleChange} aria-label="lab API tabs example">
<Tab label="Item One" value="1" />
<Tab label="Item Two" value="2" />
<Tab label="Item Three" value="3" />
</TabList>
</Box>
<TabPanel value="1">Item One</TabPanel>
<TabPanel value="2">Item Two</TabPanel>
<TabPanel value="3">Item Three</TabPanel>
</TabContext>
</Box>
);
}
| 3,142 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/LabTabs.tsx.preview | <TabContext value={value}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<TabList onChange={handleChange} aria-label="lab API tabs example">
<Tab label="Item One" value="1" />
<Tab label="Item Two" value="2" />
<Tab label="Item Three" value="3" />
</TabList>
</Box>
<TabPanel value="1">Item One</TabPanel>
<TabPanel value="2">Item Two</TabPanel>
<TabPanel value="3">Item Three</TabPanel>
</TabContext> | 3,143 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/NavTabs.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
function samePageLinkNavigation(event) {
if (
event.defaultPrevented ||
event.button !== 0 || // ignore everything but left-click
event.metaKey ||
event.ctrlKey ||
event.altKey ||
event.shiftKey
) {
return false;
}
return true;
}
function LinkTab(props) {
return (
<Tab
component="a"
onClick={(event) => {
// Routing libraries handle this, you can remove the onClick handle when using them.
if (samePageLinkNavigation(event)) {
event.preventDefault();
}
}}
{...props}
/>
);
}
export default function NavTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
// event.type can be equal to focus with selectionFollowsFocus.
if (
event.type !== 'click' ||
(event.type === 'click' && samePageLinkNavigation(event))
) {
setValue(newValue);
}
};
return (
<Box sx={{ width: '100%' }}>
<Tabs value={value} onChange={handleChange} aria-label="nav tabs example">
<LinkTab label="Page One" href="/drafts" />
<LinkTab label="Page Two" href="/trash" />
<LinkTab label="Page Three" href="/spam" />
</Tabs>
</Box>
);
}
| 3,144 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/NavTabs.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
function samePageLinkNavigation(
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
) {
if (
event.defaultPrevented ||
event.button !== 0 || // ignore everything but left-click
event.metaKey ||
event.ctrlKey ||
event.altKey ||
event.shiftKey
) {
return false;
}
return true;
}
interface LinkTabProps {
label?: string;
href?: string;
}
function LinkTab(props: LinkTabProps) {
return (
<Tab
component="a"
onClick={(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
// Routing libraries handle this, you can remove the onClick handle when using them.
if (samePageLinkNavigation(event)) {
event.preventDefault();
}
}}
{...props}
/>
);
}
export default function NavTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
// event.type can be equal to focus with selectionFollowsFocus.
if (
event.type !== 'click' ||
(event.type === 'click' &&
samePageLinkNavigation(
event as React.MouseEvent<HTMLAnchorElement, MouseEvent>,
))
) {
setValue(newValue);
}
};
return (
<Box sx={{ width: '100%' }}>
<Tabs value={value} onChange={handleChange} aria-label="nav tabs example">
<LinkTab label="Page One" href="/drafts" />
<LinkTab label="Page Two" href="/trash" />
<LinkTab label="Page Three" href="/spam" />
</Tabs>
</Box>
);
}
| 3,145 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/NavTabs.tsx.preview | <Tabs value={value} onChange={handleChange} aria-label="nav tabs example">
<LinkTab label="Page One" href="/drafts" />
<LinkTab label="Page Two" href="/trash" />
<LinkTab label="Page Three" href="/spam" />
</Tabs> | 3,146 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonAuto.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonAuto() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,147 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonAuto.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonAuto() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,148 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonAuto.tsx.preview | <Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs> | 3,149 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonForce.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonForce() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons
allowScrollButtonsMobile
aria-label="scrollable force tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,150 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonForce.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonForce() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons
allowScrollButtonsMobile
aria-label="scrollable force tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,151 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonForce.tsx.preview | <Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons
allowScrollButtonsMobile
aria-label="scrollable force tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs> | 3,152 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonPrevent.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonPrevent() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons={false}
aria-label="scrollable prevent tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,153 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonPrevent.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function ScrollableTabsButtonPrevent() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box sx={{ maxWidth: { xs: 320, sm: 480 }, bgcolor: 'background.paper' }}>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons={false}
aria-label="scrollable prevent tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,154 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonPrevent.tsx.preview | <Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons={false}
aria-label="scrollable prevent tabs example"
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs> | 3,155 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonVisible.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs, { tabsClasses } from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function ScrollableTabsButtonVisible() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box
sx={{
flexGrow: 1,
maxWidth: { xs: 320, sm: 480 },
bgcolor: 'background.paper',
}}
>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons
aria-label="visible arrows tabs example"
sx={{
[`& .${tabsClasses.scrollButtons}`]: {
'&.Mui-disabled': { opacity: 0.3 },
},
}}
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,156 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/ScrollableTabsButtonVisible.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Tabs, { tabsClasses } from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
export default function ScrollableTabsButtonVisible() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box
sx={{
flexGrow: 1,
maxWidth: { xs: 320, sm: 480 },
bgcolor: 'background.paper',
}}
>
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons
aria-label="visible arrows tabs example"
sx={{
[`& .${tabsClasses.scrollButtons}`]: {
'&.Mui-disabled': { opacity: 0.3 },
},
}}
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
<Tab label="Item Four" />
<Tab label="Item Five" />
<Tab label="Item Six" />
<Tab label="Item Seven" />
</Tabs>
</Box>
);
}
| 3,157 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/TabsWrappedLabel.js | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function TabsWrappedLabel() {
const [value, setValue] = React.useState('one');
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
value={value}
onChange={handleChange}
aria-label="wrapped label tabs example"
>
<Tab
value="one"
label="New Arrivals in the Longest Text of Nonfiction that should appear in the next line"
wrapped
/>
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs>
</Box>
);
}
| 3,158 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/TabsWrappedLabel.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
export default function TabsWrappedLabel() {
const [value, setValue] = React.useState('one');
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setValue(newValue);
};
return (
<Box sx={{ width: '100%' }}>
<Tabs
value={value}
onChange={handleChange}
aria-label="wrapped label tabs example"
>
<Tab
value="one"
label="New Arrivals in the Longest Text of Nonfiction that should appear in the next line"
wrapped
/>
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs>
</Box>
);
}
| 3,159 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/TabsWrappedLabel.tsx.preview | <Tabs
value={value}
onChange={handleChange}
aria-label="wrapped label tabs example"
>
<Tab
value="one"
label="New Arrivals in the Longest Text of Nonfiction that should appear in the next line"
wrapped
/>
<Tab value="two" label="Item Two" />
<Tab value="three" label="Item Three" />
</Tabs> | 3,160 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/VerticalTabs.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`vertical-tabpanel-${index}`}
aria-labelledby={`vertical-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired,
};
function a11yProps(index) {
return {
id: `vertical-tab-${index}`,
'aria-controls': `vertical-tabpanel-${index}`,
};
}
export default function VerticalTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box
sx={{ flexGrow: 1, bgcolor: 'background.paper', display: 'flex', height: 224 }}
>
<Tabs
orientation="vertical"
variant="scrollable"
value={value}
onChange={handleChange}
aria-label="Vertical tabs example"
sx={{ borderRight: 1, borderColor: 'divider' }}
>
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
<Tab label="Item Four" {...a11yProps(3)} />
<Tab label="Item Five" {...a11yProps(4)} />
<Tab label="Item Six" {...a11yProps(5)} />
<Tab label="Item Seven" {...a11yProps(6)} />
</Tabs>
<TabPanel value={value} index={0}>
Item One
</TabPanel>
<TabPanel value={value} index={1}>
Item Two
</TabPanel>
<TabPanel value={value} index={2}>
Item Three
</TabPanel>
<TabPanel value={value} index={3}>
Item Four
</TabPanel>
<TabPanel value={value} index={4}>
Item Five
</TabPanel>
<TabPanel value={value} index={5}>
Item Six
</TabPanel>
<TabPanel value={value} index={6}>
Item Seven
</TabPanel>
</Box>
);
}
| 3,161 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/VerticalTabs.tsx | import * as React from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
interface TabPanelProps {
children?: React.ReactNode;
index: number;
value: number;
}
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`vertical-tabpanel-${index}`}
aria-labelledby={`vertical-tab-${index}`}
{...other}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index: number) {
return {
id: `vertical-tab-${index}`,
'aria-controls': `vertical-tabpanel-${index}`,
};
}
export default function VerticalTabs() {
const [value, setValue] = React.useState(0);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
return (
<Box
sx={{ flexGrow: 1, bgcolor: 'background.paper', display: 'flex', height: 224 }}
>
<Tabs
orientation="vertical"
variant="scrollable"
value={value}
onChange={handleChange}
aria-label="Vertical tabs example"
sx={{ borderRight: 1, borderColor: 'divider' }}
>
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
<Tab label="Item Four" {...a11yProps(3)} />
<Tab label="Item Five" {...a11yProps(4)} />
<Tab label="Item Six" {...a11yProps(5)} />
<Tab label="Item Seven" {...a11yProps(6)} />
</Tabs>
<TabPanel value={value} index={0}>
Item One
</TabPanel>
<TabPanel value={value} index={1}>
Item Two
</TabPanel>
<TabPanel value={value} index={2}>
Item Three
</TabPanel>
<TabPanel value={value} index={3}>
Item Four
</TabPanel>
<TabPanel value={value} index={4}>
Item Five
</TabPanel>
<TabPanel value={value} index={5}>
Item Six
</TabPanel>
<TabPanel value={value} index={6}>
Item Seven
</TabPanel>
</Box>
);
}
| 3,162 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/tabs/tabs.md | ---
productId: material-ui
title: React Tabs component
components: Tabs, Tab, TabScrollButton, TabContext, TabList, TabPanel
githubLabel: 'component: tabs'
materialDesign: https://m2.material.io/components/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>
Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy.
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Basic tabs
A basic example with tab panels.
{{"demo": "BasicTabs.js"}}
## Experimental API
`@mui/lab` offers utility components that inject props to implement accessible tabs
following [WAI-ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/).
{{"demo": "LabTabs.js"}}
## Wrapped labels
Long labels will automatically wrap on tabs.
If the label is too long for the tab, it will overflow, and the text will not be visible.
{{"demo": "TabsWrappedLabel.js"}}
## Colored tab
{{"demo": "ColorTabs.js"}}
## Disabled tab
A tab can be disabled by setting the `disabled` prop.
{{"demo": "DisabledTabs.js"}}
## Fixed tabs
Fixed tabs should be used with a limited number of tabs, and when a consistent placement will aid muscle memory.
### Full width
The `variant="fullWidth"` prop should be used for smaller views.
This demo also uses [react-swipeable-views](https://github.com/oliviertassinari/react-swipeable-views) to animate the Tab transition, and allowing tabs to be swiped on touch devices.
{{"demo": "FullWidthTabs.js", "bg": true}}
### Centered
The `centered` prop should be used for larger views.
{{"demo": "CenteredTabs.js", "bg": true}}
## Scrollable tabs
### Automatic scroll buttons
By default, left and right scroll buttons are automatically presented on desktop and hidden on mobile. (based on viewport width)
{{"demo": "ScrollableTabsButtonAuto.js", "bg": true}}
### Forced scroll buttons
Left and right scroll buttons be presented (reserve space) regardless of the viewport width with `scrollButtons={true}` `allowScrollButtonsMobile`:
{{"demo": "ScrollableTabsButtonForce.js", "bg": true}}
If you want to make sure the buttons are always visible, you should customize the opacity.
```css
.MuiTabs-scrollButtons.Mui-disabled {
opacity: 0.3;
}
```
{{"demo": "ScrollableTabsButtonVisible.js", "bg": true}}
### Prevent scroll buttons
Left and right scroll buttons are never be presented with `scrollButtons={false}`.
All scrolling must be initiated through user agent scrolling mechanisms (e.g. left/right swipe, shift mouse wheel, etc.)
{{"demo": "ScrollableTabsButtonPrevent.js", "bg": true}}
## Customization
Here is an example of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedTabs.js"}}
🎨 If you are looking for inspiration, you can check [MUI Treasury's customization examples](https://mui-treasury.com/styles/tabs/).
## Vertical tabs
To make vertical tabs instead of default horizontal ones, there is `orientation="vertical"`:
{{"demo": "VerticalTabs.js", "bg": true}}
Note that you can restore the scrollbar with `visibleScrollbar`.
## Nav tabs
By default, tabs use a `button` element, but you can provide your custom tag or component. Here's an example of implementing tabbed navigation:
{{"demo": "NavTabs.js"}}
### Third-party routing library
One frequent use case is to perform navigation on the client only, without an HTTP round-trip to the server.
The `Tab` component provides the `component` prop to handle this use case.
Here is a [more detailed guide](/material-ui/guides/routing/#tabs).
## Icon tabs
Tab labels may be either all icons or all text.
{{"demo": "IconTabs.js"}}
{{"demo": "IconLabelTabs.js"}}
## Icon position
By default, the icon is positioned at the `top` of a tab. Other supported positions are `start`, `end`, `bottom`.
{{"demo": "IconPositionTabs.js"}}
## Accessibility
(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/tabs/)
The following steps are needed in order to provide necessary information for assistive technologies:
1. Label `Tabs` via `aria-label` or `aria-labelledby`.
2. `Tab`s need to be connected to their
corresponding `[role="tabpanel"]` by setting the correct `id`, `aria-controls` and `aria-labelledby`.
An example for the current implementation can be found in the demos on this page. We've also published [an experimental API](#experimental-api) in `@mui/lab` that does not require
extra work.
### Keyboard navigation
The components implement keyboard navigation using the "manual activation" behavior.
If you want to switch to the "selection automatically follows focus" behavior you have to pass `selectionFollowsFocus` to the `Tabs` component.
The WAI-ARIA authoring practices have a detailed guide on [how to decide when to make selection automatically follow focus](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#x6-4-deciding-when-to-make-selection-automatically-follow-focus).
#### Demo
The following two demos only differ in their keyboard navigation behavior.
Focus a tab and navigate with arrow keys to notice the difference, e.g. <kbd class="key">Arrow Left</kbd>.
```jsx
/* Tabs where selection follows focus */
<Tabs selectionFollowsFocus />
```
{{"demo": "AccessibleTabs1.js", "defaultCodeOpen": false}}
```jsx
/* Tabs where each tab needs to be selected manually */
<Tabs />
```
{{"demo": "AccessibleTabs2.js", "defaultCodeOpen": false}}
| 3,163 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/BasicTextFields.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function BasicTextFields() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<TextField id="outlined-basic" label="Outlined" variant="outlined" />
<TextField id="filled-basic" label="Filled" variant="filled" />
<TextField id="standard-basic" label="Standard" variant="standard" />
</Box>
);
}
| 3,164 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/BasicTextFields.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function BasicTextFields() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<TextField id="outlined-basic" label="Outlined" variant="outlined" />
<TextField id="filled-basic" label="Filled" variant="filled" />
<TextField id="standard-basic" label="Standard" variant="standard" />
</Box>
);
}
| 3,165 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/BasicTextFields.tsx.preview | <TextField id="outlined-basic" label="Outlined" variant="outlined" />
<TextField id="filled-basic" label="Filled" variant="filled" />
<TextField id="standard-basic" label="Standard" variant="standard" /> | 3,166 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ColorTextFields.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function ColorTextFields() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<TextField label="Outlined secondary" color="secondary" focused />
<TextField label="Filled success" variant="filled" color="success" focused />
<TextField
label="Standard warning"
variant="standard"
color="warning"
focused
/>
</Box>
);
}
| 3,167 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ColorTextFields.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function ColorTextFields() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<TextField label="Outlined secondary" color="secondary" focused />
<TextField label="Filled success" variant="filled" color="success" focused />
<TextField
label="Standard warning"
variant="standard"
color="warning"
focused
/>
</Box>
);
}
| 3,168 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ColorTextFields.tsx.preview | <TextField label="Outlined secondary" color="secondary" focused />
<TextField label="Filled success" variant="filled" color="success" focused />
<TextField
label="Standard warning"
variant="standard"
color="warning"
focused
/> | 3,169 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ComposedTextField.js | import * as React from 'react';
import Box from '@mui/material/Box';
import FilledInput from '@mui/material/FilledInput';
import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import OutlinedInput from '@mui/material/OutlinedInput';
export default function ComposedTextField() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1 },
}}
noValidate
autoComplete="off"
>
<FormControl variant="standard">
<InputLabel htmlFor="component-simple">Name</InputLabel>
<Input id="component-simple" defaultValue="Composed TextField" />
</FormControl>
<FormControl variant="standard">
<InputLabel htmlFor="component-helper">Name</InputLabel>
<Input
id="component-helper"
defaultValue="Composed TextField"
aria-describedby="component-helper-text"
/>
<FormHelperText id="component-helper-text">
Some important helper text
</FormHelperText>
</FormControl>
<FormControl disabled variant="standard">
<InputLabel htmlFor="component-disabled">Name</InputLabel>
<Input id="component-disabled" defaultValue="Composed TextField" />
<FormHelperText>Disabled</FormHelperText>
</FormControl>
<FormControl error variant="standard">
<InputLabel htmlFor="component-error">Name</InputLabel>
<Input
id="component-error"
defaultValue="Composed TextField"
aria-describedby="component-error-text"
/>
<FormHelperText id="component-error-text">Error</FormHelperText>
</FormControl>
<FormControl>
<InputLabel htmlFor="component-outlined">Name</InputLabel>
<OutlinedInput
id="component-outlined"
defaultValue="Composed TextField"
label="Name"
/>
</FormControl>
<FormControl variant="filled">
<InputLabel htmlFor="component-filled">Name</InputLabel>
<FilledInput id="component-filled" defaultValue="Composed TextField" />
</FormControl>
</Box>
);
}
| 3,170 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ComposedTextField.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import FilledInput from '@mui/material/FilledInput';
import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import OutlinedInput from '@mui/material/OutlinedInput';
export default function ComposedTextField() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1 },
}}
noValidate
autoComplete="off"
>
<FormControl variant="standard">
<InputLabel htmlFor="component-simple">Name</InputLabel>
<Input id="component-simple" defaultValue="Composed TextField" />
</FormControl>
<FormControl variant="standard">
<InputLabel htmlFor="component-helper">Name</InputLabel>
<Input
id="component-helper"
defaultValue="Composed TextField"
aria-describedby="component-helper-text"
/>
<FormHelperText id="component-helper-text">
Some important helper text
</FormHelperText>
</FormControl>
<FormControl disabled variant="standard">
<InputLabel htmlFor="component-disabled">Name</InputLabel>
<Input id="component-disabled" defaultValue="Composed TextField" />
<FormHelperText>Disabled</FormHelperText>
</FormControl>
<FormControl error variant="standard">
<InputLabel htmlFor="component-error">Name</InputLabel>
<Input
id="component-error"
defaultValue="Composed TextField"
aria-describedby="component-error-text"
/>
<FormHelperText id="component-error-text">Error</FormHelperText>
</FormControl>
<FormControl>
<InputLabel htmlFor="component-outlined">Name</InputLabel>
<OutlinedInput
id="component-outlined"
defaultValue="Composed TextField"
label="Name"
/>
</FormControl>
<FormControl variant="filled">
<InputLabel htmlFor="component-filled">Name</InputLabel>
<FilledInput id="component-filled" defaultValue="Composed TextField" />
</FormControl>
</Box>
);
}
| 3,171 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputBase.js | import * as React from 'react';
import Paper from '@mui/material/Paper';
import InputBase from '@mui/material/InputBase';
import Divider from '@mui/material/Divider';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import SearchIcon from '@mui/icons-material/Search';
import DirectionsIcon from '@mui/icons-material/Directions';
export default function CustomizedInputBase() {
return (
<Paper
component="form"
sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}
>
<IconButton sx={{ p: '10px' }} aria-label="menu">
<MenuIcon />
</IconButton>
<InputBase
sx={{ ml: 1, flex: 1 }}
placeholder="Search Google Maps"
inputProps={{ 'aria-label': 'search google maps' }}
/>
<IconButton type="button" sx={{ p: '10px' }} aria-label="search">
<SearchIcon />
</IconButton>
<Divider sx={{ height: 28, m: 0.5 }} orientation="vertical" />
<IconButton color="primary" sx={{ p: '10px' }} aria-label="directions">
<DirectionsIcon />
</IconButton>
</Paper>
);
}
| 3,172 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputBase.tsx | import * as React from 'react';
import Paper from '@mui/material/Paper';
import InputBase from '@mui/material/InputBase';
import Divider from '@mui/material/Divider';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import SearchIcon from '@mui/icons-material/Search';
import DirectionsIcon from '@mui/icons-material/Directions';
export default function CustomizedInputBase() {
return (
<Paper
component="form"
sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}
>
<IconButton sx={{ p: '10px' }} aria-label="menu">
<MenuIcon />
</IconButton>
<InputBase
sx={{ ml: 1, flex: 1 }}
placeholder="Search Google Maps"
inputProps={{ 'aria-label': 'search google maps' }}
/>
<IconButton type="button" sx={{ p: '10px' }} aria-label="search">
<SearchIcon />
</IconButton>
<Divider sx={{ height: 28, m: 0.5 }} orientation="vertical" />
<IconButton color="primary" sx={{ p: '10px' }} aria-label="directions">
<DirectionsIcon />
</IconButton>
</Paper>
);
}
| 3,173 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputsStyleOverrides.js | import * as React from 'react';
import TextField from '@mui/material/TextField';
import { outlinedInputClasses } from '@mui/material/OutlinedInput';
import Box from '@mui/material/Box';
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
const customTheme = (outerTheme) =>
createTheme({
palette: {
mode: outerTheme.palette.mode,
},
components: {
MuiTextField: {
styleOverrides: {
root: {
'--TextField-brandBorderColor': '#E0E3E7',
'--TextField-brandBorderHoverColor': '#B2BAC2',
'--TextField-brandBorderFocusedColor': '#6F7E8C',
'& label.Mui-focused': {
color: 'var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: {
borderColor: 'var(--TextField-brandBorderColor)',
},
root: {
[`&:hover .${outlinedInputClasses.notchedOutline}`]: {
borderColor: 'var(--TextField-brandBorderHoverColor)',
},
[`&.Mui-focused .${outlinedInputClasses.notchedOutline}`]: {
borderColor: 'var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiFilledInput: {
styleOverrides: {
root: {
'&:before, &:after': {
borderBottom: '2px solid var(--TextField-brandBorderColor)',
},
'&:hover:not(.Mui-disabled, .Mui-error):before': {
borderBottom: '2px solid var(--TextField-brandBorderHoverColor)',
},
'&.Mui-focused:after': {
borderBottom: '2px solid var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiInput: {
styleOverrides: {
root: {
'&:before': {
borderBottom: '2px solid var(--TextField-brandBorderColor)',
},
'&:hover:not(.Mui-disabled, .Mui-error):before': {
borderBottom: '2px solid var(--TextField-brandBorderHoverColor)',
},
'&.Mui-focused:after': {
borderBottom: '2px solid var(--TextField-brandBorderFocusedColor)',
},
},
},
},
},
});
export default function CustomizedInputsStyleOverrides() {
const outerTheme = useTheme();
return (
<Box
sx={{
display: 'grid',
gridTemplateColumns: { sm: '1fr 1fr 1fr' },
gap: 2,
}}
>
<ThemeProvider theme={customTheme(outerTheme)}>
<TextField label="Outlined" />
<TextField label="Filled" variant="filled" />
<TextField label="Standard" variant="standard" />
</ThemeProvider>
</Box>
);
}
| 3,174 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputsStyleOverrides.tsx | import * as React from 'react';
import TextField from '@mui/material/TextField';
import { outlinedInputClasses } from '@mui/material/OutlinedInput';
import Box from '@mui/material/Box';
import { createTheme, ThemeProvider, Theme, useTheme } from '@mui/material/styles';
const customTheme = (outerTheme: Theme) =>
createTheme({
palette: {
mode: outerTheme.palette.mode,
},
components: {
MuiTextField: {
styleOverrides: {
root: {
'--TextField-brandBorderColor': '#E0E3E7',
'--TextField-brandBorderHoverColor': '#B2BAC2',
'--TextField-brandBorderFocusedColor': '#6F7E8C',
'& label.Mui-focused': {
color: 'var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: {
borderColor: 'var(--TextField-brandBorderColor)',
},
root: {
[`&:hover .${outlinedInputClasses.notchedOutline}`]: {
borderColor: 'var(--TextField-brandBorderHoverColor)',
},
[`&.Mui-focused .${outlinedInputClasses.notchedOutline}`]: {
borderColor: 'var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiFilledInput: {
styleOverrides: {
root: {
'&:before, &:after': {
borderBottom: '2px solid var(--TextField-brandBorderColor)',
},
'&:hover:not(.Mui-disabled, .Mui-error):before': {
borderBottom: '2px solid var(--TextField-brandBorderHoverColor)',
},
'&.Mui-focused:after': {
borderBottom: '2px solid var(--TextField-brandBorderFocusedColor)',
},
},
},
},
MuiInput: {
styleOverrides: {
root: {
'&:before': {
borderBottom: '2px solid var(--TextField-brandBorderColor)',
},
'&:hover:not(.Mui-disabled, .Mui-error):before': {
borderBottom: '2px solid var(--TextField-brandBorderHoverColor)',
},
'&.Mui-focused:after': {
borderBottom: '2px solid var(--TextField-brandBorderFocusedColor)',
},
},
},
},
},
});
export default function CustomizedInputsStyleOverrides() {
const outerTheme = useTheme();
return (
<Box
sx={{
display: 'grid',
gridTemplateColumns: { sm: '1fr 1fr 1fr' },
gap: 2,
}}
>
<ThemeProvider theme={customTheme(outerTheme)}>
<TextField label="Outlined" />
<TextField label="Filled" variant="filled" />
<TextField label="Standard" variant="standard" />
</ThemeProvider>
</Box>
);
}
| 3,175 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputsStyleOverrides.tsx.preview | <ThemeProvider theme={customTheme(outerTheme)}>
<TextField label="Outlined" />
<TextField label="Filled" variant="filled" />
<TextField label="Standard" variant="standard" />
</ThemeProvider> | 3,176 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputsStyled.js | import * as React from 'react';
import { alpha, styled } from '@mui/material/styles';
import InputBase from '@mui/material/InputBase';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
const CssTextField = styled(TextField)({
'& label.Mui-focused': {
color: '#A0AAB4',
},
'& .MuiInput-underline:after': {
borderBottomColor: '#B2BAC2',
},
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: '#E0E3E7',
},
'&:hover fieldset': {
borderColor: '#B2BAC2',
},
'&.Mui-focused fieldset': {
borderColor: '#6F7E8C',
},
},
});
const BootstrapInput = styled(InputBase)(({ theme }) => ({
'label + &': {
marginTop: theme.spacing(3),
},
'& .MuiInputBase-input': {
borderRadius: 4,
position: 'relative',
backgroundColor: theme.palette.mode === 'light' ? '#F3F6F9' : '#1A2027',
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? '#E0E3E7' : '#2D3843',
fontSize: 16,
width: 'auto',
padding: '10px 12px',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
},
}));
const RedditTextField = styled((props) => (
<TextField InputProps={{ disableUnderline: true }} {...props} />
))(({ theme }) => ({
'& .MuiFilledInput-root': {
overflow: 'hidden',
borderRadius: 4,
backgroundColor: theme.palette.mode === 'light' ? '#F3F6F9' : '#1A2027',
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? '#E0E3E7' : '#2D3843',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
'&:hover': {
backgroundColor: 'transparent',
},
'&.Mui-focused': {
backgroundColor: 'transparent',
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 2px`,
borderColor: theme.palette.primary.main,
},
},
}));
const ValidationTextField = styled(TextField)({
'& input:valid + fieldset': {
borderColor: '#E0E3E7',
borderWidth: 1,
},
'& input:invalid + fieldset': {
borderColor: 'red',
borderWidth: 1,
},
'& input:valid:focus + fieldset': {
borderLeftWidth: 4,
padding: '4px !important', // override inline-style
},
});
export default function CustomizedInputsStyled() {
return (
<Box
component="form"
noValidate
sx={{
display: 'grid',
gridTemplateColumns: { sm: '1fr 1fr' },
gap: 2,
}}
>
<FormControl variant="standard">
<InputLabel shrink htmlFor="bootstrap-input">
Bootstrap
</InputLabel>
<BootstrapInput defaultValue="react-bootstrap" id="bootstrap-input" />
</FormControl>
<RedditTextField
label="Reddit"
defaultValue="react-reddit"
id="reddit-input"
variant="filled"
style={{ marginTop: 11 }}
/>
<CssTextField label="Custom CSS" id="custom-css-outlined-input" />
<ValidationTextField
label="CSS validation style"
required
variant="outlined"
defaultValue="Success"
id="validation-outlined-input"
/>
</Box>
);
}
| 3,177 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx | import * as React from 'react';
import { alpha, styled } from '@mui/material/styles';
import InputBase from '@mui/material/InputBase';
import Box from '@mui/material/Box';
import InputLabel from '@mui/material/InputLabel';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import { OutlinedInputProps } from '@mui/material/OutlinedInput';
const CssTextField = styled(TextField)({
'& label.Mui-focused': {
color: '#A0AAB4',
},
'& .MuiInput-underline:after': {
borderBottomColor: '#B2BAC2',
},
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: '#E0E3E7',
},
'&:hover fieldset': {
borderColor: '#B2BAC2',
},
'&.Mui-focused fieldset': {
borderColor: '#6F7E8C',
},
},
});
const BootstrapInput = styled(InputBase)(({ theme }) => ({
'label + &': {
marginTop: theme.spacing(3),
},
'& .MuiInputBase-input': {
borderRadius: 4,
position: 'relative',
backgroundColor: theme.palette.mode === 'light' ? '#F3F6F9' : '#1A2027',
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? '#E0E3E7' : '#2D3843',
fontSize: 16,
width: 'auto',
padding: '10px 12px',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
// Use the system font instead of the default Roboto font.
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:focus': {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
},
}));
const RedditTextField = styled((props: TextFieldProps) => (
<TextField
InputProps={{ disableUnderline: true } as Partial<OutlinedInputProps>}
{...props}
/>
))(({ theme }) => ({
'& .MuiFilledInput-root': {
overflow: 'hidden',
borderRadius: 4,
backgroundColor: theme.palette.mode === 'light' ? '#F3F6F9' : '#1A2027',
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? '#E0E3E7' : '#2D3843',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
'&:hover': {
backgroundColor: 'transparent',
},
'&.Mui-focused': {
backgroundColor: 'transparent',
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 2px`,
borderColor: theme.palette.primary.main,
},
},
}));
const ValidationTextField = styled(TextField)({
'& input:valid + fieldset': {
borderColor: '#E0E3E7',
borderWidth: 1,
},
'& input:invalid + fieldset': {
borderColor: 'red',
borderWidth: 1,
},
'& input:valid:focus + fieldset': {
borderLeftWidth: 4,
padding: '4px !important', // override inline-style
},
});
export default function CustomizedInputsStyled() {
return (
<Box
component="form"
noValidate
sx={{
display: 'grid',
gridTemplateColumns: { sm: '1fr 1fr' },
gap: 2,
}}
>
<FormControl variant="standard">
<InputLabel shrink htmlFor="bootstrap-input">
Bootstrap
</InputLabel>
<BootstrapInput defaultValue="react-bootstrap" id="bootstrap-input" />
</FormControl>
<RedditTextField
label="Reddit"
defaultValue="react-reddit"
id="reddit-input"
variant="filled"
style={{ marginTop: 11 }}
/>
<CssTextField label="Custom CSS" id="custom-css-outlined-input" />
<ValidationTextField
label="CSS validation style"
required
variant="outlined"
defaultValue="Success"
id="validation-outlined-input"
/>
</Box>
);
}
| 3,178 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FormPropsTextFields.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function FormPropsTextFields() {
return (
<Box
component="form"
sx={{
'& .MuiTextField-root': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<div>
<TextField
required
id="outlined-required"
label="Required"
defaultValue="Hello World"
/>
<TextField
disabled
id="outlined-disabled"
label="Disabled"
defaultValue="Hello World"
/>
<TextField
id="outlined-password-input"
label="Password"
type="password"
autoComplete="current-password"
/>
<TextField
id="outlined-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
/>
<TextField
id="outlined-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
/>
<TextField id="outlined-search" label="Search field" type="search" />
<TextField
id="outlined-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
/>
</div>
<div>
<TextField
required
id="filled-required"
label="Required"
defaultValue="Hello World"
variant="filled"
/>
<TextField
disabled
id="filled-disabled"
label="Disabled"
defaultValue="Hello World"
variant="filled"
/>
<TextField
id="filled-password-input"
label="Password"
type="password"
autoComplete="current-password"
variant="filled"
/>
<TextField
id="filled-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
variant="filled"
/>
<TextField
id="filled-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
variant="filled"
/>
<TextField
id="filled-search"
label="Search field"
type="search"
variant="filled"
/>
<TextField
id="filled-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
variant="filled"
/>
</div>
<div>
<TextField
required
id="standard-required"
label="Required"
defaultValue="Hello World"
variant="standard"
/>
<TextField
disabled
id="standard-disabled"
label="Disabled"
defaultValue="Hello World"
variant="standard"
/>
<TextField
id="standard-password-input"
label="Password"
type="password"
autoComplete="current-password"
variant="standard"
/>
<TextField
id="standard-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
variant="standard"
/>
<TextField
id="standard-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
variant="standard"
/>
<TextField
id="standard-search"
label="Search field"
type="search"
variant="standard"
/>
<TextField
id="standard-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
variant="standard"
/>
</div>
</Box>
);
}
| 3,179 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FormPropsTextFields.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function FormPropsTextFields() {
return (
<Box
component="form"
sx={{
'& .MuiTextField-root': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<div>
<TextField
required
id="outlined-required"
label="Required"
defaultValue="Hello World"
/>
<TextField
disabled
id="outlined-disabled"
label="Disabled"
defaultValue="Hello World"
/>
<TextField
id="outlined-password-input"
label="Password"
type="password"
autoComplete="current-password"
/>
<TextField
id="outlined-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
/>
<TextField
id="outlined-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
/>
<TextField id="outlined-search" label="Search field" type="search" />
<TextField
id="outlined-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
/>
</div>
<div>
<TextField
required
id="filled-required"
label="Required"
defaultValue="Hello World"
variant="filled"
/>
<TextField
disabled
id="filled-disabled"
label="Disabled"
defaultValue="Hello World"
variant="filled"
/>
<TextField
id="filled-password-input"
label="Password"
type="password"
autoComplete="current-password"
variant="filled"
/>
<TextField
id="filled-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
variant="filled"
/>
<TextField
id="filled-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
variant="filled"
/>
<TextField
id="filled-search"
label="Search field"
type="search"
variant="filled"
/>
<TextField
id="filled-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
variant="filled"
/>
</div>
<div>
<TextField
required
id="standard-required"
label="Required"
defaultValue="Hello World"
variant="standard"
/>
<TextField
disabled
id="standard-disabled"
label="Disabled"
defaultValue="Hello World"
variant="standard"
/>
<TextField
id="standard-password-input"
label="Password"
type="password"
autoComplete="current-password"
variant="standard"
/>
<TextField
id="standard-read-only-input"
label="Read Only"
defaultValue="Hello World"
InputProps={{
readOnly: true,
}}
variant="standard"
/>
<TextField
id="standard-number"
label="Number"
type="number"
InputLabelProps={{
shrink: true,
}}
variant="standard"
/>
<TextField
id="standard-search"
label="Search field"
type="search"
variant="standard"
/>
<TextField
id="standard-helperText"
label="Helper text"
defaultValue="Default Value"
helperText="Some important text"
variant="standard"
/>
</div>
</Box>
);
}
| 3,180 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FormattedInputs.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { IMaskInput } from 'react-imask';
import { NumericFormat } from 'react-number-format';
import Stack from '@mui/material/Stack';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
const TextMaskCustom = React.forwardRef(function TextMaskCustom(props, ref) {
const { onChange, ...other } = props;
return (
<IMaskInput
{...other}
mask="(#00) 000-0000"
definitions={{
'#': /[1-9]/,
}}
inputRef={ref}
onAccept={(value) => onChange({ target: { name: props.name, value } })}
overwrite
/>
);
});
TextMaskCustom.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
const NumericFormatCustom = React.forwardRef(function NumericFormatCustom(
props,
ref,
) {
const { onChange, ...other } = props;
return (
<NumericFormat
{...other}
getInputRef={ref}
onValueChange={(values) => {
onChange({
target: {
name: props.name,
value: values.value,
},
});
}}
thousandSeparator
valueIsNumericString
prefix="$"
/>
);
});
NumericFormatCustom.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
export default function FormattedInputs() {
const [values, setValues] = React.useState({
textmask: '(100) 000-0000',
numberformat: '1320',
});
const handleChange = (event) => {
setValues({
...values,
[event.target.name]: event.target.value,
});
};
return (
<Stack direction="row" spacing={2}>
<FormControl variant="standard">
<InputLabel htmlFor="formatted-text-mask-input">react-imask</InputLabel>
<Input
value={values.textmask}
onChange={handleChange}
name="textmask"
id="formatted-text-mask-input"
inputComponent={TextMaskCustom}
/>
</FormControl>
<TextField
label="react-number-format"
value={values.numberformat}
onChange={handleChange}
name="numberformat"
id="formatted-numberformat-input"
InputProps={{
inputComponent: NumericFormatCustom,
}}
variant="standard"
/>
</Stack>
);
}
| 3,181 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FormattedInputs.tsx | import * as React from 'react';
import { IMaskInput } from 'react-imask';
import { NumericFormat, NumericFormatProps } from 'react-number-format';
import Stack from '@mui/material/Stack';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
interface CustomProps {
onChange: (event: { target: { name: string; value: string } }) => void;
name: string;
}
const TextMaskCustom = React.forwardRef<HTMLInputElement, CustomProps>(
function TextMaskCustom(props, ref) {
const { onChange, ...other } = props;
return (
<IMaskInput
{...other}
mask="(#00) 000-0000"
definitions={{
'#': /[1-9]/,
}}
inputRef={ref}
onAccept={(value: any) => onChange({ target: { name: props.name, value } })}
overwrite
/>
);
},
);
const NumericFormatCustom = React.forwardRef<NumericFormatProps, CustomProps>(
function NumericFormatCustom(props, ref) {
const { onChange, ...other } = props;
return (
<NumericFormat
{...other}
getInputRef={ref}
onValueChange={(values) => {
onChange({
target: {
name: props.name,
value: values.value,
},
});
}}
thousandSeparator
valueIsNumericString
prefix="$"
/>
);
},
);
export default function FormattedInputs() {
const [values, setValues] = React.useState({
textmask: '(100) 000-0000',
numberformat: '1320',
});
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValues({
...values,
[event.target.name]: event.target.value,
});
};
return (
<Stack direction="row" spacing={2}>
<FormControl variant="standard">
<InputLabel htmlFor="formatted-text-mask-input">react-imask</InputLabel>
<Input
value={values.textmask}
onChange={handleChange}
name="textmask"
id="formatted-text-mask-input"
inputComponent={TextMaskCustom as any}
/>
</FormControl>
<TextField
label="react-number-format"
value={values.numberformat}
onChange={handleChange}
name="numberformat"
id="formatted-numberformat-input"
InputProps={{
inputComponent: NumericFormatCustom as any,
}}
variant="standard"
/>
</Stack>
);
}
| 3,182 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FullWidthTextField.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function FullWidthTextField() {
return (
<Box
sx={{
width: 500,
maxWidth: '100%',
}}
>
<TextField fullWidth label="fullWidth" id="fullWidth" />
</Box>
);
}
| 3,183 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FullWidthTextField.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function FullWidthTextField() {
return (
<Box
sx={{
width: 500,
maxWidth: '100%',
}}
>
<TextField fullWidth label="fullWidth" id="fullWidth" />
</Box>
);
}
| 3,184 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/FullWidthTextField.tsx.preview | <TextField fullWidth label="fullWidth" id="fullWidth" /> | 3,185 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextAligned.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function HelperTextAligned() {
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
'& > :not(style)': { m: 1 },
}}
>
<TextField
helperText="Please enter your name"
id="demo-helper-text-aligned"
label="Name"
/>
<TextField
helperText=" "
id="demo-helper-text-aligned-no-helper"
label="Name"
/>
</Box>
);
}
| 3,186 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextAligned.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function HelperTextAligned() {
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
'& > :not(style)': { m: 1 },
}}
>
<TextField
helperText="Please enter your name"
id="demo-helper-text-aligned"
label="Name"
/>
<TextField
helperText=" "
id="demo-helper-text-aligned-no-helper"
label="Name"
/>
</Box>
);
}
| 3,187 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextAligned.tsx.preview | <TextField
helperText="Please enter your name"
id="demo-helper-text-aligned"
label="Name"
/>
<TextField
helperText=" "
id="demo-helper-text-aligned-no-helper"
label="Name"
/> | 3,188 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextMisaligned.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function HelperTextMisaligned() {
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
'& > :not(style)': { m: 1 },
}}
>
<TextField
helperText="Please enter your name"
id="demo-helper-text-misaligned"
label="Name"
/>
<TextField id="demo-helper-text-misaligned-no-helper" label="Name" />
</Box>
);
}
| 3,189 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextMisaligned.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
export default function HelperTextMisaligned() {
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
'& > :not(style)': { m: 1 },
}}
>
<TextField
helperText="Please enter your name"
id="demo-helper-text-misaligned"
label="Name"
/>
<TextField id="demo-helper-text-misaligned-no-helper" label="Name" />
</Box>
);
}
| 3,190 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/HelperTextMisaligned.tsx.preview | <TextField
helperText="Please enter your name"
id="demo-helper-text-misaligned"
label="Name"
/>
<TextField id="demo-helper-text-misaligned-no-helper" label="Name" /> | 3,191 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/InputAdornments.js | import * as React from 'react';
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Input from '@mui/material/Input';
import FilledInput from '@mui/material/FilledInput';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import InputAdornment from '@mui/material/InputAdornment';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import TextField from '@mui/material/TextField';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
export default function InputAdornments() {
const [showPassword, setShowPassword] = React.useState(false);
const handleClickShowPassword = () => setShowPassword((show) => !show);
const handleMouseDownPassword = (event) => {
event.preventDefault();
};
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap' }}>
<div>
<TextField
label="With normal TextField"
id="outlined-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
/>
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined">
<OutlinedInput
id="outlined-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="outlined-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="outlined-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined">
<InputLabel htmlFor="outlined-adornment-password">Password</InputLabel>
<OutlinedInput
id="outlined-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
label="Password"
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }}>
<InputLabel htmlFor="outlined-adornment-amount">Amount</InputLabel>
<OutlinedInput
id="outlined-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
label="Amount"
/>
</FormControl>
</div>
<div>
<TextField
label="With normal TextField"
id="filled-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
variant="filled"
/>
<FormControl sx={{ m: 1, width: '25ch' }} variant="filled">
<FilledInput
id="filled-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="filled-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="filled-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="filled">
<InputLabel htmlFor="filled-adornment-password">Password</InputLabel>
<FilledInput
id="filled-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }} variant="filled">
<InputLabel htmlFor="filled-adornment-amount">Amount</InputLabel>
<FilledInput
id="filled-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
/>
</FormControl>
</div>
<div>
<TextField
label="With normal TextField"
id="standard-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
variant="standard"
/>
<FormControl variant="standard" sx={{ m: 1, mt: 3, width: '25ch' }}>
<Input
id="standard-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="standard-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="standard-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="standard">
<InputLabel htmlFor="standard-adornment-password">Password</InputLabel>
<Input
id="standard-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="standard-adornment-amount">Amount</InputLabel>
<Input
id="standard-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
/>
</FormControl>
</div>
</Box>
);
}
| 3,192 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/InputAdornments.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Input from '@mui/material/Input';
import FilledInput from '@mui/material/FilledInput';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputLabel from '@mui/material/InputLabel';
import InputAdornment from '@mui/material/InputAdornment';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import TextField from '@mui/material/TextField';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
export default function InputAdornments() {
const [showPassword, setShowPassword] = React.useState(false);
const handleClickShowPassword = () => setShowPassword((show) => !show);
const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap' }}>
<div>
<TextField
label="With normal TextField"
id="outlined-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
/>
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined">
<OutlinedInput
id="outlined-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="outlined-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="outlined-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="outlined">
<InputLabel htmlFor="outlined-adornment-password">Password</InputLabel>
<OutlinedInput
id="outlined-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
label="Password"
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }}>
<InputLabel htmlFor="outlined-adornment-amount">Amount</InputLabel>
<OutlinedInput
id="outlined-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
label="Amount"
/>
</FormControl>
</div>
<div>
<TextField
label="With normal TextField"
id="filled-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
variant="filled"
/>
<FormControl sx={{ m: 1, width: '25ch' }} variant="filled">
<FilledInput
id="filled-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="filled-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="filled-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="filled">
<InputLabel htmlFor="filled-adornment-password">Password</InputLabel>
<FilledInput
id="filled-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }} variant="filled">
<InputLabel htmlFor="filled-adornment-amount">Amount</InputLabel>
<FilledInput
id="filled-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
/>
</FormControl>
</div>
<div>
<TextField
label="With normal TextField"
id="standard-start-adornment"
sx={{ m: 1, width: '25ch' }}
InputProps={{
startAdornment: <InputAdornment position="start">kg</InputAdornment>,
}}
variant="standard"
/>
<FormControl variant="standard" sx={{ m: 1, mt: 3, width: '25ch' }}>
<Input
id="standard-adornment-weight"
endAdornment={<InputAdornment position="end">kg</InputAdornment>}
aria-describedby="standard-weight-helper-text"
inputProps={{
'aria-label': 'weight',
}}
/>
<FormHelperText id="standard-weight-helper-text">Weight</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, width: '25ch' }} variant="standard">
<InputLabel htmlFor="standard-adornment-password">Password</InputLabel>
<Input
id="standard-adornment-password"
type={showPassword ? 'text' : 'password'}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
<FormControl fullWidth sx={{ m: 1 }} variant="standard">
<InputLabel htmlFor="standard-adornment-amount">Amount</InputLabel>
<Input
id="standard-adornment-amount"
startAdornment={<InputAdornment position="start">$</InputAdornment>}
/>
</FormControl>
</div>
</Box>
);
}
| 3,193 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/InputWithIcon.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import InputAdornment from '@mui/material/InputAdornment';
import FormControl from '@mui/material/FormControl';
import TextField from '@mui/material/TextField';
import AccountCircle from '@mui/icons-material/AccountCircle';
export default function InputWithIcon() {
return (
<Box sx={{ '& > :not(style)': { m: 1 } }}>
<FormControl variant="standard">
<InputLabel htmlFor="input-with-icon-adornment">
With a start adornment
</InputLabel>
<Input
id="input-with-icon-adornment"
startAdornment={
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
}
/>
</FormControl>
<TextField
id="input-with-icon-textfield"
label="TextField"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
variant="standard"
/>
<Box sx={{ display: 'flex', alignItems: 'flex-end' }}>
<AccountCircle sx={{ color: 'action.active', mr: 1, my: 0.5 }} />
<TextField id="input-with-sx" label="With sx" variant="standard" />
</Box>
</Box>
);
}
| 3,194 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/InputWithIcon.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Input from '@mui/material/Input';
import InputLabel from '@mui/material/InputLabel';
import InputAdornment from '@mui/material/InputAdornment';
import FormControl from '@mui/material/FormControl';
import TextField from '@mui/material/TextField';
import AccountCircle from '@mui/icons-material/AccountCircle';
export default function InputWithIcon() {
return (
<Box sx={{ '& > :not(style)': { m: 1 } }}>
<FormControl variant="standard">
<InputLabel htmlFor="input-with-icon-adornment">
With a start adornment
</InputLabel>
<Input
id="input-with-icon-adornment"
startAdornment={
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
}
/>
</FormControl>
<TextField
id="input-with-icon-textfield"
label="TextField"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
variant="standard"
/>
<Box sx={{ display: 'flex', alignItems: 'flex-end' }}>
<AccountCircle sx={{ color: 'action.active', mr: 1, my: 0.5 }} />
<TextField id="input-with-sx" label="With sx" variant="standard" />
</Box>
</Box>
);
}
| 3,195 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/Inputs.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Input from '@mui/material/Input';
const ariaLabel = { 'aria-label': 'description' };
export default function Inputs() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1 },
}}
noValidate
autoComplete="off"
>
<Input defaultValue="Hello world" inputProps={ariaLabel} />
<Input placeholder="Placeholder" inputProps={ariaLabel} />
<Input disabled defaultValue="Disabled" inputProps={ariaLabel} />
<Input defaultValue="Error" error inputProps={ariaLabel} />
</Box>
);
}
| 3,196 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/Inputs.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Input from '@mui/material/Input';
const ariaLabel = { 'aria-label': 'description' };
export default function Inputs() {
return (
<Box
component="form"
sx={{
'& > :not(style)': { m: 1 },
}}
noValidate
autoComplete="off"
>
<Input defaultValue="Hello world" inputProps={ariaLabel} />
<Input placeholder="Placeholder" inputProps={ariaLabel} />
<Input disabled defaultValue="Disabled" inputProps={ariaLabel} />
<Input defaultValue="Error" error inputProps={ariaLabel} />
</Box>
);
}
| 3,197 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/Inputs.tsx.preview | <Input defaultValue="Hello world" inputProps={ariaLabel} />
<Input placeholder="Placeholder" inputProps={ariaLabel} />
<Input disabled defaultValue="Disabled" inputProps={ariaLabel} />
<Input defaultValue="Error" error inputProps={ariaLabel} /> | 3,198 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/text-fields/LayoutTextFields.js | import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
function RedBar() {
return (
<Box
sx={{
height: 20,
backgroundColor: (theme) =>
theme.palette.mode === 'light'
? 'rgba(255, 0, 0, 0.1)'
: 'rgb(255 132 132 / 25%)',
}}
/>
);
}
export default function LayoutTextFields() {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
'& .MuiTextField-root': { width: '25ch' },
}}
>
<RedBar />
<TextField label={'margin="none"'} id="margin-none" />
<RedBar />
<TextField label={'margin="dense"'} id="margin-dense" margin="dense" />
<RedBar />
<TextField label={'margin="normal"'} id="margin-normal" margin="normal" />
<RedBar />
</Box>
);
}
| 3,199 |
Subsets and Splits