Skip to content
Snippets Groups Projects
Unverified Commit 501ef8dc authored by JinSSJ3's avatar JinSSJ3 Committed by GitHub
Browse files

Merge pull request #4 from files-ui/14-ref-props-table-order-alpha

[REF]: 14 ref props table order alpha
parents 60e3576c f8938a39
Branches
No related tags found
No related merge requests found
...@@ -7,6 +7,10 @@ import TableContainer from "@mui/material/TableContainer"; ...@@ -7,6 +7,10 @@ import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead"; import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow"; import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper"; import Paper from "@mui/material/Paper";
import SortByAlphaIcon from "@mui/icons-material/SortByAlpha";
import LowPriorityIcon from "@mui/icons-material/LowPriority";
import SubTitle from "../../components/demo-components/sub-title/SubTitle";
import { Tooltip, IconButton, Stack } from "@mui/material";
const StyledTableCell = styled(TableCell)(({ theme }) => ({ const StyledTableCell = styled(TableCell)(({ theme }) => ({
[`&.${tableCellClasses.head}`]: { [`&.${tableCellClasses.head}`]: {
...@@ -27,44 +31,91 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({ ...@@ -27,44 +31,91 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
border: 0, border: 0,
}, },
})); }));
function compareNames(a, b) {
if (a?.name < b?.name) {
return -1;
} else {
return 1;
}
}
export default function PropsTableApi({ rows = [] }) { export default function PropsTableApi({ rows = [] }) {
const [sorted, setSorted] = React.useState(false);
const [localRows, setLocalRows] = React.useState(rows);
const handleSort = () => {
setSorted((_sorted) => {
const resultSorted = !_sorted;
const rowsToSort = [...rows];
if (resultSorted) {
setLocalRows(rowsToSort.sort(compareNames));
} else {
setLocalRows(rowsToSort);
}
return resultSorted;
});
};
return ( return (
<TableContainer component={Paper}> <React.Fragment>
<Table sx={{ minWidth: 700 }} aria-label="customized table"> <Stack
<TableHead> direction={"row"}
<TableRow> justifyContent="flex-start"
<StyledTableCell /* width={"30%"} */>Name</StyledTableCell> alignItems={"center"}
<StyledTableCell align="left" /* width={"30%"} */> spacing={2}
Type >
</StyledTableCell> <SubTitle content="Props" />{" "}
<StyledTableCell align="left">Default</StyledTableCell> <Tooltip title={sorted ? "Sort by importance" : "Sort alphabetically"}>
<StyledTableCell align="left" /* width={"30%"} */> <IconButton
Description style={{ borderRadius: "50%", border: "0.5px solid #eaeef3" }}
</StyledTableCell> onClick={handleSort}
</TableRow> aria-label="upload picture"
</TableHead> component="label"
<TableBody> >
{rows.map((row) => ( {sorted ? <SortByAlphaIcon /> : <LowPriorityIcon />}
<StyledTableRow key={row.name}> </IconButton>
<StyledTableCell </Tooltip>{" "}
component="th" </Stack>
scope="row" <TableContainer component={Paper}>
style={{ <Table sx={{ minWidth: 700 }} aria-label="customized table">
wordBreak: row.name.length > 12 ? "break-word" : "normal", <TableHead>
}} <TableRow>
> <StyledTableCell /* width={"30%"} */>Name</StyledTableCell>
{row.name} <StyledTableCell align="left" /* width={"30%"} */>
Type
</StyledTableCell> </StyledTableCell>
<StyledTableCell align="left" style={{ wordBreak: "break-word" }}> <StyledTableCell align="left">Default</StyledTableCell>
{row.type} <StyledTableCell align="left" /* width={"30%"} */>
Description
</StyledTableCell> </StyledTableCell>
<StyledTableCell align="left">{row.default}</StyledTableCell> </TableRow>
<StyledTableCell align="left">{row.description}</StyledTableCell> </TableHead>
</StyledTableRow> <TableBody>
))} {localRows.map((row) => (
</TableBody> <StyledTableRow key={row.name}>
</Table> <StyledTableCell
</TableContainer> component="th"
scope="row"
style={{
wordBreak: row.name.length > 12 ? "break-word" : "normal",
}}
>
{row.name}
</StyledTableCell>
<StyledTableCell
align="left"
style={{ wordBreak: "break-word" }}
>
{row.type}
</StyledTableCell>
<StyledTableCell align="left">{row.default}</StyledTableCell>
<StyledTableCell align="left">
{row.description}
</StyledTableCell>
</StyledTableRow>
))}
</TableBody>
</Table>
</TableContainer>
</React.Fragment>
); );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment