fix(striker-ui): move loading spinner from Dialog actions to ActionGroup

main
Tsu-ba-me 1 year ago
parent 689734b293
commit f0189b4949
  1. 7
      striker-ui/components/ActionGroup.tsx
  2. 10
      striker-ui/components/Dialog/DialogActionGroup.tsx
  3. 1
      striker-ui/types/ActionGroup.d.ts

@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import ContainedButton from './ContainedButton'; import ContainedButton from './ContainedButton';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
import Spinner from './Spinner';
const FlexEndBox = styled(FlexBox)({ const FlexEndBox = styled(FlexBox)({
justifyContent: 'flex-end', justifyContent: 'flex-end',
@ -11,7 +12,7 @@ const FlexEndBox = styled(FlexBox)({
}); });
const ActionGroup: FC<ActionGroupProps> = (props) => { const ActionGroup: FC<ActionGroupProps> = (props) => {
const { actions = [] } = props; const { actions = [], loading } = props;
const elements = useMemo( const elements = useMemo(
() => () =>
@ -23,7 +24,9 @@ const ActionGroup: FC<ActionGroupProps> = (props) => {
[actions], [actions],
); );
return ( return loading ? (
<Spinner mt={0} />
) : (
<FlexEndBox row spacing=".5em"> <FlexEndBox row spacing=".5em">
{elements} {elements}
</FlexEndBox> </FlexEndBox>

@ -2,7 +2,6 @@ import { FC, useCallback, useContext, useMemo } from 'react';
import ActionGroup from '../ActionGroup'; import ActionGroup from '../ActionGroup';
import { DialogContext } from './Dialog'; import { DialogContext } from './Dialog';
import Spinner from '../Spinner';
const handleAction: ExtendableEventHandler<ButtonClickEventHandler> = ( const handleAction: ExtendableEventHandler<ButtonClickEventHandler> = (
{ handlers: { base, origin } }, { handlers: { base, origin } },
@ -78,12 +77,14 @@ const DialogActionGroup: FC<DialogActionGroupProps> = (props) => {
onClick: proceedHandler, onClick: proceedHandler,
}, },
]} ]}
loading={loading}
/> />
), ),
[ [
cancelChildren, cancelChildren,
cancelHandler, cancelHandler,
cancelProps, cancelProps,
loading,
proceedChildren, proceedChildren,
proceedColour, proceedColour,
proceedHandler, proceedHandler,
@ -91,12 +92,7 @@ const DialogActionGroup: FC<DialogActionGroupProps> = (props) => {
], ],
); );
const result = useMemo( return actions;
() => (loading ? <Spinner mt={0} /> : actions),
[actions, loading],
);
return result;
}; };
export default DialogActionGroup; export default DialogActionGroup;

@ -1,5 +1,6 @@
type ActionGroupOptionalProps = { type ActionGroupOptionalProps = {
actions?: ContainedButtonProps[]; actions?: ContainedButtonProps[];
loading?: boolean;
}; };
type ActionGroupProps = ActionGroupOptionalProps; type ActionGroupProps = ActionGroupOptionalProps;

Loading…
Cancel
Save