@designa8/vibedesign-tinkerly-dryrun-ds-176b 0.0.4 → 0.0.5
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 +1 -1
- package/dist/index.cjs +127 -70
- package/dist/index.js +127 -70
- package/dist/styles.css +6 -6
- package/package.json +1 -1
- package/src/atoms/Icon/icons.data.ts +1 -0
- package/src/molecules/ButtonGroup/ButtonGroup.tsx +135 -42
- package/src/molecules/ButtonGroup/preview.tsx +60 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-tinkerly-dryrun-ds-176b
|
|
2
2
|
|
|
3
|
-
Complete design system generated by Atoms Design, version **0.0.
|
|
3
|
+
Complete design system generated by Atoms Design, version **0.0.5**.
|
|
4
4
|
Tokens, atoms, molecules, organisms, and templates — import from the package root;
|
|
5
5
|
never hardcode visual values in consumer code.
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -251,7 +251,8 @@ var ICON_REGISTRY = {
|
|
|
251
251
|
"calendar-days": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M8 2v4" }, { tag: "path", d: "M16 2v4" }, { tag: "rect", width: "18", height: "18", x: "3", y: "4", rx: "2" }, { tag: "path", d: "M3 10h18" }, { tag: "path", d: "M8 14h.01" }, { tag: "path", d: "M12 14h.01" }, { tag: "path", d: "M16 14h.01" }, { tag: "path", d: "M8 18h.01" }, { tag: "path", d: "M12 18h.01" }, { tag: "path", d: "M16 18h.01" }] },
|
|
252
252
|
"milestone": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 13v8" }, { tag: "path", d: "M12 3v3" }, { tag: "path", d: "M4 6a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h13a2 2 0 0 0 1.152-.365l3.424-2.317a1 1 0 0 0 0-1.635l-3.424-2.318A2 2 0 0 0 17 6z" }] },
|
|
253
253
|
"quote": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }, { tag: "path", d: "M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }] },
|
|
254
|
-
"brain": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }, { tag: "path", d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }, { tag: "path", d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }, { tag: "path", d: "M17.599 6.5a3 3 0 0 0 .399-1.375" }, { tag: "path", d: "M6.003 5.125A3 3 0 0 0 6.401 6.5" }, { tag: "path", d: "M3.477 10.896a4 4 0 0 1 .585-.396" }, { tag: "path", d: "M19.938 10.5a4 4 0 0 1 .585.396" }, { tag: "path", d: "M6 18a4 4 0 0 1-1.967-.516" }, { tag: "path", d: "M19.967 17.484A4 4 0 0 1 18 18" }] }
|
|
254
|
+
"brain": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }, { tag: "path", d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }, { tag: "path", d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }, { tag: "path", d: "M17.599 6.5a3 3 0 0 0 .399-1.375" }, { tag: "path", d: "M6.003 5.125A3 3 0 0 0 6.401 6.5" }, { tag: "path", d: "M3.477 10.896a4 4 0 0 1 .585-.396" }, { tag: "path", d: "M19.938 10.5a4 4 0 0 1 .585.396" }, { tag: "path", d: "M6 18a4 4 0 0 1-1.967-.516" }, { tag: "path", d: "M19.967 17.484A4 4 0 0 1 18 18" }] },
|
|
255
|
+
"view": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2" }, { tag: "path", d: "M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2" }, { tag: "circle", cx: "12", cy: "12", r: "1" }, { tag: "path", d: "M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0" }] }
|
|
255
256
|
};
|
|
256
257
|
|
|
257
258
|
// virtual-pkg:src/atoms/Icon/Icon.tsx
|
|
@@ -3643,7 +3644,7 @@ Breadcrumb.displayName = "Breadcrumb";
|
|
|
3643
3644
|
var React28 = __toESM(require("react"));
|
|
3644
3645
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
3645
3646
|
var cn13 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3646
|
-
var
|
|
3647
|
+
var ICON_SIZE = { sm: 16, md: 18 };
|
|
3647
3648
|
var ButtonGroup = React28.forwardRef(
|
|
3648
3649
|
({
|
|
3649
3650
|
options,
|
|
@@ -3667,6 +3668,37 @@ var ButtonGroup = React28.forwardRef(
|
|
|
3667
3668
|
);
|
|
3668
3669
|
const hasSelection = selectedIndex >= 0;
|
|
3669
3670
|
const selectedDisabled = hasSelection ? options[selectedIndex].disabled === true : false;
|
|
3671
|
+
const hasIconOnly = options.some((option) => option.iconOnly === true);
|
|
3672
|
+
const gridRef = React28.useRef(null);
|
|
3673
|
+
const [pill, setPill] = React28.useState(
|
|
3674
|
+
null
|
|
3675
|
+
);
|
|
3676
|
+
React28.useLayoutEffect(() => {
|
|
3677
|
+
const grid = gridRef.current;
|
|
3678
|
+
if (!grid) return;
|
|
3679
|
+
const measure = () => {
|
|
3680
|
+
if (selectedIndex < 0) {
|
|
3681
|
+
setPill(null);
|
|
3682
|
+
return;
|
|
3683
|
+
}
|
|
3684
|
+
const cells = grid.querySelectorAll("[data-segment]");
|
|
3685
|
+
const cell = cells[selectedIndex];
|
|
3686
|
+
if (!cell) {
|
|
3687
|
+
setPill(null);
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
const next = { x: cell.offsetLeft, width: cell.offsetWidth };
|
|
3691
|
+
setPill(
|
|
3692
|
+
(prev) => prev && prev.x === next.x && prev.width === next.width ? prev : next
|
|
3693
|
+
);
|
|
3694
|
+
};
|
|
3695
|
+
measure();
|
|
3696
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
3697
|
+
const observer = new ResizeObserver(measure);
|
|
3698
|
+
observer.observe(grid);
|
|
3699
|
+
grid.querySelectorAll("[data-segment]").forEach((cell) => observer.observe(cell));
|
|
3700
|
+
return () => observer.disconnect();
|
|
3701
|
+
}, [selectedIndex, count, size, fullWidth, hasIconOnly]);
|
|
3670
3702
|
const select = (next) => {
|
|
3671
3703
|
if (disabled) return;
|
|
3672
3704
|
if (value === void 0) setInnerValue(next);
|
|
@@ -3683,87 +3715,112 @@ var ButtonGroup = React28.forwardRef(
|
|
|
3683
3715
|
}
|
|
3684
3716
|
}
|
|
3685
3717
|
};
|
|
3686
|
-
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { ref, className: cn13("w-full", className), ...props, children: /* @__PURE__ */ (0, import_jsx_runtime28.
|
|
3718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { ref, className: cn13("w-full", className), ...props, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3687
3719
|
"div",
|
|
3688
3720
|
{
|
|
3689
3721
|
role: "group",
|
|
3690
3722
|
"aria-label": label,
|
|
3691
3723
|
"aria-disabled": disabled || void 0,
|
|
3692
3724
|
className: cn13(
|
|
3693
|
-
"
|
|
3725
|
+
"inline-flex p-xxs",
|
|
3694
3726
|
"rounded-md border border-hairline bg-surface",
|
|
3695
3727
|
"transition duration-150 ease-out",
|
|
3696
3728
|
"has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-focus-blue",
|
|
3697
3729
|
fullWidth ? "w-full" : "w-auto"
|
|
3698
3730
|
),
|
|
3699
|
-
children:
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
),
|
|
3711
|
-
style: {
|
|
3712
|
-
width: `calc((100% - ${TRACK_INSET} * 2) / ${count || 1})`,
|
|
3713
|
-
transform: `translateX(${hasSelection ? selectedIndex * 100 : 0}%)`
|
|
3714
|
-
}
|
|
3715
|
-
}
|
|
3716
|
-
),
|
|
3717
|
-
options.map((option, index) => {
|
|
3718
|
-
const isSelected = index === selectedIndex;
|
|
3719
|
-
const isDisabled = disabled || option.disabled === true;
|
|
3720
|
-
const seamHidden = isSelected || index + 1 === selectedIndex;
|
|
3721
|
-
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "relative flex", children: [
|
|
3722
|
-
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
3723
|
-
Button,
|
|
3724
|
-
{
|
|
3725
|
-
chrome: "none",
|
|
3726
|
-
variant: "ghost",
|
|
3727
|
-
size,
|
|
3728
|
-
fullWidth: true,
|
|
3729
|
-
disabled: isDisabled,
|
|
3730
|
-
"aria-pressed": isSelected,
|
|
3731
|
-
onClick: () => select(option.value),
|
|
3732
|
-
onKeyDown: (event) => {
|
|
3733
|
-
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
3734
|
-
event.preventDefault();
|
|
3735
|
-
step(index, 1);
|
|
3736
|
-
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
3737
|
-
event.preventDefault();
|
|
3738
|
-
step(index, -1);
|
|
3739
|
-
}
|
|
3740
|
-
},
|
|
3741
|
-
className: cn13(
|
|
3742
|
-
"relative z-10 rounded-sm",
|
|
3743
|
-
isDisabled ? "text-muted-soft" : isSelected ? "text-primary" : "text-ink"
|
|
3744
|
-
),
|
|
3745
|
-
labelClassName: option.badge ? void 0 : "truncate",
|
|
3746
|
-
children: [
|
|
3747
|
-
option.label,
|
|
3748
|
-
option.badge ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "ml-xs inline-flex shrink-0 items-center", children: option.badge }) : null
|
|
3749
|
-
]
|
|
3750
|
-
}
|
|
3751
|
-
),
|
|
3752
|
-
index < count - 1 ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3731
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
3732
|
+
"div",
|
|
3733
|
+
{
|
|
3734
|
+
ref: gridRef,
|
|
3735
|
+
className: cn13(
|
|
3736
|
+
"relative grid grid-flow-col items-stretch",
|
|
3737
|
+
fullWidth || !hasIconOnly ? "auto-cols-fr" : "auto-cols-auto",
|
|
3738
|
+
fullWidth && "w-full"
|
|
3739
|
+
),
|
|
3740
|
+
children: [
|
|
3741
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3753
3742
|
"span",
|
|
3754
3743
|
{
|
|
3755
3744
|
"aria-hidden": "true",
|
|
3756
3745
|
className: cn13(
|
|
3757
|
-
"pointer-events-none absolute
|
|
3758
|
-
"
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3746
|
+
"pointer-events-none absolute left-0 top-0 bottom-0 rounded-sm",
|
|
3747
|
+
"transition-[transform,width,opacity,background-color] duration-[220ms] ease-out",
|
|
3748
|
+
"motion-reduce:transition-none",
|
|
3749
|
+
selectedDisabled ? "bg-surface-strong" : "bg-primary-soft",
|
|
3750
|
+
hasSelection && pill ? "opacity-100" : "opacity-0"
|
|
3751
|
+
),
|
|
3752
|
+
style: {
|
|
3753
|
+
width: pill ? pill.width : 0,
|
|
3754
|
+
transform: `translateX(${pill ? pill.x : 0}px)`
|
|
3755
|
+
}
|
|
3762
3756
|
}
|
|
3763
|
-
)
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3757
|
+
),
|
|
3758
|
+
options.map((option, index) => {
|
|
3759
|
+
const isSelected = index === selectedIndex;
|
|
3760
|
+
const isDisabled = disabled || option.disabled === true;
|
|
3761
|
+
const seamHidden = isSelected || index + 1 === selectedIndex;
|
|
3762
|
+
const isIconOnly = option.iconOnly === true && option.icon !== void 0;
|
|
3763
|
+
const segment = /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
3764
|
+
Button,
|
|
3765
|
+
{
|
|
3766
|
+
chrome: "none",
|
|
3767
|
+
variant: "ghost",
|
|
3768
|
+
size,
|
|
3769
|
+
square: isIconOnly,
|
|
3770
|
+
fullWidth: !isIconOnly,
|
|
3771
|
+
disabled: isDisabled,
|
|
3772
|
+
"aria-pressed": isSelected,
|
|
3773
|
+
"aria-label": isIconOnly ? option.label : void 0,
|
|
3774
|
+
leadingIcon: option.icon,
|
|
3775
|
+
iconSize: ICON_SIZE[size],
|
|
3776
|
+
onClick: () => select(option.value),
|
|
3777
|
+
onKeyDown: (event) => {
|
|
3778
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
3779
|
+
event.preventDefault();
|
|
3780
|
+
step(index, 1);
|
|
3781
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
3782
|
+
event.preventDefault();
|
|
3783
|
+
step(index, -1);
|
|
3784
|
+
}
|
|
3785
|
+
},
|
|
3786
|
+
className: cn13(
|
|
3787
|
+
"relative z-10 rounded-sm",
|
|
3788
|
+
isDisabled ? "text-muted-soft" : isSelected ? "text-primary" : "text-ink"
|
|
3789
|
+
),
|
|
3790
|
+
labelClassName: option.badge ? void 0 : "truncate",
|
|
3791
|
+
children: [
|
|
3792
|
+
isIconOnly ? void 0 : option.label,
|
|
3793
|
+
option.badge && !isIconOnly ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "ml-xs inline-flex shrink-0 items-center", children: option.badge }) : null
|
|
3794
|
+
]
|
|
3795
|
+
}
|
|
3796
|
+
);
|
|
3797
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
3798
|
+
"div",
|
|
3799
|
+
{
|
|
3800
|
+
"data-segment": "",
|
|
3801
|
+
className: "relative flex justify-center",
|
|
3802
|
+
children: [
|
|
3803
|
+
isIconOnly ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Tooltip, { label: option.label, placement: "top", children: segment }) : segment,
|
|
3804
|
+
index < count - 1 ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3805
|
+
"span",
|
|
3806
|
+
{
|
|
3807
|
+
"aria-hidden": "true",
|
|
3808
|
+
className: cn13(
|
|
3809
|
+
"pointer-events-none absolute right-0 top-1/2 z-20 w-px -translate-y-1/2",
|
|
3810
|
+
"bg-hairline transition-opacity duration-150 ease-out",
|
|
3811
|
+
size === "sm" ? "h-3" : "h-4",
|
|
3812
|
+
seamHidden ? "opacity-0" : "opacity-100"
|
|
3813
|
+
)
|
|
3814
|
+
}
|
|
3815
|
+
) : null
|
|
3816
|
+
]
|
|
3817
|
+
},
|
|
3818
|
+
option.value
|
|
3819
|
+
);
|
|
3820
|
+
})
|
|
3821
|
+
]
|
|
3822
|
+
}
|
|
3823
|
+
)
|
|
3767
3824
|
}
|
|
3768
3825
|
) });
|
|
3769
3826
|
}
|
|
@@ -13373,7 +13430,7 @@ var DEFAULT_ACCOUNT2 = [
|
|
|
13373
13430
|
{ label: "Upgrade", icon: "gift", dividerBefore: true },
|
|
13374
13431
|
{ label: "Log out", icon: "log-out", dividerBefore: true }
|
|
13375
13432
|
];
|
|
13376
|
-
var
|
|
13433
|
+
var ICON_SIZE2 = 22;
|
|
13377
13434
|
var ACCOUNT_PANEL_WIDTH2 = 232;
|
|
13378
13435
|
var PANEL_GAP8 = 8;
|
|
13379
13436
|
var VIEWPORT_MARGIN10 = 8;
|
|
@@ -13506,7 +13563,7 @@ var NavigationMenuMobile = React68.forwardRef(
|
|
|
13506
13563
|
variant: "ghost",
|
|
13507
13564
|
size: "md",
|
|
13508
13565
|
icon: "menu",
|
|
13509
|
-
iconSize:
|
|
13566
|
+
iconSize: ICON_SIZE2,
|
|
13510
13567
|
label: menuOpen ? "Close main menu" : "Open main menu",
|
|
13511
13568
|
"aria-expanded": menuOpen,
|
|
13512
13569
|
"aria-controls": menuPanelId,
|
|
@@ -13608,7 +13665,7 @@ var NavigationMenuMobile = React68.forwardRef(
|
|
|
13608
13665
|
Icon,
|
|
13609
13666
|
{
|
|
13610
13667
|
name: item.icon,
|
|
13611
|
-
size:
|
|
13668
|
+
size: ICON_SIZE2,
|
|
13612
13669
|
tone: "inherit"
|
|
13613
13670
|
}
|
|
13614
13671
|
) : null,
|
package/dist/index.js
CHANGED
|
@@ -126,7 +126,8 @@ var ICON_REGISTRY = {
|
|
|
126
126
|
"calendar-days": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M8 2v4" }, { tag: "path", d: "M16 2v4" }, { tag: "rect", width: "18", height: "18", x: "3", y: "4", rx: "2" }, { tag: "path", d: "M3 10h18" }, { tag: "path", d: "M8 14h.01" }, { tag: "path", d: "M12 14h.01" }, { tag: "path", d: "M16 14h.01" }, { tag: "path", d: "M8 18h.01" }, { tag: "path", d: "M12 18h.01" }, { tag: "path", d: "M16 18h.01" }] },
|
|
127
127
|
"milestone": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 13v8" }, { tag: "path", d: "M12 3v3" }, { tag: "path", d: "M4 6a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h13a2 2 0 0 0 1.152-.365l3.424-2.317a1 1 0 0 0 0-1.635l-3.424-2.318A2 2 0 0 0 17 6z" }] },
|
|
128
128
|
"quote": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }, { tag: "path", d: "M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }] },
|
|
129
|
-
"brain": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }, { tag: "path", d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }, { tag: "path", d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }, { tag: "path", d: "M17.599 6.5a3 3 0 0 0 .399-1.375" }, { tag: "path", d: "M6.003 5.125A3 3 0 0 0 6.401 6.5" }, { tag: "path", d: "M3.477 10.896a4 4 0 0 1 .585-.396" }, { tag: "path", d: "M19.938 10.5a4 4 0 0 1 .585.396" }, { tag: "path", d: "M6 18a4 4 0 0 1-1.967-.516" }, { tag: "path", d: "M19.967 17.484A4 4 0 0 1 18 18" }] }
|
|
129
|
+
"brain": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }, { tag: "path", d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }, { tag: "path", d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }, { tag: "path", d: "M17.599 6.5a3 3 0 0 0 .399-1.375" }, { tag: "path", d: "M6.003 5.125A3 3 0 0 0 6.401 6.5" }, { tag: "path", d: "M3.477 10.896a4 4 0 0 1 .585-.396" }, { tag: "path", d: "M19.938 10.5a4 4 0 0 1 .585.396" }, { tag: "path", d: "M6 18a4 4 0 0 1-1.967-.516" }, { tag: "path", d: "M19.967 17.484A4 4 0 0 1 18 18" }] },
|
|
130
|
+
"view": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2" }, { tag: "path", d: "M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2" }, { tag: "circle", cx: "12", cy: "12", r: "1" }, { tag: "path", d: "M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0" }] }
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
// virtual-pkg:src/atoms/Icon/Icon.tsx
|
|
@@ -3518,7 +3519,7 @@ Breadcrumb.displayName = "Breadcrumb";
|
|
|
3518
3519
|
import * as React28 from "react";
|
|
3519
3520
|
import { jsx as jsx28, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
3520
3521
|
var cn13 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3521
|
-
var
|
|
3522
|
+
var ICON_SIZE = { sm: 16, md: 18 };
|
|
3522
3523
|
var ButtonGroup = React28.forwardRef(
|
|
3523
3524
|
({
|
|
3524
3525
|
options,
|
|
@@ -3542,6 +3543,37 @@ var ButtonGroup = React28.forwardRef(
|
|
|
3542
3543
|
);
|
|
3543
3544
|
const hasSelection = selectedIndex >= 0;
|
|
3544
3545
|
const selectedDisabled = hasSelection ? options[selectedIndex].disabled === true : false;
|
|
3546
|
+
const hasIconOnly = options.some((option) => option.iconOnly === true);
|
|
3547
|
+
const gridRef = React28.useRef(null);
|
|
3548
|
+
const [pill, setPill] = React28.useState(
|
|
3549
|
+
null
|
|
3550
|
+
);
|
|
3551
|
+
React28.useLayoutEffect(() => {
|
|
3552
|
+
const grid = gridRef.current;
|
|
3553
|
+
if (!grid) return;
|
|
3554
|
+
const measure = () => {
|
|
3555
|
+
if (selectedIndex < 0) {
|
|
3556
|
+
setPill(null);
|
|
3557
|
+
return;
|
|
3558
|
+
}
|
|
3559
|
+
const cells = grid.querySelectorAll("[data-segment]");
|
|
3560
|
+
const cell = cells[selectedIndex];
|
|
3561
|
+
if (!cell) {
|
|
3562
|
+
setPill(null);
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
const next = { x: cell.offsetLeft, width: cell.offsetWidth };
|
|
3566
|
+
setPill(
|
|
3567
|
+
(prev) => prev && prev.x === next.x && prev.width === next.width ? prev : next
|
|
3568
|
+
);
|
|
3569
|
+
};
|
|
3570
|
+
measure();
|
|
3571
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
3572
|
+
const observer = new ResizeObserver(measure);
|
|
3573
|
+
observer.observe(grid);
|
|
3574
|
+
grid.querySelectorAll("[data-segment]").forEach((cell) => observer.observe(cell));
|
|
3575
|
+
return () => observer.disconnect();
|
|
3576
|
+
}, [selectedIndex, count, size, fullWidth, hasIconOnly]);
|
|
3545
3577
|
const select = (next) => {
|
|
3546
3578
|
if (disabled) return;
|
|
3547
3579
|
if (value === void 0) setInnerValue(next);
|
|
@@ -3558,87 +3590,112 @@ var ButtonGroup = React28.forwardRef(
|
|
|
3558
3590
|
}
|
|
3559
3591
|
}
|
|
3560
3592
|
};
|
|
3561
|
-
return /* @__PURE__ */ jsx28("div", { ref, className: cn13("w-full", className), ...props, children: /* @__PURE__ */
|
|
3593
|
+
return /* @__PURE__ */ jsx28("div", { ref, className: cn13("w-full", className), ...props, children: /* @__PURE__ */ jsx28(
|
|
3562
3594
|
"div",
|
|
3563
3595
|
{
|
|
3564
3596
|
role: "group",
|
|
3565
3597
|
"aria-label": label,
|
|
3566
3598
|
"aria-disabled": disabled || void 0,
|
|
3567
3599
|
className: cn13(
|
|
3568
|
-
"
|
|
3600
|
+
"inline-flex p-xxs",
|
|
3569
3601
|
"rounded-md border border-hairline bg-surface",
|
|
3570
3602
|
"transition duration-150 ease-out",
|
|
3571
3603
|
"has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-focus-blue",
|
|
3572
3604
|
fullWidth ? "w-full" : "w-auto"
|
|
3573
3605
|
),
|
|
3574
|
-
children:
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
),
|
|
3586
|
-
style: {
|
|
3587
|
-
width: `calc((100% - ${TRACK_INSET} * 2) / ${count || 1})`,
|
|
3588
|
-
transform: `translateX(${hasSelection ? selectedIndex * 100 : 0}%)`
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
),
|
|
3592
|
-
options.map((option, index) => {
|
|
3593
|
-
const isSelected = index === selectedIndex;
|
|
3594
|
-
const isDisabled = disabled || option.disabled === true;
|
|
3595
|
-
const seamHidden = isSelected || index + 1 === selectedIndex;
|
|
3596
|
-
return /* @__PURE__ */ jsxs26("div", { className: "relative flex", children: [
|
|
3597
|
-
/* @__PURE__ */ jsxs26(
|
|
3598
|
-
Button,
|
|
3599
|
-
{
|
|
3600
|
-
chrome: "none",
|
|
3601
|
-
variant: "ghost",
|
|
3602
|
-
size,
|
|
3603
|
-
fullWidth: true,
|
|
3604
|
-
disabled: isDisabled,
|
|
3605
|
-
"aria-pressed": isSelected,
|
|
3606
|
-
onClick: () => select(option.value),
|
|
3607
|
-
onKeyDown: (event) => {
|
|
3608
|
-
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
3609
|
-
event.preventDefault();
|
|
3610
|
-
step(index, 1);
|
|
3611
|
-
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
3612
|
-
event.preventDefault();
|
|
3613
|
-
step(index, -1);
|
|
3614
|
-
}
|
|
3615
|
-
},
|
|
3616
|
-
className: cn13(
|
|
3617
|
-
"relative z-10 rounded-sm",
|
|
3618
|
-
isDisabled ? "text-muted-soft" : isSelected ? "text-primary" : "text-ink"
|
|
3619
|
-
),
|
|
3620
|
-
labelClassName: option.badge ? void 0 : "truncate",
|
|
3621
|
-
children: [
|
|
3622
|
-
option.label,
|
|
3623
|
-
option.badge ? /* @__PURE__ */ jsx28("span", { className: "ml-xs inline-flex shrink-0 items-center", children: option.badge }) : null
|
|
3624
|
-
]
|
|
3625
|
-
}
|
|
3626
|
-
),
|
|
3627
|
-
index < count - 1 ? /* @__PURE__ */ jsx28(
|
|
3606
|
+
children: /* @__PURE__ */ jsxs26(
|
|
3607
|
+
"div",
|
|
3608
|
+
{
|
|
3609
|
+
ref: gridRef,
|
|
3610
|
+
className: cn13(
|
|
3611
|
+
"relative grid grid-flow-col items-stretch",
|
|
3612
|
+
fullWidth || !hasIconOnly ? "auto-cols-fr" : "auto-cols-auto",
|
|
3613
|
+
fullWidth && "w-full"
|
|
3614
|
+
),
|
|
3615
|
+
children: [
|
|
3616
|
+
/* @__PURE__ */ jsx28(
|
|
3628
3617
|
"span",
|
|
3629
3618
|
{
|
|
3630
3619
|
"aria-hidden": "true",
|
|
3631
3620
|
className: cn13(
|
|
3632
|
-
"pointer-events-none absolute
|
|
3633
|
-
"
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3621
|
+
"pointer-events-none absolute left-0 top-0 bottom-0 rounded-sm",
|
|
3622
|
+
"transition-[transform,width,opacity,background-color] duration-[220ms] ease-out",
|
|
3623
|
+
"motion-reduce:transition-none",
|
|
3624
|
+
selectedDisabled ? "bg-surface-strong" : "bg-primary-soft",
|
|
3625
|
+
hasSelection && pill ? "opacity-100" : "opacity-0"
|
|
3626
|
+
),
|
|
3627
|
+
style: {
|
|
3628
|
+
width: pill ? pill.width : 0,
|
|
3629
|
+
transform: `translateX(${pill ? pill.x : 0}px)`
|
|
3630
|
+
}
|
|
3637
3631
|
}
|
|
3638
|
-
)
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3632
|
+
),
|
|
3633
|
+
options.map((option, index) => {
|
|
3634
|
+
const isSelected = index === selectedIndex;
|
|
3635
|
+
const isDisabled = disabled || option.disabled === true;
|
|
3636
|
+
const seamHidden = isSelected || index + 1 === selectedIndex;
|
|
3637
|
+
const isIconOnly = option.iconOnly === true && option.icon !== void 0;
|
|
3638
|
+
const segment = /* @__PURE__ */ jsxs26(
|
|
3639
|
+
Button,
|
|
3640
|
+
{
|
|
3641
|
+
chrome: "none",
|
|
3642
|
+
variant: "ghost",
|
|
3643
|
+
size,
|
|
3644
|
+
square: isIconOnly,
|
|
3645
|
+
fullWidth: !isIconOnly,
|
|
3646
|
+
disabled: isDisabled,
|
|
3647
|
+
"aria-pressed": isSelected,
|
|
3648
|
+
"aria-label": isIconOnly ? option.label : void 0,
|
|
3649
|
+
leadingIcon: option.icon,
|
|
3650
|
+
iconSize: ICON_SIZE[size],
|
|
3651
|
+
onClick: () => select(option.value),
|
|
3652
|
+
onKeyDown: (event) => {
|
|
3653
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
3654
|
+
event.preventDefault();
|
|
3655
|
+
step(index, 1);
|
|
3656
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
3657
|
+
event.preventDefault();
|
|
3658
|
+
step(index, -1);
|
|
3659
|
+
}
|
|
3660
|
+
},
|
|
3661
|
+
className: cn13(
|
|
3662
|
+
"relative z-10 rounded-sm",
|
|
3663
|
+
isDisabled ? "text-muted-soft" : isSelected ? "text-primary" : "text-ink"
|
|
3664
|
+
),
|
|
3665
|
+
labelClassName: option.badge ? void 0 : "truncate",
|
|
3666
|
+
children: [
|
|
3667
|
+
isIconOnly ? void 0 : option.label,
|
|
3668
|
+
option.badge && !isIconOnly ? /* @__PURE__ */ jsx28("span", { className: "ml-xs inline-flex shrink-0 items-center", children: option.badge }) : null
|
|
3669
|
+
]
|
|
3670
|
+
}
|
|
3671
|
+
);
|
|
3672
|
+
return /* @__PURE__ */ jsxs26(
|
|
3673
|
+
"div",
|
|
3674
|
+
{
|
|
3675
|
+
"data-segment": "",
|
|
3676
|
+
className: "relative flex justify-center",
|
|
3677
|
+
children: [
|
|
3678
|
+
isIconOnly ? /* @__PURE__ */ jsx28(Tooltip, { label: option.label, placement: "top", children: segment }) : segment,
|
|
3679
|
+
index < count - 1 ? /* @__PURE__ */ jsx28(
|
|
3680
|
+
"span",
|
|
3681
|
+
{
|
|
3682
|
+
"aria-hidden": "true",
|
|
3683
|
+
className: cn13(
|
|
3684
|
+
"pointer-events-none absolute right-0 top-1/2 z-20 w-px -translate-y-1/2",
|
|
3685
|
+
"bg-hairline transition-opacity duration-150 ease-out",
|
|
3686
|
+
size === "sm" ? "h-3" : "h-4",
|
|
3687
|
+
seamHidden ? "opacity-0" : "opacity-100"
|
|
3688
|
+
)
|
|
3689
|
+
}
|
|
3690
|
+
) : null
|
|
3691
|
+
]
|
|
3692
|
+
},
|
|
3693
|
+
option.value
|
|
3694
|
+
);
|
|
3695
|
+
})
|
|
3696
|
+
]
|
|
3697
|
+
}
|
|
3698
|
+
)
|
|
3642
3699
|
}
|
|
3643
3700
|
) });
|
|
3644
3701
|
}
|
|
@@ -13248,7 +13305,7 @@ var DEFAULT_ACCOUNT2 = [
|
|
|
13248
13305
|
{ label: "Upgrade", icon: "gift", dividerBefore: true },
|
|
13249
13306
|
{ label: "Log out", icon: "log-out", dividerBefore: true }
|
|
13250
13307
|
];
|
|
13251
|
-
var
|
|
13308
|
+
var ICON_SIZE2 = 22;
|
|
13252
13309
|
var ACCOUNT_PANEL_WIDTH2 = 232;
|
|
13253
13310
|
var PANEL_GAP8 = 8;
|
|
13254
13311
|
var VIEWPORT_MARGIN10 = 8;
|
|
@@ -13381,7 +13438,7 @@ var NavigationMenuMobile = React68.forwardRef(
|
|
|
13381
13438
|
variant: "ghost",
|
|
13382
13439
|
size: "md",
|
|
13383
13440
|
icon: "menu",
|
|
13384
|
-
iconSize:
|
|
13441
|
+
iconSize: ICON_SIZE2,
|
|
13385
13442
|
label: menuOpen ? "Close main menu" : "Open main menu",
|
|
13386
13443
|
"aria-expanded": menuOpen,
|
|
13387
13444
|
"aria-controls": menuPanelId,
|
|
@@ -13483,7 +13540,7 @@ var NavigationMenuMobile = React68.forwardRef(
|
|
|
13483
13540
|
Icon,
|
|
13484
13541
|
{
|
|
13485
13542
|
name: item.icon,
|
|
13486
|
-
size:
|
|
13543
|
+
size: ICON_SIZE2,
|
|
13487
13544
|
tone: "inherit"
|
|
13488
13545
|
}
|
|
13489
13546
|
) : null,
|
package/dist/styles.css
CHANGED
|
@@ -466,9 +466,6 @@
|
|
|
466
466
|
.left-lg {
|
|
467
467
|
left: var(--spacing-lg);
|
|
468
468
|
}
|
|
469
|
-
.left-xxs {
|
|
470
|
-
left: var(--spacing-xxs);
|
|
471
|
-
}
|
|
472
469
|
.z-0 {
|
|
473
470
|
z-index: 0;
|
|
474
471
|
}
|
|
@@ -609,6 +606,9 @@
|
|
|
609
606
|
-webkit-box-orient: vertical;
|
|
610
607
|
-webkit-line-clamp: 2;
|
|
611
608
|
}
|
|
609
|
+
.\!grid {
|
|
610
|
+
display: grid !important;
|
|
611
|
+
}
|
|
612
612
|
.block {
|
|
613
613
|
display: block;
|
|
614
614
|
}
|
|
@@ -630,9 +630,6 @@
|
|
|
630
630
|
.inline-flex {
|
|
631
631
|
display: inline-flex;
|
|
632
632
|
}
|
|
633
|
-
.inline-grid {
|
|
634
|
-
display: inline-grid;
|
|
635
|
-
}
|
|
636
633
|
.table {
|
|
637
634
|
display: table;
|
|
638
635
|
}
|
|
@@ -1168,6 +1165,9 @@
|
|
|
1168
1165
|
.columns-2 {
|
|
1169
1166
|
columns: 2;
|
|
1170
1167
|
}
|
|
1168
|
+
.auto-cols-auto {
|
|
1169
|
+
grid-auto-columns: auto;
|
|
1170
|
+
}
|
|
1171
1171
|
.auto-cols-fr {
|
|
1172
1172
|
grid-auto-columns: minmax(0, 1fr);
|
|
1173
1173
|
}
|
package/package.json
CHANGED
|
@@ -126,6 +126,7 @@ export const ICON_REGISTRY = {
|
|
|
126
126
|
"milestone": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 13v8" }, { tag: "path", d: "M12 3v3" }, { tag: "path", d: "M4 6a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h13a2 2 0 0 0 1.152-.365l3.424-2.317a1 1 0 0 0 0-1.635l-3.424-2.318A2 2 0 0 0 17 6z" }] },
|
|
127
127
|
"quote": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }, { tag: "path", d: "M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" }] },
|
|
128
128
|
"brain": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }, { tag: "path", d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }, { tag: "path", d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }, { tag: "path", d: "M17.599 6.5a3 3 0 0 0 .399-1.375" }, { tag: "path", d: "M6.003 5.125A3 3 0 0 0 6.401 6.5" }, { tag: "path", d: "M3.477 10.896a4 4 0 0 1 .585-.396" }, { tag: "path", d: "M19.938 10.5a4 4 0 0 1 .585.396" }, { tag: "path", d: "M6 18a4 4 0 0 1-1.967-.516" }, { tag: "path", d: "M19.967 17.484A4 4 0 0 1 18 18" }] },
|
|
129
|
+
"view": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2" }, { tag: "path", d: "M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2" }, { tag: "circle", cx: "12", cy: "12", r: "1" }, { tag: "path", d: "M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0" }] },
|
|
129
130
|
} satisfies Record<string, IconEntry>;
|
|
130
131
|
|
|
131
132
|
export type IconName = keyof typeof ICON_REGISTRY;
|
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Button } from "../../atoms/Button";
|
|
3
|
+
import { Tooltip } from "../../atoms/Tooltip";
|
|
4
|
+
import type { IconName } from "../../atoms/Icon";
|
|
3
5
|
|
|
4
6
|
/** One segment of the joined control. */
|
|
5
7
|
export interface ButtonGroupOption {
|
|
6
8
|
/** Stable value reported through `onValueChange`. */
|
|
7
9
|
value: string;
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Visible segment label — and the accessible name when the segment is
|
|
12
|
+
* icon-only, where the same text is shown in a tooltip on hover / focus.
|
|
13
|
+
*/
|
|
9
14
|
label: string;
|
|
10
15
|
/**
|
|
11
16
|
* Optional trailing node rendered after the label — the slot for a savings
|
|
12
17
|
* pill or a count, so the marker travels with the segment it belongs to.
|
|
18
|
+
* Ignored on icon-only segments, which render no label row.
|
|
13
19
|
*/
|
|
14
20
|
badge?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Glyph rendered before the label, sized for the group (`16px` on `sm`,
|
|
23
|
+
* `18px` on `md`). It inherits the segment's state color, so it turns brand
|
|
24
|
+
* on the selected segment and dims on a disabled one.
|
|
25
|
+
*/
|
|
26
|
+
icon?: IconName;
|
|
27
|
+
/**
|
|
28
|
+
* Renders the icon alone in a square segment: the label becomes the
|
|
29
|
+
* segment's `aria-label` and appears in a tooltip on hover / focus. Falls
|
|
30
|
+
* back to the plain label when no `icon` is supplied.
|
|
31
|
+
*/
|
|
32
|
+
iconOnly?: boolean;
|
|
15
33
|
/** Locks this single segment without disabling the rest of the group. */
|
|
16
34
|
disabled?: boolean;
|
|
17
35
|
}
|
|
@@ -44,13 +62,19 @@ export interface ButtonGroupProps
|
|
|
44
62
|
const cn = (...parts: Array<string | false | null | undefined>): string =>
|
|
45
63
|
parts.filter(Boolean).join(" ");
|
|
46
64
|
|
|
47
|
-
/**
|
|
48
|
-
const
|
|
65
|
+
/** Glyph size per group size — the icon tracks the label's cap height. */
|
|
66
|
+
const ICON_SIZE: Record<ButtonGroupSize, number> = { sm: 16, md: 18 };
|
|
49
67
|
|
|
50
68
|
/**
|
|
51
69
|
* A joined segmented control. The segments share one outer stroke and one
|
|
52
70
|
* selected pill that slides between them, so a selection change reads as
|
|
53
71
|
* movement rather than a per-segment colour swap.
|
|
72
|
+
*
|
|
73
|
+
* Segments take an optional `icon` (glyph before the label) and `iconOnly`
|
|
74
|
+
* (glyph alone in a square segment with its label as `aria-label` plus a
|
|
75
|
+
* tooltip). Mixed groups keep one height, one selected recipe and one
|
|
76
|
+
* keyboard behaviour: the pill is measured from the live segment geometry, so
|
|
77
|
+
* it still tracks a row of mixed-width segments.
|
|
54
78
|
*/
|
|
55
79
|
export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
56
80
|
(
|
|
@@ -81,6 +105,45 @@ export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
81
105
|
const selectedDisabled = hasSelection
|
|
82
106
|
? options[selectedIndex].disabled === true
|
|
83
107
|
: false;
|
|
108
|
+
/** Any icon-only segment switches the track from equal to content sizing. */
|
|
109
|
+
const hasIconOnly = options.some((option) => option.iconOnly === true);
|
|
110
|
+
|
|
111
|
+
const gridRef = React.useRef<HTMLDivElement | null>(null);
|
|
112
|
+
/** The selected segment's own box, so the pill can follow mixed widths. */
|
|
113
|
+
const [pill, setPill] = React.useState<{ x: number; width: number } | null>(
|
|
114
|
+
null,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
React.useLayoutEffect(() => {
|
|
118
|
+
const grid = gridRef.current;
|
|
119
|
+
if (!grid) return;
|
|
120
|
+
|
|
121
|
+
const measure = () => {
|
|
122
|
+
if (selectedIndex < 0) {
|
|
123
|
+
setPill(null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const cells = grid.querySelectorAll<HTMLElement>("[data-segment]");
|
|
127
|
+
const cell = cells[selectedIndex];
|
|
128
|
+
if (!cell) {
|
|
129
|
+
setPill(null);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const next = { x: cell.offsetLeft, width: cell.offsetWidth };
|
|
133
|
+
setPill((prev) =>
|
|
134
|
+
prev && prev.x === next.x && prev.width === next.width ? prev : next,
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
measure();
|
|
139
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
140
|
+
const observer = new ResizeObserver(measure);
|
|
141
|
+
observer.observe(grid);
|
|
142
|
+
grid
|
|
143
|
+
.querySelectorAll<HTMLElement>("[data-segment]")
|
|
144
|
+
.forEach((cell) => observer.observe(cell));
|
|
145
|
+
return () => observer.disconnect();
|
|
146
|
+
}, [selectedIndex, count, size, fullWidth, hasIconOnly]);
|
|
84
147
|
|
|
85
148
|
const select = (next: string) => {
|
|
86
149
|
if (disabled) return;
|
|
@@ -107,42 +170,56 @@ export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
107
170
|
aria-label={label}
|
|
108
171
|
aria-disabled={disabled || undefined}
|
|
109
172
|
className={cn(
|
|
110
|
-
"
|
|
173
|
+
"inline-flex p-xxs",
|
|
111
174
|
"rounded-md border border-hairline bg-surface",
|
|
112
175
|
"transition duration-150 ease-out",
|
|
113
176
|
"has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-focus-blue",
|
|
114
177
|
fullWidth ? "w-full" : "w-auto",
|
|
115
178
|
)}
|
|
116
179
|
>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
aria-hidden="true"
|
|
180
|
+
<div
|
|
181
|
+
ref={gridRef}
|
|
120
182
|
className={cn(
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
selectedDisabled ? "bg-surface-strong" : "bg-primary-soft",
|
|
125
|
-
hasSelection ? "opacity-100" : "opacity-0",
|
|
183
|
+
"relative grid grid-flow-col items-stretch",
|
|
184
|
+
fullWidth || !hasIconOnly ? "auto-cols-fr" : "auto-cols-auto",
|
|
185
|
+
fullWidth && "w-full",
|
|
126
186
|
)}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
187
|
+
>
|
|
188
|
+
{/* One shared pill; it travels to the selected segment's own box. */}
|
|
189
|
+
<span
|
|
190
|
+
aria-hidden="true"
|
|
191
|
+
className={cn(
|
|
192
|
+
"pointer-events-none absolute left-0 top-0 bottom-0 rounded-sm",
|
|
193
|
+
"transition-[transform,width,opacity,background-color] duration-[220ms] ease-out",
|
|
194
|
+
"motion-reduce:transition-none",
|
|
195
|
+
selectedDisabled ? "bg-surface-strong" : "bg-primary-soft",
|
|
196
|
+
hasSelection && pill ? "opacity-100" : "opacity-0",
|
|
197
|
+
)}
|
|
198
|
+
style={{
|
|
199
|
+
width: pill ? pill.width : 0,
|
|
200
|
+
transform: `translateX(${pill ? pill.x : 0}px)`,
|
|
201
|
+
}}
|
|
202
|
+
/>
|
|
203
|
+
|
|
204
|
+
{options.map((option, index) => {
|
|
205
|
+
const isSelected = index === selectedIndex;
|
|
206
|
+
const isDisabled = disabled || option.disabled === true;
|
|
207
|
+
const seamHidden = isSelected || index + 1 === selectedIndex;
|
|
208
|
+
const isIconOnly =
|
|
209
|
+
option.iconOnly === true && option.icon !== undefined;
|
|
210
|
+
|
|
211
|
+
const segment = (
|
|
139
212
|
<Button
|
|
140
213
|
chrome="none"
|
|
141
214
|
variant="ghost"
|
|
142
215
|
size={size}
|
|
143
|
-
|
|
216
|
+
square={isIconOnly}
|
|
217
|
+
fullWidth={!isIconOnly}
|
|
144
218
|
disabled={isDisabled}
|
|
145
219
|
aria-pressed={isSelected}
|
|
220
|
+
aria-label={isIconOnly ? option.label : undefined}
|
|
221
|
+
leadingIcon={option.icon}
|
|
222
|
+
iconSize={ICON_SIZE[size]}
|
|
146
223
|
onClick={() => select(option.value)}
|
|
147
224
|
onKeyDown={(event) => {
|
|
148
225
|
if (
|
|
@@ -169,29 +246,45 @@ export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
169
246
|
)}
|
|
170
247
|
labelClassName={option.badge ? undefined : "truncate"}
|
|
171
248
|
>
|
|
172
|
-
{option.label}
|
|
173
|
-
{option.badge ? (
|
|
249
|
+
{isIconOnly ? undefined : option.label}
|
|
250
|
+
{option.badge && !isIconOnly ? (
|
|
174
251
|
<span className="ml-xs inline-flex shrink-0 items-center">
|
|
175
252
|
{option.badge}
|
|
176
253
|
</span>
|
|
177
254
|
) : null}
|
|
178
255
|
</Button>
|
|
256
|
+
);
|
|
179
257
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
258
|
+
return (
|
|
259
|
+
<div
|
|
260
|
+
key={option.value}
|
|
261
|
+
data-segment=""
|
|
262
|
+
className="relative flex justify-center"
|
|
263
|
+
>
|
|
264
|
+
{isIconOnly ? (
|
|
265
|
+
<Tooltip label={option.label} placement="top">
|
|
266
|
+
{segment}
|
|
267
|
+
</Tooltip>
|
|
268
|
+
) : (
|
|
269
|
+
segment
|
|
270
|
+
)}
|
|
271
|
+
|
|
272
|
+
{/* A seam only survives between two unselected segments. */}
|
|
273
|
+
{index < count - 1 ? (
|
|
274
|
+
<span
|
|
275
|
+
aria-hidden="true"
|
|
276
|
+
className={cn(
|
|
277
|
+
"pointer-events-none absolute right-0 top-1/2 z-20 w-px -translate-y-1/2",
|
|
278
|
+
"bg-hairline transition-opacity duration-150 ease-out",
|
|
279
|
+
size === "sm" ? "h-3" : "h-4",
|
|
280
|
+
seamHidden ? "opacity-0" : "opacity-100",
|
|
281
|
+
)}
|
|
282
|
+
/>
|
|
283
|
+
) : null}
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
})}
|
|
287
|
+
</div>
|
|
195
288
|
</div>
|
|
196
289
|
</div>
|
|
197
290
|
);
|
|
@@ -21,13 +21,11 @@ const billingOptions = [
|
|
|
21
21
|
export default function ButtonGroupPreview() {
|
|
22
22
|
const [billing, setBilling] = React.useState("monthly");
|
|
23
23
|
const [density, setDensity] = React.useState("comfortable");
|
|
24
|
+
const [view, setView] = React.useState("list");
|
|
25
|
+
const [tab, setTab] = React.useState("upcoming");
|
|
24
26
|
|
|
25
27
|
return (
|
|
26
28
|
<div className="w-full max-w-3xl mx-auto bg-canvas p-lg space-y-xl">
|
|
27
|
-
<Demo caption="Default">
|
|
28
|
-
<ButtonGroup label="Billing period, unselected" options={billingOptions} />
|
|
29
|
-
</Demo>
|
|
30
|
-
|
|
31
29
|
<Demo caption="One selected — click a segment and the pill slides">
|
|
32
30
|
<ButtonGroup
|
|
33
31
|
label="Billing period"
|
|
@@ -37,18 +35,73 @@ export default function ButtonGroupPreview() {
|
|
|
37
35
|
/>
|
|
38
36
|
</Demo>
|
|
39
37
|
|
|
40
|
-
<Demo caption="
|
|
38
|
+
<Demo caption="Icon before the label — hover or click to change the view">
|
|
39
|
+
<ButtonGroup
|
|
40
|
+
label="View"
|
|
41
|
+
value={view}
|
|
42
|
+
onValueChange={setView}
|
|
43
|
+
options={[
|
|
44
|
+
{ value: "list", label: "List", icon: "list" },
|
|
45
|
+
{ value: "grid", label: "Grid", icon: "view" },
|
|
46
|
+
{ value: "board", label: "Board", icon: "kanban" },
|
|
47
|
+
]}
|
|
48
|
+
/>
|
|
49
|
+
</Demo>
|
|
50
|
+
|
|
51
|
+
<Demo caption="Icon-only — square segments, label as aria-label plus a tooltip">
|
|
52
|
+
<ButtonGroup
|
|
53
|
+
label="View mode"
|
|
54
|
+
value={view}
|
|
55
|
+
onValueChange={setView}
|
|
56
|
+
options={[
|
|
57
|
+
{ value: "list", label: "List view", icon: "list", iconOnly: true },
|
|
58
|
+
{ value: "grid", label: "Grid view", icon: "view", iconOnly: true },
|
|
59
|
+
{
|
|
60
|
+
value: "board",
|
|
61
|
+
label: "Board view",
|
|
62
|
+
icon: "kanban",
|
|
63
|
+
iconOnly: true,
|
|
64
|
+
},
|
|
65
|
+
]}
|
|
66
|
+
/>
|
|
67
|
+
</Demo>
|
|
68
|
+
|
|
69
|
+
<Demo caption="Mixed — two icon-only segments plus one labelled, selected segment">
|
|
70
|
+
<ButtonGroup
|
|
71
|
+
label="Schedule range"
|
|
72
|
+
size="sm"
|
|
73
|
+
value={tab}
|
|
74
|
+
onValueChange={setTab}
|
|
75
|
+
options={[
|
|
76
|
+
{
|
|
77
|
+
value: "templates",
|
|
78
|
+
label: "Saved templates",
|
|
79
|
+
icon: "list",
|
|
80
|
+
iconOnly: true,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
value: "boards",
|
|
84
|
+
label: "Boards",
|
|
85
|
+
icon: "kanban",
|
|
86
|
+
iconOnly: true,
|
|
87
|
+
},
|
|
88
|
+
{ value: "upcoming", label: "Upcoming", icon: "view" },
|
|
89
|
+
]}
|
|
90
|
+
/>
|
|
91
|
+
</Demo>
|
|
92
|
+
|
|
93
|
+
<Demo caption="Disabled segment and a locked icon-only segment">
|
|
41
94
|
<ButtonGroup
|
|
42
95
|
label="Billing period with a locked segment"
|
|
43
96
|
defaultValue="yearly"
|
|
44
97
|
options={[
|
|
45
98
|
{ value: "monthly", label: "Monthly", disabled: true },
|
|
46
|
-
{ value: "yearly", label: "Yearly" },
|
|
99
|
+
{ value: "yearly", label: "Yearly", icon: "view" },
|
|
47
100
|
]}
|
|
48
101
|
/>
|
|
49
102
|
</Demo>
|
|
50
103
|
|
|
51
|
-
<Demo caption="Three segments, compact size">
|
|
104
|
+
<Demo caption="Three labelled segments, compact size">
|
|
52
105
|
<ButtonGroup
|
|
53
106
|
label="Row density"
|
|
54
107
|
size="sm"
|