@terpjs/react-core 0.21.0 → 0.23.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/src/styles.ts CHANGED
@@ -103,7 +103,7 @@
103
103
  * touched.
104
104
  */
105
105
 
106
- import { WIDE_VIEWPORT_QUERY } from "./breakpoints";
106
+ import { ROOMY_VIEWPORT_QUERY, WIDE_VIEWPORT_QUERY } from "./breakpoints";
107
107
 
108
108
  /** The `<style>` element id used to detect a prior injection. */
109
109
  export const TERP_STYLES_ID = "terp-core-styles";
@@ -564,12 +564,15 @@ textarea[data-terp="input"] {
564
564
  Same for every gap pair. styles.test.ts pins the order, because getting it backwards
565
565
  renders the narrow value at every width and looks like the prop not working.
566
566
 
567
- The query is INTERPOLATED from ./breakpoints, which is the one \${…} in this sheet and is
568
- deliberate rather than a slip: it is the complement of the exact string AppShell and
569
- DataView hand to matchMedia, so the two halves of the cutover partition the viewport by
570
- construction. Written out here they would be two literals that agree until someone edits
571
- one. (The convention of grepping this literal for \${ still holds — there should be
572
- exactly this one.) */
567
+ The query is INTERPOLATED from ./breakpoints, and that is deliberate rather than a slip:
568
+ it is the complement of the exact string AppShell and DataView hand to matchMedia, so the
569
+ two halves of the cutover partition the viewport by construction. Written out here they
570
+ would be two literals that agree until someone edits one.
571
+
572
+ There are TWO \${…} in this sheet now, one per cutover — this one and the page band's
573
+ ROOMY block. Both come from ./breakpoints and neither spells a number, which is the
574
+ property worth grepping for: a third interpolation is fine if it names a constant from
575
+ that module, and a literal pixel width in a media query here is not. */
573
576
  @media ${WIDE_VIEWPORT_QUERY} {
574
577
  [data-terp="stack"][data-direction-wide="column"] { flex-direction: column; }
575
578
  [data-terp="stack"][data-direction-wide="row"] { flex-direction: row; }
@@ -1183,6 +1186,12 @@ textarea[data-terp="input"] {
1183
1186
  font-size: var(--font-size-lg);
1184
1187
  line-height: var(--font-line-height-relaxed);
1185
1188
  }
1189
+ /* Emphasis. Opt-in only: the base rule deliberately sets no font-weight, so a Text that
1190
+ asks for nothing keeps inheriting exactly what it inherited before this axis existed.
1191
+ Stating the default here would be tidier and would re-weight every Text nested in an
1192
+ emphasised container, which is a rendering change dressed as a tidy-up. */
1193
+ [data-terp="text"][data-weight="medium"] { font-weight: var(--font-weight-medium); }
1194
+ [data-terp="text"][data-weight="semibold"] { font-weight: var(--font-weight-semibold); }
1186
1195
  [data-terp="text"][data-tone="muted"] { color: var(--color-fg-muted); }
1187
1196
  [data-terp="text"][data-tone="subtle"] { color: var(--color-fg-subtle); }
1188
1197
  [data-terp="text"][data-measure="narrow"] { max-width: 48ch; }
@@ -1374,15 +1383,39 @@ textarea[data-terp="input"] {
1374
1383
  line-height: var(--font-line-height-snug);
1375
1384
  color: var(--color-neutral-600);
1376
1385
  }
1386
+ /* NOWRAP on both, and the li is the one that matters. A crumb's chevron lives inside the li
1387
+ beside its label, so a wrapping li let a long label push its own separator onto the next
1388
+ line -- where it sat at the start of the row pointing at nothing. The ol follows for the
1389
+ band's sake: the trail is one row of the grid, and a trail that wraps is a row whose height
1390
+ nobody declared.
1391
+
1392
+ What gives instead is the text, below. Every crumb can shrink and ellipsise, so a deep
1393
+ trail degrades by losing characters rather than by growing the chrome. */
1377
1394
  [data-terp="breadcrumbs"] ol,
1378
1395
  [data-terp="breadcrumbs"] li {
1379
1396
  list-style: none;
1380
1397
  margin: 0;
1381
1398
  padding: 0;
1382
1399
  display: flex;
1383
- flex-wrap: wrap;
1400
+ flex-wrap: nowrap;
1384
1401
  align-items: center;
1385
1402
  gap: var(--space-2);
1403
+ min-width: 0;
1404
+ }
1405
+ /* Each crumb's own text: shrinkable, and cut rather than wrapped. The automatic minimum of a
1406
+ flex item is its content's, so min-width: 0 is what admits the other three declarations --
1407
+ the same pairing the lead line makes, one level in. */
1408
+ [data-terp="breadcrumbs"] li > a,
1409
+ [data-terp="breadcrumbs"] li > h1,
1410
+ [data-terp="breadcrumbs"] li > span:not([data-terp="breadcrumbs-separator"]) {
1411
+ min-width: 0;
1412
+ overflow: hidden;
1413
+ white-space: nowrap;
1414
+ text-overflow: ellipsis;
1415
+ }
1416
+ /* The chevron is 0.85em of glyph and never the thing worth losing. */
1417
+ [data-terp="breadcrumbs"] li > [data-terp="breadcrumbs-separator"] {
1418
+ flex: 0 0 auto;
1386
1419
  }
1387
1420
  /* Keyed on our own marker, not on [aria-current="page"]. The trail's ancestor
1388
1421
  crumbs are the app router's links, and TanStack stamps aria-current="page" on
@@ -1975,24 +2008,85 @@ textarea[data-terp="input"] {
1975
2008
  meeting a wide action cluster takes a second line instead of overflowing — and the band
1976
2009
  grows past its floor when it does. */
1977
2010
  [data-terp="page-header"] {
1978
- display: flex;
1979
- flex-wrap: wrap;
2011
+ display: grid;
2012
+ grid-template-columns: minmax(0, 1fr) auto;
2013
+ grid-template-areas: "trail actions";
1980
2014
  align-items: center;
1981
- justify-content: space-between;
1982
2015
  gap: var(--space-2) var(--space-4);
1983
2016
  min-width: 0;
1984
2017
  }
1985
- /* The band's left group: the trail (whose leaf is the h1), then badges, then the lead line.
1986
- flex: 1 1 auto with min-width: 0 is what lets the lead line truncate instead of pushing
1987
- the action cluster off the row. */
2018
+ /* The two-row band, and it costs nothing to the pages that get it. A page with badges or a
2019
+ lead line ALREADY spends a second row on them; putting the action cluster there too fills
2020
+ space that was empty, and it buys the trail the whole of the first row -- which is what
2021
+ stops a deep trail having to truncate at all. A page with neither keeps the single row,
2022
+ and with it the promise the chrome is measured against: the band matches the app header
2023
+ above it.
2024
+
2025
+ A grid rather than the flex-wrap this was: wrap order follows source order, so the meta
2026
+ group and the cluster could not share a row while staying two groups, and the moment the
2027
+ band did wrap justify-content: space-between had free space to distribute -- which
2028
+ spread a page's buttons across the full width, or left-aligned a single cluster on a row
2029
+ whose whole job was to right-align it. Areas say where things go and no free space is
2030
+ distributed anywhere, so neither failure has anywhere to happen. */
2031
+ [data-terp="page-header"][data-has-meta] {
2032
+ grid-template-areas:
2033
+ "trail trail"
2034
+ "meta actions";
2035
+ /* Same-height lines, and 1fr is what spells that in a box whose height nobody declared:
2036
+ with an indefinite container the fr rows resolve to the LARGEST row's content rather
2037
+ than to a share of a height that does not exist, so both rows come out at the taller
2038
+ one. A band of two content-sized rows would otherwise be a short trail line above a
2039
+ tall control line, which reads as two different bands rather than one of two lines. */
2040
+ grid-auto-rows: 1fr;
2041
+ }
2042
+ /* The band's left group, and it generates NO box. The trail and the meta group have to be
2043
+ grid items of the band itself -- they sit on different rows -- but the marker is published
2044
+ and a wrapper that boxed them would put them both in one cell. display: contents is the
2045
+ sheet's existing answer to exactly that shape (see the markdown wrapper): the children
2046
+ stay in flow as the grid's own items, and the marker survives for the scanner and for
2047
+ anything reading the DOM.
2048
+
2049
+ The flex basis this used to carry is gone with the box. What it bought -- a heading that
2050
+ shrinks instead of pushing the cluster off the row -- is now the grid's minmax(0, 1fr)
2051
+ first column, which does the same job by construction rather than by getting a flex
2052
+ hypothetical size right. */
1988
2053
  [data-terp="page-heading"] {
2054
+ display: contents;
2055
+ }
2056
+ /* The trail owns the first row outright once there is a second one to own. */
2057
+ [data-terp="page-header"] > [data-terp="breadcrumbs"] {
2058
+ grid-area: trail;
2059
+ min-width: 0;
2060
+ }
2061
+ /* Badges and the lead line, grouped so they share the second row as one left-hand item
2062
+ rather than competing for cells with the cluster opposite them. */
2063
+ [data-terp="page-meta"] {
2064
+ grid-area: meta;
1989
2065
  display: flex;
1990
2066
  flex-wrap: wrap;
1991
2067
  align-items: center;
1992
2068
  gap: var(--space-2) var(--space-3);
1993
- flex: 1 1 auto;
1994
2069
  min-width: 0;
1995
2070
  }
2071
+ [data-terp="page-header"] > [data-terp="page-actions"] {
2072
+ grid-area: actions;
2073
+ }
2074
+ /* The lead line is desktop-only, and it is written as the correction rather than the rule:
2075
+ hidden at every width, shown again above the SECOND cutover. Mobile-first in the literal
2076
+ sense, and it is what lets the three regions come out of two queries (see ./breakpoints) —
2077
+ the middle region is simply the width at which this correction has not applied yet.
2078
+
2079
+ A sentence about the page is the first thing to go when the band is short of room: the
2080
+ trail says where you are and the cluster says what you can do, and neither has a smaller
2081
+ form that still works. */
2082
+ [data-terp="page-description"] {
2083
+ display: none;
2084
+ }
2085
+ @media ${ROOMY_VIEWPORT_QUERY} {
2086
+ [data-terp="page-description"] {
2087
+ display: block;
2088
+ }
2089
+ }
1996
2090
  /* The single h1 of the view, and now also the trail's current crumb: one node instead of two
1997
2091
  copies of one string. margin: 0 is load-bearing twice over — the browser default h1 margin
1998
2092
  would fight the band's own gap, and an h1 inside the trail's <li> would otherwise break the
@@ -2025,10 +2119,15 @@ textarea[data-terp="input"] {
2025
2119
  }
2026
2120
  /* The lead line: one short sentence about the page, truncated rather than wrapped, because
2027
2121
  the band has a height and prose that wraps would set it. A page whose explanation does not
2028
- fit on one line is describing its body, and that belongs in the body. */
2122
+ fit on one line is describing its body, and that belongs in the body.
2123
+
2124
+ Zero basis for the same reason the heading has one, one level in: nowrap makes this box's
2125
+ max-content the whole unwrapped sentence, so an auto basis breaks the heading's line before
2126
+ any of the three declarations below get a chance to run. The truncation is only reachable
2127
+ from a line the box actually shares. */
2029
2128
  [data-terp="page-description"] {
2030
2129
  margin: 0;
2031
- flex: 1 1 auto;
2130
+ flex: 1 1 0;
2032
2131
  min-width: 0;
2033
2132
  color: var(--color-fg-subtle);
2034
2133
  font-size: var(--font-size-sm);
@@ -3159,6 +3258,10 @@ th[data-terp="dataview-actions-cell"] > span {
3159
3258
  /* The bar reads only the inline half of the cell padding, with --space-2
3160
3259
  vertically, so its left edge stays flush with the first cell's text at either
3161
3260
  density — the same bargain the toolbar strikes at the other end of the box. */
3261
+ /* min-height is what lets the bar say nothing. While the total is unknown the range span
3262
+ is empty and the pager is absent, so without a floor the bar collapses to its padding and
3263
+ the whole footer jumps the moment the count lands -- which is the layout shift the
3264
+ fixed-height skeleton above it exists to avoid. One line box of the bar's own type. */
3162
3265
  [data-terp="dataview-pagination"] {
3163
3266
  display: flex;
3164
3267
  align-items: center;
@@ -3166,6 +3269,8 @@ th[data-terp="dataview-actions-cell"] > span {
3166
3269
  gap: var(--space-3);
3167
3270
  flex-wrap: wrap;
3168
3271
  padding-block: var(--space-2);
3272
+ min-height: calc(var(--font-size-sm) * var(--font-line-height-base) + 2 * var(--space-2));
3273
+ box-sizing: border-box;
3169
3274
  font-size: var(--font-size-sm);
3170
3275
  color: var(--color-fg-subtle);
3171
3276
  }
@@ -1,7 +1,12 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { describe, expect, it } from "vitest";
3
3
 
4
- import { NARROW_VIEWPORT, WIDE_VIEWPORT_QUERY } from "./breakpoints";
4
+ import {
5
+ MEDIUM_VIEWPORT,
6
+ NARROW_VIEWPORT,
7
+ ROOMY_VIEWPORT_QUERY,
8
+ WIDE_VIEWPORT_QUERY,
9
+ } from "./breakpoints";
5
10
  import { TERP_STYLES_CSS } from "./styles";
6
11
 
7
12
  // Vitest stubs .css imports to empty modules, so the sheet is read from disk.
@@ -189,11 +194,21 @@ describe("design tokens", () => {
189
194
  expect(WIDE_VIEWPORT_QUERY).toBe(`not all and ${NARROW_VIEWPORT}`);
190
195
  expect(sheet).toContain(`@media ${WIDE_VIEWPORT_QUERY}`);
191
196
 
197
+ // The second cutover, held the same way. It buys a third region without a third query
198
+ // (see breakpoints.ts): the regions are two cutovers in cascade order, so this pair has
199
+ // to satisfy exactly the invariants the pair above does, and the middle region is
200
+ // whatever the first correction leaves standing when this one does not apply.
201
+ const declaredLg = /--breakpoint-lg:\s*([^;]+);/.exec(tokensCss)?.[1]?.trim();
202
+ expect(declaredLg, "the contract should publish --breakpoint-lg").toBe("1024px");
203
+ expect(MEDIUM_VIEWPORT).toBe(`(max-width: ${declaredLg})`);
204
+ expect(ROOMY_VIEWPORT_QUERY).toBe(`not all and ${MEDIUM_VIEWPORT}`);
205
+ expect(sheet).toContain(`@media ${ROOMY_VIEWPORT_QUERY}`);
206
+
192
207
  // And nobody re-spells it. The two components import the constant now; a third copy is
193
208
  // exactly how the first two came to disagree with nothing noticing.
194
209
  const offenders = Object.entries(sources)
195
210
  .filter(([file]) => !file.includes(".test.") && file !== "./breakpoints.ts")
196
- .filter(([, text]) => text.includes("max-width: 768px"))
211
+ .filter(([, text]) => text.includes("max-width: 768px") || text.includes("max-width: 1024px"))
197
212
  .map(([file]) => file);
198
213
  expect(offenders, "the breakpoint belongs in ./breakpoints.ts and nowhere else").toEqual([]);
199
214
  });
@@ -51,13 +51,14 @@ describe("Text", () => {
51
51
  expect(el).toHaveAttribute("data-terp", "text");
52
52
  expect(el.hasAttribute("data-tone")).toBe(false);
53
53
  expect(el.hasAttribute("data-size")).toBe(false);
54
+ expect(el.hasAttribute("data-weight")).toBe(false);
54
55
  expect(el.hasAttribute("data-measure")).toBe(false);
55
56
  expect(el.getAttribute("style")).toBeNull();
56
57
  });
57
58
 
58
- it("names a tone, a step, a measure and its element", () => {
59
+ it("names a tone, a step, a weight, a measure and its element", () => {
59
60
  render(
60
- <Text data-testid="copy" as="span" tone="muted" size="sm" measure="narrow">
61
+ <Text data-testid="copy" as="span" tone="muted" size="sm" weight="semibold" measure="narrow">
61
62
  body
62
63
  </Text>,
63
64
  );
@@ -65,8 +66,39 @@ describe("Text", () => {
65
66
  expect(el.tagName).toBe("SPAN");
66
67
  expect(el).toHaveAttribute("data-tone", "muted");
67
68
  expect(el).toHaveAttribute("data-size", "sm");
69
+ expect(el).toHaveAttribute("data-weight", "semibold");
68
70
  expect(el).toHaveAttribute("data-measure", "narrow");
69
71
  });
72
+
73
+ it("carries emphasis on its own axis, so it composes with tone", () => {
74
+ // The pairing the missing axis used to force a size change for: a receding label
75
+ // above a value that carries the card. Both are body copy at the same step.
76
+ render(
77
+ <>
78
+ <Text data-testid="label" tone="muted" weight="medium">
79
+ Open incidents
80
+ </Text>
81
+ <Text data-testid="value" weight="semibold">
82
+ 14
83
+ </Text>
84
+ </>,
85
+ );
86
+ expect(screen.getByTestId("label")).toHaveAttribute("data-weight", "medium");
87
+ expect(screen.getByTestId("label")).toHaveAttribute("data-tone", "muted");
88
+ const value = screen.getByTestId("value");
89
+ expect(value).toHaveAttribute("data-weight", "semibold");
90
+ // Emphasis is not a size change, which is what a screen had to reach for before.
91
+ expect(value.hasAttribute("data-size")).toBe(false);
92
+ });
93
+
94
+ it("leaves an explicit normal weight unstamped, like every other default", () => {
95
+ render(
96
+ <Text data-testid="copy" weight="normal">
97
+ body
98
+ </Text>,
99
+ );
100
+ expect(screen.getByTestId("copy").hasAttribute("data-weight")).toBe(false);
101
+ });
70
102
  });
71
103
 
72
104
  describe("Code", () => {
@@ -81,19 +81,39 @@ export function Heading({ level, size, children, ...rest }: HeadingProps) {
81
81
  );
82
82
  }
83
83
 
84
- /** Ink weight for body copy. */
84
+ /** Ink tone for body copy. */
85
85
  export type TextTone = "default" | "muted" | "subtle";
86
86
 
87
87
  /** Type step for body copy. */
88
88
  export type TextSize = "xs" | "sm" | "base" | "lg";
89
89
 
90
+ /**
91
+ * Emphasis for body copy — the axis `tone` does not have.
92
+ *
93
+ * Every tone is a step *away* from the reader: `muted` and `subtle` recede, and the third
94
+ * option is not receding. That covers secondary copy and leaves nothing for the opposite
95
+ * case, which is just as common — the number a stat card is about, the answer in a
96
+ * definition row, the one word in a sentence that carries it. With no step for it the
97
+ * reach is for `size`, which says "this is bigger" when the thing meant was "this
98
+ * matters", and under the layout contract a screen cannot fall back on rendering its own
99
+ * heading either.
100
+ *
101
+ * Weight is kept separate from tone on purpose: tone is the ink, weight is the type, and
102
+ * they compose (a `medium` `muted` label above a `semibold` value is an ordinary pairing).
103
+ * `bold` is deliberately absent — the token exists, but body copy that needs 700 is a
104
+ * heading wearing a disguise.
105
+ */
106
+ export type TextWeight = "normal" | "medium" | "semibold";
107
+
90
108
  export interface TextProps extends Omit<HTMLAttributes<HTMLElement>, "style"> {
91
109
  /** The rendered element — `"p"` by default; `"span"` for text inside a line. */
92
110
  as?: "p" | "span" | "div";
93
- /** Ink weight (default `"default"`; `"muted"` for secondary copy, `"subtle"` for hints). */
111
+ /** Ink tone (default `"default"`; `"muted"` for secondary copy, `"subtle"` for hints). */
94
112
  tone?: TextTone;
95
113
  /** Type step (default `"base"`). */
96
114
  size?: TextSize;
115
+ /** Emphasis step (default `"normal"`). Composes with `tone`. */
116
+ weight?: TextWeight;
97
117
  /**
98
118
  * Cap the line length for readability (default off).
99
119
  *
@@ -115,6 +135,7 @@ export function Text({
115
135
  as: Component = "p",
116
136
  tone = "default",
117
137
  size = "base",
138
+ weight = "normal",
118
139
  measure,
119
140
  children,
120
141
  ...rest
@@ -123,10 +144,12 @@ export function Text({
123
144
  <Component
124
145
  {...rest}
125
146
  data-terp="text"
126
- // `default` and `base` are the base rule, so their attributes would describe the default
127
- // twice — the idiom density, Button's `md`, Grid's `auto` and Card's `boxed` all use.
147
+ // `default`, `base` and `normal` are the base rule, so their attributes would describe
148
+ // the default twice — the idiom density, Button's `md`, Grid's `auto` and Card's
149
+ // `boxed` all use.
128
150
  data-tone={tone === "default" ? undefined : tone}
129
151
  data-size={size === "base" ? undefined : size}
152
+ data-weight={weight === "normal" ? undefined : weight}
130
153
  data-measure={measure}
131
154
  >
132
155
  {children}