@designa8/vibedesign-linear-internal-v1-b737 0.0.1 → 0.2.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.
@@ -4,9 +4,25 @@ import { Icon } from "../Icon";
4
4
  /**
5
5
  * `field` is a bordered, left-aligned select/combobox trigger and `item` is a
6
6
  * borderless, left-aligned list or menu row. Both stretch to the full width
7
- * and press with a background change only (no scale).
7
+ * and press with a background change only (no scale). `item` also paints a
8
+ * soft brand tint while `aria-checked`, so a radio / checkbox row can be the
9
+ * button itself.
10
+ * `bare` is a chrome-less segment for a control whose parent owns the stroke
11
+ * and paints the selection behind the label (segmented controls, toolbars):
12
+ * transparent at rest, no focus stroke of its own, muted label that darkens on
13
+ * hover and inverts to `on-primary` while `aria-selected`.
14
+ * `media` is a borderless, full-width block trigger that wraps a thumbnail or
15
+ * other media (no fixed height, no padding); clicking it opens a larger view.
8
16
  */
9
- export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger" | "field" | "item";
17
+ export type ButtonVariant =
18
+ | "primary"
19
+ | "secondary"
20
+ | "ghost"
21
+ | "danger"
22
+ | "field"
23
+ | "item"
24
+ | "bare"
25
+ | "media";
10
26
  export type ButtonSize = "sm" | "md" | "lg";
11
27
 
12
28
  export interface ButtonProps extends React.ComponentPropsWithoutRef<"button"> {
@@ -34,7 +50,7 @@ const base =
34
50
  const rowBase =
35
51
  "relative flex w-full min-w-0 select-none items-center justify-start whitespace-nowrap border text-left font-weight-body-md cursor-pointer transition-colors duration-150 ease-out focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50";
36
52
 
37
- const isRow = (v: ButtonVariant) => v === "field" || v === "item";
53
+ const isRow = (v: ButtonVariant) => v === "field" || v === "item" || v === "media";
38
54
 
39
55
  const variants: Record<ButtonVariant, string> = {
40
56
  primary:
@@ -48,7 +64,11 @@ const variants: Record<ButtonVariant, string> = {
48
64
  field:
49
65
  "border-hairline bg-canvas text-ink enabled:hover:border-hairline-strong focus-visible:border-primary aria-expanded:border-primary aria-invalid:border-semantic-error disabled:bg-surface-soft disabled:border-hairline-soft",
50
66
  item:
51
- "border-transparent bg-transparent text-ink enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-primary-soft aria-selected:font-weight-label",
67
+ "border-transparent bg-transparent text-ink enabled:hover:bg-surface-soft enabled:active:bg-surface-strong focus-visible:bg-surface-soft aria-selected:bg-primary-soft aria-selected:font-weight-label aria-checked:bg-primary-soft disabled:bg-transparent",
68
+ bare:
69
+ "border-transparent bg-transparent text-body transition-colors aria-selected:text-on-primary not-aria-selected:enabled:hover:bg-surface-soft not-aria-selected:enabled:hover:text-ink focus-visible:ring-inset not-aria-selected:focus-visible:bg-surface-soft",
70
+ media:
71
+ "border-transparent bg-transparent p-0 focus-visible:ring-inset enabled:hover:bg-surface-soft enabled:active:bg-surface-strong",
52
72
  };
53
73
 
54
74
  const sizes: Record<ButtonSize, string> = {
@@ -85,6 +105,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
85
105
  },
86
106
  ref,
87
107
  ) => {
108
+ const media = variant === "media";
88
109
  return (
89
110
  <button
90
111
  ref={ref}
@@ -96,7 +117,11 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
96
117
  className={cn(
97
118
  isRow(variant) ? rowBase : base,
98
119
  variants[variant],
99
- iconOnly ? iconOnlySizes[size] : sizes[size],
120
+ media
121
+ ? "rounded-lg"
122
+ : iconOnly
123
+ ? iconOnlySizes[size]
124
+ : sizes[size],
100
125
  fullWidth && "w-full",
101
126
  loading && "pointer-events-none",
102
127
  className,
@@ -118,6 +143,8 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
118
143
  )}
119
144
  {iconOnly ? (
120
145
  !loading && children
146
+ ) : media ? (
147
+ children
121
148
  ) : (
122
149
  <span className={isRow(variant) ? "min-w-0 flex-1 truncate" : undefined}>
123
150
  {loading && loadingText ? loadingText : children}
@@ -95,6 +95,8 @@ export const ICON_REGISTRY = {
95
95
  "circle": { viewBox: "0 0 24 24", nodes: [{ tag: "circle", cx: "12", cy: "12", r: "10" }] },
96
96
  "trash": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M3 6h18" }, { tag: "path", d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" }, { tag: "path", d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" }] },
97
97
  "chart-bar": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M3 3v16a2 2 0 0 0 2 2h16" }, { tag: "path", d: "M7 16h8" }, { tag: "path", d: "M7 11h12" }, { tag: "path", d: "M7 6h3" }] },
98
+ "layout-grid": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "7", height: "7", x: "3", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "14", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "3", y: "14", rx: "1" }] },
99
+ "smartphone": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "14", height: "20", x: "5", y: "2", rx: "2", ry: "2" }, { tag: "path", d: "M12 18h.01" }] },
98
100
  } as const;
