@pushwoosh/dumb-components 1.1.53 → 1.1.55
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/Calendar/CalendarDropdown/CalendarDropdown.js +39 -42
- package/Calendar/CalendarDropdown/helpers.d.ts +1 -1
- package/Calendar/CalendarDropdown/helpers.js +11 -6
- package/Calendar/CalendarDropdown/styles.d.ts +0 -58
- package/Calendar/CalendarDropdown/styles.js +3 -10
- package/Popover/styles.js +2 -2
- package/package.json +2 -2
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
2
|
import { Color } from '@pushwoosh/kit-constants';
|
|
4
3
|
import { Horizontal, useClickAway, Vertical } from '@pushwoosh/kit-helpers';
|
|
5
4
|
import { CalendarIcon } from '@pushwoosh/kit-icons';
|
|
6
5
|
import { stringifyValue } from './helpers';
|
|
7
|
-
import {
|
|
6
|
+
import { PopoverContent } from './styles';
|
|
8
7
|
import { Button } from '../../Button';
|
|
9
8
|
import { Chip } from '../../Chip';
|
|
9
|
+
import { Popover } from '../../Popover';
|
|
10
10
|
import { CalendarSuperForm } from '../CalendarSuperForm';
|
|
11
|
-
import { formatTimezoneShort } from '../helpers-tz';
|
|
12
11
|
export const CalendarDropdown = props => {
|
|
13
12
|
const {
|
|
14
13
|
mode,
|
|
@@ -16,27 +15,27 @@ export const CalendarDropdown = props => {
|
|
|
16
15
|
} = props;
|
|
17
16
|
const isRangePicker = mode === 'range-date' || mode === 'range-datetime';
|
|
18
17
|
const withTime = mode === 'single-datetime' || mode === 'range-datetime';
|
|
19
|
-
const
|
|
18
|
+
const buttonRef = useRef(null);
|
|
20
19
|
const popoverRef = useRef(null);
|
|
21
20
|
const [isShaking, setIsShaking] = useState(false);
|
|
22
|
-
const [
|
|
21
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
23
22
|
const [value, setValue] = useState(props.value ?? (isRangePicker ? [] : undefined));
|
|
24
|
-
const initialTimezone =
|
|
23
|
+
const initialTimezone = calendarProps.timezone || 'UTC';
|
|
25
24
|
const [timezone, setTimezone] = useState(initialTimezone);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
setValue(props.value ?? (isRangePicker ? [] : undefined));
|
|
27
|
+
}, [props.value, isRangePicker]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setTimezone(calendarProps.timezone || 'UTC');
|
|
30
|
+
}, [calendarProps.timezone]);
|
|
26
31
|
const closePopover = () => {
|
|
27
|
-
|
|
32
|
+
setIsOpen(false);
|
|
28
33
|
setValue(props.value ?? (isRangePicker ? [] : undefined));
|
|
29
34
|
setTimezone(initialTimezone);
|
|
30
35
|
};
|
|
31
|
-
useClickAway(
|
|
36
|
+
useClickAway(isOpen, popoverRef, closePopover);
|
|
32
37
|
const openPopover = () => {
|
|
33
|
-
|
|
34
|
-
const rect = rootRef.current.getBoundingClientRect();
|
|
35
|
-
setPopoverPosition({
|
|
36
|
-
top: rect.bottom + 4,
|
|
37
|
-
left: rect.left
|
|
38
|
-
});
|
|
39
|
-
}
|
|
38
|
+
setIsOpen(true);
|
|
40
39
|
};
|
|
41
40
|
const onChangeHandler = val => {
|
|
42
41
|
var _props$onChange;
|
|
@@ -44,25 +43,35 @@ export const CalendarDropdown = props => {
|
|
|
44
43
|
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, val);
|
|
45
44
|
};
|
|
46
45
|
const presets = 'presets' in props ? props.presets : undefined;
|
|
47
|
-
const noValue = isRangePicker ? (value === null || value === void 0 ? void 0 : value.length) === 0 : !value;
|
|
46
|
+
const noValue = isRangePicker ? ((value === null || value === void 0 ? void 0 : value.length) ?? 0) === 0 : !value;
|
|
48
47
|
let buttonText;
|
|
49
48
|
if (noValue) {
|
|
50
49
|
buttonText = isRangePicker ? 'Select period' : 'Select date';
|
|
51
50
|
} else {
|
|
52
|
-
buttonText = stringifyValue(value, withTime);
|
|
53
|
-
if (withTime) {
|
|
54
|
-
const timezoneShort = formatTimezoneShort(timezone);
|
|
55
|
-
buttonText += ` ${timezoneShort}`;
|
|
56
|
-
}
|
|
51
|
+
buttonText = stringifyValue(value, withTime, timezone);
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
return React.createElement(Horizontal, {
|
|
54
|
+
"$justifyContent": "start"
|
|
55
|
+
}, React.createElement(Button, {
|
|
56
|
+
boxRef: buttonRef,
|
|
57
|
+
type: "button",
|
|
58
|
+
color: "secondary",
|
|
59
|
+
icon: React.createElement(CalendarIcon, {
|
|
60
|
+
size: "medium",
|
|
61
|
+
view: "lined"
|
|
62
|
+
}),
|
|
63
|
+
onClick: () => isOpen ? closePopover() : openPopover(),
|
|
64
|
+
isOpen: isOpen
|
|
65
|
+
}, buttonText), React.createElement(Popover, {
|
|
66
|
+
open: isOpen,
|
|
67
|
+
anchorEl: buttonRef,
|
|
68
|
+
internalWindowRef: popoverRef,
|
|
69
|
+
windowWidth: 500,
|
|
70
|
+
position: "bottom-start",
|
|
71
|
+
zIndex: 10010
|
|
72
|
+
}, React.createElement(PopoverContent, {
|
|
60
73
|
"$isShaking": isShaking,
|
|
61
|
-
onAnimationEnd: () => setIsShaking(false)
|
|
62
|
-
style: {
|
|
63
|
-
top: `${popoverPosition.top}px`,
|
|
64
|
-
left: `${popoverPosition.left}px`
|
|
65
|
-
}
|
|
74
|
+
onAnimationEnd: () => setIsShaking(false)
|
|
66
75
|
}, React.createElement(Vertical, null, presets && presets.length > 0 && React.createElement(Horizontal, {
|
|
67
76
|
"$padding": {
|
|
68
77
|
horizontal: 16,
|
|
@@ -142,17 +151,5 @@ export const CalendarDropdown = props => {
|
|
|
142
151
|
closePopover();
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
|
-
}, "Apply"))));
|
|
146
|
-
return React.createElement(DropdownRoot, {
|
|
147
|
-
ref: rootRef
|
|
148
|
-
}, React.createElement(Button, {
|
|
149
|
-
type: "button",
|
|
150
|
-
color: "secondary",
|
|
151
|
-
icon: React.createElement(CalendarIcon, {
|
|
152
|
-
size: "medium",
|
|
153
|
-
view: "lined"
|
|
154
|
-
}),
|
|
155
|
-
onClick: () => popoverPosition ? closePopover() : openPopover(),
|
|
156
|
-
isOpen: !!popoverPosition
|
|
157
|
-
}, buttonText), popoverContent && createPortal(popoverContent, document.body));
|
|
154
|
+
}, "Apply"))))));
|
|
158
155
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type DateStruct, type DateTimeStruct, type RangeValue, type SingleValue } from '../types';
|
|
2
2
|
export declare function formatDate(val: DateStruct | DateTimeStruct, withTime?: boolean): string;
|
|
3
|
-
export declare const stringifyValue: (value: SingleValue<DateStruct | DateTimeStruct> | RangeValue<DateStruct | DateTimeStruct>, withTime?:
|
|
3
|
+
export declare const stringifyValue: (value: SingleValue<DateStruct | DateTimeStruct> | RangeValue<DateStruct | DateTimeStruct>, withTime: boolean, timezone?: string) => string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatTimezoneShort } from '../helpers-tz';
|
|
1
2
|
export function formatDate(val, withTime = true) {
|
|
2
3
|
const date = new Date(val.year, val.month - 1, val.day, 'hour' in val ? val.hour : 0, 'minute' in val ? val.minute : 0);
|
|
3
4
|
if (withTime) {
|
|
@@ -16,14 +17,18 @@ export function formatDate(val, withTime = true) {
|
|
|
16
17
|
year: 'numeric'
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
|
-
export const stringifyValue = (value, withTime) => {
|
|
20
|
+
export const stringifyValue = (value, withTime, timezone) => {
|
|
21
|
+
let result = '';
|
|
20
22
|
if (Array.isArray(value)) {
|
|
21
23
|
if (value.length === 0) return '';
|
|
22
|
-
if (value.length === 1)
|
|
23
|
-
if (value.length === 2)
|
|
24
|
+
if (value.length === 1) result = `${formatDate(value[0], withTime)} - ?`;
|
|
25
|
+
if (value.length === 2) result = `${formatDate(value[0], withTime)} – ${formatDate(value[1], withTime)}`;
|
|
26
|
+
} else if (value) {
|
|
27
|
+
result = formatDate(value, withTime);
|
|
24
28
|
}
|
|
25
|
-
if (
|
|
26
|
-
|
|
29
|
+
if (withTime) {
|
|
30
|
+
const timezoneShort = formatTimezoneShort(timezone);
|
|
31
|
+
result += ` ${timezoneShort}`;
|
|
27
32
|
}
|
|
28
|
-
return
|
|
33
|
+
return result;
|
|
29
34
|
};
|
|
@@ -1,61 +1,3 @@
|
|
|
1
|
-
export declare const DropdownRoot: import("styled-components").StyledComponent<"div", any, {
|
|
2
|
-
$alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
3
|
-
$alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
4
|
-
$bgColor?: string | undefined;
|
|
5
|
-
$border?: string | ({
|
|
6
|
-
top?: string | undefined;
|
|
7
|
-
right?: string | undefined;
|
|
8
|
-
bottom?: string | undefined;
|
|
9
|
-
left?: string | undefined;
|
|
10
|
-
} | {
|
|
11
|
-
horizontal: string;
|
|
12
|
-
top?: string | undefined;
|
|
13
|
-
bottom?: string | undefined;
|
|
14
|
-
} | {
|
|
15
|
-
vertical: string;
|
|
16
|
-
right?: string | undefined;
|
|
17
|
-
left?: string | undefined;
|
|
18
|
-
}) | undefined;
|
|
19
|
-
$borderRadius?: (string | number) | undefined;
|
|
20
|
-
$boxShadow?: string | undefined;
|
|
21
|
-
$gap?: (string | number) | undefined;
|
|
22
|
-
$gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
|
|
23
|
-
$justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
|
|
24
|
-
$justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
|
|
25
|
-
$margin?: (string | number) | ({
|
|
26
|
-
top?: (string | number) | undefined;
|
|
27
|
-
right?: (string | number) | undefined;
|
|
28
|
-
bottom?: (string | number) | undefined;
|
|
29
|
-
left?: (string | number) | undefined;
|
|
30
|
-
} | {
|
|
31
|
-
horizontal: string | number;
|
|
32
|
-
top?: (string | number) | undefined;
|
|
33
|
-
bottom?: (string | number) | undefined;
|
|
34
|
-
} | {
|
|
35
|
-
vertical: string | number;
|
|
36
|
-
right?: (string | number) | undefined;
|
|
37
|
-
left?: (string | number) | undefined;
|
|
38
|
-
}) | undefined;
|
|
39
|
-
$padding?: (string | number) | ({
|
|
40
|
-
top?: (string | number) | undefined;
|
|
41
|
-
right?: (string | number) | undefined;
|
|
42
|
-
bottom?: (string | number) | undefined;
|
|
43
|
-
left?: (string | number) | undefined;
|
|
44
|
-
} | {
|
|
45
|
-
horizontal: string | number;
|
|
46
|
-
top?: (string | number) | undefined;
|
|
47
|
-
bottom?: (string | number) | undefined;
|
|
48
|
-
} | {
|
|
49
|
-
vertical: string | number;
|
|
50
|
-
right?: (string | number) | undefined;
|
|
51
|
-
left?: (string | number) | undefined;
|
|
52
|
-
}) | undefined;
|
|
53
|
-
$placeItems?: "end" | "start" | "center" | "stretch" | undefined;
|
|
54
|
-
} & {
|
|
55
|
-
$gridAutoFlow: string;
|
|
56
|
-
} & {
|
|
57
|
-
$justifyContent: string;
|
|
58
|
-
}, "$gridAutoFlow" | "$justifyContent">;
|
|
59
1
|
export declare const PopoverContent: import("styled-components").StyledComponent<"div", any, {
|
|
60
2
|
$isShaking?: boolean;
|
|
61
3
|
}, never>;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import styled, { keyframes, css } from 'styled-components';
|
|
2
|
-
import { Shadow,
|
|
3
|
-
import { Horizontal } from '@pushwoosh/kit-helpers';
|
|
2
|
+
import { Shadow, Color } from '@pushwoosh/kit-constants';
|
|
4
3
|
const shakeAnimation = keyframes(["0%,100%{transform:translateX(0);}10%,30%,50%,70%,90%{transform:translateX(-4px);}20%,40%,60%,80%{transform:translateX(4px);}"]);
|
|
5
|
-
export const DropdownRoot = styled(Horizontal).attrs({
|
|
6
|
-
$justifyContent: 'start'
|
|
7
|
-
}).withConfig({
|
|
8
|
-
displayName: "DropdownRoot",
|
|
9
|
-
componentId: "sc-h6jz87-0"
|
|
10
|
-
})(["position:relative;"]);
|
|
11
4
|
export const PopoverContent = styled.div.withConfig({
|
|
12
5
|
displayName: "PopoverContent",
|
|
13
|
-
componentId: "sc-h6jz87-
|
|
14
|
-
})(["
|
|
6
|
+
componentId: "sc-h6jz87-0"
|
|
7
|
+
})(["overflow:hidden;box-shadow:", ";background:", ";", ""], Shadow.REGULAR, Color.CLEAR, ({
|
|
15
8
|
$isShaking
|
|
16
9
|
}) => $isShaking && css(["animation:", " 0.4s ease-in-out;"], shakeAnimation));
|
package/Popover/styles.js
CHANGED
|
@@ -8,11 +8,11 @@ export const PopoverContainer = styled.div.withConfig({
|
|
|
8
8
|
export const PopoverContainerWindow = styled.div.withConfig({
|
|
9
9
|
displayName: "PopoverContainerWindow",
|
|
10
10
|
componentId: "sc-qsqk3z-1"
|
|
11
|
-
})(["min-width:", ";border:1px solid ", ";border-radius:", ";background:", ";transition:visibility 50ms linear;> *{opacity:", ";}"], ({
|
|
11
|
+
})(["min-width:", ";border:1px solid ", ";border-radius:", ";background:", ";transition:visibility 50ms linear;> *{opacity:", ";}> *:first-child{border-top-left-radius:", ";border-top-right-radius:", ";}> *:last-child{border-bottom-left-radius:", ";border-bottom-right-radius:", ";}"], ({
|
|
12
12
|
$minWidth
|
|
13
13
|
}) => $minWidth ? `${$minWidth}px` : 'auto', Color.FORM, ShapeRadius.DIALOG, Color.CLEAR, ({
|
|
14
14
|
$isLoading
|
|
15
|
-
}) => $isLoading ? '0.5' : '1');
|
|
15
|
+
}) => $isLoading ? '0.5' : '1', ShapeRadius.DIALOG, ShapeRadius.DIALOG, ShapeRadius.DIALOG, ShapeRadius.DIALOG);
|
|
16
16
|
export const PopoverContainerPortal = styled(Tippy).withConfig({
|
|
17
17
|
displayName: "PopoverContainerPortal",
|
|
18
18
|
componentId: "sc-qsqk3z-2"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/dumb-components",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.55",
|
|
4
4
|
"description": "React components to build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"pre-commit": "check",
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
20
|
+
"node": ">= 20",
|
|
21
21
|
"npm": ">= 7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|