@slipstream-ui/core 0.11.4 → 0.11.6
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/index.d.mts +100 -3
- package/dist/index.d.ts +100 -3
- package/dist/index.js +589 -441
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +484 -337
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +1 -1
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +1 -1
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cover-image.manifest.json +151 -0
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +1 -1
- package/dist/manifests/date-picker-popover.manifest.json +1 -1
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +1 -1
- package/dist/manifests/empty-state.manifest.json +45 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/image.manifest.json +7 -1
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +1 -1
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +29 -2
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +1 -1
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +23 -1
- package/dist/manifests/stepper.manifest.json +1 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/cover-image/CoverImage.d.ts +34 -0
- package/dist/src/components/cover-image/CoverImage.js +94 -0
- package/dist/src/components/cover-image/CoverImage.js.map +1 -0
- package/dist/src/components/cover-image/CoverImage.mjs +70 -0
- package/dist/src/components/cover-image/CoverImage.mjs.map +1 -0
- package/dist/src/components/cover-image/index.d.ts +1 -0
- package/dist/src/components/cover-image/index.js +29 -0
- package/dist/src/components/cover-image/index.js.map +1 -0
- package/dist/src/components/cover-image/index.mjs +5 -0
- package/dist/src/components/cover-image/index.mjs.map +1 -0
- package/dist/src/components/empty-state/EmptyState.d.ts +24 -0
- package/dist/src/components/empty-state/EmptyState.js +16 -6
- package/dist/src/components/empty-state/EmptyState.js.map +1 -1
- package/dist/src/components/empty-state/EmptyState.mjs +16 -6
- package/dist/src/components/empty-state/EmptyState.mjs.map +1 -1
- package/dist/src/components/image/Image.d.ts +3 -1
- package/dist/src/components/image/Image.js +2 -0
- package/dist/src/components/image/Image.js.map +1 -1
- package/dist/src/components/image/Image.mjs +2 -0
- package/dist/src/components/image/Image.mjs.map +1 -1
- package/dist/src/components/segmented-control/SegmentedControl.d.ts +21 -0
- package/dist/src/components/segmented-control/SegmentedControl.js +47 -16
- package/dist/src/components/segmented-control/SegmentedControl.js.map +1 -1
- package/dist/src/components/segmented-control/SegmentedControl.mjs +48 -17
- package/dist/src/components/segmented-control/SegmentedControl.mjs.map +1 -1
- package/dist/src/components/stat-band/StatBand.d.ts +16 -0
- package/dist/src/components/stat-band/StatBand.js +46 -9
- package/dist/src/components/stat-band/StatBand.js.map +1 -1
- package/dist/src/components/stat-band/StatBand.mjs +46 -9
- package/dist/src/components/stat-band/StatBand.mjs.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/components/cover-image/CoverImage.test.tsx +88 -0
- package/src/components/cover-image/CoverImage.tsx +109 -0
- package/src/components/cover-image/index.ts +1 -0
- package/src/components/empty-state/EmptyState.test.tsx +33 -0
- package/src/components/empty-state/EmptyState.tsx +34 -6
- package/src/components/image/Image.tsx +4 -0
- package/src/components/segmented-control/SegmentedControl.test.tsx +64 -0
- package/src/components/segmented-control/SegmentedControl.tsx +69 -15
- package/src/components/stat-band/StatBand.test.tsx +26 -0
- package/src/components/stat-band/StatBand.tsx +52 -7
- package/src/index.ts +1 -0
- package/src/manifests/accordion.manifest.json +1 -1
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +1 -1
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cover-image.manifest.json +151 -0
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +1 -1
- package/src/manifests/date-picker-popover.manifest.json +1 -1
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +1 -1
- package/src/manifests/empty-state.manifest.json +45 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/image.manifest.json +7 -1
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +1 -1
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +29 -2
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +1 -1
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +23 -1
- package/src/manifests/stepper.manifest.json +1 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
- package/src/styles.css +5 -0
|
@@ -5,6 +5,13 @@ export type SegmentedOption = {
|
|
|
5
5
|
/** Optional leading icon. */
|
|
6
6
|
icon?: React.ReactNode;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Destination URL. When set the segment renders as a link instead of a
|
|
10
|
+
* button - use this for view switches that must survive refresh and work
|
|
11
|
+
* without JavaScript. The active segment renders as a non-link
|
|
12
|
+
* `aria-current="page"` marker.
|
|
13
|
+
*/
|
|
14
|
+
href?: string;
|
|
8
15
|
};
|
|
9
16
|
export type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
|
10
17
|
/** Options rendered as segments. */
|
|
@@ -21,12 +28,22 @@ export type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, '
|
|
|
21
28
|
size?: 'sm' | 'md' | 'lg';
|
|
22
29
|
/** Stretch segments to fill the container width. */
|
|
23
30
|
fullWidth?: boolean;
|
|
31
|
+
/** Custom link element for routers (Next Link, react-router Link). */
|
|
32
|
+
linkComponent?: React.ElementType;
|
|
33
|
+
/** Prop used to pass the destination to `linkComponent`. */
|
|
34
|
+
linkHrefProp?: 'href' | 'to';
|
|
24
35
|
};
|
|
25
36
|
/**
|
|
26
37
|
* Segmented control for switching a view or filter. Single-select uses radio
|
|
27
38
|
* semantics and arrow-key navigation; multiple-select uses pressed buttons.
|
|
28
39
|
* Use it for filters such as All / Investors / Advisors, not for tab panels
|
|
29
40
|
* (use Tabs when each segment owns a tabpanel).
|
|
41
|
+
*
|
|
42
|
+
* Give an option an `href` to render it as a real link - the pattern for
|
|
43
|
+
* view switches that must survive refresh, work without JavaScript, and stay
|
|
44
|
+
* cacheable. The active segment then renders as a non-link
|
|
45
|
+
* `aria-current="page"` marker and link segments use normal tab navigation
|
|
46
|
+
* instead of roving tabindex. Link mode is intended for single-select.
|
|
30
47
|
*/
|
|
31
48
|
export declare const SegmentedControl: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> & {
|
|
32
49
|
/** Options rendered as segments. */
|
|
@@ -43,4 +60,8 @@ export declare const SegmentedControl: React.ForwardRefExoticComponent<Omit<Reac
|
|
|
43
60
|
size?: "sm" | "md" | "lg";
|
|
44
61
|
/** Stretch segments to fill the container width. */
|
|
45
62
|
fullWidth?: boolean;
|
|
63
|
+
/** Custom link element for routers (Next Link, react-router Link). */
|
|
64
|
+
linkComponent?: React.ElementType;
|
|
65
|
+
/** Prop used to pass the destination to `linkComponent`. */
|
|
66
|
+
linkHrefProp?: "href" | "to";
|
|
46
67
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -49,6 +49,8 @@ const SegmentedControl = React.forwardRef(
|
|
|
49
49
|
multiple = false,
|
|
50
50
|
size = "md",
|
|
51
51
|
fullWidth = false,
|
|
52
|
+
linkComponent,
|
|
53
|
+
linkHrefProp = "href",
|
|
52
54
|
className,
|
|
53
55
|
"aria-label": ariaLabel = "Segmented control",
|
|
54
56
|
...props
|
|
@@ -59,6 +61,9 @@ const SegmentedControl = React.forwardRef(
|
|
|
59
61
|
);
|
|
60
62
|
const current = isControlled ? value : internal;
|
|
61
63
|
const selected = multiple ? Array.isArray(current) ? current : [] : typeof current === "string" ? current : "";
|
|
64
|
+
const linkMode = options.some((option) => option.href !== void 0);
|
|
65
|
+
const LinkEl = linkComponent ?? "a";
|
|
66
|
+
const destination = (href) => linkHrefProp === "to" ? { to: href } : { href };
|
|
62
67
|
const refs = React.useRef([]);
|
|
63
68
|
const commit = (next) => {
|
|
64
69
|
if (!isControlled) setInternal(next);
|
|
@@ -113,7 +118,7 @@ const SegmentedControl = React.forwardRef(
|
|
|
113
118
|
"div",
|
|
114
119
|
{
|
|
115
120
|
ref,
|
|
116
|
-
role: multiple ? "group" : "radiogroup",
|
|
121
|
+
role: multiple || linkMode ? "group" : "radiogroup",
|
|
117
122
|
"aria-label": ariaLabel,
|
|
118
123
|
className: (0, import_cn.cn)(
|
|
119
124
|
"inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1",
|
|
@@ -125,32 +130,58 @@ const SegmentedControl = React.forwardRef(
|
|
|
125
130
|
const active = multiple ? Array.isArray(selected) && selected.includes(option.value) : selected === option.value;
|
|
126
131
|
const firstEnabled = options.findIndex((entry) => !entry.disabled);
|
|
127
132
|
const focusable = multiple || active || !selected && index === firstEnabled;
|
|
128
|
-
|
|
133
|
+
const segmentClass = (0, import_cn.cn)(
|
|
134
|
+
"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors",
|
|
135
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
136
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
137
|
+
sizeClasses[size],
|
|
138
|
+
fullWidth && "flex-1",
|
|
139
|
+
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
140
|
+
);
|
|
141
|
+
const segmentContent = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
142
|
+
option.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0 [&_svg]:size-4", children: option.icon }),
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate", children: option.label })
|
|
144
|
+
] });
|
|
145
|
+
if (option.href !== void 0) {
|
|
146
|
+
if (option.disabled || active) {
|
|
147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
148
|
+
"span",
|
|
149
|
+
{
|
|
150
|
+
"aria-current": active ? "page" : void 0,
|
|
151
|
+
"aria-disabled": option.disabled || void 0,
|
|
152
|
+
className: (0, import_cn.cn)(segmentClass, option.disabled && "opacity-50"),
|
|
153
|
+
children: segmentContent
|
|
154
|
+
},
|
|
155
|
+
option.value
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
|
+
LinkEl,
|
|
160
|
+
{
|
|
161
|
+
...destination(option.href),
|
|
162
|
+
className: segmentClass,
|
|
163
|
+
children: segmentContent
|
|
164
|
+
},
|
|
165
|
+
option.value
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
129
169
|
"button",
|
|
130
170
|
{
|
|
131
171
|
ref: (node) => {
|
|
132
172
|
refs.current[index] = node;
|
|
133
173
|
},
|
|
134
174
|
type: "button",
|
|
135
|
-
role: multiple ? void 0 : "radio",
|
|
136
|
-
"aria-checked": multiple ? void 0 : active,
|
|
175
|
+
role: multiple || linkMode ? void 0 : "radio",
|
|
176
|
+
"aria-checked": multiple || linkMode ? void 0 : active,
|
|
137
177
|
"aria-pressed": multiple ? active : void 0,
|
|
178
|
+
"aria-current": linkMode && active ? "page" : void 0,
|
|
138
179
|
disabled: option.disabled,
|
|
139
180
|
tabIndex: focusable ? 0 : -1,
|
|
140
181
|
onClick: () => select(option),
|
|
141
182
|
onKeyDown,
|
|
142
|
-
className:
|
|
143
|
-
|
|
144
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
145
|
-
"disabled:pointer-events-none disabled:opacity-50",
|
|
146
|
-
sizeClasses[size],
|
|
147
|
-
fullWidth && "flex-1",
|
|
148
|
-
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
149
|
-
),
|
|
150
|
-
children: [
|
|
151
|
-
option.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "shrink-0 [&_svg]:size-4", children: option.icon }),
|
|
152
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "truncate", children: option.label })
|
|
153
|
-
]
|
|
183
|
+
className: segmentClass,
|
|
184
|
+
children: segmentContent
|
|
154
185
|
},
|
|
155
186
|
option.value
|
|
156
187
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type SegmentedOption = {\n value: string;\n label: React.ReactNode;\n /** Optional leading icon. */\n icon?: React.ReactNode;\n disabled?: boolean;\n};\n\nexport type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {\n /** Options rendered as segments. */\n options: SegmentedOption[];\n /** Controlled selected value. Use string[] when multiple. */\n value?: string | string[];\n /** Initial selection when uncontrolled. */\n defaultValue?: string | string[];\n /** Fires with the next selection. */\n onValueChange?: (value: string | string[]) => void;\n /** Allow more than one segment to be active. Default false. */\n multiple?: boolean;\n /** Control density. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Stretch segments to fill the container width. */\n fullWidth?: boolean;\n};\n\nconst sizeClasses = {\n sm: 'h-8 px-2.5 text-xs',\n md: 'h-9 px-3 text-sm',\n lg: 'h-10 px-4 text-sm',\n} as const;\n\n/**\n * Segmented control for switching a view or filter. Single-select uses radio\n * semantics and arrow-key navigation; multiple-select uses pressed buttons.\n * Use it for filters such as All / Investors / Advisors, not for tab panels\n * (use Tabs when each segment owns a tabpanel).\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n function SegmentedControl(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n multiple = false,\n size = 'md',\n fullWidth = false,\n className,\n 'aria-label': ariaLabel = 'Segmented control',\n ...props\n },\n ref\n ) {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<string | string[]>(() =>\n multiple\n ? Array.isArray(defaultValue)\n ? defaultValue\n : []\n : typeof defaultValue === 'string'\n ? defaultValue\n : ''\n );\n const current = isControlled ? value : internal;\n const selected = multiple\n ? Array.isArray(current)\n ? current\n : []\n : typeof current === 'string'\n ? current\n : '';\n\n const refs = React.useRef<Array<HTMLButtonElement | null>>([]);\n\n const commit = (next: string | string[]) => {\n if (!isControlled) setInternal(next);\n onValueChange?.(next);\n };\n\n const select = (option: SegmentedOption) => {\n if (option.disabled) return;\n if (multiple) {\n const currentValues = Array.isArray(selected) ? selected : [];\n commit(\n currentValues.includes(option.value)\n ? currentValues.filter((entry) => entry !== option.value)\n : [...currentValues, option.value]\n );\n } else {\n commit(option.value);\n }\n };\n\n const moveFocus = (direction: 1 | -1 | 'first' | 'last') => {\n if (multiple) return;\n const enabled = options\n .map((option, index) => ({ option, index }))\n .filter(({ option }) => !option.disabled);\n if (enabled.length === 0) return;\n const activeValue = typeof selected === 'string' ? selected : '';\n const currentIndex = enabled.findIndex(({ option }) => option.value === activeValue);\n let nextIndex: number;\n if (direction === 'first') nextIndex = 0;\n else if (direction === 'last') nextIndex = enabled.length - 1;\n else {\n const from = currentIndex === -1 ? 0 : currentIndex;\n nextIndex = (from + direction + enabled.length) % enabled.length;\n }\n const next = enabled[nextIndex];\n if (!next) return;\n commit(next.option.value);\n refs.current[next.index]?.focus();\n };\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (multiple) return;\n if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {\n event.preventDefault();\n moveFocus(1);\n } else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {\n event.preventDefault();\n moveFocus(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n moveFocus('first');\n } else if (event.key === 'End') {\n event.preventDefault();\n moveFocus('last');\n }\n };\n\n return (\n <div\n ref={ref}\n role={multiple ? 'group' : 'radiogroup'}\n aria-label={ariaLabel}\n className={cn(\n 'inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1',\n fullWidth && 'flex w-full',\n className\n )}\n {...props}\n >\n {options.map((option, index) => {\n const active = multiple\n ? Array.isArray(selected) && selected.includes(option.value)\n : selected === option.value;\n const firstEnabled = options.findIndex((entry) => !entry.disabled);\n const focusable = multiple || active || (!selected && index === firstEnabled);\n\n return (\n <button\n key={option.value}\n ref={(node) => {\n refs.current[index] = node;\n }}\n type=\"button\"\n role={multiple ? undefined : 'radio'}\n aria-checked={multiple ? undefined : active}\n aria-pressed={multiple ? active : undefined}\n disabled={option.disabled}\n tabIndex={focusable ? 0 : -1}\n onClick={() => select(option)}\n onKeyDown={onKeyDown}\n className={cn(\n 'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n sizeClasses[size],\n fullWidth && 'flex-1',\n active\n ? 'bg-background text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {option.icon && <span className=\"shrink-0 [&_svg]:size-4\">{option.icon}</span>}\n <span className=\"truncate\">{option.label}</span>\n </button>\n );\n })}\n </div>\n );\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4JY;AA1JZ,YAAuB;AACvB,gBAAmB;AA2BnB,MAAM,cAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAQO,MAAM,mBAAmB,MAAM;AAAA,EACpC,SAASA,kBACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ;AAAA,IACA,cAAc,YAAY;AAAA,IAC1B,GAAG;AAAA,EACL,GACA,KACA;AACA,UAAM,eAAe,UAAU;AAC/B,UAAM,CAAC,UAAU,WAAW,IAAI,MAAM;AAAA,MAA4B,MAChE,WACI,MAAM,QAAQ,YAAY,IACxB,eACA,CAAC,IACH,OAAO,iBAAiB,WACtB,eACA;AAAA,IACR;AACA,U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AA,gBACA,YAAY,IAAI;AAAA,gBAChB,aAAa;AAAA,gBACb,SACI,4CACA;AAAA,cACN;AAAA,cAEC;AAAA,uBAAO,QAAQ,4CAAC,UAAK,WAAU,2BAA2B,iBAAO,MAAK;AAAA,gBACvE,4CAAC,UAAK,WAAU,YAAY,iBAAO,OAAM;AAAA;AAAA;AAAA,YAxBpC,OAAO;AAAA,UAyBd;AAAA,QAEJ,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;","names":["SegmentedControl"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type SegmentedOption = {\n value: string;\n label: React.ReactNode;\n /** Optional leading icon. */\n icon?: React.ReactNode;\n disabled?: boolean;\n /**\n * Destination URL. When set the segment renders as a link instead of a\n * button - use this for view switches that must survive refresh and work\n * without JavaScript. The active segment renders as a non-link\n * `aria-current=\"page\"` marker.\n */\n href?: string;\n};\n\nexport type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {\n /** Options rendered as segments. */\n options: SegmentedOption[];\n /** Controlled selected value. Use string[] when multiple. */\n value?: string | string[];\n /** Initial selection when uncontrolled. */\n defaultValue?: string | string[];\n /** Fires with the next selection. */\n onValueChange?: (value: string | string[]) => void;\n /** Allow more than one segment to be active. Default false. */\n multiple?: boolean;\n /** Control density. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Stretch segments to fill the container width. */\n fullWidth?: boolean;\n /** Custom link element for routers (Next Link, react-router Link). */\n linkComponent?: React.ElementType;\n /** Prop used to pass the destination to `linkComponent`. */\n linkHrefProp?: 'href' | 'to';\n};\n\nconst sizeClasses = {\n sm: 'h-8 px-2.5 text-xs',\n md: 'h-9 px-3 text-sm',\n lg: 'h-10 px-4 text-sm',\n} as const;\n\n/**\n * Segmented control for switching a view or filter. Single-select uses radio\n * semantics and arrow-key navigation; multiple-select uses pressed buttons.\n * Use it for filters such as All / Investors / Advisors, not for tab panels\n * (use Tabs when each segment owns a tabpanel).\n *\n * Give an option an `href` to render it as a real link - the pattern for\n * view switches that must survive refresh, work without JavaScript, and stay\n * cacheable. The active segment then renders as a non-link\n * `aria-current=\"page\"` marker and link segments use normal tab navigation\n * instead of roving tabindex. Link mode is intended for single-select.\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n function SegmentedControl(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n multiple = false,\n size = 'md',\n fullWidth = false,\n linkComponent,\n linkHrefProp = 'href',\n className,\n 'aria-label': ariaLabel = 'Segmented control',\n ...props\n },\n ref\n ) {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<string | string[]>(() =>\n multiple\n ? Array.isArray(defaultValue)\n ? defaultValue\n : []\n : typeof defaultValue === 'string'\n ? defaultValue\n : ''\n );\n const current = isControlled ? value : internal;\n const selected = multiple\n ? Array.isArray(current)\n ? current\n : []\n : typeof current === 'string'\n ? current\n : '';\n\n const linkMode = options.some((option) => option.href !== undefined);\n const LinkEl = linkComponent ?? 'a';\n const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });\n\n const refs = React.useRef<Array<HTMLButtonElement | null>>([]);\n\n const commit = (next: string | string[]) => {\n if (!isControlled) setInternal(next);\n onValueChange?.(next);\n };\n\n const select = (option: SegmentedOption) => {\n if (option.disabled) return;\n if (multiple) {\n const currentValues = Array.isArray(selected) ? selected : [];\n commit(\n currentValues.includes(option.value)\n ? currentValues.filter((entry) => entry !== option.value)\n : [...currentValues, option.value]\n );\n } else {\n commit(option.value);\n }\n };\n\n const moveFocus = (direction: 1 | -1 | 'first' | 'last') => {\n if (multiple) return;\n const enabled = options\n .map((option, index) => ({ option, index }))\n .filter(({ option }) => !option.disabled);\n if (enabled.length === 0) return;\n const activeValue = typeof selected === 'string' ? selected : '';\n const currentIndex = enabled.findIndex(({ option }) => option.value === activeValue);\n let nextIndex: number;\n if (direction === 'first') nextIndex = 0;\n else if (direction === 'last') nextIndex = enabled.length - 1;\n else {\n const from = currentIndex === -1 ? 0 : currentIndex;\n nextIndex = (from + direction + enabled.length) % enabled.length;\n }\n const next = enabled[nextIndex];\n if (!next) return;\n commit(next.option.value);\n refs.current[next.index]?.focus();\n };\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (multiple) return;\n if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {\n event.preventDefault();\n moveFocus(1);\n } else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {\n event.preventDefault();\n moveFocus(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n moveFocus('first');\n } else if (event.key === 'End') {\n event.preventDefault();\n moveFocus('last');\n }\n };\n\n return (\n <div\n ref={ref}\n role={multiple || linkMode ? 'group' : 'radiogroup'}\n aria-label={ariaLabel}\n className={cn(\n 'inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1',\n fullWidth && 'flex w-full',\n className\n )}\n {...props}\n >\n {options.map((option, index) => {\n const active = multiple\n ? Array.isArray(selected) && selected.includes(option.value)\n : selected === option.value;\n const firstEnabled = options.findIndex((entry) => !entry.disabled);\n const focusable = multiple || active || (!selected && index === firstEnabled);\n const segmentClass = cn(\n 'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n sizeClasses[size],\n fullWidth && 'flex-1',\n active\n ? 'bg-background text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n );\n const segmentContent = (\n <>\n {option.icon && <span className=\"shrink-0 [&_svg]:size-4\">{option.icon}</span>}\n <span className=\"truncate\">{option.label}</span>\n </>\n );\n\n if (option.href !== undefined) {\n if (option.disabled || active) {\n return (\n <span\n key={option.value}\n aria-current={active ? 'page' : undefined}\n aria-disabled={option.disabled || undefined}\n className={cn(segmentClass, option.disabled && 'opacity-50')}\n >\n {segmentContent}\n </span>\n );\n }\n return (\n <LinkEl\n key={option.value}\n {...destination(option.href)}\n className={segmentClass}\n >\n {segmentContent}\n </LinkEl>\n );\n }\n\n return (\n <button\n key={option.value}\n ref={(node) => {\n refs.current[index] = node;\n }}\n type=\"button\"\n role={multiple || linkMode ? undefined : 'radio'}\n aria-checked={multiple || linkMode ? undefined : active}\n aria-pressed={multiple ? active : undefined}\n aria-current={linkMode && active ? 'page' : undefined}\n disabled={option.disabled}\n tabIndex={focusable ? 0 : -1}\n onClick={() => select(option)}\n onKeyDown={onKeyDown}\n className={segmentClass}\n >\n {segmentContent}\n </button>\n );\n })}\n </div>\n );\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4LY;AA1LZ,YAAuB;AACvB,gBAAmB;AAsCnB,MAAM,cAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAcO,MAAM,mBAAmB,MAAM;AAAA,EACpC,SAASA,kBACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,cAAc,YAAY;AAAA,IAC1B,GAAG;AAAA,EACL,GACA,KACA;AACA,UAAM,eAAe,UAAU;AAC/B,UAAM,CAAC,UAAU,WAAW,IAAI,MAAM;AAAA,MAA4B,MAChE,WACI,MAAM,QAAQ,YAAY,IACxB,eACA,CAAC,IACH,OAAO,iBAAiB,WACtB,eACA;AAAA,IACR;AACA,UAAM,UAAU,eAAe,QAAQ;AACvC,UAAM,WAAW,WACb,MAAM,QAAQ,OAAO,IACnB,UACA,CAAC,IACH,OAAO,YAAY,WACjB,UACA;AAEN,UAAM,WAAW,QAAQ,KAAK,CAAC,WAAW,OAAO,SAAS,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C;AAAA;AAAA,kBAEC,gBAAc,SAAS,SAAS;AAAA,kBAChC,iBAAe,OAAO,YAAY;AAAA,kBAClC,eAAW,cAAG,cAAc,OAAO,YAAY,YAAY;AAAA,kBAE1D;AAAA;AAAA,gBALI,OAAO;AAAA,cAMd;AAAA,YAEJ;AACA,mBACE;AAAA,cAAC;AAAA;AAAA,gBAEE,GAAG,YAAY,OAAO,IAAI;AAAA,gBAC3B,WAAW;AAAA,gBAEV;AAAA;AAAA,cAJI,OAAO;AAAA,YAKd;AAAA,UAEJ;AAEA,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,SAAS;AACb,qBAAK,QAAQ,KAAK,IAAI;AAAA,cACxB;AAAA,cACA,MAAK;AAAA,cACL,MAAM,YAAY,WAAW,SAAY;AAAA,cACzC,gBAAc,YAAY,WAAW,SAAY;AAAA,cACjD,gBAAc,WAAW,SAAS;AAAA,cAClC,gBAAc,YAAY,SAAS,SAAS;AAAA,cAC5C,UAAU,OAAO;AAAA,cACjB,UAAU,YAAY,IAAI;AAAA,cAC1B,SAAS,MAAM,OAAO,MAAM;AAAA,cAC5B;AAAA,cACA,WAAW;AAAA,cAEV;AAAA;AAAA,YAfI,OAAO;AAAA,UAgBd;AAAA,QAEJ,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;","names":["SegmentedControl"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../utils/cn.mjs";
|
|
5
5
|
const sizeClasses = {
|
|
@@ -16,6 +16,8 @@ const SegmentedControl = React.forwardRef(
|
|
|
16
16
|
multiple = false,
|
|
17
17
|
size = "md",
|
|
18
18
|
fullWidth = false,
|
|
19
|
+
linkComponent,
|
|
20
|
+
linkHrefProp = "href",
|
|
19
21
|
className,
|
|
20
22
|
"aria-label": ariaLabel = "Segmented control",
|
|
21
23
|
...props
|
|
@@ -26,6 +28,9 @@ const SegmentedControl = React.forwardRef(
|
|
|
26
28
|
);
|
|
27
29
|
const current = isControlled ? value : internal;
|
|
28
30
|
const selected = multiple ? Array.isArray(current) ? current : [] : typeof current === "string" ? current : "";
|
|
31
|
+
const linkMode = options.some((option) => option.href !== void 0);
|
|
32
|
+
const LinkEl = linkComponent ?? "a";
|
|
33
|
+
const destination = (href) => linkHrefProp === "to" ? { to: href } : { href };
|
|
29
34
|
const refs = React.useRef([]);
|
|
30
35
|
const commit = (next) => {
|
|
31
36
|
if (!isControlled) setInternal(next);
|
|
@@ -80,7 +85,7 @@ const SegmentedControl = React.forwardRef(
|
|
|
80
85
|
"div",
|
|
81
86
|
{
|
|
82
87
|
ref,
|
|
83
|
-
role: multiple ? "group" : "radiogroup",
|
|
88
|
+
role: multiple || linkMode ? "group" : "radiogroup",
|
|
84
89
|
"aria-label": ariaLabel,
|
|
85
90
|
className: cn(
|
|
86
91
|
"inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1",
|
|
@@ -92,32 +97,58 @@ const SegmentedControl = React.forwardRef(
|
|
|
92
97
|
const active = multiple ? Array.isArray(selected) && selected.includes(option.value) : selected === option.value;
|
|
93
98
|
const firstEnabled = options.findIndex((entry) => !entry.disabled);
|
|
94
99
|
const focusable = multiple || active || !selected && index === firstEnabled;
|
|
95
|
-
|
|
100
|
+
const segmentClass = cn(
|
|
101
|
+
"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors",
|
|
102
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
103
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
104
|
+
sizeClasses[size],
|
|
105
|
+
fullWidth && "flex-1",
|
|
106
|
+
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
107
|
+
);
|
|
108
|
+
const segmentContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
109
|
+
option.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0 [&_svg]:size-4", children: option.icon }),
|
|
110
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: option.label })
|
|
111
|
+
] });
|
|
112
|
+
if (option.href !== void 0) {
|
|
113
|
+
if (option.disabled || active) {
|
|
114
|
+
return /* @__PURE__ */ jsx(
|
|
115
|
+
"span",
|
|
116
|
+
{
|
|
117
|
+
"aria-current": active ? "page" : void 0,
|
|
118
|
+
"aria-disabled": option.disabled || void 0,
|
|
119
|
+
className: cn(segmentClass, option.disabled && "opacity-50"),
|
|
120
|
+
children: segmentContent
|
|
121
|
+
},
|
|
122
|
+
option.value
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return /* @__PURE__ */ jsx(
|
|
126
|
+
LinkEl,
|
|
127
|
+
{
|
|
128
|
+
...destination(option.href),
|
|
129
|
+
className: segmentClass,
|
|
130
|
+
children: segmentContent
|
|
131
|
+
},
|
|
132
|
+
option.value
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return /* @__PURE__ */ jsx(
|
|
96
136
|
"button",
|
|
97
137
|
{
|
|
98
138
|
ref: (node) => {
|
|
99
139
|
refs.current[index] = node;
|
|
100
140
|
},
|
|
101
141
|
type: "button",
|
|
102
|
-
role: multiple ? void 0 : "radio",
|
|
103
|
-
"aria-checked": multiple ? void 0 : active,
|
|
142
|
+
role: multiple || linkMode ? void 0 : "radio",
|
|
143
|
+
"aria-checked": multiple || linkMode ? void 0 : active,
|
|
104
144
|
"aria-pressed": multiple ? active : void 0,
|
|
145
|
+
"aria-current": linkMode && active ? "page" : void 0,
|
|
105
146
|
disabled: option.disabled,
|
|
106
147
|
tabIndex: focusable ? 0 : -1,
|
|
107
148
|
onClick: () => select(option),
|
|
108
149
|
onKeyDown,
|
|
109
|
-
className:
|
|
110
|
-
|
|
111
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
112
|
-
"disabled:pointer-events-none disabled:opacity-50",
|
|
113
|
-
sizeClasses[size],
|
|
114
|
-
fullWidth && "flex-1",
|
|
115
|
-
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
116
|
-
),
|
|
117
|
-
children: [
|
|
118
|
-
option.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0 [&_svg]:size-4", children: option.icon }),
|
|
119
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children: option.label })
|
|
120
|
-
]
|
|
150
|
+
className: segmentClass,
|
|
151
|
+
children: segmentContent
|
|
121
152
|
},
|
|
122
153
|
option.value
|
|
123
154
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type SegmentedOption = {\n value: string;\n label: React.ReactNode;\n /** Optional leading icon. */\n icon?: React.ReactNode;\n disabled?: boolean;\n};\n\nexport type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {\n /** Options rendered as segments. */\n options: SegmentedOption[];\n /** Controlled selected value. Use string[] when multiple. */\n value?: string | string[];\n /** Initial selection when uncontrolled. */\n defaultValue?: string | string[];\n /** Fires with the next selection. */\n onValueChange?: (value: string | string[]) => void;\n /** Allow more than one segment to be active. Default false. */\n multiple?: boolean;\n /** Control density. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Stretch segments to fill the container width. */\n fullWidth?: boolean;\n};\n\nconst sizeClasses = {\n sm: 'h-8 px-2.5 text-xs',\n md: 'h-9 px-3 text-sm',\n lg: 'h-10 px-4 text-sm',\n} as const;\n\n/**\n * Segmented control for switching a view or filter. Single-select uses radio\n * semantics and arrow-key navigation; multiple-select uses pressed buttons.\n * Use it for filters such as All / Investors / Advisors, not for tab panels\n * (use Tabs when each segment owns a tabpanel).\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n function SegmentedControl(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n multiple = false,\n size = 'md',\n fullWidth = false,\n className,\n 'aria-label': ariaLabel = 'Segmented control',\n ...props\n },\n ref\n ) {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<string | string[]>(() =>\n multiple\n ? Array.isArray(defaultValue)\n ? defaultValue\n : []\n : typeof defaultValue === 'string'\n ? defaultValue\n : ''\n );\n const current = isControlled ? value : internal;\n const selected = multiple\n ? Array.isArray(current)\n ? current\n : []\n : typeof current === 'string'\n ? current\n : '';\n\n const refs = React.useRef<Array<HTMLButtonElement | null>>([]);\n\n const commit = (next: string | string[]) => {\n if (!isControlled) setInternal(next);\n onValueChange?.(next);\n };\n\n const select = (option: SegmentedOption) => {\n if (option.disabled) return;\n if (multiple) {\n const currentValues = Array.isArray(selected) ? selected : [];\n commit(\n currentValues.includes(option.value)\n ? currentValues.filter((entry) => entry !== option.value)\n : [...currentValues, option.value]\n );\n } else {\n commit(option.value);\n }\n };\n\n const moveFocus = (direction: 1 | -1 | 'first' | 'last') => {\n if (multiple) return;\n const enabled = options\n .map((option, index) => ({ option, index }))\n .filter(({ option }) => !option.disabled);\n if (enabled.length === 0) return;\n const activeValue = typeof selected === 'string' ? selected : '';\n const currentIndex = enabled.findIndex(({ option }) => option.value === activeValue);\n let nextIndex: number;\n if (direction === 'first') nextIndex = 0;\n else if (direction === 'last') nextIndex = enabled.length - 1;\n else {\n const from = currentIndex === -1 ? 0 : currentIndex;\n nextIndex = (from + direction + enabled.length) % enabled.length;\n }\n const next = enabled[nextIndex];\n if (!next) return;\n commit(next.option.value);\n refs.current[next.index]?.focus();\n };\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (multiple) return;\n if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {\n event.preventDefault();\n moveFocus(1);\n } else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {\n event.preventDefault();\n moveFocus(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n moveFocus('first');\n } else if (event.key === 'End') {\n event.preventDefault();\n moveFocus('last');\n }\n };\n\n return (\n <div\n ref={ref}\n role={multiple ? 'group' : 'radiogroup'}\n aria-label={ariaLabel}\n className={cn(\n 'inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1',\n fullWidth && 'flex w-full',\n className\n )}\n {...props}\n >\n {options.map((option, index) => {\n const active = multiple\n ? Array.isArray(selected) && selected.includes(option.value)\n : selected === option.value;\n const firstEnabled = options.findIndex((entry) => !entry.disabled);\n const focusable = multiple || active || (!selected && index === firstEnabled);\n\n return (\n <button\n key={option.value}\n ref={(node) => {\n refs.current[index] = node;\n }}\n type=\"button\"\n role={multiple ? undefined : 'radio'}\n aria-checked={multiple ? undefined : active}\n aria-pressed={multiple ? active : undefined}\n disabled={option.disabled}\n tabIndex={focusable ? 0 : -1}\n onClick={() => select(option)}\n onKeyDown={onKeyDown}\n className={cn(\n 'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n sizeClasses[size],\n fullWidth && 'flex-1',\n active\n ? 'bg-background text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {option.icon && <span className=\"shrink-0 [&_svg]:size-4\">{option.icon}</span>}\n <span className=\"truncate\">{option.label}</span>\n </button>\n );\n })}\n </div>\n );\n }\n);\n"],"mappings":";AA4JY,SAwBkB,KAxBlB;AA1JZ,YAAY,WAAW;AACvB,SAAS,UAAU;AA2BnB,MAAM,cAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAQO,MAAM,mBAAmB,MAAM;AAAA,EACpC,SAASA,kBACP;AAAA,IACE;AAAA,I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AAC,SAAS;AACb,qBAAK,QAAQ,KAAK,IAAI;AAAA,cACxB;AAAA,cACA,MAAK;AAAA,cACL,MAAM,WAAW,SAAY;AAAA,cAC7B,gBAAc,WAAW,SAAY;AAAA,cACrC,gBAAc,WAAW,SAAS;AAAA,cAClC,UAAU,OAAO;AAAA,cACjB,UAAU,YAAY,IAAI;AAAA,cAC1B,SAAS,MAAM,OAAO,MAAM;AAAA,cAC5B;AAAA,cACA,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,YAAY,IAAI;AAAA,gBAChB,aAAa;AAAA,gBACb,SACI,4CACA;AAAA,cACN;AAAA,cAEC;AAAA,uBAAO,QAAQ,oBAAC,UAAK,WAAU,2BAA2B,iBAAO,MAAK;AAAA,gBACvE,oBAAC,UAAK,WAAU,YAAY,iBAAO,OAAM;AAAA;AAAA;AAAA,YAxBpC,OAAO;AAAA,UAyBd;AAAA,QAEJ,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;","names":["SegmentedControl"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/segmented-control/SegmentedControl.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type SegmentedOption = {\n value: string;\n label: React.ReactNode;\n /** Optional leading icon. */\n icon?: React.ReactNode;\n disabled?: boolean;\n /**\n * Destination URL. When set the segment renders as a link instead of a\n * button - use this for view switches that must survive refresh and work\n * without JavaScript. The active segment renders as a non-link\n * `aria-current=\"page\"` marker.\n */\n href?: string;\n};\n\nexport type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {\n /** Options rendered as segments. */\n options: SegmentedOption[];\n /** Controlled selected value. Use string[] when multiple. */\n value?: string | string[];\n /** Initial selection when uncontrolled. */\n defaultValue?: string | string[];\n /** Fires with the next selection. */\n onValueChange?: (value: string | string[]) => void;\n /** Allow more than one segment to be active. Default false. */\n multiple?: boolean;\n /** Control density. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Stretch segments to fill the container width. */\n fullWidth?: boolean;\n /** Custom link element for routers (Next Link, react-router Link). */\n linkComponent?: React.ElementType;\n /** Prop used to pass the destination to `linkComponent`. */\n linkHrefProp?: 'href' | 'to';\n};\n\nconst sizeClasses = {\n sm: 'h-8 px-2.5 text-xs',\n md: 'h-9 px-3 text-sm',\n lg: 'h-10 px-4 text-sm',\n} as const;\n\n/**\n * Segmented control for switching a view or filter. Single-select uses radio\n * semantics and arrow-key navigation; multiple-select uses pressed buttons.\n * Use it for filters such as All / Investors / Advisors, not for tab panels\n * (use Tabs when each segment owns a tabpanel).\n *\n * Give an option an `href` to render it as a real link - the pattern for\n * view switches that must survive refresh, work without JavaScript, and stay\n * cacheable. The active segment then renders as a non-link\n * `aria-current=\"page\"` marker and link segments use normal tab navigation\n * instead of roving tabindex. Link mode is intended for single-select.\n */\nexport const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(\n function SegmentedControl(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n multiple = false,\n size = 'md',\n fullWidth = false,\n linkComponent,\n linkHrefProp = 'href',\n className,\n 'aria-label': ariaLabel = 'Segmented control',\n ...props\n },\n ref\n ) {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<string | string[]>(() =>\n multiple\n ? Array.isArray(defaultValue)\n ? defaultValue\n : []\n : typeof defaultValue === 'string'\n ? defaultValue\n : ''\n );\n const current = isControlled ? value : internal;\n const selected = multiple\n ? Array.isArray(current)\n ? current\n : []\n : typeof current === 'string'\n ? current\n : '';\n\n const linkMode = options.some((option) => option.href !== undefined);\n const LinkEl = linkComponent ?? 'a';\n const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });\n\n const refs = React.useRef<Array<HTMLButtonElement | null>>([]);\n\n const commit = (next: string | string[]) => {\n if (!isControlled) setInternal(next);\n onValueChange?.(next);\n };\n\n const select = (option: SegmentedOption) => {\n if (option.disabled) return;\n if (multiple) {\n const currentValues = Array.isArray(selected) ? selected : [];\n commit(\n currentValues.includes(option.value)\n ? currentValues.filter((entry) => entry !== option.value)\n : [...currentValues, option.value]\n );\n } else {\n commit(option.value);\n }\n };\n\n const moveFocus = (direction: 1 | -1 | 'first' | 'last') => {\n if (multiple) return;\n const enabled = options\n .map((option, index) => ({ option, index }))\n .filter(({ option }) => !option.disabled);\n if (enabled.length === 0) return;\n const activeValue = typeof selected === 'string' ? selected : '';\n const currentIndex = enabled.findIndex(({ option }) => option.value === activeValue);\n let nextIndex: number;\n if (direction === 'first') nextIndex = 0;\n else if (direction === 'last') nextIndex = enabled.length - 1;\n else {\n const from = currentIndex === -1 ? 0 : currentIndex;\n nextIndex = (from + direction + enabled.length) % enabled.length;\n }\n const next = enabled[nextIndex];\n if (!next) return;\n commit(next.option.value);\n refs.current[next.index]?.focus();\n };\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (multiple) return;\n if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {\n event.preventDefault();\n moveFocus(1);\n } else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {\n event.preventDefault();\n moveFocus(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n moveFocus('first');\n } else if (event.key === 'End') {\n event.preventDefault();\n moveFocus('last');\n }\n };\n\n return (\n <div\n ref={ref}\n role={multiple || linkMode ? 'group' : 'radiogroup'}\n aria-label={ariaLabel}\n className={cn(\n 'inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1',\n fullWidth && 'flex w-full',\n className\n )}\n {...props}\n >\n {options.map((option, index) => {\n const active = multiple\n ? Array.isArray(selected) && selected.includes(option.value)\n : selected === option.value;\n const firstEnabled = options.findIndex((entry) => !entry.disabled);\n const focusable = multiple || active || (!selected && index === firstEnabled);\n const segmentClass = cn(\n 'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n sizeClasses[size],\n fullWidth && 'flex-1',\n active\n ? 'bg-background text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n );\n const segmentContent = (\n <>\n {option.icon && <span className=\"shrink-0 [&_svg]:size-4\">{option.icon}</span>}\n <span className=\"truncate\">{option.label}</span>\n </>\n );\n\n if (option.href !== undefined) {\n if (option.disabled || active) {\n return (\n <span\n key={option.value}\n aria-current={active ? 'page' : undefined}\n aria-disabled={option.disabled || undefined}\n className={cn(segmentClass, option.disabled && 'opacity-50')}\n >\n {segmentContent}\n </span>\n );\n }\n return (\n <LinkEl\n key={option.value}\n {...destination(option.href)}\n className={segmentClass}\n >\n {segmentContent}\n </LinkEl>\n );\n }\n\n return (\n <button\n key={option.value}\n ref={(node) => {\n refs.current[index] = node;\n }}\n type=\"button\"\n role={multiple || linkMode ? undefined : 'radio'}\n aria-checked={multiple || linkMode ? undefined : active}\n aria-pressed={multiple ? active : undefined}\n aria-current={linkMode && active ? 'page' : undefined}\n disabled={option.disabled}\n tabIndex={focusable ? 0 : -1}\n onClick={() => select(option)}\n onKeyDown={onKeyDown}\n className={segmentClass}\n >\n {segmentContent}\n </button>\n );\n })}\n </div>\n );\n }\n);\n"],"mappings":";AA4LY,mBACkB,KADlB;AA1LZ,YAAY,WAAW;AACvB,SAAS,UAAU;AAsCnB,MAAM,cAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAcO,MAAM,mBAAmB,MAAM;AAAA,EACpC,SAASA,kBACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,cAAc,YAAY;AAAA,IAC1B,GAAG;AAAA,EACL,GACA,KACA;AACA,UAAM,eAAe,UAAU;AAC/B,UAAM,CAAC,UAAU,WAAW,IAA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|
/** Draw dividers between stats at sm and up. Default true. */
|
|
20
20
|
divided?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Surface treatment. 'panel' renders a bordered strip of hairline-separated
|
|
23
|
+
* cells with denser type for data pages; 'plain' is the marketing band.
|
|
24
|
+
* Default 'plain'.
|
|
25
|
+
*/
|
|
26
|
+
variant?: 'plain' | 'panel';
|
|
27
|
+
/** Extra classes for the value element (e.g. font-mono for tabular numerals). */
|
|
28
|
+
valueClassName?: string;
|
|
21
29
|
};
|
|
22
30
|
/**
|
|
23
31
|
* Marketing stat band: a semantic description list of headline numbers with
|
|
@@ -35,4 +43,12 @@ export declare const StatBand: React.ForwardRefExoticComponent<React.HTMLAttribu
|
|
|
35
43
|
size?: "sm" | "md" | "lg";
|
|
36
44
|
/** Draw dividers between stats at sm and up. Default true. */
|
|
37
45
|
divided?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Surface treatment. 'panel' renders a bordered strip of hairline-separated
|
|
48
|
+
* cells with denser type for data pages; 'plain' is the marketing band.
|
|
49
|
+
* Default 'plain'.
|
|
50
|
+
*/
|
|
51
|
+
variant?: "plain" | "panel";
|
|
52
|
+
/** Extra classes for the value element (e.g. font-mono for tabular numerals). */
|
|
53
|
+
valueClassName?: string;
|
|
38
54
|
} & React.RefAttributes<HTMLDListElement>>;
|
|
@@ -44,15 +44,32 @@ const valueClasses = {
|
|
|
44
44
|
md: "text-3xl",
|
|
45
45
|
lg: "text-4xl sm:text-5xl"
|
|
46
46
|
};
|
|
47
|
-
const
|
|
47
|
+
const panelValueClasses = {
|
|
48
|
+
sm: "text-lg",
|
|
49
|
+
md: "text-xl sm:text-2xl",
|
|
50
|
+
lg: "text-2xl sm:text-3xl"
|
|
51
|
+
};
|
|
52
|
+
const StatBand = React.forwardRef(function StatBand2({
|
|
53
|
+
items,
|
|
54
|
+
columns = 3,
|
|
55
|
+
align = "center",
|
|
56
|
+
size = "md",
|
|
57
|
+
divided = true,
|
|
58
|
+
variant = "plain",
|
|
59
|
+
valueClassName,
|
|
60
|
+
className,
|
|
61
|
+
...props
|
|
62
|
+
}, ref) {
|
|
63
|
+
const panel = variant === "panel";
|
|
48
64
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
65
|
"dl",
|
|
50
66
|
{
|
|
51
67
|
ref,
|
|
52
68
|
className: (0, import_cn.cn)(
|
|
53
|
-
"grid w-full
|
|
69
|
+
"grid w-full",
|
|
70
|
+
panel ? "gap-0 rounded-lg border border-border bg-card" : "gap-8",
|
|
54
71
|
columnClasses[columns],
|
|
55
|
-
divided && "sm:divide-x sm:divide-border",
|
|
72
|
+
divided && (panel ? "divide-y divide-border sm:divide-x sm:divide-y-0" : "sm:divide-x sm:divide-border"),
|
|
56
73
|
className
|
|
57
74
|
),
|
|
58
75
|
...props,
|
|
@@ -60,15 +77,35 @@ const StatBand = React.forwardRef(function StatBand2({ items, columns = 3, align
|
|
|
60
77
|
"div",
|
|
61
78
|
{
|
|
62
79
|
className: (0, import_cn.cn)(
|
|
63
|
-
"flex min-w-0 flex-col gap-1
|
|
80
|
+
"flex min-w-0 flex-col gap-1",
|
|
81
|
+
panel ? "px-4 py-3 sm:px-5 sm:py-4" : "sm:px-6 sm:first:pl-0 sm:last:pr-0",
|
|
64
82
|
align === "center" ? "items-center text-center" : "items-start text-left"
|
|
65
83
|
),
|
|
66
84
|
children: [
|
|
67
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
86
|
+
"dt",
|
|
87
|
+
{
|
|
88
|
+
className: (0, import_cn.cn)(
|
|
89
|
+
"order-2 text-muted-foreground",
|
|
90
|
+
panel ? "text-xs font-medium uppercase tracking-wide" : "text-sm font-medium"
|
|
91
|
+
),
|
|
92
|
+
children: [
|
|
93
|
+
item.label,
|
|
94
|
+
item.hint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (0, import_cn.cn)("mt-1 block font-normal", panel ? "text-xs normal-case tracking-normal" : "text-xs"), children: item.hint })
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
),
|
|
98
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
+
"dd",
|
|
100
|
+
{
|
|
101
|
+
className: (0, import_cn.cn)(
|
|
102
|
+
"order-1 m-0 font-semibold tracking-tight tabular-nums",
|
|
103
|
+
panel ? panelValueClasses[size] : valueClasses[size],
|
|
104
|
+
valueClassName
|
|
105
|
+
),
|
|
106
|
+
children: item.value
|
|
107
|
+
}
|
|
108
|
+
)
|
|
72
109
|
]
|
|
73
110
|
},
|
|
74
111
|
item.label
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/stat-band/StatBand.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type StatItem = {\n /** The headline number or short value (e.g. \"12,000+\"). */\n value: React.ReactNode;\n /** What the value measures. */\n label: string;\n /** Optional supporting line under the label. */\n hint?: string;\n};\n\nexport type StatBandProps = React.HTMLAttributes<HTMLDListElement> & {\n /** Stats to display. */\n items: StatItem[];\n /** Desktop column count (2-4). Default 3. */\n columns?: 2 | 3 | 4;\n /** Copy alignment. Default 'center'. */\n align?: 'left' | 'center';\n /** Value scale. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Draw dividers between stats at sm and up. Default true. */\n divided?: boolean;\n};\n\nconst columnClasses: Record<NonNullable<StatBandProps['columns']>, string> = {\n 2: 'sm:grid-cols-2',\n 3: 'sm:grid-cols-2 lg:grid-cols-3',\n 4: 'sm:grid-cols-2 lg:grid-cols-4',\n};\n\nconst valueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-2xl',\n md: 'text-3xl',\n lg: 'text-4xl sm:text-5xl',\n};\n\n/**\n * Marketing stat band: a semantic description list of headline numbers with\n * labels and optional hints. Use it inside a Section; the Section owns the\n * surface tone, so the same band works on white and inverse backgrounds.\n */\nexport const StatBand = React.forwardRef<HTMLDListElement, StatBandProps>(function StatBand(\n {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/stat-band/StatBand.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type StatItem = {\n /** The headline number or short value (e.g. \"12,000+\"). */\n value: React.ReactNode;\n /** What the value measures. */\n label: string;\n /** Optional supporting line under the label. */\n hint?: string;\n};\n\nexport type StatBandProps = React.HTMLAttributes<HTMLDListElement> & {\n /** Stats to display. */\n items: StatItem[];\n /** Desktop column count (2-4). Default 3. */\n columns?: 2 | 3 | 4;\n /** Copy alignment. Default 'center'. */\n align?: 'left' | 'center';\n /** Value scale. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Draw dividers between stats at sm and up. Default true. */\n divided?: boolean;\n /**\n * Surface treatment. 'panel' renders a bordered strip of hairline-separated\n * cells with denser type for data pages; 'plain' is the marketing band.\n * Default 'plain'.\n */\n variant?: 'plain' | 'panel';\n /** Extra classes for the value element (e.g. font-mono for tabular numerals). */\n valueClassName?: string;\n};\n\nconst columnClasses: Record<NonNullable<StatBandProps['columns']>, string> = {\n 2: 'sm:grid-cols-2',\n 3: 'sm:grid-cols-2 lg:grid-cols-3',\n 4: 'sm:grid-cols-2 lg:grid-cols-4',\n};\n\nconst valueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-2xl',\n md: 'text-3xl',\n lg: 'text-4xl sm:text-5xl',\n};\n\nconst panelValueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-lg',\n md: 'text-xl sm:text-2xl',\n lg: 'text-2xl sm:text-3xl',\n};\n\n/**\n * Marketing stat band: a semantic description list of headline numbers with\n * labels and optional hints. Use it inside a Section; the Section owns the\n * surface tone, so the same band works on white and inverse backgrounds.\n */\nexport const StatBand = React.forwardRef<HTMLDListElement, StatBandProps>(function StatBand(\n {\n items,\n columns = 3,\n align = 'center',\n size = 'md',\n divided = true,\n variant = 'plain',\n valueClassName,\n className,\n ...props\n },\n ref\n) {\n const panel = variant === 'panel';\n return (\n <dl\n ref={ref}\n className={cn(\n 'grid w-full',\n panel ? 'gap-0 rounded-lg border border-border bg-card' : 'gap-8',\n columnClasses[columns],\n divided &&\n (panel\n ? 'divide-y divide-border sm:divide-x sm:divide-y-0'\n : 'sm:divide-x sm:divide-border'),\n className\n )}\n {...props}\n >\n {items.map((item) => (\n <div\n key={item.label}\n className={cn(\n 'flex min-w-0 flex-col gap-1',\n panel ? 'px-4 py-3 sm:px-5 sm:py-4' : 'sm:px-6 sm:first:pl-0 sm:last:pr-0',\n align === 'center' ? 'items-center text-center' : 'items-start text-left'\n )}\n >\n <dt\n className={cn(\n 'order-2 text-muted-foreground',\n panel ? 'text-xs font-medium uppercase tracking-wide' : 'text-sm font-medium'\n )}\n >\n {item.label}\n {item.hint && (\n <span className={cn('mt-1 block font-normal', panel ? 'text-xs normal-case tracking-normal' : 'text-xs')}>\n {item.hint}\n </span>\n )}\n </dt>\n <dd\n className={cn(\n 'order-1 m-0 font-semibold tracking-tight tabular-nums',\n panel ? panelValueClasses[size] : valueClasses[size],\n valueClassName\n )}\n >\n {item.value}\n </dd>\n </div>\n ))}\n </dl>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+FU;AA/FV,YAAuB;AACvB,gBAAmB;AAgCnB,MAAM,gBAAuE;AAAA,EAC3E,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEA,MAAM,eAAmE;AAAA,EACvE,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,oBAAwE;AAAA,EAC5E,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAOO,MAAM,WAAW,MAAM,WAA4C,SAASA,UACjF;AAAA,EACE;AAAA,EACA,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,EACV,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,QAAQ,YAAY;AAC1B,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,eAAW;AAAA,QACT;AAAA,QACA,QAAQ,kDAAkD;AAAA,QAC1D,cAAc,OAAO;AAAA,QACrB,YACG,QACG,qDACA;AAAA,QACN;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH,gBAAM,IAAI,CAAC,SACV;AAAA,QAAC;AAAA;AAAA,UAEC,eAAW;AAAA,YACT;AAAA,YACA,QAAQ,8BAA8B;AAAA,YACtC,UAAU,WAAW,6BAA6B;AAAA,UACpD;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,eAAW;AAAA,kBACT;AAAA,kBACA,QAAQ,gDAAgD;AAAA,gBAC1D;AAAA,gBAEC;AAAA,uBAAK;AAAA,kBACL,KAAK,QACJ,4CAAC,UAAK,eAAW,cAAG,0BAA0B,QAAQ,wCAAwC,SAAS,GACpG,eAAK,MACR;AAAA;AAAA;AAAA,YAEJ;AAAA,YACA;AAAA,cAAC;AAAA;AAAA,gBACC,eAAW;AAAA,kBACT;AAAA,kBACA,QAAQ,kBAAkB,IAAI,IAAI,aAAa,IAAI;AAAA,kBACnD;AAAA,gBACF;AAAA,gBAEC,eAAK;AAAA;AAAA,YACR;AAAA;AAAA;AAAA,QA5BK,KAAK;AAAA,MA6BZ,CACD;AAAA;AAAA,EACH;AAEJ,CAAC;","names":["StatBand"]}
|
|
@@ -11,15 +11,32 @@ const valueClasses = {
|
|
|
11
11
|
md: "text-3xl",
|
|
12
12
|
lg: "text-4xl sm:text-5xl"
|
|
13
13
|
};
|
|
14
|
-
const
|
|
14
|
+
const panelValueClasses = {
|
|
15
|
+
sm: "text-lg",
|
|
16
|
+
md: "text-xl sm:text-2xl",
|
|
17
|
+
lg: "text-2xl sm:text-3xl"
|
|
18
|
+
};
|
|
19
|
+
const StatBand = React.forwardRef(function StatBand2({
|
|
20
|
+
items,
|
|
21
|
+
columns = 3,
|
|
22
|
+
align = "center",
|
|
23
|
+
size = "md",
|
|
24
|
+
divided = true,
|
|
25
|
+
variant = "plain",
|
|
26
|
+
valueClassName,
|
|
27
|
+
className,
|
|
28
|
+
...props
|
|
29
|
+
}, ref) {
|
|
30
|
+
const panel = variant === "panel";
|
|
15
31
|
return /* @__PURE__ */ jsx(
|
|
16
32
|
"dl",
|
|
17
33
|
{
|
|
18
34
|
ref,
|
|
19
35
|
className: cn(
|
|
20
|
-
"grid w-full
|
|
36
|
+
"grid w-full",
|
|
37
|
+
panel ? "gap-0 rounded-lg border border-border bg-card" : "gap-8",
|
|
21
38
|
columnClasses[columns],
|
|
22
|
-
divided && "sm:divide-x sm:divide-border",
|
|
39
|
+
divided && (panel ? "divide-y divide-border sm:divide-x sm:divide-y-0" : "sm:divide-x sm:divide-border"),
|
|
23
40
|
className
|
|
24
41
|
),
|
|
25
42
|
...props,
|
|
@@ -27,15 +44,35 @@ const StatBand = React.forwardRef(function StatBand2({ items, columns = 3, align
|
|
|
27
44
|
"div",
|
|
28
45
|
{
|
|
29
46
|
className: cn(
|
|
30
|
-
"flex min-w-0 flex-col gap-1
|
|
47
|
+
"flex min-w-0 flex-col gap-1",
|
|
48
|
+
panel ? "px-4 py-3 sm:px-5 sm:py-4" : "sm:px-6 sm:first:pl-0 sm:last:pr-0",
|
|
31
49
|
align === "center" ? "items-center text-center" : "items-start text-left"
|
|
32
50
|
),
|
|
33
51
|
children: [
|
|
34
|
-
/* @__PURE__ */ jsxs(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
/* @__PURE__ */ jsxs(
|
|
53
|
+
"dt",
|
|
54
|
+
{
|
|
55
|
+
className: cn(
|
|
56
|
+
"order-2 text-muted-foreground",
|
|
57
|
+
panel ? "text-xs font-medium uppercase tracking-wide" : "text-sm font-medium"
|
|
58
|
+
),
|
|
59
|
+
children: [
|
|
60
|
+
item.label,
|
|
61
|
+
item.hint && /* @__PURE__ */ jsx("span", { className: cn("mt-1 block font-normal", panel ? "text-xs normal-case tracking-normal" : "text-xs"), children: item.hint })
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
/* @__PURE__ */ jsx(
|
|
66
|
+
"dd",
|
|
67
|
+
{
|
|
68
|
+
className: cn(
|
|
69
|
+
"order-1 m-0 font-semibold tracking-tight tabular-nums",
|
|
70
|
+
panel ? panelValueClasses[size] : valueClasses[size],
|
|
71
|
+
valueClassName
|
|
72
|
+
),
|
|
73
|
+
children: item.value
|
|
74
|
+
}
|
|
75
|
+
)
|
|
39
76
|
]
|
|
40
77
|
},
|
|
41
78
|
item.label
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/stat-band/StatBand.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type StatItem = {\n /** The headline number or short value (e.g. \"12,000+\"). */\n value: React.ReactNode;\n /** What the value measures. */\n label: string;\n /** Optional supporting line under the label. */\n hint?: string;\n};\n\nexport type StatBandProps = React.HTMLAttributes<HTMLDListElement> & {\n /** Stats to display. */\n items: StatItem[];\n /** Desktop column count (2-4). Default 3. */\n columns?: 2 | 3 | 4;\n /** Copy alignment. Default 'center'. */\n align?: 'left' | 'center';\n /** Value scale. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Draw dividers between stats at sm and up. Default true. */\n divided?: boolean;\n};\n\nconst columnClasses: Record<NonNullable<StatBandProps['columns']>, string> = {\n 2: 'sm:grid-cols-2',\n 3: 'sm:grid-cols-2 lg:grid-cols-3',\n 4: 'sm:grid-cols-2 lg:grid-cols-4',\n};\n\nconst valueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-2xl',\n md: 'text-3xl',\n lg: 'text-4xl sm:text-5xl',\n};\n\n/**\n * Marketing stat band: a semantic description list of headline numbers with\n * labels and optional hints. Use it inside a Section; the Section owns the\n * surface tone, so the same band works on white and inverse backgrounds.\n */\nexport const StatBand = React.forwardRef<HTMLDListElement, StatBandProps>(function StatBand(\n {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/stat-band/StatBand.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type StatItem = {\n /** The headline number or short value (e.g. \"12,000+\"). */\n value: React.ReactNode;\n /** What the value measures. */\n label: string;\n /** Optional supporting line under the label. */\n hint?: string;\n};\n\nexport type StatBandProps = React.HTMLAttributes<HTMLDListElement> & {\n /** Stats to display. */\n items: StatItem[];\n /** Desktop column count (2-4). Default 3. */\n columns?: 2 | 3 | 4;\n /** Copy alignment. Default 'center'. */\n align?: 'left' | 'center';\n /** Value scale. Default 'md'. */\n size?: 'sm' | 'md' | 'lg';\n /** Draw dividers between stats at sm and up. Default true. */\n divided?: boolean;\n /**\n * Surface treatment. 'panel' renders a bordered strip of hairline-separated\n * cells with denser type for data pages; 'plain' is the marketing band.\n * Default 'plain'.\n */\n variant?: 'plain' | 'panel';\n /** Extra classes for the value element (e.g. font-mono for tabular numerals). */\n valueClassName?: string;\n};\n\nconst columnClasses: Record<NonNullable<StatBandProps['columns']>, string> = {\n 2: 'sm:grid-cols-2',\n 3: 'sm:grid-cols-2 lg:grid-cols-3',\n 4: 'sm:grid-cols-2 lg:grid-cols-4',\n};\n\nconst valueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-2xl',\n md: 'text-3xl',\n lg: 'text-4xl sm:text-5xl',\n};\n\nconst panelValueClasses: Record<NonNullable<StatBandProps['size']>, string> = {\n sm: 'text-lg',\n md: 'text-xl sm:text-2xl',\n lg: 'text-2xl sm:text-3xl',\n};\n\n/**\n * Marketing stat band: a semantic description list of headline numbers with\n * labels and optional hints. Use it inside a Section; the Section owns the\n * surface tone, so the same band works on white and inverse backgrounds.\n */\nexport const StatBand = React.forwardRef<HTMLDListElement, StatBandProps>(function StatBand(\n {\n items,\n columns = 3,\n align = 'center',\n size = 'md',\n divided = true,\n variant = 'plain',\n valueClassName,\n className,\n ...props\n },\n ref\n) {\n const panel = variant === 'panel';\n return (\n <dl\n ref={ref}\n className={cn(\n 'grid w-full',\n panel ? 'gap-0 rounded-lg border border-border bg-card' : 'gap-8',\n columnClasses[columns],\n divided &&\n (panel\n ? 'divide-y divide-border sm:divide-x sm:divide-y-0'\n : 'sm:divide-x sm:divide-border'),\n className\n )}\n {...props}\n >\n {items.map((item) => (\n <div\n key={item.label}\n className={cn(\n 'flex min-w-0 flex-col gap-1',\n panel ? 'px-4 py-3 sm:px-5 sm:py-4' : 'sm:px-6 sm:first:pl-0 sm:last:pr-0',\n align === 'center' ? 'items-center text-center' : 'items-start text-left'\n )}\n >\n <dt\n className={cn(\n 'order-2 text-muted-foreground',\n panel ? 'text-xs font-medium uppercase tracking-wide' : 'text-sm font-medium'\n )}\n >\n {item.label}\n {item.hint && (\n <span className={cn('mt-1 block font-normal', panel ? 'text-xs normal-case tracking-normal' : 'text-xs')}>\n {item.hint}\n </span>\n )}\n </dt>\n <dd\n className={cn(\n 'order-1 m-0 font-semibold tracking-tight tabular-nums',\n panel ? panelValueClasses[size] : valueClasses[size],\n valueClassName\n )}\n >\n {item.value}\n </dd>\n </div>\n ))}\n </dl>\n );\n});\n"],"mappings":"AA+FU,SAQI,KARJ;AA/FV,YAAY,WAAW;AACvB,SAAS,UAAU;AAgCnB,MAAM,gBAAuE;AAAA,EAC3E,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEA,MAAM,eAAmE;AAAA,EACvE,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,oBAAwE;AAAA,EAC5E,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAOO,MAAM,WAAW,MAAM,WAA4C,SAASA,UACjF;AAAA,EACE;AAAA,EACA,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,EACV,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,QAAQ,YAAY;AAC1B,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA,QAAQ,kDAAkD;AAAA,QAC1D,cAAc,OAAO;AAAA,QACrB,YACG,QACG,qDACA;AAAA,QACN;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH,gBAAM,IAAI,CAAC,SACV;AAAA,QAAC;AAAA;AAAA,UAEC,WAAW;AAAA,YACT;AAAA,YACA,QAAQ,8BAA8B;AAAA,YACtC,UAAU,WAAW,6BAA6B;AAAA,UACpD;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,QAAQ,gDAAgD;AAAA,gBAC1D;AAAA,gBAEC;AAAA,uBAAK;AAAA,kBACL,KAAK,QACJ,oBAAC,UAAK,WAAW,GAAG,0BAA0B,QAAQ,wCAAwC,SAAS,GACpG,eAAK,MACR;AAAA;AAAA;AAAA,YAEJ;AAAA,YACA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,QAAQ,kBAAkB,IAAI,IAAI,aAAa,IAAI;AAAA,kBACnD;AAAA,gBACF;AAAA,gBAEC,eAAK;AAAA;AAAA,YACR;AAAA;AAAA;AAAA,QA5BK,KAAK;AAAA,MA6BZ,CACD;AAAA;AAAA,EACH;AAEJ,CAAC;","names":["StatBand"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export * from './components/data-table';
|
|
|
48
48
|
export * from './components/list';
|
|
49
49
|
export * from './components/link';
|
|
50
50
|
export * from './components/image';
|
|
51
|
+
export * from './components/cover-image';
|
|
51
52
|
export * from './components/text';
|
|
52
53
|
export * from './components/heading';
|
|
53
54
|
export * from './components/empty-state';
|