@pushwoosh/dumb-components 1.0.12 → 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.
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.d.ts +3 -3
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.js +44 -25
- package/DropdownMenu/components/DropdownMenu/index.d.ts +1 -1
- package/DropdownMenu/components/DropdownMenu/index.js +1 -1
- package/DropdownMenu/components/DropdownMenu/styles.d.ts +28 -0
- package/DropdownMenu/components/DropdownMenu/styles.js +13 -0
- package/DropdownMenu/components/DropdownMenu/types.d.ts +11 -21
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.d.ts +3 -0
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.js +25 -0
- package/DropdownMenu/components/DropdownMenuButton/index.d.ts +1 -0
- package/DropdownMenu/components/DropdownMenuButton/index.js +1 -0
- package/DropdownMenu/components/DropdownMenuButton/types.d.ts +14 -0
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.d.ts +3 -5
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.js +25 -37
- package/DropdownMenu/components/DropdownMenuItem/index.d.ts +0 -2
- package/DropdownMenu/components/DropdownMenuItem/index.js +1 -2
- package/DropdownMenu/components/DropdownMenuItem/styles.d.ts +3 -4
- package/DropdownMenu/components/DropdownMenuItem/styles.js +9 -70
- package/DropdownMenu/components/DropdownMenuItem/types.d.ts +7 -24
- package/DropdownMenu/context.d.ts +1 -0
- package/DropdownMenu/context.js +2 -0
- package/DropdownMenu/index.d.ts +3 -9
- package/DropdownMenu/index.js +3 -9
- package/Table/hooks/helpers.d.ts +3 -0
- package/Table/hooks/helpers.js +9 -0
- package/Table/hooks/useDataTableGetParams.d.ts +2 -2
- package/Table/hooks/useDataTableGetParams.js +16 -23
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +2 -1
- package/DropdownMenu/components/DropdownMenu/hooks.d.ts +0 -4
- package/DropdownMenu/components/DropdownMenu/hooks.js +0 -10
- package/DropdownMenu/components/DropdownMenuContainer/DropdownMenuContainer.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuContainer/DropdownMenuContainer.js +0 -79
- package/DropdownMenu/components/DropdownMenuContainer/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuContainer/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuContainer/maps.d.ts +0 -26
- package/DropdownMenu/components/DropdownMenuContainer/maps.js +0 -11
- package/DropdownMenu/components/DropdownMenuContainer/styles.d.ts +0 -35
- package/DropdownMenu/components/DropdownMenuContainer/styles.js +0 -109
- package/DropdownMenu/components/DropdownMenuContainer/types.d.ts +0 -19
- package/DropdownMenu/components/DropdownMenuGroup/DropdownMenuGroup.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuGroup/DropdownMenuGroup.js +0 -12
- package/DropdownMenu/components/DropdownMenuGroup/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuGroup/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuGroup/styles.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuGroup/styles.js +0 -7
- package/DropdownMenu/components/DropdownMenuGroup/types.d.ts +0 -5
- package/DropdownMenu/components/DropdownMenuGroup/types.js +0 -1
- package/DropdownMenu/components/DropdownMenuItemCheckbox/DropdownMenuItemCheckbox.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuItemCheckbox/DropdownMenuItemCheckbox.js +0 -9
- package/DropdownMenu/components/DropdownMenuItemCheckbox/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuItemCheckbox/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuItemCheckbox/styles.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuItemCheckbox/styles.js +0 -8
- package/DropdownMenu/components/DropdownMenuItemPick/DropdownMenuItemPick.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuItemPick/DropdownMenuItemPick.js +0 -16
- package/DropdownMenu/components/DropdownMenuItemPick/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuItemPick/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuItemPick/styles.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuItemPick/styles.js +0 -8
- package/DropdownMenu/components/DropdownMenuItemPick/types.d.ts +0 -2
- package/DropdownMenu/components/DropdownMenuItemPick/types.js +0 -1
- package/DropdownMenu/components/DropdownMenuItemRadio/DropdownMenuItemRadio.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuItemRadio/DropdownMenuItemRadio.js +0 -9
- package/DropdownMenu/components/DropdownMenuItemRadio/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuItemRadio/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuItemRadio/styles.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuItemRadio/styles.js +0 -8
- package/DropdownMenu/components/DropdownMenuNested/DropdownMenuNested.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuNested/DropdownMenuNested.js +0 -69
- package/DropdownMenu/components/DropdownMenuNested/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuNested/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuNested/styles.d.ts +0 -8
- package/DropdownMenu/components/DropdownMenuNested/styles.js +0 -35
- package/DropdownMenu/components/DropdownMenuNested/types.d.ts +0 -6
- package/DropdownMenu/components/DropdownMenuNested/types.js +0 -1
- package/DropdownMenu/components/DropdownMenuWindow/DropdownMenuWindow.d.ts +0 -3
- package/DropdownMenu/components/DropdownMenuWindow/DropdownMenuWindow.js +0 -12
- package/DropdownMenu/components/DropdownMenuWindow/index.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuWindow/index.js +0 -1
- package/DropdownMenu/components/DropdownMenuWindow/styles.d.ts +0 -1
- package/DropdownMenu/components/DropdownMenuWindow/styles.js +0 -7
- package/DropdownMenu/components/DropdownMenuWindow/types.d.ts +0 -5
- package/DropdownMenu/components/DropdownMenuWindow/types.js +0 -1
- /package/DropdownMenu/components/{DropdownMenuContainer → DropdownMenuButton}/types.js +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
export declare
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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 {
|
|
2
|
+
export { DropdownMenuSection } from './styles';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { DropdownMenu } from './DropdownMenu';
|
|
2
|
-
export {
|
|
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
|
|
2
|
-
type
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
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,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
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
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, {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,2 +1 @@
|
|
|
1
|
-
export { DropdownMenuItem } from './DropdownMenuItem';
|
|
2
|
-
export { DropdownMenuItemBox } from './styles';
|
|
1
|
+
export { DropdownMenuItem } from './DropdownMenuItem';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
$
|
|
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,
|
|
3
|
-
export const
|
|
4
|
-
displayName: "
|
|
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
|
-
})(["
|
|
7
|
-
$
|
|
8
|
-
$
|
|
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 ($
|
|
11
|
-
|
|
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 {
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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>;
|
package/DropdownMenu/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export { DropdownMenu,
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
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';
|
package/DropdownMenu/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export { DropdownMenu,
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
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';
|
|
@@ -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
|
+
}
|
|
@@ -3,9 +3,9 @@ type UseDataTableParamsParams<P extends DataTableParams> = {
|
|
|
3
3
|
defaultOrder: string;
|
|
4
4
|
defaultDirection?: 'asc' | 'desc';
|
|
5
5
|
defaultPerPage?: number;
|
|
6
|
-
|
|
6
|
+
customizeParams?: (obj: Record<string, string>, params: DataTableParams) => P;
|
|
7
7
|
prefix?: string;
|
|
8
8
|
};
|
|
9
9
|
type UseDataTableParamsReturn<P> = readonly [P, (params: P) => void];
|
|
10
|
-
export declare function useDataTableGetParams<P extends DataTableParams>({ defaultOrder, defaultDirection, defaultPerPage,
|
|
10
|
+
export declare function useDataTableGetParams<P extends DataTableParams>({ defaultOrder, defaultDirection, defaultPerPage, customizeParams, prefix, }: UseDataTableParamsParams<P>): UseDataTableParamsReturn<P>;
|
|
11
11
|
export {};
|
|
@@ -1,46 +1,39 @@
|
|
|
1
1
|
import { useMemo, useRef } from 'react';
|
|
2
2
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
3
|
import { usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
4
|
-
|
|
5
|
-
return Object.fromEntries(Object.entries(obj).filter(([, value]) => !!value));
|
|
6
|
-
}
|
|
7
|
-
function mapKeys(obj, mapper) {
|
|
8
|
-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [mapper(key), value]));
|
|
9
|
-
}
|
|
10
|
-
function shallowEqual(a, b) {
|
|
11
|
-
return Object.keys(a).every(key => a[key] === b[key]);
|
|
12
|
-
}
|
|
4
|
+
import { mapKeys, pickBy, shallowEqual } from './helpers';
|
|
13
5
|
export function useDataTableGetParams({
|
|
14
6
|
defaultOrder,
|
|
15
7
|
defaultDirection = 'asc',
|
|
16
8
|
defaultPerPage = 10,
|
|
17
|
-
|
|
9
|
+
customizeParams,
|
|
18
10
|
prefix = ''
|
|
19
11
|
}) {
|
|
20
12
|
const history = useHistory();
|
|
21
13
|
const {
|
|
22
14
|
search: locationSearch
|
|
23
15
|
} = useLocation();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
16
|
+
const customizeParamsRef = useRef(customizeParams);
|
|
17
|
+
customizeParamsRef.current = customizeParams;
|
|
18
|
+
const prevDataTableParamsRef = useRef({});
|
|
27
19
|
const dataTableParams = useMemo(() => {
|
|
28
20
|
const searchParams = new URLSearchParams(locationSearch);
|
|
29
|
-
const
|
|
21
|
+
const searchParamsWoPrefix = mapKeys(Object.fromEntries(searchParams), key => key.startsWith(prefix) ? key.slice(prefix.length) : key);
|
|
30
22
|
// eslint-disable-next-line no-nested-ternary
|
|
31
|
-
const realOrderDirection = !
|
|
23
|
+
const realOrderDirection = !searchParamsWoPrefix.direction ? defaultDirection : searchParamsWoPrefix.direction === 'asc' ? 'asc' : 'desc';
|
|
32
24
|
const params = {
|
|
33
|
-
search:
|
|
34
|
-
order:
|
|
25
|
+
search: searchParamsWoPrefix.search ?? '',
|
|
26
|
+
order: searchParamsWoPrefix.order || defaultOrder,
|
|
35
27
|
direction: realOrderDirection,
|
|
36
|
-
page: +
|
|
37
|
-
perPage: +
|
|
28
|
+
page: +searchParamsWoPrefix.page || 1,
|
|
29
|
+
perPage: +searchParamsWoPrefix.perPage || defaultPerPage
|
|
38
30
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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;
|
|
42
35
|
}
|
|
43
|
-
return
|
|
36
|
+
return prevDataTableParamsRef.current;
|
|
44
37
|
}, [locationSearch, defaultDirection, defaultOrder, defaultPerPage, prefix]);
|
|
45
38
|
const changeDataTableParams = usePersistentFunction(params => {
|
|
46
39
|
const searchParams = new URLSearchParams(locationSearch);
|
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,
|
|
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';
|
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 { 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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/dumb-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "React components to build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"styled-components": "^5.3.11"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@floating-ui/react-dom": "^2.1.2",
|
|
38
39
|
"@pushwoosh/kit-helpers": "^4.6.2",
|
|
39
40
|
"@pushwoosh/kit-icons": "^2.1.1",
|
|
40
41
|
"@pushwoosh/kit-typography": "^1.7.1",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { DropdownMenuContext } from './types';
|
|
2
|
-
export declare const Context: import("react").Context<DropdownMenuContext | undefined>;
|
|
3
|
-
export declare const DropdownMenuProvider: import("react").Provider<DropdownMenuContext | undefined>;
|
|
4
|
-
export declare function useDropdownMenuContext(): DropdownMenuContext;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
export const Context = createContext(undefined);
|
|
3
|
-
export const DropdownMenuProvider = Context.Provider;
|
|
4
|
-
export function useDropdownMenuContext() {
|
|
5
|
-
const context = useContext(Context);
|
|
6
|
-
if (!context) {
|
|
7
|
-
throw new Error('DropdownMenuContext is not defined! Please check what are you using useDropdownMenuContext in a child of DropdownMenu component!');
|
|
8
|
-
}
|
|
9
|
-
return context;
|
|
10
|
-
}
|