fix(striker-ui): revise inner and expandable panel types
This commit is contained in:
parent
0f40ffe604
commit
d9685250b6
@ -3,7 +3,7 @@ import {
|
|||||||
ExpandMore as ExpandMoreIcon,
|
ExpandMore as ExpandMoreIcon,
|
||||||
} from '@mui/icons-material';
|
} from '@mui/icons-material';
|
||||||
import { Box, IconButton } from '@mui/material';
|
import { Box, IconButton } from '@mui/material';
|
||||||
import { FC, ReactNode, useMemo, useState } from 'react';
|
import { FC, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { GREY } from '../../lib/consts/DEFAULT_THEME';
|
import { GREY } from '../../lib/consts/DEFAULT_THEME';
|
||||||
|
|
||||||
@ -14,31 +14,15 @@ import InnerPanelHeader from './InnerPanelHeader';
|
|||||||
import Spinner from '../Spinner';
|
import Spinner from '../Spinner';
|
||||||
import { BodyText } from '../Text';
|
import { BodyText } from '../Text';
|
||||||
|
|
||||||
type ExpandablePanelOptionalProps = {
|
|
||||||
expandInitially?: boolean;
|
|
||||||
loading?: boolean;
|
|
||||||
showHeaderSpinner?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ExpandablePanelProps = ExpandablePanelOptionalProps & {
|
|
||||||
header: ReactNode;
|
|
||||||
};
|
|
||||||
|
|
||||||
const EXPANDABLE_PANEL_DEFAULT_PROPS: Required<ExpandablePanelOptionalProps> = {
|
|
||||||
expandInitially: false,
|
|
||||||
loading: false,
|
|
||||||
showHeaderSpinner: false,
|
|
||||||
};
|
|
||||||
const HEADER_SPINNER_LENGTH = '1.2em';
|
const HEADER_SPINNER_LENGTH = '1.2em';
|
||||||
|
|
||||||
const ExpandablePanel: FC<ExpandablePanelProps> = ({
|
const ExpandablePanel: FC<ExpandablePanelProps> = ({
|
||||||
children,
|
children,
|
||||||
expandInitially:
|
expandInitially: isExpandInitially = false,
|
||||||
isExpandInitially = EXPANDABLE_PANEL_DEFAULT_PROPS.expandInitially,
|
|
||||||
header,
|
header,
|
||||||
loading: isLoading = EXPANDABLE_PANEL_DEFAULT_PROPS.loading,
|
loading: isLoading = false,
|
||||||
showHeaderSpinner:
|
panelProps,
|
||||||
isShowHeaderSpinner = EXPANDABLE_PANEL_DEFAULT_PROPS.showHeaderSpinner,
|
showHeaderSpinner: isShowHeaderSpinner = false,
|
||||||
}) => {
|
}) => {
|
||||||
const [isExpand, setIsExpand] = useState<boolean>(isExpandInitially);
|
const [isExpand, setIsExpand] = useState<boolean>(isExpandInitially);
|
||||||
|
|
||||||
@ -76,7 +60,7 @@ const ExpandablePanel: FC<ExpandablePanelProps> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InnerPanel>
|
<InnerPanel {...panelProps}>
|
||||||
<InnerPanelHeader>
|
<InnerPanelHeader>
|
||||||
<FlexBox row>
|
<FlexBox row>
|
||||||
{headerElement}
|
{headerElement}
|
||||||
@ -96,6 +80,4 @@ const ExpandablePanel: FC<ExpandablePanelProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpandablePanel.defaultProps = EXPANDABLE_PANEL_DEFAULT_PROPS;
|
|
||||||
|
|
||||||
export default ExpandablePanel;
|
export default ExpandablePanel;
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
import { FC } from 'react';
|
import { FC, useMemo } from 'react';
|
||||||
import { Box as MUIBox, BoxProps as MUIBoxProps } from '@mui/material';
|
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';
|
||||||
|
|
||||||
type InnerPanelProps = MUIBoxProps;
|
const InnerPanel: FC<InnerPanelProps> = ({ sx, ...muiBoxRestProps }) => {
|
||||||
|
const combinedSx = useMemo<SxProps<Theme>>(
|
||||||
|
() => ({
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderRadius: BORDER_RADIUS,
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderColor: DIVIDER,
|
||||||
|
marginTop: '1.4em',
|
||||||
|
marginBottom: '1.4em',
|
||||||
|
paddingBottom: 0,
|
||||||
|
position: 'relative',
|
||||||
|
|
||||||
const InnerPanel: FC<InnerPanelProps> = ({ sx, ...muiBoxRestProps }) => (
|
...sx,
|
||||||
<MUIBox
|
}),
|
||||||
{...{
|
[sx],
|
||||||
sx: {
|
);
|
||||||
borderWidth: '1px',
|
|
||||||
borderRadius: BORDER_RADIUS,
|
|
||||||
borderStyle: 'solid',
|
|
||||||
borderColor: DIVIDER,
|
|
||||||
marginTop: '1.4em',
|
|
||||||
marginBottom: '1.4em',
|
|
||||||
paddingBottom: 0,
|
|
||||||
position: 'relative',
|
|
||||||
|
|
||||||
...sx,
|
return <MUIBox {...muiBoxRestProps} sx={combinedSx} />;
|
||||||
},
|
};
|
||||||
...muiBoxRestProps,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default InnerPanel;
|
export default InnerPanel;
|
||||||
|
10
striker-ui/types/ExpandablePanel.d.ts
vendored
Normal file
10
striker-ui/types/ExpandablePanel.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
type ExpandablePanelOptionalProps = {
|
||||||
|
expandInitially?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
panelProps?: InnerPanelProps;
|
||||||
|
showHeaderSpinner?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ExpandablePanelProps = ExpandablePanelOptionalProps & {
|
||||||
|
header: import('react').ReactNode;
|
||||||
|
};
|
1
striker-ui/types/InnerPanel.d.ts
vendored
Normal file
1
striker-ui/types/InnerPanel.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
type InnerPanelProps = import('@mui/material').BoxProps;
|
Loading…
Reference in New Issue
Block a user