@sharadox/graphical-user-interface-web-library 0.0.0-stage → 0.2.0-development.11
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/LICENCA.md +76 -0
- package/LICENSE.md +76 -0
- package/NOTICE.md +3 -0
- package/README.md +174 -2
- package/distribution/box/index.d.ts +14 -0
- package/distribution/box/index.d.ts.map +1 -0
- package/distribution/box/index.js +52 -0
- package/distribution/box/index.js.map +1 -0
- package/distribution/box/index.module.css +1 -0
- package/distribution/box/index.module.scss +130 -0
- package/distribution/box/type.d.ts +56 -0
- package/distribution/box/type.d.ts.map +1 -0
- package/distribution/box/type.js +2 -0
- package/distribution/box/type.js.map +1 -0
- package/distribution/box-axis/index.d.ts +24 -0
- package/distribution/box-axis/index.d.ts.map +1 -0
- package/distribution/box-axis/index.js +114 -0
- package/distribution/box-axis/index.js.map +1 -0
- package/distribution/box-axis/type.d.ts +15 -0
- package/distribution/box-axis/type.d.ts.map +1 -0
- package/distribution/box-axis/type.js +2 -0
- package/distribution/box-axis/type.js.map +1 -0
- package/distribution/button/index.d.ts +15 -0
- package/distribution/button/index.d.ts.map +1 -0
- package/distribution/button/index.js +42 -0
- package/distribution/button/index.js.map +1 -0
- package/distribution/button/type.d.ts +37 -0
- package/distribution/button/type.d.ts.map +1 -0
- package/distribution/button/type.js +2 -0
- package/distribution/button/type.js.map +1 -0
- package/distribution/button-axis/index.d.ts +13 -0
- package/distribution/button-axis/index.d.ts.map +1 -0
- package/distribution/button-axis/index.js +13 -0
- package/distribution/button-axis/index.js.map +1 -0
- package/distribution/checkbox/index.d.ts +10 -0
- package/distribution/checkbox/index.d.ts.map +1 -0
- package/distribution/checkbox/index.js +21 -0
- package/distribution/checkbox/index.js.map +1 -0
- package/distribution/checkbox/type.d.ts +9 -0
- package/distribution/checkbox/type.d.ts.map +1 -0
- package/distribution/checkbox/type.js +2 -0
- package/distribution/checkbox/type.js.map +1 -0
- package/distribution/choice/index.d.ts +11 -0
- package/distribution/choice/index.d.ts.map +1 -0
- package/distribution/choice/index.js +35 -0
- package/distribution/choice/index.js.map +1 -0
- package/distribution/choice/type.d.ts +19 -0
- package/distribution/choice/type.d.ts.map +1 -0
- package/distribution/choice/type.js +2 -0
- package/distribution/choice/type.js.map +1 -0
- package/distribution/field/index.d.ts +11 -0
- package/distribution/field/index.d.ts.map +1 -0
- package/distribution/field/index.js +26 -0
- package/distribution/field/index.js.map +1 -0
- package/distribution/field/index.module.css +1 -0
- package/distribution/field/index.module.scss +21 -0
- package/distribution/field/type.d.ts +23 -0
- package/distribution/field/type.d.ts.map +1 -0
- package/distribution/field/type.js +2 -0
- package/distribution/field/type.js.map +1 -0
- package/distribution/interface-configuration/index.d.ts +23 -0
- package/distribution/interface-configuration/index.d.ts.map +1 -0
- package/distribution/interface-configuration/index.js +160 -0
- package/distribution/interface-configuration/index.js.map +1 -0
- package/distribution/interface-configuration/type.d.ts +83 -0
- package/distribution/interface-configuration/type.d.ts.map +1 -0
- package/distribution/interface-configuration/type.js +2 -0
- package/distribution/interface-configuration/type.js.map +1 -0
- package/distribution/interface-style/index.d.ts +11 -0
- package/distribution/interface-style/index.d.ts.map +1 -0
- package/distribution/interface-style/index.js +14 -0
- package/distribution/interface-style/index.js.map +1 -0
- package/distribution/interface-style/type.d.ts +6 -0
- package/distribution/interface-style/type.d.ts.map +1 -0
- package/distribution/interface-style/type.js +2 -0
- package/distribution/interface-style/type.js.map +1 -0
- package/distribution/interface-styles/index.d.ts +13 -0
- package/distribution/interface-styles/index.d.ts.map +1 -0
- package/distribution/interface-styles/index.js +37 -0
- package/distribution/interface-styles/index.js.map +1 -0
- package/distribution/radio-group/index.d.ts +11 -0
- package/distribution/radio-group/index.d.ts.map +1 -0
- package/distribution/radio-group/index.js +27 -0
- package/distribution/radio-group/index.js.map +1 -0
- package/distribution/radio-group/index.module.css +1 -0
- package/distribution/radio-group/index.module.scss +10 -0
- package/distribution/radio-group/type.d.ts +25 -0
- package/distribution/radio-group/type.d.ts.map +1 -0
- package/distribution/radio-group/type.js +2 -0
- package/distribution/radio-group/type.js.map +1 -0
- package/distribution/responsive/index.d.ts +10 -0
- package/distribution/responsive/index.d.ts.map +1 -0
- package/distribution/responsive/index.js +23 -0
- package/distribution/responsive/index.js.map +1 -0
- package/distribution/responsive/type.d.ts +12 -0
- package/distribution/responsive/type.d.ts.map +1 -0
- package/distribution/responsive/type.js +2 -0
- package/distribution/responsive/type.js.map +1 -0
- package/distribution/spinner/index.d.ts +11 -0
- package/distribution/spinner/index.d.ts.map +1 -0
- package/distribution/spinner/index.js +16 -0
- package/distribution/spinner/index.js.map +1 -0
- package/distribution/spinner/index.module.css +1 -0
- package/distribution/spinner/index.module.scss +41 -0
- package/distribution/spinner/type.d.ts +4 -0
- package/distribution/spinner/type.d.ts.map +1 -0
- package/distribution/spinner/type.js +2 -0
- package/distribution/spinner/type.js.map +1 -0
- package/distribution/style-sheet/index.d.ts +18 -0
- package/distribution/style-sheet/index.d.ts.map +1 -0
- package/distribution/style-sheet/index.js +166 -0
- package/distribution/style-sheet/index.js.map +1 -0
- package/distribution/style-switch/index.d.ts +10 -0
- package/distribution/style-switch/index.d.ts.map +1 -0
- package/distribution/style-switch/index.js +16 -0
- package/distribution/style-switch/index.js.map +1 -0
- package/distribution/style-switch/type.d.ts +15 -0
- package/distribution/style-switch/type.d.ts.map +1 -0
- package/distribution/style-switch/type.js +2 -0
- package/distribution/style-switch/type.js.map +1 -0
- package/distribution/switch/index.d.ts +11 -0
- package/distribution/switch/index.d.ts.map +1 -0
- package/distribution/switch/index.js +44 -0
- package/distribution/switch/index.js.map +1 -0
- package/distribution/switch/index.module.css +1 -0
- package/distribution/switch/index.module.scss +70 -0
- package/distribution/switch/type.d.ts +20 -0
- package/distribution/switch/type.d.ts.map +1 -0
- package/distribution/switch/type.js +2 -0
- package/distribution/switch/type.js.map +1 -0
- package/distribution/text-field/index.d.ts +13 -0
- package/distribution/text-field/index.d.ts.map +1 -0
- package/distribution/text-field/index.js +21 -0
- package/distribution/text-field/index.js.map +1 -0
- package/distribution/text-field/index.module.css +1 -0
- package/distribution/text-field/index.module.scss +42 -0
- package/distribution/text-field/type.d.ts +27 -0
- package/distribution/text-field/type.d.ts.map +1 -0
- package/distribution/text-field/type.js +2 -0
- package/distribution/text-field/type.js.map +1 -0
- package/distribution/toggle-mark/index.d.ts +11 -0
- package/distribution/toggle-mark/index.d.ts.map +1 -0
- package/distribution/toggle-mark/index.js +18 -0
- package/distribution/toggle-mark/index.js.map +1 -0
- package/distribution/toggle-mark/index.module.css +1 -0
- package/distribution/toggle-mark/index.module.scss +57 -0
- package/distribution/toggle-mark/type.d.ts +13 -0
- package/distribution/toggle-mark/type.d.ts.map +1 -0
- package/distribution/toggle-mark/type.js +2 -0
- package/distribution/toggle-mark/type.js.map +1 -0
- package/package.json +100 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { classNames } from "@sharadox/web-library/class-name";
|
|
3
|
+
import styles from "./index.module.css";
|
|
4
|
+
const BARS = Array.from({ length: 8 }, (_, bar) => bar);
|
|
5
|
+
/**
|
|
6
|
+
* The loading spinner: eight bars in a circle, each lighting up one after another clockwise and fading, so it leaves a
|
|
7
|
+
* trail. It is the size of the text around it (`1em`), in its color, and hidden from screen readers (the busy element
|
|
8
|
+
* says it is busy).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <Spinner />
|
|
12
|
+
*/
|
|
13
|
+
export function Spinner({ className }) {
|
|
14
|
+
return (_jsx("span", { className: classNames(styles.spinner, className), "data-spinner": "", "aria-hidden": "true", children: BARS.map((bar) => (_jsx("span", { className: styles.bar, style: { "--spinner-bar": String(bar) } }, bar))) }));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/spinner/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAE9D,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,SAAS,EAAqB;IACtD,OAAO,CACL,eAAM,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,kBAAe,EAAE,iBAAa,MAAM,YACvF,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CACjB,eAAgB,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,EAAmB,IAApF,GAAG,CAAqF,CACpG,CAAC,GACG,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:where(.spinner){position:relative;display:inline-block;flex:none;inline-size:1em;block-size:1em;color:inherit}:where(.bar){position:absolute;inset-block-start:0;inset-inline-start:calc(50% - .0625em);inline-size:.125em;block-size:.3em;border-radius:.0625em;background:currentcolor;transform:rotate(calc(var(--spinner-bar) * 45deg));transform-origin:50% .5em;opacity:.15;animation:trail var(--spinner-duration) linear infinite;animation-delay:calc(var(--spinner-bar)*var(--spinner-duration)/8 - var(--spinner-duration))}@keyframes trail{0%{opacity:1}100%{opacity:.15}}@media(prefers-reduced-motion: reduce){:where(.bar){animation-duration:calc(var(--spinner-duration)*2)}}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
:where(.spinner) {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
flex: none;
|
|
5
|
+
inline-size: 1em;
|
|
6
|
+
block-size: 1em;
|
|
7
|
+
color: inherit;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:where(.bar) {
|
|
11
|
+
position: absolute;
|
|
12
|
+
inset-block-start: 0;
|
|
13
|
+
inset-inline-start: calc(50% - 0.0625em);
|
|
14
|
+
inline-size: 0.125em;
|
|
15
|
+
block-size: 0.3em;
|
|
16
|
+
border-radius: 0.0625em;
|
|
17
|
+
background: currentcolor;
|
|
18
|
+
transform: rotate(calc(var(--spinner-bar) * 45deg));
|
|
19
|
+
transform-origin: 50% 0.5em;
|
|
20
|
+
opacity: 0.15;
|
|
21
|
+
// Each bar starts one eighth of the turn after the one before it: the light runs clockwise and leaves a trail.
|
|
22
|
+
animation: trail var(--spinner-duration) linear infinite;
|
|
23
|
+
animation-delay: calc(var(--spinner-bar) * var(--spinner-duration) / 8 - var(--spinner-duration));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@keyframes trail {
|
|
27
|
+
0% {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
100% {
|
|
32
|
+
opacity: 0.15;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@media (prefers-reduced-motion: reduce) {
|
|
37
|
+
:where(.bar) {
|
|
38
|
+
// Still moving (it means "busy"), but slower.
|
|
39
|
+
animation-duration: calc(var(--spinner-duration) * 2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/spinner/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/spinner/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { InterfaceConfiguration } from "@sharadox/graphical-user-interface-web-library/interface-configuration/type";
|
|
2
|
+
/**
|
|
3
|
+
* The whole interface as CSS, from its configuration alone. Each value has one source:
|
|
4
|
+
* - the root holds the shared values, the scale, the breakpoints, every size, corner and line, and the defaults;
|
|
5
|
+
* - each color style (`[data-style-color="black"]`, also on any element, and `inherit`, which follows the device) holds
|
|
6
|
+
* only its sources: the constant colors' channels and the colors it chooses;
|
|
7
|
+
* - every scope derives every value of every color from them (`--red-color`, `--red-transparent-color`,
|
|
8
|
+
* `--red-border-color`, `--red-on-color`, `--red-color-paint`…), so switching a style changes only the sources;
|
|
9
|
+
* - `[data-color="red"]` points a component's `--current-*` values at red, derived on the component, so overriding a
|
|
10
|
+
* shared value (an alpha) on one component changes only that component;
|
|
11
|
+
* - `data-style-corner`, `data-style-line` and `data-size` switch their values the same way;
|
|
12
|
+
* - every attribute has a version per breakpoint (`data-color-960`), mobile first.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <style>{interfaceStyleSheet(defineInterface({ colors: { brand: { of: "blue" } } }))}</style>
|
|
16
|
+
*/
|
|
17
|
+
export declare function interfaceStyleSheet(configuration: InterfaceConfiguration): string;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-sheet/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,6EAA6E,CAAC;AA6IrF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,sBAAsB,GAAG,MAAM,CAoDjF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { INHERIT_COLOR_STYLE, isReference, } from "@sharadox/graphical-user-interface-web-library/interface-configuration";
|
|
2
|
+
import { BOX_INITIAL_VALUES, boxAxes } from "@sharadox/graphical-user-interface-web-library/box-axis";
|
|
3
|
+
/** The parts of a color that a reference takes from the color it points to, unless it sets them itself. */
|
|
4
|
+
const PARTS = ["transparent", "on", "hover"];
|
|
5
|
+
const block = (selector, declarations) => `${selector}{${declarations.join(";")}}`;
|
|
6
|
+
const media = (query, rules) => `@media ${query}{${rules.join("")}}`;
|
|
7
|
+
const attribute = (name, breakpoint) => (breakpoint ? `${name}-${breakpoint}` : name);
|
|
8
|
+
const select = (name, value, breakpoint) => `[${attribute(name, breakpoint)}="${value}"]`;
|
|
9
|
+
/** The source of a color's part (`on`, `transparent`, `hover`) when the color itself names it. */
|
|
10
|
+
function ownPart(name, color, part) {
|
|
11
|
+
const chosen = color[part];
|
|
12
|
+
if (chosen)
|
|
13
|
+
return `--${name}-${part}-color-rgb:var(--${chosen}-color-rgb)`;
|
|
14
|
+
if (isReference(color))
|
|
15
|
+
return undefined;
|
|
16
|
+
const fallback = { on: "foreground", transparent: name, hover: name }[part];
|
|
17
|
+
return `--${name}-${part}-color-rgb:var(--${fallback}-color-rgb)`;
|
|
18
|
+
}
|
|
19
|
+
/** What a reference takes from the color it points to: its channels, its gradient and every part it doesn't set. */
|
|
20
|
+
function referenceDeclarations(name, color, target) {
|
|
21
|
+
return [
|
|
22
|
+
`--${name}-color-rgb:var(--${target}-color-rgb)`,
|
|
23
|
+
`--${name}-color-gradient:var(--${target}-color-gradient)`,
|
|
24
|
+
...PARTS.filter((part) => !color[part]).map((part) => `--${name}-${part}-color-rgb:var(--${target}-${part}-color-rgb)`),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
/** A color style's sources: each constant color's channels and gradient, and the colors chosen per style. */
|
|
28
|
+
function colorStyleDeclarations(configuration, style) {
|
|
29
|
+
const declarations = [`color-scheme:${configuration.colorStyles[style].scheme}`];
|
|
30
|
+
for (const [name, color] of Object.entries(configuration.colors)) {
|
|
31
|
+
if (!isReference(color)) {
|
|
32
|
+
declarations.push(`--${name}-color-rgb:${color.rgb[style]}`);
|
|
33
|
+
if (color.gradient?.[style])
|
|
34
|
+
declarations.push(`--${name}-color-gradient:${color.gradient[style]}`);
|
|
35
|
+
}
|
|
36
|
+
else if (typeof color.of !== "string") {
|
|
37
|
+
declarations.push(...referenceDeclarations(name, color, color.of[style]));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return declarations;
|
|
41
|
+
}
|
|
42
|
+
/** Every value of a color, derived in each scope from its sources, so a style switched anywhere reaches them all. */
|
|
43
|
+
function derivedDeclarations(name, color) {
|
|
44
|
+
const color_ = `--${name}`;
|
|
45
|
+
const fixedReference = isReference(color) && typeof color.of === "string" ? color.of : undefined;
|
|
46
|
+
return [
|
|
47
|
+
...(fixedReference ? referenceDeclarations(name, color, fixedReference) : []),
|
|
48
|
+
...PARTS.map((part) => ownPart(name, color, part)).filter((declaration) => declaration !== undefined),
|
|
49
|
+
`${color_}-color-rgb-alpha:var(--color-rgb-alpha)`,
|
|
50
|
+
`${color_}-color:rgb(var(${color_}-color-rgb) / var(${color_}-color-rgb-alpha))`,
|
|
51
|
+
`${color_}-transparent-color-rgb-alpha:var(--transparent-color-rgb-alpha)`,
|
|
52
|
+
`${color_}-transparent-color:rgb(var(${color_}-transparent-color-rgb) / var(${color_}-transparent-color-rgb-alpha))`,
|
|
53
|
+
...["hover", "active"].flatMap((state) => [
|
|
54
|
+
`${color_}-transparent-${state}-color-rgb-alpha:var(--transparent-${state}-color-rgb-alpha)`,
|
|
55
|
+
`${color_}-transparent-${state}-color:rgb(var(${color_}-transparent-color-rgb) / var(${color_}-transparent-${state}-color-rgb-alpha))`,
|
|
56
|
+
]),
|
|
57
|
+
`${color_}-border-color:var(${color_}-transparent-color)`,
|
|
58
|
+
`${color_}-on-color:rgb(var(${color_}-on-color-rgb))`,
|
|
59
|
+
`${color_}-hover-color:rgb(var(${color_}-hover-color-rgb) / var(${color_}-color-rgb-alpha))`,
|
|
60
|
+
`${color_}-color-paint:var(${color_}-color-gradient, linear-gradient(var(${color_}-color), var(${color_}-color)))`,
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
/** The same values for the color a component wears (`--current-*`), derived on the component itself. */
|
|
64
|
+
const CURRENT = derivedDeclarations("current", { rgb: {} }).filter((declaration) => !/^--current-(on|transparent|hover)-color-rgb:/.test(declaration));
|
|
65
|
+
/** Points a component's current values at one color. */
|
|
66
|
+
const currentColor = (name) => [
|
|
67
|
+
`--current-color-rgb:var(--${name}-color-rgb)`,
|
|
68
|
+
`--current-color-gradient:var(--${name}-color-gradient)`,
|
|
69
|
+
...PARTS.map((part) => `--current-${part}-color-rgb:var(--${name}-${part}-color-rgb)`),
|
|
70
|
+
];
|
|
71
|
+
const declare = (declarations) => Object.entries(declarations).map(([name, value]) => `--${name}:${value}`);
|
|
72
|
+
/**
|
|
73
|
+
* One axis's rules: each value at rest, then hovered and pressed on interactive boxes, whether the state is real or
|
|
74
|
+
* forced (`data-state="hover"`). Hover and pressed repeat the rest values under theirs, so a breakpoint's value
|
|
75
|
+
* replaces the base value's whole look.
|
|
76
|
+
*/
|
|
77
|
+
function axisRules(axis, breakpoint) {
|
|
78
|
+
const rules = [];
|
|
79
|
+
// When any value changes on hover, every value writes its hover rules: a breakpoint's value must beat the base
|
|
80
|
+
// value's hover rules, which are more specific than its own rest rule.
|
|
81
|
+
const stateful = Object.values(axis.values).some((value) => value.hover || value.active);
|
|
82
|
+
for (const [name, value] of Object.entries(axis.values)) {
|
|
83
|
+
const selector = select(axis.attribute, name, breakpoint);
|
|
84
|
+
rules.push(block(selector, declare(value.rest)));
|
|
85
|
+
const hover = declare({ ...value.rest, ...value.hover });
|
|
86
|
+
const active = declare({ ...value.rest, ...value.hover, ...value.active });
|
|
87
|
+
if (!stateful)
|
|
88
|
+
continue;
|
|
89
|
+
rules.push(block(`[data-interactive][data-state="hover"]${selector}`, hover));
|
|
90
|
+
rules.push(media("(hover:hover)", [block(`[data-interactive][data-state="enabled"]:hover${selector}`, hover)]));
|
|
91
|
+
rules.push(block(`[data-interactive][data-state="active"]${selector},[data-interactive][data-state="enabled"]:active${selector}`, active));
|
|
92
|
+
}
|
|
93
|
+
return rules;
|
|
94
|
+
}
|
|
95
|
+
/** The rules that depend on an attribute's value, for the base attribute or one breakpoint's. */
|
|
96
|
+
function attributeRules(configuration, breakpoint) {
|
|
97
|
+
const { colorStyles, inheritColorStyles } = configuration;
|
|
98
|
+
const rules = Object.keys(colorStyles).map((style) => block(select("data-style-color", style, breakpoint), colorStyleDeclarations(configuration, style)));
|
|
99
|
+
const inherit = select("data-style-color", INHERIT_COLOR_STYLE, breakpoint);
|
|
100
|
+
rules.push(block(inherit, colorStyleDeclarations(configuration, inheritColorStyles.light)));
|
|
101
|
+
rules.push(media("(prefers-color-scheme:dark)", [
|
|
102
|
+
block(inherit, colorStyleDeclarations(configuration, inheritColorStyles.dark)),
|
|
103
|
+
]));
|
|
104
|
+
for (const name of Object.keys(configuration.colors))
|
|
105
|
+
rules.push(block(select("data-color", name, breakpoint), currentColor(name)));
|
|
106
|
+
for (const name of Object.keys(configuration.cornerStyles))
|
|
107
|
+
rules.push(block(select("data-style-corner", name, breakpoint), [`--corner-radius:var(--${name}-corner-radius)`]));
|
|
108
|
+
for (const name of Object.keys(configuration.lineStyles))
|
|
109
|
+
rules.push(block(select("data-style-line", name, breakpoint), [`--line-style:var(--${name}-line-style)`]));
|
|
110
|
+
for (const [name, size] of Object.entries(configuration.sizes))
|
|
111
|
+
rules.push(block(select("data-size", name, breakpoint), Object.keys(size).map((key) => `--current-${key}:var(--${name}-${key})`)));
|
|
112
|
+
for (const axis of boxAxes(configuration.scale))
|
|
113
|
+
rules.push(...axisRules(axis, breakpoint));
|
|
114
|
+
return rules;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The whole interface as CSS, from its configuration alone. Each value has one source:
|
|
118
|
+
* - the root holds the shared values, the scale, the breakpoints, every size, corner and line, and the defaults;
|
|
119
|
+
* - each color style (`[data-style-color="black"]`, also on any element, and `inherit`, which follows the device) holds
|
|
120
|
+
* only its sources: the constant colors' channels and the colors it chooses;
|
|
121
|
+
* - every scope derives every value of every color from them (`--red-color`, `--red-transparent-color`,
|
|
122
|
+
* `--red-border-color`, `--red-on-color`, `--red-color-paint`…), so switching a style changes only the sources;
|
|
123
|
+
* - `[data-color="red"]` points a component's `--current-*` values at red, derived on the component, so overriding a
|
|
124
|
+
* shared value (an alpha) on one component changes only that component;
|
|
125
|
+
* - `data-style-corner`, `data-style-line` and `data-size` switch their values the same way;
|
|
126
|
+
* - every attribute has a version per breakpoint (`data-color-960`), mobile first.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* <style>{interfaceStyleSheet(defineInterface({ colors: { brand: { of: "blue" } } }))}</style>
|
|
130
|
+
*/
|
|
131
|
+
export function interfaceStyleSheet(configuration) {
|
|
132
|
+
const { defaultColorStyle, inheritColorStyles, breakpoints } = configuration;
|
|
133
|
+
const root = [
|
|
134
|
+
...configuration.scale.map((step) => `--scale-${step}:${step}px`),
|
|
135
|
+
...breakpoints.map((breakpoint) => `--breakpoint-${breakpoint}:${breakpoint}px`),
|
|
136
|
+
...Object.entries(configuration.values).map(([name, value]) => `--${name}:${value}`),
|
|
137
|
+
...Object.entries(configuration.cornerStyles).map(([name, radius]) => `--${name}-corner-radius:${radius}`),
|
|
138
|
+
...Object.entries(configuration.lineStyles).map(([name, style]) => `--${name}-line-style:${style}`),
|
|
139
|
+
...Object.entries(configuration.sizes).flatMap(([name, size]) => Object.entries(size).map(([key, value]) => `--${name}-${key}:${value}`)),
|
|
140
|
+
`--corner-radius:var(--${configuration.defaultCornerStyle}-corner-radius)`,
|
|
141
|
+
`--line-style:var(--${configuration.defaultLineStyle}-line-style)`,
|
|
142
|
+
...Object.keys(configuration.sizes[configuration.defaultSize]).map((key) => `--current-${key}:var(--${configuration.defaultSize}-${key})`),
|
|
143
|
+
];
|
|
144
|
+
const inherit = defaultColorStyle === INHERIT_COLOR_STYLE;
|
|
145
|
+
const starting = inherit ? inheritColorStyles.light : defaultColorStyle;
|
|
146
|
+
const scope = [":root", "[data-style-color]", ...breakpoints.map((breakpoint) => `[data-style-color-${breakpoint}]`)];
|
|
147
|
+
const rules = [
|
|
148
|
+
// A box's values stay on the box: one inside another starts plain, not with its parent's border or background.
|
|
149
|
+
...Object.entries(BOX_INITIAL_VALUES).map(([name, value]) => `@property --${name}{syntax:"*";inherits:false;initial-value:${value}}`),
|
|
150
|
+
block(":root", root),
|
|
151
|
+
block(`:root,${select("data-style-color", starting)}`, colorStyleDeclarations(configuration, starting)),
|
|
152
|
+
...attributeRules(configuration).filter((rule) => !rule.startsWith(`${select("data-style-color", starting)}{`)),
|
|
153
|
+
];
|
|
154
|
+
if (inherit)
|
|
155
|
+
rules.push(media("(prefers-color-scheme:dark)", [
|
|
156
|
+
block(":root:not([data-style-color])", colorStyleDeclarations(configuration, inheritColorStyles.dark)),
|
|
157
|
+
]));
|
|
158
|
+
rules.push(block(scope.join(","), Object.entries(configuration.colors).flatMap(([name, color]) => derivedDeclarations(name, color))));
|
|
159
|
+
const styleScopes = scope.slice(1);
|
|
160
|
+
rules.push(block(`:root,${styleScopes.map((selector) => `${selector}:not([data-color])`).join(",")}`, currentColor("foreground")));
|
|
161
|
+
rules.push(block([":root", "[data-color]", ...styleScopes].join(","), CURRENT));
|
|
162
|
+
for (const breakpoint of breakpoints)
|
|
163
|
+
rules.push(media(`(min-width:${breakpoint}px)`, attributeRules(configuration, breakpoint)));
|
|
164
|
+
return rules.join("\n");
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-sheet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,WAAW,GACZ,MAAM,wEAAwE,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,yDAAyD,CAAC;AAOtG,2GAA2G;AAC3G,MAAM,KAAK,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAU,CAAC;AAItD,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE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,EAAE,sBAAsB,CAAC,aAAa,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;SACvG,CAAC,CACH,CAAC;IACJ,KAAK,CAAC,IAAI,CACR,KAAK,CACH,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EACf,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAClG,CACF,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,CACR,KAAK,CACH,SAAS,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,QAAQ,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EACnF,YAAY,CAAC,YAAY,CAAC,CAC3B,CACF,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAChF,KAAK,MAAM,UAAU,IAAI,WAAW;QAClC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,UAAU,KAAK,EAAE,cAAc,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StyleSwitchProperties } from "@sharadox/graphical-user-interface-web-library/style-switch/type";
|
|
2
|
+
/**
|
|
3
|
+
* A switch for one style group (color, corner, line…): a `Choice` of its options, the chosen one filled. The choice
|
|
4
|
+
* applies to the whole page at once and is remembered.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* <StyleSwitch configuration={STYLES} group="color" label="Color" labels={{ system: "Inherit", white: "White", black: "Black" }} />
|
|
8
|
+
*/
|
|
9
|
+
export declare function StyleSwitch({ configuration, group, label, labels, size, className }: StyleSwitchProperties): import("react").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-switch/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kEAAkE,CAAC;AAE9G;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAW,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,qBAAqB,+BAY/G"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useStyle } from "@sharadox/style-web-library/use-style";
|
|
4
|
+
import { Choice } from "@sharadox/graphical-user-interface-web-library/choice";
|
|
5
|
+
/**
|
|
6
|
+
* A switch for one style group (color, corner, line…): a `Choice` of its options, the chosen one filled. The choice
|
|
7
|
+
* applies to the whole page at once and is remembered.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <StyleSwitch configuration={STYLES} group="color" label="Color" labels={{ system: "Inherit", white: "White", black: "Black" }} />
|
|
11
|
+
*/
|
|
12
|
+
export function StyleSwitch({ configuration, group, label, labels = {}, size, className }) {
|
|
13
|
+
const { choice, choices, choose } = useStyle(configuration, group);
|
|
14
|
+
return (_jsx(Choice, { label: label, options: choices.map((entry) => ({ value: entry.name, label: labels[entry.name] ?? entry.name })), value: choice, onChange: choose, size: size, className: className }));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-switch/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,uDAAuD,CAAC;AAG/E;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAyB;IAC9G,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACnE,OAAO,CACL,KAAC,MAAM,IACL,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,EACjG,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
|
|
2
|
+
import type { Responsive } from "@sharadox/graphical-user-interface-web-library/responsive/type";
|
|
3
|
+
export interface StyleSwitchProperties {
|
|
4
|
+
/** The styles (`interfaceStyles(INTERFACE)`). */
|
|
5
|
+
configuration: StyleConfiguration;
|
|
6
|
+
/** The group it switches: `color`, `corner`, `line`. */
|
|
7
|
+
group: string;
|
|
8
|
+
/** The switch's name for assistive technology ("Color"). */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Each choice's words (`system` is the device's: "Inherit"); a choice without one shows its name. */
|
|
11
|
+
labels?: Readonly<Record<string, string>>;
|
|
12
|
+
size?: Responsive<string>;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/style-switch/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gEAAgE,CAAC;AAEjG,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,aAAa,EAAE,kBAAkB,CAAC;IAClC,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,sGAAsG;IACtG,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/style-switch/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SwitchProperties } from "@sharadox/graphical-user-interface-web-library/switch/type";
|
|
2
|
+
/**
|
|
3
|
+
* An on/off switch beside its label: a round track, outlined when off and filled when on, whose knob glides across.
|
|
4
|
+
* A change shows at once: while an asynchronous `onChange` runs the knob holds a spinner and clicks are ignored, and
|
|
5
|
+
* if it answers `false` the switch flips back.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <Switch label="Email me" checked={on} onChange={async (next) => (await save(next)).ok} />
|
|
9
|
+
*/
|
|
10
|
+
export declare function Switch(properties: SwitchProperties): import("react").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/switch/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAC;AAGnG;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,gBAAgB,+BA6DlD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { classNames } from "@sharadox/web-library/class-name";
|
|
5
|
+
import { Box } from "@sharadox/graphical-user-interface-web-library/box";
|
|
6
|
+
import { Spinner } from "@sharadox/graphical-user-interface-web-library/spinner";
|
|
7
|
+
import styles from "./index.module.css";
|
|
8
|
+
/**
|
|
9
|
+
* An on/off switch beside its label: a round track, outlined when off and filled when on, whose knob glides across.
|
|
10
|
+
* A change shows at once: while an asynchronous `onChange` runs the knob holds a spinner and clicks are ignored, and
|
|
11
|
+
* if it answers `false` the switch flips back.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <Switch label="Email me" checked={on} onChange={async (next) => (await save(next)).ok} />
|
|
15
|
+
*/
|
|
16
|
+
export function Switch(properties) {
|
|
17
|
+
const { label, checked, defaultChecked = false, onChange, disabled, state, className, corner = "circle", size = "small", color = "brand", ...look } = properties;
|
|
18
|
+
const [own, setOwn] = useState(defaultChecked);
|
|
19
|
+
const [shown, setShown] = useState(undefined);
|
|
20
|
+
const [pending, setPending] = useState(false);
|
|
21
|
+
const current = shown ?? checked ?? own;
|
|
22
|
+
const toggle = async () => {
|
|
23
|
+
if (pending)
|
|
24
|
+
return;
|
|
25
|
+
const next = !current;
|
|
26
|
+
setShown(next);
|
|
27
|
+
const answer = onChange?.(next);
|
|
28
|
+
if (answer instanceof Promise) {
|
|
29
|
+
setPending(true);
|
|
30
|
+
const accepted = (await answer) !== false;
|
|
31
|
+
setPending(false);
|
|
32
|
+
if (accepted && checked === undefined)
|
|
33
|
+
setOwn(next);
|
|
34
|
+
setShown(undefined);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (checked === undefined)
|
|
38
|
+
setOwn(next);
|
|
39
|
+
setShown(undefined);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return (_jsxs("button", { type: "button", role: "switch", "aria-checked": current, ...(pending && { "aria-busy": true }), disabled: disabled, onClick: toggle, className: classNames(styles.switch, className), "data-checked": current || undefined, children: [_jsx(Box, { as: "span", interactive: true, variant: current ? "filled" : "outlined", color: color, corner: corner, size: size, state: state ?? (disabled ? "disabled" : "enabled"), ...look, className: styles.track, children: _jsx("span", { className: styles.knob, children: pending && _jsx(Spinner, {}) }) }), _jsx("span", { className: styles.label, children: label })] }));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/switch/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,oDAAoD,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AAEjF,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,UAA4B;IACjD,MAAM,EACJ,KAAK,EACL,OAAO,EACP,cAAc,GAAG,KAAK,EACtB,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,SAAS,EACT,MAAM,GAAG,QAAQ,EACjB,IAAI,GAAG,OAAO,EACd,KAAK,GAAG,OAAO,EACf,GAAG,IAAI,EACR,GAAG,UAAU,CAAC;IACf,MAAM,CAAC,GAAG,EAAE,MAAM,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,IACF,EAAE,EAAC,MAAM,EACT,WAAW,QACX,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,EACxC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,KAC/C,IAAI,EACR,SAAS,EAAE,MAAM,CAAC,KAAK,YAEvB,eAAM,SAAS,EAAE,MAAM,CAAC,IAAI,YAAG,OAAO,IAAI,KAAC,OAAO,KAAG,GAAQ,GACzD,EACN,eAAM,SAAS,EAAE,MAAM,CAAC,KAAK,YAAG,KAAK,GAAQ,IACtC,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:where(.switch){display:inline-flex;align-items:center;gap:var(--scale-8);margin:0;padding:0;border:0;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}:where(.switch):disabled{cursor:default}:where(.switch):focus-visible{outline:none}:where(.switch):focus-visible>:where(.track){outline:var(--focus-thickness) solid var(--current-color);outline-offset:var(--focus-offset)}:where(.switch) .track{justify-content:start;inline-size:calc(var(--current-minimum-size)*2);min-inline-size:calc(var(--current-minimum-size)*2);padding:var(--line-thickness)}:where(.switch) .track>*{flex:1 1 auto;justify-content:start;padding:0}:where(.knob){display:flex;justify-content:center;align-items:center;inline-size:calc(var(--current-minimum-size) - 4*var(--line-thickness));block-size:calc(var(--current-minimum-size) - 4*var(--line-thickness));border-radius:var(--corner-radius);background:currentcolor;font-size:.6em;transition:transform var(--duration) var(--easing)}:where(.knob)>*{color:var(--current-color)}:where(.switch[data-checked]) :where(.knob){transform:translateX(calc(var(--current-minimum-size)))}:where(.switch[data-checked]:dir(rtl)) :where(.knob){transform:translateX(calc(var(--current-minimum-size) * -1))}:where(.label){font-size:var(--current-font-size)}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
:where(.switch) {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--scale-8);
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
border: 0;
|
|
8
|
+
background: none;
|
|
9
|
+
color: inherit;
|
|
10
|
+
font: inherit;
|
|
11
|
+
text-align: start;
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
|
|
14
|
+
&:disabled {
|
|
15
|
+
cursor: default;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&:focus-visible {
|
|
19
|
+
outline: none;
|
|
20
|
+
|
|
21
|
+
> :where(.track) {
|
|
22
|
+
outline: var(--focus-thickness) solid var(--current-color);
|
|
23
|
+
outline-offset: var(--focus-offset);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Twice as wide as high; the knob is a square of the track's inner height, gliding to the far end when on. Inside the
|
|
29
|
+
// switch, so these beat the box's own (zero-weight) size and padding whichever style sheet loads last.
|
|
30
|
+
:where(.switch) .track {
|
|
31
|
+
justify-content: start;
|
|
32
|
+
inline-size: calc(var(--current-minimum-size) * 2);
|
|
33
|
+
min-inline-size: calc(var(--current-minimum-size) * 2);
|
|
34
|
+
padding: var(--line-thickness);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
:where(.switch) .track > * {
|
|
38
|
+
// An interactive box puts its content in a padded section: here it holds only the knob, from the track's start.
|
|
39
|
+
flex: 1 1 auto;
|
|
40
|
+
justify-content: start;
|
|
41
|
+
padding: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
:where(.knob) {
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
align-items: center;
|
|
48
|
+
inline-size: calc(var(--current-minimum-size) - 4 * var(--line-thickness));
|
|
49
|
+
block-size: calc(var(--current-minimum-size) - 4 * var(--line-thickness));
|
|
50
|
+
border-radius: var(--corner-radius);
|
|
51
|
+
background: currentcolor;
|
|
52
|
+
font-size: 0.6em;
|
|
53
|
+
transition: transform var(--duration) var(--easing);
|
|
54
|
+
|
|
55
|
+
> * {
|
|
56
|
+
color: var(--current-color);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:where(.switch[data-checked]) :where(.knob) {
|
|
61
|
+
transform: translateX(calc(var(--current-minimum-size)));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:where(.switch[data-checked]:dir(rtl)) :where(.knob) {
|
|
65
|
+
transform: translateX(calc(var(--current-minimum-size) * -1));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
:where(.label) {
|
|
69
|
+
font-size: var(--current-font-size);
|
|
70
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { BoxLook, BoxState } from "@sharadox/graphical-user-interface-web-library/box/type";
|
|
3
|
+
export interface SwitchProperties extends Pick<BoxLook, "color" | "colorStyle" | "corner" | "line" | "size"> {
|
|
4
|
+
/** What it turns on, beside it. */
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
/** Controlled: whether it is on. */
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** Uncontrolled: whether it starts on. */
|
|
9
|
+
defaultChecked?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Called with the new value. It may answer later (a promise): the switch flips at once, is busy until then, and
|
|
12
|
+
* flips back when the answer is `false`.
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (checked: boolean) => void | Promise<boolean | void>;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Forces a state (for the design system). */
|
|
17
|
+
state?: BoxState;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/switch/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,yDAAyD,CAAC;AAEjG,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAC1G,mCAAmC;IACnC,KAAK,EAAE,SAAS,CAAC;IACjB,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAChE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/switch/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TextFieldProperties } from "@sharadox/graphical-user-interface-web-library/text-field/type";
|
|
2
|
+
/**
|
|
3
|
+
* A text field: its label, an outlined field box (middleground by default, the error color with an error) with
|
|
4
|
+
* optional prefix and suffix sections, and its hint and error under it. One line by default; `multiline` makes it a
|
|
5
|
+
* text area. Every look of a box applies, per breakpoint too.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <TextField label="Email" type="email" name="email" error={error} />
|
|
9
|
+
* <TextField label="Price" type="number" prefix="€" />
|
|
10
|
+
* <TextField label="Message" multiline rows={6} />
|
|
11
|
+
*/
|
|
12
|
+
export declare function TextField(properties: TextFieldProperties): import("react").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/text-field/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gEAAgE,CAAC;AAG1G;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,mBAAmB,+BAoDxD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { classNames } from "@sharadox/web-library/class-name";
|
|
3
|
+
import { Box } from "@sharadox/graphical-user-interface-web-library/box";
|
|
4
|
+
import { Field } from "@sharadox/graphical-user-interface-web-library/field";
|
|
5
|
+
import styles from "./index.module.css";
|
|
6
|
+
/**
|
|
7
|
+
* A text field: its label, an outlined field box (middleground by default, the error color with an error) with
|
|
8
|
+
* optional prefix and suffix sections, and its hint and error under it. One line by default; `multiline` makes it a
|
|
9
|
+
* text area. Every look of a box applies, per breakpoint too.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <TextField label="Email" type="email" name="email" error={error} />
|
|
13
|
+
* <TextField label="Price" type="number" prefix="€" />
|
|
14
|
+
* <TextField label="Message" multiline rows={6} />
|
|
15
|
+
*/
|
|
16
|
+
export function TextField(properties) {
|
|
17
|
+
const { label, hideLabel, hint, error, prefix, suffix, state, variant = "outlined", color, colorStyle, corner, line, size, className, multiline, id, ...control } = properties;
|
|
18
|
+
const disabled = Boolean(control.disabled);
|
|
19
|
+
return (_jsx(Field, { label: label, hideLabel: hideLabel, hint: hint, error: error, id: id, children: (attributes) => (_jsx(Box, { field: true, variant: variant, color: color ?? (error === undefined ? "middleground" : "error"), colorStyle: colorStyle, corner: corner, line: line, size: size, state: state ?? (disabled ? "disabled" : "enabled"), prefix: prefix, suffix: suffix, className: classNames(styles.field, multiline && styles.multiline, className), ...(multiline && { "data-multiline": "" }), children: multiline ? (_jsx("textarea", { rows: 3, ...control, ...attributes, className: styles.control })) : (_jsx("input", { type: "text", ...control, ...attributes, className: styles.control })) })) }));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/text-field/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,oDAAoD,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,sDAAsD,CAAC;AAE7E,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,UAA+B;IACvD,MAAM,EACJ,KAAK,EACL,SAAS,EACT,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,GAAG,UAAU,EACpB,KAAK,EACL,UAAU,EACV,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,EAAE,EACF,GAAG,OAAO,EACX,GAAG,UAAU,CAAC;IACf,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,CACL,KAAC,KAAK,IAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,YACxE,CAAC,UAAU,EAAE,EAAE,CAAC,CACf,KAAC,GAAG,IACF,KAAK,QACL,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,EAChE,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EACnD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,IAAI,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,KACzE,CAAC,SAAS,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,YAE1C,SAAS,CAAC,CAAC,CAAC,CACX,mBACE,IAAI,EAAE,CAAC,KACF,OAAuD,KACxD,UAAU,EACd,SAAS,EAAE,MAAM,CAAC,OAAO,GACzB,CACH,CAAC,CAAC,CAAC,CACF,gBAAO,IAAI,EAAC,MAAM,KAAM,OAAkB,KAAM,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,GAAI,CAC1F,GACG,CACP,GACK,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:where(.control){box-sizing:border-box;inline-size:100%;min-inline-size:0;min-block-size:var(--section-minimum-size);margin:0;padding:0;border:0;outline:0;background:rgba(0,0,0,0);color:inherit;font:inherit;text-align:start}:where(.control)::placeholder{color:inherit;opacity:.6}:where(.control):disabled{cursor:default}:where(textarea.control){min-block-size:calc(var(--section-minimum-size)*2);padding-block:var(--scale-8);resize:vertical}:where(.multiline){align-items:stretch}:where(.field:not([data-variant=filled])) :where(.control){color:var(--current-hover-color)}
|