@behavioral-agentic-design-system/core 0.40.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/package.json +41 -9
- package/scripts/a11y-lint.cjs +66 -3
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +23 -3
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +128 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +78 -0
- package/scripts/wcag-audit.cjs +72 -5
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +7 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/app/layout.tsx +6 -0
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +2003 -2
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +168 -49
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/customize/design-controls.tsx +16 -1
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +13 -13
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +158 -0
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +21 -5
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/gauge-chart.tsx +252 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/index.ts +9 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +27 -7
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/tour.tsx +1 -3
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -1
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +958 -0
- package/src/data/docs-index.ts +36 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/clamp.ts +2 -0
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +41 -0
- package/src/stories/DataTable.stories.tsx +30 -0
- package/src/stories/DateField.stories.tsx +21 -0
- package/src/stories/Editable.stories.tsx +2 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/GaugeChart.stories.tsx +169 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +26 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +3 -1
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/TransferList.stories.tsx +4 -0
- package/src/stories/WeekPicker.stories.tsx +21 -0
- package/src/stories/YearPicker.stories.tsx +21 -0
- package/src/stories/story-groups.json +33 -16
- package/src/tokens.json +82 -54
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../lib/utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* International phone number input that composes a country dial-code select
|
|
8
|
+
* with a tel Input into a single E.164-formatted field.
|
|
9
|
+
*
|
|
10
|
+
* No libphonenumber validation — just UI composition. The consuming form is
|
|
11
|
+
* responsible for any deeper phone-number validation it needs.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* <PhoneInput
|
|
15
|
+
* value={phone}
|
|
16
|
+
* onChange={setPhone}
|
|
17
|
+
* defaultCountry="GB"
|
|
18
|
+
* aria-label="Phone number"
|
|
19
|
+
* />
|
|
20
|
+
*
|
|
21
|
+
* Accessibility: the outer element is role="group" with an aria-label or
|
|
22
|
+
* aria-labelledby so screen readers announce it as a composite field. Tab
|
|
23
|
+
* moves from the country select to the number input.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export type Country = {
|
|
27
|
+
iso: string;
|
|
28
|
+
dialCode: string;
|
|
29
|
+
flag: string;
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const COUNTRIES: Country[] = [
|
|
34
|
+
{ iso: "US", dialCode: "+1", flag: "🇺🇸", name: "United States" },
|
|
35
|
+
{ iso: "CA", dialCode: "+1", flag: "🇨🇦", name: "Canada" },
|
|
36
|
+
{ iso: "GB", dialCode: "+44", flag: "🇬🇧", name: "United Kingdom" },
|
|
37
|
+
{ iso: "AU", dialCode: "+61", flag: "🇦🇺", name: "Australia" },
|
|
38
|
+
{ iso: "DE", dialCode: "+49", flag: "🇩🇪", name: "Germany" },
|
|
39
|
+
{ iso: "FR", dialCode: "+33", flag: "🇫🇷", name: "France" },
|
|
40
|
+
{ iso: "JP", dialCode: "+81", flag: "🇯🇵", name: "Japan" },
|
|
41
|
+
{ iso: "BR", dialCode: "+55", flag: "🇧🇷", name: "Brazil" },
|
|
42
|
+
{ iso: "IN", dialCode: "+91", flag: "🇮🇳", name: "India" },
|
|
43
|
+
{ iso: "MX", dialCode: "+52", flag: "🇲🇽", name: "Mexico" },
|
|
44
|
+
{ iso: "IT", dialCode: "+39", flag: "🇮🇹", name: "Italy" },
|
|
45
|
+
{ iso: "ES", dialCode: "+34", flag: "🇪🇸", name: "Spain" },
|
|
46
|
+
{ iso: "NL", dialCode: "+31", flag: "🇳🇱", name: "Netherlands" },
|
|
47
|
+
{ iso: "KR", dialCode: "+82", flag: "🇰🇷", name: "South Korea" },
|
|
48
|
+
{ iso: "SG", dialCode: "+65", flag: "🇸🇬", name: "Singapore" },
|
|
49
|
+
{ iso: "SE", dialCode: "+46", flag: "🇸🇪", name: "Sweden" },
|
|
50
|
+
{ iso: "NO", dialCode: "+47", flag: "🇳🇴", name: "Norway" },
|
|
51
|
+
{ iso: "DK", dialCode: "+45", flag: "🇩🇰", name: "Denmark" },
|
|
52
|
+
{ iso: "NZ", dialCode: "+64", flag: "🇳🇿", name: "New Zealand" },
|
|
53
|
+
{ iso: "ZA", dialCode: "+27", flag: "🇿🇦", name: "South Africa" },
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function findCountry(iso: string): Country {
|
|
57
|
+
return COUNTRIES.find((c) => c.iso === iso) ?? COUNTRIES[0];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse an E.164 value (+<dialCode><localNumber>) back into its parts.
|
|
62
|
+
* Returns null when the value doesn't start with "+".
|
|
63
|
+
*/
|
|
64
|
+
function parseE164(
|
|
65
|
+
value: string,
|
|
66
|
+
countries: Country[],
|
|
67
|
+
): { country: Country; localNumber: string } | null {
|
|
68
|
+
if (!value.startsWith("+")) return null;
|
|
69
|
+
// Try longest dial code first so "+1" doesn't greedily match "+10" countries.
|
|
70
|
+
const sorted = [...countries].sort((a, b) => b.dialCode.length - a.dialCode.length);
|
|
71
|
+
for (const country of sorted) {
|
|
72
|
+
if (value.startsWith(country.dialCode)) {
|
|
73
|
+
return { country, localNumber: value.slice(country.dialCode.length) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface PhoneInputProps
|
|
80
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> {
|
|
81
|
+
/** E.164 formatted phone number value (e.g. "+14155550182"). Omit for uncontrolled. */
|
|
82
|
+
value?: string;
|
|
83
|
+
/** Called with the new E.164 string whenever the country or number changes. */
|
|
84
|
+
onChange?: (value: string) => void;
|
|
85
|
+
/** ISO 2-letter country code, default "US". */
|
|
86
|
+
defaultCountry?: string;
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
/** When true, applies the destructive ring/border to both the select and the input. */
|
|
89
|
+
error?: boolean;
|
|
90
|
+
className?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const PhoneInput = React.forwardRef<HTMLInputElement, PhoneInputProps>(
|
|
94
|
+
(
|
|
95
|
+
{
|
|
96
|
+
value,
|
|
97
|
+
onChange,
|
|
98
|
+
defaultCountry = "US",
|
|
99
|
+
disabled = false,
|
|
100
|
+
error = false,
|
|
101
|
+
className,
|
|
102
|
+
id,
|
|
103
|
+
"aria-label": ariaLabel,
|
|
104
|
+
"aria-labelledby": ariaLabelledby,
|
|
105
|
+
"aria-describedby": ariaDescribedby,
|
|
106
|
+
name,
|
|
107
|
+
...rest
|
|
108
|
+
},
|
|
109
|
+
ref,
|
|
110
|
+
) => {
|
|
111
|
+
const isControlled = value !== undefined;
|
|
112
|
+
|
|
113
|
+
const controlled = React.useMemo(() => {
|
|
114
|
+
if (!isControlled || !value) return null;
|
|
115
|
+
return parseE164(value, COUNTRIES);
|
|
116
|
+
}, [isControlled, value]);
|
|
117
|
+
|
|
118
|
+
// The chosen country is always state. Re-deriving it from the value alone loses the choice for countries that
|
|
119
|
+
// share a dial code (US and CA are both +1), so Canada snapped back to the United States.
|
|
120
|
+
const [country, setCountry] = React.useState<Country>(
|
|
121
|
+
() => controlled?.country ?? findCountry(defaultCountry),
|
|
122
|
+
);
|
|
123
|
+
// What the user typed, with their spaces and brackets. The emitted value is digits only.
|
|
124
|
+
const [typed, setTyped] = React.useState(controlled?.localNumber ?? "");
|
|
125
|
+
|
|
126
|
+
// A controlled value that points at a different dial code is an outside change (a form reset, a loaded
|
|
127
|
+
// record): follow it. The same dial code keeps whichever country the user picked.
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
if (!isControlled) return;
|
|
130
|
+
if (controlled && controlled.country.dialCode !== country.dialCode) setCountry(controlled.country);
|
|
131
|
+
}, [isControlled, controlled, country.dialCode]);
|
|
132
|
+
|
|
133
|
+
const activeCountry = country;
|
|
134
|
+
const digitsOf = (text: string) => text.replace(/\D/g, "");
|
|
135
|
+
// Show what was typed while it still matches the controlled value's digits; otherwise show the value.
|
|
136
|
+
const activeLocalNumber =
|
|
137
|
+
isControlled && digitsOf(typed) !== (controlled?.localNumber ?? "")
|
|
138
|
+
? (controlled?.localNumber ?? "")
|
|
139
|
+
: typed;
|
|
140
|
+
const e164 = digitsOf(activeLocalNumber) ? `${activeCountry.dialCode}${digitsOf(activeLocalNumber)}` : "";
|
|
141
|
+
|
|
142
|
+
function handleCountryChange(e: React.ChangeEvent<HTMLSelectElement>) {
|
|
143
|
+
const next = findCountry(e.target.value);
|
|
144
|
+
setCountry(next);
|
|
145
|
+
const digits = digitsOf(activeLocalNumber);
|
|
146
|
+
onChange?.(digits ? `${next.dialCode}${digits}` : "");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handleNumberChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
150
|
+
// Keep digits and the punctuation people type; emit digits only, so "(415) 555-0182" is "+14155550182".
|
|
151
|
+
const raw = e.target.value.replace(/[^\d\s\-().]/g, "");
|
|
152
|
+
setTyped(raw);
|
|
153
|
+
const digits = digitsOf(raw);
|
|
154
|
+
onChange?.(digits ? `${activeCountry.dialCode}${digits}` : "");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const reactId = React.useId();
|
|
158
|
+
const inputId = id ?? `phone-input-${reactId}`;
|
|
159
|
+
const selectId = `${inputId}-country`;
|
|
160
|
+
|
|
161
|
+
const groupAriaProps: React.AriaAttributes & { role: string } = {
|
|
162
|
+
role: "group",
|
|
163
|
+
};
|
|
164
|
+
if (ariaLabel) {
|
|
165
|
+
groupAriaProps["aria-label"] = ariaLabel;
|
|
166
|
+
} else if (ariaLabelledby) {
|
|
167
|
+
groupAriaProps["aria-labelledby"] = ariaLabelledby;
|
|
168
|
+
} else {
|
|
169
|
+
groupAriaProps["aria-label"] = "Phone number";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<div
|
|
174
|
+
data-slot="phone-input"
|
|
175
|
+
data-disabled={disabled || undefined}
|
|
176
|
+
data-invalid={error || undefined}
|
|
177
|
+
className={cn("flex w-full min-w-0", className)}
|
|
178
|
+
{...groupAriaProps}
|
|
179
|
+
>
|
|
180
|
+
{/* Country dial-code select */}
|
|
181
|
+
<div className="relative shrink-0">
|
|
182
|
+
<select
|
|
183
|
+
id={selectId}
|
|
184
|
+
data-slot="phone-input-country"
|
|
185
|
+
value={activeCountry.iso}
|
|
186
|
+
onChange={handleCountryChange}
|
|
187
|
+
disabled={disabled}
|
|
188
|
+
aria-label={`Country code — ${activeCountry.name} (${activeCountry.dialCode})`}
|
|
189
|
+
aria-invalid={error || undefined}
|
|
190
|
+
className={cn(
|
|
191
|
+
// Base
|
|
192
|
+
"h-9 min-w-0 appearance-none rounded-l-md rounded-r-none border border-r-0 border-input",
|
|
193
|
+
"bg-transparent px-2 pr-7 text-base text-foreground outline-none",
|
|
194
|
+
"dark:bg-input/30 md:text-sm",
|
|
195
|
+
// States
|
|
196
|
+
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
197
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
198
|
+
// Error
|
|
199
|
+
error &&
|
|
200
|
+
"border-destructive ring-destructive/20 focus-visible:ring-destructive/40 dark:ring-destructive/40",
|
|
201
|
+
)}
|
|
202
|
+
style={{
|
|
203
|
+
transitionProperty: "color, box-shadow",
|
|
204
|
+
transitionDuration: "var(--duration-fast)",
|
|
205
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
{COUNTRIES.map((country) => (
|
|
209
|
+
<option key={country.iso} value={country.iso}>
|
|
210
|
+
{country.flag} {country.dialCode}
|
|
211
|
+
</option>
|
|
212
|
+
))}
|
|
213
|
+
</select>
|
|
214
|
+
{/* Chevron icon */}
|
|
215
|
+
<svg
|
|
216
|
+
aria-hidden="true"
|
|
217
|
+
viewBox="0 0 16 16"
|
|
218
|
+
className="pointer-events-none absolute right-1.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"
|
|
219
|
+
fill="none"
|
|
220
|
+
stroke="currentColor"
|
|
221
|
+
strokeWidth={1.5}
|
|
222
|
+
strokeLinecap="round"
|
|
223
|
+
strokeLinejoin="round"
|
|
224
|
+
>
|
|
225
|
+
<path d="M4 6l4 4 4-4" />
|
|
226
|
+
</svg>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
{/* A plain <form> posts this: the visible input holds only the local part, so it carries no name. */}
|
|
230
|
+
{name ? <input type="hidden" name={name} value={e164} /> : null}
|
|
231
|
+
|
|
232
|
+
{/* Local number input */}
|
|
233
|
+
<input
|
|
234
|
+
ref={ref}
|
|
235
|
+
id={inputId}
|
|
236
|
+
data-slot="phone-input-number"
|
|
237
|
+
type="tel"
|
|
238
|
+
inputMode="tel"
|
|
239
|
+
autoComplete="tel-national"
|
|
240
|
+
value={activeLocalNumber}
|
|
241
|
+
onChange={handleNumberChange}
|
|
242
|
+
disabled={disabled}
|
|
243
|
+
aria-invalid={error || undefined}
|
|
244
|
+
aria-describedby={ariaDescribedby}
|
|
245
|
+
placeholder="(555) 000-0000"
|
|
246
|
+
className={cn(
|
|
247
|
+
// Base
|
|
248
|
+
"min-w-0 flex-1 rounded-l-none rounded-r-md border border-l-0 border-input",
|
|
249
|
+
"h-9 bg-transparent px-3 py-1 text-base outline-none",
|
|
250
|
+
"selection:bg-primary selection:text-primary-foreground md:text-sm",
|
|
251
|
+
"dark:bg-input/30",
|
|
252
|
+
// States
|
|
253
|
+
"placeholder:text-muted-foreground",
|
|
254
|
+
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
255
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
256
|
+
// Error
|
|
257
|
+
error &&
|
|
258
|
+
"border-destructive ring-destructive/20 focus-visible:ring-destructive/40 dark:ring-destructive/40",
|
|
259
|
+
)}
|
|
260
|
+
style={{
|
|
261
|
+
transitionProperty: "color, box-shadow",
|
|
262
|
+
transitionDuration: "var(--duration-fast)",
|
|
263
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
264
|
+
}}
|
|
265
|
+
{...rest}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
PhoneInput.displayName = "PhoneInput";
|
|
273
|
+
|
|
274
|
+
export { PhoneInput };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
// Pill — compact, non-removable, read-only label.
|
|
7
|
+
//
|
|
8
|
+
// The fourth member of the label family, and the only one with no behavior
|
|
9
|
+
// baked into its API:
|
|
10
|
+
// - Tag → passive label WITH dismiss DNA (onClose) + semantic status
|
|
11
|
+
// variants; takes its text via `label`.
|
|
12
|
+
// - Badge → status/count semantics (primary fill by default,
|
|
13
|
+
// success/warning/info/destructive) and a focus ring for the
|
|
14
|
+
// `asChild` anchor case.
|
|
15
|
+
// - Chip → interactive filter toggle (native button, role=checkbox).
|
|
16
|
+
// - Pill → this. A neutral label for metadata that is neither a status
|
|
17
|
+
// nor an action and can never be removed in place: taxonomy
|
|
18
|
+
// terms, owner names, environment names, counts in a header.
|
|
19
|
+
//
|
|
20
|
+
// Peer parity: Mantine `Pill` (plain span, no role, `disabled` dims only) and
|
|
21
|
+
// Chakra `Tag` without its close trigger. Like both, Pill renders a plain
|
|
22
|
+
// <span> with no ARIA role: a label with no interaction needs none, and a
|
|
23
|
+
// screen reader reads it as inline text in sequence with its neighbours.
|
|
24
|
+
//
|
|
25
|
+
// Motion is pattern (c): `transition-colors` for the property list + inline
|
|
26
|
+
// var(--duration-fast) / var(--ease-out). Pill has no hover state of its own
|
|
27
|
+
// (it is not interactive), so the transition only fires when a consumer
|
|
28
|
+
// re-themes it (variant swap, theme toggle) — but the token-driven duration
|
|
29
|
+
// is still what keeps that repaint consistent with Tag and Badge.
|
|
30
|
+
|
|
31
|
+
const pillVariants = cva(
|
|
32
|
+
[
|
|
33
|
+
// Long-label overflow contract (CLAUDE.md → "Long-label overflow"): the
|
|
34
|
+
// span is the flex parent (max-w-full min-w-0 overflow-hidden); the inner
|
|
35
|
+
// label span truncates. Pills routinely hold runtime strings — user names,
|
|
36
|
+
// slugs, taxonomy terms — that have no word boundaries to wrap at.
|
|
37
|
+
"inline-flex max-w-full min-w-0 shrink-0 items-center overflow-hidden rounded-full border font-medium whitespace-nowrap select-none",
|
|
38
|
+
"transition-colors",
|
|
39
|
+
"data-[disabled]:opacity-50",
|
|
40
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
41
|
+
],
|
|
42
|
+
{
|
|
43
|
+
variants: {
|
|
44
|
+
variant: {
|
|
45
|
+
default: "border-transparent bg-secondary text-secondary-foreground",
|
|
46
|
+
outline: "border-border bg-transparent text-foreground",
|
|
47
|
+
muted: "border-transparent bg-muted text-muted-foreground",
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Height ladder. sm is the default (Mantine's default register —
|
|
51
|
+
* dense metadata rows, card footers); md matches Tag md / Badge lg for
|
|
52
|
+
* body-copy rows; lg is for header and hero metadata.
|
|
53
|
+
* BADS text-xs = 14px and text-sm = 16px — never below 14px (AAA floor).
|
|
54
|
+
*/
|
|
55
|
+
size: {
|
|
56
|
+
sm: "gap-1 px-2 py-0.5 text-xs [&_svg]:size-3",
|
|
57
|
+
md: "gap-1 px-2.5 py-0.5 text-sm [&_svg]:size-3.5",
|
|
58
|
+
lg: "gap-1.5 px-3 py-1 text-sm [&_svg]:size-4",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
variant: "default",
|
|
63
|
+
size: "sm",
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
type PillProps = Omit<React.ComponentProps<"span">, "children"> &
|
|
69
|
+
VariantProps<typeof pillVariants> & {
|
|
70
|
+
/**
|
|
71
|
+
* Optional leading element — a Lucide icon (strokeWidth 1.5), a custom
|
|
72
|
+
* SVG, or a small Avatar (`size="xs"`). SVGs are sized per `size`;
|
|
73
|
+
* anything else keeps its own dimensions.
|
|
74
|
+
*/
|
|
75
|
+
icon?: React.ReactNode
|
|
76
|
+
/**
|
|
77
|
+
* Presentational dimming. Pill has no interactive state to disable —
|
|
78
|
+
* this mirrors Mantine's `disabled` and exists so a pill inside a
|
|
79
|
+
* disabled control (a disabled fieldset's selected values, an archived
|
|
80
|
+
* row) dims with it. Sets `data-disabled` only: the owning control is
|
|
81
|
+
* responsible for conveying the disabled state to assistive tech.
|
|
82
|
+
*/
|
|
83
|
+
disabled?: boolean
|
|
84
|
+
/** Visible label text. Keep it to a few words — Pill truncates, it never wraps. */
|
|
85
|
+
children: React.ReactNode
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Pill({
|
|
89
|
+
className,
|
|
90
|
+
variant,
|
|
91
|
+
size,
|
|
92
|
+
icon,
|
|
93
|
+
disabled,
|
|
94
|
+
style,
|
|
95
|
+
children,
|
|
96
|
+
...props
|
|
97
|
+
}: PillProps) {
|
|
98
|
+
return (
|
|
99
|
+
<span
|
|
100
|
+
data-slot="pill"
|
|
101
|
+
data-variant={variant ?? "default"}
|
|
102
|
+
data-size={size ?? "sm"}
|
|
103
|
+
data-disabled={disabled ? "" : undefined}
|
|
104
|
+
className={cn(pillVariants({ variant, size }), className)}
|
|
105
|
+
style={{
|
|
106
|
+
transitionDuration: "var(--duration-fast)",
|
|
107
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
108
|
+
...style,
|
|
109
|
+
}}
|
|
110
|
+
{...props}
|
|
111
|
+
>
|
|
112
|
+
{icon != null && (
|
|
113
|
+
<span aria-hidden="true" className="flex shrink-0 items-center [&>svg]:stroke-[1.5]">
|
|
114
|
+
{icon}
|
|
115
|
+
</span>
|
|
116
|
+
)}
|
|
117
|
+
<span className="min-w-0 truncate">{children}</span>
|
|
118
|
+
</span>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type PillGroupProps = React.ComponentProps<"div">
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Wrapping flex row for a set of Pills. Plain <div> — a row of labels is
|
|
126
|
+
* inline text, not a list widget. Pass `aria-label` or `role="list"` only
|
|
127
|
+
* when the group itself is a navigable landmark in the consuming surface.
|
|
128
|
+
*/
|
|
129
|
+
function PillGroup({ className, ...props }: PillGroupProps) {
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
data-slot="pill-group"
|
|
133
|
+
className={cn("flex flex-wrap items-center gap-1.5", className)}
|
|
134
|
+
{...props}
|
|
135
|
+
/>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { Pill, PillGroup, pillVariants }
|
|
140
|
+
export type { PillProps, PillGroupProps }
|
|
@@ -21,9 +21,23 @@ function PopoverTrigger({
|
|
|
21
21
|
function PopoverContent({
|
|
22
22
|
className,
|
|
23
23
|
align = "center",
|
|
24
|
-
sideOffset
|
|
24
|
+
sideOffset,
|
|
25
|
+
showArrow = false,
|
|
26
|
+
children,
|
|
25
27
|
...props
|
|
26
|
-
}: React.ComponentProps<typeof PopoverPrimitive.Content>
|
|
28
|
+
}: React.ComponentProps<typeof PopoverPrimitive.Content> & {
|
|
29
|
+
/**
|
|
30
|
+
* Renders a directional arrow caret pointing at the trigger. Matches the
|
|
31
|
+
* popover border + background so it reads as an extension of the panel.
|
|
32
|
+
* Peer parity: Mantine Popover arrow, Ant Design Popover arrow, MUI Popper
|
|
33
|
+
* arrow, Chakra UI Popover arrow. Defaults to false (existing behaviour
|
|
34
|
+
* unchanged — byte-identical for consumers that don't set this prop).
|
|
35
|
+
*/
|
|
36
|
+
showArrow?: boolean
|
|
37
|
+
}) {
|
|
38
|
+
// When showArrow is true, add extra sideOffset to accommodate the arrow height
|
|
39
|
+
// so the panel doesn't overlap the trigger element.
|
|
40
|
+
const resolvedSideOffset = sideOffset ?? (showArrow ? 8 : 4)
|
|
27
41
|
// See use-portal-theme-class.ts: lets a PortalThemeProvider scope class
|
|
28
42
|
// (e.g. "atrium-theme") apply to portal content so theme-scoped CSS
|
|
29
43
|
// variables resolve inside the portal.
|
|
@@ -33,14 +47,23 @@ function PopoverContent({
|
|
|
33
47
|
<PopoverPrimitive.Content
|
|
34
48
|
data-slot="popover-content"
|
|
35
49
|
align={align}
|
|
36
|
-
sideOffset={
|
|
50
|
+
sideOffset={resolvedSideOffset}
|
|
37
51
|
className={cn(
|
|
38
52
|
"z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
39
53
|
portalThemeClass,
|
|
40
54
|
className
|
|
41
55
|
)}
|
|
42
56
|
{...props}
|
|
43
|
-
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
{showArrow && (
|
|
60
|
+
<PopoverPrimitive.Arrow
|
|
61
|
+
width={11}
|
|
62
|
+
height={5.5}
|
|
63
|
+
className="fill-popover [filter:drop-shadow(0_1.5px_0_var(--border))]"
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
</PopoverPrimitive.Content>
|
|
44
67
|
</PopoverPrimitive.Portal>
|
|
45
68
|
)
|
|
46
69
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
export interface ScrollProgressProps {
|
|
7
|
+
/**
|
|
8
|
+
* Element to track scroll progress for.
|
|
9
|
+
* When omitted, tracks the window (document scroll).
|
|
10
|
+
*/
|
|
11
|
+
containerRef?: React.RefObject<HTMLElement | null>
|
|
12
|
+
/**
|
|
13
|
+
* Where to render the bar. "page" = fixed at top of viewport (default for
|
|
14
|
+
* window tracking). "sticky" = sticky inside a scrolling container.
|
|
15
|
+
* "inline" = renders in flow — position it yourself.
|
|
16
|
+
*/
|
|
17
|
+
position?: "fixed" | "sticky" | "inline"
|
|
18
|
+
/** Override the bar height. Default "2px". */
|
|
19
|
+
height?: string
|
|
20
|
+
/** Override the filled color. Default `var(--primary)`. */
|
|
21
|
+
color?: string
|
|
22
|
+
/** Override the track (background) color. Default `var(--border)`. */
|
|
23
|
+
trackColor?: string
|
|
24
|
+
className?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Scroll-position progress indicator. Shows how far the user has scrolled
|
|
29
|
+
* through the tracked element or the whole page as a thin colored bar.
|
|
30
|
+
*
|
|
31
|
+
* Sources: GitHub PR scroll indicator, Mantine ScrollProgress RFC, shadcn
|
|
32
|
+
* community recipe (2026-Q3), Next.js nprogress-style indicators.
|
|
33
|
+
*
|
|
34
|
+
* Reduced-motion: the bar updates immediately without any `transition`
|
|
35
|
+
* (the base layer's 0.01ms override would silently fire here anyway).
|
|
36
|
+
*/
|
|
37
|
+
function ScrollProgress({
|
|
38
|
+
containerRef,
|
|
39
|
+
position = "fixed",
|
|
40
|
+
height = "2px",
|
|
41
|
+
color,
|
|
42
|
+
trackColor,
|
|
43
|
+
className,
|
|
44
|
+
}: ScrollProgressProps) {
|
|
45
|
+
const [progress, setProgress] = React.useState(0)
|
|
46
|
+
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
function calculate() {
|
|
49
|
+
if (containerRef?.current) {
|
|
50
|
+
const el = containerRef.current
|
|
51
|
+
const scrollTop = el.scrollTop
|
|
52
|
+
const scrollHeight = el.scrollHeight - el.clientHeight
|
|
53
|
+
setProgress(scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0)
|
|
54
|
+
} else {
|
|
55
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop
|
|
56
|
+
const docHeight =
|
|
57
|
+
document.documentElement.scrollHeight -
|
|
58
|
+
document.documentElement.clientHeight
|
|
59
|
+
setProgress(docHeight > 0 ? (scrollTop / docHeight) * 100 : 0)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const target = containerRef?.current ?? window
|
|
64
|
+
target.addEventListener("scroll", calculate, { passive: true })
|
|
65
|
+
calculate()
|
|
66
|
+
return () => target.removeEventListener("scroll", calculate)
|
|
67
|
+
}, [containerRef])
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
data-slot="scroll-progress"
|
|
72
|
+
role="progressbar"
|
|
73
|
+
aria-label="Page scroll progress"
|
|
74
|
+
aria-valuenow={Math.round(progress)}
|
|
75
|
+
aria-valuemin={0}
|
|
76
|
+
aria-valuemax={100}
|
|
77
|
+
className={cn(
|
|
78
|
+
"left-0 top-0 w-full overflow-hidden",
|
|
79
|
+
position === "fixed" && "fixed z-50",
|
|
80
|
+
position === "sticky" && "sticky z-10",
|
|
81
|
+
position === "inline" && "relative",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
style={{
|
|
85
|
+
height,
|
|
86
|
+
backgroundColor: trackColor ?? "var(--border)",
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<div
|
|
90
|
+
className="h-full"
|
|
91
|
+
style={{
|
|
92
|
+
width: `${progress}%`,
|
|
93
|
+
backgroundColor: color ?? "var(--primary)",
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { ScrollProgress }
|