-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: refactor Label with useRender; reuse in Field.Label #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32f160b
3b01c1d
a5da2bc
f37ccc4
0502561
6e758ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,27 @@ | ||
| 'use client'; | ||
|
|
||
| import { Flex, Radio } from '@raystack/apsara'; | ||
| import { Flex, Label, Radio } from '@raystack/apsara'; | ||
| import PlaygroundLayout from './playground-layout'; | ||
|
|
||
| export function RadioExamples() { | ||
| return ( | ||
| <PlaygroundLayout title='Radio'> | ||
| <Radio defaultValue='2'> | ||
| <Radio.Group defaultValue='2'> | ||
| <Flex gap='large'> | ||
| <Flex gap='small' align='center'> | ||
| <Radio.Item value='1' id='P1' /> | ||
| <label htmlFor='P1'>Option One</label> | ||
| <Radio value='1' id='P1' /> | ||
| <Label htmlFor='P1'>Option One</Label> | ||
| </Flex> | ||
| <Flex gap='small' align='center'> | ||
| <Radio.Item value='2' id='P2' /> | ||
| <label htmlFor='P2'>Option Two</label> | ||
| <Radio value='2' id='P2' /> | ||
| <Label htmlFor='P2'>Option Two</Label> | ||
| </Flex> | ||
| <Flex gap='small' align='center'> | ||
| <Radio.Item value='3' id='P3' disabled /> | ||
| <label htmlFor='P3'>Option Three</label> | ||
| <Radio value='3' id='P3' disabled /> | ||
| <Label htmlFor='P3'>Option Three</Label> | ||
|
rohanchkrabrty marked this conversation as resolved.
|
||
| </Flex> | ||
| </Flex> | ||
| </Radio> | ||
| </Radio.Group> | ||
| </PlaygroundLayout> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ description: A text label component that provides names for form controls. | |||||
| source: packages/raystack/components/label | ||||||
| --- | ||||||
|
|
||||||
| import { playground, requiredDemo, sizeDemo } from "./demo.ts"; | ||||||
| import { inlineDemo, optionalDemo, playground } from "./demo.ts"; | ||||||
|
|
||||||
| <Demo data={playground} /> | ||||||
|
|
||||||
|
|
@@ -15,35 +15,38 @@ Import and assemble the component: | |||||
| ```tsx | ||||||
| import { Label } from '@raystack/apsara' | ||||||
|
|
||||||
| <Label /> | ||||||
| <Label htmlFor="email">Email</Label> | ||||||
| ``` | ||||||
|
|
||||||
| ## API Reference | ||||||
|
|
||||||
| Renders a text label for form elements. | ||||||
| Renders a text label for form elements. Outside of a `Field`, use `Label` to | ||||||
| attach a label to a control via `htmlFor`. Inside a `Field`, prefer | ||||||
| `Field.Label` so the label is wired up to the field automatically. | ||||||
|
|
||||||
| `Label` is layout-neutral — compose it with `Flex` (or wrap a control as a | ||||||
| child) to lay out the label and its control. | ||||||
|
|
||||||
| <auto-type-table path="./props.ts" name="LabelProps" /> | ||||||
|
|
||||||
| ## Examples | ||||||
|
|
||||||
| ### Size | ||||||
| ### Inline with a control | ||||||
|
|
||||||
| Labels have 3 different sizes. | ||||||
| Use `Flex` to place a label next to a Radio or Checkbox. | ||||||
|
|
||||||
| <Demo data={sizeDemo} /> | ||||||
| <Demo data={inlineDemo} /> | ||||||
|
|
||||||
| ### Required | ||||||
| ### Optional indicator | ||||||
|
|
||||||
| Labels can indicate required fields with either a default asterisk or custom text. | ||||||
| Pass `required={false}` to display an `(optional)` indicator next to the label. | ||||||
| Override the text via `optionalText`. | ||||||
|
|
||||||
| <Demo data={requiredDemo} /> | ||||||
| <Demo data={optionalDemo} /> | ||||||
|
|
||||||
| ## Accessibility | ||||||
|
|
||||||
| The Label component is designed with accessibility in mind: | ||||||
|
|
||||||
| - Uses semantic HTML `<label>` element | ||||||
| - Renders a semantic HTML `<label>` element by default | ||||||
| - Supports programmatic association with form controls via `htmlFor` | ||||||
| - Required indicators are properly hidden from screen readers | ||||||
| - Maintains WCAG compliant color contrast ratios | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphenate “WCAG-compliant” in the accessibility bullet. Line 51 should use the compound adjective form for correct docs grammar. Suggested patch-- Maintains WCAG compliant color contrast ratios
+- Maintains WCAG-compliant color contrast ratios📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~51-~51: Use a hyphen to join words. (QB_NEW_EN_HYPHEN) 🤖 Prompt for AI Agents |
||||||
| - Supports keyboard navigation when used with form controls | ||||||
| - Shows a pointer cursor when associated with a control via `htmlFor` | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,25 @@ | ||
| export interface LabelProps { | ||
| /** | ||
| * Controls the size of the label. | ||
| * @default "small" | ||
| * Whether the labelled control is required. When `false`, an optional | ||
| * indicator (see `optionalText`) is rendered next to the label. | ||
| */ | ||
| size?: 'small' | 'medium' | 'large'; | ||
|
|
||
| /** When true, shows a required field indicator. */ | ||
| required?: boolean; | ||
|
|
||
| /** | ||
| * Customizes the required field indicator. | ||
| * @default "*" | ||
| * Text rendered next to the label when `required={false}`. | ||
| * @defaultValue "(optional)" | ||
| */ | ||
| requiredIndicator?: string; | ||
| optionalText?: string; | ||
|
|
||
| /** Associates the label with a form control using its ID. */ | ||
| htmlFor?: string; | ||
|
|
||
| /** | ||
| * A React element to override the default rendered element. Allows polymorphic | ||
| * rendering while preserving label semantics, classes, and ref forwarding. | ||
| */ | ||
| render?: React.ReactElement; | ||
|
|
||
| /** Additional CSS class names. */ | ||
| className?: string; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.