From ad06af48e429e1844492fbafacd081494b919e13 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Thu, 15 Sep 2022 04:29:15 +0900 Subject: [PATCH] Add ToggleMultipleGroupControl --- .../test/__snapshots__/index.tsx.snap | 2 + .../component.tsx | 26 ++++--- .../styles.ts | 9 +++ .../toggle-group-control/as-button-group.tsx | 11 ++- .../toggle-group-control/as-radio-group.tsx | 8 ++- .../toggle-group-control/styles.ts | 4 +- .../src/toggle-group-control/types.ts | 11 ++- .../component.tsx | 54 ++++++++++++++ .../toggle-multiple-group-control/index.ts | 1 + .../option-icon.tsx | 40 +++++++++++ .../stories/index.tsx | 70 +++++++++++++++++++ .../toggle-multiple-group-control/types.ts | 26 +++++++ 12 files changed, 245 insertions(+), 17 deletions(-) create mode 100644 packages/components/src/toggle-multiple-group-control/component.tsx create mode 100644 packages/components/src/toggle-multiple-group-control/index.ts create mode 100644 packages/components/src/toggle-multiple-group-control/option-icon.tsx create mode 100644 packages/components/src/toggle-multiple-group-control/stories/index.tsx create mode 100644 packages/components/src/toggle-multiple-group-control/types.ts diff --git a/packages/components/src/toggle-group-control/test/__snapshots__/index.tsx.snap b/packages/components/src/toggle-group-control/test/__snapshots__/index.tsx.snap index 8367f1df88844..dae96c1df92e3 100644 --- a/packages/components/src/toggle-group-control/test/__snapshots__/index.tsx.snap +++ b/packages/components/src/toggle-group-control/test/__snapshots__/index.tsx.snap @@ -142,6 +142,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = ` width: 100%; z-index: 2; width: 30px; + height: 30px; padding-left: 0; padding-right: 0; color: #fff; @@ -209,6 +210,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = ` width: 100%; z-index: 2; width: 30px; + height: 30px; padding-left: 0; padding-right: 0; } diff --git a/packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx b/packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx index e1d90fc1085a2..3c807ed9746d1 100644 --- a/packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx +++ b/packages/components/src/toggle-group-control/toggle-group-control-option-base/component.tsx @@ -66,26 +66,33 @@ function ToggleGroupControlOptionBase( const { className, isIcon = false, + isMultiple = false, value, children, showTooltip = false, ...otherButtonProps } = buttonProps; - const isPressed = otherContextProps.state === value; + const isPressed = + otherContextProps.state === value || + otherButtonProps[ 'aria-pressed' ] === true; const cx = useCx(); const labelViewClasses = cx( isBlock && styles.labelBlock ); const classes = cx( - styles.buttonView( { isDeselectable, isIcon, isPressed, size } ), + styles.buttonView( { + isDeselectable, + isIcon, + isMultiple, + isPressed, + size, + } ), className ); - const buttonOnClick = () => { - if ( isDeselectable && isPressed ) { - otherContextProps.setState( undefined ); - } else { - otherContextProps.setState( value ); - } + const singleSelectButtonProps = { + 'aria-pressed': isPressed, + onClick: () => + otherContextProps.setState( isPressed ? undefined : value ), }; return ( @@ -97,11 +104,10 @@ function ToggleGroupControlOptionBase( { isDeselectable ? (