diff --git a/code/ui/blocks/src/components/ArgsTable/types.ts b/code/ui/blocks/src/components/ArgsTable/types.ts index a8f3dd1d453e..653bf236acdb 100644 --- a/code/ui/blocks/src/components/ArgsTable/types.ts +++ b/code/ui/blocks/src/components/ArgsTable/types.ts @@ -41,6 +41,21 @@ export interface ArgType { description?: string; defaultValue?: any; if?: Conditional; + table?: { + category?: string; + disable?: boolean; + subcategory?: string; + defaultValue?: { + summary: string; + detail?: string; + }; + type?: { + summary: string; + detail?: string; + }; + readonly?: boolean; + [key: string]: any; + }; [key: string]: any; } diff --git a/code/ui/blocks/src/controls/Boolean.stories.tsx b/code/ui/blocks/src/controls/Boolean.stories.tsx index 8f7c043701c6..4629f2cc3644 100644 --- a/code/ui/blocks/src/controls/Boolean.stories.tsx +++ b/code/ui/blocks/src/controls/Boolean.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; -import { within, fireEvent, waitFor, expect } from '@storybook/test'; +import { within, fireEvent, waitFor, expect, fn } from '@storybook/test'; import { addons } from '@storybook/preview-api'; import { RESET_STORY_ARGS, STORY_ARGS_UPDATED } from '@storybook/core-events'; import { BooleanControl } from './Boolean'; @@ -14,31 +14,36 @@ const meta = { info: 'This is info for the Boolean control stories', jsx: { useBooleanShorthandSyntax: false }, }, -} as Meta; + args: { + onChange: fn(), + }, +} satisfies Meta; export default meta; -export const True: StoryObj = { +type Story = StoryObj; + +export const True: Story = { args: { value: true, name: 'True', }, }; -export const False: StoryObj = { +export const False: Story = { args: { value: false, name: 'False', }, }; -export const Undefined: StoryObj = { +export const Undefined: Story = { args: { value: undefined, name: 'Undefined', }, }; -export const Toggling: StoryObj = { +export const Toggling: Story = { args: { value: undefined, name: 'Toggling', @@ -78,7 +83,7 @@ export const Toggling: StoryObj = { }, }; -export const TogglingInDocs: StoryObj = { +export const TogglingInDocs: Story = { ...Toggling, args: { name: 'Toggling In Docs', @@ -89,3 +94,19 @@ export const TogglingInDocs: StoryObj = { }, }, }; + +export const Readonly: Story = { + args: { + name: 'readonly', + value: true, + argType: { table: { readonly: true } }, + }, +}; + +export const ReadonlyAndUndefined: Story = { + args: { + name: 'readonly-and-undefined', + value: undefined, + argType: { table: { readonly: true } }, + }, +}; diff --git a/code/ui/blocks/src/controls/Boolean.tsx b/code/ui/blocks/src/controls/Boolean.tsx index 7045d214b3c3..267f44cd5107 100644 --- a/code/ui/blocks/src/controls/Boolean.tsx +++ b/code/ui/blocks/src/controls/Boolean.tsx @@ -19,6 +19,13 @@ const Label = styled.label(({ theme }) => ({ background: theme.boolean.background, borderRadius: '3em', padding: 1, + '&[aria-disabled="true"]': { + opacity: 0.5, + + input: { + cursor: 'not-allowed', + }, + }, input: { appearance: 'none', @@ -98,8 +105,16 @@ export type BooleanProps = ControlProps & BooleanConfig; * * ``` */ -export const BooleanControl: FC = ({ name, value, onChange, onBlur, onFocus }) => { +export const BooleanControl: FC = ({ + name, + value, + onChange, + onBlur, + onFocus, + argType, +}) => { const onSetFalse = useCallback(() => onChange(false), [onChange]); + const readonly = !!argType?.table?.readonly; if (value === undefined) { return ( @@ -117,13 +133,14 @@ export const BooleanControl: FC = ({ name, value, onChange, onBlur const parsedValue = typeof value === 'string' ? parse(value) : value; return ( -