@sqrzro/ui 4.0.0-alpha.0 → 4.0.0-alpha.2

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 (219) hide show
  1. package/dist/components/buttons/ActionButton/index.d.ts +7 -0
  2. package/dist/components/buttons/ActionButton/index.js +33 -0
  3. package/dist/components/buttons/Button/index.d.ts +65 -0
  4. package/dist/components/buttons/Button/index.js +50 -0
  5. package/dist/components/buttons/ConfirmableButton/index.d.ts +7 -0
  6. package/dist/components/buttons/ConfirmableButton/index.js +13 -0
  7. package/dist/components/buttons/TextButton/index.d.ts +5 -0
  8. package/dist/components/buttons/TextButton/index.js +6 -0
  9. package/dist/components/collections/Collection/index.d.ts +15 -0
  10. package/dist/components/collections/Collection/index.js +45 -0
  11. package/dist/components/collections/EmptyMessage/index.d.ts +26 -0
  12. package/dist/components/collections/EmptyMessage/index.js +17 -0
  13. package/dist/components/collections/EmptyMessageAction/index.d.ts +6 -0
  14. package/dist/components/collections/EmptyMessageAction/index.js +19 -0
  15. package/dist/components/collections/List/index.d.ts +6 -0
  16. package/dist/components/collections/List/index.js +13 -0
  17. package/dist/components/collections/ListClientComponent/index.d.ts +7 -0
  18. package/dist/components/collections/ListClientComponent/index.js +9 -0
  19. package/dist/components/collections/ListItem/index.d.ts +14 -0
  20. package/dist/components/collections/ListItem/index.js +28 -0
  21. package/dist/components/collections/ListItemMeta/index.d.ts +11 -0
  22. package/dist/components/collections/ListItemMeta/index.js +22 -0
  23. package/dist/components/collections/ListItemSecondary/index.d.ts +6 -0
  24. package/dist/components/collections/ListItemSecondary/index.js +16 -0
  25. package/dist/components/collections/Pagination/index.d.ts +19 -0
  26. package/dist/components/collections/Pagination/index.js +17 -0
  27. package/dist/components/collections/Table/index.d.ts +9 -0
  28. package/dist/components/collections/Table/index.js +13 -0
  29. package/dist/components/collections/TableClientComponent/index.d.ts +14 -0
  30. package/dist/components/collections/TableClientComponent/index.js +30 -0
  31. package/dist/components/collections/interfaces.d.ts +57 -0
  32. package/dist/components/collections/interfaces.js +1 -0
  33. package/dist/components/collections/lang.d.ts +4 -0
  34. package/dist/components/collections/lang.js +4 -0
  35. package/dist/components/collections/utility/filter-columns.d.ts +3 -0
  36. package/dist/components/collections/utility/filter-columns.js +8 -0
  37. package/dist/components/collections/utility/get-selected-from-search-params.d.ts +2 -0
  38. package/dist/components/collections/utility/get-selected-from-search-params.js +5 -0
  39. package/dist/components/collections/utility/is-paginated.d.ts +3 -0
  40. package/dist/components/collections/utility/is-paginated.js +4 -0
  41. package/dist/components/collections/utility/set-selected-to-search-params.d.ts +2 -0
  42. package/dist/components/collections/utility/set-selected-to-search-params.js +4 -0
  43. package/dist/components/index.d.ts +16 -0
  44. package/dist/components/index.js +9 -0
  45. package/dist/components/modals/ConfirmModal/index.d.ts +7 -0
  46. package/dist/components/modals/ConfirmModal/index.js +23 -0
  47. package/dist/components/modals/Modal/index.d.ts +19 -0
  48. package/dist/components/modals/Modal/index.js +17 -0
  49. package/dist/components/modals/ModalActions/index.d.ts +9 -0
  50. package/dist/components/modals/ModalActions/index.js +8 -0
  51. package/dist/components/modals/ModalLauncher/index.d.ts +5 -0
  52. package/dist/components/modals/ModalLauncher/index.js +14 -0
  53. package/dist/components/utility/ActionList/index.d.ts +12 -0
  54. package/dist/components/utility/ActionList/index.js +9 -0
  55. package/dist/components/utility/Assistive/index.d.ts +8 -0
  56. package/dist/components/utility/Assistive/index.js +8 -0
  57. package/dist/components/utility/ClassNames/index.d.ts +6 -0
  58. package/dist/components/utility/ClassNames/index.js +7 -0
  59. package/dist/components/utility/Container/index.d.ts +9 -0
  60. package/dist/components/utility/Container/index.js +8 -0
  61. package/dist/components/utility/Link/index.d.ts +19 -0
  62. package/dist/components/utility/Link/index.js +33 -0
  63. package/dist/components/utility/Loader/index.d.ts +8 -0
  64. package/dist/components/utility/Loader/index.js +9 -0
  65. package/dist/components/utility/Page/index.d.ts +18 -0
  66. package/dist/components/utility/Page/index.js +34 -0
  67. package/dist/components/utility/Popover/index.d.ts +14 -0
  68. package/dist/components/utility/Popover/index.js +71 -0
  69. package/dist/components/utility/RootLayout/index.d.ts +12 -0
  70. package/dist/components/utility/RootLayout/index.js +14 -0
  71. package/dist/components/utility/Toast/index.d.ts +11 -0
  72. package/dist/components/utility/Toast/index.js +11 -0
  73. package/dist/components/utility/Toaster/index.d.ts +8 -0
  74. package/dist/components/utility/Toaster/index.js +57 -0
  75. package/dist/filters/components/FilterBar/index.d.ts +9 -0
  76. package/dist/filters/components/FilterBar/index.js +9 -0
  77. package/dist/filters/components/FilterBarClientComponent/index.d.ts +12 -0
  78. package/dist/filters/components/FilterBarClientComponent/index.js +68 -0
  79. package/dist/filters/components/FilterClearButton/index.d.ts +5 -0
  80. package/dist/filters/components/FilterClearButton/index.js +6 -0
  81. package/dist/filters/components/FilterControl/index.d.ts +12 -0
  82. package/dist/filters/components/FilterControl/index.js +10 -0
  83. package/dist/filters/components/FilterItem/index.d.ts +14 -0
  84. package/dist/filters/components/FilterItem/index.js +43 -0
  85. package/dist/filters/components/FilterPanel/index.d.ts +19 -0
  86. package/dist/filters/components/FilterPanel/index.js +36 -0
  87. package/dist/filters/filters/BooleanFilter/index.d.ts +3 -0
  88. package/dist/filters/filters/BooleanFilter/index.js +10 -0
  89. package/dist/filters/filters/CalendarFilter/index.d.ts +3 -0
  90. package/dist/filters/filters/CalendarFilter/index.js +10 -0
  91. package/dist/filters/filters/DateFilter/index.d.ts +3 -0
  92. package/dist/filters/filters/DateFilter/index.js +21 -0
  93. package/dist/filters/filters/DropdownFilter/index.d.ts +3 -0
  94. package/dist/filters/filters/DropdownFilter/index.js +10 -0
  95. package/dist/filters/filters/Filter/index.d.ts +16 -0
  96. package/dist/filters/filters/Filter/index.js +13 -0
  97. package/dist/filters/filters/MultiFilter/index.d.ts +3 -0
  98. package/dist/filters/filters/MultiFilter/index.js +9 -0
  99. package/dist/filters/filters/SearchFilter/index.d.ts +4 -0
  100. package/dist/filters/filters/SearchFilter/index.js +30 -0
  101. package/dist/filters/filters/interfaces.d.ts +10 -0
  102. package/dist/filters/filters/interfaces.js +1 -0
  103. package/dist/filters/hooks/useFilters.d.ts +5 -0
  104. package/dist/filters/hooks/useFilters.js +25 -0
  105. package/dist/filters/index.d.ts +2 -0
  106. package/dist/filters/index.js +2 -0
  107. package/dist/filters/interfaces.d.ts +28 -0
  108. package/dist/filters/interfaces.js +1 -0
  109. package/dist/filters/lang.d.ts +1 -0
  110. package/dist/filters/lang.js +1 -0
  111. package/dist/filters/utility/check-has-filters.d.ts +2 -0
  112. package/dist/filters/utility/check-has-filters.js +8 -0
  113. package/dist/filters/utility/create-client-filter-map.d.ts +3 -0
  114. package/dist/filters/utility/create-client-filter-map.js +14 -0
  115. package/dist/filters/utility/filter.d.ts +16 -0
  116. package/dist/filters/utility/filter.js +120 -0
  117. package/dist/filters/utility/get-quick-dates.d.ts +3 -0
  118. package/dist/filters/utility/get-quick-dates.js +90 -0
  119. package/dist/filters/utility/parse-filters.d.ts +3 -0
  120. package/dist/filters/utility/parse-filters.js +16 -0
  121. package/dist/filters/utility/parse-page.d.ts +2 -0
  122. package/dist/filters/utility/parse-page.js +8 -0
  123. package/dist/filters/utility/render-value.d.ts +3 -0
  124. package/dist/filters/utility/render-value.js +57 -0
  125. package/dist/filters/utility/transform-boolean.d.ts +2 -0
  126. package/dist/filters/utility/transform-boolean.js +10 -0
  127. package/dist/filters/utility/transform-date.d.ts +2 -0
  128. package/dist/filters/utility/transform-date.js +29 -0
  129. package/dist/filters/utility/transform-multi.d.ts +2 -0
  130. package/dist/filters/utility/transform-multi.js +9 -0
  131. package/dist/forms/components/Dropdown/index.d.ts +22 -0
  132. package/dist/forms/components/Dropdown/index.js +41 -0
  133. package/dist/forms/components/DropdownList/index.d.ts +8 -0
  134. package/dist/forms/components/DropdownList/index.js +20 -0
  135. package/dist/forms/components/EditableForm/index.d.ts +24 -0
  136. package/dist/forms/components/EditableForm/index.js +23 -0
  137. package/dist/forms/components/EditableFormField/index.d.ts +14 -0
  138. package/dist/forms/components/EditableFormField/index.js +37 -0
  139. package/dist/forms/components/EditableFormFields/index.d.ts +7 -0
  140. package/dist/forms/components/EditableFormFields/index.js +20 -0
  141. package/dist/forms/components/Form/index.d.ts +12 -0
  142. package/dist/forms/components/Form/index.js +9 -0
  143. package/dist/forms/components/FormError/index.d.ts +9 -0
  144. package/dist/forms/components/FormError/index.js +8 -0
  145. package/dist/forms/components/FormField/index.d.ts +25 -0
  146. package/dist/forms/components/FormField/index.js +37 -0
  147. package/dist/forms/components/FormFields/index.d.ts +10 -0
  148. package/dist/forms/components/FormFields/index.js +22 -0
  149. package/dist/forms/components/FormLabel/index.d.ts +10 -0
  150. package/dist/forms/components/FormLabel/index.js +8 -0
  151. package/dist/forms/components/FormSubmit/index.d.ts +4 -0
  152. package/dist/forms/components/FormSubmit/index.js +9 -0
  153. package/dist/forms/components/ModalForm/index.d.ts +13 -0
  154. package/dist/forms/components/ModalForm/index.js +25 -0
  155. package/dist/forms/components/PasswordInput/index.d.ts +11 -0
  156. package/dist/forms/components/PasswordInput/index.js +17 -0
  157. package/dist/forms/components/StaticTextInput/index.d.ts +22 -0
  158. package/dist/forms/components/StaticTextInput/index.js +22 -0
  159. package/dist/forms/components/Switch/index.d.ts +11 -0
  160. package/dist/forms/components/Switch/index.js +17 -0
  161. package/dist/forms/components/TextInput/index.d.ts +34 -0
  162. package/dist/forms/components/TextInput/index.js +30 -0
  163. package/dist/forms/hooks/useDropdown.d.ts +10 -0
  164. package/dist/forms/hooks/useDropdown.js +14 -0
  165. package/dist/forms/hooks/useEditableForm.d.ts +24 -0
  166. package/dist/forms/hooks/useEditableForm.js +34 -0
  167. package/dist/forms/hooks/useForm.d.ts +136 -0
  168. package/dist/forms/hooks/useForm.js +209 -0
  169. package/dist/forms/hooks/useModalForm.d.ts +14 -0
  170. package/dist/forms/hooks/useModalForm.js +29 -0
  171. package/dist/forms/index.d.ts +27 -0
  172. package/dist/forms/index.js +17 -0
  173. package/dist/forms/interfaces.d.ts +32 -0
  174. package/dist/forms/interfaces.js +1 -0
  175. package/dist/forms/utility/extract-editable-input-props.d.ts +8 -0
  176. package/dist/forms/utility/extract-editable-input-props.js +19 -0
  177. package/dist/forms/utility/extract-input-props.d.ts +9 -0
  178. package/dist/forms/utility/extract-input-props.js +37 -0
  179. package/dist/hooks/index.d.ts +0 -0
  180. package/dist/hooks/index.js +1 -0
  181. package/dist/hooks/useClickOutside.d.ts +93 -0
  182. package/dist/hooks/useClickOutside.js +124 -0
  183. package/dist/hooks/usePagination.d.ts +17 -0
  184. package/dist/hooks/usePagination.js +46 -0
  185. package/dist/hooks/useSearchParamsHref.d.ts +6 -0
  186. package/dist/hooks/useSearchParamsHref.js +33 -0
  187. package/dist/hooks/useToast.d.ts +18 -0
  188. package/dist/hooks/useToast.js +25 -0
  189. package/dist/navigation/components/AppNavigation/index.d.ts +13 -0
  190. package/dist/navigation/components/AppNavigation/index.js +15 -0
  191. package/dist/navigation/components/AppNavigationItem/index.d.ts +6 -0
  192. package/dist/navigation/components/AppNavigationItem/index.js +9 -0
  193. package/dist/navigation/components/Tabs/index.d.ts +7 -0
  194. package/dist/navigation/components/Tabs/index.js +9 -0
  195. package/dist/navigation/hooks/useNavigation.d.ts +10 -0
  196. package/dist/navigation/hooks/useNavigation.js +38 -0
  197. package/dist/navigation/index.d.ts +5 -0
  198. package/dist/navigation/index.js +3 -0
  199. package/dist/navigation/interfaces.d.ts +7 -0
  200. package/dist/navigation/interfaces.js +1 -0
  201. package/dist/styles/config.d.ts +64 -0
  202. package/dist/styles/config.js +43 -0
  203. package/dist/styles/icons.d.ts +15 -0
  204. package/dist/styles/icons.js +7 -0
  205. package/dist/styles/index.d.ts +2 -0
  206. package/dist/styles/index.js +1 -0
  207. package/dist/styles/interfaces.d.ts +41 -0
  208. package/dist/styles/interfaces.js +1 -0
  209. package/dist/styles/tw.d.ts +9 -0
  210. package/dist/styles/tw.js +15 -0
  211. package/dist/utility/index.d.ts +1 -0
  212. package/dist/utility/index.js +1 -0
  213. package/dist/utility/interfaces.d.ts +35 -0
  214. package/dist/utility/interfaces.js +1 -1
  215. package/package.json +55 -8
  216. package/dist/index.d.ts +0 -2
  217. package/dist/index.js +0 -1
  218. package/dist/lists/List/index.d.ts +0 -5
  219. package/dist/lists/List/index.js +0 -6
