@newtone-dev/ui-react-web 0.35.1 → 0.37.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.
@@ -181,6 +181,43 @@
181
181
  cursor: default;
182
182
  }
183
183
 
184
+ .newtone-segmented-control-segment[aria-current] {
185
+ background: var(--newtone-segmented-control-segment-chosen-fill);
186
+ color: var(--newtone-segmented-control-segment-chosen-text);
187
+ }
188
+
189
+ /* THE TWO RUNGS: the text is 14/20 at both, so the rung is the block padding. `sm` is a 36px segment
190
+ * in a 44px track; the track's padding and corner do not move, so 12 still wraps 8.
191
+ * components/segmented-control.md, *size and square*. */
192
+ .newtone-segmented-control--sm .newtone-segmented-control-segment {
193
+ padding-block: var(--newtone-space-2);
194
+ }
195
+
196
+ /* SQUARE: as wide as tall, the label centered, for one or two letters. The width is stated, the
197
+ * label's 20px leading plus the rung's block padding twice, because `aspect-ratio` cannot widen a
198
+ * flex item whose height is not definite (measured: it left ES 16px wide). */
199
+ .newtone-segmented-control--square .newtone-segmented-control-segment {
200
+ box-sizing: border-box;
201
+ inline-size: calc(
202
+ var(--newtone-typography-step-sm-leading) + 2 *
203
+ var(--newtone-segmented-control-segment-padding-block)
204
+ );
205
+ padding-inline: 0;
206
+ justify-content: center;
207
+ }
208
+
209
+ .newtone-segmented-control--sm.newtone-segmented-control--square
210
+ .newtone-segmented-control-segment {
211
+ inline-size: calc(var(--newtone-typography-step-sm-leading) + 2 * var(--newtone-space-2));
212
+ }
213
+
214
+ /* A link segment is an <a>: no underline, and its own focus ring, where a radio segment's ring is
215
+ * its input's. components/segmented-control.md, *Links*. */
216
+ .newtone-segmented-control--links .newtone-segmented-control-segment {
217
+ text-decoration: none;
218
+ }
219
+
220
+ .newtone-segmented-control--links .newtone-segmented-control-segment:focus-visible,
184
221
  .newtone-segmented-control-segment:has(.newtone-segmented-control-input:focus-visible) {
185
222
  outline: 2px solid;
186
223
  outline-offset: 0;
@@ -206,12 +243,15 @@
206
243
  }
207
244
 
