« Material-UI » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
(→Theme) |
(→Button) |
||
Ligne 3 : | Ligne 3 : | ||
* [https://mui.com Material-UI] | * [https://mui.com Material-UI] | ||
* [https://github.com/mui/material-ui/blob/master/examples/material-ui-vite-ts Example project Material-UI, Vite, TypeScript] | * [https://github.com/mui/material-ui/blob/master/examples/material-ui-vite-ts Example project Material-UI, Vite, TypeScript] | ||
= Layout = | |||
== [https://mui.com/material-ui/react-box Box] == | |||
Generic container for grouping other components like the {{boxx|div}} tag.<br> | |||
It has access to the theme and the {{boxx|sx}} property. | |||
<kode lang='tsx'> | |||
import Box from '@mui/material/Box'; | |||
<Box component="section" sx={{ p: 2, border: '1px dashed grey' }}> | |||
This Box renders as an HTML section element. | |||
</Box> | |||
</kode> | |||
== Container == | |||
== Grid v2 == | |||
== Stack == | |||
= [https://mui.com/material-ui/react-button/ Button] = | = [https://mui.com/material-ui/react-button/ Button] = |
Version du 27 octobre 2024 à 21:05
Links
Layout
Box
Generic container for grouping other components like the div tag.
It has access to the theme and the sx property.
import Box from '@mui/material/Box'; <Box component="section" sx={{ p: 2, border: '1px dashed grey' }}> This Box renders as an HTML section element. </Box> |
Container
Grid v2
Stack
Button
import IconButton from '@mui/material/IconButton'; import AddIcon from '@mui/icons-material/Add'; <IconButton aria-label="add" color="primary"> <AddIcon /> </IconButton> |
Table
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'; <TableContainer component={Paper}> <Table sx={{ minWidth: 600 }} aria-label="table"> <TableHead> <TableRow> <TableCell align="right">Name</TableCell> </TableRow> </TableHead> <TableBody> {rows.map((row) => ( <TableRow key={row.name} sx={{ '&:last-child td, &:last-child th': { border: 0 } }} > <TableCell component="th" scope="row"> {row.name} </TableCell> </TableRow> ))} </TableBody> </Table> </TableContainer> |
Styling
App.tsx |
<div sx={{ display: flex }}></div> |
Theme
src/main.tsx |
import { ThemeProvider } from '@mui/material/styles'; import theme from './theme'; createRoot(document.getElementById('root')!).render( <StrictMode> <ThemeProvider theme={theme}> <App /> </ThemeProvider> </StrictMode>, ) |
src/theme.tsx |
import { createTheme } from '@mui/material/styles'; import { red } from '@mui/material/colors'; const theme = createTheme({ cssVariables: true, palette: { mode: 'dark', primary: { main: '#556cd6', }, secondary: { main: '#19857b', }, error: { main: red.A400, }, }, }); export default theme; |
Installation
npm install @mui/material @emotion/react @emotion/styled npm install @mui/icons-material npm install @fontsource/roboto |
main.tsx |
import '@fontsource/roboto/300.css'; import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; |