Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 60 additions & 11 deletions src/docs/30_mui_components/buttons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import {
faMagic,
faTrashCan,
faPlus,
faCheck,
faDownload,
faExclamationCircle,
faUpRightAndDownLeftFromCenter,
faClose,
faGrip, faTable,
faGrip,
faTable,
faWarning,
faInfoCircle,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

Expand Down Expand Up @@ -125,20 +130,60 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
<FontAwesomeIcon icon={faClose} />
</IconButton>
</Stack>
<Stack direction="row" gap={3} sx={{ flexWrap: 'wrap' }}>
<IconButton color="primary">
<FontAwesomeIcon icon={faPlus} />
</IconButton>
<IconButton color="secondary">
<FontAwesomeIcon icon={faPlus} />
</IconButton>
<IconButton color="info">
<FontAwesomeIcon icon={faInfoCircle} />
</IconButton>
<IconButton color="success">
<FontAwesomeIcon icon={faCheck} />
</IconButton>
<IconButton color="warning">
<FontAwesomeIcon icon={faWarning} />
</IconButton>
<IconButton color="error">
<FontAwesomeIcon icon={faExclamationCircle} />
</IconButton>
</Stack>
<Stack direction="row" gap={3} sx={{ flexWrap: 'wrap' }}>
<IconButton variant="contained" color="primary">
<FontAwesomeIcon icon={faPlus} />
</IconButton>
<IconButton variant="contained" color="secondary">
<FontAwesomeIcon icon={faPlus} />
</IconButton>
<IconButton variant="contained" color="info">
<FontAwesomeIcon icon={faInfoCircle} />
</IconButton>
<IconButton variant="contained" color="success">
<FontAwesomeIcon icon={faCheck} />
</IconButton>
<IconButton variant="contained" color="warning">
<FontAwesomeIcon icon={faWarning} />
</IconButton>
<IconButton variant="contained" color="error">
<FontAwesomeIcon icon={faExclamationCircle} />
</IconButton>
</Stack>
</ThemeProvider>

## Toggle Button

While MUI provides color variants, stick to the default one as the colored variant don't make much semantic sense (expect
While MUI provides color variants, stick to the default one as the colored variant don't make much semantic sense (expect
maybe for the _danger_ one).

### Text

<Unstyled>
<ThemeProvider theme={theme}>
<Stack gap={3} direction="row">
<LensToggle segments={[{label: 'Geo location' }, {label: 'Manual location' }]} />
<LensToggle segments={[{label: 'Geo location' }, {label: 'Manual location' }]} color="primary" />
<LensToggle segments={[{ label: 'Geo location' }, { label: 'Manual location' }]} />
<LensToggle segments={[{ label: 'Geo location' }, { label: 'Manual location' }]} color="primary" />
</Stack>
</ThemeProvider>
</Unstyled>
Expand All @@ -148,8 +193,8 @@ maybe for the _danger_ one).
<Unstyled>
<ThemeProvider theme={theme}>
<Stack gap={3} direction="row">
<LensToggle segments={[{icon: faGrip }, {icon: faTable }]} />
<LensToggle segments={[{icon: faGrip }, {icon: faTable }]} color="primary" />
<LensToggle segments={[{ icon: faGrip }, { icon: faTable }]} />
<LensToggle segments={[{ icon: faGrip }, { icon: faTable }]} color="primary" />
</Stack>
</ThemeProvider>
</Unstyled>
Expand All @@ -159,8 +204,9 @@ maybe for the _danger_ one).
<Unstyled>
<ThemeProvider theme={theme}>
<Stack gap={3} direction="row">
<LensToggle segments={[{icon: faGrip, label: 'Geo location' }, {icon: faTable, label: 'Manual location' }]} />
<LensToggle segments={[{icon: faGrip, label: 'Geo location' }, {icon: faTable, label: 'Manual location' }]} color="primary" />
<LensToggle segments={[{ icon: faGrip, label: 'Geo location' }, { icon: faTable, label: 'Manual location' }]} />
<LensToggle segments={[{ icon: faGrip, label: 'Geo location' }, { icon: faTable, label: 'Manual location' }]}
color="primary" />
</Stack>
</ThemeProvider>
</Unstyled>
Expand All @@ -169,15 +215,18 @@ maybe for the _danger_ one).
on icon only toggles, we have to decrease the padding so that the total size is less or equal to 31px.