208
245
  @media (max-width: 48rem) {
209
- .newtone-segmented-control:where(:not([data-newtone-breakpoints='container'] *)) {
246
+ .newtone-segmented-control:where(:not([data-newtone-breakpoints='container'] *)):not(
247
+ .newtone-segmented-control--links
248
+ ) {
210
249
  display: flex;
211
250
  inline-size: 100%;
212
251
  }
213
252
 
214
- .newtone-segmented-control-segment:where(:not([data-newtone-breakpoints='container'] *)) {
253
+ .newtone-segmented-control:not(.newtone-segmented-control--links)
254
+ .newtone-segmented-control-segment:where(:not([data-newtone-breakpoints='container'] *)) {
215
255
  flex: 1 1 0;
216
256
  min-inline-size: 0;
217
257
  justify-content: center;
@@ -220,12 +260,13 @@
220
260
  }
221
261
 
222
262
  @container newtone-breakpoints (max-width: 48rem) {
223
- .newtone-segmented-control {
263
+ .newtone-segmented-control:not(.newtone-segmented-control--links) {
224
264
  display: flex;
225
265
  inline-size: 100%;
226
266
  }
227
267
 
228
- .newtone-segmented-control-segment {
268
+ .newtone-segmented-control:not(.newtone-segmented-control--links)
269
+ .newtone-segmented-control-segment {
229
270
  flex: 1 1 0;
230
271
  min-inline-size: 0;
231
272
  justify-content: center;
@@ -76,6 +76,13 @@ export interface SegmentedControlOption {
76
76
  label: string;
77
77
  /** A small mark after the label -- `−50%`. The word is the caller's; the shape is this file's. */
78
78
  badge?: string;
79
+ /**
80
+ * Where the segment goes. **When every option has one, the group is links**: a `<nav>` of `<a>`
81
+ * segments, the chosen one marked `aria-current`. components/segmented-control.md, *Links*.
82
+ */
83
+ href?: string;
84
+ /** The language the `href` is in, written as the link's `hrefLang` and `lang`. */
85
+ hrefLang?: string;
79
86
  }
80
87
  export interface SegmentedControlProps extends HTMLAttributes<HTMLElement> {
81
88
  /**
@@ -89,6 +96,10 @@ export interface SegmentedControlProps extends HTMLAttributes<HTMLElement> {
89
96
  options: readonly SegmentedControlOption[];
90
97
  /** The `value` of the option checked first; the first option when it names none. */
91
98
  defaultValue?: string;
99
+ /** 44px segments in a 52px track (`md`, the default) or 36 in 44 (`sm`). */
100
+ size?: 'sm' | 'md';
101
+ /** Each segment as wide as it is tall, for labels of one or two letters (*ES | EN*). */
102
+ square?: boolean;
92
103
  }
93
- export declare function SegmentedControl({ name, label, options, defaultValue, className, ...rest }: SegmentedControlProps): import("react").JSX.Element;
104
+ export declare function SegmentedControl({ name, label, options, defaultValue, size, square, className, ...rest }: SegmentedControlProps): import("react").JSX.Element;
94
105
  //# sourceMappingURL=segmented-control.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmented-control.d.ts","sourceRoot":"","sources":["../../src/segmented-control/segmented-control.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,MAAM,WAAW,sBAAsB;IACnC,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb,kGAAkG;IAClG,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACtE;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAA;IAC1C,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,wBAAgB,gBAAgB,CAAC,EAC7B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,YAAY,EACZ,SAAS,EACT,GAAG,IAAI,EACV,EAAE,qBAAqB,+BA4CvB"}
1
+ {"version":3,"file":"segmented-control.d.ts","sourceRoot":"","sources":["../../src/segmented-control/segmented-control.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,MAAM,WAAW,sBAAsB;IACnC,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb,kGAAkG;IAClG,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACtE;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAA;IAC1C,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IAClB,wFAAwF;IACxF,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAC7B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,YAAY,EACZ,IAAW,EACX,MAAc,EACd,SAAS,EACT,GAAG,IAAI,EACV,EAAE,qBAAqB,+BAuFvB"}
@@ -3,9 +3,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // this is a server component -- see the repo blueprint, section 4.3.
4
4
  import { Surface } from '../surface/index.js';
5
5
  import { Text } from '../text/index.js';
6
- export function SegmentedControl({ name, label, options, defaultValue, className, ...rest }) {
6
+ export function SegmentedControl({ name, label, options, defaultValue, size = 'md', square = false, className, ...rest }) {
7
+ const modifiers = [
8
+ size === 'sm' ? 'newtone-segmented-control--sm' : null,
9
+ square ? 'newtone-segmented-control--square' : null,
10
+ ];
7
11
  const named = options.findIndex((option) => option.value === defaultValue);
8
12
  const checked = named === -1 ? 0 : named;
9
- return (_jsx("div", { className: ['newtone-segmented-control', className].filter(Boolean).join(' '), role: "radiogroup", "aria-label": label, ...rest, children: options.map((option, index) => (_jsxs("label", { className: "newtone-segmented-control-segment", children: [_jsx("input", { className: "newtone-segmented-control-input", type: "radio", name: name, value: option.value, defaultChecked: index === checked }), _jsx(Text, { as: "span", scale: "body-sm", weight: "medium", children: option.label }), option.badge ? (_jsx(Surface, { as: "span", theme: "tinted", className: "newtone-segmented-control-badge", children: _jsx(Text, { as: "span", scale: "caption", weight: "medium", figures: "tabular", children: option.badge }) })) : null] }, option.value))) }));
13
+ // LINKS, when every option goes somewhere: the choice is a different address, so each segment
14
+ // is an <a>, and the chosen one is the current page. Same segment classes and tokens; the
15
+ // `--links` class keeps its width below 48rem, because it sits in chrome. components/
16
+ // segmented-control.md, *Links*.
17
+ if (options.length > 0 && options.every((option) => option.href !== undefined)) {
18
+ return (_jsx("nav", { className: [
19
+ 'newtone-segmented-control',
20
+ 'newtone-segmented-control--links',
21
+ ...modifiers,
22
+ className,
23
+ ]
24
+ .filter(Boolean)
25
+ .join(' '), "aria-label": label, ...rest, children: options.map((option, index) => (_jsx("a", { className: "newtone-segmented-control-segment", href: option.href, hrefLang: option.hrefLang, lang: option.hrefLang, "aria-current": index === checked ? 'page' : undefined, children: _jsx(Text, { as: "span", scale: "body-sm", weight: "medium", children: option.label }) }, option.value))) }));
26
+ }
27
+ return (_jsx("div", { className: ['newtone-segmented-control', ...modifiers, className]
28
+ .filter(Boolean)
29
+ .join(' '), role: "radiogroup", "aria-label": label, ...rest, children: options.map((option, index) => (_jsxs("label", { className: "newtone-segmented-control-segment", children: [_jsx("input", { className: "newtone-segmented-control-input", type: "radio", name: name, value: option.value, defaultChecked: index === checked }), _jsx(Text, { as: "span", scale: "body-sm", weight: "medium", children: option.label }), option.badge ? (_jsx(Surface, { as: "span", theme: "tinted", className: "newtone-segmented-control-badge", children: _jsx(Text, { as: "span", scale: "caption", weight: "medium", figures: "tabular", children: option.badge }) })) : null] }, option.value))) }));
10
30
  }
11
31
  //# sourceMappingURL=segmented-control.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmented-control.js","sourceRoot":"","sources":["../../src/segmented-control/segmented-control.tsx"],"names":[],"mappings":";AAAA,uGAAuG;AACvG,qEAAqE;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAgGvC,MAAM,UAAU,gBAAgB,CAAC,EAC7B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,YAAY,EACZ,SAAS,EACT,GAAG,IAAI,EACa;IACpB,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,YAAY,CAAC,CAAA;IAC1E,MAAM,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IACxC,OAAO,CACH,cACI,SAAS,EAAE,CAAC,2BAA2B,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAC7E,IAAI,EAAC,YAAY,gBACL,KAAK,KACb,IAAI,YAEP,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAC5B,iBAA0B,SAAS,EAAC,mCAAmC,aAInE,gBACI,SAAS,EAAC,iCAAiC,EAC3C,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,cAAc,EAAE,KAAK,KAAK,OAAO,GACnC,EACF,KAAC,IAAI,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAC,SAAS,EAAC,MAAM,EAAC,QAAQ,YAC1C,MAAM,CAAC,KAAK,GACV,EAKN,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CACZ,KAAC,OAAO,IACJ,EAAE,EAAC,MAAM,EACT,KAAK,EAAC,QAAQ,EACd,SAAS,EAAC,iCAAiC,YAE3C,KAAC,IAAI,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAC,SAAS,EAAC,MAAM,EAAC,QAAQ,EAAC,OAAO,EAAC,SAAS,YAC5D,MAAM,CAAC,KAAK,GACV,GACD,CACb,CAAC,CAAC,CAAC,IAAI,KA5BA,MAAM,CAAC,KAAK,CA6BhB,CACX,CAAC,GACA,CACT,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"segmented-control.js","sourceRoot":"","sources":["../../src/segmented-control/segmented-control.tsx"],"names":[],"mappings":";AAAA,uGAAuG;AACvG,qEAAqE;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AA2GvC,MAAM,UAAU,gBAAgB,CAAC,EAC7B,IAAI,EACJ,KAAK,EACL,OAAO,EACP,YAAY,EACZ,IAAI,GAAG,IAAI,EACX,MAAM,GAAG,KAAK,EACd,SAAS,EACT,GAAG,IAAI,EACa;IACpB,MAAM,SAAS,GAAG;QACd,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,IAAI;QACtD,MAAM,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,IAAI;KACtD,CAAA;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,YAAY,CAAC,CAAA;IAC1E,MAAM,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAExC,8FAA8F;IAC9F,0FAA0F;IAC1F,sFAAsF;IACtF,iCA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KAAK,EACnB,cAAc,EAAE,KAAK,KAAK,OAAO,GACnC,EACF,KAAC,IAAI,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAC,SAAS,EAAC,MAAM,EAAC,QAAQ,YAC1C,MAAM,CAAC,KAAK,GACV,EAKN,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CACZ,KAAC,OAAO,IACJ,EAAE,EAAC,MAAM,EACT,KAAK,EAAC,QAAQ,EACd,SAAS,EAAC,iCAAiC,YAE3C,KAAC,IAAI,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAC,SAAS,EAAC,MAAM,EAAC,QAAQ,EAAC,OAAO,EAAC,SAAS,YAC5D,MAAM,CAAC,KAAK,GACV,GACD,CACb,CAAC,CAAC,CAAC,IAAI,KA5BA,MAAM,CAAC,KAAK,CA6BhB,CACX,CAAC,GACA,CACT,CAAA;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtone-dev/ui-react-web",
3
- "version": "0.35.1",
3
+ "version": "0.37.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",