From e3b4f81f9e4855b1ae15afa8580c1110a84479c6 Mon Sep 17 00:00:00 2001 From: ericakdiaz Date: Tue, 10 Dec 2024 14:03:28 -0800 Subject: [PATCH 1/2] chore(weave): Update ToggleButtonGroup to allow disabling individual options --- weave-js/src/components/ToggleButtonGroup.tsx | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/weave-js/src/components/ToggleButtonGroup.tsx b/weave-js/src/components/ToggleButtonGroup.tsx index 65b2c538975..44bcd4038cb 100644 --- a/weave-js/src/components/ToggleButtonGroup.tsx +++ b/weave-js/src/components/ToggleButtonGroup.tsx @@ -3,12 +3,13 @@ import React from 'react'; import {twMerge} from 'tailwind-merge'; import {Button, ButtonSize} from './Button'; -import {IconName} from './Icon'; +import {Icon, IconName} from './Icon'; import {Tailwind} from './Tailwind'; export type ToggleOption = { value: string; icon?: IconName; + isDisabled?: boolean; }; export type ToggleButtonGroupProps = { @@ -37,7 +38,10 @@ export const ToggleButtonGroup = React.forwardRef< } const handleValueChange = (newValue: string) => { - if (newValue !== value) { + if ( + newValue !== value && + options.find(option => option.value === newValue)?.isDisabled !== true + ) { onValueChange(newValue); } }; @@ -49,34 +53,39 @@ export const ToggleButtonGroup = React.forwardRef< onValueChange={handleValueChange} className="flex gap-px" ref={ref}> - {options.map(({value: optionValue, icon}) => ( - - - - ))} + {options.map( + ({value: optionValue, icon, isDisabled: optionIsDisabled}) => ( + + + + ) + )} ); From 827ca8e31db74dd70bf8541919b5c86fa2f20ced Mon Sep 17 00:00:00 2001 From: ericakdiaz Date: Tue, 10 Dec 2024 14:11:36 -0800 Subject: [PATCH 2/2] Remove unused import --- weave-js/src/components/ToggleButtonGroup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave-js/src/components/ToggleButtonGroup.tsx b/weave-js/src/components/ToggleButtonGroup.tsx index 44bcd4038cb..eca93e95657 100644 --- a/weave-js/src/components/ToggleButtonGroup.tsx +++ b/weave-js/src/components/ToggleButtonGroup.tsx @@ -3,7 +3,7 @@ import React from 'react'; import {twMerge} from 'tailwind-merge'; import {Button, ButtonSize} from './Button'; -import {Icon, IconName} from './Icon'; +import {IconName} from './Icon'; import {Tailwind} from './Tailwind'; export type ToggleOption = {