@chobantonov/jsonforms-react-shadcn-webcomponent 0.0.0-stage → 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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -2
  3. package/dist/JsonFormsShadcnElement.d.ts +29 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/jsonforms-react-shadcn.js +1 -0
  6. package/dist/register.d.ts +2 -0
  7. package/dist/register.js +6 -0
  8. package/dist/register.js.map +1 -0
  9. package/dist/renderers.d.ts +2 -0
  10. package/dist/src-CLRAt7jc.mjs +9482 -0
  11. package/dist/src-CLRAt7jc.mjs.map +1 -0
  12. package/dist/standalone/AgGridControlRenderer.impl-BZS8_ocu-Dp2429lF.mjs +39184 -0
  13. package/dist/standalone/AgGridControlRenderer.impl-BZS8_ocu-Dp2429lF.mjs.map +1 -0
  14. package/dist/standalone/DynamicJSXRenderer-DyB3ZpZV-Dr83kPeb.mjs +14893 -0
  15. package/dist/standalone/DynamicJSXRenderer-DyB3ZpZV-Dr83kPeb.mjs.map +1 -0
  16. package/dist/standalone/FileArrayInput.esm-BG196JYM.mjs +760 -0
  17. package/dist/standalone/FileArrayInput.esm-BG196JYM.mjs.map +1 -0
  18. package/dist/standalone/MarkupLabelRenderer.impl-CWfdcUuH-BgJ-v1Ei.mjs +12 -0
  19. package/dist/standalone/MarkupLabelRenderer.impl-CWfdcUuH-BgJ-v1Ei.mjs.map +1 -0
  20. package/dist/standalone/MonacoControlRenderer.impl-CyjMHbOd-BP-CDX3S.mjs +773 -0
  21. package/dist/standalone/MonacoControlRenderer.impl-CyjMHbOd-BP-CDX3S.mjs.map +1 -0
  22. package/dist/standalone/RactiveTemplate-Cat7CxUp-BnyPMY_h.mjs +8028 -0
  23. package/dist/standalone/RactiveTemplate-Cat7CxUp-BnyPMY_h.mjs.map +1 -0
  24. package/dist/standalone/celTemplate-D_AGhaIL-ryXLzhcw.mjs +137 -0
  25. package/dist/standalone/celTemplate-D_AGhaIL-ryXLzhcw.mjs.map +1 -0
  26. package/dist/standalone/classPrivateFieldGet2-CAMXi-8L.mjs +22 -0
  27. package/dist/standalone/dynamicCel.esm-DrqwYtar.mjs +43 -0
  28. package/dist/standalone/dynamicCel.esm-DrqwYtar.mjs.map +1 -0
  29. package/dist/standalone/index.js +24493 -0
  30. package/dist/standalone/index.js.map +1 -0
  31. package/dist/standalone/jsonforms-react-extended.esm-CFwqhFcu.mjs +13760 -0
  32. package/dist/standalone/jsonforms-react-extended.esm-CFwqhFcu.mjs.map +1 -0
  33. package/dist/standalone/lib-DHN5bkVZ.mjs +3149 -0
  34. package/dist/standalone/lib-DHN5bkVZ.mjs.map +1 -0
  35. package/dist/standalone/markdown-C_y73Q0w-DE-0r4-5.mjs +3060 -0
  36. package/dist/standalone/markdown-C_y73Q0w-DE-0r4-5.mjs.map +1 -0
  37. package/dist/standalone/plainRecord.esm-D_l3rehZ.mjs +123 -0
  38. package/dist/standalone/plainRecord.esm-D_l3rehZ.mjs.map +1 -0
  39. package/dist/standalone/react-dom-DUZYP7tL.mjs +5644 -0
  40. package/dist/standalone/react-dom-DUZYP7tL.mjs.map +1 -0
  41. package/package.json +82 -3
  42. package/src/JsonFormsShadcnElement.tsx +208 -0
  43. package/src/components/ui/alert.tsx +65 -0
  44. package/src/components/ui/avatar.tsx +108 -0
  45. package/src/components/ui/breadcrumb.tsx +111 -0
  46. package/src/components/ui/button.tsx +64 -0
  47. package/src/components/ui/calendar.tsx +223 -0
  48. package/src/components/ui/card.tsx +91 -0
  49. package/src/components/ui/checkbox.tsx +31 -0
  50. package/src/components/ui/collapsible.tsx +21 -0
  51. package/src/components/ui/dialog.tsx +175 -0
  52. package/src/components/ui/index.ts +12 -0
  53. package/src/components/ui/input.tsx +22 -0
  54. package/src/components/ui/item.tsx +193 -0
  55. package/src/components/ui/pagination.tsx +132 -0
  56. package/src/components/ui/popover.tsx +88 -0
  57. package/src/components/ui/radio-group.tsx +44 -0
  58. package/src/components/ui/resizable.tsx +52 -0
  59. package/src/components/ui/scroll-area.tsx +57 -0
  60. package/src/components/ui/select.tsx +189 -0
  61. package/src/components/ui/separator.tsx +27 -0
  62. package/src/components/ui/slider.tsx +62 -0
  63. package/src/components/ui/switch.tsx +34 -0
  64. package/src/components/ui/tabs.tsx +90 -0
  65. package/src/components/ui/textarea.tsx +17 -0
  66. package/src/components/ui/tooltip.tsx +56 -0
  67. package/src/components/ui/utils.ts +5 -0
  68. package/src/index.tsx +4 -0
  69. package/src/register.ts +13 -0
  70. package/src/renderers.ts +14 -0
  71. package/src/styles.css +29 -0
  72. package/src/vite-env.d.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,85 @@
