aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/PaneButtons.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-08-31 01:47:46 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-08-31 12:40:54 +0200
commitcd5162fc1bba739e9c32dcbf048e51a0a8903d11 (patch)
tree65e18ac744c308706d1690b9d4c81b2e02516ec0 /subprojects/frontend/src/PaneButtons.tsx
parentfeat(frontend): implement grid view (diff)
downloadrefinery-cd5162fc1bba739e9c32dcbf048e51a0a8903d11.tar.gz
refinery-cd5162fc1bba739e9c32dcbf048e51a0a8903d11.tar.zst
refinery-cd5162fc1bba739e9c32dcbf048e51a0a8903d11.zip
refactor(frontend): pane button theme
Diffstat (limited to 'subprojects/frontend/src/PaneButtons.tsx')
-rw-r--r--subprojects/frontend/src/PaneButtons.tsx94
1 files changed, 69 insertions, 25 deletions
diff --git a/subprojects/frontend/src/PaneButtons.tsx b/subprojects/frontend/src/PaneButtons.tsx
index 9cb02793..9df56baa 100644
--- a/subprojects/frontend/src/PaneButtons.tsx
+++ b/subprojects/frontend/src/PaneButtons.tsx
@@ -9,10 +9,76 @@ import SchemaRoundedIcon from '@mui/icons-material/SchemaRounded';
9import TableChartIcon from '@mui/icons-material/TableChart'; 9import TableChartIcon from '@mui/icons-material/TableChart';
10import ToggleButton from '@mui/material/ToggleButton'; 10import ToggleButton from '@mui/material/ToggleButton';
11import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; 11import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
12import { alpha, styled } from '@mui/material/styles';
12import { observer } from 'mobx-react-lite'; 13import { observer } from 'mobx-react-lite';
13 14
14import type ThemeStore from './theme/ThemeStore'; 15import type ThemeStore from './theme/ThemeStore';
15 16
17const PaneButtonGroup = styled(ToggleButtonGroup, {
18 name: 'PaneButtons-Group',
19 shouldForwardProp: (prop) => prop !== 'hideLabel',
20})<{ hideLabel: boolean }>(({ theme, hideLabel }) => {
21 const color =
22 theme.palette.mode === 'dark'
23 ? theme.palette.primary.main
24 : theme.palette.text.primary;
25 return {
26 gap: theme.spacing(1),
27 '.MuiToggleButton-root': {
28 fontSize: '1rem',
29 lineHeight: '1.5',
30 border: 'none',
31 ...(hideLabel ? {} : { paddingBlock: 6 }),
32 '&::before': {
33 content: '" "',
34 position: 'absolute',
35 bottom: 0,
36 left: 0,
37 width: '0%',
38 height: '2px',
39 background: color,
40 transition: theme.transitions.create('width', {
41 duration: theme.transitions.duration.standard,
42 }),
43 },
44 '&.MuiToggleButtonGroup-grouped': {
45 borderTopLeftRadius: theme.shape.borderRadius,
46 borderTopRightRadius: theme.shape.borderRadius,
47 borderBottomLeftRadius: 0,
48 borderBottomRightRadius: 0,
49 },
50 '&:not(.Mui-selected)': {
51 color: theme.palette.text.secondary,
52 },
53 '&.Mui-selected': {
54 color,
55 '&::before': {
56 width: '100%',
57 },
58 '&:not(:active)': {
59 background: 'transparent',
60 },
61 '&:hover': {
62 background: alpha(
63 theme.palette.text.primary,
64 theme.palette.action.hoverOpacity,
65 ),
66 '@media (hover: none)': {
67 background: 'transparent',
68 },
69 },
70 },
71 },
72 ...(hideLabel
73 ? {}
74 : {
75 '& svg': {
76 margin: '0 6px 0 -4px',
77 },
78 }),
79 };
80});
81
16function PaneButtons({ 82function PaneButtons({
17 themeStore, 83 themeStore,
18 hideLabel, 84 hideLabel,
@@ -21,31 +87,9 @@ function PaneButtons({
21 hideLabel?: boolean; 87 hideLabel?: boolean;
22}): JSX.Element { 88}): JSX.Element {
23 return ( 89 return (
24 <ToggleButtonGroup 90 <PaneButtonGroup
25 size={hideLabel ? 'small' : 'medium'} 91 size={hideLabel ? 'small' : 'medium'}
26 className="rounded" 92 hideLabel={hideLabel ?? PaneButtons.defaultProps.hideLabel}
27 sx={(theme) => ({
28 '.MuiToggleButton-root': {
29 ...(hideLabel
30 ? {}
31 : {
32 paddingBlock: '6px',
33 }),
34 fontSize: '1rem',
35 lineHeight: '1.5',
36 fontWeight: theme.typography.fontWeightMedium ?? 500,
37 '&:not(.Mui-selected)': {
38 color: theme.palette.text.secondary,
39 },
40 },
41 ...(hideLabel
42 ? {}
43 : {
44 '& svg': {
45 margin: '0 6px 0 -4px',
46 },
47 }),
48 })}
49 > 93 >
50 <ToggleButton 94 <ToggleButton
51 value="code" 95 value="code"
@@ -89,7 +133,7 @@ function PaneButtons({
89 <TableChartIcon fontSize="small" /> 133 <TableChartIcon fontSize="small" />
90 {!hideLabel && 'Table'} 134 {!hideLabel && 'Table'}
91 </ToggleButton> 135 </ToggleButton>
92 </ToggleButtonGroup> 136 </PaneButtonGroup>
93 ); 137 );
94} 138}
95 139