@pushwoosh/dumb-components 1.0.11 → 1.0.13

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.
Files changed (95) hide show
  1. package/DropdownMenu/components/DropdownMenu/DropdownMenu.d.ts +3 -3
  2. package/DropdownMenu/components/DropdownMenu/DropdownMenu.js +44 -25
  3. package/DropdownMenu/components/DropdownMenu/index.d.ts +1 -1
  4. package/DropdownMenu/components/DropdownMenu/index.js +1 -1
  5. package/DropdownMenu/components/DropdownMenu/styles.d.ts +28 -0
  6. package/DropdownMenu/components/DropdownMenu/styles.js +13 -0
  7. package/DropdownMenu/components/DropdownMenu/types.d.ts +11 -21
  8. package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.d.ts +3 -0
  9. package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.js +25 -0
  10. package/DropdownMenu/components/DropdownMenuButton/index.d.ts +1 -0
  11. package/DropdownMenu/components/DropdownMenuButton/index.js +1 -0
  12. package/DropdownMenu/components/DropdownMenuButton/types.d.ts +14 -0
  13. package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.d.ts +3 -5
  14. package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.js +25 -37
  15. package/DropdownMenu/components/DropdownMenuItem/index.d.ts +0 -2
  16. package/DropdownMenu/components/DropdownMenuItem/index.js +1 -2
  17. package/DropdownMenu/components/DropdownMenuItem/styles.d.ts +3 -4
  18. package/DropdownMenu/components/DropdownMenuItem/styles.js +9 -70
  19. package/DropdownMenu/components/DropdownMenuItem/types.d.ts +7 -24
  20. package/DropdownMenu/context.d.ts +1 -0
  21. package/DropdownMenu/context.js +2 -0
  22. package/DropdownMenu/index.d.ts +3 -9
  23. package/DropdownMenu/index.js +3 -9
  24. package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +3 -3
  25. package/EmailTemplatePreview/components/NoEmailTemplatePreview/assets/email.svg +5 -0
  26. package/Table/hooks/helpers.d.ts +3 -0
  27. package/Table/hooks/helpers.js +9 -0
  28. package/Table/hooks/index.d.ts +1 -1
  29. package/Table/hooks/index.js +1 -1
  30. package/Table/hooks/useDataTableGetParams.d.ts +11 -0
  31. package/Table/hooks/useDataTableGetParams.js +49 -0
  32. package/Table/index.d.ts +1 -1
  33. package/Table/index.js +1 -1
  34. package/index.d.ts +2 -2
  35. package/index.js +2 -2
  36. package/package.json +2 -1
  37. package/DropdownMenu/components/DropdownMenu/hooks.d.ts +0 -4
  38. package/DropdownMenu/components/DropdownMenu/hooks.js +0 -10
  39. package/DropdownMenu/components/DropdownMenuContainer/DropdownMenuContainer.d.ts +0 -3
  40. package/DropdownMenu/components/DropdownMenuContainer/DropdownMenuContainer.js +0 -79
  41. package/DropdownMenu/components/DropdownMenuContainer/index.d.ts +0 -1
  42. package/DropdownMenu/components/DropdownMenuContainer/index.js +0 -1
  43. package/DropdownMenu/components/DropdownMenuContainer/maps.d.ts +0 -26
  44. package/DropdownMenu/components/DropdownMenuContainer/maps.js +0 -11
  45. package/DropdownMenu/components/DropdownMenuContainer/styles.d.ts +0 -35
  46. package/DropdownMenu/components/DropdownMenuContainer/styles.js +0 -109
  47. package/DropdownMenu/components/DropdownMenuContainer/types.d.ts +0 -19
  48. package/DropdownMenu/components/DropdownMenuGroup/DropdownMenuGroup.d.ts +0 -3
  49. package/DropdownMenu/components/DropdownMenuGroup/DropdownMenuGroup.js +0 -12
  50. package/DropdownMenu/components/DropdownMenuGroup/index.d.ts +0 -1
  51. package/DropdownMenu/components/DropdownMenuGroup/index.js +0 -1
  52. package/DropdownMenu/components/DropdownMenuGroup/styles.d.ts +0 -1
  53. package/DropdownMenu/components/DropdownMenuGroup/styles.js +0 -7
  54. package/DropdownMenu/components/DropdownMenuGroup/types.d.ts +0 -5
  55. package/DropdownMenu/components/DropdownMenuGroup/types.js +0 -1
  56. package/DropdownMenu/components/DropdownMenuItemCheckbox/DropdownMenuItemCheckbox.d.ts +0 -3
  57. package/DropdownMenu/components/DropdownMenuItemCheckbox/DropdownMenuItemCheckbox.js +0 -9
  58. package/DropdownMenu/components/DropdownMenuItemCheckbox/index.d.ts +0 -1
  59. package/DropdownMenu/components/DropdownMenuItemCheckbox/index.js +0 -1
  60. package/DropdownMenu/components/DropdownMenuItemCheckbox/styles.d.ts +0 -1
  61. package/DropdownMenu/components/DropdownMenuItemCheckbox/styles.js +0 -8
  62. package/DropdownMenu/components/DropdownMenuItemPick/DropdownMenuItemPick.d.ts +0 -3
  63. package/DropdownMenu/components/DropdownMenuItemPick/DropdownMenuItemPick.js +0 -16
  64. package/DropdownMenu/components/DropdownMenuItemPick/index.d.ts +0 -1
  65. package/DropdownMenu/components/DropdownMenuItemPick/index.js +0 -1
  66. package/DropdownMenu/components/DropdownMenuItemPick/styles.d.ts +0 -3
  67. package/DropdownMenu/components/DropdownMenuItemPick/styles.js +0 -8
  68. package/DropdownMenu/components/DropdownMenuItemPick/types.d.ts +0 -2
  69. package/DropdownMenu/components/DropdownMenuItemPick/types.js +0 -1
  70. package/DropdownMenu/components/DropdownMenuItemRadio/DropdownMenuItemRadio.d.ts +0 -3
  71. package/DropdownMenu/components/DropdownMenuItemRadio/DropdownMenuItemRadio.js +0 -9
  72. package/DropdownMenu/components/DropdownMenuItemRadio/index.d.ts +0 -1
  73. package/DropdownMenu/components/DropdownMenuItemRadio/index.js +0 -1
  74. package/DropdownMenu/components/DropdownMenuItemRadio/styles.d.ts +0 -1
  75. package/DropdownMenu/components/DropdownMenuItemRadio/styles.js +0 -8
  76. package/DropdownMenu/components/DropdownMenuNested/DropdownMenuNested.d.ts +0 -3
  77. package/DropdownMenu/components/DropdownMenuNested/DropdownMenuNested.js +0 -69
  78. package/DropdownMenu/components/DropdownMenuNested/index.d.ts +0 -1
  79. package/DropdownMenu/components/DropdownMenuNested/index.js +0 -1
  80. package/DropdownMenu/components/DropdownMenuNested/styles.d.ts +0 -8
  81. package/DropdownMenu/components/DropdownMenuNested/styles.js +0 -35
  82. package/DropdownMenu/components/DropdownMenuNested/types.d.ts +0 -6
  83. package/DropdownMenu/components/DropdownMenuNested/types.js +0 -1
  84. package/DropdownMenu/components/DropdownMenuWindow/DropdownMenuWindow.d.ts +0 -3
  85. package/DropdownMenu/components/DropdownMenuWindow/DropdownMenuWindow.js +0 -12
  86. package/DropdownMenu/components/DropdownMenuWindow/index.d.ts +0 -1
  87. package/DropdownMenu/components/DropdownMenuWindow/index.js +0 -1
  88. package/DropdownMenu/components/DropdownMenuWindow/styles.d.ts +0 -1
  89. package/DropdownMenu/components/DropdownMenuWindow/styles.js +0 -7
  90. package/DropdownMenu/components/DropdownMenuWindow/types.d.ts +0 -5
  91. package/DropdownMenu/components/DropdownMenuWindow/types.js +0 -1
  92. package/EmailTemplatePreview/components/NoEmailTemplatePreview/assets/PW_logo.svg +0 -1
  93. package/Table/hooks/useDataTableParams.d.ts +0 -10
  94. package/Table/hooks/useDataTableParams.js +0 -39
  95. /package/DropdownMenu/components/{DropdownMenuContainer → DropdownMenuButton}/types.js +0 -0
