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. 61
      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,36 +62,36 @@ 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={[ background: proceedColour,
{ ...proceedProps,
...cancelProps, children: proceedChildren,
children: cancelChildren, onClick: proceedHandler,
onClick: cancelHandler, },
}, ];
{
background: proceedColour, if (showCancel) {
...proceedProps, acts.unshift({
children: proceedChildren, ...cancelProps,
onClick: proceedHandler, children: cancelChildren,
}, onClick: cancelHandler,
]} });
loading={loading} }
/>
), return <ActionGroup actions={acts} loading={loading} />;
[ }, [
cancelChildren, cancelChildren,
cancelHandler, cancelHandler,
cancelProps, cancelProps,
loading, loading,
proceedChildren, proceedChildren,
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