The Open Standard for Generative UI
Option blocks with description (#179)
Ankit Das7fb67e95a833
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.jsonindex ad33f46aa..e279d1565 100644--- a/js/packages/react-ui/package.json+++ b/js/packages/react-ui/package.json@@ -2,7 +2,7 @@"type": "module","name": "@crayonai/react-ui","license": "MIT",- "version": "0.8.21",+ "version": "0.8.22","description": "Component library for Generative UI SDK","main": "dist/index.js","types": "dist/index.d.ts",diff --git a/js/packages/react-ui/src/components/CheckBoxGroup/stories/CheckBoxGroup.stories.tsx b/js/packages/react-ui/src/components/CheckBoxGroup/stories/CheckBoxGroup.stories.tsxindex 582d8fe61..16b298be9 100644--- a/js/packages/react-ui/src/components/CheckBoxGroup/stories/CheckBoxGroup.stories.tsx+++ b/js/packages/react-ui/src/components/CheckBoxGroup/stories/CheckBoxGroup.stories.tsx@@ -72,9 +72,9 @@ export const ClearVariant: Story = {args: {variant: "card",children: [- <CheckBoxItem key="1" label="Option 1" />,- <CheckBoxItem key="2" label="Option 2" />,- <CheckBoxItem key="3" label="Option 3" />,+ <CheckBoxItem key="1" label="Option 1" description="This is a description" />,+ <CheckBoxItem key="2" label="Option 2" description="This is a description" />,+ <CheckBoxItem key="3" label="Option 3" description="This is a description" />,],},};diff --git a/js/packages/react-ui/src/components/CheckBoxItem/CheckBoxItem.tsx b/js/packages/react-ui/src/components/CheckBoxItem/CheckBoxItem.tsxindex 46c38a81a..56adadfef 100644--- a/js/packages/react-ui/src/components/CheckBoxItem/CheckBoxItem.tsx+++ b/js/packages/react-ui/src/components/CheckBoxItem/CheckBoxItem.tsx@@ -5,6 +5,7 @@ import { useId } from "../../polyfills";export interface CheckBoxItemProps {label?: ReactNode;+ description?: ReactNode;className?: string;style?: CSSProperties;checked?: boolean;@@ -17,7 +18,7 @@ export interface CheckBoxItemProps {}const CheckBoxItem = forwardRef<HTMLButtonElement, CheckBoxItemProps>((props, ref) => {- const { label, onChange, className, disabled, required, ...rest } = props;+ const { label, description, onChange, className, disabled, required, ...rest } = props;const id = useId();return (<div className="crayon-checkbox-item-container">@@ -48,11 +49,14 @@ const CheckBoxItem = forwardRef<HTMLButtonElement, CheckBoxItemProps>((props, re</svg></Checkbox.Indicator></Checkbox.Root>- {label && (- <label htmlFor={id} className="crayon-checkbox-item-label">- {label}- </label>- )}+ <div className="crayon-checkbox-item-content">+ {label && (+ <label htmlFor={id} className="crayon-checkbox-item-label">+ {label}+ </label>+ )}+ {description && <p className="crayon-checkbox-item-description">{description}</p>}+ </div></div>);});diff --git a/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss b/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scssindex 8edd42cc7..ff8767eed 100644--- a/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss+++ b/js/packages/react-ui/src/components/CheckBoxItem/checkBoxItem.scss@@ -2,7 +2,7 @@.crayon-checkbox-item-container {display: flex;- align-items: center;+ align-items: flex-start;gap: cssUtils.$spacing-s;padding: cssUtils.$spacing-3xs cssUtils.$spacing-0;width: 100%;@@ -19,6 +19,7 @@border-radius: cssUtils.$rounded-xs;border: 1px solid cssUtils.$stroke-interactive-el;cursor: pointer;+ margin-top: cssUtils.$spacing-2xs;&[data-state="checked"] {background-color: cssUtils.$interactive-accent;@@ -44,6 +45,11 @@color: cssUtils.$accent-primary-text;}+.crayon-checkbox-item-content {+ display: flex;+ flex-direction: column;+}+.crayon-checkbox-item-label {flex: 1;@include cssUtils.typography(primary, default);@@ -52,3 +58,8 @@color: cssUtils.$disabled-text;}}++.crayon-checkbox-item-description {+ @include cssUtils.typography(body, default);+ color: cssUtils.$secondary-text;+}diff --git a/js/packages/react-ui/src/components/CheckBoxItem/stories/CheckBoxItem.stories.tsx b/js/packages/react-ui/src/components/CheckBoxItem/stories/CheckBoxItem.stories.tsxindex 21d8f7559..7761acb3b 100644--- a/js/packages/react-ui/src/components/CheckBoxItem/stories/CheckBoxItem.stories.tsx+++ b/js/packages/react-ui/src/components/CheckBoxItem/stories/CheckBoxItem.stories.tsx@@ -23,6 +23,16 @@ const meta: Meta<typeof CheckBoxItem> = {},},},+ description: {+ control: "text",+ defaultValue: "This is a description",+ description: "The description of the checkbox",+ table: {+ type: {+ summary: "string",+ },+ },+ },checked: {control: "boolean",description: "State of the checkbox, used for controlled mode",@@ -115,6 +125,7 @@ type Story = StoryObj<typeof CheckBoxItem>;export const Default: Story = {args: {label: "Default Checkbox",+ description: "This is a description",onChange: (checked) => console.log("Checkbox changed:", checked),},};diff --git a/js/packages/react-ui/src/components/FormControl/stories/FormControl.stories.tsx b/js/packages/react-ui/src/components/FormControl/stories/FormControl.stories.tsxindex f9521b438..bc7f4c6be 100644--- a/js/packages/react-ui/src/components/FormControl/stories/FormControl.stories.tsx+++ b/js/packages/react-ui/src/components/FormControl/stories/FormControl.stories.tsx@@ -62,7 +62,9 @@ type Story = StoryObj<typeof FormControl>;export const WithLabelAndHint: Story = {render: (args) => (<FormControl>- <Label htmlFor="username">Username</Label>+ <Label htmlFor="username" required>+ Username+ </Label><Input placeholder="Enter username" id="username" /><Hint><Info size={14} />diff --git a/js/packages/react-ui/src/components/Label/label.scss b/js/packages/react-ui/src/components/Label/label.scssindex 5f13d6776..96dd0ebd6 100644--- a/js/packages/react-ui/src/components/Label/label.scss+++ b/js/packages/react-ui/src/components/Label/label.scss@@ -10,3 +10,7 @@cursor: not-allowed;}}++.crayon-label-required-asterisk {+ margin-left: cssUtils.$spacing-3xs;+}diff --git a/js/packages/react-ui/src/components/RadioGroup/stories/RadioGroup.stories.tsx b/js/packages/react-ui/src/components/RadioGroup/stories/RadioGroup.stories.tsxindex a669866a2..c899bd510 100644--- a/js/packages/react-ui/src/components/RadioGroup/stories/RadioGroup.stories.tsx+++ b/js/packages/react-ui/src/components/RadioGroup/stories/RadioGroup.stories.tsx@@ -62,9 +62,9 @@ export const Default: Story = {},render: (args) => (<RadioGroup {...args}>- <RadioItem value="option1" label="Option 1" />- <RadioItem value="option2" label="Option 2" />- <RadioItem value="option3" label="Option 3" />+ <RadioItem value="option1" label="Option 1" description="Option 1 description" />+ <RadioItem value="option2" label="Option 2" description="Option 2 description" />+ <RadioItem value="option3" label="Option 3" description="Option 3 description" /></RadioGroup>),};diff --git a/js/packages/react-ui/src/components/RadioItem/RadioItem.tsx b/js/packages/react-ui/src/components/RadioItem/RadioItem.tsxindex 1066d1ece..83e58d73d 100644--- a/js/packages/react-ui/src/components/RadioItem/RadioItem.tsx+++ b/js/packages/react-ui/src/components/RadioItem/RadioItem.tsx@@ -5,6 +5,7 @@ import { useId } from "../../polyfills";export interface RadioItemProps {label?: ReactNode;+ description?: ReactNode;className?: string;style?: CSSProperties;disabled?: boolean;@@ -13,7 +14,7 @@ export interface RadioItemProps {}const RadioItem = forwardRef<HTMLButtonElement, RadioItemProps>((props, ref) => {- const { label, className, style, disabled, required, value } = props;+ const { label, description, className, style, disabled, required, value } = props;const id = useId();return (<div className="crayon-radio-item-container">@@ -50,11 +51,14 @@ const RadioItem = forwardRef<HTMLButtonElement, RadioItemProps>((props, ref) =>/></svg></Radio.Item>- {label && (- <label htmlFor={id} className="crayon-radio-item-label">- {label}- </label>- )}+ <div className="crayon-radio-item-content">+ {label && (+ <label htmlFor={id} className="crayon-radio-item-label">+ {label}+ </label>+ )}+ {description && <p className="crayon-radio-item-description">{description}</p>}+ </div></div>);});diff --git a/js/packages/react-ui/src/components/RadioItem/radioItem.scss b/js/packages/react-ui/src/components/RadioItem/radioItem.scssindex 6dfc4b77a..107459387 100644--- a/js/packages/react-ui/src/components/RadioItem/radioItem.scss+++ b/js/packages/react-ui/src/components/RadioItem/radioItem.scss@@ -2,7 +2,7 @@.crayon-radio-item-container {display: flex;- align-items: center;+ align-items: flex-start;gap: cssUtils.$spacing-s;padding: cssUtils.$spacing-3xs cssUtils.$spacing-0;width: 100%;@@ -18,6 +18,7 @@width: 16px;cursor: pointer;background-color: transparent;+ margin-top: cssUtils.$spacing-2xs;&[data-state] {// This makes the root element a styling context for children@@ -86,3 +87,8 @@color: cssUtils.$disabled-text;}}++.crayon-radio-item-description {+ @include cssUtils.typography(body, default);+ color: cssUtils.$secondary-text;+}diff --git a/js/packages/react-ui/src/components/RadioItem/stories/RadioItem.stories.tsx b/js/packages/react-ui/src/components/RadioItem/stories/RadioItem.stories.tsxindex 280eb80ef..8d30acfda 100644--- a/js/packages/react-ui/src/components/RadioItem/stories/RadioItem.stories.tsx+++ b/js/packages/react-ui/src/components/RadioItem/stories/RadioItem.stories.tsx@@ -32,6 +32,14 @@ const meta: Meta<typeof RadioItem> = {type: { summary: "string" },},},+ description: {+ control: "text",+ description: "The description of the radio item",+ table: {+ category: "Content",+ type: { summary: "string" },+ },+ },required: {control: "boolean",description: "Whether the radio item is required",@@ -79,6 +87,7 @@ export const Default: Story = {args: {value: "default",label: "Default",+ description: "Default description",required: false,disabled: false,},diff --git a/js/packages/react-ui/src/components/Slider/slider.scss b/js/packages/react-ui/src/components/Slider/slider.scssindex 3d9d773fb..3386dc0ab 100644--- a/js/packages/react-ui/src/components/Slider/slider.scss+++ b/js/packages/react-ui/src/components/Slider/slider.scss@@ -113,6 +113,8 @@box-shadow: cssUtils.$shadow-m;opacity: 0;transition: opacity 0.2s;+ border: 1px solid cssUtils.$stroke-interactive-el;+ box-shadow: cssUtils.$shadow-s;.slider-thumb-handle:hover &,.slider-thumb-handle:focus & {diff --git a/js/packages/react-ui/src/components/SwitchGroup/stories/SwitchGroup.stories.tsx b/js/packages/react-ui/src/components/SwitchGroup/stories/SwitchGroup.stories.tsxindex 50eb4c8a3..cc70ef903 100644--- a/js/packages/react-ui/src/components/SwitchGroup/stories/SwitchGroup.stories.tsx+++ b/js/packages/react-ui/src/components/SwitchGroup/stories/SwitchGroup.stories.tsx@@ -63,9 +63,9 @@ export const SwitchGroupStory: Story = {},render: (args) => (<SwitchGroup {...args}>- <SwitchItem value="option1" label="Option 1" />- <SwitchItem value="option2" label="Option 2" />- <SwitchItem value="option3" label="Option 3" />+ <SwitchItem value="option1" label="Option 1" description="Option 1 description" />+ <SwitchItem value="option2" label="Option 2" description="Option 2 description" />+ <SwitchItem value="option3" label="Option 3" description="Option 3 description" /></SwitchGroup>),};diff --git a/js/packages/react-ui/src/components/SwitchItem/SwitchItem.tsx b/js/packages/react-ui/src/components/SwitchItem/SwitchItem.tsxindex f82b32cf2..161f6eb5a 100644--- a/js/packages/react-ui/src/components/SwitchItem/SwitchItem.tsx+++ b/js/packages/react-ui/src/components/SwitchItem/SwitchItem.tsx@@ -5,6 +5,7 @@ import { useId } from "../../polyfills";interface SwitchItemProps {label?: ReactNode;+ description?: ReactNode;className?: string;style?: CSSProperties;checked?: boolean;@@ -17,7 +18,7 @@ interface SwitchItemProps {}const SwitchItem = forwardRef<HTMLButtonElement, SwitchItemProps>((props, ref) => {- const { label, onChange, className, disabled, required, ...rest } = props;+ const { label, description, onChange, className, disabled, required, ...rest } = props;const id = useId();return (<div className="crayon-switch-item-container">@@ -32,11 +33,14 @@ const SwitchItem = forwardRef<HTMLButtonElement, SwitchItemProps>((props, ref) =><Switch.Thumb className="crayon-switch-item-thumb" /></Switch.Root>- {label && (- <label htmlFor={id} className="crayon-switch-item-label">- {label}- </label>- )}+ <div className="crayon-switch-item-content">+ {label && (+ <label htmlFor={id} className="crayon-switch-item-label">+ {label}+ </label>+ )}+ {description && <p className="crayon-switch-item-description">{description}</p>}+ </div></div>);});diff --git a/js/packages/react-ui/src/components/SwitchItem/stories/SwitchItem.stories.tsx b/js/packages/react-ui/src/components/SwitchItem/stories/SwitchItem.stories.tsxindex 74fa3c962..3e92d67d9 100644--- a/js/packages/react-ui/src/components/SwitchItem/stories/SwitchItem.stories.tsx+++ b/js/packages/react-ui/src/components/SwitchItem/stories/SwitchItem.stories.tsx@@ -17,6 +17,14 @@ const meta = {type: { summary: "string" },},},+ description: {+ control: "text",+ description: "The description of the switch item",+ table: {+ category: "Content",+ type: { summary: "string" },+ },+ },disabled: {control: "boolean",description: "Whether the switch item is disabled",diff --git a/js/packages/react-ui/src/components/SwitchItem/switchItem.scss b/js/packages/react-ui/src/components/SwitchItem/switchItem.scssindex f08dc05ce..b5f2d5e6d 100644--- a/js/packages/react-ui/src/components/SwitchItem/switchItem.scss+++ b/js/packages/react-ui/src/components/SwitchItem/switchItem.scss@@ -3,7 +3,7 @@.crayon-switch-item-container {box-sizing: border-box;display: flex;- align-items: center;+ align-items: flex-start;gap: cssUtils.$spacing-s;max-width: 100%;width: 100%;@@ -16,6 +16,7 @@display: inline-block;height: 16px;width: 24px;+ margin-top: cssUtils.$spacing-2xs;cursor: pointer;border-radius: cssUtils.$rounded-full;padding: cssUtils.$spacing-3xs;@@ -68,3 +69,8 @@color: cssUtils.$disabled-text;}}++.crayon-switch-item-description {+ @include cssUtils.typography(body, default);+ color: cssUtils.$secondary-text;+}