@@ -1,3 +1,3 @@
1
- import { type ReactElement } from 'react';
2
- import type { DropdownMenuProps } from './types';
3
- export declare function DropdownMenu(props: DropdownMenuProps): ReactElement;
1
+ import { type FC } from 'react';
2
+ import { type DropdownMenuProps } from './types';
3
+ export declare const DropdownMenu: FC<DropdownMenuProps>;
@@ -1,27 +1,46 @@
1
- import React, { useCallback, useState } from 'react';
2
- import { DropdownMenuContainer } from '../DropdownMenuContainer';
3
- import { DropdownMenuProvider } from './hooks';
4
- export function DropdownMenu(props) {
5
- const [isAutoOpen, setIsAutoOpen] = useState(false);
1
+ import { autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
2
+ import React, { useEffect, useState } from 'react';
3
+ import { Place } from './styles';
4
+ import { DropdownContext } from '../../context';
5
+ const defaultPlacements = ['top-start', 'top-end', 'bottom-start', 'bottom-end'];
6
+ export const DropdownMenu = ({
7
+ renderHandler,
8
+ children,
9
+ menuZIndex,
10
+ menuPlacement
11
+ }) => {
12
+ const [isOpen, setIsOpen] = useState(false);
6
13
  const {
7
- windowZIndex = 999,
8
- windowPlacement = 'bottom-start',
9
- isOpen = isAutoOpen,
10
- children,
11
- onChangeIsOpen = setIsAutoOpen,
12
- ...rest
13
- } = props;
14
- const handleSetIsOpenFalse = useCallback(() => onChangeIsOpen(false), [onChangeIsOpen]);
15
- return React.createElement(DropdownMenuProvider, {
16
- value: {
17
- windowZIndex,
18
- closeDropdown: handleSetIsOpenFalse
14
+ refs,
15
+ floatingStyles
16
+ } = useFloating({
17
+ middleware: [offset(2), autoPlacement({
18
+ allowedPlacements: menuPlacement ? [menuPlacement] : defaultPlacements
19
+ })]
20
+ });
21
+ useEffect(() => {
22
+ if (isOpen) {
23
+ const handleClickListener = e => {
24
+ var _refs$floating$curren;
25
+ if (!((_refs$floating$curren = refs.floating.current) !== null && _refs$floating$curren !== void 0 && _refs$floating$curren.contains(e.target)) && !refs.reference.current.contains(e.target)) {
26
+ setIsOpen(false);
27
+ }
28
+ };
29
+ document.addEventListener('click', handleClickListener);
30
+ return () => {
31
+ document.removeEventListener('click', handleClickListener);
32
+ };
19
33
  }
20
- }, React.createElement(DropdownMenuContainer, {
21
- windowZIndex: windowZIndex,
22
- windowPlacement: windowPlacement,
23
- onChangeIsOpen: onChangeIsOpen,
24
- isOpen: isOpen,
25
- ...rest
26
- }, children));
27
- }
34
+ }, [isOpen, refs.floating, refs.reference]);
35
+ return React.createElement(DropdownContext.Provider, {
36
+ value: setIsOpen
37
+ }, renderHandler({
38
+ onClick: () => setIsOpen(prev => !prev),
39
+ ref: refs.setReference,
40
+ isOpen
41
+ }), isOpen && React.createElement(Place, {
42
+ ref: refs.setFloating,
43
+ style: floatingStyles,
44
+ "$zIndex": menuZIndex
45
+ }, typeof children === 'function' ? children() : children));
46
+ };
@@ -1,2 +1,2 @@
1
1
  export { DropdownMenu } from './DropdownMenu';
2
- export { DropdownMenuProvider, useDropdownMenuContext } from './hooks';
2
+ export { DropdownMenuSection } from './styles';
@@ -1,2 +1,2 @@
1
1
  export { DropdownMenu } from './DropdownMenu';
2
- export { DropdownMenuProvider, useDropdownMenuContext } from './hooks';
2
+ export { DropdownMenuSection } from './styles';
@@ -0,0 +1,28 @@
1
+ export declare const Place: 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
+ $gap?: string | number | undefined;
5
+ $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
6
+ $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
7
+ $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
8
+ $margin?: string | number | undefined;
9
+ $padding?: string | number | undefined;
10
+ $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
11
+ } & {
12
+ $gridAutoFlow: string;
13
+ } & {
14
+ $zIndex?: number;
15
+ }, "$gridAutoFlow">;
16
+ export declare const DropdownMenuSection: import("styled-components").StyledComponent<"div", any, {
17
+ $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
18
+ $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
19
+ $gap?: string | number | undefined;
20
+ $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
21
+ $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
22
+ $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
23
+ $margin?: string | number | undefined;
24
+ $padding?: string | number | undefined;
25
+ $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
26
+ } & {
27
+ $gridAutoFlow: string;
28
+ }, "$gridAutoFlow">;
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+ import { Color, Shadow, ShapeRadius, Spacing } from '@pushwoosh/kit-constants';
3
+ import { Vertical } from '@pushwoosh/kit-helpers';
4
+ export const Place = styled(Vertical).withConfig({
5
+ displayName: "Place",
6
+ componentId: "sc-ij8wqc-0"
7
+ })(["border:1px solid ", ";background-color:", ";min-width:200px;max-height:300px;overflow-y:auto;border-radius:", ";box-shadow:", ";z-index:", ";"], Color.FORM, Color.FROZEN, ShapeRadius.CONTROL, Shadow.REGULAR, ({
8
+ $zIndex
9
+ }) => $zIndex || 10);
10
+ export const DropdownMenuSection = styled(Vertical).withConfig({
11
+ displayName: "DropdownMenuSection",
12
+ componentId: "sc-ij8wqc-1"
13
+ })(["padding:", " 0;&:not(:first-child){border-top:1px solid ", ";}"], Spacing.S3, Color.FORM);
@@ -1,23 +1,13 @@
1
- import type { Ref, ReactNode } from 'react';
2
- type WindowPlacement = 'auto' | 'auto-start' | 'auto-end' | 'top' | 'bottom' | 'right' | 'left' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end';
3
- export type DropdownMenuProps = {
4
- readonly boxRef?: Ref<HTMLDivElement>;
5
- readonly title?: string | ReactNode;
6
- readonly color: 'primary' | 'secondary';
7
- readonly view: 'shape' | 'ghost';
8
- readonly minimal?: boolean;
9
- readonly hideChevron?: boolean;
10
- readonly icon?: ReactNode;
11
- readonly iconPlacement?: 'left' | 'right';
12
- readonly windowPlacement?: WindowPlacement;
13
- readonly windowZIndex?: number;
14
- readonly isDisabled?: boolean;
15
- readonly isOpen?: boolean;
16
- readonly onChangeIsOpen?: (isOpen: boolean) => void;
17
- readonly children: ReactNode;
1
+ import { type ReferenceType, type Placement } from '@floating-ui/react-dom';
2
+ import type { ReactNode } from 'react';
3
+ export type HandlerProps = {
4
+ onClick: () => void;
5
+ ref: (el: ReferenceType | null) => void;
6
+ isOpen: boolean;
18
7
  };
19
- export type DropdownMenuContext = {
20
- readonly closeDropdown: () => void;
21
- readonly windowZIndex: number;
8
+ export type DropdownMenuProps = {
9
+ renderHandler: (args: HandlerProps) => ReactNode;
10
+ children: (() => ReactNode) | ReactNode;
11
+ menuZIndex?: number;
12
+ menuPlacement?: Placement;
22
13
  };
23
- export {};
@@ -0,0 +1,3 @@
1
+ import { type FC } from 'react';
2
+ import { type DropdownMenuButtonProps } from './types';
3
+ export declare const DropdownMenuButton: FC<DropdownMenuButtonProps>;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { Button } from '../../../Button';
3
+ import { DropdownMenu } from '../DropdownMenu';
4
+ export const DropdownMenuButton = ({
5
+ label,
6
+ menuZIndex,
7
+ menuPlacement,
8
+ children,
9
+ ...buttonProps
10
+ }) => {
11
+ return React.createElement(DropdownMenu, {
12
+ menuZIndex: menuZIndex,
13
+ menuPlacement: menuPlacement,
14
+ renderHandler: ({
15
+ ref,
16
+ onClick,
17
+ isOpen
18
+ }) => React.createElement(Button, {
19
+ ...buttonProps,
20
+ boxRef: ref,
21
+ onClick: onClick,
22
+ isOpen: isOpen
23
+ }, label)
24
+ }, children);
25
+ };
@@ -0,0 +1 @@
1
+ export { DropdownMenuButton } from './DropdownMenuButton';
@@ -0,0 +1 @@
1
+ export { DropdownMenuButton } from './DropdownMenuButton';
@@ -0,0 +1,14 @@
1
+ import { type Placement } from '@floating-ui/react-dom';
2
+ import { type ReactNode } from 'react';
3
+ import { type RequiredButtonProps } from '../../../Button';
4
+ export type DropdownMenuButtonProps = {
5
+ label: ReactNode;
6
+ menuZIndex?: number;
7
+ menuPlacement?: Placement;
8
+ color: RequiredButtonProps['color'];
9
+ size?: RequiredButtonProps['size'];
10
+ view?: RequiredButtonProps['view'];
11
+ icon?: RequiredButtonProps['icon'];
12
+ rightIcon?: RequiredButtonProps['rightIcon'];
13
+ children: (() => ReactNode) | ReactNode;
14
+ };
@@ -1,5 +1,3 @@
1
- import { type ReactElement } from 'react';
2
- import type { DropdownMenuItemPropsWithoutAs, DropdownMenuItemPropsWithAsTag, DropdownMenuItemPropsWithAsComponent } from './types';
3
- export declare function DropdownMenuItem(props: DropdownMenuItemPropsWithoutAs): ReactElement;
4
- export declare function DropdownMenuItem<AS extends keyof HTMLElementTagNameMap>(props: DropdownMenuItemPropsWithAsTag<AS>): ReactElement;
5
- export declare function DropdownMenuItem<OuterProps extends object>(props: DropdownMenuItemPropsWithAsComponent<OuterProps>): ReactElement;
1
+ import { type FC } from 'react';
2
+ import { type DropdownMenuItemProps } from './types';
3
+ export declare const DropdownMenuItem: FC<DropdownMenuItemProps>;
@@ -1,38 +1,26 @@
1
- import React, { useCallback } from 'react';
2
- import { useDropdownMenuContext } from '../DropdownMenu';
3
- import { DropdownMenuItemBox } from './styles';
4
- export function DropdownMenuItem(props) {
5
- const {
6
- boxRef,
7
- color,
8
- isInteractive,
9
- isDisabled,
10
- onClick,
11
- onChange,
12
- ...rest
13
- } = props;
14
- const {
15
- closeDropdown
16
- } = useDropdownMenuContext();
17
- const handleClick = useCallback(event => {
18
- onClick === null || onClick === void 0 || onClick(event);
19
- if (!isInteractive && !isDisabled && !onChange) {
20
- closeDropdown();
1
+ import React, { useContext } from 'react';
2
+ import { DropdownMenuItemStyled } from './styles';
3
+ import { DropdownContext } from '../../context';
4
+ export const DropdownMenuItem = ({
5
+ children,
6
+ onClick,
7
+ isActive,
8
+ isDanger,
9
+ disabled
10
+ }) => {
11
+ const onClickContext = useContext(DropdownContext);
12
+ if (process.env.NODE_ENV === 'development') {
13
+ if (!onClickContext) {
14
+ console.error('DropdownMenuItem must be inside DropdownMenu');
21
15
  }
22
- }, [isDisabled, isInteractive, onClick, onChange, closeDropdown]);
23
- const handleChange = useCallback(event => {
24
- onChange === null || onChange === void 0 || onChange(event);
25
- if (!isInteractive && !isDisabled) {
26
- closeDropdown();
27
- }
28
- }, [isDisabled, isInteractive, onChange, closeDropdown]);
29
- return React.createElement(DropdownMenuItemBox, {
30
- ref: boxRef,
31
- "$color": color,
32
- "$isDisabled": isDisabled,
33
- disabled: isDisabled,
34
- onClick: handleClick,
35
- onChange: handleChange,
36
- ...rest
37
- });
38
- }
16
+ }
17
+ return React.createElement(DropdownMenuItemStyled, {
18
+ "$active": isActive,
19
+ "$danger": isDanger,
20
+ onClick: () => {
21
+ onClickContext === null || onClickContext === void 0 || onClickContext(false);
22
+ onClick();
23
+ },
24
+ disabled: disabled
25
+ }, children);
26
+ };
@@ -1,3 +1 @@
1
1
  export { DropdownMenuItem } from './DropdownMenuItem';
2
- export { DropdownMenuItemBox } from './styles';
3
- export type { DropdownMenuItemColor } from './types';
@@ -1,2 +1 @@
1
- export { DropdownMenuItem } from './DropdownMenuItem';
2
- export { DropdownMenuItemBox } from './styles';
1
+ export { DropdownMenuItem } from './DropdownMenuItem';
@@ -1,5 +1,4 @@
1
- import type { DropdownMenuItemColor } from './types';
2
- export declare const DropdownMenuItemBox: import("styled-components").StyledComponent<"a", any, {
3
- $color: DropdownMenuItemColor;
4
- $isDisabled?: boolean;
1
+ export declare const DropdownMenuItemStyled: import("styled-components").StyledComponent<"button", any, {
2
+ $active?: boolean;
3
+ $danger?: boolean;
5
4
  }, never>;
@@ -1,73 +1,12 @@
1
1
  import styled from 'styled-components';
2
- import { Color, FontSize, FontWeight, LineHeight, Spacing } from '@pushwoosh/kit-constants';
3
- export const DropdownMenuItemBox = styled.a.withConfig({
4
- displayName: "DropdownMenuItemBox",
2
+ import { Color, Spacing, UnitSize } from '@pushwoosh/kit-constants';
3
+ export const DropdownMenuItemStyled = styled.button.withConfig({
4
+ displayName: "DropdownMenuItemStyled",
5
5
  componentId: "sc-1wmyvxp-0"
6
- })(["display:block;width:100%;padding:", " ", ";appearance:none;background:transparent;border:none;color:", ";font-size:", ";font-weight:", ";line-height:", ";white-space:nowrap;text-decoration:none;text-align:left;cursor:", ";user-select:none;&:hover{background:", ";color:", ";text-decoration:none;}&:active{background:", ";color:", ";pointer-events:", ";}"], Spacing.S3, Spacing.S4, ({
7
- $color,
8
- $isDisabled
6
+ })(["appearance:none;display:flex;align-items:center;padding:0 ", ";height:", ";border:none;color:", ";background:none;cursor:pointer;&:hover{background:", ";color:", ";}&:disabled{color:", ";cursor:not-allowed;}"], Spacing.S3, UnitSize.FIELD_HEIGHT, ({
7
+ $active,
8
+ $danger
9
9
  }) => {
10
- if ($isDisabled) {
11
- return Color.LOCKED;
12
- }
13
- switch ($color) {
14
- case 'primary':
15
- return Color.PRIMARY;
16
- case 'danger':
17
- return Color.DANGER;
18
- default:
19
- return Color.MAIN;
20
- }
21
- }, FontSize.REGULAR, FontWeight.REGULAR, LineHeight.REGULAR, ({
22
- $isDisabled
23
- }) => $isDisabled ? 'not-allowed' : 'pointer', ({
24
- $isDisabled
25
- }) => $isDisabled ? 'transparent' : Color.SOFT_LIGHT, ({
26
- $color,
27
- $isDisabled
28
- }) => {
29
- if ($isDisabled) {
30
- return Color.LOCKED;
31
- }
32
- switch ($color) {
33
- case 'primary':
34
- return Color.PRIMARY_HOVER;
35
- case 'danger':
36
- return Color.DANGER_HOVER;
37
- default:
38
- return Color.MAIN;
39
- }
40
- }, ({
41
- $color,
42
- $isDisabled
43
- }) => {
44
- if ($isDisabled) {
45
- return 'transparent';
46
- }
47
- switch ($color) {
48
- case 'primary':
49
- return Color.BRIGHT_LIGHT;
50
- case 'danger':
51
- return Color.DANGER_LIGHT;
52
- default:
53
- return Color.BRIGHT_LIGHT;
54
- }
55
- }, ({
56
- $color,
57
- $isDisabled
58
- }) => {
59
- if ($isDisabled) {
60
- return Color.LOCKED;
61
- }
62
- switch ($color) {
63
- case 'primary':
64
- return Color.PRIMARY_PRESSED;
65
- case 'danger':
66
- return Color.DANGER_PRESSED;
67
- default:
68
- return Color.PRIMARY_PRESSED;
69
- }
70
- }, ({
71
- $isDisabled
72
- }) => $isDisabled ? 'none' : 'auto');
73
- DropdownMenuItemBox.displayName = 'DropdownMenuItemBox';
10
+ if ($danger) return Color.DANGER;
11
+ return $active ? Color.PRIMARY : Color.MAIN;
12
+ }, Color.SOFT_LIGHT, Color.MAIN, Color.LOCKED);
@@ -1,24 +1,7 @@
1
- import type { JSX, Ref, ComponentType } from 'react';
2
- export type DropdownMenuItemColor = 'main' | 'primary' | 'danger';
3
- export type DropdownMenuItemPropsWithoutAs = Omit<JSX.IntrinsicElements['a'], 'ref'> & {
4
- readonly boxRef?: Ref<HTMLAnchorElement>;
5
- readonly color: DropdownMenuItemColor;
6
- readonly title: string;
7
- readonly href: string;
8
- readonly isInteractive?: boolean;
9
- readonly isDisabled?: boolean;
10
- };
11
- export type DropdownMenuItemPropsWithAsTag<AS extends keyof HTMLElementTagNameMap> = Omit<JSX.IntrinsicElements[AS], 'ref'> & {
12
- readonly boxRef?: Ref<HTMLElementTagNameMap[AS]>;
13
- readonly as: AS;
14
- readonly color: DropdownMenuItemColor;
15
- readonly isInteractive?: boolean;
16
- readonly isDisabled?: boolean;
17
- };
18
- export type DropdownMenuItemPropsWithAsComponent<OuterProps extends object> = OuterProps & {
19
- readonly boxRef?: Ref<HTMLElement>;
20
- readonly as: ComponentType<OuterProps>;
21
- readonly color: DropdownMenuItemColor;
22
- readonly isInteractive?: boolean;
23
- readonly isDisabled?: boolean;
24
- };
1
+ import type { PropsWithChildren } from 'react';
2
+ export type DropdownMenuItemProps = PropsWithChildren<{
3
+ onClick: () => void;
4
+ isActive?: boolean;
5
+ isDanger?: boolean;
6
+ disabled?: boolean;
7
+ }>;
@@ -0,0 +1 @@
1
+ export declare const DropdownContext: import("react").Context<((isOpen: false) => void) | null>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const DropdownContext = createContext(null);
@@ -1,9 +1,3 @@
1
- export { DropdownMenu, DropdownMenuProvider, useDropdownMenuContext } from './components/DropdownMenu';
2
- export { DropdownMenuContainer } from './components/DropdownMenuContainer';
3
- export { DropdownMenuGroup } from './components/DropdownMenuGroup';
4
- export { DropdownMenuItem, DropdownMenuItemBox, type DropdownMenuItemColor } from './components/DropdownMenuItem';
5
- export { DropdownMenuItemCheckbox } from './components/DropdownMenuItemCheckbox';
6
- export { DropdownMenuItemPick } from './components/DropdownMenuItemPick';
7
- export { DropdownMenuItemRadio } from './components/DropdownMenuItemRadio';
8
- export { DropdownMenuNested } from './components/DropdownMenuNested';
9
- export { DropdownMenuWindow } from './components/DropdownMenuWindow';
1
+ export { DropdownMenu, DropdownMenuSection } from './components/DropdownMenu';
2
+ export { DropdownMenuButton } from './components/DropdownMenuButton';
3
+ export { DropdownMenuItem } from './components/DropdownMenuItem';
@@ -1,9 +1,3 @@
1
- export { DropdownMenu, DropdownMenuProvider, useDropdownMenuContext } from './components/DropdownMenu';
2
- export { DropdownMenuContainer } from './components/DropdownMenuContainer';
3
- export { DropdownMenuGroup } from './components/DropdownMenuGroup';
4
- export { DropdownMenuItem, DropdownMenuItemBox } from './components/DropdownMenuItem';
5
- export { DropdownMenuItemCheckbox } from './components/DropdownMenuItemCheckbox';
6
- export { DropdownMenuItemPick } from './components/DropdownMenuItemPick';
7
- export { DropdownMenuItemRadio } from './components/DropdownMenuItemRadio';
8
- export { DropdownMenuNested } from './components/DropdownMenuNested';
9
- export { DropdownMenuWindow } from './components/DropdownMenuWindow';
1
+ export { DropdownMenu, DropdownMenuSection } from './components/DropdownMenu';
2
+ export { DropdownMenuButton } from './components/DropdownMenuButton';
3
+ export { DropdownMenuItem } from './components/DropdownMenuItem';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { Spacing } from '@pushwoosh/kit-constants';
3
3
  import { Vertical } from '@pushwoosh/kit-helpers';
4
- import PwLogo from './assets/PW_logo.svg?url';
4
+ import Email from './assets/email.svg?url';
5
5
  import { Container, PreviewMock } from './styles';
6
6
  import { LockedText, LockedTitle } from '../../../common';
7
7
  export function NoEmailTemplatePreview() {
@@ -12,8 +12,8 @@ export function NoEmailTemplatePreview() {
12
12
  "$alignItems": "center",
13
13
  "$justifyContent": "center"
14
14
  }, React.createElement("img", {
15
- src: PwLogo,
16
- alt: "Application logo"
15
+ src: Email,
16
+ alt: "Email envelop icon"
17
17
  })), React.createElement(Vertical, null, React.createElement(LockedTitle, null, "Content missed..."), React.createElement(LockedText, {
18
18
  "$small": true
19
19
  }, "Might be old data or deleted presets")));
@@ -0,0 +1,5 @@
1
+ <svg width="40" height="41" viewBox="0 0 40 41" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g id="logo - for light bg - outlines" opacity="0.5">
3
+ <path id="shape" fill-rule="evenodd" clip-rule="evenodd" d="M9.16671 9.25C7.09564 9.25 5.41671 10.9289 5.41671 13V13.393C5.41644 13.408 5.41644 13.423 5.41671 13.438V28C5.41671 30.0711 7.09564 31.75 9.16671 31.75H30.8334C32.9044 31.75 34.5834 30.0711 34.5834 28V13.44C34.5837 13.4237 34.5837 13.4074 34.5834 13.391V13C34.5834 10.9289 32.9044 9.25 30.8334 9.25H9.16671ZM32.0484 12.7053C31.9159 12.1571 31.4222 11.75 30.8334 11.75H9.16671C8.57788 11.75 8.08415 12.1571 7.95166 12.7052L20.0001 19.4825L32.0484 12.7053ZM7.91671 15.554V28C7.91671 28.6904 8.47635 29.25 9.16671 29.25H30.8334C31.5237 29.25 32.0834 28.6904 32.0834 28V15.554L20.6129 22.0061C20.2324 22.2202 19.7677 22.2202 19.3872 22.0061L7.91671 15.554Z" fill="#7694B8" fill-opacity="0.2"/>
4
+ </g>
5
+ </svg>
@@ -0,0 +1,3 @@
1
+ export declare function pickBy<T extends Record<string, any>>(obj: T): Record<string, any>;
2
+ export declare function mapKeys<T extends Record<string, any>, K extends string>(obj: T, mapper: (key: string) => K): Record<K, T[keyof T]>;
3
+ export declare function shallowEqual<T extends Record<string, any>>(a: T, b: T): boolean;
@@ -0,0 +1,9 @@
1
+ export function pickBy(obj) {
2
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => !!value));
3
+ }
4
+ export function mapKeys(obj, mapper) {
5
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [mapper(key), value]));
6
+ }
7
+ export function shallowEqual(a, b) {
8
+ return Object.keys(a).every(key => a[key] === b[key]);
9
+ }
@@ -1,2 +1,2 @@
1
1
  export { useDataTableContext } from './useDataTableContext';
