@carbonbits/sixr 1.3.0 → 1.5.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 +204 -66
- package/dist/button.cjs +223 -0
- package/dist/button.cjs.map +1 -0
- package/dist/button.d.cts +34 -0
- package/dist/button.d.ts +34 -0
- package/dist/button.js +4 -0
- package/dist/button.js.map +1 -0
- package/dist/chunk-HDTW4FRT.js +111 -0
- package/dist/chunk-HDTW4FRT.js.map +1 -0
- package/dist/chunk-NZHHNVXZ.js +118 -0
- package/dist/chunk-NZHHNVXZ.js.map +1 -0
- package/dist/email-input.cjs +433 -0
- package/dist/email-input.cjs.map +1 -0
- package/dist/email-input.d.cts +12 -0
- package/dist/email-input.d.ts +12 -0
- package/dist/email-input.js +416 -0
- package/dist/email-input.js.map +1 -0
- package/dist/field.cjs +206 -0
- package/dist/field.cjs.map +1 -0
- package/dist/field.d.cts +80 -0
- package/dist/field.d.ts +80 -0
- package/dist/field.js +186 -0
- package/dist/field.js.map +1 -0
- package/dist/form.cjs +283 -42
- package/dist/form.cjs.map +1 -1
- package/dist/form.d.cts +79 -10
- package/dist/form.d.ts +79 -10
- package/dist/form.js +285 -45
- package/dist/form.js.map +1 -1
- package/dist/index-CdYkd6zz.d.cts +22 -0
- package/dist/index-CdYkd6zz.d.ts +22 -0
- package/dist/index.cjs +217 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -46
- package/dist/index.d.ts +146 -46
- package/dist/index.js +2 -0
- package/dist/password-input.cjs +449 -0
- package/dist/password-input.cjs.map +1 -0
- package/dist/password-input.d.cts +19 -0
- package/dist/password-input.d.ts +19 -0
- package/dist/password-input.js +434 -0
- package/dist/password-input.js.map +1 -0
- package/dist/phone-input.cjs +429 -0
- package/dist/phone-input.cjs.map +1 -0
- package/dist/phone-input.d.cts +12 -0
- package/dist/phone-input.d.ts +12 -0
- package/dist/phone-input.js +412 -0
- package/dist/phone-input.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/text-input.cjs +359 -147
- package/dist/text-input.cjs.map +1 -1
- package/dist/text-input.d.cts +9 -58
- package/dist/text-input.d.ts +9 -58
- package/dist/text-input.js +365 -150
- package/dist/text-input.js.map +1 -1
- package/dist/typography.cjs +120 -0
- package/dist/typography.cjs.map +1 -0
- package/dist/typography.d.cts +46 -0
- package/dist/typography.d.ts +46 -0
- package/dist/typography.js +3 -0
- package/dist/typography.js.map +1 -0
- package/package.json +69 -1
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ButtonHTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The design's primary action, as the auth screens use it: a 40px (or 44px)
|
|
6
|
+
* accent-filled control with the field type scale, a 4px radius and the
|
|
7
|
+
* shared 45% disabled opacity. `secondary` and `ghost` cover the quieter
|
|
8
|
+
* actions that sit beside it.
|
|
9
|
+
*
|
|
10
|
+
* Server-safe: no state, no handlers of its own. `asChild` composes onto a
|
|
11
|
+
* consumer's element — a `next/link` for a navigation styled as a button —
|
|
12
|
+
* through Radix `Slot`, so the link keeps its own semantics. `loading` swaps
|
|
13
|
+
* the label for a spinner and disables the control; it applies to the
|
|
14
|
+
* rendered `<button>` only, since a child element owns its own content.
|
|
15
|
+
*/
|
|
16
|
+
type ButtonVariant = "primary" | "secondary" | "ghost";
|
|
17
|
+
type ButtonSize = "md" | "lg";
|
|
18
|
+
type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> & {
|
|
19
|
+
variant?: ButtonVariant;
|
|
20
|
+
size?: ButtonSize;
|
|
21
|
+
/** Stretch to the container, as the auth forms' submit does. */
|
|
22
|
+
fullWidth?: boolean;
|
|
23
|
+
/** Shows a spinner in place of the label and disables the control. */
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
/** Shown next to the spinner while `loading`; nothing but the spinner otherwise. */
|
|
26
|
+
loadingLabel?: ReactNode;
|
|
27
|
+
/** Merge the styles onto the child element instead of rendering a button. */
|
|
28
|
+
asChild?: boolean;
|
|
29
|
+
ref?: Ref<HTMLButtonElement>;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
};
|
|
32
|
+
declare function Button({ variant, size, fullWidth, loading, loadingLabel, asChild, type, disabled, className, children, ...rest }: ButtonProps): react.JSX.Element;
|
|
33
|
+
|
|
34
|
+
export { Button, type ButtonProps, type ButtonSize, type ButtonVariant };
|
package/dist/button.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"button.js"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Typography } from './chunk-NZHHNVXZ.js';
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var BASE_CLASSES = "inline-flex shrink-0 items-center justify-center gap-2 rounded-field border font-[inherit] text-field font-semibold outline-none transition-colors focus-visible:ring-3 focus-visible:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-45";
|
|
6
|
+
var VARIANT_CLASSES = {
|
|
7
|
+
primary: "border-transparent bg-accent text-on-accent enabled:hover:bg-accent-2",
|
|
8
|
+
secondary: "border-line bg-surface text-fg enabled:hover:bg-surface-2",
|
|
9
|
+
ghost: "border-transparent bg-transparent text-fg enabled:hover:bg-surface-2"
|
|
10
|
+
};
|
|
11
|
+
var SIZE_CLASSES = {
|
|
12
|
+
md: "h-10 px-4",
|
|
13
|
+
lg: "h-11 px-5"
|
|
14
|
+
};
|
|
15
|
+
var LABEL_TONE = {
|
|
16
|
+
primary: "on-accent",
|
|
17
|
+
secondary: "default",
|
|
18
|
+
ghost: "default"
|
|
19
|
+
};
|
|
20
|
+
function buttonClassName({
|
|
21
|
+
variant,
|
|
22
|
+
size,
|
|
23
|
+
fullWidth,
|
|
24
|
+
className
|
|
25
|
+
}) {
|
|
26
|
+
return [
|
|
27
|
+
BASE_CLASSES,
|
|
28
|
+
VARIANT_CLASSES[variant],
|
|
29
|
+
SIZE_CLASSES[size],
|
|
30
|
+
fullWidth ? "w-full" : "",
|
|
31
|
+
className ?? ""
|
|
32
|
+
].filter(Boolean).join(" ");
|
|
33
|
+
}
|
|
34
|
+
function Spinner() {
|
|
35
|
+
return /* @__PURE__ */ jsxs(
|
|
36
|
+
"svg",
|
|
37
|
+
{
|
|
38
|
+
className: "h-4 w-4 animate-spin",
|
|
39
|
+
viewBox: "0 0 24 24",
|
|
40
|
+
fill: "none",
|
|
41
|
+
"aria-hidden": "true",
|
|
42
|
+
"data-testid": "button-spinner",
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
"circle",
|
|
46
|
+
{
|
|
47
|
+
className: "opacity-25",
|
|
48
|
+
cx: "12",
|
|
49
|
+
cy: "12",
|
|
50
|
+
r: "10",
|
|
51
|
+
stroke: "currentColor",
|
|
52
|
+
strokeWidth: "4"
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
/* @__PURE__ */ jsx(
|
|
56
|
+
"path",
|
|
57
|
+
{
|
|
58
|
+
className: "opacity-75",
|
|
59
|
+
fill: "currentColor",
|
|
60
|
+
d: "M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12H4Z"
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function Button({
|
|
68
|
+
variant = "primary",
|
|
69
|
+
size = "md",
|
|
70
|
+
fullWidth = false,
|
|
71
|
+
loading = false,
|
|
72
|
+
loadingLabel,
|
|
73
|
+
asChild = false,
|
|
74
|
+
type = "button",
|
|
75
|
+
disabled,
|
|
76
|
+
className,
|
|
77
|
+
children,
|
|
78
|
+
...rest
|
|
79
|
+
}) {
|
|
80
|
+
const classes = buttonClassName({ variant, size, fullWidth, className });
|
|
81
|
+
if (asChild) {
|
|
82
|
+
return /* @__PURE__ */ jsx(Slot, { ...rest, className: classes, children });
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
"button",
|
|
86
|
+
{
|
|
87
|
+
...rest,
|
|
88
|
+
type,
|
|
89
|
+
disabled: disabled || loading,
|
|
90
|
+
"aria-busy": loading || void 0,
|
|
91
|
+
className: classes,
|
|
92
|
+
children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
93
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
94
|
+
loadingLabel
|
|
95
|
+
] }) : /* @__PURE__ */ jsx(
|
|
96
|
+
Typography,
|
|
97
|
+
{
|
|
98
|
+
as: "span",
|
|
99
|
+
variant: "body",
|
|
100
|
+
weight: "semibold",
|
|
101
|
+
tone: LABEL_TONE[variant],
|
|
102
|
+
children
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { Button };
|
|
110
|
+
//# sourceMappingURL=chunk-HDTW4FRT.js.map
|
|
111
|
+
//# sourceMappingURL=chunk-HDTW4FRT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/button/index.tsx"],"names":[],"mappings":";;;;AAsCA,IAAM,YAAA,GACJ,wPAAA;AAEF,IAAM,eAAA,GAAiD;AAAA,EACrD,OAAA,EACE,uEAAA;AAAA,EACF,SAAA,EAAW,2DAAA;AAAA,EACX,KAAA,EAAO;AACT,CAAA;AAEA,IAAM,YAAA,GAA2C;AAAA,EAC/C,EAAA,EAAI,WAAA;AAAA,EACJ,EAAA,EAAI;AACN,CAAA;AAEA,IAAM,UAAA,GAAoD;AAAA,EACxD,OAAA,EAAS,WAAA;AAAA,EACT,SAAA,EAAW,SAAA;AAAA,EACX,KAAA,EAAO;AACT,CAAA;AAEA,SAAS,eAAA,CAAgB;AAAA,EACvB,OAAA;AA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,EAAgB;AACd,EAAA,MAAM,UAAU,eAAA,CAAgB,EAAE,SAAS,IAAA,EAAM,SAAA,EAAW,WAAW,CAAA;AAEvE,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,2BACG,IAAA,EAAA,EAAM,GAAG,IAAA,EAAM,SAAA,EAAW,SACxB,QAAA,EACH,CAAA;AAAA,EAEJ;AAEA,EAAA,uBACE,GAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACE,GAAG,IAAA;AAAA,MACJ,IAAA;AAAA,MACA,UAAU,QAAA,IAAY,OAAA;AAAA,MACtB,aAAW,OAAA,IAAW,MAAA;AAAA,MACtB,SAAA,EAAW,OAAA;AAAA,MAEV,oCACC,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,OAAA,EAAA,EAAQ,CAAA;AAAA,QACR;AAAA,OAAA,EACH,CAAA,mBAEA,GAAA;AAAA,QAAC,UAAA;AAAA,QAAA;AAAA,UACC,EAAA,EAAG,MAAA;AAAA,UACH,OAAA,EAAQ,MAAA;AAAA,UACR,MAAA,EAAO,UAAA;AAAA,UACP,IAAA,EAAM,WAAW,OAAO,CAAA;AAAA,UAEvB;AAAA;AAAA;AACH;AAAA,GAEJ;AAEJ","file":"chunk-HDTW4FRT.js","sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ButtonHTMLAttributes, ReactNode, Ref } from \"react\";\nimport { Typography, type TypographyTone } from \"@/components/typography\";\n\n/**\n * The design's primary action, as the auth screens use it: a 40px (or 44px)\n * accent-filled control with the field type scale, a 4px radius and the\n * shared 45% disabled opacity. `secondary` and `ghost` cover the quieter\n * actions that sit beside it.\n *\n * Server-safe: no state, no handlers of its own. `asChild` composes onto a\n * consumer's element — a `next/link` for a navigation styled as a button —\n * through Radix `Slot`, so the link keeps its own semantics. `loading` swaps\n * the label for a spinner and disables the control; it applies to the\n * rendered `<button>` only, since a child element owns its own content.\n */\n\nexport type ButtonVariant = \"primary\" | \"secondary\" | \"ghost\";\nexport type ButtonSize = \"md\" | \"lg\";\n\nexport type ButtonProps = Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"children\"\n> & {\n variant?: ButtonVariant;\n size?: ButtonSize;\n /** Stretch to the container, as the auth forms' submit does. */\n fullWidth?: boolean;\n /** Shows a spinner in place of the label and disables the control. */\n loading?: boolean;\n /** Shown next to the spinner while `loading`; nothing but the spinner otherwise. */\n loadingLabel?: ReactNode;\n /** Merge the styles onto the child element instead of rendering a button. */\n asChild?: boolean;\n ref?: Ref<HTMLButtonElement>;\n children: ReactNode;\n};\n\nconst BASE_CLASSES =\n \"inline-flex shrink-0 items-center justify-center gap-2 rounded-field border font-[inherit] text-field font-semibold outline-none transition-colors focus-visible:ring-3 focus-visible:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-45\";\n\nconst VARIANT_CLASSES: Record<ButtonVariant, string> = {\n primary:\n \"border-transparent bg-accent text-on-accent enabled:hover:bg-accent-2\",\n secondary: \"border-line bg-surface text-fg enabled:hover:bg-surface-2\",\n ghost: \"border-transparent bg-transparent text-fg enabled:hover:bg-surface-2\",\n};\n\nconst SIZE_CLASSES: Record<ButtonSize, string> = {\n md: \"h-10 px-4\",\n lg: \"h-11 px-5\",\n};\n\nconst LABEL_TONE: Record<ButtonVariant, TypographyTone> = {\n primary: \"on-accent\",\n secondary: \"default\",\n ghost: \"default\",\n};\n\nfunction buttonClassName({\n variant,\n size,\n fullWidth,\n className,\n}: {\n variant: ButtonVariant;\n size: ButtonSize;\n fullWidth: boolean;\n className: string | undefined;\n}): string {\n return [\n BASE_CLASSES,\n VARIANT_CLASSES[variant],\n SIZE_CLASSES[size],\n fullWidth ? \"w-full\" : \"\",\n className ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n}\n\nfunction Spinner() {\n return (\n <svg\n className=\"h-4 w-4 animate-spin\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n aria-hidden=\"true\"\n data-testid=\"button-spinner\"\n >\n <circle\n className=\"opacity-25\"\n cx=\"12\"\n cy=\"12\"\n r=\"10\"\n stroke=\"currentColor\"\n strokeWidth=\"4\"\n />\n <path\n className=\"opacity-75\"\n fill=\"currentColor\"\n d=\"M4 12a8 8 0 0 1 8-8V0C5.373 0 0 5.373 0 12H4Z\"\n />\n </svg>\n );\n}\n\nexport function Button({\n variant = \"primary\",\n size = \"md\",\n fullWidth = false,\n loading = false,\n loadingLabel,\n asChild = false,\n type = \"button\",\n disabled,\n className,\n children,\n ...rest\n}: ButtonProps) {\n const classes = buttonClassName({ variant, size, fullWidth, className });\n\n if (asChild) {\n return (\n <Slot {...rest} className={classes}>\n {children}\n </Slot>\n );\n }\n\n return (\n <button\n {...rest}\n type={type}\n disabled={disabled || loading}\n aria-busy={loading || undefined}\n className={classes}\n >\n {loading ? (\n <>\n <Spinner />\n {loadingLabel}\n </>\n ) : (\n <Typography\n as=\"span\"\n variant=\"body\"\n weight=\"semibold\"\n tone={LABEL_TONE[variant]}\n >\n {children}\n </Typography>\n )}\n </button>\n );\n}\n"]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/components/typography/index.tsx
|
|
5
|
+
var DEFAULT_ELEMENT = {
|
|
6
|
+
display: "h1",
|
|
7
|
+
heading: "h2",
|
|
8
|
+
subheading: "h3",
|
|
9
|
+
body: "p",
|
|
10
|
+
label: "span",
|
|
11
|
+
hint: "p",
|
|
12
|
+
code: "code"
|
|
13
|
+
};
|
|
14
|
+
var DEFAULT_WEIGHT = {
|
|
15
|
+
display: "semibold",
|
|
16
|
+
heading: "semibold",
|
|
17
|
+
subheading: "medium",
|
|
18
|
+
body: "regular",
|
|
19
|
+
label: "semibold",
|
|
20
|
+
hint: "regular",
|
|
21
|
+
code: "regular"
|
|
22
|
+
};
|
|
23
|
+
var VARIANT_CLASSES = {
|
|
24
|
+
display: "text-display leading-tight tracking-tight",
|
|
25
|
+
heading: "text-heading leading-tight tracking-tight",
|
|
26
|
+
subheading: "text-subheading leading-snug",
|
|
27
|
+
body: "text-field leading-normal",
|
|
28
|
+
label: "text-label leading-normal",
|
|
29
|
+
hint: "text-hint leading-normal",
|
|
30
|
+
code: "font-code text-field leading-normal"
|
|
31
|
+
};
|
|
32
|
+
var TONE_CLASSES = {
|
|
33
|
+
default: "text-fg",
|
|
34
|
+
muted: "text-fg-muted",
|
|
35
|
+
subtle: "text-fg-subtle",
|
|
36
|
+
accent: "text-accent",
|
|
37
|
+
"on-accent": "text-on-accent",
|
|
38
|
+
success: "text-success",
|
|
39
|
+
warning: "text-warning",
|
|
40
|
+
info: "text-info",
|
|
41
|
+
danger: "text-danger"
|
|
42
|
+
};
|
|
43
|
+
var WEIGHT_CLASSES = {
|
|
44
|
+
regular: "font-normal",
|
|
45
|
+
medium: "font-medium",
|
|
46
|
+
semibold: "font-semibold",
|
|
47
|
+
bold: "font-bold"
|
|
48
|
+
};
|
|
49
|
+
var ALIGN_CLASSES = {
|
|
50
|
+
start: "text-start",
|
|
51
|
+
center: "text-center",
|
|
52
|
+
end: "text-end"
|
|
53
|
+
};
|
|
54
|
+
var ICON_CLASSES = "inline-flex shrink-0 items-center [&>svg]:h-[1em] [&>svg]:w-[1em]";
|
|
55
|
+
function typographyClassName({
|
|
56
|
+
variant,
|
|
57
|
+
tone,
|
|
58
|
+
weight,
|
|
59
|
+
align,
|
|
60
|
+
truncate,
|
|
61
|
+
hasIcon,
|
|
62
|
+
className
|
|
63
|
+
}) {
|
|
64
|
+
return [
|
|
65
|
+
VARIANT_CLASSES[variant],
|
|
66
|
+
TONE_CLASSES[tone],
|
|
67
|
+
WEIGHT_CLASSES[weight],
|
|
68
|
+
align ? ALIGN_CLASSES[align] : "",
|
|
69
|
+
hasIcon ? "inline-flex items-center gap-1.5" : "",
|
|
70
|
+
// With an icon the root is a flex container, and text-overflow only
|
|
71
|
+
// clips block text, so the text span carries the truncation instead.
|
|
72
|
+
truncate && !hasIcon ? "truncate" : "",
|
|
73
|
+
className ?? ""
|
|
74
|
+
].filter(Boolean).join(" ");
|
|
75
|
+
}
|
|
76
|
+
function Typography({
|
|
77
|
+
variant = "body",
|
|
78
|
+
tone = "default",
|
|
79
|
+
weight,
|
|
80
|
+
align,
|
|
81
|
+
truncate = false,
|
|
82
|
+
icon,
|
|
83
|
+
iconPosition = "leading",
|
|
84
|
+
as,
|
|
85
|
+
asChild = false,
|
|
86
|
+
className,
|
|
87
|
+
children,
|
|
88
|
+
...rest
|
|
89
|
+
}) {
|
|
90
|
+
const hasIcon = icon !== void 0 && icon !== null;
|
|
91
|
+
const Component = asChild ? Slot : as ?? DEFAULT_ELEMENT[variant];
|
|
92
|
+
const iconNode = hasIcon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: ICON_CLASSES, children: icon }) : null;
|
|
93
|
+
const content = hasIcon ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
94
|
+
iconPosition === "leading" ? iconNode : null,
|
|
95
|
+
/* @__PURE__ */ jsx("span", { className: truncate ? "min-w-0 truncate" : void 0, children }),
|
|
96
|
+
iconPosition === "trailing" ? iconNode : null
|
|
97
|
+
] }) : children;
|
|
98
|
+
return /* @__PURE__ */ jsx(
|
|
99
|
+
Component,
|
|
100
|
+
{
|
|
101
|
+
...rest,
|
|
102
|
+
className: typographyClassName({
|
|
103
|
+
variant,
|
|
104
|
+
tone,
|
|
105
|
+
weight: weight ?? DEFAULT_WEIGHT[variant],
|
|
106
|
+
align,
|
|
107
|
+
truncate,
|
|
108
|
+
hasIcon,
|
|
109
|
+
className
|
|
110
|
+
}),
|
|
111
|
+
children: content
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { Typography };
|
|
117
|
+
//# sourceMappingURL=chunk-NZHHNVXZ.js.map
|
|
118
|
+
//# sourceMappingURL=chunk-NZHHNVXZ.js.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,MAAA,EAAO,SAAA,EAAW,YAAA,EACjC,QAAA,EAAA,IAAA,EACH,CAAA,GACE,IAAA;AAEJ,EAAA,MAAM,OAAA,GAAU,0BACd,IAAA,CAAA,QAAA,EAAA,EACG,QAAA,EAAA;AAAA,IAAA,YAAA,KAAiB,YAAY,QAAA,GAAW,IAAA;AAAA,wBACxC,MAAA,EAAA,EAAK,SAAA,EAAW,QAAA,GAAW,kBAAA,GAAqB,QAC9C,QAAA,EACH,CAAA;AAAA,IACC,YAAA,KAAiB,aAAa,QAAA,GAAW;AAAA,GAAA,EAC5C,CAAA,GAEA,QAAA;AAGF,EAAA,uBACE,GAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACE,GAAG,IAAA;AAAA,MACJ,WAAW,mBAAA,CAAoB;AAAA,QAC7B,OAAA;AAAA,QACA,IAAA;AAAA,QACA,MAAA,EAAQ,MAAA,IAAU,cAAA,CAAe,OAAO,CAAA;AAAA,QACxC,KAAA;AAAA,QACA,QAAA;AAAA,QACA,OAAA;AAAA,QACA;AAAA,OACD,CAAA;AAAA,MAEA,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"chunk-NZHHNVXZ.js","sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ElementType, HTMLAttributes, ReactNode, Ref } from \"react\";\n\n/**\n * The library's type scale. Everything that renders text — field labels, hints,\n * form errors, headings — goes through here, so a size or colour lives in one\n * place and the tokens in `src/styles/index.css` stay the single source of\n * truth for what \"hint\" or \"muted\" means.\n *\n * Server-safe: no state, no handlers, no directive. It composes Radix `Slot`\n * for `asChild`, which is how a consumer puts these styles on their own\n * element (a `next/link`, a Radix `Label`) without an extra wrapper.\n */\n\nexport type TypographyVariant =\n | \"display\"\n | \"heading\"\n | \"subheading\"\n | \"body\"\n | \"label\"\n | \"hint\"\n | \"code\";\n\nexport type TypographyTone =\n | \"default\"\n | \"muted\"\n | \"subtle\"\n | \"accent\"\n | \"on-accent\"\n | \"success\"\n | \"warning\"\n | \"info\"\n | \"danger\";\n\nexport type TypographyWeight = \"regular\" | \"medium\" | \"semibold\" | \"bold\";\n\nexport type TypographyElement =\n | \"p\"\n | \"span\"\n | \"div\"\n | \"h1\"\n | \"h2\"\n | \"h3\"\n | \"h4\"\n | \"h5\"\n | \"h6\"\n | \"label\"\n | \"code\"\n | \"strong\"\n | \"em\"\n | \"small\";\n\nexport type TypographyProps = Omit<HTMLAttributes<HTMLElement>, \"color\"> & {\n /** Size and default element. `body` unless told otherwise. */\n variant?: TypographyVariant;\n /** Colour role, from the design tokens. */\n tone?: TypographyTone;\n /** Overrides the variant's default weight. */\n weight?: TypographyWeight;\n align?: \"start\" | \"center\" | \"end\";\n /** Clip to one line with an ellipsis. */\n truncate?: boolean;\n /**\n * An icon rendered beside the text, hidden from assistive tech. Sized to the\n * text with `1em`, so the same SVG fits every variant.\n */\n icon?: ReactNode;\n iconPosition?: \"leading\" | \"trailing\";\n /** The element to render. Defaults per variant (`h2` for a heading, and so on). */\n as?: TypographyElement;\n /**\n * Radix-style composition: render the child element itself, with these\n * styles merged onto it, instead of a wrapper. Takes precedence over `as`.\n */\n asChild?: boolean;\n ref?: Ref<HTMLElement>;\n children?: ReactNode;\n};\n\nconst DEFAULT_ELEMENT: Record<TypographyVariant, TypographyElement> = {\n display: \"h1\",\n heading: \"h2\",\n subheading: \"h3\",\n body: \"p\",\n label: \"span\",\n hint: \"p\",\n code: \"code\",\n};\n\nconst DEFAULT_WEIGHT: Record<TypographyVariant, TypographyWeight> = {\n display: \"semibold\",\n heading: \"semibold\",\n subheading: \"medium\",\n body: \"regular\",\n label: \"semibold\",\n hint: \"regular\",\n code: \"regular\",\n};\n\nconst VARIANT_CLASSES: Record<TypographyVariant, string> = {\n display: \"text-display leading-tight tracking-tight\",\n heading: \"text-heading leading-tight tracking-tight\",\n subheading: \"text-subheading leading-snug\",\n body: \"text-field leading-normal\",\n label: \"text-label leading-normal\",\n hint: \"text-hint leading-normal\",\n code: \"font-code text-field leading-normal\",\n};\n\nconst TONE_CLASSES: Record<TypographyTone, string> = {\n default: \"text-fg\",\n muted: \"text-fg-muted\",\n subtle: \"text-fg-subtle\",\n accent: \"text-accent\",\n \"on-accent\": \"text-on-accent\",\n success: \"text-success\",\n warning: \"text-warning\",\n info: \"text-info\",\n danger: \"text-danger\",\n};\n\nconst WEIGHT_CLASSES: Record<TypographyWeight, string> = {\n regular: \"font-normal\",\n medium: \"font-medium\",\n semibold: \"font-semibold\",\n bold: \"font-bold\",\n};\n\nconst ALIGN_CLASSES = {\n start: \"text-start\",\n center: \"text-center\",\n end: \"text-end\",\n} as const;\n\nconst ICON_CLASSES =\n \"inline-flex shrink-0 items-center [&>svg]:h-[1em] [&>svg]:w-[1em]\";\n\nfunction typographyClassName({\n variant,\n tone,\n weight,\n align,\n truncate,\n hasIcon,\n className,\n}: {\n variant: TypographyVariant;\n tone: TypographyTone;\n weight: TypographyWeight;\n align: \"start\" | \"center\" | \"end\" | undefined;\n truncate: boolean;\n hasIcon: boolean;\n className: string | undefined;\n}): string {\n return [\n VARIANT_CLASSES[variant],\n TONE_CLASSES[tone],\n WEIGHT_CLASSES[weight],\n align ? ALIGN_CLASSES[align] : \"\",\n hasIcon ? \"inline-flex items-center gap-1.5\" : \"\",\n // With an icon the root is a flex container, and text-overflow only\n // clips block text, so the text span carries the truncation instead.\n truncate && !hasIcon ? \"truncate\" : \"\",\n className ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n}\n\nexport function Typography({\n variant = \"body\",\n tone = \"default\",\n weight,\n align,\n truncate = false,\n icon,\n iconPosition = \"leading\",\n as,\n asChild = false,\n className,\n children,\n ...rest\n}: TypographyProps) {\n const hasIcon = icon !== undefined && icon !== null;\n // Widened to `ElementType`: the union of intrinsic tags would otherwise\n // demand a `ref` typed to one specific element.\n const Component: ElementType = asChild\n ? Slot\n : (as ?? DEFAULT_ELEMENT[variant]);\n\n const iconNode = hasIcon ? (\n <span aria-hidden=\"true\" className={ICON_CLASSES}>\n {icon}\n </span>\n ) : null;\n\n const content = hasIcon ? (\n <>\n {iconPosition === \"leading\" ? iconNode : null}\n <span className={truncate ? \"min-w-0 truncate\" : undefined}>\n {children}\n </span>\n {iconPosition === \"trailing\" ? iconNode : null}\n </>\n ) : (\n children\n );\n\n return (\n <Component\n {...rest}\n className={typographyClassName({\n variant,\n tone,\n weight: weight ?? DEFAULT_WEIGHT[variant],\n align,\n truncate,\n hasIcon,\n className,\n })}\n >\n {content}\n </Component>\n );\n}\n"]}
|