@42-central/ui-react 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/biome/no-gray-color.grit +18 -0
- package/dist/{chunk-6I4R3HR6.js → chunk-RQL7FVCS.js} +3 -3
- package/dist/{chunk-6I4R3HR6.js.map → chunk-RQL7FVCS.js.map} +1 -1
- package/dist/{chunk-JBVFWSRQ.js → chunk-VIYVN4WF.js} +6 -4
- package/dist/chunk-VIYVN4WF.js.map +1 -0
- package/dist/{chunk-S53FHWNG.js → chunk-YWRBG23W.js} +3 -3
- package/dist/chunk-YWRBG23W.js.map +1 -0
- package/dist/colors.css +12 -26
- package/dist/components/avatar/avatar.d.ts +3 -3
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/chart/chart.d.ts +1 -1
- package/dist/components/chart/index.js +1 -1
- package/dist/components/chart/index.js.map +1 -1
- package/dist/components/code/index.js +1 -1
- package/dist/components/data-table/data-table-stack.d.ts +2 -2
- package/dist/components/data-table/data-table-stack.d.ts.map +1 -1
- package/dist/components/data-table/data-table.d.ts.map +1 -1
- package/dist/components/data-table/index.js +45 -6
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/kbd/index.js +29 -14
- package/dist/components/kbd/index.js.map +1 -1
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/mark/index.js +1 -1
- package/dist/components/mark/mark.d.ts +2 -2
- package/dist/components/schedule/index.js +2 -1
- package/dist/components/schedule/index.js.map +1 -1
- package/dist/components/schedule/now-cursor-line.d.ts.map +1 -1
- package/dist/components/schedule/schedule-types.d.ts +1 -1
- package/dist/components/switch/index.js +1 -1
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/switch.d.ts +2 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/theme-icon/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/colors.d.ts +1 -1
- package/dist/lib/colors.d.ts.map +1 -1
- package/dist/theme.css +0 -33
- package/package.json +2 -1
- package/src/biome-plugins.test.ts +61 -0
- package/src/colors.css +12 -26
- package/src/components/avatar/avatar.tsx +3 -3
- package/src/components/chart/chart.test.tsx +1 -2
- package/src/components/chart/chart.tsx +1 -1
- package/src/components/code-block/gutters.test.ts +2 -2
- package/src/components/data-table/data-table-stack.tsx +5 -3
- package/src/components/data-table/data-table.test.tsx +91 -0
- package/src/components/data-table/data-table.tsx +55 -6
- package/src/components/kbd/kbd.test.tsx +31 -0
- package/src/components/kbd/kbd.tsx +29 -14
- package/src/components/mark/mark.test.tsx +4 -4
- package/src/components/mark/mark.tsx +3 -3
- package/src/components/schedule/now-cursor-line.test.tsx +19 -0
- package/src/components/schedule/now-cursor-line.tsx +10 -1
- package/src/components/schedule/schedule-types.ts +1 -1
- package/src/components/switch/switch.test.tsx +12 -0
- package/src/components/switch/switch.tsx +3 -1
- package/src/components/theme-icon/theme-icon.tsx +1 -1
- package/src/lib/colors.ts +4 -2
- package/src/theme.css +0 -33
- package/dist/chunk-JBVFWSRQ.js.map +0 -1
- package/dist/chunk-S53FHWNG.js.map +0 -1
|
@@ -36,9 +36,17 @@ const kbdVariants = cva(
|
|
|
36
36
|
[
|
|
37
37
|
"inline-flex items-center justify-center gap-1",
|
|
38
38
|
"whitespace-nowrap select-none",
|
|
39
|
-
|
|
39
|
+
// Regular weight, not medium: the mono face (Kode Mono) has no ⌘ ⇧ ⌥ ↵
|
|
40
|
+
// glyphs, so they fall back to a system font — and a 500 weight makes that
|
|
41
|
+
// fallback resolve to its *bold* face (Menlo Bold), a heavy blot next to
|
|
42
|
+
// the regular letters around it.
|
|
43
|
+
"font-mono font-normal leading-none",
|
|
40
44
|
"rounded-md border border-transparent",
|
|
41
45
|
"[&_svg]:shrink-0 [&_svg]:pointer-events-none",
|
|
46
|
+
// A 1.5px stroke at every size: the icon is sized by CSS, so a stroke in
|
|
47
|
+
// viewBox units would thin out at `size-3`. `non-scaling-stroke` keeps it in
|
|
48
|
+
// screen pixels (lucide's `absoluteStrokeWidth` ignores CSS sizing).
|
|
49
|
+
"[&_svg]:stroke-[1.5] [&_svg_*]:[vector-effect:non-scaling-stroke]",
|
|
42
50
|
// Inert on the default non-focusable <kbd>; applies once `asChild`
|
|
43
51
|
// renders Kbd onto a real <button>/<a>. See `focusStyles`.
|
|
44
52
|
focusStyles(),
|
|
@@ -50,23 +58,30 @@ const kbdVariants = cva(
|
|
|
50
58
|
light: "bg-(--c-soft) text-(--c-text)",
|
|
51
59
|
outline: "bg-transparent text-(--c-text) border-(--c-solid)",
|
|
52
60
|
subtle: "bg-transparent text-(--c-text)",
|
|
53
|
-
// The key cap sits on the kit's translucent surface recipe —
|
|
54
|
-
// plus the hairline `border-brand-900/20 dark:border-white/15`,
|
|
55
|
-
// pair `Input`'s default shell, `Card`, `Tabs
|
|
56
|
-
// `ChoiceCardGroup` use. An opaque gray step can only ever be right on
|
|
57
|
-
// one background it was picked against, and a `Kbd` is most often
|
|
58
|
-
// into a Button, a Menu row or a tinted panel
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
+
// The key cap sits on the kit's translucent surface recipe — a 3%/4%
|
|
62
|
+
// overlay plus the hairline `border-brand-900/20 dark:border-white/15`,
|
|
63
|
+
// the same pair `Input`'s default shell, `Card`, `Tabs` and
|
|
64
|
+
// `ChoiceCardGroup` use. An opaque gray step can only ever be right on
|
|
65
|
+
// the one background it was picked against, and a `Kbd` is most often
|
|
66
|
+
// inlined into a Button, a Menu row or a tinted panel. Light mode
|
|
67
|
+
// darkens (`bg-black/3`) because `bg-white/4` on a near-white page is
|
|
68
|
+
// invisible; dark mode lightens. A 1px inset shade along the bottom
|
|
69
|
+
// edge is the key-cap depth cue — the lip of a physical key — without
|
|
70
|
+
// adding height. The label is the kit's secondary text, not full
|
|
71
|
+
// contrast: a shortcut hint annotates the action, it is not the action.
|
|
61
72
|
default: [
|
|
62
|
-
"bg-
|
|
63
|
-
"
|
|
73
|
+
"bg-black/3 text-gray-light-700 border-brand-900/20",
|
|
74
|
+
"shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.08)]",
|
|
75
|
+
"dark:bg-white/4 dark:text-gray-dark-300 dark:border-white/15",
|
|
76
|
+
"dark:shadow-[inset_0_-1px_0_0_rgb(0_0_0/0.35)]",
|
|
64
77
|
],
|
|
65
78
|
},
|
|
79
|
+
// Type is one Tailwind step per size (12 / 14 / 16px), the scale of
|
|
80
|
+
// the text a key sits beside — a 10px label left ⌘ and ↵ unreadable.
|
|
66
81
|
size: {
|
|
67
|
-
sm: "h-5 min-w-5 px-1.5 text-
|
|
68
|
-
md: "h-6 min-w-6 px-1.5 text-
|
|
69
|
-
lg: "h-7 min-w-7 px-2 text-
|
|
82
|
+
sm: "h-5 min-w-5 px-1.5 text-xs [&_svg]:size-3",
|
|
83
|
+
md: "h-6 min-w-6 px-1.5 text-sm [&_svg]:size-3.5",
|
|
84
|
+
lg: "h-7 min-w-7 px-2 text-base [&_svg]:size-4",
|
|
70
85
|
},
|
|
71
86
|
},
|
|
72
87
|
defaultVariants: {
|
|
@@ -17,12 +17,12 @@ describe("Mark", () => {
|
|
|
17
17
|
expect(screen.getByTestId("note")).toBeTruthy()
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
it("defaults background to yellow and text to neutral
|
|
20
|
+
it("defaults background to yellow and text to neutral when neither is set", () => {
|
|
21
21
|
const { container } = render(<Mark>hi</Mark>)
|
|
22
22
|
const root = container.firstElementChild as HTMLElement
|
|
23
23
|
const inner = root.firstElementChild as HTMLElement
|
|
24
24
|
expect(root.getAttribute("data-color")).toBe("yellow")
|
|
25
|
-
expect(inner.getAttribute("data-color")).toBe("
|
|
25
|
+
expect(inner.getAttribute("data-color")).toBe("neutral")
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
it("the inner span always contains text-(--c-text), unconditionally", () => {
|
|
@@ -68,12 +68,12 @@ describe("Mark", () => {
|
|
|
68
68
|
expect(root.className).toContain("bg-transparent")
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
it("background alone tints only the highlight — text stays neutral
|
|
71
|
+
it("background alone tints only the highlight — text stays neutral, not matching background", () => {
|
|
72
72
|
const { container } = render(<Mark background="red">hi</Mark>)
|
|
73
73
|
const root = container.firstElementChild as HTMLElement
|
|
74
74
|
const inner = root.firstElementChild as HTMLElement
|
|
75
75
|
expect(root.getAttribute("data-color")).toBe("red")
|
|
76
|
-
expect(inner.getAttribute("data-color")).toBe("
|
|
76
|
+
expect(inner.getAttribute("data-color")).toBe("neutral")
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
it("root className carries the translucent soft background, never a text color", () => {
|
|
@@ -10,7 +10,7 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
10
10
|
* `background` and `color` are fully independent — `background` only ever
|
|
11
11
|
* changes the highlight, `color` only ever changes the text, neither leaks
|
|
12
12
|
* into the other: `background` alone (no `color`) tints the highlight with
|
|
13
|
-
* *neutral*
|
|
13
|
+
* *neutral* text, not text matching the highlight; `color` alone (no
|
|
14
14
|
* `background`) renders as tinted text with no highlight at all —
|
|
15
15
|
* `background` only defaults to `"yellow"` when it's unset, regardless of
|
|
16
16
|
* `color`. This needs two DOM nodes rather than one: `--c-soft`/`--c-text`
|
|
@@ -41,7 +41,7 @@ export type MarkProps = ComponentPropsWithoutRef<"mark"> &
|
|
|
41
41
|
WithTestId & {
|
|
42
42
|
/**
|
|
43
43
|
* Text color. Independent of `background` — never falls back to it.
|
|
44
|
-
* @default "
|
|
44
|
+
* @default "neutral"
|
|
45
45
|
*/
|
|
46
46
|
color?: Color
|
|
47
47
|
/**
|
|
@@ -71,7 +71,7 @@ export const Mark = ({ className, color, background, children, testId, ...rest }
|
|
|
71
71
|
className,
|
|
72
72
|
)}
|
|
73
73
|
>
|
|
74
|
-
<span data-color={color ?? "
|
|
74
|
+
<span data-color={color ?? "neutral"} className="text-(--c-text)">
|
|
75
75
|
{children}
|
|
76
76
|
</span>
|
|
77
77
|
</mark>
|
|
@@ -183,6 +183,25 @@ describe("NowCursorLine — the painted window gates it", () => {
|
|
|
183
183
|
})
|
|
184
184
|
})
|
|
185
185
|
|
|
186
|
+
describe("NowCursorLabel — stays inside the band", () => {
|
|
187
|
+
// Centered on the line, a label at the very top or bottom used to stick
|
|
188
|
+
// half its height out of the grid, and the whole view scrolled a few px.
|
|
189
|
+
it("clamps its position to half its own height inside both edges", () => {
|
|
190
|
+
const { container } = render(
|
|
191
|
+
<NowCursorLabel now={new Date(2026, 0, 1, 17, 57)} startHour={8} endHour={18} />,
|
|
192
|
+
)
|
|
193
|
+
const label = container.querySelector('[data-schedule-part="now-indicator-label"]')
|
|
194
|
+
const top = (label as HTMLElement).style.top
|
|
195
|
+
// A clamp whose preferred value is still the line's exact position...
|
|
196
|
+
expect(top).toMatch(/^clamp\(/)
|
|
197
|
+
expect(top).toContain(`${((9 * 60 + 57) / 600) * 100}%`)
|
|
198
|
+
// ...bounded by the label's half-height, from 100% at the bottom edge.
|
|
199
|
+
// (jsdom normalizes the calc, so match its parts, not one spelling.)
|
|
200
|
+
expect(top).toContain("1em + 0.25rem")
|
|
201
|
+
expect(top).toContain("100%")
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
186
205
|
describe("NowCursorLabel — the painted window gates it too", () => {
|
|
187
206
|
it("renders its clock text inside the window", () => {
|
|
188
207
|
render(<NowCursorLabel now={INSIDE} {...WINDOW} />)
|
|
@@ -119,6 +119,9 @@ export function NowCursorLine({
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/** Half of `NowCursorLabel`'s own height: `leading-none` (1em) plus `py-0.5`. */
|
|
123
|
+
const HALF_LABEL = "calc((1em + 0.25rem) / 2)"
|
|
124
|
+
|
|
122
125
|
/**
|
|
123
126
|
* The now-cursor's presence in the hour gutter — a leaf on its own, same
|
|
124
127
|
* isolation reasoning as `NowCursorLine` above (a per-minute tick only
|
|
@@ -231,7 +234,13 @@ export function NowCursorLabel({
|
|
|
231
234
|
"[--sch-now-line-color:var(--color-red-500)]",
|
|
232
235
|
className,
|
|
233
236
|
)}
|
|
234
|
-
|
|
237
|
+
// Centered on the line, but never past the band's own edges: near the
|
|
238
|
+
// top or bottom it stops half its height inside, so it can't stick
|
|
239
|
+
// out of the grid (which made the whole view scroll by a few px for
|
|
240
|
+
// the minutes around `startHour`/`endHour`). Only the label nudges;
|
|
241
|
+
// the line stays exact. Half its height is derived from its own box:
|
|
242
|
+
// a 1em line (`leading-none`) plus `py-0.5` (0.125rem top and bottom).
|
|
243
|
+
style={{ top: `clamp(${HALF_LABEL}, ${top}%, calc(100% - ${HALF_LABEL}))` }}
|
|
235
244
|
>
|
|
236
245
|
{clockTimeLabel(current, locale)}
|
|
237
246
|
</span>
|
|
@@ -6,7 +6,7 @@ import type { ScheduleSlotPredicate } from "../../lib/schedule-predicates"
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A closed subset of the kit's full palette (`lib/colors.ts`), not the
|
|
9
|
-
* shared `Color` type: `brand` and `
|
|
9
|
+
* shared `Color` type: `brand` and `neutral` are excluded (reserved for chrome),
|
|
10
10
|
* and there's no custom-string escape hatch — every allowed value's
|
|
11
11
|
* `--c-text`/`--c-soft` pairing has been checked against a white/near-black
|
|
12
12
|
* grid background, a guarantee an arbitrary custom color couldn't make.
|
|
@@ -73,6 +73,18 @@ describe("Switch", () => {
|
|
|
73
73
|
expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["SPAN", "SPAN", "INPUT"])
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
// Neutral's solid is white in dark mode, the same white as the thumb, so a
|
|
77
|
+
// checked neutral switch would be white on white. It fills green instead.
|
|
78
|
+
it('fills green for `color="neutral"`', () => {
|
|
79
|
+
render(<Switch label="Airplane mode" color="neutral" testId="airplane-mode" />)
|
|
80
|
+
expect(screen.getByTestId("airplane-mode").getAttribute("data-color")).toBe("green")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("keeps every other color as given", () => {
|
|
84
|
+
render(<Switch label="Airplane mode" color="red" testId="airplane-mode" />)
|
|
85
|
+
expect(screen.getByTestId("airplane-mode").getAttribute("data-color")).toBe("red")
|
|
86
|
+
})
|
|
87
|
+
|
|
76
88
|
it("renders testId as data-testid on the root label, not the hidden input", () => {
|
|
77
89
|
render(<Switch label="Airplane mode" testId="airplane-mode" />)
|
|
78
90
|
const el = screen.getByTestId("airplane-mode")
|
|
@@ -107,6 +107,8 @@ export type SwitchProps = WithTestId & {
|
|
|
107
107
|
/** Keeps full contrast but blocks edits. */
|
|
108
108
|
readOnly?: boolean
|
|
109
109
|
size?: Size
|
|
110
|
+
/** Checked fill. `neutral` is the one exception: it fills green, since
|
|
111
|
+
* neutral's solid is the same white as the thumb on a dark page. */
|
|
110
112
|
color?: Color
|
|
111
113
|
/** Field name for native form submission. */
|
|
112
114
|
name?: string
|
|
@@ -195,7 +197,7 @@ export const Switch = ({
|
|
|
195
197
|
name={name}
|
|
196
198
|
value={value}
|
|
197
199
|
id={id}
|
|
198
|
-
data-color={color}
|
|
200
|
+
data-color={color === "neutral" ? "green" : color}
|
|
199
201
|
{...props({ "data-testid": testId })}
|
|
200
202
|
// `relative` contains the absolutely positioned hidden input, which would
|
|
201
203
|
// otherwise escape any scroller this control sits in.
|
|
@@ -38,7 +38,7 @@ const themeIconVariants = cva(
|
|
|
38
38
|
// fill blends with whatever surface it sits on instead of reading
|
|
39
39
|
// as a painted CTA block. The border mixes in black on top of that
|
|
40
40
|
// same var — a fixed darkening, not another opacity step of it —
|
|
41
|
-
// so it reads as a recessed edge in both themes; some colors (
|
|
41
|
+
// so it reads as a recessed edge in both themes; some colors (neutral
|
|
42
42
|
// in particular) have a dark-mode `--c-solid` that's lighter than
|
|
43
43
|
// its own soft/text steps, which would flip a same-var-opacity
|
|
44
44
|
// border the wrong way. This is the ThemeIcon-specific reading of
|
package/src/lib/colors.ts
CHANGED
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export const COLORS = [
|
|
13
13
|
"brand",
|
|
14
|
-
"gray",
|
|
15
14
|
// Composed from existing white/gray/brand-950 tokens rather than its own
|
|
16
|
-
// scale — the literal white/dark-navy button from the 42 UI Kit Figma
|
|
15
|
+
// scale — the literal white/dark-navy button from the 42 UI Kit Figma
|
|
16
|
+
// (where it is still labelled "gray" on Button). The former mid-gray `gray`
|
|
17
|
+
// palette was cut in its favor; `data-color="gray"` survives only as a
|
|
18
|
+
// deprecated CSS alias of this one (see colors.css).
|
|
17
19
|
"neutral",
|
|
18
20
|
"red",
|
|
19
21
|
"orange",
|
package/src/theme.css
CHANGED
|
@@ -48,34 +48,6 @@
|
|
|
48
48
|
--color-gray-dark-900: #13161b;
|
|
49
49
|
--color-gray-dark-950: #0c0e12;
|
|
50
50
|
|
|
51
|
-
/* Gray Modern */
|
|
52
|
-
--color-gray-modern-25: #fcfcfd;
|
|
53
|
-
--color-gray-modern-50: #f8fafc;
|
|
54
|
-
--color-gray-modern-100: #eef2f6;
|
|
55
|
-
--color-gray-modern-200: #e3e8ef;
|
|
56
|
-
--color-gray-modern-300: #cdd5df;
|
|
57
|
-
--color-gray-modern-400: #9aa4b2;
|
|
58
|
-
--color-gray-modern-500: #697586;
|
|
59
|
-
--color-gray-modern-600: #4b5565;
|
|
60
|
-
--color-gray-modern-700: #364152;
|
|
61
|
-
--color-gray-modern-800: #202939;
|
|
62
|
-
--color-gray-modern-900: #121926;
|
|
63
|
-
--color-gray-modern-950: #0d121c;
|
|
64
|
-
|
|
65
|
-
/* Gray Blue */
|
|
66
|
-
--color-gray-blue-25: #fcfcfd;
|
|
67
|
-
--color-gray-blue-50: #f8f9fc;
|
|
68
|
-
--color-gray-blue-100: #eaecf5;
|
|
69
|
-
--color-gray-blue-200: #d5d9eb;
|
|
70
|
-
--color-gray-blue-300: #b3b8db;
|
|
71
|
-
--color-gray-blue-400: #717bbc;
|
|
72
|
-
--color-gray-blue-500: #4e5ba6;
|
|
73
|
-
--color-gray-blue-600: #3e4784;
|
|
74
|
-
--color-gray-blue-700: #363f72;
|
|
75
|
-
--color-gray-blue-800: #293056;
|
|
76
|
-
--color-gray-blue-900: #101323;
|
|
77
|
-
--color-gray-blue-950: #0d0f1c;
|
|
78
|
-
|
|
79
51
|
/* Gray True */
|
|
80
52
|
--color-gray-true-25: #fcfcfc;
|
|
81
53
|
--color-gray-true-50: #f7f7f7;
|
|
@@ -1274,8 +1246,3 @@ body {
|
|
|
1274
1246
|
|
|
1275
1247
|
/* Variants to use with slider's values */
|
|
1276
1248
|
@custom-variant state-under-or-at (&:is([data-state="under-value"], [data-state="at-value"]));
|
|
1277
|
-
|
|
1278
|
-
*,
|
|
1279
|
-
:root {
|
|
1280
|
-
@apply scrollbar-thumb-gray-300/60 hover:scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-500/60 dark:hover:scrollbar-thumb-gray-500 scrollbar-track-transparent;
|
|
1281
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/colors.ts"],"names":[],"mappings":";AAWO,IAAM,MAAA,GAAS;AAAA,EACpB,OAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA,EAGA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF","file":"chunk-JBVFWSRQ.js","sourcesContent":["/**\n * Single source of truth for the `color` prop accepted by colored components\n * (Button, ActionIcon, Slider, …). The const array drives both the type and\n * any runtime iteration (docs swatches, story controls).\n *\n * Adding a new color is a three-step change:\n * 1. Append the name here.\n * 2. Define its `--color-<name>-{25..950}` scale in `theme.css`.\n * 3. Add a `[data-color=\"<name>\"]` block in `colors.css` with the slot vars\n * (and a dark-mode override if the shade should shift).\n */\nexport const COLORS = [\n \"brand\",\n \"gray\",\n // Composed from existing white/gray/brand-950 tokens rather than its own\n // scale — the literal white/dark-navy button from the 42 UI Kit Figma.\n \"neutral\",\n \"red\",\n \"orange\",\n \"yellow\",\n \"green\",\n \"teal\",\n \"cyan\",\n \"blue\",\n \"purple\",\n \"pink\",\n] as const\n\n// Extend the type to allow custom color strings (e.g. `color=\"custom\"`)\n// but still allow complete type safety for the predefined colors\nexport type Color = (typeof COLORS)[number] | (string & {})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/mark/mark.tsx"],"names":[],"mappings":";;;;AAqDO,IAAM,IAAA,GAAO,CAAC,EAAE,SAAA,EAAW,KAAA,EAAO,YAAY,QAAA,EAAU,MAAA,EAAQ,GAAG,IAAA,EAAK,KAAiB;AAG9F,EAAA,MAAM,cAAA,GAAiB,UAAA,KAAe,MAAA,IAAa,KAAA,KAAU,MAAA;AAC7D,EAAA,MAAM,KAAK,UAAA,IAAc,QAAA;AACzB,EAAA,uBACE,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,YAAA,EAAY,iBAAiB,EAAA,GAAK,MAAA;AAAA,MACjC,GAAG,KAAA,CAAM,EAAE,aAAA,EAAe,QAAQ,CAAA;AAAA,MAClC,GAAG,IAAA;AAAA,MACJ,SAAA,EAAW,EAAA;AAAA,QACT,YAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAKA,iBAAiB,+BAAA,GAAkC,gBAAA;AAAA,QACnD;AAAA,OACF;AAAA,MAEA,8BAAC,MAAA,EAAA,EAAK,YAAA,EAAY,SAAS,MAAA,EAAQ,SAAA,EAAU,mBAC1C,QAAA,EACH;AAAA;AAAA,GACF;AAEJ","file":"chunk-S53FHWNG.js","sourcesContent":["import type { ComponentPropsWithoutRef } from \"react\"\nimport { cn } from \"../../lib/cn\"\nimport type { Color } from \"../../lib/colors\"\nimport { props } from \"../../lib/props\"\nimport type { WithTestId } from \"../../lib/test-id\"\n\n/**\n * Mark — an inline `<mark>` highlighter. Pure React Server Component.\n *\n * `background` and `color` are fully independent — `background` only ever\n * changes the highlight, `color` only ever changes the text, neither leaks\n * into the other: `background` alone (no `color`) tints the highlight with\n * *neutral* (\"gray\") text, not text matching the highlight; `color` alone (no\n * `background`) renders as tinted text with no highlight at all —\n * `background` only defaults to `\"yellow\"` when it's unset, regardless of\n * `color`. This needs two DOM nodes rather than one: `--c-soft`/`--c-text`\n * are both defined together inside the same `[data-color=\"X\"]` block in\n * `colors.css`, so a single `data-color` attribute can only ever scope one\n * color's worth of both vars at once. Letting background and text pick\n * *different* color names — and stay theme-aware, the whole reason\n * `--c-soft`/`--c-text` exist instead of a fixed shade — means they need two\n * independently-scoped `data-color` attributes. The outer `<mark>` scopes\n * `--c-soft` for the background; the inner `<span>` scopes its own `--c-text`\n * for the text, independent of the outer scope.\n *\n * The inner span's `text-(--c-text)` class is unconditional — never gated\n * behind an `if (color)` branch — so it always declares its own explicit\n * `color`, never inheriting one. That's what makes nesting a colored `<Mark>`\n * inside a colored `<Code>` (or any other colored ancestor) \"just work\": an\n * ancestor's `color` only reaches a descendant by inheritance, the\n * lowest-priority source of a property's value, so the inner span's own\n * declaration always wins, no `!important` or descendant-selector games\n * needed.\n *\n * No `asChild` (plain `ComponentPropsWithoutRef<\"mark\">`, not `HTMLArkProps`):\n * the inner span above already repurposes `children` as \"the highlighted\n * content,\" which collides with `asChild`'s usual meaning (the one child to\n * render as root) — the same reasoning `Skeleton`'s wrap mode uses to skip it.\n */\nexport type MarkProps = ComponentPropsWithoutRef<\"mark\"> &\n WithTestId & {\n /**\n * Text color. Independent of `background` — never falls back to it.\n * @default \"gray\" (neutral)\n */\n color?: Color\n /**\n * Background/highlight tint. Re-exported as `Color` from `@42/ui-react`.\n * @default \"yellow\"\n */\n background?: Color\n }\n\nexport const Mark = ({ className, color, background, children, testId, ...rest }: MarkProps) => {\n // A background only defaults to \"yellow\" when neither prop is given —\n // `color` alone must render as tinted text with no highlight at all.\n const showBackground = background !== undefined || color === undefined\n const bg = background ?? \"yellow\"\n return (\n <mark\n data-color={showBackground ? bg : undefined}\n {...props({ \"data-testid\": testId })}\n {...rest}\n className={cn(\n \"rounded-xs\",\n // Browsers ship a UA-stylesheet default for `<mark>` (a solid yellow\n // background, historically with black text) — an explicit\n // `bg-transparent` is required in the no-background branch, or that\n // default bleeds through instead of \"no highlight at all\".\n showBackground ? \"bg-(--c-soft)/60 px-0.5 py-px\" : \"bg-transparent\",\n className,\n )}\n >\n <span data-color={color ?? \"gray\"} className=\"text-(--c-text)\">\n {children}\n </span>\n </mark>\n )\n}\n"]}
|