@agilant/toga-blox 1.0.43 → 1.0.45
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/InputAndCheck/InputAndCheck.js +12 -3
- package/dist/components/MagnifyingIcon/types.d.ts +2 -2
- package/dist/components/SortArrows/SortArrows.d.ts +1 -3
- package/dist/components/SortArrows/SortArrows.js +2 -1
- package/dist/components/SortArrows/types.d.ts +4 -3
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// In your NPM library @agilant/toga-blox/dist/components/InputAndCheck/InputAndCheck
|
|
3
|
+
// EXACTLY as you showed (with Badge, TableHeaderInput, etc.):
|
|
2
4
|
import { useEffect, useRef, useState } from "react";
|
|
3
5
|
import { getFontAwesomeIcon } from "../../utils/getFontAwesomeIcon";
|
|
4
6
|
import Badge from "../Badge";
|
|
@@ -6,6 +8,7 @@ import TableHeaderInput from "../TableHeaderInput";
|
|
|
6
8
|
function InputAndCheck({ closeOutSearch, setResetSearch, setEditingHeader, column, searchCriteria, setSearchCriteria, badgeColor = "bg-blue-400", badgeIcon = { icon: "x", weight: "regular" }, cancelIcon = { icon: "xmark", weight: "regular" }, iconBadgeContainerClasses = "mr-2 rounded-full p-2 text-white cursor-pointer my-2 text-sm", searchIcon = { icon: "search", weight: "regular" }, searchIconClasses = " text-md absolute right-3 top-2 text-gray-400 hover:cursor-pointer hover:text-blue-500 ", additionalInputClasses = "min-w-[300px] max-w-[250px] border-b border-t-0 border-r-0 rounded-tl-none rounded-tr-lg bg-gray-50 text-gray-800 flex", secondIconClasses = "flex absolute right-6 top-0.5 items-center text-gray-400 hover:cursor-pointer hover:text-blue-400", initialIcon = { icon: "search", weight: "regular" }, initialIconClasses = "text-gray-400", }) {
|
|
7
9
|
const containerRef = useRef(null);
|
|
8
10
|
const [localSearchText, setLocalSearchText] = useState("");
|
|
11
|
+
// Load initial text from searchCriteria:
|
|
9
12
|
useEffect(() => {
|
|
10
13
|
const existing = searchCriteria.find((criterion) => criterion.searchColumn.id === column.id);
|
|
11
14
|
if (existing) {
|
|
@@ -15,24 +18,28 @@ function InputAndCheck({ closeOutSearch, setResetSearch, setEditingHeader, colum
|
|
|
15
18
|
setLocalSearchText("");
|
|
16
19
|
}
|
|
17
20
|
}, [searchCriteria, column.id]);
|
|
21
|
+
// Handle changes
|
|
18
22
|
const handleInputChange = (e) => {
|
|
19
23
|
setLocalSearchText(e.target.value);
|
|
20
24
|
};
|
|
25
|
+
// Submit
|
|
21
26
|
const handleSubmit = () => {
|
|
22
27
|
const trimmed = localSearchText.trim();
|
|
23
28
|
if (!trimmed) {
|
|
29
|
+
// remove criterion
|
|
24
30
|
setSearchCriteria((prev) => prev.filter((c) => c.searchColumn.id !== column.id));
|
|
25
31
|
}
|
|
26
32
|
else {
|
|
33
|
+
// add or update
|
|
27
34
|
setSearchCriteria((prev) => {
|
|
28
35
|
const existingIndex = prev.findIndex((c) => c.searchColumn.id === column.id);
|
|
29
36
|
if (existingIndex >= 0) {
|
|
30
|
-
const
|
|
31
|
-
|
|
37
|
+
const clone = [...prev];
|
|
38
|
+
clone[existingIndex] = {
|
|
32
39
|
searchColumn: column,
|
|
33
40
|
submittedSearchText: trimmed,
|
|
34
41
|
};
|
|
35
|
-
return
|
|
42
|
+
return clone;
|
|
36
43
|
}
|
|
37
44
|
else {
|
|
38
45
|
return [
|
|
@@ -44,12 +51,14 @@ function InputAndCheck({ closeOutSearch, setResetSearch, setEditingHeader, colum
|
|
|
44
51
|
}
|
|
45
52
|
setEditingHeader(null);
|
|
46
53
|
};
|
|
54
|
+
// Clear
|
|
47
55
|
const handleClearSearch = () => {
|
|
48
56
|
setSearchCriteria((prev) => prev.filter((c) => c.searchColumn.id !== column.id));
|
|
49
57
|
setLocalSearchText("");
|
|
50
58
|
setResetSearch((prev) => !prev);
|
|
51
59
|
closeOutSearch(null);
|
|
52
60
|
};
|
|
61
|
+
// Let user press Enter
|
|
53
62
|
const handleKeyDown = (e) => {
|
|
54
63
|
if (e.key === "Enter") {
|
|
55
64
|
e.preventDefault();
|
|
@@ -5,8 +5,8 @@ export interface MagnifyingIconProps<T extends object> {
|
|
|
5
5
|
setEditingHeader: (index: number | null) => void;
|
|
6
6
|
setHeaderValue: (value: string) => void;
|
|
7
7
|
column: ColumnInstance<T>;
|
|
8
|
-
setSearchColumn
|
|
9
|
-
setActiveColumnFromSearch
|
|
8
|
+
setSearchColumn?: (col: Column<T>) => void;
|
|
9
|
+
setActiveColumnFromSearch?: (id: string) => void;
|
|
10
10
|
setActiveColumn: (index: number) => void;
|
|
11
11
|
iconColor?: string;
|
|
12
12
|
iconBackgroundColor?: string;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { SortArrowsProps } from "./types";
|
|
2
|
-
declare const SortArrows: <T extends object>({ column, setSortColumn, slug, isNested, parentIndex, onSortChange, renderPortalOverlay, onRequestClose, counterIcon, directionContainerClassNames, }: SortArrowsProps<T>
|
|
3
|
-
getFontAwesomeIconFn?: (iconName: string, iconStyle: string) => React.ReactElement | null;
|
|
4
|
-
}) => JSX.Element | null;
|
|
2
|
+
declare const SortArrows: <T extends object>({ column, setSortColumn, slug, isNested, parentIndex, onSortChange, renderPortalOverlay, onRequestClose, counterIcon, directionContainerClassNames, }: SortArrowsProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
5
3
|
export default SortArrows;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// src/components/SortArrows/SortArrows.tsx
|
|
2
3
|
import { useRef } from "react";
|
|
3
4
|
import { motion } from "framer-motion";
|
|
4
5
|
import { useSortArrowsViewModel } from "./useSortArrowsViewModel";
|
|
@@ -26,7 +27,7 @@ const SortArrows = ({ column, setSortColumn, slug, isNested, parentIndex, onSort
|
|
|
26
27
|
setShowArrowContainer(false);
|
|
27
28
|
onRequestClose?.();
|
|
28
29
|
};
|
|
29
|
-
return (_jsxs("div", { "data-testid": `sort-arrows-${slug}`, ref: containerRef, className: arrowContainerClassNames, onClick: handleParentClick, children: [isActive && (_jsxs("div", { className: "relative", children: [_jsx("div", { className: `${counterIcon.iconClassNames} ${activeDirection === "desc" ? "rotate-180" : ""}`, children: _jsx("span", { className:
|
|
30
|
+
return (_jsxs("div", { "data-testid": `sort-arrows-${slug}`, ref: containerRef, className: arrowContainerClassNames, onClick: handleParentClick, children: [isActive && (_jsxs("div", { className: "relative", children: [_jsx("div", { className: `${counterIcon.iconClassNames} ${activeDirection === "desc" ? "rotate-180" : ""}`, children: _jsx("span", { className: counterIcon.numberSize, children: getFontAwesomeIcon(counterIcon.icon, counterIcon.weight) }) }), _jsx("span", { className: `${counterIcon.numberClassNames} ${activeDirection === "desc" && " pb-0.5"}`, children: sortOrderNumber })] })), !isActive && (_jsxs(_Fragment, { children: [_jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "up", setColumn: () => { }, isActive: false }), _jsx(SortArrowIcon, { slug: slug, parentIndex: parentIndex, columnName: String(column.render("Header")), direction: "down", setColumn: () => { }, isActive: false })] })), showArrowContainer && (_jsxs(motion.div, { className: `${directionContainerClassNames} ${column.id === "col1" ? "left-[5px]" : ""}`, initial: "initial", animate: "animate", exit: "exit", children: [activeDirection !== "asc" && (_jsxs("div", { className: "flex border-b-1 p-1 hover:bg-blue-50", onClick: () => handleClick("up"), children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("arrowUp", "regular") }), _jsx("span", { className: "flex-1 text-left pl-4", children: "Ascending" })] })), activeDirection !== "desc" && (_jsxs("div", { className: "flex p-1 hover:bg-blue-50 border-b-1", onClick: () => handleClick("down"), children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("arrowDown", "regular") }), _jsx("span", { className: "flex-1 text-left pl-4", children: "Descending" })] })), isActive && (_jsxs("div", { className: "flex border-b-1 p-1 hover:bg-blue-50", onClick: handleResetSort, children: [_jsx("span", { className: "pl-1 text-primary", children: getFontAwesomeIcon("rotateLeft", "solid") }), _jsx("span", { className: "flex-1 text-left pl-3", children: "Reset" })] }))] })), showArrowContainer &&
|
|
30
31
|
renderPortalOverlay &&
|
|
31
32
|
renderPortalOverlay(handleClose)] }));
|
|
32
33
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ColumnInstance } from "react-table";
|
|
2
|
+
export interface CustomColumnInstance<T extends object> extends ColumnInstance<T> {
|
|
3
|
+
/** We want to guarantee an accessor exists and can be a string or function, etc. */
|
|
4
|
+
accessor: string | number | symbol | ((row: T) => any);
|
|
5
|
+
}
|
|
2
6
|
export interface SortArrowsProps<T extends object> {
|
|
3
7
|
column: CustomColumnInstance<T>;
|
|
4
8
|
setSortColumn: any;
|
|
@@ -17,6 +21,3 @@ export interface SortArrowsProps<T extends object> {
|
|
|
17
21
|
};
|
|
18
22
|
directionContainerClassNames?: string;
|
|
19
23
|
}
|
|
20
|
-
export interface CustomColumnInstance<T extends object> extends ColumnInstance<T> {
|
|
21
|
-
accessor: string | number | symbol | ((row: T) => any);
|
|
22
|
-
}
|