@dev-dga/react 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +520 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +483 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { Checkbox as Checkbox$1 } from 'radix-ui';
|
|
6
|
+
import { ClassValue } from 'clsx';
|
|
7
|
+
|
|
8
|
+
declare const buttonVariants: (props?: ({
|
|
9
|
+
variant?: "primary" | "secondary" | "outline" | "ghost" | "destructive" | null | undefined;
|
|
10
|
+
size?: "sm" | "md" | "lg" | "icon" | "icon-sm" | null | undefined;
|
|
11
|
+
fullWidth?: boolean | null | undefined;
|
|
12
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
13
|
+
interface ButtonProps extends React.ComponentProps<'button'>, VariantProps<typeof buttonVariants> {
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
startIcon?: ReactNode;
|
|
16
|
+
endIcon?: ReactNode;
|
|
17
|
+
/** Flip start/end icons horizontally in RTL (for chevrons, arrows, etc.) */
|
|
18
|
+
iconFlip?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function Button({ variant, size, fullWidth, loading, disabled, startIcon, endIcon, iconFlip, className, children, type, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
declare const inputVariants: (props?: ({
|
|
23
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
24
|
+
error?: boolean | null | undefined;
|
|
25
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
26
|
+
interface InputProps extends Omit<React.ComponentProps<'input'>, 'size'>, VariantProps<typeof inputVariants> {
|
|
27
|
+
/** Visible field label, auto-associated to the input via `htmlFor`/`id`. */
|
|
28
|
+
label?: ReactNode;
|
|
29
|
+
/** Hint shown below the field. Hidden while an error message is showing. */
|
|
30
|
+
helperText?: ReactNode;
|
|
31
|
+
/** Message shown below the field when `error` is true. */
|
|
32
|
+
errorMessage?: ReactNode;
|
|
33
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
34
|
+
error?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Content rendered inside the field, before the input (icon or short text,
|
|
37
|
+
* e.g. a search glyph or `https://`). May be interactive — it is NOT
|
|
38
|
+
* `aria-hidden`. Mark purely-decorative icons `aria-hidden` yourself.
|
|
39
|
+
*/
|
|
40
|
+
startAdornment?: ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Content rendered inside the field, after the input. Compose a clear
|
|
43
|
+
* button or password-reveal toggle here with `<Button size="icon-sm">`
|
|
44
|
+
* — the 28px in-field icon size that fits the field without overflow.
|
|
45
|
+
*/
|
|
46
|
+
endAdornment?: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
declare function Input({ id: externalId, label, helperText, errorMessage, error, size, required, startAdornment, endAdornment, className, ...props }: InputProps): react_jsx_runtime.JSX.Element;
|
|
49
|
+
|
|
50
|
+
declare const textareaVariants: (props?: ({
|
|
51
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
52
|
+
error?: boolean | null | undefined;
|
|
53
|
+
resize?: "none" | "vertical" | null | undefined;
|
|
54
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
55
|
+
interface TextareaProps extends React.ComponentProps<'textarea'>, VariantProps<typeof textareaVariants> {
|
|
56
|
+
/** Visible field label, auto-associated to the textarea via `htmlFor`/`id`. */
|
|
57
|
+
label?: ReactNode;
|
|
58
|
+
/** Hint shown below the field. Hidden while an error message is showing. */
|
|
59
|
+
helperText?: ReactNode;
|
|
60
|
+
/** Message shown below the field when `error` is true. */
|
|
61
|
+
errorMessage?: ReactNode;
|
|
62
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
63
|
+
error?: boolean;
|
|
64
|
+
}
|
|
65
|
+
declare function Textarea({ id: externalId, label, helperText, errorMessage, error, size, resize, required, rows, className, ...props }: TextareaProps): react_jsx_runtime.JSX.Element;
|
|
66
|
+
|
|
67
|
+
declare const checkboxVariants: (props?: ({
|
|
68
|
+
size?: "sm" | "md" | null | undefined;
|
|
69
|
+
error?: boolean | null | undefined;
|
|
70
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
71
|
+
interface CheckboxProps extends Omit<React.ComponentProps<typeof Checkbox$1.Root>, 'children'>, VariantProps<typeof checkboxVariants> {
|
|
72
|
+
/** Visible label, sits beside the box, associated via `htmlFor`/`id`. */
|
|
73
|
+
label?: ReactNode;
|
|
74
|
+
/** Hint shown below the row. Hidden while an error message is showing. */
|
|
75
|
+
helperText?: ReactNode;
|
|
76
|
+
/** Message shown below the row when `error` is true. */
|
|
77
|
+
errorMessage?: ReactNode;
|
|
78
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
79
|
+
error?: boolean;
|
|
80
|
+
}
|
|
81
|
+
declare function Checkbox({ id: externalId, label, helperText, errorMessage, error, size, required, className, ...props }: CheckboxProps): react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
type DgaRootElement = 'div' | 'main' | 'nav' | 'section' | 'article' | 'aside' | 'header' | 'footer';
|
|
84
|
+
interface DgaProviderProps {
|
|
85
|
+
dir?: 'ltr' | 'rtl';
|
|
86
|
+
locale?: string;
|
|
87
|
+
mode?: 'light' | 'dark';
|
|
88
|
+
as?: DgaRootElement;
|
|
89
|
+
className?: string;
|
|
90
|
+
style?: React.CSSProperties;
|
|
91
|
+
children: React.ReactNode;
|
|
92
|
+
}
|
|
93
|
+
declare function DgaProvider({ dir, locale, mode, as: Component, className, style: consumerStyle, children, }: DgaProviderProps): react_jsx_runtime.JSX.Element;
|
|
94
|
+
|
|
95
|
+
interface DgaContextValue {
|
|
96
|
+
dir: 'ltr' | 'rtl';
|
|
97
|
+
locale: string;
|
|
98
|
+
mode: 'light' | 'dark';
|
|
99
|
+
rootRef: React.RefObject<HTMLElement | null>;
|
|
100
|
+
}
|
|
101
|
+
declare function useDga(): DgaContextValue;
|
|
102
|
+
|
|
103
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
104
|
+
|
|
105
|
+
export { Button, type ButtonProps, Checkbox, type CheckboxProps, DgaProvider, type DgaProviderProps, Input, type InputProps, Textarea, type TextareaProps, buttonVariants, checkboxVariants, cn, inputVariants, textareaVariants, useDga };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { Checkbox as Checkbox$1 } from 'radix-ui';
|
|
6
|
+
import { ClassValue } from 'clsx';
|
|
7
|
+
|
|
8
|
+
declare const buttonVariants: (props?: ({
|
|
9
|
+
variant?: "primary" | "secondary" | "outline" | "ghost" | "destructive" | null | undefined;
|
|
10
|
+
size?: "sm" | "md" | "lg" | "icon" | "icon-sm" | null | undefined;
|
|
11
|
+
fullWidth?: boolean | null | undefined;
|
|
12
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
13
|
+
interface ButtonProps extends React.ComponentProps<'button'>, VariantProps<typeof buttonVariants> {
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
startIcon?: ReactNode;
|
|
16
|
+
endIcon?: ReactNode;
|
|
17
|
+
/** Flip start/end icons horizontally in RTL (for chevrons, arrows, etc.) */
|
|
18
|
+
iconFlip?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function Button({ variant, size, fullWidth, loading, disabled, startIcon, endIcon, iconFlip, className, children, type, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
declare const inputVariants: (props?: ({
|
|
23
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
24
|
+
error?: boolean | null | undefined;
|
|
25
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
26
|
+
interface InputProps extends Omit<React.ComponentProps<'input'>, 'size'>, VariantProps<typeof inputVariants> {
|
|
27
|
+
/** Visible field label, auto-associated to the input via `htmlFor`/`id`. */
|
|
28
|
+
label?: ReactNode;
|
|
29
|
+
/** Hint shown below the field. Hidden while an error message is showing. */
|
|
30
|
+
helperText?: ReactNode;
|
|
31
|
+
/** Message shown below the field when `error` is true. */
|
|
32
|
+
errorMessage?: ReactNode;
|
|
33
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
34
|
+
error?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Content rendered inside the field, before the input (icon or short text,
|
|
37
|
+
* e.g. a search glyph or `https://`). May be interactive — it is NOT
|
|
38
|
+
* `aria-hidden`. Mark purely-decorative icons `aria-hidden` yourself.
|
|
39
|
+
*/
|
|
40
|
+
startAdornment?: ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Content rendered inside the field, after the input. Compose a clear
|
|
43
|
+
* button or password-reveal toggle here with `<Button size="icon-sm">`
|
|
44
|
+
* — the 28px in-field icon size that fits the field without overflow.
|
|
45
|
+
*/
|
|
46
|
+
endAdornment?: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
declare function Input({ id: externalId, label, helperText, errorMessage, error, size, required, startAdornment, endAdornment, className, ...props }: InputProps): react_jsx_runtime.JSX.Element;
|
|
49
|
+
|
|
50
|
+
declare const textareaVariants: (props?: ({
|
|
51
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
52
|
+
error?: boolean | null | undefined;
|
|
53
|
+
resize?: "none" | "vertical" | null | undefined;
|
|
54
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
55
|
+
interface TextareaProps extends React.ComponentProps<'textarea'>, VariantProps<typeof textareaVariants> {
|
|
56
|
+
/** Visible field label, auto-associated to the textarea via `htmlFor`/`id`. */
|
|
57
|
+
label?: ReactNode;
|
|
58
|
+
/** Hint shown below the field. Hidden while an error message is showing. */
|
|
59
|
+
helperText?: ReactNode;
|
|
60
|
+
/** Message shown below the field when `error` is true. */
|
|
61
|
+
errorMessage?: ReactNode;
|
|
62
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
63
|
+
error?: boolean;
|
|
64
|
+
}
|
|
65
|
+
declare function Textarea({ id: externalId, label, helperText, errorMessage, error, size, resize, required, rows, className, ...props }: TextareaProps): react_jsx_runtime.JSX.Element;
|
|
66
|
+
|
|
67
|
+
declare const checkboxVariants: (props?: ({
|
|
68
|
+
size?: "sm" | "md" | null | undefined;
|
|
69
|
+
error?: boolean | null | undefined;
|
|
70
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
71
|
+
interface CheckboxProps extends Omit<React.ComponentProps<typeof Checkbox$1.Root>, 'children'>, VariantProps<typeof checkboxVariants> {
|
|
72
|
+
/** Visible label, sits beside the box, associated via `htmlFor`/`id`. */
|
|
73
|
+
label?: ReactNode;
|
|
74
|
+
/** Hint shown below the row. Hidden while an error message is showing. */
|
|
75
|
+
helperText?: ReactNode;
|
|
76
|
+
/** Message shown below the row when `error` is true. */
|
|
77
|
+
errorMessage?: ReactNode;
|
|
78
|
+
/** Marks the field invalid: sets `aria-invalid` and error styling. */
|
|
79
|
+
error?: boolean;
|
|
80
|
+
}
|
|
81
|
+
declare function Checkbox({ id: externalId, label, helperText, errorMessage, error, size, required, className, ...props }: CheckboxProps): react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
type DgaRootElement = 'div' | 'main' | 'nav' | 'section' | 'article' | 'aside' | 'header' | 'footer';
|
|
84
|
+
interface DgaProviderProps {
|
|
85
|
+
dir?: 'ltr' | 'rtl';
|
|
86
|
+
locale?: string;
|
|
87
|
+
mode?: 'light' | 'dark';
|
|
88
|
+
as?: DgaRootElement;
|
|
89
|
+
className?: string;
|
|
90
|
+
style?: React.CSSProperties;
|
|
91
|
+
children: React.ReactNode;
|
|
92
|
+
}
|
|
93
|
+
declare function DgaProvider({ dir, locale, mode, as: Component, className, style: consumerStyle, children, }: DgaProviderProps): react_jsx_runtime.JSX.Element;
|
|
94
|
+
|
|
95
|
+
interface DgaContextValue {
|
|
96
|
+
dir: 'ltr' | 'rtl';
|
|
97
|
+
locale: string;
|
|
98
|
+
mode: 'light' | 'dark';
|
|
99
|
+
rootRef: React.RefObject<HTMLElement | null>;
|
|
100
|
+
}
|
|
101
|
+
declare function useDga(): DgaContextValue;
|
|
102
|
+
|
|
103
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
104
|
+
|
|
105
|
+
export { Button, type ButtonProps, Checkbox, type CheckboxProps, DgaProvider, type DgaProviderProps, Input, type InputProps, Textarea, type TextareaProps, buttonVariants, checkboxVariants, cn, inputVariants, textareaVariants, useDga };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
// src/components/Button/Button.tsx
|
|
2
|
+
import "react";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
|
|
5
|
+
// src/utils/cn.ts
|
|
6
|
+
import { clsx } from "clsx";
|
|
7
|
+
function cn(...inputs) {
|
|
8
|
+
return clsx(inputs);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/internal/icons/index.tsx
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
function Spinner(props) {
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
"svg",
|
|
16
|
+
{
|
|
17
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
18
|
+
width: "1em",
|
|
19
|
+
height: "1em",
|
|
20
|
+
viewBox: "0 0 24 24",
|
|
21
|
+
fill: "none",
|
|
22
|
+
stroke: "currentColor",
|
|
23
|
+
strokeWidth: "2",
|
|
24
|
+
strokeLinecap: "round",
|
|
25
|
+
strokeLinejoin: "round",
|
|
26
|
+
className: "ddga-spinner",
|
|
27
|
+
...props,
|
|
28
|
+
children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function Check(props) {
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
"svg",
|
|
35
|
+
{
|
|
36
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
37
|
+
width: "1em",
|
|
38
|
+
height: "1em",
|
|
39
|
+
viewBox: "0 0 24 24",
|
|
40
|
+
fill: "none",
|
|
41
|
+
stroke: "currentColor",
|
|
42
|
+
strokeWidth: "3",
|
|
43
|
+
strokeLinecap: "round",
|
|
44
|
+
strokeLinejoin: "round",
|
|
45
|
+
...props,
|
|
46
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function Minus(props) {
|
|
51
|
+
return /* @__PURE__ */ jsx(
|
|
52
|
+
"svg",
|
|
53
|
+
{
|
|
54
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
55
|
+
width: "1em",
|
|
56
|
+
height: "1em",
|
|
57
|
+
viewBox: "0 0 24 24",
|
|
58
|
+
fill: "none",
|
|
59
|
+
stroke: "currentColor",
|
|
60
|
+
strokeWidth: "3",
|
|
61
|
+
strokeLinecap: "round",
|
|
62
|
+
strokeLinejoin: "round",
|
|
63
|
+
...props,
|
|
64
|
+
children: /* @__PURE__ */ jsx("path", { d: "M5 12h14" })
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/components/Button/Button.tsx
|
|
70
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
71
|
+
var buttonVariants = cva("ddga-button", {
|
|
72
|
+
variants: {
|
|
73
|
+
variant: {
|
|
74
|
+
primary: "ddga-button--primary",
|
|
75
|
+
secondary: "ddga-button--secondary",
|
|
76
|
+
outline: "ddga-button--outline",
|
|
77
|
+
ghost: "ddga-button--ghost",
|
|
78
|
+
destructive: "ddga-button--destructive"
|
|
79
|
+
},
|
|
80
|
+
size: {
|
|
81
|
+
sm: "ddga-button--sm",
|
|
82
|
+
md: "ddga-button--md",
|
|
83
|
+
lg: "ddga-button--lg",
|
|
84
|
+
icon: "ddga-button--icon",
|
|
85
|
+
"icon-sm": "ddga-button--icon-sm"
|
|
86
|
+
},
|
|
87
|
+
fullWidth: {
|
|
88
|
+
true: "ddga-button--full-width"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
compoundVariants: [],
|
|
92
|
+
defaultVariants: {
|
|
93
|
+
variant: "primary",
|
|
94
|
+
size: "md"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
function Button({
|
|
98
|
+
variant,
|
|
99
|
+
size,
|
|
100
|
+
fullWidth,
|
|
101
|
+
loading,
|
|
102
|
+
disabled,
|
|
103
|
+
startIcon,
|
|
104
|
+
endIcon,
|
|
105
|
+
iconFlip,
|
|
106
|
+
className,
|
|
107
|
+
children,
|
|
108
|
+
type = "button",
|
|
109
|
+
...props
|
|
110
|
+
}) {
|
|
111
|
+
if (process.env.NODE_ENV === "development" && (size === "icon" || size === "icon-sm")) {
|
|
112
|
+
if (!props["aria-label"] && !props["aria-labelledby"]) {
|
|
113
|
+
console.warn(
|
|
114
|
+
'[@dev-dga/react] Button with an icon-only size (size="icon" or "icon-sm") requires an aria-label or aria-labelledby attribute for screen reader accessibility.'
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const isDisabled = disabled || loading;
|
|
119
|
+
return /* @__PURE__ */ jsxs(
|
|
120
|
+
"button",
|
|
121
|
+
{
|
|
122
|
+
type,
|
|
123
|
+
disabled: isDisabled,
|
|
124
|
+
"aria-disabled": isDisabled || void 0,
|
|
125
|
+
"aria-busy": loading || void 0,
|
|
126
|
+
"data-slot": "button",
|
|
127
|
+
className: cn(
|
|
128
|
+
buttonVariants({ variant, size, fullWidth }),
|
|
129
|
+
loading && "ddga-button--loading",
|
|
130
|
+
className
|
|
131
|
+
),
|
|
132
|
+
...props,
|
|
133
|
+
children: [
|
|
134
|
+
loading && /* @__PURE__ */ jsx2(Spinner, { "aria-hidden": "true" }),
|
|
135
|
+
!loading && startIcon && /* @__PURE__ */ jsx2("span", { className: cn("ddga-button__icon", iconFlip && "ddga-icon-flip"), "aria-hidden": "true", children: startIcon }),
|
|
136
|
+
children != null && children !== "" && /* @__PURE__ */ jsx2("span", { className: "ddga-button__text", children }),
|
|
137
|
+
!loading && endIcon && /* @__PURE__ */ jsx2("span", { className: cn("ddga-button__icon", iconFlip && "ddga-icon-flip"), "aria-hidden": "true", children: endIcon })
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/components/Input/Input.tsx
|
|
144
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
145
|
+
|
|
146
|
+
// src/internal/field/use-field-a11y.ts
|
|
147
|
+
import { useId } from "react";
|
|
148
|
+
function isPresent(value) {
|
|
149
|
+
return value != null && value !== "";
|
|
150
|
+
}
|
|
151
|
+
function useFieldA11y(options) {
|
|
152
|
+
const generatedId = useId();
|
|
153
|
+
const fieldId = options.id ?? generatedId;
|
|
154
|
+
const helperId = `${fieldId}-helper`;
|
|
155
|
+
const errorId = `${fieldId}-error`;
|
|
156
|
+
const hasError = !!options.error;
|
|
157
|
+
const hasErrorMessage = hasError && isPresent(options.errorMessage);
|
|
158
|
+
const hasHelper = !hasErrorMessage && isPresent(options.helperText);
|
|
159
|
+
if (process.env.NODE_ENV === "development" && !options.label) {
|
|
160
|
+
if (!options["aria-label"] && !options["aria-labelledby"]) {
|
|
161
|
+
console.warn(
|
|
162
|
+
`[@dev-dga/react] ${options.name} requires a \`label\`, or an aria-label / aria-labelledby attribute, for screen reader accessibility.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
fieldId,
|
|
168
|
+
helperId,
|
|
169
|
+
errorId,
|
|
170
|
+
hasError,
|
|
171
|
+
hasErrorMessage,
|
|
172
|
+
hasHelper,
|
|
173
|
+
controlProps: {
|
|
174
|
+
id: fieldId,
|
|
175
|
+
"aria-invalid": hasError || void 0,
|
|
176
|
+
"aria-describedby": hasErrorMessage ? errorId : hasHelper ? helperId : void 0
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/internal/field/FieldMessage.tsx
|
|
182
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
183
|
+
function FieldMessage({ id, variant, children }) {
|
|
184
|
+
return /* @__PURE__ */ jsx3(
|
|
185
|
+
"p",
|
|
186
|
+
{
|
|
187
|
+
id,
|
|
188
|
+
"data-slot": `field-${variant}`,
|
|
189
|
+
className: `ddga-field__message ddga-field__message--${variant}`,
|
|
190
|
+
"aria-live": variant === "error" ? "polite" : void 0,
|
|
191
|
+
children
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/components/Input/Input.tsx
|
|
197
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
198
|
+
var inputVariants = cva2("ddga-input", {
|
|
199
|
+
variants: {
|
|
200
|
+
size: {
|
|
201
|
+
sm: "ddga-input--sm",
|
|
202
|
+
md: "ddga-input--md",
|
|
203
|
+
lg: "ddga-input--lg"
|
|
204
|
+
},
|
|
205
|
+
error: {
|
|
206
|
+
true: "ddga-input--error"
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
defaultVariants: {
|
|
210
|
+
size: "md"
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
function Input({
|
|
214
|
+
id: externalId,
|
|
215
|
+
label,
|
|
216
|
+
helperText,
|
|
217
|
+
errorMessage,
|
|
218
|
+
error,
|
|
219
|
+
size,
|
|
220
|
+
required,
|
|
221
|
+
startAdornment,
|
|
222
|
+
endAdornment,
|
|
223
|
+
className,
|
|
224
|
+
...props
|
|
225
|
+
}) {
|
|
226
|
+
const { fieldId, errorId, helperId, hasError, hasErrorMessage, hasHelper, controlProps } = useFieldA11y({
|
|
227
|
+
name: "Input",
|
|
228
|
+
id: externalId,
|
|
229
|
+
label,
|
|
230
|
+
error,
|
|
231
|
+
errorMessage,
|
|
232
|
+
helperText,
|
|
233
|
+
"aria-label": props["aria-label"],
|
|
234
|
+
"aria-labelledby": props["aria-labelledby"]
|
|
235
|
+
});
|
|
236
|
+
return /* @__PURE__ */ jsxs2("div", { "data-slot": "input-field", className: "ddga-field", children: [
|
|
237
|
+
label && /* @__PURE__ */ jsxs2("label", { htmlFor: fieldId, className: "ddga-input__label", children: [
|
|
238
|
+
label,
|
|
239
|
+
required && /* @__PURE__ */ jsx4("span", { "aria-hidden": "true", className: "ddga-input__required", children: "*" })
|
|
240
|
+
] }),
|
|
241
|
+
/* @__PURE__ */ jsxs2(
|
|
242
|
+
"div",
|
|
243
|
+
{
|
|
244
|
+
"data-slot": "input-control",
|
|
245
|
+
className: cn(inputVariants({ size, error: hasError }), className),
|
|
246
|
+
children: [
|
|
247
|
+
startAdornment != null && startAdornment !== "" && /* @__PURE__ */ jsx4(
|
|
248
|
+
"span",
|
|
249
|
+
{
|
|
250
|
+
"data-slot": "input-adornment",
|
|
251
|
+
className: "ddga-input__adornment ddga-input__adornment--start",
|
|
252
|
+
children: startAdornment
|
|
253
|
+
}
|
|
254
|
+
),
|
|
255
|
+
/* @__PURE__ */ jsx4(
|
|
256
|
+
"input",
|
|
257
|
+
{
|
|
258
|
+
...props,
|
|
259
|
+
...controlProps,
|
|
260
|
+
"data-slot": "input",
|
|
261
|
+
required,
|
|
262
|
+
className: "ddga-input__field"
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
endAdornment != null && endAdornment !== "" && /* @__PURE__ */ jsx4(
|
|
266
|
+
"span",
|
|
267
|
+
{
|
|
268
|
+
"data-slot": "input-adornment",
|
|
269
|
+
className: "ddga-input__adornment ddga-input__adornment--end",
|
|
270
|
+
children: endAdornment
|
|
271
|
+
}
|
|
272
|
+
)
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
),
|
|
276
|
+
hasErrorMessage && /* @__PURE__ */ jsx4(FieldMessage, { id: errorId, variant: "error", children: errorMessage }),
|
|
277
|
+
hasHelper && /* @__PURE__ */ jsx4(FieldMessage, { id: helperId, variant: "helper", children: helperText })
|
|
278
|
+
] });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/components/Textarea/Textarea.tsx
|
|
282
|
+
import { cva as cva3 } from "class-variance-authority";
|
|
283
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
284
|
+
var textareaVariants = cva3("ddga-textarea", {
|
|
285
|
+
variants: {
|
|
286
|
+
size: {
|
|
287
|
+
sm: "ddga-textarea--sm",
|
|
288
|
+
md: "ddga-textarea--md",
|
|
289
|
+
lg: "ddga-textarea--lg"
|
|
290
|
+
},
|
|
291
|
+
error: {
|
|
292
|
+
true: "ddga-textarea--error"
|
|
293
|
+
},
|
|
294
|
+
// Horizontal/both resize breaks form layout (same reason it's not the
|
|
295
|
+
// default) — only vertical or locked are offered.
|
|
296
|
+
resize: {
|
|
297
|
+
vertical: "ddga-textarea--resize-vertical",
|
|
298
|
+
none: "ddga-textarea--resize-none"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
defaultVariants: {
|
|
302
|
+
size: "md",
|
|
303
|
+
resize: "vertical"
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
function Textarea({
|
|
307
|
+
id: externalId,
|
|
308
|
+
label,
|
|
309
|
+
helperText,
|
|
310
|
+
errorMessage,
|
|
311
|
+
error,
|
|
312
|
+
size,
|
|
313
|
+
resize,
|
|
314
|
+
required,
|
|
315
|
+
rows = 3,
|
|
316
|
+
className,
|
|
317
|
+
...props
|
|
318
|
+
}) {
|
|
319
|
+
const { fieldId, errorId, helperId, hasError, hasErrorMessage, hasHelper, controlProps } = useFieldA11y({
|
|
320
|
+
name: "Textarea",
|
|
321
|
+
id: externalId,
|
|
322
|
+
label,
|
|
323
|
+
error,
|
|
324
|
+
errorMessage,
|
|
325
|
+
helperText,
|
|
326
|
+
"aria-label": props["aria-label"],
|
|
327
|
+
"aria-labelledby": props["aria-labelledby"]
|
|
328
|
+
});
|
|
329
|
+
return /* @__PURE__ */ jsxs3("div", { "data-slot": "textarea-field", className: "ddga-field", children: [
|
|
330
|
+
label && /* @__PURE__ */ jsxs3("label", { htmlFor: fieldId, className: "ddga-textarea__label", children: [
|
|
331
|
+
label,
|
|
332
|
+
required && /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", className: "ddga-textarea__required", children: "*" })
|
|
333
|
+
] }),
|
|
334
|
+
/* @__PURE__ */ jsx5(
|
|
335
|
+
"textarea",
|
|
336
|
+
{
|
|
337
|
+
...props,
|
|
338
|
+
...controlProps,
|
|
339
|
+
"data-slot": "textarea",
|
|
340
|
+
rows,
|
|
341
|
+
required,
|
|
342
|
+
className: cn(textareaVariants({ size, error: hasError, resize }), className)
|
|
343
|
+
}
|
|
344
|
+
),
|
|
345
|
+
hasErrorMessage && /* @__PURE__ */ jsx5(FieldMessage, { id: errorId, variant: "error", children: errorMessage }),
|
|
346
|
+
hasHelper && /* @__PURE__ */ jsx5(FieldMessage, { id: helperId, variant: "helper", children: helperText })
|
|
347
|
+
] });
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/components/Checkbox/Checkbox.tsx
|
|
351
|
+
import { Checkbox as CheckboxPrimitive } from "radix-ui";
|
|
352
|
+
import { cva as cva4 } from "class-variance-authority";
|
|
353
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
354
|
+
var checkboxVariants = cva4("ddga-checkbox", {
|
|
355
|
+
variants: {
|
|
356
|
+
size: {
|
|
357
|
+
sm: "ddga-checkbox--sm",
|
|
358
|
+
md: "ddga-checkbox--md"
|
|
359
|
+
},
|
|
360
|
+
error: {
|
|
361
|
+
true: "ddga-checkbox--error"
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
defaultVariants: {
|
|
365
|
+
size: "md"
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
function Checkbox({
|
|
369
|
+
id: externalId,
|
|
370
|
+
label,
|
|
371
|
+
helperText,
|
|
372
|
+
errorMessage,
|
|
373
|
+
error,
|
|
374
|
+
size,
|
|
375
|
+
required,
|
|
376
|
+
className,
|
|
377
|
+
...props
|
|
378
|
+
}) {
|
|
379
|
+
const { fieldId, errorId, helperId, hasError, hasErrorMessage, hasHelper, controlProps } = useFieldA11y({
|
|
380
|
+
name: "Checkbox",
|
|
381
|
+
id: externalId,
|
|
382
|
+
label,
|
|
383
|
+
error,
|
|
384
|
+
errorMessage,
|
|
385
|
+
helperText,
|
|
386
|
+
"aria-label": props["aria-label"],
|
|
387
|
+
"aria-labelledby": props["aria-labelledby"]
|
|
388
|
+
});
|
|
389
|
+
return /* @__PURE__ */ jsxs4("div", { "data-slot": "checkbox-field", className: "ddga-field", children: [
|
|
390
|
+
/* @__PURE__ */ jsxs4("div", { className: "ddga-checkbox-row", children: [
|
|
391
|
+
/* @__PURE__ */ jsx6(
|
|
392
|
+
CheckboxPrimitive.Root,
|
|
393
|
+
{
|
|
394
|
+
...props,
|
|
395
|
+
...controlProps,
|
|
396
|
+
"data-slot": "checkbox",
|
|
397
|
+
required,
|
|
398
|
+
className: cn(checkboxVariants({ size, error: hasError }), className),
|
|
399
|
+
children: /* @__PURE__ */ jsxs4(
|
|
400
|
+
CheckboxPrimitive.Indicator,
|
|
401
|
+
{
|
|
402
|
+
"data-slot": "checkbox-indicator",
|
|
403
|
+
className: "ddga-checkbox__indicator",
|
|
404
|
+
children: [
|
|
405
|
+
/* @__PURE__ */ jsx6(Check, { className: "ddga-checkbox__check", "aria-hidden": "true" }),
|
|
406
|
+
/* @__PURE__ */ jsx6(Minus, { className: "ddga-checkbox__minus", "aria-hidden": "true" })
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
}
|
|
411
|
+
),
|
|
412
|
+
label && /* @__PURE__ */ jsxs4("label", { htmlFor: fieldId, className: "ddga-checkbox__label", children: [
|
|
413
|
+
label,
|
|
414
|
+
required && /* @__PURE__ */ jsx6("span", { "aria-hidden": "true", className: "ddga-checkbox__required", children: "*" })
|
|
415
|
+
] })
|
|
416
|
+
] }),
|
|
417
|
+
hasErrorMessage && /* @__PURE__ */ jsx6(FieldMessage, { id: errorId, variant: "error", children: errorMessage }),
|
|
418
|
+
hasHelper && /* @__PURE__ */ jsx6(FieldMessage, { id: helperId, variant: "helper", children: helperText })
|
|
419
|
+
] });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/providers/DgaProvider.tsx
|
|
423
|
+
import { useRef, useMemo, useContext as useContext2 } from "react";
|
|
424
|
+
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
|
425
|
+
|
|
426
|
+
// src/providers/DgaContext.ts
|
|
427
|
+
import { createContext, useContext } from "react";
|
|
428
|
+
var DgaContext = createContext(null);
|
|
429
|
+
function useDga() {
|
|
430
|
+
const ctx = useContext(DgaContext);
|
|
431
|
+
if (!ctx) {
|
|
432
|
+
throw new Error("useDga must be used within a <DgaProvider>");
|
|
433
|
+
}
|
|
434
|
+
return ctx;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// src/providers/DgaProvider.tsx
|
|
438
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
439
|
+
function DgaProvider({
|
|
440
|
+
dir = "ltr",
|
|
441
|
+
locale,
|
|
442
|
+
mode = "light",
|
|
443
|
+
as: Component = "div",
|
|
444
|
+
className,
|
|
445
|
+
style: consumerStyle,
|
|
446
|
+
children
|
|
447
|
+
}) {
|
|
448
|
+
const parentCtx = useContext2(DgaContext);
|
|
449
|
+
const isNested = parentCtx !== null;
|
|
450
|
+
const rootRef = useRef(null);
|
|
451
|
+
const resolvedLocale = locale ?? (dir === "rtl" ? "ar" : "en");
|
|
452
|
+
const ctxValue = useMemo(
|
|
453
|
+
() => ({ dir, locale: resolvedLocale, mode, rootRef }),
|
|
454
|
+
[dir, resolvedLocale, mode]
|
|
455
|
+
);
|
|
456
|
+
return /* @__PURE__ */ jsx7(DgaContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsx7(
|
|
457
|
+
Component,
|
|
458
|
+
{
|
|
459
|
+
ref: rootRef,
|
|
460
|
+
dir,
|
|
461
|
+
lang: resolvedLocale,
|
|
462
|
+
"data-slot": "dga-root",
|
|
463
|
+
"data-theme": mode,
|
|
464
|
+
className,
|
|
465
|
+
style: { colorScheme: mode, ...consumerStyle },
|
|
466
|
+
children: isNested ? children : /* @__PURE__ */ jsx7(TooltipPrimitive.Provider, { delayDuration: 300, skipDelayDuration: 100, children })
|
|
467
|
+
}
|
|
468
|
+
) });
|
|
469
|
+
}
|
|
470
|
+
export {
|
|
471
|
+
Button,
|
|
472
|
+
Checkbox,
|
|
473
|
+
DgaProvider,
|
|
474
|
+
Input,
|
|
475
|
+
Textarea,
|
|
476
|
+
buttonVariants,
|
|
477
|
+
checkboxVariants,
|
|
478
|
+
cn,
|
|
479
|
+
inputVariants,
|
|
480
|
+
textareaVariants,
|
|
481
|
+
useDga
|
|
482
|
+
};
|
|
483
|
+
//# sourceMappingURL=index.js.map
|