@pushwoosh/dumb-components 1.1.48 → 1.1.50

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.
@@ -1,4 +1,4 @@
1
- import { formatTwoDigitNumber } from './helpers';
1
+ import { formatTwoDigitNumber, getTimezoneOffset } from './helpers';
2
2
  function getAllTimeZones() {
3
3
  return Intl.supportedValuesOf('timeZone');
4
4
  }
@@ -13,33 +13,11 @@ function formatTimezoneOffset(minutes) {
13
13
  return `UTC${sign}${hours}:${formatTwoDigitNumber(mins)}`;
14
14
  }
15
15
  }
16
- function getTimezoneDifferenceInMinutes(timezoneName, at = new Date()) {
17
- var _parts$find, _parts$find2, _parts$find3, _parts$find4, _parts$find5, _parts$find6;
18
- const dtf = new Intl.DateTimeFormat('en-US', {
19
- timeZone: timezoneName,
20
- hour12: false,
21
- year: 'numeric',
22
- month: '2-digit',
23
- day: '2-digit',
24
- hour: '2-digit',
25
- minute: '2-digit',
26
- second: '2-digit'
27
- });
28
- const parts = dtf.formatToParts(at);
29
- const y = Number((_parts$find = parts.find(p => p.type === 'year')) === null || _parts$find === void 0 ? void 0 : _parts$find.value);
30
- const mo = Number((_parts$find2 = parts.find(p => p.type === 'month')) === null || _parts$find2 === void 0 ? void 0 : _parts$find2.value) - 1;
31
- const d = Number((_parts$find3 = parts.find(p => p.type === 'day')) === null || _parts$find3 === void 0 ? void 0 : _parts$find3.value);
32
- const h = Number((_parts$find4 = parts.find(p => p.type === 'hour')) === null || _parts$find4 === void 0 ? void 0 : _parts$find4.value);
33
- const mi = Number((_parts$find5 = parts.find(p => p.type === 'minute')) === null || _parts$find5 === void 0 ? void 0 : _parts$find5.value);
34
- const s = Number((_parts$find6 = parts.find(p => p.type === 'second')) === null || _parts$find6 === void 0 ? void 0 : _parts$find6.value);
35
- const asUTC = Date.UTC(y, mo, d, h, mi, s);
36
- return Math.round((asUTC - at.getTime()) / 60000);
37
- }
38
16
  export function getSortedTimezones() {
39
17
  const timezones = getAllTimeZones();
40
18
  const now = new Date();
41
19
  return [...timezones, 'UTC'].map(tz => {
42
- const offset = getTimezoneDifferenceInMinutes(tz, now);
20
+ const offset = getTimezoneOffset(tz, now);
43
21
  const offsetFormatted = formatTimezoneOffset(offset);
44
22
  let displayName;
45
23
  if (tz === 'UTC') {
@@ -71,7 +49,7 @@ export function groupTimezonesByOffset(at = new Date()) {
71
49
  const groups = new Map();
72
50
  for (const tz of zones) {
73
51
  try {
74
- const diff = getTimezoneDifferenceInMinutes(tz, at);
52
+ const diff = getTimezoneOffset(tz, at);
75
53
  const arr = groups.get(diff);
76
54
  if (arr) {
77
55
  arr.push(tz);
@@ -91,7 +69,7 @@ export function groupTimezonesByOffset(at = new Date()) {
91
69
  return result;
92
70
  }
93
71
  export function formatTimezoneShort(timezone) {
94
- const offsetMinutes = getTimezoneDifferenceInMinutes(timezone, new Date());
72
+ const offsetMinutes = getTimezoneOffset(timezone, new Date());
95
73
  const formattedOffset = formatTimezoneOffset(offsetMinutes);
96
74
  if (formattedOffset === 'UTC+0' || formattedOffset === 'UTC-0') {
97
75
  return 'UTC';
@@ -20,3 +20,6 @@ export declare const getPeriodStart: (date: DateTimeStruct | DateStruct, period:
20
20
  export declare const getPeriodEnd: (date: DateTimeStruct | DateStruct, period: Period) => DateTimeStruct;
21
21
  export declare const dateToStruct: (date: Date, tzOffsetMinutes: number) => DateTimeStruct;
22
22
  export declare const structToDate: (ds: DateTimeStruct, tzOffsetMinutes: number) => Date;
23
+ export declare function getTimezoneOffset(timezoneName: string, at?: Date): number;
24
+ export declare const dateToStructTz: (date: Date, tzName: string) => DateTimeStruct;
25
+ export declare const structToDateTz: (ds: DateTimeStruct, tzName: string) => Date;
@@ -131,4 +131,35 @@ export const dateToStruct = (date, tzOffsetMinutes) => {
131
131
  export const structToDate = (ds, tzOffsetMinutes) => {
132
132
  const utcTime = Date.UTC(ds.year, ds.month - 1, ds.day, ds.hour, ds.minute, ds.second, ds.millisecond);
133
133
  return new Date(utcTime - tzOffsetMinutes * 60_000);
134
+ };
135
+ export function getTimezoneOffset(timezoneName, at = new Date()) {
136
+ var _parts$find, _parts$find2, _parts$find3, _parts$find4, _parts$find5, _parts$find6;
137
+ const dtf = new Intl.DateTimeFormat('en-US', {
138
+ timeZone: timezoneName,
139
+ hour12: false,
140
+ year: 'numeric',
141
+ month: '2-digit',
142
+ day: '2-digit',
143
+ hour: '2-digit',
144
+ minute: '2-digit',
145
+ second: '2-digit'
146
+ });
147
+ const parts = dtf.formatToParts(at);
148
+ const y = Number((_parts$find = parts.find(p => p.type === 'year')) === null || _parts$find === void 0 ? void 0 : _parts$find.value);
149
+ const mo = Number((_parts$find2 = parts.find(p => p.type === 'month')) === null || _parts$find2 === void 0 ? void 0 : _parts$find2.value) - 1;
150
+ const d = Number((_parts$find3 = parts.find(p => p.type === 'day')) === null || _parts$find3 === void 0 ? void 0 : _parts$find3.value);
151
+ const h = Number((_parts$find4 = parts.find(p => p.type === 'hour')) === null || _parts$find4 === void 0 ? void 0 : _parts$find4.value);
152
+ const mi = Number((_parts$find5 = parts.find(p => p.type === 'minute')) === null || _parts$find5 === void 0 ? void 0 : _parts$find5.value);
153
+ const s = Number((_parts$find6 = parts.find(p => p.type === 'second')) === null || _parts$find6 === void 0 ? void 0 : _parts$find6.value);
154
+ const asUTC = Date.UTC(y, mo, d, h, mi, s);
155
+ return Math.round((asUTC - at.getTime()) / 60000);
156
+ }
157
+ export const dateToStructTz = (date, tzName) => {
158
+ const tzOffsetMinutes = getTimezoneOffset(tzName, date);
159
+ return dateToStruct(date, tzOffsetMinutes);
160
+ };
161
+ export const structToDateTz = (ds, tzName) => {
162
+ const tentativeDate = new Date(Date.UTC(ds.year, ds.month - 1, ds.day, ds.hour, ds.minute, ds.second, ds.millisecond));
163
+ const tzOffsetMinutes = getTimezoneOffset(tzName, tentativeDate);
164
+ return structToDate(ds, tzOffsetMinutes);
134
165
  };
@@ -1,2 +1,3 @@
1
1
  export { CalendarSuperForm, type CalendarSuperFormProps } from './CalendarSuperForm';
2
2
  export { CalendarDropdown, type CalendarDropdownProps } from './CalendarDropdown';
3
+ export { dateToStruct, structToDate, dateToStructTz, structToDateTz, getTimezoneOffset } from './helpers';
package/Calendar/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { CalendarSuperForm } from './CalendarSuperForm';
2
- export { CalendarDropdown } from './CalendarDropdown';
2
+ export { CalendarDropdown } from './CalendarDropdown';
3
+ export { dateToStruct, structToDate, dateToStructTz, structToDateTz, getTimezoneOffset } from './helpers';
@@ -5,9 +5,12 @@ import { Text } from '@pushwoosh/kit-typography';
5
5
  import { DropdownMenuSectionRoot } from './styles';
6
6
  export const DropdownMenuSection = ({
7
7
  title,
8
+ bgColor,
8
9
  children
9
10
  }) => {
10
- return React.createElement(DropdownMenuSectionRoot, null, title && React.createElement(Horizontal, {
11
+ return React.createElement(DropdownMenuSectionRoot, {
12
+ "$bgColor": bgColor
13
+ }, title && React.createElement(Horizontal, {
11
14
  "$padding": "8px 12px"
12
15
  }, React.createElement(Text, {
13
16
  "$variant": "h5",
@@ -1,4 +1,5 @@
1
1
  import { type PropsWithChildren } from 'react';
2
2
  export type DropdownMenuSectionProps = PropsWithChildren<{
3
3
  title?: string;
4
+ bgColor?: string;
4
5
  }>;
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { Button, GhostButton } from './Button';
5
5
  export { CardMetric } from './CardMetric';
6
6
  export { Checkbox } from './Checkbox';
7
7
  export { Drawer, DrawerHeader, DrawerTitle, DrawerBody, DrawerDocs, useDocs, } from './Drawer';
8
- export { CalendarSuperForm, type CalendarSuperFormProps, CalendarDropdown, type CalendarDropdownProps, } from './Calendar';
8
+ export { CalendarSuperForm, type CalendarSuperFormProps, CalendarDropdown, type CalendarDropdownProps, dateToStruct, structToDate, dateToStructTz, structToDateTz, getTimezoneOffset, } from './Calendar';
9
9
  export { DatePicker, DatePickerField, DateTimePicker, DateTimePickerField, } from './DateTimePicker';
10
10
  export { DropdownMenu, DropdownMenuButton, DropdownMenuSection, DropdownMenuItem, } from './DropdownMenu';
11
11
  export { GetStartedPage } from './GetStartedPage';
package/index.js CHANGED
@@ -5,7 +5,7 @@ export { Button, GhostButton } from './Button';
5
5
  export { CardMetric } from './CardMetric';
6
6
  export { Checkbox } from './Checkbox';
7
7
  export { Drawer, DrawerHeader, DrawerTitle, DrawerBody, DrawerDocs, useDocs } from './Drawer';
8
- export { CalendarSuperForm, CalendarDropdown } from './Calendar';
8
+ export { CalendarSuperForm, CalendarDropdown, dateToStruct, structToDate, dateToStructTz, structToDateTz, getTimezoneOffset } from './Calendar';
9
9
  export { DatePicker, DatePickerField, DateTimePicker, DateTimePickerField } from './DateTimePicker';
10
10
  export { DropdownMenu, DropdownMenuButton, DropdownMenuSection, DropdownMenuItem } from './DropdownMenu';
11
11
  export { GetStartedPage } from './GetStartedPage';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.48",
3
+ "version": "1.1.50",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",