fix(striker-ui): add prop to control show cancel button in dialog actions

main
Tsu-ba-me 1 year ago
parent 753358a13b
commit 1b328913d1
  1. 33
      striker-ui/components/Dialog/DialogActionGroup.tsx
  2. 1
      striker-ui/types/Dialog.d.ts

@ -20,6 +20,7 @@ const DialogActionGroup: FC<DialogActionGroupProps> = (props) => {
onProceed = handleAction, onProceed = handleAction,
proceedColour, proceedColour,
proceedProps, proceedProps,
showCancel = true,
// Dependents // Dependents
cancelChildren = cancelProps?.children, cancelChildren = cancelProps?.children,
proceedChildren = proceedProps?.children, proceedChildren = proceedProps?.children,
@ -61,26 +62,26 @@ const DialogActionGroup: FC<DialogActionGroupProps> = (props) => {
[closeOnProceed, dialogContext, onProceed, proceedProps?.onClick], [closeOnProceed, dialogContext, onProceed, proceedProps?.onClick],
); );
const actions = useMemo( const actions = useMemo(() => {
() => ( const acts: ContainedButtonProps[] = [
<ActionGroup
actions={[
{
...cancelProps,
children: cancelChildren,
onClick: cancelHandler,
},
{ {
background: proceedColour, background: proceedColour,
...proceedProps, ...proceedProps,
children: proceedChildren, children: proceedChildren,
onClick: proceedHandler, onClick: proceedHandler,
}, },
]} ];
loading={loading}
/> if (showCancel) {
), acts.unshift({
[ ...cancelProps,
children: cancelChildren,
onClick: cancelHandler,
});
}
return <ActionGroup actions={acts} loading={loading} />;
}, [
cancelChildren, cancelChildren,
cancelHandler, cancelHandler,
cancelProps, cancelProps,
@ -89,8 +90,8 @@ const DialogActionGroup: FC<DialogActionGroupProps> = (props) => {
proceedColour, proceedColour,
proceedHandler, proceedHandler,
proceedProps, proceedProps,
], showCancel,
); ]);
return actions; return actions;
}; };

@ -31,6 +31,7 @@ type DialogActionGroupOptionalProps = {
proceedChildren?: ContainedButtonProps['children']; proceedChildren?: ContainedButtonProps['children'];
proceedColour?: ContainedButtonProps['background']; proceedColour?: ContainedButtonProps['background'];
proceedProps?: Partial<ContainedButtonProps>; proceedProps?: Partial<ContainedButtonProps>;
showCancel?: boolean;
}; };
type DialogActionGroupProps = DialogActionGroupOptionalProps; type DialogActionGroupProps = DialogActionGroupOptionalProps;

Loading…
Cancel
Save