dyvix-ui 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 younisayoub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # dyvix-ui
@@ -0,0 +1,5 @@
1
+ [
2
+ {
3
+ "s": ["Dyvix"]
4
+ }
5
+ ]
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "element": "text",
4
+ "tag": "input",
5
+ "tag-type": "text",
6
+ "default-class": "modal-text",
7
+ "aria": {
8
+ "role": "textbox",
9
+ "aria-required": false,
10
+ "aria-label": ""
11
+ },
12
+ "inherited-element": ["email", "password", "search", "url", "tel"],
13
+ "supports-placeholder": true,
14
+ "is_custom": false,
15
+ "requires-options": false,
16
+ "r-variant": true
17
+ },
18
+ {
19
+ "element": "select",
20
+ "tag": "select",
21
+ "default-class": "select",
22
+ "aria": {
23
+ "role": "combobox",
24
+ "aria-required": false,
25
+ "aria-label": ""
26
+ },
27
+ "supports-placeholder": true,
28
+ "is_custom": true,
29
+ "requires-options": true,
30
+ "r-variant": true
31
+ }
32
+ ]
@@ -0,0 +1,60 @@
1
+ .modal
2
+ {
3
+ display: flex;
4
+ flex-direction: column;
5
+ margin: 5rem auto;
6
+ width: 30rem;
7
+ height: 30rem;
8
+ font-family: "Geist";
9
+ border: 1px solid black;
10
+ border-radius: 50%;
11
+ }
12
+ #modal-header
13
+ {
14
+ width: 100%;
15
+ text-align: center;
16
+ font-size: xx-large;
17
+ font-weight: bolder;
18
+ margin-bottom: 0;
19
+ }
20
+ .grouped-elements
21
+ {
22
+ display: flex;
23
+ gap: 20px;
24
+ flex-direction: row;
25
+ margin: .5rem auto;
26
+ width: 80%;
27
+ margin-top: 1rem;
28
+ }
29
+ .grouped-elements input {
30
+ flex: 1;
31
+ max-width: 15rem;
32
+ min-width: 0;
33
+ }
34
+ .grouped-elements:first-of-type
35
+ {
36
+ margin-top: 3rem;
37
+ }
38
+ .modal-text
39
+ {
40
+ width: 100%;
41
+ border: 1px solid rgba(255,255,255,0.2);
42
+ border-radius: 1rem;
43
+ height: 25px;
44
+ margin: 0 auto;
45
+ background: transparent;
46
+ padding: 0.5rem 1rem;
47
+ }
48
+ .modal-text:focus {
49
+ outline: none;
50
+ border-color: #0ea5e9;
51
+ }
52
+ .modal-btn {
53
+ width: 8rem;
54
+ height: 2.5rem;
55
+ margin: 1rem auto;
56
+ border: 1px solid black;
57
+ border-radius: 1rem;
58
+ background-color: #0ea5e9;
59
+ margin-top: 3rem;
60
+ }
@@ -0,0 +1,144 @@
1
+ import elementsData from "./dependencies/elements.json"
2
+ import SelectEngine from "../select/SelectEngine";
3
+ import "./dependencies/style/elements.css"
4
+
5
+ const defaultElement = {type: "!", placeholder: ["!"], id: "!", className: "!", amount: 1 };
6
+ const supportedTypes = ["text", "select", "email", "password", "search", "url", "tel"]
7
+ const componentsMap = {"SelectEngine": SelectEngine};
8
+ function Modal({title, type, elements, animation, Id, Class})
9
+ {
10
+
11
+ const fields = SerializeData(title, type, elements, animation, Id, Class);
12
+
13
+ if(fields === null)
14
+ {
15
+ return null;
16
+ }
17
+
18
+ //console.log(fields);
19
+ //console.log(elementsData);
20
+ return (
21
+ <>
22
+ <div className={Class} id={Id}>
23
+ <h3 id="modal-header">{title}</h3>
24
+
25
+ {fields.map((field, i) => {
26
+ const elementDef = elementsData.find(e => e.element === field.type) || elementsData.find(e => e["inherited-element"]?.includes(field.type));
27
+ const Tag = elementDef.is_custom? componentsMap[elementDef.tag] : elementDef.tag;
28
+
29
+ return(
30
+ <div className="grouped-elements" key={`1${i}`} >
31
+ {Array.from({ length: field.amount }, (_, j) => {
32
+ const Tagprobs = {
33
+ className: elementDef["default-class"],
34
+ role: elementDef.aria.role,
35
+ ...(elementDef["supports-placeholder"] && ({placeholder: Array.isArray(field.placeholder) ? field.placeholder[j] : field.placeholder })),
36
+ ...(elementDef["tag-type"] && ({ type: elementDef["tag-type"] }))
37
+ }
38
+ return <Tag key={j} {...Tagprobs}/>
39
+ })
40
+ }
41
+
42
+ </div>
43
+ )
44
+ })}
45
+ <button className="modal-btn">Submit</button>
46
+ </div>
47
+ </>
48
+ )
49
+ }
50
+ function SerializeData(title, type, elements, animation, Id, Class)
51
+ {
52
+ const validator = ValidateInput(title, type, elements, animation, Id, Class)
53
+
54
+ if(validator.status !== 1)
55
+ {
56
+ console.error(validator.error)
57
+ return null
58
+ }
59
+
60
+ const normalizedElements = elements.map(ele => ({...defaultElement, ...ele}));
61
+ const eleValidator = validateElements(normalizedElements);
62
+
63
+ if(eleValidator.status !== 1)
64
+ {
65
+ console.error(eleValidator.error)
66
+ return null
67
+ }
68
+
69
+ return normalizedElements;
70
+ }
71
+ function ValidateInput(title, type, elements = [], animation, Id, Class)
72
+ {
73
+ if(!title)
74
+ {
75
+ return {status: -1, error: "Please provide a title"};
76
+ }
77
+ if (!Array.isArray(elements) || !elements.every(ele => typeof ele === 'object'))
78
+ {
79
+ return {status: -1, error: "Element should be provided as an array of objects."};
80
+ }
81
+ if(animation && typeof animation === 'string')
82
+ {
83
+ // todo when you figure out animations configue you need to write a great validation here
84
+ }
85
+
86
+ return {status: 1};
87
+ }
88
+ function validateElements(elements)
89
+ {
90
+
91
+ for(const element of elements)
92
+ {
93
+ if(!supportedTypes.includes(element.type))
94
+ {
95
+ return {status: -1, error: "Elements should include a valid type."};
96
+ }
97
+ if(element.amount < 1 || element.amount > 3)
98
+ {
99
+ return {status: -1, error: "Element amount should be positive and less than 3."};
100
+ }
101
+ else if (element.amount > 1)
102
+ {
103
+ if (!Array.isArray(element.placeholder) || element.placeholder.length !== element.amount)
104
+ {
105
+ return {status: -1, error: "Element placeholder should be provided as an array of the same length as the provided amount."};
106
+ }
107
+ }
108
+ else
109
+ {
110
+ if(typeof element.placeholder !== "string")
111
+ {
112
+ return {status: -1, error: "Element placeholder should be provided as string when the amount is set to 1."};
113
+ }
114
+ }
115
+ };
116
+
117
+ return {status: 1};
118
+ }
119
+
120
+ export default Modal;
121
+ /*
122
+ {
123
+ title: "Create Post",
124
+ animation: "bubble", // or "slide", "fade", "scale", "flip"
125
+ fields: [
126
+ {
127
+ type: "text",
128
+ name: "caption",
129
+ placeholder: "What's on your mind?",
130
+ className: "caption-input",
131
+ id: "post-caption"
132
+ },
133
+ {
134
+ type: "file",
135
+ name: "image",
136
+ className: "file-upload",
137
+ id: "post-image",
138
+ holder: "upload-zone" // custom wrapper class?
139
+ },
140
+ ],
141
+ onSubmit: (data) => createPost(data)
142
+ }
143
+ prototype
144
+ */
@@ -0,0 +1,100 @@
1
+ //needs testing and polishing
2
+ import React, { forwardRef, useEffect } from 'react';
3
+ import gsap from 'gsap';
4
+ const SelectEngine = forwardRef(
5
+ (
6
+ {
7
+ elements = [],
8
+ is_open,
9
+ is_rendered,
10
+ selectedElement = '',
11
+ controller,
12
+ inputRef,
13
+ OnChangeCallback
14
+ },
15
+ ref
16
+ ) => {
17
+ function ChangeValue(value) {
18
+ if (!value) {
19
+ return;
20
+ }
21
+ inputRef.current.value = value;
22
+ controller((prevData) => ({
23
+ ...prevData,
24
+ is_open: false,
25
+ }));
26
+ // Fixes major bug
27
+ OnChangeCallback();
28
+ }
29
+
30
+ React.useEffect(() => {
31
+ if (!ref?.current) return;
32
+
33
+ if (is_open) {
34
+ gsap.fromTo(
35
+ ref.current,
36
+ {
37
+ height: 0,
38
+ opacity: 0,
39
+ },
40
+ {
41
+ height: 'auto',
42
+ opacity: 1,
43
+ duration: 1.1,
44
+ ease: 'power2.inOut',
45
+ }
46
+ );
47
+ } else {
48
+ gsap.to(ref.current, {
49
+ height: 0,
50
+ opacity: 0,
51
+ duration: 0.3,
52
+ ease: 'power2.inOut',
53
+ });
54
+ }
55
+ }, [is_open, elements]);
56
+
57
+ return (
58
+ <>
59
+ {is_rendered && (
60
+ <ul
61
+ id="dropdown-select"
62
+ role="listbox"
63
+ style={
64
+ is_open
65
+ ? { background: 'whitesmoke', border: '1px solid #e2e8f0' }
66
+ : { background: 'transparent', border: 'none' }
67
+ }
68
+ ref={ref}
69
+ >
70
+ {is_open &&
71
+ elements.map((element, index) => (
72
+ <li
73
+ role="listitem"
74
+ key={index}
75
+ onClick={() => ChangeValue(element)}
76
+ >
77
+ {element}
78
+ </li>
79
+ ))}
80
+ {is_open && elements.length === 0 && (
81
+ <li
82
+ role="listitem"
83
+ key={404}
84
+ style={{
85
+ fontSize: '.5rem',
86
+ color: '#888',
87
+ textAlign: 'center',
88
+ }}
89
+ >
90
+ Not Found!
91
+ </li>
92
+ )}
93
+ </ul>
94
+ )}
95
+ </>
96
+ );
97
+ }
98
+ );
99
+
100
+ export default SelectEngine;
package/index.jsx ADDED
@@ -0,0 +1 @@
1
+ export { default as Modal } from "./components/modal/modal";
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "dyvix-ui",
3
+ "version": "0.0.1",
4
+ "main": "index.jsx",
5
+ "type": "module"
6
+ }