From 26711767d52df34799b47bdd92177e6f71c29b66 Mon Sep 17 00:00:00 2001 From: Mikko Riippi Date: Thu, 14 Sep 2023 15:56:48 +0300 Subject: [PATCH] Make toggle button text optional depending on show boolean --- .../Expander/ExpanderGroup/ExpanderGroup.tsx | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/core/Expander/ExpanderGroup/ExpanderGroup.tsx b/src/core/Expander/ExpanderGroup/ExpanderGroup.tsx index 66597616f..d002b476b 100644 --- a/src/core/Expander/ExpanderGroup/ExpanderGroup.tsx +++ b/src/core/Expander/ExpanderGroup/ExpanderGroup.tsx @@ -15,24 +15,16 @@ const baseClassName = 'fi-expander-group'; const openClassName = `${baseClassName}--open`; const expandersContainerClassName = `${baseClassName}_expanders`; const openAllButtonClassName = `${baseClassName}_all-button`; -export interface ExpanderGroupProps extends MarginProps { + +interface PartialExpanderGroupProps extends MarginProps { /** Expanders (and optionally other ReactNodes) */ children: ReactNode; - /** 'Open all' button text */ - openAllText: string; - /** 'Close all' button text */ - closeAllText: string; /** 'Open all' button text for screen readers, hides `OpenAllText` for screen readers if provided */ ariaOpenAllText?: string; /** 'Close all' button text for screen readers, hides `CloseAllText` for screen readers if provided */ ariaCloseAllText?: string; /** CSS class for custom styles */ className?: string; - /** - * Shows Open/Close all button - * @default true - */ - showToggleAllButton?: boolean; /** Props passed to the Open/Close all button */ toggleAllButtonProps?: Omit< HtmlButtonProps, @@ -47,6 +39,32 @@ export interface ExpanderGroupProps extends MarginProps { forwardedRef?: React.Ref; } +type ToggleAllProps = + | { + /** 'Open all' button text */ + openAllText?: string; + /** 'Close all' button text */ + closeAllText?: string; + /** + * Shows Open/Close all button + * @default true + */ + showToggleAllButton?: false | never; + } + | { + /** 'Open all' button text. Required when `showToggleAllButton` is true. */ + openAllText: string; + /** 'Close all' button text. Required when `showToggleAllButton` is true. */ + closeAllText: string; + /** + * Shows Open/Close all button + * @default true + */ + showToggleAllButton: true; + }; + +export type ExpanderGroupProps = PartialExpanderGroupProps & ToggleAllProps; + interface ExpanderOpenStates { [key: string]: boolean; }