@duskmoon-dev/components 0.3.3 → 0.4.1
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/README.md +142 -2
- package/dist/classes/chat.d.ts +9 -1
- package/dist/classes/console-page.d.ts +16 -0
- package/dist/classes/dropdown.d.ts +5 -5
- package/dist/classes/fab.d.ts +11 -0
- package/dist/classes/index.d.ts +5 -0
- package/dist/classes/index.js +180 -34
- package/dist/classes/megamenu.d.ts +10 -0
- package/dist/classes/otp-input.d.ts +12 -0
- package/dist/classes/popover.d.ts +1 -3
- package/dist/classes/swap.d.ts +12 -0
- package/dist/classes/tree-select.d.ts +6 -6
- package/dist/components/app/index.js +128 -68
- package/dist/components/avatar/Avatar.types.d.ts +1 -1
- package/dist/components/avatar/index.js +2 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/Button.d.ts +1 -1
- package/dist/components/button/Button.types.d.ts +8 -0
- package/dist/components/button/index.js +253 -24
- package/dist/components/calendar/index.js +44 -19
- package/dist/components/chat/Chat.d.ts +9 -1
- package/dist/components/chat/Chat.types.d.ts +26 -0
- package/dist/components/chat/index.js +92 -3
- package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
- package/dist/components/color-picker/index.js +206 -9
- package/dist/components/console-page/ConsolePage.d.ts +2 -0
- package/dist/components/console-page/ConsolePage.types.d.ts +29 -0
- package/dist/components/console-page/index.d.ts +2 -0
- package/dist/components/console-page/index.js +205 -0
- package/dist/components/date-picker/DatePicker.types.d.ts +1 -0
- package/dist/components/date-picker/index.js +537 -35
- package/dist/components/date-picker/usePickerDropdown.d.ts +17 -0
- package/dist/components/dm-date-picker/index.js +545 -43
- package/dist/components/dm-drawer/index.js +253 -24
- package/dist/components/dm-layout/index.js +391 -24
- package/dist/components/dm-menu/index.js +380 -13
- package/dist/components/dm-page-header/index.js +404 -114
- package/dist/components/dm-pro-table/index.js +1195 -368
- package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
- package/dist/components/dm-query/index.js +943 -188
- package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
- package/dist/components/dm-search/index.js +929 -163
- package/dist/components/dm-table/index.js +1013 -247
- package/dist/components/dm-toolbar/index.js +400 -110
- package/dist/components/dm-truncate/index.js +115 -35
- package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
- package/dist/components/dropdown/index.js +400 -110
- package/dist/components/fab/Fab.d.ts +4 -0
- package/dist/components/fab/Fab.types.d.ts +25 -0
- package/dist/components/fab/index.d.ts +2 -0
- package/dist/components/fab/index.js +480 -0
- package/dist/components/form/Form.types.d.ts +1 -0
- package/dist/components/form/index.js +14 -3
- package/dist/components/json-schema-form/JsonSchemaForm.d.ts +19 -0
- package/dist/components/json-schema-form/JsonSchemaWidget.d.ts +14 -0
- package/dist/components/json-schema-form/index.d.ts +8 -0
- package/dist/components/json-schema-form/index.js +7661 -0
- package/dist/components/json-schema-form/json-form-widgets.d.ts +26 -0
- package/dist/components/json-schema-form/json-schema-form.d.ts +50 -0
- package/dist/components/megamenu/Megamenu.d.ts +2 -0
- package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
- package/dist/components/megamenu/index.d.ts +2 -0
- package/dist/components/megamenu/index.js +214 -0
- package/dist/components/modal/index.js +128 -68
- package/dist/components/otp-input/OtpInput.d.ts +2 -0
- package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
- package/dist/components/otp-input/index.d.ts +2 -0
- package/dist/components/otp-input/index.js +112 -0
- package/dist/components/popconfirm/index.js +255 -26
- package/dist/components/popover/index.js +24 -4
- package/dist/components/select/index.js +12 -0
- package/dist/components/swap/Swap.d.ts +3 -0
- package/dist/components/swap/Swap.types.d.ts +22 -0
- package/dist/components/swap/index.d.ts +2 -0
- package/dist/components/swap/index.js +109 -0
- package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
- package/dist/components/time-picker/index.js +167 -29
- package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
- package/dist/components/tooltip/index.js +107 -27
- package/dist/components/tour/index.js +253 -24
- package/dist/components/tree-select/index.js +8 -8
- package/dist/components/upload/Upload.types.d.ts +1 -0
- package/dist/components/upload/index.js +2 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3343 -1633
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +1359 -865
- package/package.json +31 -5
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JsonValue, RenderableSchema } from "./json-schema-form";
|
|
2
|
+
export declare const widgetNames: readonly ["input", "input-number", "checkbox", "radio", "radio-group", "checkbox-group", "color-picker", "date-picker", "dm-date-picker", "mentions", "otp-input", "rate", "segmented", "select", "slider", "switch", "time-picker", "transfer", "tree-select", "cascader", "upload"];
|
|
3
|
+
export type WidgetName = (typeof widgetNames)[number];
|
|
4
|
+
export type WidgetOption = {
|
|
5
|
+
value: string | number | boolean;
|
|
6
|
+
label: string;
|
|
7
|
+
children?: WidgetOption[];
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type OrientationWidgetConfig = {
|
|
11
|
+
orientation?: "horizontal" | "vertical";
|
|
12
|
+
};
|
|
13
|
+
export type WidgetConfig = OrientationWidgetConfig & {
|
|
14
|
+
length?: number;
|
|
15
|
+
count?: number;
|
|
16
|
+
allowHalf?: boolean;
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
step?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const flattenOptions: (options: WidgetOption[]) => WidgetOption[];
|
|
22
|
+
export declare function widgetConfig(schema: RenderableSchema): WidgetConfig;
|
|
23
|
+
export declare function naturalWidgetValue(schema: RenderableSchema): JsonValue | undefined;
|
|
24
|
+
export declare function optionsFor(schema: RenderableSchema): WidgetOption[];
|
|
25
|
+
export declare function inspectWidgets(input: Record<string, unknown>, location: string): void;
|
|
26
|
+
export declare function widgetValueError(schema: RenderableSchema, value: JsonValue): string | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type WidgetName, type WidgetOption, type WidgetConfig } from "./json-form-widgets";
|
|
2
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
export type FormValue = {
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
};
|
|
8
|
+
export type RenderableSchema = {
|
|
9
|
+
type: "object" | "array" | "string" | "number" | "integer" | "boolean";
|
|
10
|
+
$schema?: "https://json-schema.org/draft/2020-12/schema";
|
|
11
|
+
$id?: string;
|
|
12
|
+
$comment?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
default?: JsonValue;
|
|
16
|
+
enum?: JsonValue[];
|
|
17
|
+
properties?: Record<string, RenderableSchema>;
|
|
18
|
+
required?: string[];
|
|
19
|
+
items?: RenderableSchema;
|
|
20
|
+
additionalProperties?: false;
|
|
21
|
+
minLength?: number;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
pattern?: string;
|
|
24
|
+
format?: string;
|
|
25
|
+
minItems?: number;
|
|
26
|
+
maxItems?: number;
|
|
27
|
+
uniqueItems?: boolean;
|
|
28
|
+
minProperties?: number;
|
|
29
|
+
maxProperties?: number;
|
|
30
|
+
exclusiveMinimum?: number;
|
|
31
|
+
exclusiveMaximum?: number;
|
|
32
|
+
minimum?: number;
|
|
33
|
+
maximum?: number;
|
|
34
|
+
multipleOf?: number;
|
|
35
|
+
"x-widget"?: WidgetName;
|
|
36
|
+
"x-options"?: WidgetOption[];
|
|
37
|
+
"x-widget-options"?: WidgetConfig;
|
|
38
|
+
};
|
|
39
|
+
/** Errors keyed by escaped JSON Pointer, with an empty key for form errors. */
|
|
40
|
+
export type FormErrors = Record<string, string>;
|
|
41
|
+
export type FormValidationResult = {
|
|
42
|
+
valid: boolean;
|
|
43
|
+
errors: FormErrors;
|
|
44
|
+
};
|
|
45
|
+
export type CompiledForm = {
|
|
46
|
+
schema: RenderableSchema;
|
|
47
|
+
initialValue: () => FormValue;
|
|
48
|
+
validate: (value: FormValue) => FormValidationResult;
|
|
49
|
+
};
|
|
50
|
+
export declare function compileForm(input: unknown): CompiledForm;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ComponentProps, ForwardRefExoticComponent, ReactNode, RefAttributes } from "react";
|
|
2
|
+
export interface MegamenuProps extends Omit<ComponentProps<"nav">, "ref"> {
|
|
3
|
+
trigger?: ReactNode;
|
|
4
|
+
panelHeading?: ReactNode;
|
|
5
|
+
panel?: ReactNode;
|
|
6
|
+
mobile?: ReactNode;
|
|
7
|
+
leading?: ReactNode;
|
|
8
|
+
fullWidth?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type MegamenuBarProps = Omit<ComponentProps<"ul">, "ref">;
|
|
11
|
+
export type MegamenuItemProps = Omit<ComponentProps<"li">, "ref">;
|
|
12
|
+
export type MegamenuTriggerProps = Omit<ComponentProps<"button">, "ref">;
|
|
13
|
+
export interface MegamenuPanelProps extends Omit<ComponentProps<"div">, "ref"> {
|
|
14
|
+
full?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type MegamenuGroupProps = Omit<ComponentProps<"section">, "ref">;
|
|
17
|
+
export type MegamenuHeadingProps = Omit<ComponentProps<"h2">, "ref">;
|
|
18
|
+
export type MegamenuSupportingProps = Omit<ComponentProps<"p">, "ref">;
|
|
19
|
+
export interface MegamenuMobileProps extends Omit<ComponentProps<"details">, "ref"> {
|
|
20
|
+
summary: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export interface MegamenuComponent extends ForwardRefExoticComponent<MegamenuProps & RefAttributes<HTMLElement>> {
|
|
23
|
+
Bar: ForwardRefExoticComponent<MegamenuBarProps & RefAttributes<HTMLUListElement>>;
|
|
24
|
+
Item: ForwardRefExoticComponent<MegamenuItemProps & RefAttributes<HTMLLIElement>>;
|
|
25
|
+
Trigger: ForwardRefExoticComponent<MegamenuTriggerProps & RefAttributes<HTMLButtonElement>>;
|
|
26
|
+
Panel: ForwardRefExoticComponent<MegamenuPanelProps & RefAttributes<HTMLDivElement>>;
|
|
27
|
+
Grid: ForwardRefExoticComponent<Omit<ComponentProps<"div">, "ref"> & RefAttributes<HTMLDivElement>>;
|
|
28
|
+
Group: ForwardRefExoticComponent<MegamenuGroupProps & RefAttributes<HTMLElement>>;
|
|
29
|
+
Heading: ForwardRefExoticComponent<MegamenuHeadingProps & RefAttributes<HTMLHeadingElement>>;
|
|
30
|
+
Supporting: ForwardRefExoticComponent<MegamenuSupportingProps & RefAttributes<HTMLParagraphElement>>;
|
|
31
|
+
Mobile: ForwardRefExoticComponent<MegamenuMobileProps & RefAttributes<HTMLDetailsElement>>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/megamenu/Megamenu.tsx
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
useContext,
|
|
8
|
+
useId
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
// src/classes/megamenu.ts
|
|
12
|
+
var megamenuClass = "megamenu";
|
|
13
|
+
var megamenuBarClass = "megamenu-bar";
|
|
14
|
+
var megamenuTriggerClass = "megamenu-trigger";
|
|
15
|
+
var megamenuPanelClass = "megamenu-panel";
|
|
16
|
+
var megamenuGridClass = "megamenu-grid";
|
|
17
|
+
var megamenuGroupClass = "megamenu-group";
|
|
18
|
+
var megamenuHeadingClass = "megamenu-heading";
|
|
19
|
+
var megamenuSupportingClass = "megamenu-supporting";
|
|
20
|
+
var megamenuMobileClass = "megamenu-mobile";
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
23
|
+
function r(e) {
|
|
24
|
+
var t, f, n = "";
|
|
25
|
+
if (typeof e == "string" || typeof e == "number")
|
|
26
|
+
n += e;
|
|
27
|
+
else if (typeof e == "object")
|
|
28
|
+
if (Array.isArray(e)) {
|
|
29
|
+
var o = e.length;
|
|
30
|
+
for (t = 0;t < o; t++)
|
|
31
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
32
|
+
} else
|
|
33
|
+
for (f in e)
|
|
34
|
+
e[f] && (n && (n += " "), n += f);
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
37
|
+
function clsx() {
|
|
38
|
+
for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
|
|
39
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/utils/cn.ts
|
|
44
|
+
function cn(...inputs) {
|
|
45
|
+
return clsx(inputs);
|
|
46
|
+
}
|
|
47
|
+
// src/components/megamenu/Megamenu.tsx
|
|
48
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
49
|
+
var ItemContext = createContext(null);
|
|
50
|
+
function useItem() {
|
|
51
|
+
const context = useContext(ItemContext);
|
|
52
|
+
if (!context)
|
|
53
|
+
throw new Error("Megamenu.Trigger and Panel require Megamenu.Item");
|
|
54
|
+
return context;
|
|
55
|
+
}
|
|
56
|
+
var Bar = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("ul", {
|
|
57
|
+
...props,
|
|
58
|
+
ref,
|
|
59
|
+
className: cn(megamenuBarClass, "megamenu-desktop", className)
|
|
60
|
+
}));
|
|
61
|
+
Bar.displayName = "Megamenu.Bar";
|
|
62
|
+
var Item = forwardRef(({ style, children, ...props }, ref) => {
|
|
63
|
+
const key = useId().replace(/:/g, "");
|
|
64
|
+
const panelId = `megamenu-panel-${key}`;
|
|
65
|
+
const anchorStyle = {
|
|
66
|
+
...style,
|
|
67
|
+
"--megamenu-anchor": `--megamenu-${key}`
|
|
68
|
+
};
|
|
69
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
70
|
+
value: { panelId },
|
|
71
|
+
children: /* @__PURE__ */ jsx("li", {
|
|
72
|
+
...props,
|
|
73
|
+
ref,
|
|
74
|
+
style: anchorStyle,
|
|
75
|
+
children
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
Item.displayName = "Megamenu.Item";
|
|
80
|
+
var Trigger = forwardRef(({ className, type = "button", ...props }, ref) => {
|
|
81
|
+
const { panelId } = useItem();
|
|
82
|
+
return /* @__PURE__ */ jsx("button", {
|
|
83
|
+
...props,
|
|
84
|
+
ref,
|
|
85
|
+
type,
|
|
86
|
+
popoverTarget: panelId,
|
|
87
|
+
className: cn(megamenuTriggerClass, className)
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
Trigger.displayName = "Megamenu.Trigger";
|
|
91
|
+
var Panel = forwardRef(({ full, className, ...props }, ref) => {
|
|
92
|
+
const { panelId } = useItem();
|
|
93
|
+
return /* @__PURE__ */ jsx("div", {
|
|
94
|
+
...props,
|
|
95
|
+
ref,
|
|
96
|
+
id: panelId,
|
|
97
|
+
popover: "auto",
|
|
98
|
+
className: cn(megamenuPanelClass, full && "megamenu-panel-full", className)
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
Panel.displayName = "Megamenu.Panel";
|
|
102
|
+
var Grid = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
103
|
+
...props,
|
|
104
|
+
ref,
|
|
105
|
+
className: cn(megamenuGridClass, className)
|
|
106
|
+
}));
|
|
107
|
+
Grid.displayName = "Megamenu.Grid";
|
|
108
|
+
var Group = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("section", {
|
|
109
|
+
...props,
|
|
110
|
+
ref,
|
|
111
|
+
className: cn(megamenuGroupClass, className)
|
|
112
|
+
}));
|
|
113
|
+
Group.displayName = "Megamenu.Group";
|
|
114
|
+
var Heading = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("h2", {
|
|
115
|
+
...props,
|
|
116
|
+
ref,
|
|
117
|
+
className: cn(megamenuHeadingClass, className)
|
|
118
|
+
}));
|
|
119
|
+
Heading.displayName = "Megamenu.Heading";
|
|
120
|
+
var Supporting = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("p", {
|
|
121
|
+
...props,
|
|
122
|
+
ref,
|
|
123
|
+
className: cn(megamenuSupportingClass, className)
|
|
124
|
+
}));
|
|
125
|
+
Supporting.displayName = "Megamenu.Supporting";
|
|
126
|
+
var Mobile = forwardRef(({ summary, className, children, ...props }, ref) => /* @__PURE__ */ jsxs("details", {
|
|
127
|
+
...props,
|
|
128
|
+
ref,
|
|
129
|
+
className: cn(megamenuMobileClass, className),
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx("summary", {
|
|
132
|
+
children: summary
|
|
133
|
+
}),
|
|
134
|
+
children
|
|
135
|
+
]
|
|
136
|
+
}));
|
|
137
|
+
Mobile.displayName = "Megamenu.Mobile";
|
|
138
|
+
var MegamenuRoot = forwardRef(({
|
|
139
|
+
trigger,
|
|
140
|
+
panelHeading,
|
|
141
|
+
panel,
|
|
142
|
+
mobile,
|
|
143
|
+
leading,
|
|
144
|
+
fullWidth,
|
|
145
|
+
className,
|
|
146
|
+
children,
|
|
147
|
+
...props
|
|
148
|
+
}, ref) => {
|
|
149
|
+
const key = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
150
|
+
const panelId = `dm-megamenu-${key}`;
|
|
151
|
+
const headingId = `${panelId}-heading`;
|
|
152
|
+
const anchorStyle = {
|
|
153
|
+
"--megamenu-anchor": `--dm-megamenu-${key}`
|
|
154
|
+
};
|
|
155
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
156
|
+
...props,
|
|
157
|
+
ref,
|
|
158
|
+
className: cn(megamenuClass, className),
|
|
159
|
+
children: trigger != null ? /* @__PURE__ */ jsxs(Fragment, {
|
|
160
|
+
children: [
|
|
161
|
+
/* @__PURE__ */ jsxs(Bar, {
|
|
162
|
+
children: [
|
|
163
|
+
leading != null && /* @__PURE__ */ jsx("li", {
|
|
164
|
+
children: leading
|
|
165
|
+
}),
|
|
166
|
+
/* @__PURE__ */ jsxs("li", {
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ jsx("button", {
|
|
169
|
+
type: "button",
|
|
170
|
+
className: megamenuTriggerClass,
|
|
171
|
+
popoverTarget: panelId,
|
|
172
|
+
style: anchorStyle,
|
|
173
|
+
children: trigger
|
|
174
|
+
}),
|
|
175
|
+
/* @__PURE__ */ jsxs("div", {
|
|
176
|
+
id: panelId,
|
|
177
|
+
className: cn(megamenuPanelClass, fullWidth && "megamenu-panel-full"),
|
|
178
|
+
popover: "auto",
|
|
179
|
+
"aria-labelledby": headingId,
|
|
180
|
+
style: anchorStyle,
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ jsx(Heading, {
|
|
183
|
+
id: headingId,
|
|
184
|
+
children: panelHeading
|
|
185
|
+
}),
|
|
186
|
+
panel
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
]
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ jsx("div", {
|
|
194
|
+
className: megamenuMobileClass,
|
|
195
|
+
children: mobile
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
}) : children
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
MegamenuRoot.displayName = "Megamenu";
|
|
202
|
+
MegamenuRoot.Bar = Bar;
|
|
203
|
+
MegamenuRoot.Item = Item;
|
|
204
|
+
MegamenuRoot.Trigger = Trigger;
|
|
205
|
+
MegamenuRoot.Panel = Panel;
|
|
206
|
+
MegamenuRoot.Grid = Grid;
|
|
207
|
+
MegamenuRoot.Group = Group;
|
|
208
|
+
MegamenuRoot.Heading = Heading;
|
|
209
|
+
MegamenuRoot.Supporting = Supporting;
|
|
210
|
+
MegamenuRoot.Mobile = Mobile;
|
|
211
|
+
var Megamenu = MegamenuRoot;
|
|
212
|
+
export {
|
|
213
|
+
Megamenu
|
|
214
|
+
};
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
forwardRef,
|
|
6
6
|
useCallback,
|
|
7
7
|
useEffect,
|
|
8
|
+
useId,
|
|
8
9
|
useRef,
|
|
9
10
|
useState
|
|
10
11
|
} from "react";
|
|
@@ -35,22 +36,12 @@ function cn(...inputs) {
|
|
|
35
36
|
return clsx(inputs);
|
|
36
37
|
}
|
|
37
38
|
// src/classes/modal.ts
|
|
38
|
-
var modalBackdropClass = "modal-backdrop";
|
|
39
|
-
var modalOpenClass = "modal-open";
|
|
40
|
-
var modalBackdropCenterClass = "modal-backdrop-center";
|
|
41
39
|
var modalClass = "modal";
|
|
42
40
|
var modalHeaderClass = "modal-header";
|
|
43
41
|
var modalTitleClass = "modal-title";
|
|
44
42
|
var modalCloseClass = "modal-close";
|
|
45
43
|
var modalBodyClass = "modal-body";
|
|
46
44
|
var modalFooterClass = "modal-footer";
|
|
47
|
-
function getModalBackdropClasses({
|
|
48
|
-
open,
|
|
49
|
-
centered,
|
|
50
|
-
className
|
|
51
|
-
}) {
|
|
52
|
-
return cn(modalBackdropClass, open && modalOpenClass, centered && modalBackdropCenterClass, className);
|
|
53
|
-
}
|
|
54
45
|
function getModalClasses({ className }) {
|
|
55
46
|
return cn(modalClass, className);
|
|
56
47
|
}
|
|
@@ -81,6 +72,13 @@ function getModalStyle({
|
|
|
81
72
|
...width !== undefined ? { width } : undefined
|
|
82
73
|
};
|
|
83
74
|
}
|
|
75
|
+
function showNativeModal(dialog) {
|
|
76
|
+
if (!dialog.isConnected || dialog.matches(":modal"))
|
|
77
|
+
return;
|
|
78
|
+
if (dialog.open)
|
|
79
|
+
dialog.close();
|
|
80
|
+
dialog.showModal();
|
|
81
|
+
}
|
|
84
82
|
var ModalBase = forwardRef(({
|
|
85
83
|
open,
|
|
86
84
|
defaultOpen = false,
|
|
@@ -103,15 +101,41 @@ var ModalBase = forwardRef(({
|
|
|
103
101
|
maskClassName,
|
|
104
102
|
closeIcon = defaultCloseIcon,
|
|
105
103
|
style,
|
|
106
|
-
role
|
|
104
|
+
role,
|
|
107
105
|
...props
|
|
108
106
|
}, ref) => {
|
|
109
107
|
const controlled = open !== undefined;
|
|
110
108
|
const [innerOpen, setInnerOpen] = useState(defaultOpen);
|
|
111
109
|
const mergedOpen = controlled ? Boolean(open) : innerOpen;
|
|
112
110
|
const previousOpen = useRef(mergedOpen);
|
|
111
|
+
const desiredOpen = useRef(mergedOpen);
|
|
112
|
+
desiredOpen.current = mergedOpen;
|
|
113
|
+
const dialogRef = useRef(null);
|
|
114
|
+
const cancelRequestRef = useRef(null);
|
|
115
|
+
const programmaticClose = useRef(false);
|
|
116
|
+
const titleId = useId();
|
|
117
|
+
const surfaceWidth = width ?? style?.width;
|
|
118
|
+
const callerNamed = props["aria-label"] != null || props["aria-labelledby"] != null;
|
|
113
119
|
const showClose = closable && closeIcon !== null && closeIcon !== false;
|
|
114
120
|
const body = children ?? content;
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const dialog = dialogRef.current;
|
|
123
|
+
if (!dialog)
|
|
124
|
+
return;
|
|
125
|
+
if (mergedOpen) {
|
|
126
|
+
programmaticClose.current = false;
|
|
127
|
+
showNativeModal(dialog);
|
|
128
|
+
} else if (dialog.open) {
|
|
129
|
+
programmaticClose.current = true;
|
|
130
|
+
dialog.close();
|
|
131
|
+
}
|
|
132
|
+
return () => {
|
|
133
|
+
if (dialog.open) {
|
|
134
|
+
programmaticClose.current = true;
|
|
135
|
+
dialog.close();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}, [mergedOpen]);
|
|
115
139
|
useEffect(() => {
|
|
116
140
|
if (previousOpen.current === mergedOpen) {
|
|
117
141
|
return;
|
|
@@ -128,73 +152,109 @@ var ModalBase = forwardRef(({
|
|
|
128
152
|
const handleOk = useCallback((event) => {
|
|
129
153
|
onOk?.(event);
|
|
130
154
|
}, [onOk]);
|
|
131
|
-
const
|
|
132
|
-
|
|
155
|
+
const requestCancel = useCallback(() => {
|
|
156
|
+
cancelRequestRef.current?.click();
|
|
157
|
+
}, []);
|
|
158
|
+
const handleNativeClose = useCallback(() => {
|
|
159
|
+
const dialog = dialogRef.current;
|
|
160
|
+
if (!dialog || dialog.open || programmaticClose.current) {
|
|
161
|
+
programmaticClose.current = false;
|
|
133
162
|
return;
|
|
134
163
|
}
|
|
135
|
-
|
|
136
|
-
|
|
164
|
+
if (desiredOpen.current) {
|
|
165
|
+
requestCancel();
|
|
166
|
+
if (controlled) {
|
|
167
|
+
queueMicrotask(() => {
|
|
168
|
+
if (desiredOpen.current) {
|
|
169
|
+
showNativeModal(dialog);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, [controlled, requestCancel]);
|
|
137
175
|
if (!mergedOpen && destroyOnClose) {
|
|
138
176
|
return null;
|
|
139
177
|
}
|
|
140
|
-
return /* @__PURE__ */
|
|
141
|
-
|
|
142
|
-
role: "
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
children: footer !== undefined ? footer : /* @__PURE__ */ jsxs(Fragment, {
|
|
178
|
+
return /* @__PURE__ */ jsxs("dialog", {
|
|
179
|
+
ref: dialogRef,
|
|
180
|
+
role: role === "alertdialog" ? role : undefined,
|
|
181
|
+
"aria-label": props["aria-label"] ?? (!callerNamed && title == null ? "Modal" : undefined),
|
|
182
|
+
"aria-labelledby": props["aria-labelledby"] ?? (!callerNamed && title != null ? titleId : undefined),
|
|
183
|
+
"aria-describedby": props["aria-describedby"],
|
|
184
|
+
className: getModalClasses({ className: cn(maskClassName, centered ? "modal-middle" : "modal-top") }),
|
|
185
|
+
style: surfaceWidth !== undefined ? { width: surfaceWidth, maxWidth: surfaceWidth } : undefined,
|
|
186
|
+
onCancel: (event) => {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
requestCancel();
|
|
189
|
+
},
|
|
190
|
+
onClose: handleNativeClose,
|
|
191
|
+
onMouseDown: (event) => {
|
|
192
|
+
if (!maskClosable || event.target !== event.currentTarget)
|
|
193
|
+
return;
|
|
194
|
+
const { left, right, top, bottom } = event.currentTarget.getBoundingClientRect();
|
|
195
|
+
if (event.clientX < left || event.clientX > right || event.clientY < top || event.clientY > bottom) {
|
|
196
|
+
requestCancel();
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
children: [
|
|
200
|
+
/* @__PURE__ */ jsx("button", {
|
|
201
|
+
ref: cancelRequestRef,
|
|
202
|
+
type: "button",
|
|
203
|
+
hidden: true,
|
|
204
|
+
tabIndex: -1,
|
|
205
|
+
"aria-hidden": "true",
|
|
206
|
+
onClick: close
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ jsxs("div", {
|
|
209
|
+
...props,
|
|
210
|
+
ref,
|
|
211
|
+
role,
|
|
212
|
+
className: cn("modal-box", "react-modal-box", className),
|
|
213
|
+
style: getModalStyle({ width, style }),
|
|
214
|
+
children: [
|
|
215
|
+
title !== undefined || showClose ? /* @__PURE__ */ jsxs("div", {
|
|
216
|
+
className: modalHeaderClass,
|
|
180
217
|
children: [
|
|
181
|
-
/* @__PURE__ */ jsx("
|
|
218
|
+
title !== undefined ? /* @__PURE__ */ jsx("h2", {
|
|
219
|
+
id: titleId,
|
|
220
|
+
className: modalTitleClass,
|
|
221
|
+
children: title
|
|
222
|
+
}) : null,
|
|
223
|
+
showClose ? /* @__PURE__ */ jsx("button", {
|
|
182
224
|
type: "button",
|
|
225
|
+
className: modalCloseClass,
|
|
226
|
+
"aria-label": "Close",
|
|
183
227
|
onClick: close,
|
|
184
|
-
children:
|
|
185
|
-
})
|
|
186
|
-
/* @__PURE__ */ jsx("button", {
|
|
187
|
-
type: "button",
|
|
188
|
-
"aria-busy": confirmLoading,
|
|
189
|
-
disabled: confirmLoading,
|
|
190
|
-
onClick: handleOk,
|
|
191
|
-
children: okText
|
|
192
|
-
})
|
|
228
|
+
children: closeIcon
|
|
229
|
+
}) : null
|
|
193
230
|
]
|
|
231
|
+
}) : null,
|
|
232
|
+
/* @__PURE__ */ jsx("div", {
|
|
233
|
+
className: modalBodyClass,
|
|
234
|
+
children: body
|
|
235
|
+
}),
|
|
236
|
+
footer === null ? null : /* @__PURE__ */ jsx("div", {
|
|
237
|
+
className: modalFooterClass,
|
|
238
|
+
children: footer !== undefined ? footer : /* @__PURE__ */ jsxs(Fragment, {
|
|
239
|
+
children: [
|
|
240
|
+
/* @__PURE__ */ jsx("button", {
|
|
241
|
+
type: "button",
|
|
242
|
+
onClick: close,
|
|
243
|
+
children: cancelText
|
|
244
|
+
}),
|
|
245
|
+
/* @__PURE__ */ jsx("button", {
|
|
246
|
+
type: "button",
|
|
247
|
+
"aria-busy": confirmLoading,
|
|
248
|
+
disabled: confirmLoading,
|
|
249
|
+
onClick: handleOk,
|
|
250
|
+
children: okText
|
|
251
|
+
})
|
|
252
|
+
]
|
|
253
|
+
})
|
|
194
254
|
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
255
|
+
]
|
|
256
|
+
})
|
|
257
|
+
]
|
|
198
258
|
});
|
|
199
259
|
});
|
|
200
260
|
ModalBase.displayName = "Modal";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
export type OtpInputLength = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
3
|
+
export type OtpInputSize = "xs" | "sm" | "md" | "lg" | "xl";
|
|
4
|
+
export type OtpInputVariant = "outlined" | "filled" | "underlined";
|
|
5
|
+
export type OtpInputColor = "primary" | "secondary" | "tertiary" | "info" | "success" | "warning" | "error" | "accent" | "neutral" | "base";
|
|
6
|
+
export interface OtpInputProps extends Omit<ComponentProps<"input">, "children" | "className" | "size" | "type"> {
|
|
7
|
+
/** Number of decorative slots. Native input constraints default to this length. */
|
|
8
|
+
length?: OtpInputLength;
|
|
9
|
+
size?: OtpInputSize;
|
|
10
|
+
variant?: OtpInputVariant;
|
|
11
|
+
color?: OtpInputColor;
|
|
12
|
+
/** Additional class names for the wrapping label. */
|
|
13
|
+
wrapperClassName?: string;
|
|
14
|
+
/** Additional class names for the native input. */
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|