@zuzjs/ui 0.3.7 → 0.3.8
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/bin.d.ts +2 -0
- package/dist/bin.js +107 -0
- package/dist/comps/box.d.ts +3 -0
- package/dist/comps/box.js +7 -0
- package/dist/comps/button.d.ts +3 -0
- package/dist/comps/button.js +8 -0
- package/dist/comps/checkbox.d.ts +3 -0
- package/dist/comps/checkbox.js +14 -0
- package/dist/comps/cover.d.ts +4 -0
- package/dist/comps/cover.js +8 -0
- package/dist/comps/form.d.ts +4 -0
- package/dist/comps/form.js +105 -0
- package/dist/comps/heading.d.ts +3 -0
- package/dist/comps/heading.js +10 -0
- package/dist/comps/icon.d.ts +3 -0
- package/dist/comps/icon.js +7 -0
- package/dist/comps/input.d.ts +7 -0
- package/dist/comps/input.js +8 -0
- package/dist/comps/spinner.d.ts +13 -0
- package/dist/comps/spinner.js +40 -0
- package/dist/funs/css.d.ts +268 -0
- package/dist/funs/css.js +339 -0
- package/dist/funs/index.d.ts +17 -0
- package/dist/funs/index.js +60 -0
- package/dist/funs/styles.d.ts +242 -0
- package/dist/funs/styles.js +249 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/styles.css +1 -460
- package/dist/types/enums.d.ts +10 -0
- package/dist/types/enums.js +12 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/index.js +1 -0
- package/dist/types/interfaces.d.ts +4 -0
- package/dist/types/interfaces.js +1 -0
- package/package.json +48 -44
- package/README.md +0 -1
- package/dist/hooks.js +0 -89
- package/dist/ui.js +0 -688
package/dist/ui.js
DELETED
|
@@ -1,688 +0,0 @@
|
|
|
1
|
-
import Hashids from 'hashids';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
|
-
import Cookies from 'js-cookie';
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
import { forwardRef } from 'react';
|
|
7
|
-
import Link from 'next/link';
|
|
8
|
-
import Children from 'react-children-utilities';
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
|
|
11
|
-
var StyleCache = {};
|
|
12
|
-
|
|
13
|
-
const cssProps = {
|
|
14
|
-
"ac": "align-content",
|
|
15
|
-
"alignContent": "align-content",
|
|
16
|
-
"aic": "aic",
|
|
17
|
-
"ais": "ais",
|
|
18
|
-
"aie": "aie",
|
|
19
|
-
"nous": "nous",
|
|
20
|
-
"nope": "nope",
|
|
21
|
-
"ai": "align-items",
|
|
22
|
-
"alignItems": "align-items",
|
|
23
|
-
"ass": "ass",
|
|
24
|
-
"asc": "asc",
|
|
25
|
-
"ase": "ase",
|
|
26
|
-
"alignSelf": "align-self",
|
|
27
|
-
"all": "all",
|
|
28
|
-
"animation": "animation",
|
|
29
|
-
"animationDelay": "animation-delay",
|
|
30
|
-
"animationDirection": "animation-direction",
|
|
31
|
-
"animationDuration": "animation-duration",
|
|
32
|
-
"animationFillMode": "animation-fill-mode",
|
|
33
|
-
"animationIterationCount": "animation-iteration-count",
|
|
34
|
-
"animationName": "animation-name",
|
|
35
|
-
"animationPlayState": "animation-play-state",
|
|
36
|
-
"animationTimingFunction": "animation-timing-function",
|
|
37
|
-
"backfaceVisibility": "backface-visibility",
|
|
38
|
-
"backgroundAttachment": "background-attachment",
|
|
39
|
-
"backgroundBlendMode": "background-blend-mode",
|
|
40
|
-
"backgroundClip": "background-clip",
|
|
41
|
-
"bg": "background",
|
|
42
|
-
"background": "background",
|
|
43
|
-
"bgc": "background-color",
|
|
44
|
-
"bgColor": "background-color",
|
|
45
|
-
"backgroundColor": "background-color",
|
|
46
|
-
"backgroundImage": "background-image",
|
|
47
|
-
"backgroundOrigin": "background-origin",
|
|
48
|
-
"backgroundPosition": "background-position",
|
|
49
|
-
"backgroundRepeat": "background-repeat",
|
|
50
|
-
"backgroundSize": "background-size",
|
|
51
|
-
"border": "border",
|
|
52
|
-
"borderBottom": "border-bottom",
|
|
53
|
-
"borderBottomColor": "border-bottom-color",
|
|
54
|
-
"borderBottomStyle": "border-bottom-style",
|
|
55
|
-
"borderBottomWidth": "border-bottom-width",
|
|
56
|
-
"borderCollapse": "border-collapse",
|
|
57
|
-
"borderColor": "border-color",
|
|
58
|
-
"borderImage": "border-image",
|
|
59
|
-
"borderImageOutset": "border-image-outset",
|
|
60
|
-
"borderImageRepeat": "border-image-repeat",
|
|
61
|
-
"borderImageSlice": "border-image-slice",
|
|
62
|
-
"borderImageSource": "border-image-source",
|
|
63
|
-
"borderImageWidth": "border-image-width",
|
|
64
|
-
"borderLeft": "border-left",
|
|
65
|
-
"borderLeftColor": "border-left-color",
|
|
66
|
-
"borderLeftStyle": "border-left-style",
|
|
67
|
-
"borderLeftWidth": "border-left-width",
|
|
68
|
-
//Radius
|
|
69
|
-
"r": "border-radius",
|
|
70
|
-
"br": "border-radius",
|
|
71
|
-
"borderRadius": "border-radius",
|
|
72
|
-
"brtl": "border-top-left-radius",
|
|
73
|
-
"borderTopLeftRadius": "border-top-left-radius",
|
|
74
|
-
"brtr": "border-top-right-radius",
|
|
75
|
-
"borderTopRightRadius": "border-top-right-radius",
|
|
76
|
-
"brbl": "border-bottom-left-radius",
|
|
77
|
-
"borderBottomLeftRadius": "border-bottom-left-radius",
|
|
78
|
-
"brbr": "border-bottom-right-radius",
|
|
79
|
-
"borderBottomRightRadius": "border-bottom-right-radius",
|
|
80
|
-
"borderRight": "border-right",
|
|
81
|
-
"borderRightColor": "border-right-color",
|
|
82
|
-
"borderRightStyle": "border-right-style",
|
|
83
|
-
"borderRightWidth": "border-right-width",
|
|
84
|
-
"borderSpacing": "border-spacing",
|
|
85
|
-
"borderStyle": "border-style",
|
|
86
|
-
"borderTop": "border-top",
|
|
87
|
-
"borderTopColor": "border-top-color",
|
|
88
|
-
"borderTopStyle": "border-top-style",
|
|
89
|
-
"borderTopWidth": "border-top-width",
|
|
90
|
-
"borderWidth": "border-width",
|
|
91
|
-
"bottom": "bottom",
|
|
92
|
-
"boxDecorationBreak": "box-decoration-break",
|
|
93
|
-
"boxShadow": "box-shadow",
|
|
94
|
-
"boxSizing": "box-sizing",
|
|
95
|
-
"captionSide": "caption-side",
|
|
96
|
-
"caretColor": "caret-color",
|
|
97
|
-
"@charset": "@charset",
|
|
98
|
-
"clear": "clear",
|
|
99
|
-
"clip": "clip",
|
|
100
|
-
"clipPath": "clip-path",
|
|
101
|
-
"color": "color",
|
|
102
|
-
"columnCount": "column-count",
|
|
103
|
-
"columnFill": "column-fill",
|
|
104
|
-
"columnGap": "column-gap",
|
|
105
|
-
"colGap": "column-gap",
|
|
106
|
-
"columnRule": "column-rule",
|
|
107
|
-
"columnRuleColor": "column-rule-color",
|
|
108
|
-
"columnRuleStyle": "column-rule-style",
|
|
109
|
-
"columnRuleWidth": "column-rule-width",
|
|
110
|
-
"columnSpan": "column-span",
|
|
111
|
-
"columnWidth": "column-width",
|
|
112
|
-
"colW": "column-width",
|
|
113
|
-
"columns": "columns",
|
|
114
|
-
"content": "content",
|
|
115
|
-
"counterIncrement": "counter-increment",
|
|
116
|
-
"counterReset": "counter-reset",
|
|
117
|
-
"cursor": "cursor",
|
|
118
|
-
"pointer": "pointer",
|
|
119
|
-
"direction": "direction",
|
|
120
|
-
"display": "display",
|
|
121
|
-
"emptyCells": "empty-cells",
|
|
122
|
-
"filter": "filter",
|
|
123
|
-
"flex": "flex",
|
|
124
|
-
"flexBasis": "flex-basis",
|
|
125
|
-
"dir": "flex-direction",
|
|
126
|
-
"flexDirection": "flex-direction",
|
|
127
|
-
"flexFlow": "flex-flow",
|
|
128
|
-
"flexGrow": "flex-grow",
|
|
129
|
-
"flexShrink": "flex-shrink",
|
|
130
|
-
"flexWrap": "flex-wrap",
|
|
131
|
-
"float": "float",
|
|
132
|
-
"font": "font",
|
|
133
|
-
"fontFamily": "font-family",
|
|
134
|
-
"fontKerning": "font-kerning",
|
|
135
|
-
"size": "font-size",
|
|
136
|
-
"fontSize": "font-size",
|
|
137
|
-
"fontSizeAdjust": "font-size-adjust",
|
|
138
|
-
"fontStretch": "font-stretch",
|
|
139
|
-
"fontStyle": "font-style",
|
|
140
|
-
"fontVariant": "font-variant",
|
|
141
|
-
"bold": "bold",
|
|
142
|
-
"b900": "b900",
|
|
143
|
-
"b800": "b800",
|
|
144
|
-
"b700": "b700",
|
|
145
|
-
"fontWeight": "font-weight",
|
|
146
|
-
"gap": "gap",
|
|
147
|
-
"grid": "grid",
|
|
148
|
-
"gridArea": "grid-area",
|
|
149
|
-
"gridAutoColumns": "grid-auto-columns",
|
|
150
|
-
"gridAutoFlow": "grid-auto-flow",
|
|
151
|
-
"gridAutoRows": "grid-auto-rows",
|
|
152
|
-
"gridColumn": "grid-column",
|
|
153
|
-
"gridColumnEnd": "grid-column-end",
|
|
154
|
-
"gridColumnGap": "grid-column-gap",
|
|
155
|
-
"gridColumnStart": "grid-column-start",
|
|
156
|
-
"gridGap": "grid-gap",
|
|
157
|
-
"gridRow": "grid-row",
|
|
158
|
-
"gridRowEnd": "grid-row-end",
|
|
159
|
-
"gridRowGap": "grid-row-gap",
|
|
160
|
-
"gridRowStart": "grid-row-start",
|
|
161
|
-
"gridTemplate": "grid-template",
|
|
162
|
-
"gridTemplateAreas": "grid-template-areas",
|
|
163
|
-
"gridTemplateColumns": "grid-template-columns",
|
|
164
|
-
"gridTemplateRows": "grid-template-rows",
|
|
165
|
-
"hangingPunctuation": "hanging-punctuation",
|
|
166
|
-
"hyphens": "hyphens",
|
|
167
|
-
"isolation": "isolation",
|
|
168
|
-
"jcc": "jcc",
|
|
169
|
-
"jcs": "jcs",
|
|
170
|
-
"jce": "jce",
|
|
171
|
-
"jc": "justify-content",
|
|
172
|
-
"justifyContent": "justify-content",
|
|
173
|
-
"left": "left",
|
|
174
|
-
"letterSpacing": "letter-spacing",
|
|
175
|
-
"lineHeight": "line-height",
|
|
176
|
-
"listStyle": "list-style",
|
|
177
|
-
"listStyleImage": "list-style-image",
|
|
178
|
-
"listStylePosition": "list-style-position",
|
|
179
|
-
"listStyleType": "list-style-type",
|
|
180
|
-
"aspectRatio": "aspect-ratio",
|
|
181
|
-
//Margin
|
|
182
|
-
"m": "margin",
|
|
183
|
-
"margin": "margin",
|
|
184
|
-
"mb": "margin-bottom",
|
|
185
|
-
"marginBottom": "margin-bottom",
|
|
186
|
-
"ml": "margin-left",
|
|
187
|
-
"marginLeft": "margin-left",
|
|
188
|
-
"mr": "margin-right",
|
|
189
|
-
"marginRight": "margin-right",
|
|
190
|
-
"mt": "margin-top",
|
|
191
|
-
"marginTop": "margin-top",
|
|
192
|
-
//Height
|
|
193
|
-
"h": "height",
|
|
194
|
-
"height": "height",
|
|
195
|
-
"minH": "min-height",
|
|
196
|
-
"minHeight": "min-height",
|
|
197
|
-
"maxH": "max-height",
|
|
198
|
-
"maxHeight": "max-height",
|
|
199
|
-
//Width
|
|
200
|
-
"w": "width",
|
|
201
|
-
"width": "width",
|
|
202
|
-
"minW": "min-width",
|
|
203
|
-
"minWidth": "min-width",
|
|
204
|
-
"maxW": "max-width",
|
|
205
|
-
"maxWidth": "max-width",
|
|
206
|
-
"mixBlendMode": "mix-blend-mode",
|
|
207
|
-
"objectFit": "object-fit",
|
|
208
|
-
"objectPosition": "object-position",
|
|
209
|
-
"opacity": "opacity",
|
|
210
|
-
"order": "order",
|
|
211
|
-
"outline": "outline",
|
|
212
|
-
"outlineColor": "outline-color",
|
|
213
|
-
"outlineOffset": "outline-offset",
|
|
214
|
-
"outlineStyle": "outline-style",
|
|
215
|
-
"outlineWidth": "outline-width",
|
|
216
|
-
"overflow": "overflow",
|
|
217
|
-
"overflowX": "overflow-x",
|
|
218
|
-
"overflowY": "overflow-y",
|
|
219
|
-
"p": "padding",
|
|
220
|
-
"padding": "padding",
|
|
221
|
-
"pb": "padding-bottom",
|
|
222
|
-
"paddingBottom": "padding-bottom",
|
|
223
|
-
"pl": "padding-left",
|
|
224
|
-
"paddingLeft": "padding-left",
|
|
225
|
-
"pr": "padding-right",
|
|
226
|
-
"paddingRight": "padding-right",
|
|
227
|
-
"pt": "padding-top",
|
|
228
|
-
"paddingTop": "padding-top",
|
|
229
|
-
"pageBreakAfter": "page-break-after",
|
|
230
|
-
"pageBreakBefore": "page-break-before",
|
|
231
|
-
"pageBreakInside": "page-break-inside",
|
|
232
|
-
"perspective": "perspective",
|
|
233
|
-
"perspectiveOrigin": "perspective-origin",
|
|
234
|
-
"pointerEvents": "pointer-events",
|
|
235
|
-
"rel": "rel",
|
|
236
|
-
"abs": "abs",
|
|
237
|
-
"fixed": "fixed",
|
|
238
|
-
"sticky": "sticky",
|
|
239
|
-
"pos": "position",
|
|
240
|
-
"position": "position",
|
|
241
|
-
"quotes": "quotes",
|
|
242
|
-
"resize": "resize",
|
|
243
|
-
"right": "right",
|
|
244
|
-
"scrollBehavior": "scroll-behavior",
|
|
245
|
-
"tabSize": "tab-size",
|
|
246
|
-
"tableLayout": "table-layout",
|
|
247
|
-
"align": "text-align",
|
|
248
|
-
"textAlign": "text-align",
|
|
249
|
-
"textAlignLast": "text-align-last",
|
|
250
|
-
"tdh": "tdh", //text-decoration: underline on hover
|
|
251
|
-
"td": "text-decoration",
|
|
252
|
-
"textDecoration": "text-decoration",
|
|
253
|
-
"textDecorationColor": "text-decoration-color",
|
|
254
|
-
"textDecorationLine": "text-decoration-line",
|
|
255
|
-
"textDecorationStyle": "text-decoration-style",
|
|
256
|
-
"textIndent": "text-indent",
|
|
257
|
-
"textJustify": "text-justify",
|
|
258
|
-
"textOverflow": "text-overflow",
|
|
259
|
-
"textShadow": "text-shadow",
|
|
260
|
-
"textTransform": "text-transform",
|
|
261
|
-
"top": "top",
|
|
262
|
-
"transform": "transform",
|
|
263
|
-
"transform(2D)": "transform(2D)",
|
|
264
|
-
"transformOrigin(twoValue syntax)": "transform-origin(two-value syntax)",
|
|
265
|
-
"transformStyle": "transform-style",
|
|
266
|
-
"transition": "transition",
|
|
267
|
-
"transitionDelay": "transition-delay",
|
|
268
|
-
"transitionDuration": "transition-duration",
|
|
269
|
-
"transitionProperty": "transition-property",
|
|
270
|
-
"transitionTimingFunction": "transition-timing-function",
|
|
271
|
-
"unicodeBidi": "unicode-bidi",
|
|
272
|
-
"userSelect": "user-select",
|
|
273
|
-
"verticalAlign": "vertical-align",
|
|
274
|
-
"visibility": "visibility",
|
|
275
|
-
"weight": "flex",
|
|
276
|
-
"whiteSpace": "white-space",
|
|
277
|
-
"ws": "white-space",
|
|
278
|
-
"wordBreak": "word-break",
|
|
279
|
-
"wordSpacing": "word-spacing",
|
|
280
|
-
"wrap": "wrap",
|
|
281
|
-
"textWrap": "textWrap",
|
|
282
|
-
"wordWrap": "word-wrap",
|
|
283
|
-
"writingMode": "writing-mode",
|
|
284
|
-
"zIndex": "z-index",
|
|
285
|
-
"backdropFilter": "backdrop-filter",
|
|
286
|
-
"bgFilter": "backdrop-filter",
|
|
287
|
-
//Custom
|
|
288
|
-
"anim": "anim",
|
|
289
|
-
"fill": "fill",
|
|
290
|
-
"abc": "abc",
|
|
291
|
-
"fb": "fb",
|
|
292
|
-
"ph": "ph",
|
|
293
|
-
"pv": "pv",
|
|
294
|
-
"mv": "mv",
|
|
295
|
-
"mh": "mh"
|
|
296
|
-
};
|
|
297
|
-
const cssPropsVals = {
|
|
298
|
-
//Colors
|
|
299
|
-
"primary": 'var(--primary-color)',
|
|
300
|
-
"c": "center",
|
|
301
|
-
//Flex Directions
|
|
302
|
-
"cols": "column",
|
|
303
|
-
"colsr": "column-reverse",
|
|
304
|
-
"rows": "row",
|
|
305
|
-
"rowsr": "row-reverse",
|
|
306
|
-
//Positions
|
|
307
|
-
"rel": "relative",
|
|
308
|
-
"abs": "absolute",
|
|
309
|
-
};
|
|
310
|
-
const cssPropsDirect = {
|
|
311
|
-
'rel': 'position: relative;',
|
|
312
|
-
'fixed': 'position: fixed;',
|
|
313
|
-
'abs': 'position: absolute;',
|
|
314
|
-
'sticky': 'position: sticky;',
|
|
315
|
-
'flex': 'display: flex;',
|
|
316
|
-
'fwrap': 'flex-wrap: wrap;',
|
|
317
|
-
'aic': 'align-items: center;',
|
|
318
|
-
'ais': 'align-items: flex-start;',
|
|
319
|
-
'aie': 'align-items: flex-end;',
|
|
320
|
-
'ass': 'align-self: flex-start;',
|
|
321
|
-
'asc': 'align-self: center;',
|
|
322
|
-
'ase': 'align-self: flex-end;',
|
|
323
|
-
'jcc': 'justify-content: center;',
|
|
324
|
-
'jcs': 'justify-content: flex-start;',
|
|
325
|
-
'jce': 'justify-content: flex-end;',
|
|
326
|
-
'grid': 'display: grid;',
|
|
327
|
-
'fill': 'top: 0px;left: 0px;right: 0px;bottom: 0px;',
|
|
328
|
-
'abc': 'top: 50%;left: 50%;transform: translate(-50%, -50%);',
|
|
329
|
-
'block': 'display: block;',
|
|
330
|
-
'bold': "font-weight: bold;",
|
|
331
|
-
'b900': "font-weight: 900;",
|
|
332
|
-
'b800': "font-weight: 800;",
|
|
333
|
-
'b700': "font-weight: 700;",
|
|
334
|
-
'wrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
|
|
335
|
-
'textWrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
|
|
336
|
-
'pointer': "cursor: pointer;",
|
|
337
|
-
'fb': 'font-family: var(--primary-font-bold);',
|
|
338
|
-
'ph': 'padding-left: __VALUE__;padding-right: __VALUE__;',
|
|
339
|
-
'pv': 'padding-bottom: __VALUE__;padding-top: __VALUE__;',
|
|
340
|
-
'mv': 'margin-bottom: __VALUE__;margin-top: __VALUE__;',
|
|
341
|
-
'mh': 'margin-left: __VALUE__;margin-right: __VALUE__;',
|
|
342
|
-
'anim': 'transition:all __VALUE__s linear 0s;',
|
|
343
|
-
'nous': 'user-select: none;',
|
|
344
|
-
'nope': 'pointer-events: none;',
|
|
345
|
-
'tdn': 'text-decoration: none;',
|
|
346
|
-
'aspectRatio': 'aspect-ratio: __VALUE__;'
|
|
347
|
-
};
|
|
348
|
-
const cssPropsIgnore = [
|
|
349
|
-
'weight', `opacity`
|
|
350
|
-
];
|
|
351
|
-
const _cssColors = [`white`, `black`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `cyan`, `purple`, `pink`, `linkedin`, `facebook`, `messenger`, `whatsapp`, `twitter`, `telegram`];
|
|
352
|
-
const _cssColorsRange = [`50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`];
|
|
353
|
-
let cssColors = [];
|
|
354
|
-
if (cssColors.length == 0) {
|
|
355
|
-
_cssColors.map(c => {
|
|
356
|
-
_cssColorsRange.map(r => cssColors.push(`${c}.${r}`));
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const _Hashids = new Hashids('', 4);
|
|
361
|
-
const _Alphabets = "#abcdefghijklmnopqrstuvwxyz0123456789";
|
|
362
|
-
const setCookie = (key, value, expiry, host) => Cookies.set(key, value, { expires: expiry || 7, domain: host || window.location.host });
|
|
363
|
-
const getCookie = (key) => key == `` ? Cookies.get() : Cookies.get(key) || null;
|
|
364
|
-
const removeCookie = (key) => Cookies.remove(key);
|
|
365
|
-
const uuid = (len = 11) => nanoid(len);
|
|
366
|
-
const makeCSSValue = (k, v, o) => {
|
|
367
|
-
let ignore = cssPropsIgnore.indexOf(o) == -1;
|
|
368
|
-
if (k in cssPropsDirect && ignore == true) {
|
|
369
|
-
return cssPropsDirect[k].indexOf(`__VALUE__`) > -1 ?
|
|
370
|
-
cssPropsDirect[k].replaceAll(`__VALUE__`, `${v}${"number" == typeof v ? `px` : ``}`)
|
|
371
|
-
: cssPropsDirect[k];
|
|
372
|
-
}
|
|
373
|
-
let unit = "number" == typeof v && ignore ? `px` : ``;
|
|
374
|
-
if (cssColors.indexOf(v) > -1) {
|
|
375
|
-
v = `var(--colors-${v.replaceAll(`.`, `-`)})`;
|
|
376
|
-
unit = ``;
|
|
377
|
-
}
|
|
378
|
-
else if (v in cssPropsVals) {
|
|
379
|
-
v = cssPropsVals[v];
|
|
380
|
-
}
|
|
381
|
-
return `${k}:${v}${unit};`;
|
|
382
|
-
};
|
|
383
|
-
const cleanProps = (props, del = true) => {
|
|
384
|
-
const ignore = [`as`, `hover`, `bref`, `tag`, `onSubmit`, `method`, `should`, `options`, `required`];
|
|
385
|
-
let items = Object.assign({}, props);
|
|
386
|
-
Object.keys(props).map(k => {
|
|
387
|
-
if (k in cssProps || ignore.indexOf(k) > -1) {
|
|
388
|
-
if (del)
|
|
389
|
-
delete items[k];
|
|
390
|
-
else
|
|
391
|
-
items[k] = undefined;
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
return items;
|
|
395
|
-
};
|
|
396
|
-
const buildCSS = (k, v) => {
|
|
397
|
-
if (k in cssProps) {
|
|
398
|
-
return makeCSSValue(cssProps[k], v, k);
|
|
399
|
-
}
|
|
400
|
-
return ``;
|
|
401
|
-
};
|
|
402
|
-
const _withStyle = (props, pseudo = ``) => {
|
|
403
|
-
if (!props)
|
|
404
|
-
return ``;
|
|
405
|
-
let cx = [props.className || props.as || ``];
|
|
406
|
-
Object.keys(props).map(k => {
|
|
407
|
-
if (k != 'children' && k in cssProps) {
|
|
408
|
-
const _css = buildCSS(k, props[k]).toString().replace(/;|:|\s/g, "");
|
|
409
|
-
let _indices = 0;
|
|
410
|
-
for (let i = 0; i < _css.length; i++) {
|
|
411
|
-
_indices += _Alphabets.indexOf(_css.charAt(i));
|
|
412
|
-
}
|
|
413
|
-
let _cp = k.substring(0, 1);
|
|
414
|
-
if (cssProps[k].indexOf("-") > -1) {
|
|
415
|
-
_cp = "";
|
|
416
|
-
cssProps[k].split("-").map(c => _cp += c.substring(0, 1));
|
|
417
|
-
}
|
|
418
|
-
if (props[k].toString().indexOf("-") > -1) {
|
|
419
|
-
props[k].toString().split("-").map(c => _cp += c.substring(0, 1));
|
|
420
|
-
}
|
|
421
|
-
const _id = `${_cp}${_Hashids.encode(cssProps[k].length + _indices + (isNaN(parseInt(props[k])) ? 0 : parseInt(props[k])))}`.replace(/\s/g, '-');
|
|
422
|
-
// const _id = `${_cp}${cssProps[k]}-${props[k]}`
|
|
423
|
-
cx.push(_id);
|
|
424
|
-
StyleCache[_id + pseudo] = buildCSS(k, props[k]);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
return cx.join(" ").trim();
|
|
428
|
-
};
|
|
429
|
-
const withStyle = (props) => {
|
|
430
|
-
const style = [_withStyle(props)];
|
|
431
|
-
if ("hover" in props) {
|
|
432
|
-
style.push(_withStyle(props.hover, `:hover`));
|
|
433
|
-
}
|
|
434
|
-
if ("before" in props) {
|
|
435
|
-
style.push(_withStyle(props.hover, `:before`));
|
|
436
|
-
}
|
|
437
|
-
if ("after" in props) {
|
|
438
|
-
style.push(_withStyle(props.hover, `:after`));
|
|
439
|
-
}
|
|
440
|
-
return style.join(style.length > 1 ? " " : "");
|
|
441
|
-
};
|
|
442
|
-
const getStylesheet = () => Object.keys(StyleCache).map(ck => StyleCache[ck] != "" ? `.${ck}{${StyleCache[ck]}}` : `__`).filter(x => x != `__`);
|
|
443
|
-
const isEmail = (e) => {
|
|
444
|
-
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
|
|
445
|
-
return reg.test(e);
|
|
446
|
-
};
|
|
447
|
-
const buildFormData = form => {
|
|
448
|
-
if (!form || form.nodeName !== "FORM") {
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
var i, j, q = [];
|
|
452
|
-
for (i = form.elements.length - 1; i >= 0; i = i - 1) {
|
|
453
|
-
if (form.elements[i].name === "") {
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
switch (form.elements[i].nodeName) {
|
|
457
|
-
case 'INPUT':
|
|
458
|
-
switch (form.elements[i].type) {
|
|
459
|
-
case 'text':
|
|
460
|
-
case 'hidden':
|
|
461
|
-
case 'password':
|
|
462
|
-
case 'button':
|
|
463
|
-
case 'reset':
|
|
464
|
-
case 'submit':
|
|
465
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
|
|
466
|
-
break;
|
|
467
|
-
case 'checkbox':
|
|
468
|
-
case 'radio':
|
|
469
|
-
if (form.elements[i].checked) {
|
|
470
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
|
|
471
|
-
}
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
474
|
-
break;
|
|
475
|
-
case 'TEXTAREA':
|
|
476
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
|
|
477
|
-
break;
|
|
478
|
-
case 'SELECT':
|
|
479
|
-
switch (form.elements[i].type) {
|
|
480
|
-
case 'select-one':
|
|
481
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
|
|
482
|
-
break;
|
|
483
|
-
case 'select-multiple':
|
|
484
|
-
for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) {
|
|
485
|
-
if (form.elements[i].options[j].selected) {
|
|
486
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].options[j].value) });
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
break;
|
|
492
|
-
case 'BUTTON':
|
|
493
|
-
switch (form.elements[i].type) {
|
|
494
|
-
case 'reset':
|
|
495
|
-
case 'submit':
|
|
496
|
-
case 'button':
|
|
497
|
-
q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
break;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return q; //return q.join("&");
|
|
504
|
-
};
|
|
505
|
-
const withRest = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
|
|
506
|
-
var Bearer = getCookie(bearer) || `${uuid(8)}^${uuid(8)}`;
|
|
507
|
-
var isWindow = typeof window !== 'undefined';
|
|
508
|
-
var cancelToken = null;
|
|
509
|
-
if (isWindow) {
|
|
510
|
-
window['__grabToken'] = axios.CancelToken.source();
|
|
511
|
-
cancelToken = window['__grabToken'].token;
|
|
512
|
-
}
|
|
513
|
-
if (fd) {
|
|
514
|
-
return new Promise((resolve, reject) => {
|
|
515
|
-
axios({
|
|
516
|
-
method: "post",
|
|
517
|
-
url: uri,
|
|
518
|
-
data: buildFormData(data),
|
|
519
|
-
timeout: 1000 * timeout,
|
|
520
|
-
cancelToken: cancelToken,
|
|
521
|
-
headers: {
|
|
522
|
-
'Content-Type': 'multipart/form-data',
|
|
523
|
-
'Authorization': `Bearer ${Bearer}`
|
|
524
|
-
},
|
|
525
|
-
onUploadProgress: ev => {
|
|
526
|
-
//TODO: Add progress
|
|
527
|
-
}
|
|
528
|
-
})
|
|
529
|
-
.then(resp => {
|
|
530
|
-
if (resp.data && "kind" in resp.data) {
|
|
531
|
-
resolve(resp.data);
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
reject(resp.data);
|
|
535
|
-
}
|
|
536
|
-
})
|
|
537
|
-
.catch(err => reject(err));
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
return new Promise((resolve, reject) => {
|
|
541
|
-
axios.post(uri, Object.assign(Object.assign(Object.assign({}, Cookies.get()), data), { __poken: new Date().getTime() / 1000 }), {
|
|
542
|
-
timeout: 1000 * timeout,
|
|
543
|
-
headers: {
|
|
544
|
-
'Content-Type': 'application/json',
|
|
545
|
-
'Authorization': `Bearer ${Bearer}`
|
|
546
|
-
},
|
|
547
|
-
cancelToken: cancelToken
|
|
548
|
-
})
|
|
549
|
-
.then(resp => {
|
|
550
|
-
if (resp.data && "kind" in resp.data) {
|
|
551
|
-
resolve(resp.data);
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
reject(resp.data);
|
|
555
|
-
}
|
|
556
|
-
})
|
|
557
|
-
.catch(err => reject(err));
|
|
558
|
-
});
|
|
559
|
-
};
|
|
560
|
-
const formatBytes = bytes => {
|
|
561
|
-
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
562
|
-
if (bytes == 0)
|
|
563
|
-
return '0 Byte';
|
|
564
|
-
var i = Math.floor(Math.log(bytes) / Math.log(1024)), nx = bytes / Math.pow(1024, i);
|
|
565
|
-
return nx.toFixed(2) + ' ' + sizes[i];
|
|
566
|
-
};
|
|
567
|
-
const formatSeconds = (n) => {
|
|
568
|
-
let d = new Date(n * 1000).toISOString().slice(11, 19);
|
|
569
|
-
return d.indexOf("00:") > -1 ? d.replace("00:", "") : d;
|
|
570
|
-
};
|
|
571
|
-
const formatTime = time => {
|
|
572
|
-
time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
|
|
573
|
-
if (time.length > 1) { // If time format correct
|
|
574
|
-
time = time.slice(1); // Remove full string match value
|
|
575
|
-
time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
|
|
576
|
-
time[0] = +time[0] % 12 || 12;
|
|
577
|
-
}
|
|
578
|
-
return time.join('');
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
const Stylesheet = (props) => jsx("style", { className: props.id || undefined, children: getStylesheet().join("") });
|
|
582
|
-
|
|
583
|
-
const Box = forwardRef((props, ref) => {
|
|
584
|
-
const _styles = withStyle(props);
|
|
585
|
-
return jsx("div", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
const Heading = forwardRef((props, ref) => {
|
|
589
|
-
const _styles = withStyle(props);
|
|
590
|
-
const Tag = `h${props.h || 1}`;
|
|
591
|
-
const HeadingTag = Tag;
|
|
592
|
-
return jsx(HeadingTag, Object.assign({ className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
const Icon = forwardRef((props, ref) => {
|
|
596
|
-
const _styles = withStyle(Object.assign(Object.assign({}, props), { as: `icon-${props.as}`, size: props.size || 16 }));
|
|
597
|
-
return jsx("span", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
function Crumb({ items, size }) {
|
|
601
|
-
const list = [];
|
|
602
|
-
{
|
|
603
|
-
items.map((n, i) => {
|
|
604
|
-
const h = jsx(Heading, { flex: true, size: size || 24, children: n.label }, `hc-${i}-${n.label.replace(/\s/g, '-')}`);
|
|
605
|
-
list.push(n.href ? jsx(Link, { href: n.href, className: `tdn tdnh`, children: h }, `crumb-${i}-${n.label.replace(/\s/g, '-')}`) : h);
|
|
606
|
-
if (i < items.length - 1)
|
|
607
|
-
list.push(jsx(Icon, { as: `chevron_right`, size: size || 24 }, `chev-${i}-${n.label.replace(/\s/g, '-')}`));
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
return (jsx(Box, { flex: true, aic: true, gap: 15, children: list }));
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const Input = forwardRef((props, ref) => {
|
|
614
|
-
let Tag = props.tag || 'input';
|
|
615
|
-
const El = Tag;
|
|
616
|
-
const _styles = withStyle(props);
|
|
617
|
-
return jsx(El, Object.assign({ className: _styles, onChange: e => { props.onChange && props.onChange(e); } }, cleanProps(props)));
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
const Button = forwardRef((props, ref) => {
|
|
621
|
-
const _styles = withStyle(props);
|
|
622
|
-
return jsx("button", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
const Form = (props) => {
|
|
626
|
-
const _props = Object.assign({}, props);
|
|
627
|
-
delete _props['children'];
|
|
628
|
-
const formName = `form-${props.name}`;
|
|
629
|
-
const fields = [];
|
|
630
|
-
const validateForm = () => {
|
|
631
|
-
const _data = buildFormData(document.querySelector(`form[name="${formName}"]`));
|
|
632
|
-
const data = [];
|
|
633
|
-
_data.map(f => {
|
|
634
|
-
const id = Object.keys(f)[0];
|
|
635
|
-
const field = fields.find(x => x.name == id);
|
|
636
|
-
if (field) {
|
|
637
|
-
const value = decodeURIComponent(f[id]);
|
|
638
|
-
let valid = 'should' in field ? field.value != "" : true;
|
|
639
|
-
if ('should' in field) {
|
|
640
|
-
switch (field.should) {
|
|
641
|
-
case "email":
|
|
642
|
-
valid = isEmail(value);
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
data.push({ name: field.name, value: value, valid: valid });
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
if (props.onSubmit) {
|
|
650
|
-
props.onSubmit({ validation: !data.find(x => x.valid == false), data: data });
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
Children.deepMap(props.children, c => {
|
|
654
|
-
if (c['props'].name && !fields.find(x => x.name == c['props'].name)) {
|
|
655
|
-
let xyz = { name: c['props'].name, touched: false };
|
|
656
|
-
if ('should' in c['props']) {
|
|
657
|
-
xyz['should'] = c['props'].should;
|
|
658
|
-
}
|
|
659
|
-
fields.push(xyz);
|
|
660
|
-
}
|
|
661
|
-
return null;
|
|
662
|
-
});
|
|
663
|
-
return jsx("form", { name: formName, method: props.method || undefined, onSubmit: e => {
|
|
664
|
-
e.preventDefault();
|
|
665
|
-
e.stopPropagation();
|
|
666
|
-
validateForm();
|
|
667
|
-
}, children: jsx(Box, Object.assign({}, _props, { children: props.children })) });
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
const Spinner = (props) => {
|
|
671
|
-
const { size, w, h, color, radius, anim } = props;
|
|
672
|
-
return jsx(Box, { w: size || 50, rel: true, zIndex: `1`, userSelect: `none`, h: size || 50, as: `zuz-spinner`, anim: (anim || 2).toString(), flex: true, aic: true, jcc: true, children: jsx(Box, { as: `zuz-loader`, r: radius || 4, w: w || 30, h: h || 6, bg: color || `#111` }) });
|
|
673
|
-
};
|
|
674
|
-
Spinner.propTypes = {
|
|
675
|
-
size: PropTypes.number,
|
|
676
|
-
w: PropTypes.number,
|
|
677
|
-
h: PropTypes.number,
|
|
678
|
-
radius: PropTypes.number,
|
|
679
|
-
color: PropTypes.string,
|
|
680
|
-
anim: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
const Select = forwardRef((props, ref) => {
|
|
684
|
-
const _styles = withStyle(props);
|
|
685
|
-
return jsx("select", Object.assign({ className: _styles }, cleanProps(props), { onChange: e => { props.onChange && props.onChange(e); }, children: props.options && props.options.map(o => jsx("option", { value: o.value, children: o.label }, `${props.id || props.as || props.name}-option-${o.value}`)) }));
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
export { Box, Button, Crumb, Form, Heading, Icon, Input, Select, Spinner, Stylesheet, buildCSS, buildFormData, cleanProps, formatBytes, formatSeconds, formatTime, getCookie, getStylesheet, isEmail, makeCSSValue, removeCookie, setCookie, uuid, withRest, withStyle };
|