@star-insure/sdk 3.0.2 → 3.1.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.
@@ -0,0 +1,105 @@
1
+ import { router } from "@inertiajs/react";
2
+ import React from "react";
3
+ import { HiMagnifyingGlass, HiXMark } from "react-icons/hi2";
4
+ import { useClickOutside } from "../../lib";
5
+
6
+
7
+ export default function SearchBar({ search, active, onActive, placeholder }: { search?: string, active: boolean, onActive: Function, placeholder?: string }) {
8
+ const [query, setQuery] = React.useState<string>('');
9
+
10
+ const searchRef = React.useRef<HTMLDivElement | null>(null);
11
+
12
+ /**
13
+ * Populate search input on load
14
+ */
15
+ React.useEffect(() => {
16
+ if (typeof window !== 'undefined') {
17
+ // Populate search
18
+ const search = new URLSearchParams(window.location.search);
19
+
20
+ const q = search.get('search') as string;
21
+
22
+ if (q) {
23
+ setQuery(q);
24
+ onActive(true);
25
+ }
26
+ }
27
+ }, []);
28
+
29
+ /**
30
+ * Minimise the search bar on click outside if there's no search query
31
+ */
32
+ useClickOutside(searchRef, () => {
33
+ if (!query) {
34
+ onActive(false);
35
+ }
36
+ });
37
+
38
+ /**
39
+ * Handle the search function
40
+ */
41
+ function handleSearch(e?: React.FormEvent, queryOverride?: string) {
42
+ e?.preventDefault();
43
+
44
+ if (typeof search !== 'string') return;
45
+
46
+ let path: string = search;
47
+ if (path[0] !== '/') {
48
+ path = `/${path}`;
49
+ }
50
+
51
+ const params = new URLSearchParams(window?.location.search);
52
+ params.set('search', queryOverride ?? query);
53
+ params.set('page', '1');
54
+
55
+ router.get(`${path}?${params.toString()}`);
56
+ }
57
+
58
+ return (
59
+ <div ref={searchRef} className="">
60
+ {!active && (
61
+ <button
62
+ title="Open Search Bar"
63
+ type="button"
64
+ onClick={() => onActive(true)}
65
+ className="flex items-center justify-center rounded-full hover:text-teal p-1 transition-colors hover:bg-gray-100"
66
+ >
67
+ <HiMagnifyingGlass className="h-5 w-5 stroke-[1.25]" />
68
+ </button>
69
+ )}
70
+ {active && (
71
+ <form
72
+ onSubmit={handleSearch}
73
+ className="group flex items-center gap-2 rounded-full bg-white pr-4 pl-1 shadow transition-all focus-within:outline-none focus-within:ring-1 focus-within:ring-teal"
74
+ >
75
+ <input
76
+ type="text"
77
+ name="search"
78
+ id="search"
79
+ value={query}
80
+ onChange={(e) => setQuery(e.currentTarget.value || '')}
81
+ className="!focus:border-0 !border-0 !bg-transparent !shadow-none !ring-opacity-0 !transition-none placeholder:text-gray-400 !py-1.5 text-sm"
82
+ autoFocus
83
+ placeholder={placeholder}
84
+ />
85
+ {query && (
86
+ <button
87
+ type="button"
88
+ title="Clear Search"
89
+ onClick={() => {
90
+ setQuery('');
91
+ handleSearch(undefined, '');
92
+ }}
93
+ >
94
+ <HiXMark className="h-5 w-5" />
95
+ </button>
96
+ )}
97
+ <button type="submit">
98
+ <HiMagnifyingGlass className="h-5 w-5" />
99
+ </button>
100
+ </form>
101
+ )}
102
+ </div>
103
+ );
104
+ }
105
+
@@ -0,0 +1 @@
1
+ export { default as PageHeader } from './PageHeader';
@@ -0,0 +1,24 @@
1
+ import { Page, PageProps } from '@inertiajs/core';
2
+ import { usePage as inertiaUsePage } from '@inertiajs/react';
3
+ import { AuthContext, Breadcrumb, Environment } from '../types';
4
+
5
+ /**
6
+ * Add custom props here, that are defined in `app/Http/Middleware/HandleInertiaRequests.php`
7
+ */
8
+ type CustomPageProps = {
9
+ env: Environment;
10
+ breadcrumbs: Breadcrumb[];
11
+ links: Record<string, string>;
12
+ access_token?: string;
13
+ impersonate_id?: number;
14
+ csrf_token?: string;
15
+ auth: AuthContext;
16
+ } & PageProps;
17
+
18
+ /**
19
+ * A wrapper around Inertia's usePage function that gives better type-safety
20
+ */
21
+ export function usePage<T>(): Page<CustomPageProps & T> {
22
+ // @ts-ignore
23
+ return inertiaUsePage();
24
+ }
@@ -6,3 +6,36 @@ export interface Toast {
6
6
  status?: 'success' | 'error' | 'default' | 'warning';
7
7
  timeout?: number;
8
8
  }
9
+
10
+ export interface FilterOption {
11
+ label: string;
12
+ name: string;
13
+ options?: FilterValue[];
14
+ type?: 'options' | 'date' | 'greaterThan' | 'scope' | 'select';
15
+ }
16
+
17
+ export interface FilterValue {
18
+ label: string;
19
+ value: string | number;
20
+ }
21
+
22
+ export interface Filter {
23
+ [key: string]: (string | number)[];
24
+ }
25
+
26
+ export type TPageHeaderAction = {
27
+ title: string;
28
+ as?: 'button' | 'a' | 'Link';
29
+ href?: string;
30
+ target?: '_self' | '_blank';
31
+ onClick?: Function;
32
+ type?: 'button' | 'submit';
33
+ };
34
+
35
+ export type Environment = 'production' | 'staging' | 'testing' | 'local';
36
+
37
+ export type Breadcrumb = {
38
+ current?: boolean;
39
+ title: string;
40
+ url?: string;
41
+ };