The root issue is that we use `:only-child` selector on icon only toggle buttons, but text nodes are not considered children
elements in CSS, so icon + text is mistakenly selected by the rule.
elements in CSS, so icon + text is mistakenly selected by the rule.

If you want to prevent that, you can wrap the text in a `span` element, like so:

<Unstyled>
<ThemeProvider theme={theme}>
<Stack gap={3} direction="row">
<LensToggle withWrapAroundLabel segments={[{icon: faGrip, label: 'Geo location' }, {icon: faTable, label: 'Manual location' }]} />
<LensToggle withWrapAroundLabel segments={[{icon: faGrip, label: 'Geo location' }, {icon: faTable, label: 'Manual location' }]} color="primary" />
<LensToggle withWrapAroundLabel
segments={[{ icon: faGrip, label: 'Geo location' }, { icon: faTable, label: 'Manual location' }]} />
<LensToggle withWrapAroundLabel
segments={[{ icon: faGrip, label: 'Geo location' }, { icon: faTable, label: 'Manual location' }]}
color="primary" />
</Stack>
</ThemeProvider>
</Unstyled>
80 changes: 80 additions & 0 deletions src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ declare module '@mui/material/Button' {
light: true;
}
}
declare module '@mui/material/IconButton' {
interface IconButtonOwnProps {
variant?: 'text' | 'contained';
}
}

declare module '@mui/material/Chip' {
interface ChipPropsColorOverrides {
Expand Down Expand Up @@ -869,6 +874,66 @@ export const theme = createTheme({
},
},
MuiIconButton: {
defaultProps: {
variant: 'text',
},
variants: [
{
props: { variant: 'contained' },
style: {
color: color.icon.inverse.value,
backgroundColor: color.bg.strong.value,
'&:hover': {
backgroundColor: color.bg.strong.value,
},
},
},
{
props: { variant: 'contained', color: 'primary' },
style: {
backgroundColor: color.bg.accent.strong.value,
'&:hover': {
backgroundColor: color.bg.accent.strong.value,
},
},
},
{
props: { variant: 'contained', color: 'info' },
style: {
backgroundColor: color.bg.info.strong.value,
'&:hover': {
backgroundColor: color.bg.info.strong.value,
},
},
},
{
props: { variant: 'contained', color: 'success' },
style: {
backgroundColor: color.bg.success.strong.value,
'&:hover': {
backgroundColor: color.bg.success.strong.value,
},
},
},
{
props: { variant: 'contained', color: 'warning' },
style: {
backgroundColor: color.bg.warning.strong.value,
'&:hover': {
backgroundColor: color.bg.warning.strong.value,
},
},
},
{
props: { variant: 'contained', color: 'error' },
style: {
backgroundColor: color.bg.danger.strong.value,
'&:hover': {
backgroundColor: color.bg.danger.strong.value,
},
},
},
],
styleOverrides: {
root: {
color: color.icon.value,
Expand All @@ -880,6 +945,21 @@ export const theme = createTheme({
opacity: 0.4,
},
},
colorPrimary: {
color: color.icon.accent.value,
},
colorSuccess: {
color: color.icon.success.value,
},
colorInfo: {
color: color.icon.info.value,
},
colorWarning: {
color: color.icon.warning.value,
},
colorError: {
color: color.icon.danger.value,
},
sizeSmall: {
padding: '10px',
fontSize: '12px',
Expand Down