@saykit/react 0.6.0 → 0.7.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/dist/index.d.mts CHANGED
@@ -1,6 +1,17 @@
1
- import { PropsWithChildren, ReactElement, ReactNode } from "react";
2
- import { Disallow, Named, NumeralOptions, SelectOptions } from "saykit";
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { DateTimeOptions, Disallow, Named, NumberOptions, NumeralOptions, SelectOptions } from "saykit";
3
3
  //#region src/types.d.ts
4
+ /**
5
+ * What a message is allowed to contain. On top of everything React renders, a
6
+ * named placeholder — `{{ name: value }}` — reaches the type checker as a plain
7
+ * object child, so the object form has to be part of the contract even though
8
+ * nothing ever renders it: the transform reads the name off it and compiles the
9
+ * child away before React sees the tree.
10
+ */
11
+ type SayNode = ReactNode | Named<unknown> | Iterable<SayNode>;
12
+ type PropsWithSayChildren<P = unknown> = P & {
13
+ children?: SayNode;
14
+ };
4
15
  type PropsWithJSXSafeKeys<T> = { [K in keyof T as K extends number | `${number}${string}` ? `_${K}` : K extends `_${number}${string}` ? never : K]: T[K]; };
5
16
  //#endregion
6
17
  //#region src/runtime/index.d.ts
@@ -11,7 +22,7 @@ type PropsWithJSXSafeKeys<T> = { [K in keyof T as K extends number | `${number}$
11
22
  * @returns The translation node for the descriptor
12
23
  * @remark This is a macro and must be used with the relevant saykit plugin
13
24
  */
14
- declare function Say(props: PropsWithChildren<Disallow<{
25
+ declare function Say(props: PropsWithSayChildren<Disallow<{
15
26
  context?: string;
16
27
  whitespace?: boolean;
17
28
  }, 'id'>>): ReactElement;
@@ -77,8 +88,60 @@ declare namespace Say {
77
88
  * @remark This is a macro and must be used with the relevant saykit plugin
78
89
  */
79
90
  function Select(props: {
80
- _: string | Named<string>;
91
+ _: string | number | Named<string | number>;
81
92
  } & PropsWithJSXSafeKeys<Disallow<SelectOptions, 'id' | 'context'>>): ReactNode;
93
+ /**
94
+ * Format a number the way the active locale writes one.
95
+ *
96
+ * Unlike `Say.Plural`, `Say.Ordinal`, and `Say.Select`, this is a fragment
97
+ * rather than a whole message, and is normally written inside one.
98
+ *
99
+ * @example
100
+ * ```tsx
101
+ * <Say>You have <Say.Number _={items.length} /> items</Say>
102
+ * <Say>Battery at <Say.Number _={level} style="percent" /></Say>
103
+ * ```
104
+ *
105
+ * @param props._ Number to format
106
+ * @param props.style Formatting style, either a named style or a literal number pattern
107
+ * @returns The formatted number, as a React node
108
+ * @remark This is a macro and must be used with the relevant saykit plugin
109
+ */
110
+ function Number(props: {
111
+ _: number | Named<number>;
112
+ } & Disallow<NumberOptions, 'id' | 'context'>): ReactNode;
113
+ /**
114
+ * Format the date portion of a value the way the active locale writes one.
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * <Say>Published <Say.Date _={post.publishedAt} style="medium" /></Say>
119
+ * ```
120
+ *
121
+ * @param props._ Date to format
122
+ * @param props.style Formatting style
123
+ * @returns The formatted date, as a React node
124
+ * @remark This is a macro and must be used with the relevant saykit plugin
125
+ */
126
+ function Date(props: {
127
+ _: globalThis.Date | number | Named<globalThis.Date | number>;
128
+ } & Disallow<DateTimeOptions, 'id' | 'context'>): ReactNode;
129
+ /**
130
+ * Format the time portion of a value the way the active locale writes one.
131
+ *
132
+ * @example
133
+ * ```tsx
134
+ * <Say>Doors open at <Say.Time _={opensAt} style="short" /></Say>
135
+ * ```
136
+ *
137
+ * @param props._ Date to format
138
+ * @param props.style Formatting style
139
+ * @returns The formatted time, as a React node
140
+ * @remark This is a macro and must be used with the relevant saykit plugin
141
+ */
142
+ function Time(props: {
143
+ _: globalThis.Date | number | Named<globalThis.Date | number>;
144
+ } & Disallow<DateTimeOptions, 'id' | 'context'>): ReactNode;
82
145
  }
83
146
  //#endregion
84
147
  export { Say };
package/dist/index.mjs CHANGED
@@ -101,6 +101,18 @@ function Say(props) {
101
101
  throw new Error("'Say.Select' is a macro and must be used with the relevant saykit plugin");
102
102
  }
103
103
  _Say.Select = Select;
104
+ function Number(props) {
105
+ throw new Error("'Say.Number' is a macro and must be used with the relevant saykit plugin");
106
+ }
107
+ _Say.Number = Number;
108
+ function Date(props) {
109
+ throw new Error("'Say.Date' is a macro and must be used with the relevant saykit plugin");
110
+ }
111
+ _Say.Date = Date;
112
+ function Time(props) {
113
+ throw new Error("'Say.Time' is a macro and must be used with the relevant saykit plugin");
114
+ }
115
+ _Say.Time = Time;
104
116
  })(Say || (Say = {}));
105
117
  //#endregion
106
118
  export { Say };
@@ -101,6 +101,18 @@ function Say(props) {
101
101
  throw new Error("'Say.Select' is a macro and must be used with the relevant saykit plugin");
102
102
  }
103
103
  _Say.Select = Select;
104
+ function Number(props) {
105
+ throw new Error("'Say.Number' is a macro and must be used with the relevant saykit plugin");
106
+ }
107
+ _Say.Number = Number;
108
+ function Date(props) {
109
+ throw new Error("'Say.Date' is a macro and must be used with the relevant saykit plugin");
110
+ }
111
+ _Say.Date = Date;
112
+ function Time(props) {
113
+ throw new Error("'Say.Time' is a macro and must be used with the relevant saykit plugin");
114
+ }
115
+ _Say.Time = Time;
104
116
  })(Say || (Say = {}));
105
117
  //#endregion
106
118
  export { Say };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saykit/react",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "React integration for saykit, i18n hooks and components",
5
5
  "keywords": [
6
6
  "i18n",
@@ -52,7 +52,7 @@
52
52
  "jsdom": "^29.1.1",
53
53
  "react": "^19.2.8",
54
54
  "react-dom": "^19.2.8",
55
- "saykit": "^0.6.0"
55
+ "saykit": "^0.7.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": "*",