From cd5162fc1bba739e9c32dcbf048e51a0a8903d11 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 31 Aug 2023 01:47:46 +0200 Subject: refactor(frontend): pane button theme --- subprojects/frontend/src/PaneButtons.tsx | 94 +++++++++++++++++++++++--------- subprojects/frontend/src/TopBar.tsx | 9 ++- 2 files changed, 76 insertions(+), 27 deletions(-) (limited to 'subprojects/frontend') 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'; import TableChartIcon from '@mui/icons-material/TableChart'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; +import { alpha, styled } from '@mui/material/styles'; import { observer } from 'mobx-react-lite'; import type ThemeStore from './theme/ThemeStore'; +const PaneButtonGroup = styled(ToggleButtonGroup, { + name: 'PaneButtons-Group', + shouldForwardProp: (prop) => prop !== 'hideLabel', +})<{ hideLabel: boolean }>(({ theme, hideLabel }) => { + const color = + theme.palette.mode === 'dark' + ? theme.palette.primary.main + : theme.palette.text.primary; + return { + gap: theme.spacing(1), + '.MuiToggleButton-root': { + fontSize: '1rem', + lineHeight: '1.5', + border: 'none', + ...(hideLabel ? {} : { paddingBlock: 6 }), + '&::before': { + content: '" "', + position: 'absolute', + bottom: 0, + left: 0, + width: '0%', + height: '2px', + background: color, + transition: theme.transitions.create('width', { + duration: theme.transitions.duration.standard, + }), + }, + '&.MuiToggleButtonGroup-grouped': { + borderTopLeftRadius: theme.shape.borderRadius, + borderTopRightRadius: theme.shape.borderRadius, + borderBottomLeftRadius: 0, + borderBottomRightRadius: 0, + }, + '&:not(.Mui-selected)': { + color: theme.palette.text.secondary, + }, + '&.Mui-selected': { + color, + '&::before': { + width: '100%', + }, + '&:not(:active)': { + background: 'transparent', + }, + '&:hover': { + background: alpha( + theme.palette.text.primary, + theme.palette.action.hoverOpacity, + ), + '@media (hover: none)': { + background: 'transparent', + }, + }, + }, + }, + ...(hideLabel + ? {} + : { + '& svg': { + margin: '0 6px 0 -4px', + }, + }), + }; +}); + function PaneButtons({ themeStore, hideLabel, @@ -21,31 +87,9 @@ function PaneButtons({ hideLabel?: boolean; }): JSX.Element { return ( - ({ - '.MuiToggleButton-root': { - ...(hideLabel - ? {} - : { - paddingBlock: '6px', - }), - fontSize: '1rem', - lineHeight: '1.5', - fontWeight: theme.typography.fontWeightMedium ?? 500, - '&:not(.Mui-selected)': { - color: theme.palette.text.secondary, - }, - }, - ...(hideLabel - ? {} - : { - '& svg': { - margin: '0 6px 0 -4px', - }, - }), - })} + hideLabel={hideLabel ?? PaneButtons.defaultProps.hideLabel} > {!hideLabel && 'Table'} - + ); } diff --git a/subprojects/frontend/src/TopBar.tsx b/subprojects/frontend/src/TopBar.tsx index c22ca8b1..cfeab6d7 100644 --- a/subprojects/frontend/src/TopBar.tsx +++ b/subprojects/frontend/src/TopBar.tsx @@ -109,7 +109,6 @@ export default observer(function TopBar(): JSX.Element { direction="row" alignItems="center" sx={{ - py: 0.5, position: 'absolute', top: 0, bottom: 0, @@ -120,7 +119,13 @@ export default observer(function TopBar(): JSX.Element { )} - + {large && (