1
1
  {
2
2
  "name": "@chobantonov/jsonforms-react-shadcn-webcomponent",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Shadcn UI JSON Forms React custom element",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/kchobantonov/jsonforms-react-renderers.git",
8
+ "directory": "packages/jsonforms-react-shadcn-webcomponent"
9
+ },
10
+ "bugs": "https://github.com/kchobantonov/jsonforms-react-renderers/issues",
11
+ "homepage": "https://github.com/kchobantonov/jsonforms-react-renderers",
12
+ "license": "MIT",
13
+ "directories": {
14
+ "src": "src"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "keywords": [
21
+ "shadcn-ui",
22
+ "shadcn",
23
+ "react",
24
+ "jsonforms",
25
+ "webcomponent",
26
+ "custom-element"
27
+ ],
28
+ "module": "dist/jsonforms-react-shadcn.js",
29
+ "typings": "dist/index.d.ts",
30
+ "peerDependencies": {
31
+ "@jsonforms/core": "3.9.0-alpha.4",
32
+ "@jsonforms/react": "3.9.0-alpha.4",
33
+ "react": "^18.0.0 || ^19.0.0",
34
+ "react-dom": "^18.0.0 || ^19.0.0",
35
+ "@chobantonov/jsonforms-react-extended-renderers": "0.1.0",
36
+ "@chobantonov/jsonforms-react-shadcn-renderers": "0.1.0",
37
+ "@chobantonov/jsonforms-react-shadcn-extended-renderers": "0.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@jsonforms/core": "3.9.0-alpha.4",
41
+ "@jsonforms/react": "3.9.0-alpha.4",
42
+ "@tailwindcss/postcss": "^4.3.3",
43
+ "@types/react": "^18.3.23",
44
+ "@types/react-dom": "^18.3.7",
45
+ "jsdom": "^22.0.0",
46
+ "postcss": "8.5.34",
47
+ "react": "^18.3.1",
48
+ "react-dom": "^18.3.1",
49
+ "rimraf": "^6.1.4",
50
+ "tailwindcss": "4.3.3",
51
+ "tailwindcss-animate": "1.0.7",
52
+ "typescript": "~6.0.3",
53
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
54
+ "vitest": "5.1.1",
55
+ "@types/node": "^22.0.0",
56
+ "@vitest/coverage-v8": "5.1.1",
57
+ "@chobantonov/jsonforms-react-shadcn-extended-renderers": "0.1.0",
58
+ "@chobantonov/jsonforms-react-extended-renderers": "0.1.0",
59
+ "@chobantonov/jsonforms-react-shadcn-renderers": "0.1.0"
60
+ },
61
+ "dependencies": {
62
+ "@base-ui/react": "^1.8.0",
63
+ "class-variance-authority": "0.7.1",
64
+ "clsx": "2.1.1",
65
+ "lucide-react": "1.37.0",
66
+ "radix-ui": "^1.6.7",
67
+ "react-day-picker": "10.0.2",
68
+ "react-resizable-panels": "^4.12.3",
69
+ "tailwind-merge": "3.6.0",
70
+ "@chobantonov/jsonforms-react-renderer-common": "0.1.0"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ },
75
+ "scripts": {
76
+ "build": "vp build && vp build --config vite.standalone.config.mjs && tsc --emitDeclarationOnly",
77
+ "clean": "rimraf dist 2> /dev/null",
78
+ "lint": "vp lint .",
79
+ "lint:fix": "vp run lint --fix",
80
+ "test": "vp test run",
81
+ "test:watch": "vp test",
82
+ "tsc": "tsc --build tsconfig.json",
83
+ "test-cov": "vp test run --coverage"
84
+ }
6
85
  }
