@pushwoosh/dumb-components 1.1.44 → 1.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,12 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Color } from '@pushwoosh/kit-constants';
3
3
  import { formatNumber, Horizontal } from '@pushwoosh/kit-helpers';
4
+ import { KebabIcon } from '@pushwoosh/kit-icons';
4
5
  import { Text } from '@pushwoosh/kit-typography';
5
6
  import { Spinner } from '../Spinner';
6
7
  import { Container, RightSlotContainer, StatValue, Title } from './styles';
8
+ import { Button } from '../Button';
9
+ import { DropdownMenu, DropdownMenuItem, DropdownMenuSection } from '../DropdownMenu';
7
10
  export function StatisticCard(props) {
8
11
  const {
9
12
  title,
@@ -13,6 +16,7 @@ export function StatisticCard(props) {
13
16
  active,
14
17
  selectable,
15
18
  rightSlot,
19
+ actions,
16
20
  width,
17
21
  isLoading,
18
22
  onClick,
@@ -35,15 +39,41 @@ export function StatisticCard(props) {
35
39
  }
36
40
  return React.createElement(StatValue, null, typeof value === 'number' ? formatNumber(value, 'spaced') : value);
37
41
  }, [isLoading, value, valueSubtext]);
42
+ const resolvedRightSlot = rightSlot ?? (actions ? React.createElement(DropdownMenu, {
43
+ renderHandler: ({
44
+ onClick,
45
+ ref,
46
+ isOpen
47
+ }) => React.createElement(Button, {
48
+ color: "secondary",
49
+ view: "ghost",
50
+ icon: React.createElement(KebabIcon, {
51
+ size: "small"
52
+ }),
53
+ onClick: onClick,
54
+ boxRef: ref,
55
+ isOpen: isOpen,
56
+ style: {
57
+ width: '28px',
58
+ height: '28px'
59
+ }
60
+ })
61
+ }, React.createElement(DropdownMenuSection, null, actions.map(a => React.createElement(DropdownMenuItem, {
62
+ key: a.id,
63
+ onClick: a.onClick,
64
+ disabled: a.disabled
65
+ }, a.label)))) : null);
38
66
  return React.createElement(Container, {
39
67
  "$active": active,
40
68
  "$selectable": selectable,
41
69
  "$width": width,
42
70
  onClick: onClick,
43
71
  ...rest
44
- }, React.createElement(Title, null, title), rightSlot && React.createElement(RightSlotContainer, {
72
+ }, React.createElement(Title, {
73
+ "$hasRightSlot": !!resolvedRightSlot
74
+ }, title), resolvedRightSlot && React.createElement(RightSlotContainer, {
45
75
  onClick: e => e.stopPropagation()
46
- }, rightSlot), statisticValue, footer && React.createElement(Text, {
76
+ }, resolvedRightSlot), statisticValue, footer && React.createElement(Text, {
47
77
  "$variant": "footnote",
48
78
  "$color": Color.LOCKED
49
79
  }, footer));
@@ -4,6 +4,8 @@ export declare const Container: import("styled-components").StyledComponent<"div
4
4
  $selectable?: boolean;
5
5
  $width?: string;
6
6
  }, never>;
7
- export declare const Title: import("styled-components").StyledComponent<typeof H5, any, {}, never>;
7
+ export declare const Title: import("styled-components").StyledComponent<typeof H5, any, {
8
+ $hasRightSlot?: boolean;
9
+ }, never>;
8
10
  export declare const StatValue: import("styled-components").StyledComponent<typeof H2, any, {}, never>;
9
11
  export declare const RightSlotContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -22,7 +22,9 @@ export const Container = styled.div.withConfig({
22
22
  export const Title = styled(H5).withConfig({
23
23
  displayName: "Title",
24
24
  componentId: "sc-12f82mq-1"
25
- })(["text-transform:uppercase;color:", ";text-overflow:ellipsis;"], Color.MAIN);
25
+ })(["text-transform:uppercase;color:", ";white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:", ";"], Color.MAIN, ({
26
+ $hasRightSlot
27
+ }) => $hasRightSlot ? 'calc(100% - 20px)' : '100%');
26
28
  export const StatValue = styled(H2).withConfig({
27
29
  displayName: "StatValue",
28
30
  componentId: "sc-12f82mq-2"
@@ -30,4 +32,4 @@ export const StatValue = styled(H2).withConfig({
30
32
  export const RightSlotContainer = styled.div.withConfig({
31
33
  displayName: "RightSlotContainer",
32
34
  componentId: "sc-12f82mq-3"
33
- })(["position:absolute;right:", ";top:", ";"], Spacing.S5, Spacing.S4);
35
+ })(["position:absolute;right:8px;top:8px;"]);
@@ -1,10 +1,17 @@
1
1
  import { type ReactNode } from 'react';
2
2
  export type StatisticCardProps = CommonProps & (SelectableProps | NonSelectableProps);
3
+ type StatisticCardAction = {
4
+ id: string;
5
+ label: ReactNode;
6
+ onClick: () => void;
7
+ disabled?: boolean;
8
+ };
3
9
  export type CommonProps = {
4
10
  title: ReactNode;
5
11
  value: number | string;
6
12
  valueSubtext?: string;
7
13
  rightSlot?: ReactNode;
14
+ actions?: StatisticCardAction[];
8
15
  footer?: string;
9
16
  isLoading?: boolean;
10
17
  width?: string;
@@ -19,3 +26,4 @@ export type NonSelectableProps = {
19
26
  onClick?: never;
20
27
  active?: never;
21
28
  };
29
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.44",
3
+ "version": "1.1.45",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",