@pushwoosh/dumb-components 1.1.54 → 1.1.56
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 +30 -39
- 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
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
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,10 +15,10 @@ 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
23
|
const initialTimezone = calendarProps.timezone || 'UTC';
|
|
25
24
|
const [timezone, setTimezone] = useState(initialTimezone);
|
|
@@ -30,19 +29,13 @@ export const CalendarDropdown = props => {
|
|
|
30
29
|
setTimezone(calendarProps.timezone || 'UTC');
|
|
31
30
|
}, [calendarProps.timezone]);
|
|
32
31
|
const closePopover = () => {
|
|
33
|
-
|
|
32
|
+
setIsOpen(false);
|
|
34
33
|
setValue(props.value ?? (isRangePicker ? [] : undefined));
|
|
35
34
|
setTimezone(initialTimezone);
|
|
36
35
|
};
|
|
37
|
-
useClickAway(
|
|
36
|
+
useClickAway(isOpen, popoverRef, closePopover);
|
|
38
37
|
const openPopover = () => {
|
|
39
|
-
|
|
40
|
-
const rect = rootRef.current.getBoundingClientRect();
|
|
41
|
-
setPopoverPosition({
|
|
42
|
-
top: rect.bottom + 4,
|
|
43
|
-
left: rect.left
|
|
44
|
-
});
|
|
45
|
-
}
|
|
38
|
+
setIsOpen(true);
|
|
46
39
|
};
|
|
47
40
|
const onChangeHandler = val => {
|
|
48
41
|
var _props$onChange;
|
|
@@ -55,20 +48,30 @@ export const CalendarDropdown = props => {
|
|
|
55
48
|
if (noValue) {
|
|
56
49
|
buttonText = isRangePicker ? 'Select period' : 'Select date';
|
|
57
50
|
} else {
|
|
58
|
-
buttonText = stringifyValue(value, withTime);
|
|
59
|
-
if (withTime) {
|
|
60
|
-
const timezoneShort = formatTimezoneShort(timezone);
|
|
61
|
-
buttonText += ` ${timezoneShort}`;
|
|
62
|
-
}
|
|
51
|
+
buttonText = stringifyValue(value, withTime, timezone);
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
|
|
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, {
|
|
66
73
|
"$isShaking": isShaking,
|
|
67
|
-
onAnimationEnd: () => setIsShaking(false)
|
|
68
|
-
style: {
|
|
69
|
-
top: `${popoverPosition.top}px`,
|
|
70
|
-
left: `${popoverPosition.left}px`
|
|
71
|
-
}
|
|
74
|
+
onAnimationEnd: () => setIsShaking(false)
|
|
72
75
|
}, React.createElement(Vertical, null, presets && presets.length > 0 && React.createElement(Horizontal, {
|
|
73
76
|
"$padding": {
|
|
74
77
|
horizontal: 16,
|
|
@@ -148,17 +151,5 @@ export const CalendarDropdown = props => {
|
|
|
148
151
|
closePopover();
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
|
-
}, "Apply"))));
|
|
152
|
-
return React.createElement(DropdownRoot, {
|
|
153
|
-
ref: rootRef
|
|
154
|
-
}, React.createElement(Button, {
|
|
155
|
-
type: "button",
|
|
156
|
-
color: "secondary",
|
|
157
|
-
icon: React.createElement(CalendarIcon, {
|
|
158
|
-
size: "medium",
|
|
159
|
-
view: "lined"
|
|
160
|
-
}),
|
|
161
|
-
onClick: () => popoverPosition ? closePopover() : openPopover(),
|
|
162
|
-
isOpen: !!popoverPosition
|
|
163
|
-
}, buttonText), popoverContent && createPortal(popoverContent, document.body));
|
|
154
|
+
}, "Apply"))))));
|
|
164
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.56",
|
|
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": {
|