@designa8/vibedesign-linear-internal-v1-b737 0.11.1 → 0.11.2
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 +94 -73
- package/dist/index.js +94 -73
- package/package.json +1 -1
- package/src/atoms/Badge/Badge.tsx +5 -1
- package/src/atoms/SegmentedControl/SegmentedControl.tsx +40 -5
- package/src/atoms/SegmentedControl/preview.tsx +21 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-linear-internal-v1-b737
|
|
2
2
|
|
|
3
|
-
Complete design system generated by Atoms Design, version **0.11.
|
|
3
|
+
Complete design system generated by Atoms Design, version **0.11.2**.
|
|
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
|
@@ -1858,7 +1858,8 @@ var TONE = {
|
|
|
1858
1858
|
warning: "bg-semantic-warning-soft text-semantic-warning",
|
|
1859
1859
|
error: "bg-semantic-error-soft text-semantic-error",
|
|
1860
1860
|
info: "bg-semantic-info-soft text-semantic-info",
|
|
1861
|
-
"on-primary": "bg-on-primary/20 text-on-primary"
|
|
1861
|
+
"on-primary": "bg-on-primary/20 text-on-primary",
|
|
1862
|
+
"on-primary-solid": "bg-on-primary text-primary"
|
|
1862
1863
|
};
|
|
1863
1864
|
var SIZE = {
|
|
1864
1865
|
sm: "h-5 gap-xs rounded-sm px-xs text-caption",
|
|
@@ -9994,7 +9995,16 @@ var pillRadius = {
|
|
|
9994
9995
|
md: "rounded-md"
|
|
9995
9996
|
};
|
|
9996
9997
|
var SegmentedControl = React83.forwardRef(
|
|
9997
|
-
({
|
|
9998
|
+
({
|
|
9999
|
+
items,
|
|
10000
|
+
value,
|
|
10001
|
+
onValueChange,
|
|
10002
|
+
size = "sm",
|
|
10003
|
+
bare = false,
|
|
10004
|
+
fullWidth = false,
|
|
10005
|
+
className,
|
|
10006
|
+
...rest
|
|
10007
|
+
}, ref) => {
|
|
9998
10008
|
const trackRef = React83.useRef(null);
|
|
9999
10009
|
const itemRefs = React83.useRef({});
|
|
10000
10010
|
const [pill, setPill] = React83.useState(null);
|
|
@@ -10029,80 +10039,91 @@ var SegmentedControl = React83.forwardRef(
|
|
|
10029
10039
|
onValueChange(next.value);
|
|
10030
10040
|
itemRefs.current[next.value]?.focus();
|
|
10031
10041
|
};
|
|
10032
|
-
return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10042
|
+
return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10033
10043
|
"div",
|
|
10034
10044
|
{
|
|
10035
|
-
ref
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
"
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
"
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
|
|
10073
|
-
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10045
|
+
ref,
|
|
10046
|
+
className: cn62("min-w-0", fullWidth ? "flex w-full" : "inline-flex max-w-full"),
|
|
10047
|
+
...rest,
|
|
10048
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime83.jsxs)(
|
|
10049
|
+
"div",
|
|
10050
|
+
{
|
|
10051
|
+
ref: trackRef,
|
|
10052
|
+
role: "tablist",
|
|
10053
|
+
"aria-orientation": "horizontal",
|
|
10054
|
+
onKeyDown,
|
|
10055
|
+
className: cn62(
|
|
10056
|
+
"relative isolate inline-flex max-w-full items-center overflow-x-auto rounded-lg",
|
|
10057
|
+
frame[size],
|
|
10058
|
+
bare ? "bg-transparent" : "border border-hairline bg-canvas shadow-sm",
|
|
10059
|
+
fullWidth && "flex w-full",
|
|
10060
|
+
"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
10061
|
+
className
|
|
10062
|
+
),
|
|
10063
|
+
children: [
|
|
10064
|
+
!bare ? /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10065
|
+
"span",
|
|
10066
|
+
{
|
|
10067
|
+
"aria-hidden": "true",
|
|
10068
|
+
className: cn62(
|
|
10069
|
+
"pointer-events-none absolute top-xxs bottom-xxs left-0 -z-10 bg-primary shadow-sm transition-[transform,width] duration-200 ease-out",
|
|
10070
|
+
pillRadius[size]
|
|
10071
|
+
),
|
|
10072
|
+
style: pill ? { width: pill.width, transform: `translateX(${pill.offset}px)` } : { width: 0, opacity: 0 }
|
|
10073
|
+
}
|
|
10074
|
+
) : null,
|
|
10075
|
+
items.map((item) => {
|
|
10076
|
+
const active = item.value === value;
|
|
10077
|
+
const iconOnly = Boolean(item.icon) && item.label == null;
|
|
10078
|
+
const glyphSize3 = size === "sm" ? 14 : 16;
|
|
10079
|
+
const pillFallback = !bare && active && !pill ? "bg-primary" : false;
|
|
10080
|
+
return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10081
|
+
Button,
|
|
10082
|
+
{
|
|
10083
|
+
ref: (el) => {
|
|
10084
|
+
itemRefs.current[item.value] = el;
|
|
10085
|
+
},
|
|
10086
|
+
type: "button",
|
|
10087
|
+
role: "tab",
|
|
10088
|
+
"aria-selected": active,
|
|
10089
|
+
"aria-label": iconOnly ? item["aria-label"] ?? item.value : void 0,
|
|
10090
|
+
tabIndex: active || value === void 0 && item.value === firstEnabled ? 0 : -1,
|
|
10091
|
+
variant: bare ? active ? "primary" : "ghost" : "bare",
|
|
10092
|
+
size,
|
|
10093
|
+
iconOnly,
|
|
10094
|
+
disabled: item.disabled,
|
|
10095
|
+
onClick: () => onValueChange(item.value),
|
|
10096
|
+
className: cn62(segmentInteraction, pillFallback, fullWidth && "flex-1"),
|
|
10097
|
+
children: iconOnly ? /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(Icon, { name: item.icon, size: glyphSize3 }) : /* @__PURE__ */ (0, import_jsx_runtime83.jsxs)("span", { className: "inline-flex min-w-0 items-center gap-xs", children: [
|
|
10098
|
+
item.dotClassName ? /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10099
|
+
"span",
|
|
10100
|
+
{
|
|
10101
|
+
"aria-hidden": "true",
|
|
10102
|
+
className: cn62("h-2 w-2 shrink-0 rounded-full", item.dotClassName)
|
|
10103
|
+
}
|
|
10104
|
+
) : null,
|
|
10105
|
+
item.icon ? /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(Icon, { name: item.icon, size: glyphSize3 }) : null,
|
|
10106
|
+
/* @__PURE__ */ (0, import_jsx_runtime83.jsx)("span", { className: "truncate", children: item.label }),
|
|
10107
|
+
item.count !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
|
|
10108
|
+
Badge,
|
|
10109
|
+
{
|
|
10110
|
+
size: "sm",
|
|
10111
|
+
tone: active ? "on-primary-solid" : "neutral",
|
|
10112
|
+
"aria-label": `${item.count} items`,
|
|
10113
|
+
className: "min-w-5 justify-center",
|
|
10114
|
+
children: item.count
|
|
10115
|
+
}
|
|
10116
|
+
) : null
|
|
10117
|
+
] })
|
|
10118
|
+
},
|
|
10119
|
+
item.value
|
|
10120
|
+
);
|
|
10121
|
+
})
|
|
10122
|
+
]
|
|
10123
|
+
}
|
|
10124
|
+
)
|
|
10104
10125
|
}
|
|
10105
|
-
)
|
|
10126
|
+
);
|
|
10106
10127
|
}
|
|
10107
10128
|
);
|
|
10108
10129
|
SegmentedControl.displayName = "SegmentedControl";
|
package/dist/index.js
CHANGED
|
@@ -1714,7 +1714,8 @@ var TONE = {
|
|
|
1714
1714
|
warning: "bg-semantic-warning-soft text-semantic-warning",
|
|
1715
1715
|
error: "bg-semantic-error-soft text-semantic-error",
|
|
1716
1716
|
info: "bg-semantic-info-soft text-semantic-info",
|
|
1717
|
-
"on-primary": "bg-on-primary/20 text-on-primary"
|
|
1717
|
+
"on-primary": "bg-on-primary/20 text-on-primary",
|
|
1718
|
+
"on-primary-solid": "bg-on-primary text-primary"
|
|
1718
1719
|
};
|
|
1719
1720
|
var SIZE = {
|
|
1720
1721
|
sm: "h-5 gap-xs rounded-sm px-xs text-caption",
|
|
@@ -9850,7 +9851,16 @@ var pillRadius = {
|
|
|
9850
9851
|
md: "rounded-md"
|
|
9851
9852
|
};
|
|
9852
9853
|
var SegmentedControl = React83.forwardRef(
|
|
9853
|
-
({
|
|
9854
|
+
({
|
|
9855
|
+
items,
|
|
9856
|
+
value,
|
|
9857
|
+
onValueChange,
|
|
9858
|
+
size = "sm",
|
|
9859
|
+
bare = false,
|
|
9860
|
+
fullWidth = false,
|
|
9861
|
+
className,
|
|
9862
|
+
...rest
|
|
9863
|
+
}, ref) => {
|
|
9854
9864
|
const trackRef = React83.useRef(null);
|
|
9855
9865
|
const itemRefs = React83.useRef({});
|
|
9856
9866
|
const [pill, setPill] = React83.useState(null);
|
|
@@ -9885,80 +9895,91 @@ var SegmentedControl = React83.forwardRef(
|
|
|
9885
9895
|
onValueChange(next.value);
|
|
9886
9896
|
itemRefs.current[next.value]?.focus();
|
|
9887
9897
|
};
|
|
9888
|
-
return /* @__PURE__ */ jsx83(
|
|
9898
|
+
return /* @__PURE__ */ jsx83(
|
|
9889
9899
|
"div",
|
|
9890
9900
|
{
|
|
9891
|
-
ref
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
"
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
"
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9901
|
+
ref,
|
|
9902
|
+
className: cn62("min-w-0", fullWidth ? "flex w-full" : "inline-flex max-w-full"),
|
|
9903
|
+
...rest,
|
|
9904
|
+
children: /* @__PURE__ */ jsxs77(
|
|
9905
|
+
"div",
|
|
9906
|
+
{
|
|
9907
|
+
ref: trackRef,
|
|
9908
|
+
role: "tablist",
|
|
9909
|
+
"aria-orientation": "horizontal",
|
|
9910
|
+
onKeyDown,
|
|
9911
|
+
className: cn62(
|
|
9912
|
+
"relative isolate inline-flex max-w-full items-center overflow-x-auto rounded-lg",
|
|
9913
|
+
frame[size],
|
|
9914
|
+
bare ? "bg-transparent" : "border border-hairline bg-canvas shadow-sm",
|
|
9915
|
+
fullWidth && "flex w-full",
|
|
9916
|
+
"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
9917
|
+
className
|
|
9918
|
+
),
|
|
9919
|
+
children: [
|
|
9920
|
+
!bare ? /* @__PURE__ */ jsx83(
|
|
9921
|
+
"span",
|
|
9922
|
+
{
|
|
9923
|
+
"aria-hidden": "true",
|
|
9924
|
+
className: cn62(
|
|
9925
|
+
"pointer-events-none absolute top-xxs bottom-xxs left-0 -z-10 bg-primary shadow-sm transition-[transform,width] duration-200 ease-out",
|
|
9926
|
+
pillRadius[size]
|
|
9927
|
+
),
|
|
9928
|
+
style: pill ? { width: pill.width, transform: `translateX(${pill.offset}px)` } : { width: 0, opacity: 0 }
|
|
9929
|
+
}
|
|
9930
|
+
) : null,
|
|
9931
|
+
items.map((item) => {
|
|
9932
|
+
const active = item.value === value;
|
|
9933
|
+
const iconOnly = Boolean(item.icon) && item.label == null;
|
|
9934
|
+
const glyphSize3 = size === "sm" ? 14 : 16;
|
|
9935
|
+
const pillFallback = !bare && active && !pill ? "bg-primary" : false;
|
|
9936
|
+
return /* @__PURE__ */ jsx83(
|
|
9937
|
+
Button,
|
|
9938
|
+
{
|
|
9939
|
+
ref: (el) => {
|
|
9940
|
+
itemRefs.current[item.value] = el;
|
|
9941
|
+
},
|
|
9942
|
+
type: "button",
|
|
9943
|
+
role: "tab",
|
|
9944
|
+
"aria-selected": active,
|
|
9945
|
+
"aria-label": iconOnly ? item["aria-label"] ?? item.value : void 0,
|
|
9946
|
+
tabIndex: active || value === void 0 && item.value === firstEnabled ? 0 : -1,
|
|
9947
|
+
variant: bare ? active ? "primary" : "ghost" : "bare",
|
|
9948
|
+
size,
|
|
9949
|
+
iconOnly,
|
|
9950
|
+
disabled: item.disabled,
|
|
9951
|
+
onClick: () => onValueChange(item.value),
|
|
9952
|
+
className: cn62(segmentInteraction, pillFallback, fullWidth && "flex-1"),
|
|
9953
|
+
children: iconOnly ? /* @__PURE__ */ jsx83(Icon, { name: item.icon, size: glyphSize3 }) : /* @__PURE__ */ jsxs77("span", { className: "inline-flex min-w-0 items-center gap-xs", children: [
|
|
9954
|
+
item.dotClassName ? /* @__PURE__ */ jsx83(
|
|
9955
|
+
"span",
|
|
9956
|
+
{
|
|
9957
|
+
"aria-hidden": "true",
|
|
9958
|
+
className: cn62("h-2 w-2 shrink-0 rounded-full", item.dotClassName)
|
|
9959
|
+
}
|
|
9960
|
+
) : null,
|
|
9961
|
+
item.icon ? /* @__PURE__ */ jsx83(Icon, { name: item.icon, size: glyphSize3 }) : null,
|
|
9962
|
+
/* @__PURE__ */ jsx83("span", { className: "truncate", children: item.label }),
|
|
9963
|
+
item.count !== void 0 ? /* @__PURE__ */ jsx83(
|
|
9964
|
+
Badge,
|
|
9965
|
+
{
|
|
9966
|
+
size: "sm",
|
|
9967
|
+
tone: active ? "on-primary-solid" : "neutral",
|
|
9968
|
+
"aria-label": `${item.count} items`,
|
|
9969
|
+
className: "min-w-5 justify-center",
|
|
9970
|
+
children: item.count
|
|
9971
|
+
}
|
|
9972
|
+
) : null
|
|
9973
|
+
] })
|
|
9974
|
+
},
|
|
9975
|
+
item.value
|
|
9976
|
+
);
|
|
9977
|
+
})
|
|
9978
|
+
]
|
|
9979
|
+
}
|
|
9980
|
+
)
|
|
9960
9981
|
}
|
|
9961
|
-
)
|
|
9982
|
+
);
|
|
9962
9983
|
}
|
|
9963
9984
|
);
|
|
9964
9985
|
SegmentedControl.displayName = "SegmentedControl";
|
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import type { IconProps } from "../Icon";
|
|
|
6
6
|
* `on-primary` keeps a count legible when the badge sits on a solid primary
|
|
7
7
|
* fill (e.g. the active segment of a segmented control): it inverts to
|
|
8
8
|
* `on-primary` text over a translucent `on-primary` tint.
|
|
9
|
+
* `on-primary-solid` is the high-contrast companion for small caption text on
|
|
10
|
+
* that same fill: a solid `on-primary` chip with `primary` text.
|
|
9
11
|
*/
|
|
10
12
|
export type BadgeTone =
|
|
11
13
|
| "neutral"
|
|
@@ -14,7 +16,8 @@ export type BadgeTone =
|
|
|
14
16
|
| "warning"
|
|
15
17
|
| "error"
|
|
16
18
|
| "info"
|
|
17
|
-
| "on-primary"
|
|
19
|
+
| "on-primary"
|
|
20
|
+
| "on-primary-solid";
|
|
18
21
|
export type BadgeSize = "sm" | "md" | "lg";
|
|
19
22
|
|
|
20
23
|
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
@@ -32,6 +35,7 @@ const TONE: Record<BadgeTone, string> = {
|
|
|
32
35
|
error: "bg-semantic-error-soft text-semantic-error",
|
|
33
36
|
info: "bg-semantic-info-soft text-semantic-info",
|
|
34
37
|
"on-primary": "bg-on-primary/20 text-on-primary",
|
|
38
|
+
"on-primary-solid": "bg-on-primary text-primary",
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
const SIZE: Record<BadgeSize, string> = {
|
|
@@ -19,7 +19,7 @@ export interface SegmentedControlItem {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface SegmentedControlProps
|
|
22
|
-
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
22
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "className"> {
|
|
23
23
|
items: SegmentedControlItem[];
|
|
24
24
|
/** Selected value. Pass `undefined` for "no segment selected". */
|
|
25
25
|
value: string | undefined;
|
|
@@ -27,6 +27,13 @@ export interface SegmentedControlProps
|
|
|
27
27
|
size?: "sm" | "md";
|
|
28
28
|
/** Drop the frame (border, surface, shadow), e.g. when nested in a toolbar. */
|
|
29
29
|
bare?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Stretch the control to the full width of its container and share the space
|
|
32
|
+
* between segments. Defaults to `false`, which sizes the control to content.
|
|
33
|
+
*/
|
|
34
|
+
fullWidth?: boolean;
|
|
35
|
+
/** Lands on the tablist itself, so consumers can shape it without a wrapper. */
|
|
36
|
+
className?: string;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
@@ -54,9 +61,25 @@ const pillRadius: Record<"sm" | "md", string> = {
|
|
|
54
61
|
* A compact segmented control: one framed surface, a single primary indicator
|
|
55
62
|
* that slides between segments, and segments that only report the chosen value
|
|
56
63
|
* (`onValueChange`) — no panels, unlike Tabs.
|
|
64
|
+
*
|
|
65
|
+
* The active segment carries a `bg-primary` fallback that the sliding pill
|
|
66
|
+
* replaces once it is measured, so the on-primary label never renders
|
|
67
|
+
* invisible on first paint.
|
|
57
68
|
*/
|
|
58
69
|
export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(
|
|
59
|
-
(
|
|
70
|
+
(
|
|
71
|
+
{
|
|
72
|
+
items,
|
|
73
|
+
value,
|
|
74
|
+
onValueChange,
|
|
75
|
+
size = "sm",
|
|
76
|
+
bare = false,
|
|
77
|
+
fullWidth = false,
|
|
78
|
+
className,
|
|
79
|
+
...rest
|
|
80
|
+
},
|
|
81
|
+
ref,
|
|
82
|
+
) => {
|
|
60
83
|
const trackRef = React.useRef<HTMLDivElement | null>(null);
|
|
61
84
|
const itemRefs = React.useRef<Record<string, HTMLButtonElement | null>>({});
|
|
62
85
|
const [pill, setPill] = React.useState<{ offset: number; width: number } | null>(null);
|
|
@@ -96,7 +119,11 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
96
119
|
};
|
|
97
120
|
|
|
98
121
|
return (
|
|
99
|
-
<div
|
|
122
|
+
<div
|
|
123
|
+
ref={ref}
|
|
124
|
+
className={cn("min-w-0", fullWidth ? "flex w-full" : "inline-flex max-w-full")}
|
|
125
|
+
{...rest}
|
|
126
|
+
>
|
|
100
127
|
<div
|
|
101
128
|
ref={trackRef}
|
|
102
129
|
role="tablist"
|
|
@@ -106,7 +133,9 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
106
133
|
"relative isolate inline-flex max-w-full items-center overflow-x-auto rounded-lg",
|
|
107
134
|
frame[size],
|
|
108
135
|
bare ? "bg-transparent" : "border border-hairline bg-canvas shadow-sm",
|
|
136
|
+
fullWidth && "flex w-full",
|
|
109
137
|
"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
138
|
+
className,
|
|
110
139
|
)}
|
|
111
140
|
>
|
|
112
141
|
{!bare ? (
|
|
@@ -128,6 +157,12 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
128
157
|
const active = item.value === value;
|
|
129
158
|
const iconOnly = Boolean(item.icon) && item.label == null;
|
|
130
159
|
const glyphSize = size === "sm" ? 14 : 16;
|
|
160
|
+
/**
|
|
161
|
+
* Until the sliding pill is measured (first paint, before the
|
|
162
|
+
* layout effect runs) the active segment paints its own primary
|
|
163
|
+
* fill, so `on-primary` text is never invisible on `canvas`.
|
|
164
|
+
*/
|
|
165
|
+
const pillFallback = !bare && active && !pill ? "bg-primary" : false;
|
|
131
166
|
return (
|
|
132
167
|
<Button
|
|
133
168
|
key={item.value}
|
|
@@ -144,7 +179,7 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
144
179
|
iconOnly={iconOnly}
|
|
145
180
|
disabled={item.disabled}
|
|
146
181
|
onClick={() => onValueChange(item.value)}
|
|
147
|
-
className={segmentInteraction}
|
|
182
|
+
className={cn(segmentInteraction, pillFallback, fullWidth && "flex-1")}
|
|
148
183
|
>
|
|
149
184
|
{iconOnly ? (
|
|
150
185
|
<Icon name={item.icon!} size={glyphSize} />
|
|
@@ -161,7 +196,7 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
161
196
|
{item.count !== undefined ? (
|
|
162
197
|
<Badge
|
|
163
198
|
size="sm"
|
|
164
|
-
tone={active ? "on-primary" : "neutral"}
|
|
199
|
+
tone={active ? "on-primary-solid" : "neutral"}
|
|
165
200
|
aria-label={`${item.count} items`}
|
|
166
201
|
className="min-w-5 justify-center"
|
|
167
202
|
>
|
|
@@ -21,11 +21,18 @@ const STATE_ITEMS: SegmentedControlItem[] = [
|
|
|
21
21
|
{ value: "archived", label: "Archived", disabled: true },
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
+
const RANGE_ITEMS: SegmentedControlItem[] = [
|
|
25
|
+
{ value: "day", label: "Day" },
|
|
26
|
+
{ value: "week", label: "Week" },
|
|
27
|
+
{ value: "month", label: "Month" },
|
|
28
|
+
];
|
|
29
|
+
|
|
24
30
|
export default function SegmentedControlPreview() {
|
|
25
31
|
const [kind, setKind] = React.useState("all");
|
|
26
32
|
const [viewport, setViewport] = React.useState("desktop");
|
|
27
33
|
const [state, setState] = React.useState("review");
|
|
28
34
|
const [toolbarView, setToolbarView] = React.useState("grid");
|
|
35
|
+
const [range, setRange] = React.useState("week");
|
|
29
36
|
|
|
30
37
|
return (
|
|
31
38
|
<div className="w-full max-w-3xl mx-auto space-y-xl p-lg">
|
|
@@ -64,6 +71,20 @@ export default function SegmentedControlPreview() {
|
|
|
64
71
|
/>
|
|
65
72
|
</section>
|
|
66
73
|
|
|
74
|
+
<section className="space-y-sm">
|
|
75
|
+
<p className="text-caption text-muted">
|
|
76
|
+
Full width — segments share the available space
|
|
77
|
+
</p>
|
|
78
|
+
<SegmentedControl
|
|
79
|
+
items={RANGE_ITEMS}
|
|
80
|
+
value={range}
|
|
81
|
+
onValueChange={setRange}
|
|
82
|
+
size="md"
|
|
83
|
+
fullWidth
|
|
84
|
+
aria-label="Range"
|
|
85
|
+
/>
|
|
86
|
+
</section>
|
|
87
|
+
|
|
67
88
|
<section className="space-y-sm">
|
|
68
89
|
<p className="text-caption text-muted">Bare — nested inside a toolbar row</p>
|
|
69
90
|
<div className="space-y-xs rounded-lg border border-hairline bg-surface-soft p-sm">
|