Skip to content

Commit

Permalink
Make toggle button text optional depending on show boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Riippi committed Sep 25, 2023
1 parent e987cb5 commit 2671176
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/core/Expander/ExpanderGroup/ExpanderGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,6 +39,32 @@ export interface ExpanderGroupProps extends MarginProps {
forwardedRef?: React.Ref<HTMLButtonElement>;
}

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;
}
Expand Down

0 comments on commit 2671176

Please sign in to comment.