fix(striker-ui): adjust inner panel margin

main
Tsu-ba-me 2 years ago
parent fb8e92ffb4
commit 15942d258d
  1. 34
      striker-ui/components/Panels/InnerPanel.tsx
  2. 25
      striker-ui/components/Panels/InnerPanelBody.tsx
  3. 8
      striker-ui/types/InnerPanel.d.ts

@ -3,15 +3,33 @@ import { Box as MUIBox, SxProps, Theme } from '@mui/material';
import { BORDER_RADIUS, DIVIDER } from '../../lib/consts/DEFAULT_THEME'; import { BORDER_RADIUS, DIVIDER } from '../../lib/consts/DEFAULT_THEME';
const InnerPanel: FC<InnerPanelProps> = ({ sx, ...muiBoxRestProps }) => { const InnerPanel: FC<InnerPanelProps> = ({
headerMarginOffset: hmo = '.3em',
ml,
mv = '1.4em',
sx,
// Props that depend on others.
mb = mv,
mt = mv,
...muiBoxRestProps
}) => {
const marginLeft = useMemo(
() => (ml ? `calc(${ml} + ${hmo})` : hmo),
[hmo, ml],
);
const marginTop = useMemo(() => {
const resultMt = typeof mt === 'number' ? `${mt}px` : mt;
return `calc(${resultMt} + ${hmo})`;
}, [hmo, mt]);
const combinedSx = useMemo<SxProps<Theme>>( const combinedSx = useMemo<SxProps<Theme>>(
() => ({ () => ({
borderWidth: '1px', borderWidth: '1px',
borderRadius: BORDER_RADIUS, borderRadius: BORDER_RADIUS,
borderStyle: 'solid', borderStyle: 'solid',
borderColor: DIVIDER, borderColor: DIVIDER,
marginTop: '1.4em',
marginBottom: '1.4em',
paddingBottom: 0, paddingBottom: 0,
position: 'relative', position: 'relative',
@ -20,7 +38,15 @@ const InnerPanel: FC<InnerPanelProps> = ({ sx, ...muiBoxRestProps }) => {
[sx], [sx],
); );
return <MUIBox {...muiBoxRestProps} sx={combinedSx} />; return (
<MUIBox
mb={mb}
ml={marginLeft}
mt={marginTop}
{...muiBoxRestProps}
sx={combinedSx}
/>
);
}; };
export default InnerPanel; export default InnerPanel;

@ -1,17 +1,20 @@
import { Box, BoxProps } from '@mui/material'; import { Box, BoxProps, SxProps, Theme } from '@mui/material';
import { FC } from 'react'; import { FC, useMemo } from 'react';
const InnerPanelBody: FC<BoxProps> = ({ sx, ...innerPanelBodyRestProps }) => ( const InnerPanelBody: FC<BoxProps> = ({ sx, ...innerPanelBodyRestProps }) => {
<Box const combinedSx = useMemo<SxProps<Theme>>(
{...{ () => ({
...innerPanelBodyRestProps, position: 'relative',
sx: { zIndex: 20,
padding: '.3em .7em',
...sx, ...sx,
}, }),
}} [sx],
/>
); );
return (
<Box padding=".3em .7em" {...innerPanelBodyRestProps} sx={combinedSx} />
);
};
export default InnerPanelBody; export default InnerPanelBody;

@ -1 +1,7 @@
type InnerPanelProps = import('@mui/material').BoxProps; type InnerPanelOptionalProps = {
headerMarginOffset?: number | string;
mv?: number | string;
};
type InnerPanelProps = InnerPanelOptionalProps &
import('@mui/material').BoxProps;

Loading…
Cancel
Save