Skip to content

Commit

Permalink
remove barrel files, use ButtonSize instead of ToggleButtonGroupSizes
Browse files Browse the repository at this point in the history
  • Loading branch information
molliean committed Nov 22, 2024
1 parent afaef09 commit 428c80b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import * as ToggleGroup from '@radix-ui/react-toggle-group';
import React from 'react';
import {twMerge} from 'tailwind-merge';

import {Button} from '../Button';
import {IconName} from '../Icon';
import {Tailwind} from '../Tailwind';
import {ToggleButtonGroupSizes} from './types';
import {Button, ButtonSize} from './Button';
import {IconName} from './Icon';
import {Tailwind} from './Tailwind';

export type ToggleOption = {
label: string;
value: string;
icon?: IconName;
};

export type ToggleButtonGroupProps = {
options: ToggleOption[];
value: string;
size: ToggleButtonGroupSizes;
size: ButtonSize;
isDisabled?: boolean;
onValueChange: (value: string) => void;
};
Expand All @@ -31,6 +30,12 @@ export const ToggleButtonGroup = React.forwardRef<
return null; // Do not render if there are fewer than two options
}

if (!options.some(option => option.value === value)) {
console.warn(
`Warning: The provided value "${value}" is not one of the options.`
);
}

const handleValueChange = (newValue: string) => {
if (newValue !== value) {
onValueChange(newValue);
Expand All @@ -44,11 +49,11 @@ export const ToggleButtonGroup = React.forwardRef<
onValueChange={handleValueChange}
className="flex gap-px"
ref={ref}>
{options.map(({label, icon}) => (
{options.map(({value: optionValue, icon}) => (
<ToggleGroup.Item
key={label}
value={label}
disabled={isDisabled || value === label}>
key={optionValue}
value={optionValue}
disabled={isDisabled || value === optionValue}>
<Button
icon={icon}
size={size}
Expand All @@ -57,13 +62,13 @@ export const ToggleButtonGroup = React.forwardRef<
size === 'medium' && 'gap-3 px-10 py-4 text-base',
size === 'large' && 'gap-2 px-12 py-8 text-base',
isDisabled && 'pointer-events-none opacity-35',
value === label
value === optionValue
? 'bg-teal-300/[0.48] text-teal-600 hover:bg-teal-300/[0.48]'
: 'hover:bg-oblivion/7 bg-oblivion/5 text-moon-600 hover:text-moon-800',
'first:rounded-l-sm', // First button rounded left
'last:rounded-r-sm' // Last button rounded right
)}>
{label}
{optionValue}
</Button>
</ToggleGroup.Item>
))}
Expand Down
2 changes: 0 additions & 2 deletions weave-js/src/components/ToggleButtonGroup/index.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions weave-js/src/components/ToggleButtonGroup/types.tsx

This file was deleted.

0 comments on commit 428c80b

Please sign in to comment.