@star-insure/sdk 4.3.5 → 4.4.0

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.
@@ -27,6 +27,15 @@ export declare type TPageHeaderAction = {
27
27
  type?: 'button' | 'submit';
28
28
  hidden?: boolean;
29
29
  shortcutKey?: string;
30
+ actions?: TPageHeaderInnerAction[];
31
+ };
32
+ export declare type TPageHeaderInnerAction = {
33
+ title: string;
34
+ as?: 'button' | 'a' | 'Link';
35
+ href?: string;
36
+ target?: '_self' | '_blank';
37
+ onClick?: Function;
38
+ hidden?: boolean;
30
39
  };
31
40
  export declare type Environment = 'production' | 'staging' | 'testing' | 'local';
32
41
  export declare type Breadcrumb = {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@star-insure/sdk",
3
3
  "description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
4
4
  "author": "alexclark_nz",
5
- "version": "4.3.5",
5
+ "version": "4.4.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -2,14 +2,26 @@ import React from "react";
2
2
  import { Tooltip } from 'react-tooltip';
3
3
  import { Link, router } from "@inertiajs/react";
4
4
  import { TPageHeaderAction } from "../../types";
5
+ import {useClickOutside} from "../../lib";
5
6
 
6
- export default function Action({ title, href, as = 'Link', target = '_self', type, onClick = () => {}, shortcutKey }: TPageHeaderAction) {
7
+ export default function Action({ title, href, as = 'Link', target = '_self', type, onClick = () => {}, shortcutKey, actions }: TPageHeaderAction) {
7
8
  const className =
8
9
  'bg-white rounded-full font-bold px-4 py-1.5 text-sm whitespace-nowrap hover:bg-gray-100 hover:border-gray-400 transition-colors border border-gray-300';
9
10
 
10
11
  const tooltipId = `action-${title}`;
11
12
  const tooltipContent = shortcutKey ? `Ctrl + ${shortcutKey}` : undefined;
12
13
 
14
+ const actionButtonRef = React.useRef(null);
15
+ const isActionsButton = actions && actions.length > 0;
16
+ const actionsButtonClassName = 'relative cursor-pointer ' + className;
17
+ const [isInnerActionVisible, setIsInnerActionVisible] = React.useState(false);
18
+
19
+ const toggleActionsMenu = () => {
20
+ setIsInnerActionVisible(!isInnerActionVisible);
21
+ };
22
+
23
+ useClickOutside(actionButtonRef, () => setIsInnerActionVisible(false));
24
+
13
25
  function runAction() {
14
26
  if (as === 'Link' && href) {
15
27
  return router.get(href);
@@ -47,6 +59,43 @@ export default function Action({ title, href, as = 'Link', target = '_self', typ
47
59
  };
48
60
  }, [shortcutKey]);
49
61
 
62
+ if (isActionsButton) {
63
+ return (
64
+ <>
65
+ {tooltipContent && <Tooltip id={tooltipId} className="z-10" />}
66
+ <div
67
+ ref={actionButtonRef}
68
+ data-tooltip-id={tooltipId}
69
+ data-tooltip-content={tooltipContent}
70
+ className={actionsButtonClassName}
71
+ onClick={toggleActionsMenu}>
72
+ {title}
73
+ {isInnerActionVisible && (
74
+ <div className="absolute top-[120%] right-[-20%] z-10">
75
+ <div className="flex flex-col gap-2 bg-white rounded-lg shadow-xl p-3">
76
+ {actions && actions.map((action, index) => {
77
+ if (action.hidden) return null;
78
+
79
+ return (
80
+ <Action
81
+ key={index}
82
+ title={action.title}
83
+ as={action.as}
84
+ href={action.href}
85
+ target={action.target}
86
+ onClick={action.onClick}
87
+ type={'button'}
88
+ />
89
+ );
90
+ })}
91
+ </div>
92
+ </div>
93
+ )}
94
+ </div>
95
+ </>
96
+ );
97
+ }
98
+
50
99
  if (as === 'Link' && href) {
51
100
  return (
52
101
  <>
@@ -32,6 +32,16 @@ export type TPageHeaderAction = {
32
32
  type?: 'button' | 'submit';
33
33
  hidden?: boolean;
34
34
  shortcutKey?: string;
35
+ actions?: TPageHeaderInnerAction[];
36
+ };
37
+
38
+ export type TPageHeaderInnerAction = {
39
+ title: string;
40
+ as?: 'button' | 'a' | 'Link';
41
+ href?: string;
42
+ target?: '_self' | '_blank';
43
+ onClick?: Function;
44
+ hidden?: boolean;
35
45
  };
36
46
 
37
47
  export type Environment = 'production' | 'staging' | 'testing' | 'local';