@unofficialbox/box-open-elements 0.13.0 → 0.14.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.
@@ -28,9 +28,25 @@ export declare class FormattedNumber extends FormattedValue {
28
28
  /** ISO 4217 code, required by `Intl` when the style is `currency`. */
29
29
  get currency(): string;
30
30
  set currency(next: string);
31
- /** A sanctioned unit identifier, e.g. `megabyte`, when the style is `unit`. */
31
+ /**
32
+ * A sanctioned unit identifier, e.g. `megabyte`, when the style is `unit`.
33
+ *
34
+ * `Intl` accepts a closed list and throws on anything else, so this is not a
35
+ * free-text label — "widgets" will not work, and the component falls back to
36
+ * a plain number rather than losing the value over it.
37
+ */
32
38
  get unit(): string;
33
39
  set unit(next: string);
40
+ /**
41
+ * How wide to write the unit: `short` (2.5 MB), `narrow` (2.5MB) or `long`
42
+ * (2.5 megabytes).
43
+ *
44
+ * `Intl` defaults to `short`, which is what a table wants. `long` is for
45
+ * prose, where an abbreviation a reader has to expand in their head is worse
46
+ * than the words.
47
+ */
48
+ get unitDisplay(): string;
49
+ set unitDisplay(next: string);
34
50
  protected formatted(): {
35
51
  text: string;
36
52
  } | null;
@@ -2,6 +2,7 @@ import { FormattedValue } from "./formatted-value.js";
2
2
  import { parseNumber } from "../../foundations/format/index.js";
3
3
  const DEFAULT_TAG_NAME = "box-formatted-number";
4
4
  const NUMBER_STYLES = new Set(["decimal", "currency", "percent", "unit"]);
5
+ const UNIT_DISPLAYS = new Set(["short", "narrow", "long"]);
5
6
  /**
6
7
  * A number, rendered in the reader's locale.
7
8
  *
@@ -29,6 +30,7 @@ export class FormattedNumber extends FormattedValue {
29
30
  "maximum-fraction-digits",
30
31
  "minimum-fraction-digits",
31
32
  "unit",
33
+ "unit-display",
32
34
  "value",
33
35
  ];
34
36
  }
@@ -54,13 +56,34 @@ export class FormattedNumber extends FormattedValue {
54
56
  set currency(next) {
55
57
  this.setAttribute("currency", next);
56
58
  }
57
- /** A sanctioned unit identifier, e.g. `megabyte`, when the style is `unit`. */
59
+ /**
60
+ * A sanctioned unit identifier, e.g. `megabyte`, when the style is `unit`.
61
+ *
62
+ * `Intl` accepts a closed list and throws on anything else, so this is not a
63
+ * free-text label — "widgets" will not work, and the component falls back to
64
+ * a plain number rather than losing the value over it.
65
+ */
58
66
  get unit() {
59
67
  return this.getAttribute("unit") ?? "";
60
68
  }
61
69
  set unit(next) {
62
70
  this.setAttribute("unit", next);
63
71
  }
72
+ /**
73
+ * How wide to write the unit: `short` (2.5 MB), `narrow` (2.5MB) or `long`
74
+ * (2.5 megabytes).
75
+ *
76
+ * `Intl` defaults to `short`, which is what a table wants. `long` is for
77
+ * prose, where an abbreviation a reader has to expand in their head is worse
78
+ * than the words.
79
+ */
80
+ get unitDisplay() {
81
+ const raw = this.getAttribute("unit-display");
82
+ return raw && UNIT_DISPLAYS.has(raw) ? raw : "short";
83
+ }
84
+ set unitDisplay(next) {
85
+ this.setAttribute("unit-display", next);
86
+ }
64
87
  formatted() {
65
88
  const numeric = parseNumber(this.value);
66
89
  if (numeric === null) {
@@ -83,6 +106,7 @@ export class FormattedNumber extends FormattedValue {
83
106
  }
84
107
  else {
85
108
  options.unit = this.unit;
109
+ options.unitDisplay = this.unitDisplay;
86
110
  }
87
111
  }
88
112
  const min = parseNumber(this.getAttribute("minimum-fraction-digits"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unofficialbox/box-open-elements",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Box Open Elements: an open, framework-agnostic design system and web component library for Box-style experiences",
5
5
  "license": "MIT",
6
6
  "homepage": "https://unofficialbox.github.io/box-open-elements",