@@ -0,0 +1,57 @@
1
+ /* eslint-disable react/no-multi-comp */
2
+ 'use client';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { Fragment, Suspense, useEffect, useRef, useState } from 'react';
5
+ import { usePathname } from 'next/navigation';
6
+ import Toast from '../Toast';
7
+ const TOAST_DURATION = 5000;
8
+ const TRANSITION_DURATION = 200;
9
+ function ToasterComponent({ channel, duration, render = Toast, }) {
10
+ const to = useRef(null);
11
+ const pathname = usePathname();
12
+ const [message, setMessage] = useState(null);
13
+ const [variant, setVariant] = useState(null);
14
+ const [visible, setVisible] = useState(false);
15
+ function showToast(toast) {
16
+ setMessage(toast?.message || null);
17
+ setVariant(toast?.type || null);
18
+ }
19
+ function hideToast() {
20
+ setTimeout(() => {
21
+ setVisible(false);
22
+ setMessage(null);
23
+ }, TRANSITION_DURATION);
24
+ }
25
+ function addToast(toast) {
26
+ if (visible) {
27
+ setTimeout(() => {
28
+ showToast(toast);
29
+ }, TRANSITION_DURATION);
30
+ }
31
+ else {
32
+ showToast(toast);
33
+ }
34
+ setVisible(true);
35
+ if (to.current) {
36
+ clearTimeout(to.current);
37
+ }
38
+ to.current = setTimeout(hideToast, duration || TOAST_DURATION);
39
+ }
40
+ useEffect(() => {
41
+ const eventName = channel ? `toast-${channel}` : 'toast';
42
+ document.addEventListener(eventName, (event) => {
43
+ addToast(event.detail);
44
+ });
45
+ }, []);
46
+ useEffect(() => {
47
+ hideToast();
48
+ }, [pathname]);
49
+ return visible ? (_jsx(Fragment, { children: render({
50
+ children: message,
51
+ variant,
52
+ }) })) : null;
53
+ }
54
+ function Toaster(props) {
55
+ return (_jsx(Suspense, { children: _jsx(ToasterComponent, { ...props }) }));
56
+ }
57
+ export default Toaster;
@@ -0,0 +1,9 @@
1
+ import type { TableColumnObject } from '../../../components/collections/interfaces';
2
+ import type { FilterMap } from '../../interfaces';
3
+ export type { FilterBarClassNames } from '../FilterBarClientComponent';
4
+ interface FilterBarProps<T> {
5
+ columns?: TableColumnObject[];
6
+ map?: FilterMap<T>;
7
+ }
8
+ declare function FilterBar<T>({ columns, map }: Readonly<FilterBarProps<T>>): React.ReactElement;
9
+ export default FilterBar;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Suspense } from 'react';
3
+ import createClientFilterMap from '../../utility/create-client-filter-map';
4
+ import FilterBarClientComponent from '../FilterBarClientComponent';
5
+ function FilterBar({ columns, map }) {
6
+ const clientMap = createClientFilterMap(map);
7
+ return (_jsx(Suspense, { children: _jsx(FilterBarClientComponent, { columns: columns, map: clientMap }) }));
8
+ }
9
+ export default FilterBar;
@@ -0,0 +1,12 @@
1
+ import type { TableColumnObject } from '../../../components/collections/interfaces';
2
+ import type { ClassNameProps } from '../../../styles/interfaces';
3
+ import type { ClientFilterMap } from '../../interfaces';
4
+ export interface FilterBarClassNames {
5
+ root: string;
6
+ }
7
+ interface FilterBarClientComponentProps<T> extends ClassNameProps<FilterBarClassNames> {
8
+ columns?: TableColumnObject[];
9
+ map?: ClientFilterMap<T>;
10
+ }
11
+ declare function FilterBarClientComponent<T>({ classNames, classNameProps, columns, map, }: Readonly<FilterBarClientComponentProps<T>>): React.ReactElement;
12
+ export default FilterBarClientComponent;
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // import { Fragment } from 'react';
4
+ // import { useFilters } from '@sqrzro/hooks';
5
+ // import type { InputEvent } from '@sqrzro/interfaces';
6
+ // import { getEntries } from '@sqrzro/utility';
7
+ // import { useRouter } from 'next/navigation';
8
+ // import { getClassNames } from '../../../styles/config';
9
+ // import type { TableColumnObject } from '../../../tables/TableClientComponent';
10
+ // import type { ClassNameProps } from '../../../utility/interfaces';
11
+ import { getEntries } from '@sqrzro/utility';
12
+ import useFilters from '../../../filters/hooks/useFilters';
13
+ import { getClassNames } from '../../../styles/config';
14
+ import SearchFilter from '../../filters/SearchFilter';
15
+ import FilterItem from '../FilterItem';
16
+ const FILTERED_TYPES = ['assistive', 'search'];
17
+ function FilterBarClientComponent({ classNames, classNameProps, columns, map, }) {
18
+ const componentClassNames = classNames || getClassNames('filterBar')?.(classNameProps);
19
+ const [filters, setFilter] = useFilters();
20
+ const mapArray = map ? getEntries(map) : [];
21
+ const hasSearch = mapArray.some(([, item]) => item?.type === 'search');
22
+ const filteredArray = mapArray.filter(([, item]) => item?.type && !FILTERED_TYPES.includes(item.type));
23
+ function handleChange(event) {
24
+ setFilter(event.target.name, event.target.value);
25
+ }
26
+ return (_jsxs("ul", { className: componentClassNames?.root, children: [hasSearch ? (_jsx("li", { className: "relative", children: _jsx(SearchFilter, { onChange: handleChange, value: filters.get('search') || '' }) })) : null, filteredArray.map(([name, props]) => (_jsx("li", { className: "relative", children: _jsx(FilterItem, { name: String(name), onChange: handleChange, value: filters.get(String(name)) || '', ...props }, String(name)) }, String(name))))] }));
27
+ // const componentClassNames = classNames || getClassNames('filterBar')?.(classNameProps);
28
+ // const router = useRouter();
29
+ // const [filters, setFilter] = useFilters();
30
+ // const mapArray = map ? getEntries(map) : [];
31
+ // const hasSearch = mapArray.some(([, item]) => item.type === 'search');
32
+ // const filteredArray = mapArray.filter(([, item]) => !FILTERED_TYPES.includes(item.type));
33
+ // function handleChange(event: InputEvent<string>): void {
34
+ // setFilter(event.target.name, event.target.value);
35
+ // router.refresh();
36
+ // }
37
+ // return (
38
+ // <ul className={componentClassNames?.root}>
39
+ // {hasSearch ? (
40
+ // <li className="relative">
41
+ // <SearchFilter onChange={handleChange} value={filters.get('search') || ''} />
42
+ // </li>
43
+ // ) : null}
44
+ // {filteredArray.map(([name, props]) => (
45
+ // <li key={String(name)} className="relative">
46
+ // <FilterItem
47
+ // key={String(name)}
48
+ // name={String(name)}
49
+ // onChange={handleChange}
50
+ // value={filters.get(String(name)) || ''}
51
+ // {...props}
52
+ // />
53
+ // </li>
54
+ // ))}
55
+ // {columns?.length ? (
56
+ // <Fragment>
57
+ // <li className="relative ml-auto">
58
+ // <ColumnFilter columns={columns} filters={filters} onChange={handleChange} />
59
+ // </li>
60
+ // <li className="relative">
61
+ // <SortFilter columns={columns} filters={filters} onChange={handleChange} />
62
+ // </li>
63
+ // </Fragment>
64
+ // ) : null}
65
+ // </ul>
66
+ // );
67
+ }
68
+ export default FilterBarClientComponent;
@@ -0,0 +1,5 @@
1
+ interface FilterClearButtonProps {
2
+ onClick: () => void;
3
+ }
4
+ declare function FilterClearButton({ onClick }: Readonly<FilterClearButtonProps>): React.ReactElement;
5
+ export default FilterClearButton;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ function FilterClearButton({ onClick }) {
3
+ // const Icon = getIcon('filterClearButton');
4
+ return (_jsx("button", { className: "absolute right-0 top-0 z-20 flex h-full w-8 select-none items-center justify-center text-xs", onClick: onClick, type: "button", children: "Remove" }));
5
+ }
6
+ export default FilterClearButton;
@@ -0,0 +1,12 @@
1
+ import { ClassNameProps } from '../../../styles/interfaces';
2
+ import type { FilterItemClassNames } from '../FilterItem';
3
+ interface FilterControlProps extends ClassNameProps<FilterItemClassNames> {
4
+ children: React.ReactNode;
5
+ isDisabled?: boolean;
6
+ isFocused?: boolean;
7
+ isHighlighted?: boolean;
8
+ onClear?: () => void;
9
+ onClick?: () => void;
10
+ }
11
+ declare function FilterControl({ classNameProps, classNames, children, isDisabled, isFocused, isHighlighted, onClear, onClick, }: Readonly<FilterControlProps>): React.ReactElement;
12
+ export default FilterControl;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // import FilterClearButton from '../FilterClearButton';
3
+ import { getClassNames } from '../../../styles/config';
4
+ import tw from '../../../styles/tw';
5
+ import FilterClearButton from '../FilterClearButton';
6
+ function FilterControl({ classNameProps, classNames, children, isDisabled, isFocused, isHighlighted, onClear, onClick, }) {
7
+ const componentClassNames = classNames || getClassNames('filterItem')?.(classNameProps);
8
+ return (_jsxs("div", { className: tw(componentClassNames?.root?.default, isDisabled ? 'pointer-events-none opacity-30' : null, isFocused ? componentClassNames?.root?.focused : null, isHighlighted ? componentClassNames?.root?.highlighted : null), children: [children, isFocused && onClear ? _jsx(FilterClearButton, { onClick: onClear }) : null, onClick ? (_jsx("button", { className: tw('absolute -inset-1 z-10 select-none text-transparent'), disabled: isDisabled, onClick: onClick, type: "button", children: "Edit" })) : null] }));
9
+ }
10
+ export default FilterControl;
@@ -0,0 +1,14 @@
1
+ import { InputProps } from '../../../forms/interfaces';
2
+ import { ClassNameProps, FocusableClassName, HighlightableClassName } from '../../../styles/interfaces';
3
+ import { ClientFilterObject, FilterType } from '../../interfaces';
4
+ export interface FilterItemClassNames {
5
+ root: FocusableClassName & HighlightableClassName;
6
+ value: string;
7
+ }
8
+ interface FilterItemProps<F extends FilterType> extends ClassNameProps<FilterItemClassNames>, ClientFilterObject<F>, InputProps<string> {
9
+ align?: 'left' | 'right';
10
+ icon?: React.ReactNode;
11
+ title?: string;
12
+ }
13
+ declare function FilterItem<F extends FilterType>({ align, classNameProps, classNames, config, icon, isDisabled, label, name, onChange, title, type, value, }: Readonly<FilterItemProps<F>>): React.ReactElement;
14
+ export default FilterItem;
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useState } from 'react';
4
+ import useClickOutside from '../../../hooks/useClickOutside';
5
+ import { getClassNames } from '../../../styles/config';
6
+ import renderValue from '../../utility/render-value';
7
+ import FilterControl from '../FilterControl';
8
+ import FilterPanel from '../FilterPanel';
9
+ function FilterItem({ align, classNameProps, classNames, config, icon, isDisabled, label, name, onChange, title, type, value, }) {
10
+ const componentClassNames = classNames || getClassNames('filterItem')?.(classNameProps);
11
+ const [isOpen, setIsOpen, node] = useClickOutside();
12
+ // const { dynamicConfig } = useDynamicData(config);
13
+ const [pendingValue, setPendingValue] = useState(value);
14
+ function toggleIsOpen() {
15
+ setIsOpen(!isOpen);
16
+ }
17
+ function handleApply() {
18
+ onChange?.({ target: { name, value: pendingValue } });
19
+ setIsOpen(false);
20
+ }
21
+ function handleChange(event) {
22
+ setPendingValue(event.target.value);
23
+ }
24
+ function handleClear() {
25
+ onChange?.({ target: { name, value: '' } });
26
+ setIsOpen(false);
27
+ }
28
+ useEffect(() => {
29
+ if (isOpen) {
30
+ setPendingValue(value);
31
+ }
32
+ }, [isOpen]);
33
+ // Switch filter doesn't require the usual `FilterPanel`, so we just return it here.
34
+ // if (type === 'switch') {
35
+ // return <SwitchFilter label={label} name={name} onChange={onChange} value={value || ''} />;
36
+ // }
37
+ return (_jsxs("div", { ref: node, children: [_jsxs(FilterControl
38
+ // isDisabled={isDisabled || (config?.data && config.data.length === 0)}
39
+ , {
40
+ // isDisabled={isDisabled || (config?.data && config.data.length === 0)}
41
+ isFocused: Boolean(value), isHighlighted: isOpen, onClear: handleClear, onClick: toggleIsOpen, children: [_jsx("p", { children: label }), value ? (_jsx("p", { className: componentClassNames?.value, children: renderValue(value, config) })) : null] }), _jsx(FilterPanel, { align: align, config: config, icon: icon, isOpen: isOpen, label: label, name: name, onApply: handleApply, onChange: handleChange, title: title, type: type, value: pendingValue })] }));
42
+ }
43
+ export default FilterItem;
@@ -0,0 +1,19 @@
1
+ import { InputProps } from '../../../forms/interfaces';
2
+ import { SizableClassName } from '../../../styles/interfaces';
3
+ import type { ClientFilterObject, FilterType } from '../../interfaces';
4
+ export interface FilterPanelClassNames {
5
+ content: string;
6
+ footer: string;
7
+ icon: string;
8
+ root: SizableClassName;
9
+ title: string;
10
+ }
11
+ export interface FilterPanelProps<F extends FilterType> extends ClientFilterObject<F>, InputProps<string> {
12
+ align?: 'left' | 'right';
13
+ icon?: React.ReactNode;
14
+ isOpen: boolean;
15
+ onApply: () => void;
16
+ title?: string;
17
+ }
18
+ declare function FilterPanel<F extends FilterType>({ align, config, icon, isOpen, label, name, onApply, onChange, title, type, value, }: Readonly<FilterPanelProps<F>>): React.ReactElement | null;
19
+ export default FilterPanel;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import BooleanFilter from '../../filters/BooleanFilter';
3
+ import CalendarFilter from '../../filters/CalendarFilter';
4
+ import DateFilter from '../../filters/DateFilter';
5
+ import DropdownFilter from '../../filters/DropdownFilter';
6
+ import MultiFilter from '../../filters/MultiFilter';
7
+ function FilterPanel({ align, config, icon, isOpen, label, name, onApply, onChange, title, type, value, }) {
8
+ const props = {
9
+ align,
10
+ icon,
11
+ isOpen,
12
+ label,
13
+ name,
14
+ onApply,
15
+ onChange,
16
+ title,
17
+ value,
18
+ };
19
+ if (type === 'boolean') {
20
+ return _jsx(BooleanFilter, { config: config, ...props });
21
+ }
22
+ if (type === 'calendar') {
23
+ return _jsx(CalendarFilter, { ...props });
24
+ }
25
+ if (type === 'date') {
26
+ return _jsx(DateFilter, { config: config, ...props });
27
+ }
28
+ if (type === 'dropdown') {
29
+ return _jsx(DropdownFilter, { config: config, ...props });
30
+ }
31
+ if (type === 'multi') {
32
+ return _jsx(MultiFilter, { config: config, ...props });
33
+ }
34
+ return null;
35
+ }
36
+ export default FilterPanel;
@@ -0,0 +1,3 @@
1
+ import type { FilterComponentProps } from '../interfaces';
2
+ declare function BooleanFilter({ config, name, onChange, value, ...filterBarProps }: Readonly<FilterComponentProps<'boolean'>>): React.ReactElement;
3
+ export default BooleanFilter;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Dropdown from '../../../forms/components/Dropdown';
3
+ import Filter from '../Filter';
4
+ function BooleanFilter({ config, name, onChange, value, ...filterBarProps }) {
5
+ function handleChange(event) {
6
+ onChange?.({ target: { name, value: event.target.value || '' } });
7
+ }
8
+ return (_jsx(Filter, { ...filterBarProps, children: _jsx(Dropdown, { isPanelOnly: true, name: name, onChange: handleChange, options: config?.data, value: value }) }));
9
+ }
10
+ export default BooleanFilter;
@@ -0,0 +1,3 @@
1
+ import type { FilterComponentProps } from '../interfaces';
2
+ declare function CalendarFilter({ name, onChange, value, ...filterBarProps }: Readonly<FilterComponentProps<'calendar'>>): React.ReactElement;
3
+ export default CalendarFilter;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Filter from '../Filter';
3
+ import { transformFromDate } from '../../utility/transform-date';
4
+ function CalendarFilter({ name, onChange, value, ...filterBarProps }) {
5
+ function handleChange(event) {
6
+ onChange?.({ target: { name, value: transformFromDate(event.target.value) } });
7
+ }
8
+ return (_jsx(Filter, { ...filterBarProps, size: "lg", children: "LOREM" }));
9
+ }
10
+ export default CalendarFilter;
@@ -0,0 +1,3 @@
1
+ import type { FilterComponentProps } from '../interfaces';
2
+ declare function DateFilter({ isOpen, onChange, ...filterBarProps }: Readonly<FilterComponentProps<'date'>>): React.ReactElement;
3
+ export default DateFilter;
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Fragment, useEffect, useState } from 'react';
4
+ import CalendarFilter from '../CalendarFilter';
5
+ import DropdownFilter from '../DropdownFilter';
6
+ function DateFilter({ isOpen, onChange, ...filterBarProps }) {
7
+ const [panel, setPanel] = useState('quick');
8
+ function handleDropdownChange(event) {
9
+ onChange?.(event);
10
+ if (event.target.value === 'custom') {
11
+ setPanel('calendar');
12
+ }
13
+ }
14
+ useEffect(() => {
15
+ if (isOpen) {
16
+ setPanel('quick');
17
+ }
18
+ }, [isOpen]);
19
+ return (_jsxs(Fragment, { children: [_jsx(DropdownFilter, { ...filterBarProps, isOpen: Boolean(isOpen && panel === 'quick'), onChange: handleDropdownChange }), _jsx(CalendarFilter, { ...filterBarProps, isOpen: Boolean(isOpen && panel === 'calendar'), onChange: onChange })] }));
20
+ }
21
+ export default DateFilter;
@@ -0,0 +1,3 @@
1
+ import type { FilterComponentProps } from '../interfaces';
2
+ declare function DropdownFilter({ config, name, onChange, value, ...filterBarProps }: Readonly<FilterComponentProps<'dropdown'>>): React.ReactElement;
3
+ export default DropdownFilter;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Dropdown from '../../../forms/components/Dropdown';
3
+ import Filter from '../Filter';
4
+ function DropdownFilter({ config, name, onChange, value, ...filterBarProps }) {
5
+ function handleChange(event) {
6
+ onChange?.({ target: { name, value: event.target.value || '' } });
7
+ }
8
+ return (_jsx(Filter, { ...filterBarProps, children: _jsx(Dropdown, { isPanelOnly: true, name: name, onChange: handleChange, options: config?.data, value: value }) }));
9
+ }
10
+ export default DropdownFilter;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { ClientFilterObject, FilterType } from '../../../filters/interfaces';
3
+ import { ClassNameProps } from '../../../styles/interfaces';
4
+ import { FilterPanelClassNames } from '../../components/FilterPanel';
5
+ import { FilterComponentSize } from '../interfaces';
6
+ interface FilterProps<F extends FilterType> extends ClassNameProps<FilterPanelClassNames>, ClientFilterObject<F> {
7
+ align?: 'left' | 'right';
8
+ children: React.ReactNode;
9
+ icon?: React.ReactNode;
10
+ isOpen: boolean;
11
+ onApply: () => void;
12
+ size?: FilterComponentSize;
13
+ title?: string;
14
+ }
15
+ declare function Filter<F extends FilterType>({ align, children, classNameProps, classNames, icon, isOpen, label, onApply, size, title, }: Readonly<FilterProps<F>>): React.ReactElement;
16
+ export default Filter;
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import Button from '../../../components/buttons/Button';
4
+ import Popover from '../../../components/utility/Popover';
5
+ import { getClassNames } from '../../../styles/config';
6
+ import { getIcon } from '../../../styles/icons';
7
+ import tw from '../../../styles/tw';
8
+ function Filter({ align, children, classNameProps, classNames, icon, isOpen, label, onApply, size, title, }) {
9
+ const componentClassNames = classNames || getClassNames('filterPanel')?.(classNameProps);
10
+ const DefaultIcon = getIcon('filter.panel');
11
+ return (_jsx(Popover, { align: align, isOpen: isOpen, children: _jsxs("div", { className: tw(componentClassNames?.root?.default, size ? componentClassNames?.root?.[size] : null), children: [_jsxs("p", { className: componentClassNames?.title, children: [icon === false ? null : (_jsx("span", { className: componentClassNames?.icon, children: icon || (DefaultIcon ? _jsx(DefaultIcon, {}) : null) })), title || (label ? `Filter by ${label}` : 'Filter')] }), _jsx("div", { className: componentClassNames?.content, children: children }), _jsx("div", { className: componentClassNames?.footer, children: _jsx(Button, { isFullWidth: true, onClick: onApply, variant: "primary", children: "Apply" }) })] }) }));
12
+ }
13
+ export default Filter;
@@ -0,0 +1,3 @@
1
+ import type { FilterComponentProps } from '../interfaces';
2
+ declare function MultiFilter({ config, name, onChange, value, ...filterBarProps }: Readonly<FilterComponentProps<'multi'>>): React.ReactElement;
3
+ export default MultiFilter;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Filter from '../Filter';
3
+ function MultiFilter({ config, name, onChange, value, ...filterBarProps }) {
4
+ // function handleChange(event: InputEvent<string[] | null>): void {
5
+ // onChange?.({ target: { name, value: transformFromMulti(event.target.value) } });
6
+ // }
7
+ return (_jsx(Filter, { ...filterBarProps, children: "LOREM" }));
8
+ }
9
+ export default MultiFilter;
@@ -0,0 +1,4 @@
1
+ import type { InputProps } from '../../../forms/interfaces';
2
+ type SearchFilterProps = Pick<InputProps<string>, 'onChange' | 'value'>;
3
+ declare function SearchFilter({ onChange, value }: Readonly<SearchFilterProps>): React.ReactElement;
4
+ export default SearchFilter;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment, useState } from 'react';
3
+ import FilterClearButton from '../../../filters/components/FilterClearButton';
4
+ import TextInput from '../../../forms/components/TextInput';
5
+ import { getIcon } from '../../../styles/icons';
6
+ import tw from '../../../styles/tw';
7
+ function SearchFilter({ onChange, value }) {
8
+ const Icon = getIcon('filter.search');
9
+ const [pendingValue, setPendingValue] = useState(value);
10
+ function handleChange(event) {
11
+ setPendingValue(event.target.value);
12
+ }
13
+ function handleClear() {
14
+ setPendingValue('');
15
+ onChange?.({ target: { name: 'search', value: '' } });
16
+ }
17
+ function handleKeyDown(event) {
18
+ if (event.key === 'Enter') {
19
+ onChange?.({ target: { name: 'search', value: pendingValue } });
20
+ }
21
+ }
22
+ //pointer-events-none absolute left-2 top-0 z-10 flex h-full items-center
23
+ //h-8 w-56 rounded-full border border-slate-400 pl-7 pr-3 text-xs text-white placeholder:text-slate-300
24
+ return (_jsxs(Fragment, { children: [_jsx("div", { className: "", children: Icon ? _jsx(Icon, { className: "h-4 w-4 text-white" }) : null }), _jsx(TextInput, { classNames: {
25
+ root: {
26
+ default: tw('', value ? 'bg-slate-700' : 'bg-transparent focus:bg-slate-700'),
27
+ },
28
+ }, name: "search", onChange: handleChange, onKeyDown: handleKeyDown, value: pendingValue }), value ? _jsx(FilterClearButton, { onClick: handleClear }) : null] }));
29
+ }
30
+ export default SearchFilter;
@@ -0,0 +1,10 @@
1
+ import { InputProps } from '../../forms/interfaces';
2
+ import { ClientFilterObject, FilterType } from '../interfaces';
3
+ export type FilterComponentSize = 'lg';
4
+ export interface FilterComponentProps<F extends FilterType> extends Omit<ClientFilterObject<F>, 'type'>, InputProps<string> {
5
+ icon?: React.ReactNode;
6
+ isOpen: boolean;
7
+ onApply: () => void;
8
+ size?: FilterComponentSize;
9
+ title?: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ declare function useFilters(): [
2
+ URLSearchParams,
3
+ (first: Record<string, string | null> | string, second?: string | null) => void
4
+ ];
5
+ export default useFilters;
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
3
+ function useFilters() {
4
+ const searchParams = useSearchParams();
5
+ const pathname = usePathname();
6
+ const router = useRouter();
7
+ function setToURL(searchParams) {
8
+ router.replace(`${pathname}?${searchParams.toString()}`);
9
+ }
10
+ function setFilters(first, second) {
11
+ const newSearchParams = new URLSearchParams(searchParams.toString());
12
+ const data = typeof first === 'string' ? { [first]: second } : first;
13
+ for (const [name, value] of Object.entries(data)) {
14
+ if (value === '' || value === null || typeof value === 'undefined') {
15
+ newSearchParams.delete(name);
16
+ }
17
+ else {
18
+ newSearchParams.set(name, value);
19
+ }
20
+ }
21
+ setToURL(newSearchParams);
22
+ }
23
+ return [new URLSearchParams(searchParams.toString()), setFilters];
24
+ }
25
+ export default useFilters;
@@ -0,0 +1,2 @@
1
+ export * from './interfaces';
2
+ export { default as filter } from './utility/filter';
@@ -0,0 +1,2 @@
1
+ export * from './interfaces';
2
+ export { default as filter } from './utility/filter';
@@ -0,0 +1,28 @@
1
+ import type { DropdownObject } from '../forms/interfaces';
2
+ export type FilterType = 'assistive' | 'boolean' | 'calendar' | 'column' | 'date' | 'dropdown' | 'money' | 'multi' | 'range' | 'search' | 'sort' | 'switch';
3
+ export interface FilterConfig {
4
+ align?: 'left' | 'right';
5
+ icon?: React.ReactNode;
6
+ title?: string;
7
+ }
8
+ export interface FilterConfigWithBooleanData extends FilterConfig {
9
+ data?: [string, string];
10
+ }
11
+ export interface FilterConfigWithData extends FilterConfig {
12
+ data?: DropdownObject[];
13
+ url?: string;
14
+ }
15
+ export interface ClientFilterObject<F extends FilterType> {
16
+ config?: F extends 'boolean' | 'date' | 'dropdown' | 'multi' ? FilterConfigWithData : FilterConfig;
17
+ label?: string;
18
+ type?: F;
19
+ }
20
+ export type ClientFilterMap<T> = {
21
+ [K in keyof T]?: ClientFilterObject<FilterType>;
22
+ };
23
+ export interface FilterObject<T, F extends FilterType> extends ClientFilterObject<F> {
24
+ transformer: (value: string) => T;
25
+ }
26
+ export type FilterMap<T> = {
27
+ [K in keyof T]?: FilterObject<T[K], FilterType>;
28
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const NON_FILTER_KEYS: string[];
@@ -0,0 +1 @@
1
+ export const NON_FILTER_KEYS = ['action', 'columns', 'id', 'page', 'selected', 'sort'];
@@ -0,0 +1,2 @@
1
+ declare function checkHasFilters(searchParams: Record<string, string> | null): boolean;
2
+ export default checkHasFilters;
@@ -0,0 +1,8 @@
1
+ import { NON_FILTER_KEYS } from '../lang';
2
+ function checkHasFilters(searchParams) {
3
+ if (!searchParams) {
4
+ return false;
5
+ }
6
+ return Object.keys(searchParams).filter((key) => !NON_FILTER_KEYS.includes(key)).length > 0;
7
+ }
8
+ export default checkHasFilters;
@@ -0,0 +1,3 @@
1
+ import type { ClientFilterMap, FilterMap } from '../interfaces';
2
+ declare function createClientFilterMap<T>(map?: FilterMap<T>): ClientFilterMap<T>;
3
+ export default createClientFilterMap;
@@ -0,0 +1,14 @@
1
+ function createClientFilterMap(map) {
2
+ const clientMap = {};
3
+ if (!map) {
4
+ return clientMap;
5
+ }
6
+ for (const key in map) {
7
+ if (Object.hasOwn(map, key) && typeof map[key] !== 'undefined') {
8
+ const { transformer, ...rest } = map[key];
9
+ clientMap[key] = rest;
10
+ }
11
+ }
12
+ return clientMap;
13
+ }
14
+ export default createClientFilterMap;