@nxgt/material 3.30.0 → 3.31.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.
@@ -1044,11 +1044,42 @@ export function Zone() {
1044
1044
  | `value` | `string \| null` | `null` | an IANA identifier |
1045
1045
  | `onChange` | `(value: string \| null) => void` | — | `null` when cleared |
1046
1046
  | `timezones` | `readonly string[]` | `TIMEZONES` | restrict the list |
1047
+ | `now` | `Date \| string` | the rendering machine's clock | the instant every offset is read at |
1048
+
1049
+ The offsets come from the clock of the machine that renders, so a page
1050
+ server-rendered just before a daylight-saving change and hydrated just after
1051
+ it (or a test that fixes the browser clock) shows "GMT+1" on one side and
1052
+ "GMT+2" on the other, and React reports a hydration mismatch. Pass the same
1053
+ `now` on both sides, read once in the loader; `TimezoneFormField` takes it too.
1054
+
1055
+ ```tsx
1056
+ import { TimezoneFormField } from '@nxgt/material/components';
1057
+ import type { Control } from 'react-hook-form';
1058
+ import { useLoaderData } from 'react-router';
1059
+
1060
+ type Profile = { timeZone: string };
1061
+
1062
+ export async function loader() {
1063
+ return { now: new Date().toISOString() };
1064
+ }
1065
+
1066
+ export function ZoneForm({ control }: { control: Control<Profile> }) {
1067
+ const { now } = useLoaderData<typeof loader>();
1068
+ return (
1069
+ <TimezoneFormField
1070
+ control={control}
1071
+ name="timeZone"
1072
+ label="Time zone"
1073
+ now={now}
1074
+ />
1075
+ );
1076
+ }
1077
+ ```
1047
1078
 
1048
1079
  The helpers behind it are exported too: `TIMEZONES` (the default list),
1049
- `timezoneOffset(zone, language?)` (the offset now, as the language writes
1050
- it; `''` when the zone is unknown) and `timezoneLabel(zone, language?)`
1051
- (the city and its offset in one string).
1080
+ `timezoneOffset(zone, language?, now?)` (the offset at `now`, else now, as the
1081
+ language writes it; `''` when the zone is unknown) and
1082
+ `timezoneLabel(zone, language?, now?)` (the city and its offset in one string).
1052
1083
 
1053
1084
  ```ts
1054
1085
  import { timezoneLabel, timezoneOffset } from '@nxgt/material/components';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/material",
3
- "version": "3.30.0",
3
+ "version": "3.31.0",
4
4
  "license": "MIT",
5
5
  "bugs": {
6
6
  "email": "stevegires@gmail.com"