@dev-dga/react 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as class_variance_authority_types from 'class-variance-authority/types';
3
3
  import { ReactNode } from 'react';
4
4
  import { VariantProps } from 'class-variance-authority';
5
- import { Checkbox as Checkbox$1 } from 'radix-ui';
5
+ import { Checkbox as Checkbox$1, RadioGroup as RadioGroup$1, Switch as Switch$1, Select as Select$1 } from 'radix-ui';
6
+ import { DgaTheme } from '@dev-dga/tokens';
7
+ export { DgaTheme, PaletteName, ThemeColor } from '@dev-dga/tokens';
6
8
  import { ClassValue } from 'clsx';
7
9
 
8
10
  declare const buttonVariants: (props?: ({
@@ -16,8 +18,24 @@ interface ButtonProps extends React.ComponentProps<'button'>, VariantProps<typeo
16
18
  endIcon?: ReactNode;
17
19
  /** Flip start/end icons horizontally in RTL (for chevrons, arrows, etc.) */
18
20
  iconFlip?: boolean;
21
+ /**
22
+ * Render as the single child element instead of a `<button>`. Lets consumers
23
+ * compose Button with router links (`<Button asChild><Link href="…">…</Link></Button>`)
24
+ * without `<button><a>` invalid nesting.
25
+ *
26
+ * The `type` and native `disabled` attributes are dropped in this mode
27
+ * (they're meaningless on non-button elements) , the disabled visual + a11y
28
+ * state still works via `aria-disabled` + `tabIndex={-1}`. button.css
29
+ * matches on `[aria-disabled='true']` alongside `:disabled` so the styling
30
+ * applies on any element.
31
+ *
32
+ * Consumer remains responsible for preventing the underlying action when
33
+ * disabled (e.g., calling `e.preventDefault()` in the Link's onClick),
34
+ * since native `disabled` doesn't gate clicks on non-form-controls.
35
+ */
36
+ asChild?: boolean;
19
37
  }
20
- declare function Button({ variant, size, fullWidth, loading, disabled, startIcon, endIcon, iconFlip, className, children, type, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
38
+ declare function Button({ variant, size, fullWidth, loading, disabled, startIcon, endIcon, iconFlip, asChild, className, children, type, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
21
39
 
22
40
  declare const inputVariants: (props?: ({
23
41
  size?: "sm" | "md" | "lg" | null | undefined;
@@ -80,23 +98,115 @@ interface CheckboxProps extends Omit<React.ComponentProps<typeof Checkbox$1.Root
80
98
  }
81
99
  declare function Checkbox({ id: externalId, label, helperText, errorMessage, error, size, required, className, ...props }: CheckboxProps): react_jsx_runtime.JSX.Element;
82
100
 
101
+ declare const radioGroupVariants: (props?: ({
102
+ size?: "sm" | "md" | null | undefined;
103
+ orientation?: "horizontal" | "vertical" | null | undefined;
104
+ error?: boolean | null | undefined;
105
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
106
+ declare const radioVariants: (props?: class_variance_authority_types.ClassProp | undefined) => string;
107
+ interface RadioGroupProps extends Omit<React.ComponentProps<typeof RadioGroup$1.Root>, 'children' | 'orientation'>, Pick<VariantProps<typeof radioGroupVariants>, 'size' | 'orientation'> {
108
+ /** Group label, sits above the rows. Associated to the group via aria-labelledby. */
109
+ label?: ReactNode;
110
+ /** Hint shown below the group. Hidden while an error message is showing. */
111
+ helperText?: ReactNode;
112
+ /** Message shown below the group when `error` is true (or when only `errorMessage` is set). */
113
+ errorMessage?: ReactNode;
114
+ /** Marks the group invalid: sets aria-invalid and applies error styling. */
115
+ error?: boolean;
116
+ /** `<Radio>` children. */
117
+ children: ReactNode;
118
+ }
119
+ interface RadioProps extends Omit<React.ComponentProps<typeof RadioGroup$1.Item>, 'children'> {
120
+ /** Visible label for this radio, sits beside the circle, associated via htmlFor/id. */
121
+ label?: ReactNode;
122
+ }
123
+ declare function RadioGroup({ id: externalId, label, helperText, errorMessage, error, size, orientation, required, className, children, ...props }: RadioGroupProps): react_jsx_runtime.JSX.Element;
124
+ declare function Radio({ id: externalId, label, className, ...props }: RadioProps): react_jsx_runtime.JSX.Element;
125
+
126
+ declare const switchVariants: (props?: ({
127
+ size?: "sm" | "md" | null | undefined;
128
+ error?: boolean | null | undefined;
129
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
130
+ interface SwitchProps extends Omit<React.ComponentProps<typeof Switch$1.Root>, 'children'>, VariantProps<typeof switchVariants> {
131
+ /** Visible label, sits beside the track, associated via `htmlFor`/`id`. */
132
+ label?: ReactNode;
133
+ /** Hint shown below the row. Hidden while an error message is showing. */
134
+ helperText?: ReactNode;
135
+ /** Message shown below the row when `error` is true. */
136
+ errorMessage?: ReactNode;
137
+ /** Marks the field invalid: sets `aria-invalid` and error styling. */
138
+ error?: boolean;
139
+ }
140
+ declare function Switch({ id: externalId, label, helperText, errorMessage, error, size, required, className, ...props }: SwitchProps): react_jsx_runtime.JSX.Element;
141
+
142
+ declare const selectTriggerVariants: (props?: ({
143
+ size?: "sm" | "md" | null | undefined;
144
+ error?: boolean | null | undefined;
145
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
146
+ interface SelectProps extends Omit<React.ComponentProps<typeof Select$1.Root>, 'children' | 'dir'>, VariantProps<typeof selectTriggerVariants> {
147
+ /** Visible label above the trigger, associated via `htmlFor`/`id`. */
148
+ label?: ReactNode;
149
+ /** Hint shown below the trigger. Hidden while an error message is showing. */
150
+ helperText?: ReactNode;
151
+ /** Message shown below the trigger when `error` is true. */
152
+ errorMessage?: ReactNode;
153
+ /** Marks the field invalid: sets `aria-invalid` and error styling. */
154
+ error?: boolean;
155
+ /** Placeholder shown in the trigger when no value is selected. */
156
+ placeholder?: ReactNode;
157
+ /** `<SelectItem>` children, rendered inside the dropdown panel. */
158
+ children: ReactNode;
159
+ /** Caller-supplied id for the trigger; falls back to a generated one. */
160
+ id?: string;
161
+ /** Forwarded to the trigger (the focusable control). */
162
+ className?: string;
163
+ 'aria-label'?: string;
164
+ 'aria-labelledby'?: string;
165
+ }
166
+ interface SelectItemProps extends React.ComponentProps<typeof Select$1.Item> {
167
+ /** The visible label for this item. */
168
+ children: ReactNode;
169
+ }
170
+ declare function Select({ id: externalId, label, helperText, errorMessage, error, size, required, placeholder, className, children, ...rootProps }: SelectProps): react_jsx_runtime.JSX.Element;
171
+ declare function SelectItem({ className, children, ...props }: SelectItemProps): react_jsx_runtime.JSX.Element;
172
+
83
173
  type DgaRootElement = 'div' | 'main' | 'nav' | 'section' | 'article' | 'aside' | 'header' | 'footer';
84
174
  interface DgaProviderProps {
85
175
  dir?: 'ltr' | 'rtl';
86
176
  locale?: string;
87
177
  mode?: 'light' | 'dark';
178
+ /**
179
+ * Brand theme. `theme.primary` accepts a palette name (`'lavender'`),
180
+ * any CSS color string (`'#7C3AED'` , hover/active auto-derived via
181
+ * `color-mix()`), or an explicit `{ base, hover, active, foreground? }`
182
+ * triplet. The override-object pattern (`style={{ '--ddga-color-primary':
183
+ * '...' }}`) still works , `style` wins over `theme`.
184
+ */
185
+ theme?: DgaTheme;
88
186
  as?: DgaRootElement;
89
187
  className?: string;
90
188
  style?: React.CSSProperties;
91
189
  children: React.ReactNode;
92
190
  }
93
- declare function DgaProvider({ dir, locale, mode, as: Component, className, style: consumerStyle, children, }: DgaProviderProps): react_jsx_runtime.JSX.Element;
191
+ declare function DgaProvider({ dir, locale, mode, theme, as: Component, className, style: consumerStyle, children, }: DgaProviderProps): react_jsx_runtime.JSX.Element;
94
192
 
95
193
  interface DgaContextValue {
96
194
  dir: 'ltr' | 'rtl';
97
195
  locale: string;
98
196
  mode: 'light' | 'dark';
99
- rootRef: React.RefObject<HTMLElement | null>;
197
+ /**
198
+ * The DgaProvider root element. Portal-rendering components (Select, and
199
+ * future Tooltip / Modal / Toast / Popover / DropdownMenu) MUST pass this
200
+ * as their Radix `Portal container={…}` so that `data-theme`, custom
201
+ * theme vars, and `.ddga-theme-*` classes set on the root inherit into
202
+ * the portaled content. Without it, portals mount under <body> and
203
+ * silently miss dark mode + custom themes.
204
+ *
205
+ * Exposed as state (not a ref) so consumers re-render once the element
206
+ * mounts , a useRef wouldn't fire that update and the portal would
207
+ * race to <body> on the first commit.
208
+ */
209
+ rootEl: HTMLElement | null;
100
210
  }
101
211
  declare function useDga(): DgaContextValue;
102
212
 
@@ -110,6 +220,43 @@ declare function useDga(): DgaContextValue;
110
220
  */
111
221
  declare function useDir(): 'ltr' | 'rtl';
112
222
 
223
+ interface UseFieldA11yOptions {
224
+ /** Component name used in the dev warning, e.g. `'Input'`. */
225
+ name: string;
226
+ /** Caller-supplied id; falls back to a stable generated one. */
227
+ id?: string;
228
+ label?: ReactNode;
229
+ error?: boolean;
230
+ errorMessage?: ReactNode;
231
+ helperText?: ReactNode;
232
+ /** From the consumer's props , used to suppress the no-label warning. */
233
+ 'aria-label'?: string;
234
+ 'aria-labelledby'?: string;
235
+ }
236
+ interface FieldA11y {
237
+ fieldId: string;
238
+ helperId: string;
239
+ errorId: string;
240
+ hasError: boolean;
241
+ hasErrorMessage: boolean;
242
+ hasHelper: boolean;
243
+ /** Spread onto the control element (input / textarea / Radix root). */
244
+ controlProps: {
245
+ id: string;
246
+ 'aria-invalid': true | undefined;
247
+ 'aria-describedby': string | undefined;
248
+ };
249
+ }
250
+ declare function useFieldA11y(options: UseFieldA11yOptions): FieldA11y;
251
+
252
+ interface FieldMessageProps {
253
+ id: string;
254
+ /** `error` announces politely; `helper` is static. */
255
+ variant: 'error' | 'helper';
256
+ children: ReactNode;
257
+ }
258
+ declare function FieldMessage({ id, variant, children }: FieldMessageProps): react_jsx_runtime.JSX.Element;
259
+
113
260
  declare function cn(...inputs: ClassValue[]): string;
114
261
 
115
- export { Button, type ButtonProps, Checkbox, type CheckboxProps, DgaProvider, type DgaProviderProps, Input, type InputProps, Textarea, type TextareaProps, buttonVariants, checkboxVariants, cn, inputVariants, textareaVariants, useDga, useDir };
262
+ export { Button, type ButtonProps, Checkbox, type CheckboxProps, DgaProvider, type DgaProviderProps, type FieldA11y, FieldMessage, type FieldMessageProps, Input, type InputProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, Select, SelectItem, type SelectItemProps, type SelectProps, Switch, type SwitchProps, Textarea, type TextareaProps, type UseFieldA11yOptions, buttonVariants, checkboxVariants, cn, inputVariants, radioGroupVariants, radioVariants, selectTriggerVariants, switchVariants, textareaVariants, useDga, useDir, useFieldA11y };