From e3b4f81f9e4855b1ae15afa8580c1110a84479c6 Mon Sep 17 00:00:00 2001 From: ericakdiaz Date: Tue, 10 Dec 2024 14:03:28 -0800 Subject: [PATCH] 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}) => ( + + + + ) + )} );