@servicetitan/mpa-components 1.1.0 → 1.1.1

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 (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/components/campaign-actions/action-button/action-button-archive.d.ts +7 -0
  3. package/lib/components/campaign-actions/action-button/action-button-archive.d.ts.map +1 -0
  4. package/lib/components/campaign-actions/action-button/action-button-archive.js +4 -0
  5. package/lib/components/campaign-actions/action-button/action-button-archive.js.map +1 -0
  6. package/lib/components/campaign-actions/action-button/action-button-clone.d.ts +6 -0
  7. package/lib/components/campaign-actions/action-button/action-button-clone.d.ts.map +1 -0
  8. package/lib/components/campaign-actions/action-button/action-button-clone.js +4 -0
  9. package/lib/components/campaign-actions/action-button/action-button-clone.js.map +1 -0
  10. package/lib/components/campaign-actions/action-button/action-button-edit.d.ts +7 -0
  11. package/lib/components/campaign-actions/action-button/action-button-edit.d.ts.map +1 -0
  12. package/lib/components/campaign-actions/action-button/action-button-edit.js +4 -0
  13. package/lib/components/campaign-actions/action-button/action-button-edit.js.map +1 -0
  14. package/lib/components/campaign-actions/action-button/action-button-unarchive.d.ts +6 -0
  15. package/lib/components/campaign-actions/action-button/action-button-unarchive.d.ts.map +1 -0
  16. package/lib/components/campaign-actions/action-button/action-button-unarchive.js +4 -0
  17. package/lib/components/campaign-actions/action-button/action-button-unarchive.js.map +1 -0
  18. package/lib/components/campaign-actions/action-button/action-button.d.ts +14 -0
  19. package/lib/components/campaign-actions/action-button/action-button.d.ts.map +1 -0
  20. package/lib/components/campaign-actions/action-button/action-button.js +29 -0
  21. package/lib/components/campaign-actions/action-button/action-button.js.map +1 -0
  22. package/lib/components/campaign-actions/action-button/action-button.module.less +17 -0
  23. package/lib/components/campaign-actions/actions-button/actions-button.d.ts +5 -0
  24. package/lib/components/campaign-actions/actions-button/actions-button.d.ts.map +1 -0
  25. package/lib/components/campaign-actions/actions-button/actions-button.js +33 -0
  26. package/lib/components/campaign-actions/actions-button/actions-button.js.map +1 -0
  27. package/lib/components/campaign-actions/actions-button/actions-button.module.less +10 -0
  28. package/lib/components/campaign-actions/actions-button/campaign-actions.d.ts +11 -0
  29. package/lib/components/campaign-actions/actions-button/campaign-actions.d.ts.map +1 -0
  30. package/lib/components/campaign-actions/actions-button/campaign-actions.js +15 -0
  31. package/lib/components/campaign-actions/actions-button/campaign-actions.js.map +1 -0
  32. package/lib/components/campaign-actions/actions-button/campaign-actions.stories.d.ts +9 -0
  33. package/lib/components/campaign-actions/actions-button/campaign-actions.stories.d.ts.map +1 -0
  34. package/lib/components/campaign-actions/actions-button/campaign-actions.stories.js +11 -0
  35. package/lib/components/campaign-actions/actions-button/campaign-actions.stories.js.map +1 -0
  36. package/lib/components/campaign-actions/index.d.ts +2 -0
  37. package/lib/components/campaign-actions/index.d.ts.map +1 -0
  38. package/lib/components/campaign-actions/index.js +2 -0
  39. package/lib/components/campaign-actions/index.js.map +1 -0
  40. package/lib/index.d.ts +1 -0
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +1 -0
  43. package/lib/index.js.map +1 -1
  44. package/package.json +2 -2
  45. package/src/components/campaign-actions/action-button/action-button-archive.tsx +18 -0
  46. package/src/components/campaign-actions/action-button/action-button-clone.tsx +13 -0
  47. package/src/components/campaign-actions/action-button/action-button-edit.tsx +18 -0
  48. package/src/components/campaign-actions/action-button/action-button-unarchive.tsx +13 -0
  49. package/src/components/campaign-actions/action-button/action-button.module.less +17 -0
  50. package/src/components/campaign-actions/action-button/action-button.module.less.d.ts +5 -0
  51. package/src/components/campaign-actions/action-button/action-button.tsx +78 -0
  52. package/src/components/campaign-actions/actions-button/actions-button.module.less +10 -0
  53. package/src/components/campaign-actions/actions-button/actions-button.module.less.d.ts +3 -0
  54. package/src/components/campaign-actions/actions-button/actions-button.tsx +76 -0
  55. package/src/components/campaign-actions/actions-button/campaign-actions.stories.tsx +19 -0
  56. package/src/components/campaign-actions/actions-button/campaign-actions.tsx +77 -0
  57. package/src/components/campaign-actions/index.ts +1 -0
  58. package/src/index.ts +1 -0
  59. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,76 @@
1
+ import { Card, Popover, Icon } from '@servicetitan/design-system';
2
+ import { FC, useState, useRef, useEffect, ReactNode } from 'react';
3
+
4
+ import * as Styles from './actions-button.module.less';
5
+
6
+ export const ActionsButton: FC<{
7
+ children: ReactNode;
8
+ }> = ({ children }) => {
9
+ const [isOpen, setIsOpen] = useState(false);
10
+ const wrapElem = useRef<HTMLDivElement>(null);
11
+
12
+ useEffect(() => {
13
+ const handleClick = (event: MouseEvent) => {
14
+ if (!wrapElem.current) {
15
+ return;
16
+ }
17
+
18
+ const isClickedInside = wrapElem.current.contains(event.target as Node);
19
+
20
+ if (!isClickedInside) {
21
+ close();
22
+ }
23
+ };
24
+
25
+ window.addEventListener('click', handleClick);
26
+
27
+ return () => {
28
+ window.removeEventListener('click', handleClick);
29
+ };
30
+ }, []);
31
+
32
+ const toggle = () => {
33
+ setIsOpen(!isOpen);
34
+ };
35
+
36
+ const close = () => {
37
+ setIsOpen(false);
38
+ };
39
+
40
+ return (
41
+ <div
42
+ ref={wrapElem}
43
+ className="qa-actions-button d-ib"
44
+ onClick={e => {
45
+ e.stopPropagation();
46
+ }}
47
+ >
48
+ <Popover
49
+ className={Styles.popover}
50
+ width="xs"
51
+ open={isOpen}
52
+ direction="bl"
53
+ trigger={
54
+ <Card
55
+ raised
56
+ sharp
57
+ padding="none"
58
+ active={isOpen}
59
+ onClick={toggle}
60
+ className="qa-actions-button-menu-button"
61
+ >
62
+ <Card.Section className="p-half-i">
63
+ <Icon
64
+ name="more_vert"
65
+ size="22px"
66
+ className={isOpen ? 'c-blue-400' : ''}
67
+ />
68
+ </Card.Section>
69
+ </Card>
70
+ }
71
+ >
72
+ {children}
73
+ </Popover>
74
+ </div>
75
+ );
76
+ };
@@ -0,0 +1,19 @@
1
+ import { CampaignActions as Component } from './campaign-actions';
2
+
3
+ export function CampaignActions() {
4
+ return (
5
+ <Component
6
+ onClickEdit={() => {}}
7
+ onClickStop={() => {}}
8
+ onClickClone={() => {}}
9
+ onClickArchive={() => {}}
10
+ onClickUnarchive={() => {}}
11
+ />
12
+ );
13
+ }
14
+
15
+ export default {
16
+ title: 'MRK Components/CampaignActions',
17
+ component: CampaignActions,
18
+ parameters: {},
19
+ };
@@ -0,0 +1,77 @@
1
+ import { FC } from 'react';
2
+ import { ButtonGroup, Button } from '@servicetitan/design-system';
3
+ import { Confirm } from '@servicetitan/confirm';
4
+ import { ActionButtonArchive } from '../action-button/action-button-archive';
5
+ import { ActionButtonUnarchive } from '../action-button/action-button-unarchive';
6
+ import { ActionsButton } from './actions-button';
7
+ import { ActionButtonClone } from '../action-button/action-button-clone';
8
+ import { ActionButtonEdit } from '../action-button/action-button-edit';
9
+
10
+ interface CampaignActionsProps {
11
+ onClickEdit?(): void;
12
+ onClickStop?(): void;
13
+ onClickClone?(): void;
14
+ onClickArchive?(): void;
15
+ onClickUnarchive?(): void;
16
+ }
17
+
18
+ export const CampaignActions: FC<CampaignActionsProps> = ({
19
+ onClickEdit,
20
+ onClickStop,
21
+ onClickClone,
22
+ onClickArchive,
23
+ onClickUnarchive,
24
+ }) => {
25
+ const stopAction = (handleClick: () => void) => (
26
+ <Button outline onClick={handleClick} small negative className="qa-campaign-actions-stop">
27
+ Stop
28
+ </Button>
29
+ );
30
+
31
+ const archiveAction = (handleClick: () => void) => (
32
+ <ActionButtonArchive onClick={handleClick} />
33
+ );
34
+
35
+ const unarchiveAction = (handleClick: () => void) => (
36
+ <ActionButtonUnarchive onClick={handleClick} />
37
+ );
38
+
39
+ return (
40
+ <ButtonGroup>
41
+ {onClickStop && (
42
+ <Confirm
43
+ onConfirm={onClickStop}
44
+ title="Confirm stop"
45
+ message="Are you sure you want to stop this campaign?"
46
+ negative
47
+ >
48
+ {stopAction}
49
+ </Confirm>
50
+ )}
51
+ <ActionsButton>
52
+ {onClickClone && <ActionButtonClone onClick={onClickClone} />}
53
+ {onClickArchive && (
54
+ <Confirm
55
+ onConfirm={onClickArchive}
56
+ title="Confirm archive"
57
+ message="Are you sure you want to archive this campaign?"
58
+ negative={false}
59
+ >
60
+ {archiveAction}
61
+ </Confirm>
62
+ )}
63
+ {onClickUnarchive && (
64
+ <Confirm
65
+ onConfirm={onClickUnarchive}
66
+ title="Confirm unarchive"
67
+ message="Are you sure you want to unarchive this campaign?"
68
+ negative={false}
69
+ >
70
+ {unarchiveAction}
71
+ </Confirm>
72
+ )}
73
+ {onClickEdit && <ActionButtonEdit onClick={onClickEdit} />}
74
+ </ActionsButton>
75
+ </ButtonGroup>
76
+ );
77
+ };
@@ -0,0 +1 @@
1
+ export * from './actions-button/campaign-actions';
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components/settings';
2
+ export * from './components/campaign-actions';
2
3
 
3
4
  export * from './utils/helpers';