2
- export { useDataTableParams } from './useDataTableParams';
2
+ export { useDataTableGetParams } from './useDataTableGetParams';
@@ -1,2 +1,2 @@
1
1
  export { useDataTableContext } from './useDataTableContext';
2
- export { useDataTableParams } from './useDataTableParams';
2
+ export { useDataTableGetParams } from './useDataTableGetParams';
@@ -0,0 +1,11 @@
1
+ import type { DataTableParams } from '../types';
2
+ type UseDataTableParamsParams<P extends DataTableParams> = {
3
+ defaultOrder: string;
4
+ defaultDirection?: 'asc' | 'desc';
5
+ defaultPerPage?: number;
6
+ customizeParams?: (obj: Record<string, string>, params: DataTableParams) => P;
7
+ prefix?: string;
8
+ };
9
+ type UseDataTableParamsReturn<P> = readonly [P, (params: P) => void];
10
+ export declare function useDataTableGetParams<P extends DataTableParams>({ defaultOrder, defaultDirection, defaultPerPage, customizeParams, prefix, }: UseDataTableParamsParams<P>): UseDataTableParamsReturn<P>;
11
+ export {};
@@ -0,0 +1,49 @@
1
+ import { useMemo, useRef } from 'react';
2
+ import { useHistory, useLocation } from 'react-router-dom';
3
+ import { usePersistentFunction } from '@pushwoosh/kit-helpers';
4
+ import { mapKeys, pickBy, shallowEqual } from './helpers';
5
+ export function useDataTableGetParams({
6
+ defaultOrder,
7
+ defaultDirection = 'asc',
8
+ defaultPerPage = 10,
9
+ customizeParams,
10
+ prefix = ''
11
+ }) {
12
+ const history = useHistory();
13
+ const {
14
+ search: locationSearch
15
+ } = useLocation();
16
+ const customizeParamsRef = useRef(customizeParams);
17
+ customizeParamsRef.current = customizeParams;
18
+ const prevDataTableParamsRef = useRef({});
19
+ const dataTableParams = useMemo(() => {
20
+ const searchParams = new URLSearchParams(locationSearch);
21
+ const searchParamsWoPrefix = mapKeys(Object.fromEntries(searchParams), key => key.startsWith(prefix) ? key.slice(prefix.length) : key);
22
+ // eslint-disable-next-line no-nested-ternary
23
+ const realOrderDirection = !searchParamsWoPrefix.direction ? defaultDirection : searchParamsWoPrefix.direction === 'asc' ? 'asc' : 'desc';
24
+ const params = {
25
+ search: searchParamsWoPrefix.search ?? '',
26
+ order: searchParamsWoPrefix.order || defaultOrder,
27
+ direction: realOrderDirection,
28
+ page: +searchParamsWoPrefix.page || 1,
29
+ perPage: +searchParamsWoPrefix.perPage || defaultPerPage
30
+ };
31
+ // it is necessary to compare with the previous parameters so that there are no extra rerenders
32
+ const resultParams = customizeParamsRef.current ? customizeParamsRef.current(searchParamsWoPrefix, params) : params;
33
+ if (!shallowEqual(resultParams, prevDataTableParamsRef.current)) {
34
+ prevDataTableParamsRef.current = resultParams;
35
+ }
36
+ return prevDataTableParamsRef.current;
37
+ }, [locationSearch, defaultDirection, defaultOrder, defaultPerPage, prefix]);
38
+ const changeDataTableParams = usePersistentFunction(params => {
39
+ const searchParams = new URLSearchParams(locationSearch);
40
+ const paramsWithPrefix = pickBy(mapKeys(params, key => `${prefix}${key}`));
41
+ Object.entries(paramsWithPrefix).forEach(([key, value]) => {
42
+ searchParams.set(key, value);
43
+ });
44
+ history.push({
45
+ search: searchParams.toString()
46
+ });
47
+ });
48
+ return [dataTableParams, changeDataTableParams];
49
+ }
package/Table/index.d.ts CHANGED
@@ -8,6 +8,6 @@ export { DataTableSortableCell } from './components/DataTableSortableCell';
8
8
  export { Loading } from './components/Loading';
