@plexui/ui 0.45.0 → 0.46.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/dist/es/components/Icon/index.js +1 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/MinusLg.js +5 -0
- package/dist/es/components/Icon/svg/MinusLg.js.map +1 -0
- package/dist/es/components/Slider/Slider.js +28 -4
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Tabs/Tabs.js +24 -0
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/Tabs/segments.js +92 -0
- package/dist/es/components/Tabs/segments.js.map +1 -0
- package/dist/types/components/Icon/index.d.ts +1 -0
- package/dist/types/components/Icon/svg/MinusLg.d.ts +6 -0
- package/dist/types/components/Tabs/segments.d.ts +19 -0
- package/package.json +2 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One width for the segments of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must
|
|
3
|
+
* match).
|
|
4
|
+
*
|
|
5
|
+
* UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,
|
|
6
|
+
* each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app
|
|
7
|
+
* segmented-hug, 13.11). A grid that hugs its content cannot size its tracks to the widest one by itself (the browser
|
|
8
|
+
* sizes it by the sum of its labels), so the widest is measured here and set as the track. Tabs.module.css asks for it
|
|
9
|
+
* with `--tabs-equal-segments: 1` on a phone's horizontal control that is not `block`; elsewhere nothing is set.
|
|
10
|
+
*/
|
|
11
|
+
const TRACK = "--tabs-segment-track";
|
|
12
|
+
/** The phone block of Tabs.module.css, where a control starts or stops asking for one width */
|
|
13
|
+
const PHONE_QUERY = "(max-width: 767px)";
|
|
14
|
+
/** Slack for the rounding of clientWidth */
|
|
15
|
+
const FIT_TOLERANCE_PX = 1;
|
|
16
|
+
const px = (style, name) => Number.parseFloat(style.getPropertyValue(name)) || 0;
|
|
17
|
+
/** The control's border box as laid out, unscaled and unrounded (offsetWidth rounds to whole pixels) */
|
|
18
|
+
const laidOutWidth = (root, style) => {
|
|
19
|
+
const width = px(style, "width");
|
|
20
|
+
if (!width)
|
|
21
|
+
return root.offsetWidth;
|
|
22
|
+
if (style.getPropertyValue("box-sizing") === "border-box")
|
|
23
|
+
return width;
|
|
24
|
+
const sides = ["padding-left", "padding-right", "border-left-width", "border-right-width"];
|
|
25
|
+
return sides.reduce((sum, side) => sum + px(style, side), width);
|
|
26
|
+
};
|
|
27
|
+
/** Sets the track and says whether it changed, so a thumb on a segment that moved can follow. */
|
|
28
|
+
export function equalizeSegments(root, thumb) {
|
|
29
|
+
if (!root)
|
|
30
|
+
return false;
|
|
31
|
+
const before = root.style.getPropertyValue(TRACK);
|
|
32
|
+
const style = getComputedStyle(root);
|
|
33
|
+
const asked = style.getPropertyValue("--tabs-equal-segments").trim() === "1";
|
|
34
|
+
// The segments of the row: a tab that is not drawn takes no track
|
|
35
|
+
const segments = Array.from(root.children).filter((child) => child instanceof HTMLElement && child !== thumb && getComputedStyle(child).getPropertyValue("display") !== "none");
|
|
36
|
+
if (!asked || root.getAttribute("data-orientation") !== "horizontal" || segments.length < 2 || !root.offsetWidth) {
|
|
37
|
+
root.style.removeProperty(TRACK);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Each segment at its label's width, unscaled while the control is held (it grows under the finger)
|
|
41
|
+
root.style.setProperty(TRACK, "max-content");
|
|
42
|
+
const width = laidOutWidth(root, style);
|
|
43
|
+
const scale = width / (root.getBoundingClientRect().width || width);
|
|
44
|
+
const widest = Math.max(...segments.map((segment) => segment.getBoundingClientRect().width * scale));
|
|
45
|
+
root.style.setProperty(TRACK, `minmax(${widest}px, 1fr)`);
|
|
46
|
+
// The row of equal segments against the room the control has, counted: scrollWidth would take in a thumb still
|
|
47
|
+
// standing where its segment was
|
|
48
|
+
const row = widest * segments.length + px(style, "column-gap") * (segments.length - 1);
|
|
49
|
+
const room = root.clientWidth - px(style, "padding-left") - px(style, "padding-right");
|
|
50
|
+
if (row > room + FIT_TOLERANCE_PX)
|
|
51
|
+
root.style.removeProperty(TRACK);
|
|
52
|
+
}
|
|
53
|
+
return root.style.getPropertyValue(TRACK) !== before;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of
|
|
57
|
+
* the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels
|
|
58
|
+
* widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has
|
|
59
|
+
* loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.
|
|
60
|
+
*/
|
|
61
|
+
export function watchSegments(root, thumb, moved) {
|
|
62
|
+
const refit = () => {
|
|
63
|
+
if (equalizeSegments(root, thumb()))
|
|
64
|
+
moved();
|
|
65
|
+
};
|
|
66
|
+
const box = root.parentElement;
|
|
67
|
+
const observer = box && typeof ResizeObserver !== "undefined" ? new ResizeObserver(refit) : undefined;
|
|
68
|
+
if (box)
|
|
69
|
+
observer?.observe(box);
|
|
70
|
+
const phone = typeof window.matchMedia === "function" ? window.matchMedia(PHONE_QUERY) : undefined;
|
|
71
|
+
// Browsers before 2020 offer only addListener
|
|
72
|
+
if (phone?.addEventListener)
|
|
73
|
+
phone.addEventListener("change", refit);
|
|
74
|
+
else
|
|
75
|
+
phone?.addListener?.(refit);
|
|
76
|
+
let live = true;
|
|
77
|
+
document.fonts?.ready.then(() => {
|
|
78
|
+
if (!live)
|
|
79
|
+
return;
|
|
80
|
+
equalizeSegments(root, thumb());
|
|
81
|
+
moved();
|
|
82
|
+
});
|
|
83
|
+
return () => {
|
|
84
|
+
live = false;
|
|
85
|
+
observer?.disconnect();
|
|
86
|
+
if (phone?.removeEventListener)
|
|
87
|
+
phone.removeEventListener("change", refit);
|
|
88
|
+
else
|
|
89
|
+
phone?.removeListener?.(refit);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=segments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segments.js","sourceRoot":"","sources":["../../../../src/components/Tabs/segments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,KAAK,GAAG,sBAAsB,CAAA;AAEpC,+FAA+F;AAC/F,MAAM,WAAW,GAAG,oBAAoB,CAAA;AAExC,4CAA4C;AAC5C,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAE1B,MAAM,EAAE,GAAG,CAAC,KAA0B,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAA;AAE7G,wGAAwG;AACxG,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAE,KAA0B,EAAE,EAAE;IACrE,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC,WAAW,CAAA;IACnC,IAAI,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,YAAY;QAAE,OAAO,KAAK,CAAA;IACvE,MAAM,KAAK,GAAG,CAAC,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,CAAC,CAAA;IAC1F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAA;AAClE,CAAC,CAAA;AAED,iGAAiG;AACjG,MAAM,UAAU,gBAAgB,CAAC,IAAwB,EAAE,KAAyB;IAClF,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,KA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AC,KAAK,CAAC,CAAA;IAChC,IAAI,IAAI,GAAG,IAAI,CAAA;IACf,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QAC9B,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAC/B,KAAK,EAAE,CAAA;IACT,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,KAAK,CAAA;QACZ,QAAQ,EAAE,UAAU,EAAE,CAAA;QACtB,IAAI,KAAK,EAAE,mBAAmB;YAAE,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;;YACrE,KAAK,EAAE,cAAc,EAAE,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * One width for the segments of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must\n * match).\n *\n * UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,\n * each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app\n * segmented-hug, 13.11). A grid that hugs its content cannot size its tracks to the widest one by itself (the browser\n * sizes it by the sum of its labels), so the widest is measured here and set as the track. Tabs.module.css asks for it\n * with `--tabs-equal-segments: 1` on a phone's horizontal control that is not `block`; elsewhere nothing is set.\n */\n\nconst TRACK = \"--tabs-segment-track\"\n\n/** The phone block of Tabs.module.css, where a control starts or stops asking for one width */\nconst PHONE_QUERY = \"(max-width: 767px)\"\n\n/** Slack for the rounding of clientWidth */\nconst FIT_TOLERANCE_PX = 1\n\nconst px = (style: CSSStyleDeclaration, name: string) => Number.parseFloat(style.getPropertyValue(name)) || 0\n\n/** The control's border box as laid out, unscaled and unrounded (offsetWidth rounds to whole pixels) */\nconst laidOutWidth = (root: HTMLElement, style: CSSStyleDeclaration) => {\n const width = px(style, \"width\")\n if (!width) return root.offsetWidth\n if (style.getPropertyValue(\"box-sizing\") === \"border-box\") return width\n const sides = [\"padding-left\", \"padding-right\", \"border-left-width\", \"border-right-width\"]\n return sides.reduce((sum, side) => sum + px(style, side), width)\n}\n\n/** Sets the track and says whether it changed, so a thumb on a segment that moved can follow. */\nexport function equalizeSegments(root: HTMLElement | null, thumb: HTMLElement | null): boolean {\n if (!root) return false\n const before = root.style.getPropertyValue(TRACK)\n const style = getComputedStyle(root)\n const asked = style.getPropertyValue(\"--tabs-equal-segments\").trim() === \"1\"\n // The segments of the row: a tab that is not drawn takes no track\n const segments = Array.from(root.children).filter(\n (child): child is HTMLElement =>\n child instanceof HTMLElement && child !== thumb && getComputedStyle(child).getPropertyValue(\"display\") !== \"none\",\n )\n if (!asked || root.getAttribute(\"data-orientation\") !== \"horizontal\" || segments.length < 2 || !root.offsetWidth) {\n root.style.removeProperty(TRACK)\n } else {\n // Each segment at its label's width, unscaled while the control is held (it grows under the finger)\n root.style.setProperty(TRACK, \"max-content\")\n const width = laidOutWidth(root, style)\n const scale = width / (root.getBoundingClientRect().width || width)\n const widest = Math.max(...segments.map((segment) => segment.getBoundingClientRect().width * scale))\n root.style.setProperty(TRACK, `minmax(${widest}px, 1fr)`)\n // The row of equal segments against the room the control has, counted: scrollWidth would take in a thumb still\n // standing where its segment was\n const row = widest * segments.length + px(style, \"column-gap\") * (segments.length - 1)\n const room = root.clientWidth - px(style, \"padding-left\") - px(style, \"padding-right\")\n if (row > room + FIT_TOLERANCE_PX) root.style.removeProperty(TRACK)\n }\n return root.style.getPropertyValue(TRACK) !== before\n}\n\n/**\n * Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of\n * the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels\n * widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has\n * loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.\n */\nexport function watchSegments(root: HTMLElement, thumb: () => HTMLElement | null, moved: () => void): () => void {\n const refit = () => {\n if (equalizeSegments(root, thumb())) moved()\n }\n const box = root.parentElement\n const observer = box && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(refit) : undefined\n if (box) observer?.observe(box)\n const phone = typeof window.matchMedia === \"function\" ? window.matchMedia(PHONE_QUERY) : undefined\n // Browsers before 2020 offer only addListener\n if (phone?.addEventListener) phone.addEventListener(\"change\", refit)\n else phone?.addListener?.(refit)\n let live = true\n document.fonts?.ready.then(() => {\n if (!live) return\n equalizeSegments(root, thumb())\n moved()\n })\n return () => {\n live = false\n observer?.disconnect()\n if (phone?.removeEventListener) phone.removeEventListener(\"change\", refit)\n else phone?.removeListener?.(refit)\n }\n}\n"]}
|
|
@@ -362,6 +362,7 @@ export { default as MinimizeTop } from "./svg/MinimizeTop.js";
|
|
|
362
362
|
export { default as Minus } from "./svg/Minus.js";
|
|
363
363
|
export { default as MinusCircle } from "./svg/MinusCircle.js";
|
|
364
364
|
export { default as MinusCircleFilled } from "./svg/MinusCircleFilled.js";
|
|
365
|
+
export { default as MinusLg } from "./svg/MinusLg.js";
|
|
365
366
|
export { default as Mobile } from "./svg/Mobile.js";
|
|
366
367
|
export { default as Moon } from "./svg/Moon.js";
|
|
367
368
|
export { default as MoonSun } from "./svg/MoonSun.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One width for the segments of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must
|
|
3
|
+
* match).
|
|
4
|
+
*
|
|
5
|
+
* UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,
|
|
6
|
+
* each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app
|
|
7
|
+
* segmented-hug, 13.11). A grid that hugs its content cannot size its tracks to the widest one by itself (the browser
|
|
8
|
+
* sizes it by the sum of its labels), so the widest is measured here and set as the track. Tabs.module.css asks for it
|
|
9
|
+
* with `--tabs-equal-segments: 1` on a phone's horizontal control that is not `block`; elsewhere nothing is set.
|
|
10
|
+
*/
|
|
11
|
+
/** Sets the track and says whether it changed, so a thumb on a segment that moved can follow. */
|
|
12
|
+
export declare function equalizeSegments(root: HTMLElement | null, thumb: HTMLElement | null): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of
|
|
15
|
+
* the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels
|
|
16
|
+
* widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has
|
|
17
|
+
* loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.
|
|
18
|
+
*/
|
|
19
|
+
export declare function watchSegments(root: HTMLElement, thumb: () => HTMLElement | null, moved: () => void): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Modern design system for building high-quality applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@maskito/core": "^5.2.2",
|
|
100
100
|
"@maskito/kit": "^5.2.2",
|
|
101
101
|
"@maskito/react": "^5.2.2",
|
|
102
|
-
"@plexui/styles": "^0.
|
|
102
|
+
"@plexui/styles": "^0.5.0",
|
|
103
103
|
"@radix-ui/react-dismissable-layer": "1.2.1",
|
|
104
104
|
"@radix-ui/react-focus-guards": "1.2.0",
|
|
105
105
|
"@radix-ui/react-focus-scope": "1.3.1",
|