fix(striker-ui): make header spinner toggle-able in ExpandablePanel

main
Tsu-ba-me 2 years ago
parent 68f019414b
commit 4bbe570098
  1. 35
      striker-ui/components/Panels/ExpandablePanel.tsx

@ -14,8 +14,9 @@ import InnerPanelHeader from './InnerPanelHeader';
import Spinner from '../Spinner'; import Spinner from '../Spinner';
type ExpandablePanelOptionalProps = { type ExpandablePanelOptionalProps = {
isExpandInitially?: boolean; expandInitially?: boolean;
isLoading?: boolean; loading?: boolean;
showHeaderSpinner?: boolean;
}; };
type ExpandablePanelProps = ExpandablePanelOptionalProps & { type ExpandablePanelProps = ExpandablePanelOptionalProps & {
@ -23,15 +24,20 @@ type ExpandablePanelProps = ExpandablePanelOptionalProps & {
}; };
const EXPANDABLE_PANEL_DEFAULT_PROPS: Required<ExpandablePanelOptionalProps> = { const EXPANDABLE_PANEL_DEFAULT_PROPS: Required<ExpandablePanelOptionalProps> = {
isExpandInitially: false, expandInitially: false,
isLoading: false, loading: false,
showHeaderSpinner: false,
}; };
const HEADER_SPINNER_LENGTH = '1.2em';
const ExpandablePanel: FC<ExpandablePanelProps> = ({ const ExpandablePanel: FC<ExpandablePanelProps> = ({
children, children,
expandInitially:
isExpandInitially = EXPANDABLE_PANEL_DEFAULT_PROPS.expandInitially,
header, header,
isExpandInitially = EXPANDABLE_PANEL_DEFAULT_PROPS.isExpandInitially, loading: isLoading = EXPANDABLE_PANEL_DEFAULT_PROPS.loading,
isLoading = EXPANDABLE_PANEL_DEFAULT_PROPS.isLoading, showHeaderSpinner:
isShowHeaderSpinner = EXPANDABLE_PANEL_DEFAULT_PROPS.showHeaderSpinner,
}) => { }) => {
const [isExpand, setIsExpand] = useState<boolean>(isExpandInitially); const [isExpand, setIsExpand] = useState<boolean>(isExpandInitially);
@ -40,17 +46,20 @@ const ExpandablePanel: FC<ExpandablePanelProps> = ({
[isExpand], [isExpand],
); );
const contentHeight = useMemo(() => (isExpand ? 'auto' : '.2em'), [isExpand]); const contentHeight = useMemo(() => (isExpand ? 'auto' : '.2em'), [isExpand]);
const headerSpinner = useMemo(() => { const headerSpinner = useMemo(
const spinnerLength = '1.2em'; () =>
isShowHeaderSpinner && !isExpand && isLoading ? (
return !isExpand && isLoading ? (
<Spinner <Spinner
progressProps={{ progressProps={{
style: { height: spinnerLength, width: spinnerLength }, style: {
height: HEADER_SPINNER_LENGTH,
width: HEADER_SPINNER_LENGTH,
},
}} }}
/> />
) : undefined; ) : undefined,
}, [isExpand, isLoading]); [isExpand, isLoading, isShowHeaderSpinner],
);
const content = useMemo( const content = useMemo(
() => () =>
isExpand && isLoading ? ( isExpand && isLoading ? (

Loading…
Cancel
Save