ehscan-react-components 0.1.36 → 0.1.38
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/README.md +1 -0
- package/dist/AddBox.d.ts +12 -0
- package/dist/AddBox.js +11 -0
- package/dist/Components.d.ts +2 -0
- package/dist/Components.js +2 -0
- package/dist/DropDown.js +9 -1
- package/dist/style/addbox.css +112 -0
- package/dist/tools/useChangeAddBox.d.ts +7 -0
- package/dist/tools/useChangeAddBox.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/AddBox.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './style/addbox.css';
|
|
3
|
+
interface Entry {
|
|
4
|
+
id: number;
|
|
5
|
+
title: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
value: Entry[];
|
|
9
|
+
onChange: (value: string | Entry[], id?: number) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const AddBox: React.FC<Props>;
|
|
12
|
+
export {};
|
package/dist/AddBox.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import './style/addbox.css';
|
|
3
|
+
export const AddBox = ({ value, onChange }) => {
|
|
4
|
+
const closeBtn = () => (_jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "8", y1: "8", x2: "16", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" }), _jsx("line", { x1: "16", y1: "8", x2: "8", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" })] }));
|
|
5
|
+
const plusBtn = () => (_jsxs("svg", { className: "ext-add-inputbox-plus-svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: [_jsx("line", { x1: "12", y1: "5", x2: "12", y2: "19", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" }), _jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" })] }));
|
|
6
|
+
const addRow = () => onChange([...value, { id: Date.now(), title: "" }]);
|
|
7
|
+
const removeRow = (id) => onChange(value.filter((entry) => entry.id !== id));
|
|
8
|
+
const changeTxt = (id, newTitle) => onChange(newTitle, id);
|
|
9
|
+
const btnRow = (item) => (_jsxs("div", { className: "ext-add-content-row", children: [_jsx("div", { className: "ext-add-content-row-bullet", children: "\u2022" }), _jsx("input", { className: "ext-addbox-input", type: "text", placeholder: "...", value: item.title, onChange: (e) => changeTxt(item.id, e.target.value), spellCheck: false }), _jsx("div", { className: "ext-addbox-textarea-tag-erase", onClick: () => removeRow(item.id), children: closeBtn() })] }, item.id));
|
|
10
|
+
return (_jsxs("div", { className: "ext-add-inputbox", children: [_jsxs("div", { className: "ext-add-inputbox-title", children: [_jsx("div", { className: "ext-add-inputbox-title-txt", children: "title" }), _jsx("div", { className: "ext-add-inputbox-title-plus-wrapper", children: _jsx("div", { className: "ext-add-inputbox-title-plus", onClick: addRow, children: plusBtn() }) })] }), _jsx("div", { className: "ext-add-inputbox-body", children: value.map((item) => btnRow(item)) })] }));
|
|
11
|
+
};
|
package/dist/Components.d.ts
CHANGED
package/dist/Components.js
CHANGED
package/dist/DropDown.js
CHANGED
|
@@ -35,7 +35,15 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
35
35
|
if (e.key === "Enter" && tabId !== undefined) {
|
|
36
36
|
console.log('use', display[tabId]);
|
|
37
37
|
addItem(tabId);
|
|
38
|
-
setTabId(
|
|
38
|
+
setTabId(prevTabId => {
|
|
39
|
+
if (prevTabId === undefined)
|
|
40
|
+
return 0;
|
|
41
|
+
if (display[prevTabId])
|
|
42
|
+
return prevTabId;
|
|
43
|
+
if (display[prevTabId - 1])
|
|
44
|
+
return prevTabId - 1;
|
|
45
|
+
return 0;
|
|
46
|
+
});
|
|
39
47
|
}
|
|
40
48
|
// Add other keys here if needed
|
|
41
49
|
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
.ext-add-inputbox{
|
|
2
|
+
background-color: transparent;
|
|
3
|
+
position: relative;
|
|
4
|
+
border-radius: var(--ext-add-inputbox-border-radius, 10px);
|
|
5
|
+
user-select: none;
|
|
6
|
+
border:2px solid white
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ext-add-inputbox-title{
|
|
10
|
+
display: grid;
|
|
11
|
+
grid-template-columns: 1fr auto;
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: var(--ext-add-inputbox-title-top, -15px);
|
|
14
|
+
width: 100%;
|
|
15
|
+
align-items: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.ext-add-inputbox-plus-svg > line{
|
|
19
|
+
stroke: var(--ext-add-inputbox-plus-svg-stroke, white);
|
|
20
|
+
stroke-width: var(--ext-add-inputbox-plus-svg-strokeWidth, 3);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ext-add-inputbox-title-plus-wrapper{
|
|
24
|
+
background-color: var(--ext-add-inputbox-plus-bck-clr, lightblue);
|
|
25
|
+
padding: 0 var(--ext-add-inputbox-plus-padding, 7px);
|
|
26
|
+
display: flex;
|
|
27
|
+
margin-right: var(--ext-add-inputbox-title-plus-margin-right, 15px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ext-add-inputbox-title-plus{
|
|
31
|
+
display: flex;
|
|
32
|
+
background-color: var(--ext-add-inputbox-title-plus-bck-clr, transparent);
|
|
33
|
+
border-radius: var(--ext-add-inputbox-title-plus-border-radius, 50px);
|
|
34
|
+
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
height: var(--ext-add-inputbox-title-plus-h, 25px);
|
|
38
|
+
width: var(--ext-add-inputbox-title-plus-w, 25px);
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
border: var(--ext-add-inputbox-title-plus-border, 2px solid white);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ext-add-inputbox-title-plus:hover{
|
|
44
|
+
background-color: var(--ext-add-inputbox-title-plus-bck-clr-hvr, lightgray);
|
|
45
|
+
border: var(--ext-add-inputbox-title-plus-border, 2px solid lightgrey);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.ext-add-inputbox-title-txt{
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
border-radius: 4px;
|
|
52
|
+
margin-left: var(--ext-add-inputbox-txt-margin-left, 10px);
|
|
53
|
+
padding: 0 7px;
|
|
54
|
+
background-color: var(--ext-add-inputbox-txt-bck-clr, lightblue);
|
|
55
|
+
color: var(--ext-add-inputbox-txt-clr, black);
|
|
56
|
+
width: fit-content;
|
|
57
|
+
height: var(--ext-add-inputbox-txt-plus-h, 20px);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.ext-add-inputbox-body{
|
|
61
|
+
padding: 20px 10px 10px 10px;
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
gap: 7px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.ext-add-content-row {
|
|
68
|
+
height: var(--ext-add-content-row-height, 30px);
|
|
69
|
+
background-color: var(--ext-add-content-row-bck-clr, white);
|
|
70
|
+
padding: 0 5px 0 15px;
|
|
71
|
+
border-radius: var(--ext-add-content-row-border-radius, 50px);
|
|
72
|
+
display: grid;
|
|
73
|
+
grid-template-columns: auto 1fr auto;
|
|
74
|
+
align-items: center;
|
|
75
|
+
gap: 5px;
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.ext-add-content-row:hover{
|
|
80
|
+
filter: brightness(1.1);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.ext-add-content-row-bullet{
|
|
85
|
+
padding: 2px 0 0 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.ext-addbox-textarea-tag-erase {
|
|
89
|
+
width: var(--tag-erase-w, 25px);
|
|
90
|
+
height: var(--tag-erase-h, 25px);
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
justify-content: center;
|
|
94
|
+
border-radius: 50px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.ext-addbox-textarea-tag-erase:hover{
|
|
98
|
+
background-color: darkgray;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.ext-addbox-input {
|
|
103
|
+
border-radius: 10px;
|
|
104
|
+
padding: 0 5px 0 10px;
|
|
105
|
+
border: 1px solid transparent;
|
|
106
|
+
height: 75%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.ext-addbox-input:focus {
|
|
110
|
+
background: #f0f4ff;
|
|
111
|
+
border: 1px dashed darkgrey;
|
|
112
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Entry = {
|
|
2
|
+
id: number;
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
type InValue = Record<string, Entry[]>;
|
|
6
|
+
export declare const useChangeAddBox: (inValue: InValue, setInValue: React.Dispatch<React.SetStateAction<InValue>>, tag: string) => (value: Entry[] | string, id?: number) => void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
export const useChangeAddBox = (inValue, setInValue, tag) => {
|
|
3
|
+
const changeTag = useCallback((value, id) => {
|
|
4
|
+
if (!(tag in inValue))
|
|
5
|
+
return;
|
|
6
|
+
if (id !== undefined) { // change single row
|
|
7
|
+
setInValue(prev => (Object.assign(Object.assign({}, prev), { [tag]: prev[tag].map(item => item.id === id ? Object.assign(Object.assign({}, item), { title: value }) : item) })));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
setInValue(prev => (Object.assign(Object.assign({}, prev), { [tag]: value })));
|
|
11
|
+
}, [inValue, setInValue, tag]);
|
|
12
|
+
return changeTag;
|
|
13
|
+
};
|