99
101
 
100
102
  export type IconName = keyof typeof ICON_REGISTRY;
@@ -0,0 +1,181 @@
1
+ import * as React from "react";
2
+ import { Badge } from "../Badge";
3
+ import { Button } from "../Button";
4
+ import { Icon, type IconName } from "../Icon";
5
+
6
+ export interface SegmentedControlItem {
7
+ value: string;
8
+ /** Visible text. Omit for an icon-only segment. */
9
+ label?: React.ReactNode;
10
+ /** Leading glyph from the shared Icon registry. */
11
+ icon?: IconName;
12
+ /** Optional count rendered in a small badge after the label. */
13
+ count?: number;
14
+ /** Optional leading colour dot, e.g. `bg-semantic-info`. */
15
+ dotClassName?: string;
16
+ /** Accessible name for icon-only segments. Defaults to the value. */
17
+ "aria-label"?: string;
18
+ disabled?: boolean;
19
+ }
20
+
21
+ export interface SegmentedControlProps
22
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
23
+ items: SegmentedControlItem[];
24
+ /** Selected value. Pass `undefined` for "no segment selected". */
25
+ value: string | undefined;
26
+ onValueChange: (value: string) => void;
27
+ size?: "sm" | "md";
28
+ /** Drop the frame (border, surface, shadow), e.g. when nested in a toolbar. */
29
+ bare?: boolean;
30
+ }
31
+
32
+ const cn = (...parts: Array<string | false | null | undefined>) =>
33
+ parts.filter(Boolean).join(" ");
34
+
35
+ /**
36
+ * A segment sits inside a surface that already owns the stroke, so the ring is
37
+ * inset, the press is a background change, and hover fills only the idle
38
+ * segments — never over the primary indicator.
39
+ */
40
+ const segmentInteraction =
41
+ "cursor-pointer transition duration-150 ease-out not-aria-selected:hover:bg-surface-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50";
42
+
43
+ const frame: Record<"sm" | "md", string> = {
44
+ sm: "gap-xxs p-xxs",
45
+ md: "gap-xs p-xs",
46
+ };
47
+
48
+ const pillRadius: Record<"sm" | "md", string> = {
49
+ sm: "rounded-sm",
50
+ md: "rounded-md",
51
+ };
52
+
53
+ /**
54
+ * A compact segmented control: one framed surface, a single primary indicator
55
+ * that slides between segments, and segments that only report the chosen value
56
+ * (`onValueChange`) — no panels, unlike Tabs.
57
+ */
58
+ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(
59
+ ({ items, value, onValueChange, size = "sm", bare = false, className, ...rest }, ref) => {
60
+ const trackRef = React.useRef<HTMLDivElement | null>(null);
61
+ const itemRefs = React.useRef<Record<string, HTMLButtonElement | null>>({});
62
+ const [pill, setPill] = React.useState<{ offset: number; width: number } | null>(null);
63
+ const valueKey = items.map((item) => item.value).join("|");
64
+
65
+ React.useLayoutEffect(() => {
66
+ const el = value !== undefined ? itemRefs.current[value] : null;
67
+ if (!el) {
68
+ setPill(null);
69
+ return;
70
+ }
71
+ const measure = () => setPill({ offset: el.offsetLeft, width: el.offsetWidth });
72
+ measure();
73
+ if (typeof ResizeObserver === "undefined") return;
74
+ const observer = new ResizeObserver(measure);
75
+ observer.observe(el);
76
+ if (trackRef.current) observer.observe(trackRef.current);
77
+ return () => observer.disconnect();
78
+ }, [value, valueKey, size, bare]);
79
+
80
+ const firstEnabled = items.find((item) => !item.disabled)?.value;
81
+
82
+ const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
83
+ const enabled = items.filter((item) => !item.disabled);
84
+ if (enabled.length === 0) return;
85
+ const index = enabled.findIndex((item) => item.value === value);
86
+ let next: SegmentedControlItem | undefined;
87
+ if (event.key === "ArrowRight") next = enabled[(index + 1) % enabled.length];
88
+ else if (event.key === "ArrowLeft")
89
+ next = enabled[(index - 1 + enabled.length) % enabled.length];
90
+ else if (event.key === "Home") next = enabled[0];
91
+ else if (event.key === "End") next = enabled[enabled.length - 1];
92
+ if (!next) return;
93
+ event.preventDefault();
94
+ onValueChange(next.value);
95
+ itemRefs.current[next.value]?.focus();
96
+ };
97
+
98
+ return (
99
+ <div ref={ref} className={cn("w-full", className)} {...rest}>
100
+ <div
101
+ ref={trackRef}
102
+ role="tablist"
103
+ aria-orientation="horizontal"
104
+ onKeyDown={onKeyDown}
105
+ className={cn(
106
+ "relative isolate inline-flex max-w-full items-center overflow-x-auto rounded-lg",
107
+ frame[size],
108
+ bare ? "bg-transparent" : "border border-hairline bg-canvas shadow-sm",
109
+ "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
110
+ )}
111
+ >
112
+ {!bare ? (
113
+ <span
114
+ aria-hidden="true"
115
+ className={cn(
116
+ "pointer-events-none absolute top-xxs bottom-xxs left-0 -z-10 bg-primary shadow-sm transition-[transform,width] duration-200 ease-out",
117
+ pillRadius[size],
118
+ )}
119
+ style={
120
+ pill
121
+ ? { width: pill.width, transform: `translateX(${pill.offset}px)` }
122
+ : { width: 0, opacity: 0 }
123
+ }
124
+ />
125
+ ) : null}
126
+
127
+ {items.map((item) => {
128
+ const active = item.value === value;
129
+ const iconOnly = Boolean(item.icon) && item.label == null;
130
+ const glyphSize = size === "sm" ? 14 : 16;
131
+ return (
132
+ <Button
133
+ key={item.value}
134
+ ref={(el) => {
135
+ itemRefs.current[item.value] = el;
136
+ }}
137
+ type="button"
138
+ role="tab"
139
+ aria-selected={active}
140
+ aria-label={iconOnly ? (item["aria-label"] ?? item.value) : undefined}
141
+ tabIndex={active || (value === undefined && item.value === firstEnabled) ? 0 : -1}
142
+ variant={bare ? (active ? "primary" : "ghost") : "bare"}
143
+ size={size}
144
+ iconOnly={iconOnly}
145
+ disabled={item.disabled}
146
+ onClick={() => onValueChange(item.value)}
147
+ className={segmentInteraction}
148
+ >
149
+ {iconOnly ? (
150
+ <Icon name={item.icon!} size={glyphSize} />
151
+ ) : (
152
+ <span className="inline-flex min-w-0 items-center gap-xs">
153
+ {item.dotClassName ? (
154
+ <span
155
+ aria-hidden="true"
156
+ className={cn("h-2 w-2 shrink-0 rounded-full", item.dotClassName)}
157
+ />
158
+ ) : null}
159
+ {item.icon ? <Icon name={item.icon} size={glyphSize} /> : null}
160
+ <span className="truncate">{item.label}</span>
161
+ {item.count !== undefined ? (
162
+ <Badge
163
+ size="sm"
164
+ tone={active ? "on-primary" : "neutral"}
165
+ aria-label={`${item.count} items`}
166
+ className="min-w-5 justify-center"
167
+ >
168
+ {item.count}
169
+ </Badge>
170
+ ) : null}
171
+ </span>
172
+ )}
173
+ </Button>
174
+ );
175
+ })}
176
+ </div>
177
+ </div>
178
+ );
179
+ },
180
+ );
181
+ SegmentedControl.displayName = "SegmentedControl";
@@ -0,0 +1,2 @@
1
+ export { SegmentedControl } from "./SegmentedControl";
2
+ export type { SegmentedControlProps, SegmentedControlItem } from "./SegmentedControl";
@@ -0,0 +1,86 @@
1
+ import * as React from "react";
2
+ import { SegmentedControl, type SegmentedControlItem } from "./SegmentedControl";
3
+
4
+ const KIND_ITEMS: SegmentedControlItem[] = [
5
+ { value: "all", label: "All", count: 24 },
6
+ { value: "atoms", label: "Atoms", count: 9 },
7
+ { value: "molecules", label: "Molecules", count: 8 },
8
+ { value: "organisms", label: "Organisms", count: 7 },
9
+ ];
10
+
11
+ const VIEWPORT_ITEMS: SegmentedControlItem[] = [
12
+ { value: "desktop", icon: "monitor", "aria-label": "Desktop" },
13
+ { value: "mobile", icon: "smartphone", "aria-label": "Mobile" },
14
+ { value: "free", icon: "fullscreen", "aria-label": "Free" },
15
+ ];
16
+
17
+ const STATE_ITEMS: SegmentedControlItem[] = [
18
+ { value: "open", label: "Open", dotClassName: "bg-semantic-success" },
19
+ { value: "review", label: "In review", dotClassName: "bg-semantic-warning", count: 3 },
20
+ { value: "blocked", label: "Blocked", dotClassName: "bg-semantic-error" },
21
+ { value: "archived", label: "Archived", disabled: true },
22
+ ];
23
+
24
+ export default function SegmentedControlPreview() {
25
+ const [kind, setKind] = React.useState("all");
26
+ const [viewport, setViewport] = React.useState("desktop");
27
+ const [state, setState] = React.useState("review");
28
+ const [toolbarView, setToolbarView] = React.useState("grid");
29
+
30
+ return (
31
+ <div className="w-full max-w-3xl mx-auto space-y-xl p-lg">
32
+ <section className="space-y-sm">
33
+ <p className="text-caption text-muted">Gallery filter — labels with counts</p>
34
+ <SegmentedControl
35
+ items={KIND_ITEMS}
36
+ value={kind}
37
+ onValueChange={setKind}
38
+ size="md"
39
+ aria-label="Filter gallery by kind"
40
+ />
41
+ </section>
42
+
43
+ <section className="space-y-sm">
44
+ <p className="text-caption text-muted">Icon-only viewport picker</p>
45
+ <SegmentedControl
46
+ items={VIEWPORT_ITEMS}
47
+ value={viewport}
48
+ onValueChange={setViewport}
49
+ size="sm"
50
+ aria-label="Viewport"
51
+ />
52
+ </section>
53
+
54
+ <section className="space-y-sm">
55
+ <p className="text-caption text-muted">
56
+ Colour dots, a count, and a disabled segment
57
+ </p>
58
+ <SegmentedControl
59
+ items={STATE_ITEMS}
60
+ value={state}
61
+ onValueChange={setState}
62
+ size="md"
63
+ aria-label="Issue state"
64
+ />
65
+ </section>
66
+
67
+ <section className="space-y-sm">
68
+ <p className="text-caption text-muted">Bare — nested inside a toolbar row</p>
69
+ <div className="space-y-xs rounded-lg border border-hairline bg-surface-soft p-sm">
70
+ <span className="text-caption text-muted">Layout</span>
71
+ <SegmentedControl
72
+ items={[
73
+ { value: "grid", label: "Grid", icon: "layout-grid" },
74
+ { value: "list", label: "List" },
75
+ ]}
76
+ value={toolbarView}
77
+ onValueChange={setToolbarView}
78
+ size="sm"
79
+ bare
80
+ aria-label="Layout"
81
+ />
82
+ </div>
83
+ </section>
84
+ </div>
85
+ );
86
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./atoms/Accordion";
4
4
  export * from "./atoms/AccordionItem";
5
5
  export * from "./atoms/AccordionItemDesktop";
6
6
  export * from "./atoms/AccordionItemMobile";
7
+ export * from "./atoms/AgentQuestionCard";
7
8
  export * from "./atoms/Alert";
8
9
  export * from "./atoms/Avatar";
9
10
  export * from "./atoms/AvatarGroup";
@@ -66,6 +67,7 @@ export * from "./atoms/Radio";
66
67
  export * from "./atoms/Rating";
67
68
  export * from "./atoms/SearchBar";
68
69
  export * from "./atoms/SearchResultsList";
70
+ export * from "./atoms/SegmentedControl";
69
71
  export * from "./atoms/Sidebar";
70
72
  export * from "./atoms/SidebarDesktop";
71
73
  export * from "./atoms/SidebarMobile";