@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.
- package/dist/components/common/Button.d.ts +2 -1
- package/dist/components/filter/Action.d.ts +3 -0
- package/dist/components/filter/Back.d.ts +4 -0
- package/dist/components/filter/Dropdown.d.ts +12 -0
- package/dist/components/filter/FilterItem.d.ts +6 -0
- package/dist/components/filter/FilterOptions.d.ts +5 -0
- package/dist/components/filter/PageHeader.d.ts +14 -0
- package/dist/components/filter/SearchBar.d.ts +7 -0
- package/dist/components/filter/index.d.ts +1 -0
- package/dist/lib/page.d.ts +19 -0
- package/dist/sdk.cjs.development.js +4 -2
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +4 -2
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/misc/index.d.ts +27 -0
- package/package.json +4 -1
- package/src/components/common/Button.tsx +5 -2
- package/src/components/filter/Action.tsx +30 -0
- package/src/components/filter/Back.tsx +35 -0
- package/src/components/filter/Dropdown.tsx +51 -0
- package/src/components/filter/FilterItem.tsx +318 -0
- package/src/components/filter/FilterOptions.tsx +21 -0
- package/src/components/filter/PageHeader.tsx +176 -0
- package/src/components/filter/SearchBar.tsx +105 -0
- package/src/components/filter/index.ts +1 -0
- package/src/lib/page.tsx +24 -0
- package/src/types/misc/index.ts +33 -0
|
@@ -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';
|
package/src/lib/page.tsx
ADDED
|
@@ -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
|
+
}
|
package/src/types/misc/index.ts
CHANGED
|
@@ -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
|
+
};
|