ehscan-react-components 0.1.37 → 0.1.39

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 CHANGED
@@ -4,6 +4,9 @@
4
4
  - Window
5
5
  - TextArea
6
6
  - TextAreaDropDown
7
+ - AddBox
8
+ - useChangeAddBox.tsx
9
+ - css changes on vars can be done in parent class
7
10
 
8
11
  # Styling
9
12
 
@@ -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", { id: `inputAddBox-${item.id}`, 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
+ };
@@ -2,3 +2,5 @@ export { Button } from './Button';
2
2
  export { Window } from './Window';
3
3
  export { TextArea } from './TextArea';
4
4
  export { TextAreaDropDown } from './TextAreaDropDown';
5
+ export { AddBox } from './AddBox';
6
+ export { useChangeAddBox } from './tools/useChangeAddBox';
@@ -3,3 +3,5 @@ export { Button } from './Button';
3
3
  export { Window } from './Window';
4
4
  export { TextArea } from './TextArea';
5
5
  export { TextAreaDropDown } from './TextAreaDropDown';
6
+ export { AddBox } from './AddBox';
7
+ export { useChangeAddBox } from './tools/useChangeAddBox';
@@ -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: var(--ext-add-inputbox-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: var(--ext-addbox-textarea-tag-erase-hover-bck-clr, 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: var(--ext-addbox-input-focus-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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-components",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",