9
9
  export { TableList } from './components/TableList';
10
10
  export { TablePagination } from './components/TablePagination';
11
- export { useDataTableContext, useDataTableParams } from './hooks';
11
+ export { useDataTableContext, useDataTableGetParams } from './hooks';
12
12
  export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, } from './styles';
13
13
  export type { DataTableParams, DataTableData, DataTableContextType } from './types';
package/Table/index.js CHANGED
@@ -8,5 +8,5 @@ export { DataTableSortableCell } from './components/DataTableSortableCell';
8
8
  export { Loading } from './components/Loading';
9
9
  export { TableList } from './components/TableList';
10
10
  export { TablePagination } from './components/TablePagination';
11
- export { useDataTableContext, useDataTableParams } from './hooks';
11
+ export { useDataTableContext, useDataTableGetParams } from './hooks';
12
12
  export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description } from './styles';
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 { DropdownMenu, DropdownMenuProvider, useDropdownMenuContext, DropdownMenuContainer, DropdownMenuGroup, DropdownMenuItem, DropdownMenuItemBox, DropdownMenuItemCheckbox, DropdownMenuItemPick, DropdownMenuItemRadio, DropdownMenuNested, DropdownMenuWindow, } from './DropdownMenu';
8
+ export { DropdownMenu, DropdownMenuButton, DropdownMenuSection, DropdownMenuItem, } from './DropdownMenu';
9
9
  export { EditableField } from './EditableField';
