@sanity/rich-date-input 2.0.10 → 3.0.1
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/LICENSE +1 -1
- package/README.md +67 -33
- package/dist/index.d.ts +36 -0
- package/dist/index.esm.js +258 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +263 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -24
- package/sanity.json +2 -15
- package/src/components/RelativeDateTimePicker.tsx +56 -0
- package/src/components/RichDateInput.tsx +58 -0
- package/src/components/TimezoneButton.tsx +31 -0
- package/src/components/TimezoneSelector.tsx +82 -0
- package/src/index.ts +12 -0
- package/src/schema.ts +61 -0
- package/src/types/index.ts +18 -0
- package/src/utils/index.ts +40 -0
- package/v2-incompatible.js +11 -0
- package/schema.js +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var sanity = require('sanity');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var ui = require('@sanity/ui');
|
|
9
|
+
var tzdb = require('@vvo/tzdb');
|
|
10
|
+
var dateFnsTz = require('date-fns-tz');
|
|
11
|
+
var icons = require('@sanity/icons');
|
|
12
|
+
var react = require('react');
|
|
13
|
+
const unlocalizeDateTime = (datetime, timezone) => {
|
|
14
|
+
return dateFnsTz.formatInTimeZone(datetime, timezone, "yyyy-MM-dd HH:mm:ss");
|
|
15
|
+
};
|
|
16
|
+
const getConstructedUTCDate = (utc, offset) => {
|
|
17
|
+
const date = new Date(utc);
|
|
18
|
+
const currentOffset = ( /* @__PURE__ */new Date()).getTimezoneOffset() * -1;
|
|
19
|
+
const diff = currentOffset - offset;
|
|
20
|
+
const fakeUTCDate = new Date(date.getTime() - diff * 60 * 1e3);
|
|
21
|
+
return fakeUTCDate.toISOString();
|
|
22
|
+
};
|
|
23
|
+
const allTimezones = tzdb.getTimeZones().map(tz => {
|
|
24
|
+
return {
|
|
25
|
+
abbreviation: tz.abbreviation,
|
|
26
|
+
alternativeName: tz.alternativeName,
|
|
27
|
+
mainCities: tz.mainCities.join(", "),
|
|
28
|
+
// Main time zone name 'Africa/Dar_es_Salaam'
|
|
29
|
+
name: tz.name,
|
|
30
|
+
// Time zone name with underscores removed
|
|
31
|
+
namePretty: tz.name.replaceAll("_", " "),
|
|
32
|
+
offset: tz.currentTimeFormat.split(" ")[0],
|
|
33
|
+
// all searchable text - this is transformed before being rendered in `<AutoComplete>`
|
|
34
|
+
value: "".concat(tz.currentTimeFormat, " ").concat(tz.abbreviation, " ").concat(tz.name),
|
|
35
|
+
currentTimeOffsetInMinutes: tz.currentTimeOffsetInMinutes,
|
|
36
|
+
group: tz.group
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
const RelativeDateTimePicker = props => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const value = props.dateValue;
|
|
42
|
+
const timezone = (_a = value == null ? void 0 : value.timezone) != null ? _a : Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
43
|
+
const offset = (_b = value == null ? void 0 : value.offset) != null ? _b : ( /* @__PURE__ */new Date()).getTimezoneOffset() * -1;
|
|
44
|
+
const handleDateChange = patch => {
|
|
45
|
+
const patches = [];
|
|
46
|
+
const newDatetime = patch == null ? void 0 : patch.value;
|
|
47
|
+
if (!newDatetime || !("type" in patch) || patch.type !== "set") {
|
|
48
|
+
props.onChange(sanity.unset());
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const desiredDateTime = unlocalizeDateTime(newDatetime, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
|
52
|
+
const utcDate = dateFnsTz.zonedTimeToUtc(desiredDateTime, timezone).toISOString();
|
|
53
|
+
const localDate = dateFnsTz.formatInTimeZone(utcDate, timezone, "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
54
|
+
patches.push(sanity.set(utcDate, ["utc"]));
|
|
55
|
+
patches.push(sanity.set(localDate, ["local"]));
|
|
56
|
+
if (!(value == null ? void 0 : value.timezone)) {
|
|
57
|
+
patches.push(sanity.set(timezone, ["timezone"]));
|
|
58
|
+
}
|
|
59
|
+
if (!(value == null ? void 0 : value.offset)) {
|
|
60
|
+
patches.push(sanity.set(offset, ["offset"]));
|
|
61
|
+
}
|
|
62
|
+
props.onChange(patches);
|
|
63
|
+
};
|
|
64
|
+
const dateToDisplay = (value == null ? void 0 : value.utc) ? getConstructedUTCDate(value.utc, value.offset) : "";
|
|
65
|
+
return /* @__PURE__ */jsxRuntime.jsx(sanity.DateTimeInput, {
|
|
66
|
+
...props,
|
|
67
|
+
onChange: handleDateChange,
|
|
68
|
+
value: dateToDisplay
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const TimezoneSelector = props => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const {
|
|
74
|
+
onChange,
|
|
75
|
+
value
|
|
76
|
+
} = props;
|
|
77
|
+
const currentTz = allTimezones.find(tz => tz.name === (value == null ? void 0 : value.timezone));
|
|
78
|
+
const userTzName = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
79
|
+
const userTz = (_a = allTimezones.find(tz => tz.name === userTzName)) != null ? _a : allTimezones.find(tz => tz.group.includes(userTzName));
|
|
80
|
+
const handleTimezoneChange = selectedTz => {
|
|
81
|
+
var _a2, _b2;
|
|
82
|
+
const newTimezone = (_a2 = allTimezones.find(tz => tz.value === selectedTz)) != null ? _a2 : userTz;
|
|
83
|
+
const offset = (_b2 = newTimezone.currentTimeOffsetInMinutes) != null ? _b2 : 0;
|
|
84
|
+
const timezonePatch = sanity.set(newTimezone.name, ["timezone"]);
|
|
85
|
+
const offsetPatch = sanity.set(offset, ["offset"]);
|
|
86
|
+
const patches = [timezonePatch, offsetPatch];
|
|
87
|
+
if (value == null ? void 0 : value.utc) {
|
|
88
|
+
const desiredDateTime = unlocalizeDateTime(value.utc, value.timezone);
|
|
89
|
+
const newUtcDate = dateFnsTz.zonedTimeToUtc(desiredDateTime, newTimezone.name).toISOString();
|
|
90
|
+
const newLocalDate = dateFnsTz.formatInTimeZone(newUtcDate, newTimezone.name, "yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
91
|
+
patches.push(sanity.set(newUtcDate, ["utc"]));
|
|
92
|
+
patches.push(sanity.set(newLocalDate, ["local"]));
|
|
93
|
+
}
|
|
94
|
+
onChange(patches);
|
|
95
|
+
};
|
|
96
|
+
return (
|
|
97
|
+
//taken from Scheduled Publishing, again!
|
|
98
|
+
//https://github.com/sanity-io/sanity-plugin-scheduled-publishing/blob/bb282e3df9a8a73df37fab8ee1fdd0e2430745be/src/components/dialogs/DialogTimeZone.tsx#L100
|
|
99
|
+
/* @__PURE__ */
|
|
100
|
+
jsxRuntime.jsx(ui.Box, {
|
|
101
|
+
padding: 4,
|
|
102
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Autocomplete, {
|
|
103
|
+
fontSize: 2,
|
|
104
|
+
icon: icons.SearchIcon,
|
|
105
|
+
id: "timezone",
|
|
106
|
+
onChange: handleTimezoneChange,
|
|
107
|
+
openButton: true,
|
|
108
|
+
options: allTimezones,
|
|
109
|
+
padding: 4,
|
|
110
|
+
placeholder: "Search for a city or time zone",
|
|
111
|
+
popover: {
|
|
112
|
+
boundaryElement: document.querySelector("body"),
|
|
113
|
+
constrainSize: true,
|
|
114
|
+
placement: "bottom-start"
|
|
115
|
+
},
|
|
116
|
+
renderOption: option => {
|
|
117
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
118
|
+
as: "button",
|
|
119
|
+
padding: 3,
|
|
120
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
|
|
121
|
+
size: 1,
|
|
122
|
+
textOverflow: "ellipsis",
|
|
123
|
+
children: [/* @__PURE__ */jsxRuntime.jsxs("span", {
|
|
124
|
+
children: ["GMT", option.offset]
|
|
125
|
+
}), /* @__PURE__ */jsxRuntime.jsx("span", {
|
|
126
|
+
style: {
|
|
127
|
+
fontWeight: 500,
|
|
128
|
+
marginLeft: "1em"
|
|
129
|
+
},
|
|
130
|
+
children: option.alternativeName
|
|
131
|
+
}), /* @__PURE__ */jsxRuntime.jsx("span", {
|
|
132
|
+
style: {
|
|
133
|
+
marginLeft: "1em"
|
|
134
|
+
},
|
|
135
|
+
children: option.mainCities
|
|
136
|
+
})]
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
renderValue: (_, option) => {
|
|
141
|
+
if (!option) return "";
|
|
142
|
+
return "".concat(option.alternativeName, " (").concat(option.namePretty, ")");
|
|
143
|
+
},
|
|
144
|
+
tabIndex: -1,
|
|
145
|
+
value: (_b = currentTz == null ? void 0 : currentTz.value) != null ? _b : userTz.value
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
const TimezoneButton = props => {
|
|
151
|
+
var _a, _b, _c, _d, _e;
|
|
152
|
+
const {
|
|
153
|
+
onClick,
|
|
154
|
+
timezone
|
|
155
|
+
} = props;
|
|
156
|
+
const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
157
|
+
const label = (_e = (_c = (_a = allTimezones.find(tz => tz.name === timezone)) == null ? void 0 : _a.abbreviation) != null ? _c : (_b = allTimezones.find(tz => tz.name === currentTimezone)) == null ? void 0 : _b.abbreviation) != null ? _e : (_d = allTimezones.find(tz => tz.group.includes(currentTimezone))) == null ? void 0 : _d.abbreviation;
|
|
158
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
159
|
+
fontSize: 1,
|
|
160
|
+
style: {
|
|
161
|
+
width: "100%"
|
|
162
|
+
},
|
|
163
|
+
justify: "flex-start",
|
|
164
|
+
icon: icons.EarthAmericasIcon,
|
|
165
|
+
mode: "ghost",
|
|
166
|
+
onClick,
|
|
167
|
+
text: "".concat(label),
|
|
168
|
+
"aria-label": "Select a timezone"
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const RichDateInput = props => {
|
|
172
|
+
const {
|
|
173
|
+
onChange,
|
|
174
|
+
value,
|
|
175
|
+
members,
|
|
176
|
+
schemaType
|
|
177
|
+
} = props;
|
|
178
|
+
const {
|
|
179
|
+
options
|
|
180
|
+
} = schemaType;
|
|
181
|
+
const localMember = members.find(member => member.kind === "field" && member.name === "local");
|
|
182
|
+
const timezoneMember = members.find(member => member.kind === "field" && member.name === "timezone");
|
|
183
|
+
const [timezoneSelectorOpen, setTimezoneSelectorOpen] = react.useState(false);
|
|
184
|
+
const onClose = react.useCallback(() => setTimezoneSelectorOpen(false), []);
|
|
185
|
+
const onOpen = react.useCallback(() => setTimezoneSelectorOpen(true), []);
|
|
186
|
+
return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
187
|
+
children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
188
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
189
|
+
flex: [1, 2, 4],
|
|
190
|
+
children: localMember && /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, {
|
|
191
|
+
...props,
|
|
192
|
+
member: localMember,
|
|
193
|
+
renderInput: renderInputProps => /* @__PURE__ */jsxRuntime.jsx(RelativeDateTimePicker, {
|
|
194
|
+
...renderInputProps,
|
|
195
|
+
dateValue: value,
|
|
196
|
+
schemaType: {
|
|
197
|
+
...renderInputProps.schemaType,
|
|
198
|
+
options
|
|
199
|
+
},
|
|
200
|
+
onChange
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
204
|
+
flex: [1],
|
|
205
|
+
marginLeft: [2, 2, 3, 4],
|
|
206
|
+
children: timezoneMember && /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, {
|
|
207
|
+
...props,
|
|
208
|
+
member: timezoneMember,
|
|
209
|
+
renderInput: () => {
|
|
210
|
+
var _a;
|
|
211
|
+
return /* @__PURE__ */jsxRuntime.jsx(TimezoneButton, {
|
|
212
|
+
onClick: onOpen,
|
|
213
|
+
timezone: (_a = value == null ? void 0 : value.timezone) != null ? _a : ""
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
})]
|
|
218
|
+
}), timezoneSelectorOpen && /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
|
|
219
|
+
onClose,
|
|
220
|
+
header: "Select a timezone",
|
|
221
|
+
id: "timezone-select",
|
|
222
|
+
width: 1,
|
|
223
|
+
children: /* @__PURE__ */jsxRuntime.jsx(TimezoneSelector, {
|
|
224
|
+
onChange,
|
|
225
|
+
value
|
|
226
|
+
})
|
|
227
|
+
})]
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
const richDateTypeName = "richDate";
|
|
231
|
+
const richDateSchema = sanity.defineType({
|
|
232
|
+
name: richDateTypeName,
|
|
233
|
+
title: "Rich Date",
|
|
234
|
+
type: "object",
|
|
235
|
+
fields: [sanity.defineField({
|
|
236
|
+
name: "local",
|
|
237
|
+
title: "Local",
|
|
238
|
+
type: "string"
|
|
239
|
+
}), sanity.defineField({
|
|
240
|
+
name: "utc",
|
|
241
|
+
title: "UTC",
|
|
242
|
+
type: "string"
|
|
243
|
+
}), sanity.defineField({
|
|
244
|
+
name: "timezone",
|
|
245
|
+
title: "Timezone",
|
|
246
|
+
type: "string"
|
|
247
|
+
}), sanity.defineField({
|
|
248
|
+
name: "offset",
|
|
249
|
+
title: "Offset",
|
|
250
|
+
type: "number"
|
|
251
|
+
})],
|
|
252
|
+
components: {
|
|
253
|
+
input: RichDateInput
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const richDate = sanity.definePlugin({
|
|
257
|
+
name: "v3-rich-date-input",
|
|
258
|
+
schema: {
|
|
259
|
+
types: [richDateSchema]
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
exports.richDate = richDate;
|
|
263
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils/index.ts","../src/components/RelativeDateTimePicker.tsx","../src/components/TimezoneSelector.tsx","../src/components/TimezoneButton.tsx","../src/components/RichDateInput.tsx","../src/schema.ts","../src/index.ts"],"sourcesContent":["import {getTimeZones} from '@vvo/tzdb'\nimport {NormalizedTimeZone} from '../types'\nimport {formatInTimeZone} from 'date-fns-tz'\n\nexport const unlocalizeDateTime = (datetime: string, timezone: string): string => {\n return formatInTimeZone(datetime, timezone, 'yyyy-MM-dd HH:mm:ss')\n}\n\n/* We have to \"fake\" a UTC date to make the datepicker look \"right\"\n * to the user. For example, if someone sets 7:00AM PST, which is 3PM UTC\n * and I am on the east coast, I want to have 12:00PM UTC, which will look like 7:00AM to me\n * In other words, UTC minus 3 hours, or (UTC(my offset - their offset))\n * this is purely cosmetic and should not be saved at all\n */\nexport const getConstructedUTCDate = (utc: string, offset: number): string => {\n const date = new Date(utc)\n const currentOffset = new Date().getTimezoneOffset() * -1\n const diff = currentOffset - offset\n const fakeUTCDate = new Date(date.getTime() - diff * 60 * 1000)\n return fakeUTCDate.toISOString()\n}\n\n//keep some consistency with scheduled publishing\n//https://github.com/sanity-io/sanity-plugin-scheduled-publishing/blob/bb282e3df9a8a73df37fab8ee1fdd0e2430745be/src/hooks/useTimeZone.tsx#L17\nexport const allTimezones = getTimeZones().map((tz) => {\n return {\n abbreviation: tz.abbreviation,\n alternativeName: tz.alternativeName,\n mainCities: tz.mainCities.join(', '),\n // Main time zone name 'Africa/Dar_es_Salaam'\n name: tz.name,\n // Time zone name with underscores removed\n namePretty: tz.name.replaceAll('_', ' '),\n offset: tz.currentTimeFormat.split(' ')[0],\n // all searchable text - this is transformed before being rendered in `<AutoComplete>`\n value: `${tz.currentTimeFormat} ${tz.abbreviation} ${tz.name}`,\n currentTimeOffsetInMinutes: tz.currentTimeOffsetInMinutes,\n group: tz.group,\n } as NormalizedTimeZone\n})\n","import {DateTimeInput, FormPatch, PatchEvent, InputProps, set, unset} from 'sanity'\n\nimport {getConstructedUTCDate, unlocalizeDateTime} from '../utils'\nimport {RichDate} from '../types'\nimport {formatInTimeZone, zonedTimeToUtc} from 'date-fns-tz'\n\ninterface RelativeDateTimePickerProps extends Omit<InputProps, 'renderDefault'> {\n dateValue?: RichDate\n}\n\nexport const RelativeDateTimePicker = (props: RelativeDateTimePickerProps) => {\n const value = props.dateValue\n const timezone = value?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone\n /*\n * if our offset is not coming from a lib, we have to reverse it\n * to get the real offset used everywhere\n * https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/\n */\n const offset = value?.offset ?? new Date().getTimezoneOffset() * -1\n const handleDateChange = (patch: FormPatch | PatchEvent | FormPatch[]) => {\n const patches = []\n const newDatetime = (patch as unknown as {value: string})?.value\n if (!newDatetime || !('type' in patch) || patch.type !== 'set') {\n props.onChange(unset())\n return\n }\n\n //get what time the user \"meant\" to set without tz info\n //since the datepicker always localizes to the user's timezone\n const desiredDateTime = unlocalizeDateTime(\n newDatetime,\n Intl.DateTimeFormat().resolvedOptions().timeZone,\n )\n\n //use the user-selected timezone here\n const utcDate = zonedTimeToUtc(desiredDateTime, timezone).toISOString()\n const localDate = formatInTimeZone(utcDate, timezone, \"yyyy-MM-dd'T'HH:mm:ssXXX\")\n\n patches.push(set(utcDate, ['utc']))\n patches.push(set(localDate, ['local']))\n\n if (!value?.timezone) {\n patches.push(set(timezone, ['timezone']))\n }\n\n if (!value?.offset) {\n patches.push(set(offset, ['offset']))\n }\n\n props.onChange(patches)\n }\n\n const dateToDisplay = value?.utc ? getConstructedUTCDate(value.utc, value.offset) : ''\n //@ts-expect-error -- slight mismatch in elementProps and renderDefault, but should line up in practice\n return <DateTimeInput {...props} onChange={handleDateChange} value={dateToDisplay} />\n}\n","import {SearchIcon} from '@sanity/icons'\nimport {ObjectInputProps, set} from 'sanity'\nimport {allTimezones, unlocalizeDateTime} from '../utils'\nimport {NormalizedTimeZone, RichDate} from '../types'\nimport {Autocomplete, Card, Text, Box} from '@sanity/ui'\nimport {formatInTimeZone, zonedTimeToUtc} from 'date-fns-tz'\n\ninterface TimezoneSelectorProps {\n onChange: Pick<ObjectInputProps, 'onChange'>['onChange']\n value?: RichDate\n}\n\nexport const TimezoneSelector = (props: TimezoneSelectorProps) => {\n const {onChange, value} = props\n const currentTz = allTimezones.find((tz) => tz.name === value?.timezone)\n const userTzName = Intl.DateTimeFormat().resolvedOptions().timeZone\n const userTz = (allTimezones.find((tz) => tz.name === userTzName) ??\n allTimezones.find((tz) => tz.group.includes(userTzName)))!\n\n const handleTimezoneChange = (selectedTz: string) => {\n const newTimezone =\n allTimezones.find((tz) => tz.value === selectedTz) ?? (userTz as NormalizedTimeZone)\n\n const offset = newTimezone.currentTimeOffsetInMinutes ?? 0\n const timezonePatch = set(newTimezone.name, ['timezone'])\n const offsetPatch = set(offset, ['offset'])\n const patches = [timezonePatch, offsetPatch]\n\n //then, recalculate UTC and local from \"old\" time with the new offset\n if (value?.utc) {\n const desiredDateTime = unlocalizeDateTime(value.utc, value.timezone)\n const newUtcDate = zonedTimeToUtc(desiredDateTime, newTimezone.name).toISOString()\n const newLocalDate = formatInTimeZone(\n newUtcDate,\n newTimezone.name,\n \"yyyy-MM-dd'T'HH:mm:ssXXX\",\n )\n patches.push(set(newUtcDate, ['utc']))\n patches.push(set(newLocalDate, ['local']))\n }\n onChange(patches)\n }\n\n return (\n //taken from Scheduled Publishing, again!\n //https://github.com/sanity-io/sanity-plugin-scheduled-publishing/blob/bb282e3df9a8a73df37fab8ee1fdd0e2430745be/src/components/dialogs/DialogTimeZone.tsx#L100\n <Box padding={4}>\n <Autocomplete\n fontSize={2}\n icon={SearchIcon}\n id=\"timezone\"\n onChange={handleTimezoneChange}\n openButton\n options={allTimezones}\n padding={4}\n placeholder=\"Search for a city or time zone\"\n popover={{\n boundaryElement: document.querySelector('body'),\n constrainSize: true,\n placement: 'bottom-start',\n }}\n renderOption={(option) => {\n return (\n <Card as=\"button\" padding={3}>\n <Text size={1} textOverflow=\"ellipsis\">\n <span>GMT{option.offset}</span>\n <span style={{fontWeight: 500, marginLeft: '1em'}}>{option.alternativeName}</span>\n <span style={{marginLeft: '1em'}}>{option.mainCities}</span>\n </Text>\n </Card>\n )\n }}\n renderValue={(_, option) => {\n if (!option) return ''\n return `${option.alternativeName} (${option.namePretty})`\n }}\n tabIndex={-1}\n value={currentTz?.value ?? userTz.value}\n />\n </Box>\n )\n}\n","import {Button} from '@sanity/ui'\nimport {EarthAmericasIcon} from '@sanity/icons'\nimport {allTimezones} from '../utils'\n\ninterface TimezoneButtonProps {\n onClick: () => void\n timezone: string\n}\n\nexport const TimezoneButton = (props: TimezoneButtonProps) => {\n const {onClick, timezone} = props\n const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone\n\n const label =\n allTimezones.find((tz) => tz.name === timezone)?.abbreviation ??\n allTimezones.find((tz) => tz.name === currentTimezone)?.abbreviation ??\n allTimezones.find((tz) => tz.group.includes(currentTimezone))?.abbreviation\n\n return (\n <Button\n fontSize={1}\n style={{width: '100%'}}\n justify={'flex-start'}\n icon={EarthAmericasIcon}\n mode=\"ghost\"\n onClick={onClick}\n text={`${label}`}\n aria-label=\"Select a timezone\"\n />\n )\n}\n","import {ObjectInputMember, ObjectInputProps} from 'sanity'\nimport {Box, Flex, Dialog} from '@sanity/ui'\nimport {RelativeDateTimePicker} from './RelativeDateTimePicker'\nimport {TimezoneSelector} from './TimezoneSelector'\nimport {useCallback, useState} from 'react'\nimport {TimezoneButton} from './TimezoneButton'\nimport {RichDate} from '../types'\n\nexport const RichDateInput = (props: ObjectInputProps) => {\n const {onChange, value, members, schemaType} = props\n const {options} = schemaType\n const localMember = members.find((member) => member.kind === 'field' && member.name === 'local')\n const timezoneMember = members.find(\n (member) => member.kind === 'field' && member.name === 'timezone',\n )\n const [timezoneSelectorOpen, setTimezoneSelectorOpen] = useState(false)\n const onClose = useCallback(() => setTimezoneSelectorOpen(false), [])\n const onOpen = useCallback(() => setTimezoneSelectorOpen(true), [])\n\n return (\n <>\n <Flex>\n <Box flex={[1, 2, 4]}>\n {localMember && (\n <ObjectInputMember\n {...props}\n member={localMember}\n renderInput={(renderInputProps) => (\n <RelativeDateTimePicker\n {...renderInputProps}\n dateValue={value as RichDate}\n schemaType={{...renderInputProps.schemaType, options}}\n onChange={onChange}\n />\n )}\n />\n )}\n </Box>\n <Box flex={[1]} marginLeft={[2, 2, 3, 4]}>\n {timezoneMember && (\n <ObjectInputMember\n {...props}\n member={timezoneMember}\n renderInput={() => (\n <TimezoneButton onClick={onOpen} timezone={value?.timezone ?? ''} />\n )}\n />\n )}\n </Box>\n </Flex>\n {timezoneSelectorOpen && (\n <Dialog onClose={onClose} header=\"Select a timezone\" id=\"timezone-select\" width={1}>\n <TimezoneSelector onChange={onChange} value={value as RichDate} />\n </Dialog>\n )}\n </>\n )\n}\n","import {\n DatetimeDefinition,\n ObjectDefinition,\n ObjectSchemaType,\n defineField,\n defineType,\n} from 'sanity'\nimport {RichDateInput} from './components/RichDateInput'\n\nconst richDateTypeName = 'richDate' as const\n\nexport type RichDateSchemaType = Omit<ObjectSchemaType, 'options'> & {\n options?: DatetimeDefinition['options']\n}\n\n/**\n * @public\n */\nexport interface RichDateDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {\n type: typeof richDateTypeName\n options?: DatetimeDefinition['options']\n}\n\ndeclare module 'sanity' {\n //allows the custom input to be valid for the schema def\n export interface IntrinsicDefinitions {\n richDate: RichDateDefinition\n }\n}\n\nexport const richDateSchema = defineType({\n name: richDateTypeName,\n title: 'Rich Date',\n type: 'object',\n fields: [\n defineField({\n name: 'local',\n title: 'Local',\n type: 'string',\n }),\n defineField({\n name: 'utc',\n title: 'UTC',\n type: 'string',\n }),\n defineField({\n name: 'timezone',\n title: 'Timezone',\n type: 'string',\n }),\n defineField({\n name: 'offset',\n title: 'Offset',\n type: 'number',\n }),\n ],\n\n components: {\n input: RichDateInput,\n },\n})\n","import {definePlugin} from 'sanity'\nimport {richDateSchema, RichDateDefinition, RichDateSchemaType} from './schema'\nimport {RichDate} from './types'\n\nexport const richDate = definePlugin({\n name: 'v3-rich-date-input',\n schema: {\n types: [richDateSchema],\n },\n})\n\nexport type {RichDateDefinition, RichDateSchemaType, RichDate}\n"],"names":["unlocalizeDateTime","datetime","timezone","formatInTimeZone","getConstructedUTCDate","utc","offset","date","Date","currentOffset","getTimezoneOffset","diff","fakeUTCDate","getTime","toISOString","allTimezones","getTimeZones","map","tz","abbreviation","alternativeName","mainCities","join","name","namePretty","replaceAll","currentTimeFormat","split","value","concat","currentTimeOffsetInMinutes","group","RelativeDateTimePicker","props","_a","_b","dateValue","Intl","DateTimeFormat","resolvedOptions","timeZone","handleDateChange","patch","patches","newDatetime","type","onChange","unset","desiredDateTime","utcDate","zonedTimeToUtc","localDate","push","set","dateToDisplay","DateTimeInput","TimezoneSelector","currentTz","find","userTzName","userTz","includes","handleTimezoneChange","selectedTz","newTimezone","timezonePatch","offsetPatch","newUtcDate","newLocalDate","jsx","Box","padding","children","Autocomplete","fontSize","icon","SearchIcon","id","openButton","options","placeholder","popover","boundaryElement","document","querySelector","constrainSize","placement","renderOption","option","Card","as","jsxs","Text","size","textOverflow","style","fontWeight","marginLeft","renderValue","_","tabIndex","TimezoneButton","_c","_d","_e","onClick","currentTimezone","label","Button","width","justify","EarthAmericasIcon","mode","text","RichDateInput","members","schemaType","localMember","member","kind","timezoneMember","timezoneSelectorOpen","setTimezoneSelectorOpen","useState","onClose","useCallback","onOpen","Fragment","Flex","flex","ObjectInputMember","renderInput","renderInputProps","Dialog","header","richDateTypeName","richDateSchema","defineType","title","fields","defineField","components","input","richDate","definePlugin","schema","types"],"mappings":";;;;;;;;;;;;AAIa,MAAAA,kBAAA,GAAqBA,CAACC,QAAA,EAAkBC,QAA6B,KAAA;EACzE,OAAA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MAAAgC,KAAA,EAAO,CAC/E;MAAArC,QAAA,EAAA,eAAAH,cAAA,CAACb,gBAAiB,EAAA;QAAAV,QAAA;QAAoBlB;MAA0B,CAAA;KAClE,CAAA;EAEJ,CAAA,CAAA;AAEJ,CAAA;AChDA,MAAM2G,gBAAmB,GAAA,UAAA;AAqBlB,MAAMC,iBAAiBC,MAAAA,CAAAA,UAAW,CAAA;EACvClH,IAAM,EAAAgH,gBAAA;EACNG,KAAO,EAAA,WAAA;EACP7F,IAAM,EAAA,QAAA;EACN8F,MAAQ,EAAA,CACNC,kBAAY,CAAA;IACVrH,IAAM,EAAA,OAAA;IACNmH,KAAO,EAAA,OAAA;IACP7F,IAAM,EAAA;EAAA,CACP,CAAA,EACD+F,kBAAY,CAAA;IACVrH,IAAM,EAAA,KAAA;IACNmH,KAAO,EAAA,KAAA;IACP7F,IAAM,EAAA;EAAA,CACP,CAAA,EACD+F,kBAAY,CAAA;IACVrH,IAAM,EAAA,UAAA;IACNmH,KAAO,EAAA,UAAA;IACP7F,IAAM,EAAA;EAAA,CACP,CAAA,EACD+F,kBAAY,CAAA;IACVrH,IAAM,EAAA,QAAA;IACNmH,KAAO,EAAA,QAAA;IACP7F,IAAM,EAAA;EAAA,CACP,CAAA,CACH;EAEAgG,UAAY,EAAA;IACVC,KAAO,EAAA5B;EACT;AACF,CAAC,CAAA;ACxDM,MAAM6B,WAAWC,MAAAA,CAAAA,YAAa,CAAA;EACnCzH,IAAM,EAAA,oBAAA;EACN0H,MAAQ,EAAA;IACNC,KAAA,EAAO,CAACV,cAAc;EACxB;AACF,CAAC,CAAA;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/rich-date-input",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"author": "Sanity.io <hello@sanity.io>",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"clean": "rimraf lib"
|
|
10
|
-
},
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "A timezone-aware datetime type and input component for Sanity Studio",
|
|
11
5
|
"keywords": [
|
|
12
6
|
"sanity",
|
|
13
7
|
"cms",
|
|
@@ -17,26 +11,87 @@
|
|
|
17
11
|
"rich-date-input",
|
|
18
12
|
"sanity-plugin"
|
|
19
13
|
],
|
|
14
|
+
"homepage": "https://github.com/sanity-io/rich-date-input#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sanity-io/rich-date-input/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+ssh://git@github.com/sanity-io/rich-date-input.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"require": "./dist/index.js",
|
|
29
|
+
"import": "./dist/index.esm.js",
|
|
30
|
+
"default": "./dist/index.esm.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"module": "./dist/index.esm.js",
|
|
36
|
+
"source": "./src/index.ts",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"sanity.json",
|
|
41
|
+
"src",
|
|
42
|
+
"v2-incompatible.js"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
|
|
46
|
+
"clean": "rimraf dist",
|
|
47
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
48
|
+
"link-watch": "plugin-kit link-watch",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"prepublishOnly": "run-s build",
|
|
51
|
+
"watch": "pkg-utils watch --strict",
|
|
52
|
+
"prebuild": "plugin-kit verify-package --silent && pkg-utils",
|
|
53
|
+
"prepare": "husky install"
|
|
54
|
+
},
|
|
20
55
|
"dependencies": {
|
|
21
|
-
"@sanity/
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"react-datepicker": "^1.8.0"
|
|
56
|
+
"@sanity/icons": "^2.7.0",
|
|
57
|
+
"@sanity/incompatible-plugin": "^1.0.4",
|
|
58
|
+
"@sanity/ui": "^2.0.2",
|
|
59
|
+
"@vvo/tzdb": "^6.125.0",
|
|
60
|
+
"date-fns-tz": "^2.0.0"
|
|
27
61
|
},
|
|
28
62
|
"devDependencies": {
|
|
29
|
-
"
|
|
63
|
+
"@commitlint/cli": "^18.4.1",
|
|
64
|
+
"@commitlint/config-conventional": "^18.4.0",
|
|
65
|
+
"@sanity/pkg-utils": "^3.2.3",
|
|
66
|
+
"@sanity/plugin-kit": "^3.1.10",
|
|
67
|
+
"@sanity/semantic-release-preset": "^4.1.6",
|
|
68
|
+
"@types/react": "^18.2.37",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
70
|
+
"@typescript-eslint/parser": "^6.11.0",
|
|
71
|
+
"eslint": "^8.53.0",
|
|
72
|
+
"eslint-config-prettier": "^9.0.0",
|
|
73
|
+
"eslint-config-sanity": "^7.0.1",
|
|
74
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
75
|
+
"eslint-plugin-react": "^7.33.2",
|
|
76
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
77
|
+
"husky": "^8.0.3",
|
|
78
|
+
"lint-staged": "^15.1.0",
|
|
79
|
+
"npm-run-all": "^4.1.5",
|
|
80
|
+
"prettier": "^3.1.0",
|
|
81
|
+
"prettier-plugin-packagejson": "^2.4.6",
|
|
82
|
+
"react": "^18.2.0",
|
|
83
|
+
"react-dom": "^18.2.0",
|
|
84
|
+
"react-is": "^18.2.0",
|
|
85
|
+
"rimraf": "^5.0.5",
|
|
86
|
+
"sanity": "^3.29.1",
|
|
87
|
+
"styled-components": "^5.3.11",
|
|
88
|
+
"typescript": "^5.2.2"
|
|
30
89
|
},
|
|
31
90
|
"peerDependencies": {
|
|
32
|
-
"react": "^
|
|
33
|
-
|
|
34
|
-
"repository": {
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/sanity-io/sanity.git"
|
|
37
|
-
},
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/sanity-io/sanity/issues"
|
|
91
|
+
"react": "^18",
|
|
92
|
+
"sanity": "^3"
|
|
40
93
|
},
|
|
41
|
-
"
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">=14"
|
|
96
|
+
}
|
|
42
97
|
}
|
package/sanity.json
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"paths": {
|
|
3
|
-
"source": "./src",
|
|
4
|
-
"compiled": "./lib"
|
|
5
|
-
},
|
|
6
|
-
|
|
7
2
|
"parts": [
|
|
8
3
|
{
|
|
9
|
-
"implements": "part:@sanity/
|
|
10
|
-
"path": "
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"implements": "part:@sanity/form-builder/input/rich-date/schema",
|
|
14
|
-
"path": "schema"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"implements": "part:@sanity/base/component",
|
|
18
|
-
"path": "story"
|
|
4
|
+
"implements": "part:@sanity/base/sanity-root",
|
|
5
|
+
"path": "./v2-incompatible.js"
|
|
19
6
|
}
|
|
20
7
|
]
|
|
21
8
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {DateTimeInput, FormPatch, PatchEvent, InputProps, set, unset} from 'sanity'
|
|
2
|
+
|
|
3
|
+
import {getConstructedUTCDate, unlocalizeDateTime} from '../utils'
|
|
4
|
+
import {RichDate} from '../types'
|
|
5
|
+
import {formatInTimeZone, zonedTimeToUtc} from 'date-fns-tz'
|
|
6
|
+
|
|
7
|
+
interface RelativeDateTimePickerProps extends Omit<InputProps, 'renderDefault'> {
|
|
8
|
+
dateValue?: RichDate
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const RelativeDateTimePicker = (props: RelativeDateTimePickerProps) => {
|
|
12
|
+
const value = props.dateValue
|
|
13
|
+
const timezone = value?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
14
|
+
/*
|
|
15
|
+
* if our offset is not coming from a lib, we have to reverse it
|
|
16
|
+
* to get the real offset used everywhere
|
|
17
|
+
* https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/
|
|
18
|
+
*/
|
|
19
|
+
const offset = value?.offset ?? new Date().getTimezoneOffset() * -1
|
|
20
|
+
const handleDateChange = (patch: FormPatch | PatchEvent | FormPatch[]) => {
|
|
21
|
+
const patches = []
|
|
22
|
+
const newDatetime = (patch as unknown as {value: string})?.value
|
|
23
|
+
if (!newDatetime || !('type' in patch) || patch.type !== 'set') {
|
|
24
|
+
props.onChange(unset())
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//get what time the user "meant" to set without tz info
|
|
29
|
+
//since the datepicker always localizes to the user's timezone
|
|
30
|
+
const desiredDateTime = unlocalizeDateTime(
|
|
31
|
+
newDatetime,
|
|
32
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
//use the user-selected timezone here
|
|
36
|
+
const utcDate = zonedTimeToUtc(desiredDateTime, timezone).toISOString()
|
|
37
|
+
const localDate = formatInTimeZone(utcDate, timezone, "yyyy-MM-dd'T'HH:mm:ssXXX")
|
|
38
|
+
|
|
39
|
+
patches.push(set(utcDate, ['utc']))
|
|
40
|
+
patches.push(set(localDate, ['local']))
|
|
41
|
+
|
|
42
|
+
if (!value?.timezone) {
|
|
43
|
+
patches.push(set(timezone, ['timezone']))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!value?.offset) {
|
|
47
|
+
patches.push(set(offset, ['offset']))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
props.onChange(patches)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const dateToDisplay = value?.utc ? getConstructedUTCDate(value.utc, value.offset) : ''
|
|
54
|
+
//@ts-expect-error -- slight mismatch in elementProps and renderDefault, but should line up in practice
|
|
55
|
+
return <DateTimeInput {...props} onChange={handleDateChange} value={dateToDisplay} />
|
|
56
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {ObjectInputMember, ObjectInputProps} from 'sanity'
|
|
2
|
+
import {Box, Flex, Dialog} from '@sanity/ui'
|
|
3
|
+
import {RelativeDateTimePicker} from './RelativeDateTimePicker'
|
|
4
|
+
import {TimezoneSelector} from './TimezoneSelector'
|
|
5
|
+
import {useCallback, useState} from 'react'
|
|
6
|
+
import {TimezoneButton} from './TimezoneButton'
|
|
7
|
+
import {RichDate} from '../types'
|
|
8
|
+
|
|
9
|
+
export const RichDateInput = (props: ObjectInputProps) => {
|
|
10
|
+
const {onChange, value, members, schemaType} = props
|
|
11
|
+
const {options} = schemaType
|
|
12
|
+
const localMember = members.find((member) => member.kind === 'field' && member.name === 'local')
|
|
13
|
+
const timezoneMember = members.find(
|
|
14
|
+
(member) => member.kind === 'field' && member.name === 'timezone',
|
|
15
|
+
)
|
|
16
|
+
const [timezoneSelectorOpen, setTimezoneSelectorOpen] = useState(false)
|
|
17
|
+
const onClose = useCallback(() => setTimezoneSelectorOpen(false), [])
|
|
18
|
+
const onOpen = useCallback(() => setTimezoneSelectorOpen(true), [])
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<Flex>
|
|
23
|
+
<Box flex={[1, 2, 4]}>
|
|
24
|
+
{localMember && (
|
|
25
|
+
<ObjectInputMember
|
|
26
|
+
{...props}
|
|
27
|
+
member={localMember}
|
|
28
|
+
renderInput={(renderInputProps) => (
|
|
29
|
+
<RelativeDateTimePicker
|
|
30
|
+
{...renderInputProps}
|
|
31
|
+
dateValue={value as RichDate}
|
|
32
|
+
schemaType={{...renderInputProps.schemaType, options}}
|
|
33
|
+
onChange={onChange}
|
|
34
|
+
/>
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
)}
|
|
38
|
+
</Box>
|
|
39
|
+
<Box flex={[1]} marginLeft={[2, 2, 3, 4]}>
|
|
40
|
+
{timezoneMember && (
|
|
41
|
+
<ObjectInputMember
|
|
42
|
+
{...props}
|
|
43
|
+
member={timezoneMember}
|
|
44
|
+
renderInput={() => (
|
|
45
|
+
<TimezoneButton onClick={onOpen} timezone={value?.timezone ?? ''} />
|
|
46
|
+
)}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
</Box>
|
|
50
|
+
</Flex>
|
|
51
|
+
{timezoneSelectorOpen && (
|
|
52
|
+
<Dialog onClose={onClose} header="Select a timezone" id="timezone-select" width={1}>
|
|
53
|
+
<TimezoneSelector onChange={onChange} value={value as RichDate} />
|
|
54
|
+
</Dialog>
|
|
55
|
+
)}
|
|
56
|
+
</>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Button} from '@sanity/ui'
|
|
2
|
+
import {EarthAmericasIcon} from '@sanity/icons'
|
|
3
|
+
import {allTimezones} from '../utils'
|
|
4
|
+
|
|
5
|
+
interface TimezoneButtonProps {
|
|
6
|
+
onClick: () => void
|
|
7
|
+
timezone: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TimezoneButton = (props: TimezoneButtonProps) => {
|
|
11
|
+
const {onClick, timezone} = props
|
|
12
|
+
const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
13
|
+
|
|
14
|
+
const label =
|
|
15
|
+
allTimezones.find((tz) => tz.name === timezone)?.abbreviation ??
|
|
16
|
+
allTimezones.find((tz) => tz.name === currentTimezone)?.abbreviation ??
|
|
17
|
+
allTimezones.find((tz) => tz.group.includes(currentTimezone))?.abbreviation
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Button
|
|
21
|
+
fontSize={1}
|
|
22
|
+
style={{width: '100%'}}
|
|
23
|
+
justify={'flex-start'}
|
|
24
|
+
icon={EarthAmericasIcon}
|
|
25
|
+
mode="ghost"
|
|
26
|
+
onClick={onClick}
|
|
27
|
+
text={`${label}`}
|
|
28
|
+
aria-label="Select a timezone"
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|