@duskmoon-dev/components 2.0.0-rc.4 → 2.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/README.md +6 -1
- package/dist/components/settings/Settings.d.ts +7 -0
- package/dist/components/settings/Settings.types.d.ts +35 -0
- package/dist/components/settings/index.d.ts +2 -0
- package/dist/components/settings/index.js +290 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +358 -192
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +150 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ import { Button, DmTable, theme } from "@duskmoon-dev/components";
|
|
|
41
41
|
|
|
42
42
|
## Public Surface
|
|
43
43
|
|
|
44
|
-
-
|
|
44
|
+
- 80 standard components such as `Button`, `Chat`, `OtpInput`, `Swap`, `Fab`,
|
|
45
45
|
`Megamenu`, `ConsolePage`, `Table`, `Modal`, `Select`, and `Typography`.
|
|
46
46
|
- 21 DuskMoon workflow components such as `DmLayout`, `DmSearch`, `DmTable`,
|
|
47
47
|
`DmProTable`, and `DmToolbar`.
|
|
@@ -50,6 +50,11 @@ import { Button, DmTable, theme } from "@duskmoon-dev/components";
|
|
|
50
50
|
- Component subpath exports follow `@duskmoon-dev/components/{component-id}`,
|
|
51
51
|
for example `@duskmoon-dev/components/date-picker`.
|
|
52
52
|
|
|
53
|
+
Use `SettingsList`, `SettingsSection`, and `SettingsTile` from
|
|
54
|
+
`@duskmoon-dev/components/settings` for grouped preferences.
|
|
55
|
+
`SettingsTile.Link` renders a native link and `SettingsTile.Switch` takes
|
|
56
|
+
`checked` and `onCheckedChange` from the application.
|
|
57
|
+
|
|
53
58
|
`OtpInput` uses one native input with decorative slots. `Swap` uses a native
|
|
54
59
|
checkbox. `Fab`, `Megamenu`, and the mobile menu in `ConsolePage` use the
|
|
55
60
|
browser's Popover API for opening, Escape dismissal, and focus restoration.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SettingsLinkTileProps, SettingsSectionProps, SettingsSwitchTileProps, SettingsTileProps } from "./Settings.types.js";
|
|
2
|
+
export declare const SettingsList: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
3
|
+
export declare const SettingsSection: import("react").ForwardRefExoticComponent<SettingsSectionProps & import("react").RefAttributes<HTMLElement>>;
|
|
4
|
+
export declare const SettingsTile: import("react").ForwardRefExoticComponent<SettingsTileProps & import("react").RefAttributes<HTMLLIElement>> & {
|
|
5
|
+
Link: import("react").ForwardRefExoticComponent<SettingsLinkTileProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
6
|
+
Switch: import("react").ForwardRefExoticComponent<SettingsSwitchTileProps & import("react").RefAttributes<HTMLLIElement>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import type { SwitchChangeEvent } from "../switch/index.js";
|
|
3
|
+
export type SettingsListProps = ComponentPropsWithoutRef<"div">;
|
|
4
|
+
export interface SettingsSectionProps extends Omit<ComponentPropsWithoutRef<"section">, "title"> {
|
|
5
|
+
/** Visible heading for the group. */
|
|
6
|
+
title: ReactNode;
|
|
7
|
+
/** Supporting information displayed under the group. */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
10
|
+
}
|
|
11
|
+
interface SettingsTileContent {
|
|
12
|
+
/** Visible name of the setting. */
|
|
13
|
+
title: ReactNode;
|
|
14
|
+
description?: ReactNode;
|
|
15
|
+
/** Decorative icon shown before the setting. */
|
|
16
|
+
leading?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export interface SettingsTileProps extends Omit<ComponentPropsWithoutRef<"li">, "title" | "children">, SettingsTileContent {
|
|
19
|
+
/** Current value or a custom control with its own accessible name. */
|
|
20
|
+
trailing?: ReactNode;
|
|
21
|
+
/** Place a wider control on its own line. */
|
|
22
|
+
stacked?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface SettingsLinkTileProps extends Omit<ComponentPropsWithoutRef<"a">, "title" | "href" | "children">, SettingsTileContent {
|
|
25
|
+
href: string;
|
|
26
|
+
/** Current value shown inside the link. */
|
|
27
|
+
value?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SettingsSwitchTileProps extends Omit<SettingsTileProps, "stacked" | "trailing"> {
|
|
30
|
+
checked: boolean;
|
|
31
|
+
onCheckedChange: (checked: boolean, event: SwitchChangeEvent) => void;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
name?: string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/switch/Switch.tsx
|
|
4
|
+
import { forwardRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
// ../../../node_modules/clsx/dist/clsx.mjs
|
|
7
|
+
function r(e) {
|
|
8
|
+
var t, f, n = "";
|
|
9
|
+
if (typeof e == "string" || typeof e == "number")
|
|
10
|
+
n += e;
|
|
11
|
+
else if (typeof e == "object")
|
|
12
|
+
if (Array.isArray(e)) {
|
|
13
|
+
var o = e.length;
|
|
14
|
+
for (t = 0;t < o; t++)
|
|
15
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
16
|
+
} else
|
|
17
|
+
for (f in e)
|
|
18
|
+
e[f] && (n && (n += " "), n += f);
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
function clsx() {
|
|
22
|
+
for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
|
|
23
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/utils/cn.ts
|
|
28
|
+
function cn(...inputs) {
|
|
29
|
+
return clsx(inputs);
|
|
30
|
+
}
|
|
31
|
+
// src/classes/switch.ts
|
|
32
|
+
var switchBaseClass = "switch";
|
|
33
|
+
var switchInputClass = "switch-input";
|
|
34
|
+
var switchTrackClass = "switch-track";
|
|
35
|
+
var switchThumbClass = "switch-thumb";
|
|
36
|
+
var switchLoadingClass = "switch-loading";
|
|
37
|
+
var switchSizeClasses = {
|
|
38
|
+
sm: "switch-sm",
|
|
39
|
+
md: "",
|
|
40
|
+
lg: "switch-lg"
|
|
41
|
+
};
|
|
42
|
+
var switchColorClasses = {
|
|
43
|
+
primary: "switch-primary",
|
|
44
|
+
secondary: "switch-secondary",
|
|
45
|
+
tertiary: "switch-tertiary",
|
|
46
|
+
accent: "switch-accent",
|
|
47
|
+
neutral: "switch-neutral",
|
|
48
|
+
base: "switch-base",
|
|
49
|
+
info: "switch-info",
|
|
50
|
+
success: "switch-success",
|
|
51
|
+
warning: "switch-warning",
|
|
52
|
+
error: "switch-error"
|
|
53
|
+
};
|
|
54
|
+
function getSwitchClasses({
|
|
55
|
+
size = "md",
|
|
56
|
+
loading,
|
|
57
|
+
className
|
|
58
|
+
}) {
|
|
59
|
+
return cn(switchBaseClass, switchSizeClasses[size], loading && switchLoadingClass, className);
|
|
60
|
+
}
|
|
61
|
+
function getSwitchTrackClasses({
|
|
62
|
+
color = "primary"
|
|
63
|
+
}) {
|
|
64
|
+
return cn(switchTrackClass, switchColorClasses[color]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/components/switch/Switch.tsx
|
|
68
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
69
|
+
var Switch = forwardRef(({
|
|
70
|
+
checked,
|
|
71
|
+
defaultChecked,
|
|
72
|
+
onChange,
|
|
73
|
+
disabled,
|
|
74
|
+
loading,
|
|
75
|
+
size = "md",
|
|
76
|
+
color = "primary",
|
|
77
|
+
checkedChildren,
|
|
78
|
+
unCheckedChildren,
|
|
79
|
+
className,
|
|
80
|
+
...props
|
|
81
|
+
}, ref) => {
|
|
82
|
+
const [internalChecked, setInternalChecked] = useState(() => defaultChecked ?? false);
|
|
83
|
+
const isControlled = checked !== undefined;
|
|
84
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
85
|
+
const isDisabled = disabled || loading;
|
|
86
|
+
const hasChildren = checkedChildren != null || unCheckedChildren != null;
|
|
87
|
+
function handleChange(event) {
|
|
88
|
+
const nextChecked = event.currentTarget.checked;
|
|
89
|
+
if (!isControlled) {
|
|
90
|
+
setInternalChecked(nextChecked);
|
|
91
|
+
}
|
|
92
|
+
onChange?.(nextChecked, event);
|
|
93
|
+
}
|
|
94
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
95
|
+
className: getSwitchClasses({ size, loading, className }),
|
|
96
|
+
children: [
|
|
97
|
+
/* @__PURE__ */ jsx("input", {
|
|
98
|
+
...props,
|
|
99
|
+
ref,
|
|
100
|
+
type: "checkbox",
|
|
101
|
+
role: "switch",
|
|
102
|
+
className: switchInputClass,
|
|
103
|
+
checked: isChecked,
|
|
104
|
+
disabled: isDisabled,
|
|
105
|
+
"aria-checked": isChecked,
|
|
106
|
+
"aria-busy": loading || undefined,
|
|
107
|
+
onChange: handleChange
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsxs("span", {
|
|
110
|
+
className: getSwitchTrackClasses({ color }),
|
|
111
|
+
"aria-hidden": "true",
|
|
112
|
+
children: [
|
|
113
|
+
hasChildren && /* @__PURE__ */ jsx("span", {
|
|
114
|
+
children: isChecked ? checkedChildren : unCheckedChildren
|
|
115
|
+
}),
|
|
116
|
+
/* @__PURE__ */ jsx("span", {
|
|
117
|
+
className: switchThumbClass
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
Switch.displayName = "Switch";
|
|
125
|
+
// src/components/settings/Settings.tsx
|
|
126
|
+
import { forwardRef as forwardRef2, useId } from "react";
|
|
127
|
+
import { jsx as jsx2, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
128
|
+
var SettingsList = forwardRef2(({ className, ...props }, ref) => /* @__PURE__ */ jsx2("div", {
|
|
129
|
+
...props,
|
|
130
|
+
ref,
|
|
131
|
+
className: cn("settings-list", className)
|
|
132
|
+
}));
|
|
133
|
+
SettingsList.displayName = "SettingsList";
|
|
134
|
+
var SettingsSection = forwardRef2(({ title, description, headingLevel = 2, className, children, ...props }, ref) => {
|
|
135
|
+
const headingId = useId();
|
|
136
|
+
const descriptionId = `${headingId}-description`;
|
|
137
|
+
const Heading = `h${headingLevel}`;
|
|
138
|
+
return /* @__PURE__ */ jsxs2("section", {
|
|
139
|
+
"aria-labelledby": headingId,
|
|
140
|
+
"aria-describedby": description != null ? descriptionId : undefined,
|
|
141
|
+
...props,
|
|
142
|
+
ref,
|
|
143
|
+
className: cn("settings-section", className),
|
|
144
|
+
children: [
|
|
145
|
+
/* @__PURE__ */ jsx2(Heading, {
|
|
146
|
+
className: "settings-section-title",
|
|
147
|
+
id: headingId,
|
|
148
|
+
children: title
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ jsx2("ul", {
|
|
151
|
+
className: "settings-section-items",
|
|
152
|
+
role: "list",
|
|
153
|
+
children
|
|
154
|
+
}),
|
|
155
|
+
description != null && /* @__PURE__ */ jsx2("div", {
|
|
156
|
+
className: "settings-section-description",
|
|
157
|
+
id: descriptionId,
|
|
158
|
+
children: description
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
SettingsSection.displayName = "SettingsSection";
|
|
164
|
+
function TileContent({
|
|
165
|
+
title,
|
|
166
|
+
description,
|
|
167
|
+
leading,
|
|
168
|
+
titleId,
|
|
169
|
+
descriptionId
|
|
170
|
+
}) {
|
|
171
|
+
return /* @__PURE__ */ jsxs2(Fragment, {
|
|
172
|
+
children: [
|
|
173
|
+
leading != null && /* @__PURE__ */ jsx2("span", {
|
|
174
|
+
className: "settings-row-leading",
|
|
175
|
+
"aria-hidden": "true",
|
|
176
|
+
children: leading
|
|
177
|
+
}),
|
|
178
|
+
/* @__PURE__ */ jsxs2("span", {
|
|
179
|
+
className: "settings-row-content",
|
|
180
|
+
children: [
|
|
181
|
+
/* @__PURE__ */ jsx2("span", {
|
|
182
|
+
className: "settings-row-title",
|
|
183
|
+
id: titleId,
|
|
184
|
+
children: title
|
|
185
|
+
}),
|
|
186
|
+
description != null && /* @__PURE__ */ jsx2("span", {
|
|
187
|
+
className: "settings-row-description",
|
|
188
|
+
id: descriptionId,
|
|
189
|
+
children: description
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
var StaticTile = forwardRef2(({ title, description, leading, trailing, stacked, ...props }, ref) => /* @__PURE__ */ jsx2("li", {
|
|
197
|
+
...props,
|
|
198
|
+
ref,
|
|
199
|
+
children: /* @__PURE__ */ jsxs2("div", {
|
|
200
|
+
className: cn("settings-row", stacked && "settings-row-stacked"),
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ jsx2(TileContent, {
|
|
203
|
+
title,
|
|
204
|
+
description,
|
|
205
|
+
leading
|
|
206
|
+
}),
|
|
207
|
+
trailing != null && /* @__PURE__ */ jsx2("div", {
|
|
208
|
+
className: "settings-row-trailing",
|
|
209
|
+
children: trailing
|
|
210
|
+
})
|
|
211
|
+
]
|
|
212
|
+
})
|
|
213
|
+
}));
|
|
214
|
+
StaticTile.displayName = "SettingsTile";
|
|
215
|
+
var LinkTile = forwardRef2(({ title, description, leading, value, className, ...props }, ref) => /* @__PURE__ */ jsx2("li", {
|
|
216
|
+
children: /* @__PURE__ */ jsxs2("a", {
|
|
217
|
+
...props,
|
|
218
|
+
ref,
|
|
219
|
+
className: cn("settings-row", className),
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx2(TileContent, {
|
|
222
|
+
title,
|
|
223
|
+
description,
|
|
224
|
+
leading
|
|
225
|
+
}),
|
|
226
|
+
/* @__PURE__ */ jsxs2("span", {
|
|
227
|
+
className: "settings-row-trailing",
|
|
228
|
+
children: [
|
|
229
|
+
value,
|
|
230
|
+
/* @__PURE__ */ jsx2("span", {
|
|
231
|
+
className: "settings-row-chevron",
|
|
232
|
+
"aria-hidden": "true"
|
|
233
|
+
})
|
|
234
|
+
]
|
|
235
|
+
})
|
|
236
|
+
]
|
|
237
|
+
})
|
|
238
|
+
}));
|
|
239
|
+
LinkTile.displayName = "SettingsTile.Link";
|
|
240
|
+
var SwitchTile = forwardRef2(({
|
|
241
|
+
title,
|
|
242
|
+
description,
|
|
243
|
+
leading,
|
|
244
|
+
checked,
|
|
245
|
+
onCheckedChange,
|
|
246
|
+
disabled,
|
|
247
|
+
name,
|
|
248
|
+
...props
|
|
249
|
+
}, ref) => {
|
|
250
|
+
const id = useId();
|
|
251
|
+
const titleId = `${id}-title`;
|
|
252
|
+
const descriptionId = `${id}-description`;
|
|
253
|
+
return /* @__PURE__ */ jsx2("li", {
|
|
254
|
+
...props,
|
|
255
|
+
ref,
|
|
256
|
+
children: /* @__PURE__ */ jsxs2("div", {
|
|
257
|
+
className: "settings-row",
|
|
258
|
+
children: [
|
|
259
|
+
/* @__PURE__ */ jsx2(TileContent, {
|
|
260
|
+
title,
|
|
261
|
+
description,
|
|
262
|
+
leading,
|
|
263
|
+
titleId,
|
|
264
|
+
descriptionId
|
|
265
|
+
}),
|
|
266
|
+
/* @__PURE__ */ jsx2("div", {
|
|
267
|
+
className: "settings-row-trailing",
|
|
268
|
+
children: /* @__PURE__ */ jsx2(Switch, {
|
|
269
|
+
checked,
|
|
270
|
+
disabled,
|
|
271
|
+
name,
|
|
272
|
+
onChange: onCheckedChange,
|
|
273
|
+
"aria-labelledby": titleId,
|
|
274
|
+
"aria-describedby": description != null ? descriptionId : undefined
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
]
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
SwitchTile.displayName = "SettingsTile.Switch";
|
|
282
|
+
var SettingsTile = Object.assign(StaticTile, {
|
|
283
|
+
Link: LinkTile,
|
|
284
|
+
Switch: SwitchTile
|
|
285
|
+
});
|
|
286
|
+
export {
|
|
287
|
+
SettingsList,
|
|
288
|
+
SettingsSection,
|
|
289
|
+
SettingsTile
|
|
290
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.1.0";
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ export * from "./components/spin/index.js";
|
|
|
88
88
|
export * from "./components/splitter/index.js";
|
|
89
89
|
export * from "./components/statistic/index.js";
|
|
90
90
|
export * from "./components/steps/index.js";
|
|
91
|
+
export * from "./components/settings/index.js";
|
|
91
92
|
export * from "./components/switch/index.js";
|
|
92
93
|
export * from "./components/swap/index.js";
|
|
93
94
|
export * from "./components/tabs/index.js";
|