10
10
  export { InputFile } from './InputFile';
11
11
  export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter, } from './Modal';
@@ -26,7 +26,7 @@ export { StatisticCard } from './StatisticCard';
26
26
  export { EmailTemplatePreview, NoEmailTemplatePreview } from './EmailTemplatePreview';
27
27
  export { PushPreview } from './PushPreview';
28
28
  export { Toast, ToastProvider, useToast } from './Toast';
29
- export { ClearableInput, DataTable, DataTableList, DataTableGetContext, DataTablePagination, DataTableSearchInput, DataTableSortableCell, Loading, TableList, TablePagination, useDataTableContext, useDataTableParams, Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, type DataTableParams, type DataTableData, type DataTableContextType, } from './Table';
29
+ export { ClearableInput, DataTable, DataTableList, DataTableGetContext, DataTablePagination, DataTableSearchInput, DataTableSortableCell, Loading, TableList, TablePagination, useDataTableContext, useDataTableGetParams, Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, type DataTableParams, type DataTableData, type DataTableContextType, } from './Table';
30
30
  export { AutosizeInput, PageHeader, PageHeaderEditable } from './PageHeader';
31
31
  export { ExportResult } from './ExportResult';
32
32
  export { NativeInput, NativeTextarea, NativeSelect } from './native';