@@ -0,0 +1,208 @@
1
+ import { defaultTranslator } from '@jsonforms/core';
2
+ import {
3
+ FormElement,
4
+ formAttributes,
5
+ type FormElementState,
6
+ } from '@chobantonov/jsonforms-react-renderer-common/webcomponent/element';
7
+ import {
8
+ ShadcnRendererSettings,
9
+ createShadcnRendererStyle,
10
+ } from '@chobantonov/jsonforms-react-shadcn-extended-renderers';
11
+ import {
12
+ ActionEvent,
13
+ ExtendedJsonForms,
14
+ createAdditionalErrorStore,
15
+ createFormsAjv,
16
+ } from '@chobantonov/jsonforms-react-extended-renderers';
17
+ import { createRoot, Root } from 'react-dom/client';
18
+ import {
19
+ shadcnWebcomponentCells,
20
+ shadcnWebcomponentRenderers,
21
+ } from './renderers';
22
+ import rendererStyles from '../../jsonforms-react-shadcn-renderers/src/styles.css?inline';
23
+ import webcomponentStyles from './styles.css?inline';
24
+ import {
25
+ createTranslator,
26
+ parseBoolean,
27
+ parseJson,
28
+ parseMode,
29
+ type JsonInput,
30
+ } from '@chobantonov/jsonforms-react-renderer-common/webcomponent/input';
31
+
32
+ export { createTranslator, parseBoolean, parseJson, parseMode };
33
+ export type { JsonInput };
34
+
35
+ export const JSON_FORMS_SHADCN_TAG = 'jsonforms-react-shadcn';
36
+
37
+ type ElementState = FormElementState & {
38
+ accentColor?: string;
39
+ borderRadius?: JsonInput;
40
+ density?: ShadcnRendererSettings['density'];
41
+ };
42
+ const observedAttributes = [
43
+ ...formAttributes,
44
+ 'accent-color',
45
+ 'border-radius',
46
+ 'density',
47
+ ];
48
+
49
+ export class JsonFormsShadcnElement extends FormElement {
50
+ static get observedAttributes() {
51
+ return observedAttributes;
52
+ }
53
+
54
+ private root?: Root;
55
+ readonly errorStore = createAdditionalErrorStore();
56
+ private ajv = createFormsAjv({
57
+ i18n: () => ({
58
+ locale: this.state.locale,
59
+ translate: this.state.translations
60
+ ? createTranslator(this.state.translations, this.state.locale)
61
+ : defaultTranslator,
62
+ }),
63
+ });
64
+ protected state: ElementState = {
65
+ validationMode: 'ValidateAndShow',
66
+ locale: 'en',
67
+ mode: 'system',
68
+ readonly: false,
69
+ customStyle: '',
70
+ };
71
+
72
+ constructor() {
73
+ super();
74
+ this.attachShadow({ mode: 'open' });
75
+ }
76
+
77
+ connectedCallback() {
78
+ if (!this.shadowRoot) return;
79
+ this.root ??= createRoot(this.shadowRoot);
80
+ this.render();
81
+ }
82
+
83
+ disconnectedCallback() {
84
+ // The host may be removing this element during its own React commit.
85
+ // Reuse the root if the element is moved/reconnected before cleanup runs.
86
+ queueMicrotask(() => {
87
+ if (this.isConnected) return;
88
+ this.root?.unmount();
89
+ this.root = undefined;
90
+ });
91
+ }
92
+
93
+ set accentColor(value: string) {
94
+ this.setValue('accentColor', value);
95
+ }
96
+ set borderRadius(value: JsonInput) {
97
+ this.setValue('borderRadius', value);
98
+ }
99
+ set density(value: ShadcnRendererSettings['density']) {
100
+ this.setValue('density', value);
101
+ }
102
+
103
+ protected setValue(name: string, value: JsonInput) {
104
+ const key = name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
105
+ (this.state as any)[key] = value;
106
+ this.render();
107
+ }
108
+
109
+ private emitChange(data: unknown, errors: unknown[] = []) {
110
+ this.dispatchEvent(
111
+ new CustomEvent('change', {
112
+ bubbles: true,
113
+ composed: true,
114
+ detail: { data, errors },
115
+ }),
116
+ );
117
+ }
118
+
119
+ private emitAction(event: ActionEvent) {
120
+ this.dispatchEvent(
121
+ new CustomEvent('handle-action', {
122
+ bubbles: true,
123
+ composed: true,
124
+ detail: event,
125
+ }),
126
+ );
127
+ }
128
+
129
+ private render() {
130
+ if (!this.root) return;
131
+ const input = this.readFormInput();
132
+ if (!input) return;
133
+ const { schema, data } = input;
134
+
135
+ const dark =
136
+ parseBoolean(this.state.dark) ?? parseMode(this.state.mode) === 'dark';
137
+ const rendererSettings = {
138
+ ...(parseJson(this.state.rendererSettings) as ShadcnRendererSettings),
139
+ accentColor: this.state.accentColor,
140
+ borderRadius:
141
+ typeof this.state.borderRadius === 'string'
142
+ ? Number(this.state.borderRadius)
143
+ : this.state.borderRadius,
144
+ density: this.state.density,
145
+ } as ShadcnRendererSettings;
146
+ const style = createShadcnRendererStyle(rendererSettings, dark);
147
+ const translate = this.state.translations
148
+ ? createTranslator(this.state.translations, this.state.locale)
149
+ : undefined;
150
+
151
+ this.root.render(
152
+ <>
153
+ <style>{rendererStyles}</style>
154
+ <style>{webcomponentStyles}</style>
155
+ <style>{this.state.customStyle ?? ''}</style>
156
+ <div
157
+ className={
158
+ dark
159
+ ? 'shadcn-jsonforms-host shadcn-jsonforms-root app-dark dark'
160
+ : 'shadcn-jsonforms-host shadcn-jsonforms-root'
161
+ }
162
+ data-dark={dark ? 'true' : 'false'}
163
+ dir={parseBoolean(this.state.rtl) ? 'rtl' : undefined}
164
+ style={style}
165
+ >
166
+ <slot name='form-header' />
167
+ <ExtendedJsonForms
168
+ external={
169
+ parseJson(this.state.external) as
170
+ | Readonly<Record<string, unknown>>
171
+ | undefined
172
+ }
173
+ ajv={this.ajv}
174
+ store={this.errorStore}
175
+ onAction={(event) => this.emitAction(event)}
176
+ data={data}
177
+ schema={schema as any}
178
+ uischema={parseJson(this.state.uischema) as any}
179
+ uischemas={parseJson(this.state.uischemas) as any}
180
+ config={{
181
+ ...(parseJson(this.state.config) as Record<string, any>),
182
+ readonly: parseBoolean(this.state.readonly),
183
+ }}
184
+ readonly={parseBoolean(this.state.readonly)}
185
+ validationMode={this.state.validationMode}
186
+ renderers={shadcnWebcomponentRenderers}
187
+ cells={shadcnWebcomponentCells}
188
+ additionalErrors={parseJson(this.state.additionalErrors) as any}
189
+ i18n={{
190
+ locale: this.state.locale,
191
+ translate,
192
+ }}
193
+ onChange={({ data, errors }) => this.emitChange(data, errors)}
194
+ />
195
+ <slot name='form-footer' />
196
+ </div>
197
+ </>,
198
+ );
199
+ }
200
+ }
201
+
202
+ export const registerJsonFormsShadcn = (
203
+ tagName: string = JSON_FORMS_SHADCN_TAG,
204
+ ) => {
205
+ if (!customElements.get(tagName)) {
206
+ customElements.define(tagName, JsonFormsShadcnElement);
207
+ }
208
+ };
@@ -0,0 +1,65 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { cn } from "./utils"
4
+
5
+ const alertVariants = cva(
6
+ "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
7
+ {
8
+ variants: {
9
+ variant: {
10
+ default: "bg-card text-card-foreground",
11
+ destructive:
12
+ "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current",
13
+ },
14
+ },
15
+ defaultVariants: {
16
+ variant: "default",
17
+ },
18
+ }
19
+ )
20
+
21
+ function Alert({
22
+ className,
23
+ variant,
24
+ ...props
25
+ }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
26
+ return (
27
+ <div
28
+ data-slot="alert"
29
+ role="alert"
30
+ className={cn(alertVariants({ variant }), className)}
31
+ {...props}
32
+ />
33
+ )
34
+ }
35
+
36
+ function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
37
+ return (
38
+ <div
39
+ data-slot="alert-title"
40
+ className={cn(
41
+ "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
42
+ className
43
+ )}
44
+ {...props}
45
+ />
46
+ )
47
+ }
48
+
49
+ function AlertDescription({
50
+ className,
51
+ ...props
52
+ }: React.ComponentProps<"div">) {
53
+ return (
54
+ <div
55
+ data-slot="alert-description"
56
+ className={cn(
57
+ "col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed",
58
+ className
59
+ )}
60
+ {...props}
61
+ />
62
+ )
63
+ }
64
+
65
+ export { Alert, AlertTitle, AlertDescription }
@@ -0,0 +1,108 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { cn } from "./utils"
5
+ import { Avatar as AvatarPrimitive } from "radix-ui"
6
+
7
+ function Avatar({
8
+ className,
9
+ size = "default",
10
+ ...props
11
+ }: React.ComponentProps<typeof AvatarPrimitive.Root> & {
12
+ size?: "default" | "sm" | "lg"
13
+ }) {
14
+ return (
15
+ <AvatarPrimitive.Root
16
+ data-slot="avatar"
17
+ data-size={size}
18
+ className={cn(
19
+ "group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6",
20
+ className
21
+ )}
22
+ {...props}
23
+ />
24
+ )
25
+ }
26
+
27
+ function AvatarImage({
28
+ className,
29
+ ...props
30
+ }: React.ComponentProps<typeof AvatarPrimitive.Image>) {
31
+ return (
32
+ <AvatarPrimitive.Image
33
+ data-slot="avatar-image"
34
+ className={cn("aspect-square size-full", className)}
35
+ {...props}
36
+ />
37
+ )
38
+ }
39
+
40
+ function AvatarFallback({
41
+ className,
42
+ ...props
43
+ }: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
44
+ return (
45
+ <AvatarPrimitive.Fallback
46
+ data-slot="avatar-fallback"
47
+ className={cn(
48
+ "flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
49
+ className
50
+ )}
51
+ {...props}
52
+ />
53
+ )
54
+ }
55
+
56
+ function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
57
+ return (
58
+ <span
59
+ data-slot="avatar-badge"
60
+ className={cn(
61
+ "absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground ring-2 ring-background select-none",
62
+ "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
63
+ "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
64
+ "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
65
+ className
66
+ )}
67
+ {...props}
68
+ />
69
+ )
70
+ }
71
+
72
+ function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
73
+ return (
74
+ <div
75
+ data-slot="avatar-group"
76
+ className={cn(
77
+ "group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
78
+ className
79
+ )}
80
+ {...props}
81
+ />
82
+ )
83
+ }
84
+
85
+ function AvatarGroupCount({
86
+ className,
87
+ ...props
88
+ }: React.ComponentProps<"div">) {
89
+ return (
90
+ <div
91
+ data-slot="avatar-group-count"
92
+ className={cn(
93
+ "relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
94
+ className
95
+ )}
96
+ {...props}
97
+ />
98
+ )
99
+ }
100
+
101
+ export {
102
+ Avatar,
103
+ AvatarImage,
104
+ AvatarFallback,
105
+ AvatarBadge,
106
+ AvatarGroup,
107
+ AvatarGroupCount,
108
+ }
@@ -0,0 +1,111 @@
1
+ import { useI18n } from "@chobantonov/jsonforms-react-renderer-common/locale/translate"
2
+ import * as React from "react"
3
+ import { cn } from "./utils"
4
+ import { ChevronRight, MoreHorizontal } from "lucide-react"
5
+ import { Slot } from "radix-ui"
6
+
7
+ function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
8
+ const t = useI18n()
9
+ return <nav aria-label={t("breadcrumb.label")} data-slot="breadcrumb" {...props} />
10
+ }
11
+
12
+ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
13
+ return (
14
+ <ol
15
+ data-slot="breadcrumb-list"
16
+ className={cn(
17
+ "flex flex-wrap items-center gap-1.5 text-sm break-words text-muted-foreground sm:gap-2.5",
18
+ className
19
+ )}
20
+ {...props}
21
+ />
22
+ )
23
+ }
24
+
25
+ function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
26
+ return (
27
+ <li
28
+ data-slot="breadcrumb-item"
29
+ className={cn("inline-flex items-center gap-1.5", className)}
30
+ {...props}
31
+ />
32
+ )
33
+ }
34
+
35
+ function BreadcrumbLink({
36
+ asChild,
37
+ className,
38
+ ...props
39
+ }: React.ComponentProps<"a"> & {
40
+ asChild?: boolean
41
+ }) {
42
+ const Comp = asChild ? Slot.Root : "a"
43
+
44
+ return (
45
+ <Comp
46
+ data-slot="breadcrumb-link"
47
+ className={cn("transition-colors hover:text-foreground", className)}
48
+ {...props}
49
+ />
50
+ )
51
+ }
52
+
53
+ function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
54
+ return (
55
+ <span
56
+ data-slot="breadcrumb-page"
57
+ role="link"
58
+ aria-disabled="true"
59
+ aria-current="page"
60
+ className={cn("font-normal text-foreground", className)}
61
+ {...props}
62
+ />
63
+ )
64
+ }
65
+
66
+ function BreadcrumbSeparator({
67
+ children,
68
+ className,
69
+ ...props
70
+ }: React.ComponentProps<"li">) {
71
+ return (
72
+ <li
73
+ data-slot="breadcrumb-separator"
74
+ role="presentation"
75
+ aria-hidden="true"
76
+ className={cn("[&>svg]:size-3.5", className)}
77
+ {...props}
78
+ >
79
+ {children ?? <ChevronRight />}
80
+ </li>
81
+ )
82
+ }
83
+
84
+ function BreadcrumbEllipsis({
85
+ className,
86
+ ...props
87
+ }: React.ComponentProps<"span">) {
88
+ const t = useI18n()
89
+ return (
90
+ <span
91
+ data-slot="breadcrumb-ellipsis"
92
+ role="presentation"
93
+ aria-hidden="true"
94
+ className={cn("flex size-9 items-center justify-center", className)}
95
+ {...props}
96
+ >
97
+ <MoreHorizontal className="size-4" />
98
+ <span className="sr-only">{t("control.more")}</span>
99
+ </span>
100
+ )
101
+ }
102
+
103
+ export {
104
+ Breadcrumb,
105
+ BreadcrumbList,
106
+ BreadcrumbItem,
107
+ BreadcrumbLink,
108
+ BreadcrumbPage,
109
+ BreadcrumbSeparator,
110
+ BreadcrumbEllipsis,
111
+ }
@@ -0,0 +1,64 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { cn } from "./utils"
4
+ import { Slot } from "radix-ui"
5
+
6
+ const buttonVariants = cva(
7
+ "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
12
+ destructive:
13
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
14
+ outline:
15
+ "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
16
+ secondary:
17
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
18
+ ghost:
19
+ "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
20
+ link: "text-primary underline-offset-4 hover:underline",
21
+ },
22
+ size: {
23
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
24
+ xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
25
+ sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
26
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
27
+ icon: "size-9",
28
+ "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
29
+ "icon-sm": "size-8",
30
+ "icon-lg": "size-10",
31
+ },
32
+ },
33
+ defaultVariants: {
34
+ variant: "default",
35
+ size: "default",
36
+ },
37
+ }
38
+ )
39
+
40
+ const Button = React.forwardRef<HTMLButtonElement,
41
+ React.ComponentPropsWithoutRef<"button"> &
42
+ VariantProps<typeof buttonVariants> & { asChild?: boolean }
43
+ >(function Button({
44
+ className,
45
+ variant = "default",
46
+ size = "default",
47
+ asChild = false,
48
+ ...props
49
+ }, ref) {
50
+ const Comp = asChild ? Slot.Root : "button"
51
+
52
+ return (
53
+ <Comp
54
+ ref={ref}
55
+ data-slot="button"
56
+ data-variant={variant}
57
+ data-size={size}
58
+ className={cn(buttonVariants({ variant, size, className }))}
59
+ {...props}
60
+ />
61
+ )
62
+ })
63
+
64
+ export { Button, buttonVariants }