@vitus-labs/elements 1.4.3-alpha.1 → 1.4.3-alpha.3
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/lib/index.js +156 -125
- package/lib/vitus-labs-elements.native.js +156 -125
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Provider, alignContent, extendCss, makeItResponsive, value } from "@vitus-labs/unistyle";
|
|
2
2
|
import { config, context, isEmpty, omit, pick, render, throttle } from "@vitus-labs/core";
|
|
3
|
-
import { Children, createContext,
|
|
3
|
+
import { Children, createContext, forwardRef, memo, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { isFragment } from "react-is";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
@@ -12,6 +12,125 @@ const PKG_NAME = "@vitus-labs/elements";
|
|
|
12
12
|
//#region src/utils.ts
|
|
13
13
|
const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
|
|
14
14
|
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/helpers/Content/styled.ts
|
|
17
|
+
/**
|
|
18
|
+
* Styled component for content areas (before/content/after). Applies
|
|
19
|
+
* responsive flex alignment, gap spacing between slots based on parent
|
|
20
|
+
* direction (margin-right for inline, margin-bottom for rows), and
|
|
21
|
+
* equalCols flex distribution. The "content" slot gets `flex: 1` to
|
|
22
|
+
* fill remaining space between before and after.
|
|
23
|
+
*/
|
|
24
|
+
const { styled: styled$2, css: css$2, component: component$2 } = config;
|
|
25
|
+
const equalColsCSS = `
|
|
26
|
+
flex: 1;
|
|
27
|
+
`;
|
|
28
|
+
const typeContentCSS = `
|
|
29
|
+
flex: 1;
|
|
30
|
+
`;
|
|
31
|
+
const gapDimensions = {
|
|
32
|
+
inline: {
|
|
33
|
+
before: "margin-right",
|
|
34
|
+
after: "margin-left"
|
|
35
|
+
},
|
|
36
|
+
reverseInline: {
|
|
37
|
+
before: "margin-right",
|
|
38
|
+
after: "margin-left"
|
|
39
|
+
},
|
|
40
|
+
rows: {
|
|
41
|
+
before: "margin-bottom",
|
|
42
|
+
after: "margin-top"
|
|
43
|
+
},
|
|
44
|
+
reverseRows: {
|
|
45
|
+
before: "margin-bottom",
|
|
46
|
+
after: "margin-top"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const calculateGap = ({ direction, type, value }) => {
|
|
50
|
+
if (!direction || !type || type === "content") return void 0;
|
|
51
|
+
return `${gapDimensions[direction][type]}: ${value};`;
|
|
52
|
+
};
|
|
53
|
+
const styles$2 = ({ css, theme: t, rootSize }) => css`
|
|
54
|
+
${alignContent({
|
|
55
|
+
direction: t.direction,
|
|
56
|
+
alignX: t.alignX,
|
|
57
|
+
alignY: t.alignY
|
|
58
|
+
})};
|
|
59
|
+
|
|
60
|
+
${t.equalCols && equalColsCSS};
|
|
61
|
+
|
|
62
|
+
${t.gap && t.contentType && calculateGap({
|
|
63
|
+
direction: t.parentDirection,
|
|
64
|
+
type: t.contentType,
|
|
65
|
+
value: value(t.gap, rootSize)
|
|
66
|
+
})};
|
|
67
|
+
|
|
68
|
+
${t.extraStyles && extendCss(t.extraStyles)};
|
|
69
|
+
`;
|
|
70
|
+
const StyledComponent = styled$2(component$2)`
|
|
71
|
+
${`box-sizing: border-box;`};
|
|
72
|
+
|
|
73
|
+
display: flex;
|
|
74
|
+
align-self: stretch;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
|
|
77
|
+
${({ $contentType }) => $contentType === "content" && typeContentCSS};
|
|
78
|
+
|
|
79
|
+
${makeItResponsive({
|
|
80
|
+
key: "$element",
|
|
81
|
+
styles: styles$2,
|
|
82
|
+
css: css$2,
|
|
83
|
+
normalize: true
|
|
84
|
+
})};
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/Content/component.tsx
|
|
89
|
+
/**
|
|
90
|
+
* Memoized content area used inside Element to render one of the three
|
|
91
|
+
* layout slots (before, content, after). Passes alignment, direction,
|
|
92
|
+
* gap, and equalCols styling props to the underlying styled component.
|
|
93
|
+
* Adds a `data-vl-element` attribute in development for debugging.
|
|
94
|
+
*
|
|
95
|
+
* Children are passed as raw content and rendered inside the memo boundary
|
|
96
|
+
* via core `render()` — this lets React.memo skip re-renders when the
|
|
97
|
+
* content reference is stable (common for component-type or string content).
|
|
98
|
+
*/
|
|
99
|
+
const Component$9 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, children, ...props }) => {
|
|
100
|
+
const debugProps = IS_DEVELOPMENT ? { "data-vl-element": contentType } : {};
|
|
101
|
+
return /* @__PURE__ */ jsx(StyledComponent, {
|
|
102
|
+
as: tag,
|
|
103
|
+
$contentType: contentType,
|
|
104
|
+
$element: useMemo(() => ({
|
|
105
|
+
contentType,
|
|
106
|
+
parentDirection,
|
|
107
|
+
direction,
|
|
108
|
+
alignX,
|
|
109
|
+
alignY,
|
|
110
|
+
equalCols,
|
|
111
|
+
gap,
|
|
112
|
+
extraStyles: extendCss
|
|
113
|
+
}), [
|
|
114
|
+
contentType,
|
|
115
|
+
parentDirection,
|
|
116
|
+
direction,
|
|
117
|
+
alignX,
|
|
118
|
+
alignY,
|
|
119
|
+
equalCols,
|
|
120
|
+
gap,
|
|
121
|
+
extendCss
|
|
122
|
+
]),
|
|
123
|
+
...debugProps,
|
|
124
|
+
...props,
|
|
125
|
+
children: render(children)
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var component_default$1 = memo(Component$9);
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/helpers/Content/index.ts
|
|
132
|
+
var Content_default = component_default$1;
|
|
133
|
+
|
|
15
134
|
//#endregion
|
|
16
135
|
//#region src/helpers/Wrapper/styled.ts
|
|
17
136
|
/**
|
|
@@ -165,73 +284,6 @@ const Component$8 = forwardRef(({ children, tag, block, extendCss, direction, al
|
|
|
165
284
|
//#region src/helpers/Wrapper/index.ts
|
|
166
285
|
var Wrapper_default = Component$8;
|
|
167
286
|
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/Element/slotStyles.ts
|
|
170
|
-
/**
|
|
171
|
-
* Slot styling logic extracted from Content/styled.ts for use with the
|
|
172
|
-
* useCSS hook. Handles responsive flex alignment, gap spacing, equalCols,
|
|
173
|
-
* and extendCss injection for before/content/after slots.
|
|
174
|
-
*/
|
|
175
|
-
const gapDimensions = {
|
|
176
|
-
inline: {
|
|
177
|
-
before: "margin-right",
|
|
178
|
-
after: "margin-left"
|
|
179
|
-
},
|
|
180
|
-
reverseInline: {
|
|
181
|
-
before: "margin-right",
|
|
182
|
-
after: "margin-left"
|
|
183
|
-
},
|
|
184
|
-
rows: {
|
|
185
|
-
before: "margin-bottom",
|
|
186
|
-
after: "margin-top"
|
|
187
|
-
},
|
|
188
|
-
reverseRows: {
|
|
189
|
-
before: "margin-bottom",
|
|
190
|
-
after: "margin-top"
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const calculateGap = ({ direction, type, value: v }) => {
|
|
194
|
-
if (!direction || !type || type === "content") return void 0;
|
|
195
|
-
return `${gapDimensions[direction][type]}: ${v};`;
|
|
196
|
-
};
|
|
197
|
-
const slotStyles = ({ css, theme: t, rootSize }) => css`
|
|
198
|
-
${alignContent({
|
|
199
|
-
direction: t.direction,
|
|
200
|
-
alignX: t.alignX,
|
|
201
|
-
alignY: t.alignY
|
|
202
|
-
})};
|
|
203
|
-
|
|
204
|
-
${t.equalCols && "flex: 1;"};
|
|
205
|
-
|
|
206
|
-
${t.gap && t.contentType && calculateGap({
|
|
207
|
-
direction: t.parentDirection,
|
|
208
|
-
type: t.contentType,
|
|
209
|
-
value: value(t.gap, rootSize)
|
|
210
|
-
})};
|
|
211
|
-
|
|
212
|
-
${t.extraStyles && extendCss(t.extraStyles)};
|
|
213
|
-
`;
|
|
214
|
-
let _template = null;
|
|
215
|
-
const getSlotTemplate = () => {
|
|
216
|
-
if (!_template) {
|
|
217
|
-
const { css } = config;
|
|
218
|
-
_template = css`
|
|
219
|
-
${"box-sizing: border-box;"};
|
|
220
|
-
display: flex;
|
|
221
|
-
align-self: stretch;
|
|
222
|
-
flex-wrap: wrap;
|
|
223
|
-
${({ $contentType }) => $contentType === "content" && "flex: 1;"};
|
|
224
|
-
${makeItResponsive({
|
|
225
|
-
key: "$element",
|
|
226
|
-
styles: slotStyles,
|
|
227
|
-
css,
|
|
228
|
-
normalize: true
|
|
229
|
-
})};
|
|
230
|
-
`;
|
|
231
|
-
}
|
|
232
|
-
return _template;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
287
|
//#endregion
|
|
236
288
|
//#region src/Element/constants.ts
|
|
237
289
|
/**
|
|
@@ -316,11 +368,7 @@ const getShouldBeEmpty = (tag) => {
|
|
|
316
368
|
* to avoid an unnecessary nesting layer. Handles HTML-specific edge cases
|
|
317
369
|
* like void elements (input, img) and inline elements (span, a) by
|
|
318
370
|
* skipping children or switching sub-tags accordingly.
|
|
319
|
-
*
|
|
320
|
-
* Slot elements (before/content/after) use `useCSS` for direct className
|
|
321
|
-
* injection — no styled component wrapper overhead per slot.
|
|
322
371
|
*/
|
|
323
|
-
const { useCSS } = config;
|
|
324
372
|
const defaultDirection = "inline";
|
|
325
373
|
const defaultContentDirection = "rows";
|
|
326
374
|
const defaultAlignX = "left";
|
|
@@ -330,7 +378,7 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
330
378
|
const isSimpleElement = !beforeContent && !afterContent;
|
|
331
379
|
const CHILDREN = children ?? content ?? label;
|
|
332
380
|
const isInline = isInlineElement(tag);
|
|
333
|
-
const SUB_TAG = isInline ? "span" :
|
|
381
|
+
const SUB_TAG = isInline ? "span" : void 0;
|
|
334
382
|
const { wrapperDirection, wrapperAlignX, wrapperAlignY } = useMemo(() => {
|
|
335
383
|
let wrapperDirection = direction;
|
|
336
384
|
let wrapperAlignX = alignX;
|
|
@@ -355,45 +403,6 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
355
403
|
alignY,
|
|
356
404
|
direction
|
|
357
405
|
]);
|
|
358
|
-
const slotTemplate = getSlotTemplate();
|
|
359
|
-
const beforeClass = useCSS(slotTemplate, {
|
|
360
|
-
$element: {
|
|
361
|
-
contentType: "before",
|
|
362
|
-
parentDirection: wrapperDirection,
|
|
363
|
-
direction: beforeContentDirection,
|
|
364
|
-
alignX: beforeContentAlignX,
|
|
365
|
-
alignY: beforeContentAlignY,
|
|
366
|
-
equalCols,
|
|
367
|
-
gap,
|
|
368
|
-
extraStyles: beforeContentCss
|
|
369
|
-
},
|
|
370
|
-
$contentType: "before"
|
|
371
|
-
});
|
|
372
|
-
const contentClass = useCSS(slotTemplate, {
|
|
373
|
-
$element: {
|
|
374
|
-
contentType: "content",
|
|
375
|
-
parentDirection: wrapperDirection,
|
|
376
|
-
direction: contentDirection,
|
|
377
|
-
alignX: contentAlignX,
|
|
378
|
-
alignY: contentAlignY,
|
|
379
|
-
equalCols,
|
|
380
|
-
extraStyles: contentCss
|
|
381
|
-
},
|
|
382
|
-
$contentType: "content"
|
|
383
|
-
});
|
|
384
|
-
const afterClass = useCSS(slotTemplate, {
|
|
385
|
-
$element: {
|
|
386
|
-
contentType: "after",
|
|
387
|
-
parentDirection: wrapperDirection,
|
|
388
|
-
direction: afterContentDirection,
|
|
389
|
-
alignX: afterContentAlignX,
|
|
390
|
-
alignY: afterContentAlignY,
|
|
391
|
-
equalCols,
|
|
392
|
-
gap,
|
|
393
|
-
extraStyles: afterContentCss
|
|
394
|
-
},
|
|
395
|
-
$contentType: "after"
|
|
396
|
-
});
|
|
397
406
|
const WRAPPER_PROPS = {
|
|
398
407
|
ref: ref ?? innerRef,
|
|
399
408
|
extendCss: css,
|
|
@@ -408,24 +417,46 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
408
417
|
...props,
|
|
409
418
|
...WRAPPER_PROPS
|
|
410
419
|
});
|
|
411
|
-
const contentRenderOutput = render(CHILDREN);
|
|
412
420
|
return /* @__PURE__ */ jsxs(Wrapper_default, {
|
|
413
421
|
...props,
|
|
414
422
|
...WRAPPER_PROPS,
|
|
415
423
|
isInline,
|
|
416
424
|
children: [
|
|
417
|
-
beforeContent &&
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
},
|
|
425
|
+
beforeContent && /* @__PURE__ */ jsx(Content_default, {
|
|
426
|
+
tag: SUB_TAG,
|
|
427
|
+
contentType: "before",
|
|
428
|
+
parentDirection: wrapperDirection,
|
|
429
|
+
extendCss: beforeContentCss,
|
|
430
|
+
direction: beforeContentDirection,
|
|
431
|
+
alignX: beforeContentAlignX,
|
|
432
|
+
alignY: beforeContentAlignY,
|
|
433
|
+
equalCols,
|
|
434
|
+
gap,
|
|
435
|
+
children: beforeContent
|
|
436
|
+
}),
|
|
437
|
+
isSimpleElement ? render(CHILDREN) : /* @__PURE__ */ jsx(Content_default, {
|
|
438
|
+
tag: SUB_TAG,
|
|
439
|
+
contentType: "content",
|
|
440
|
+
parentDirection: wrapperDirection,
|
|
441
|
+
extendCss: contentCss,
|
|
442
|
+
direction: contentDirection,
|
|
443
|
+
alignX: contentAlignX,
|
|
444
|
+
alignY: contentAlignY,
|
|
445
|
+
equalCols,
|
|
446
|
+
children: CHILDREN
|
|
447
|
+
}),
|
|
448
|
+
afterContent && /* @__PURE__ */ jsx(Content_default, {
|
|
449
|
+
tag: SUB_TAG,
|
|
450
|
+
contentType: "after",
|
|
451
|
+
parentDirection: wrapperDirection,
|
|
452
|
+
extendCss: afterContentCss,
|
|
453
|
+
direction: afterContentDirection,
|
|
454
|
+
alignX: afterContentAlignX,
|
|
455
|
+
alignY: afterContentAlignY,
|
|
456
|
+
equalCols,
|
|
457
|
+
gap,
|
|
458
|
+
children: afterContent
|
|
459
|
+
})
|
|
429
460
|
]
|
|
430
461
|
});
|
|
431
462
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Provider, alignContent, extendCss, makeItResponsive, value } from "@vitus-labs/unistyle";
|
|
2
2
|
import { config, context, isEmpty, omit, pick, render, throttle } from "@vitus-labs/core";
|
|
3
|
-
import { Children, createContext,
|
|
3
|
+
import { Children, createContext, forwardRef, memo, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { isFragment } from "react-is";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
@@ -12,6 +12,125 @@ const PKG_NAME = "@vitus-labs/elements";
|
|
|
12
12
|
//#region src/utils.ts
|
|
13
13
|
const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
|
|
14
14
|
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/helpers/Content/styled.ts
|
|
17
|
+
/**
|
|
18
|
+
* Styled component for content areas (before/content/after). Applies
|
|
19
|
+
* responsive flex alignment, gap spacing between slots based on parent
|
|
20
|
+
* direction (margin-right for inline, margin-bottom for rows), and
|
|
21
|
+
* equalCols flex distribution. The "content" slot gets `flex: 1` to
|
|
22
|
+
* fill remaining space between before and after.
|
|
23
|
+
*/
|
|
24
|
+
const { styled: styled$2, css: css$2, component: component$2 } = config;
|
|
25
|
+
const equalColsCSS = `
|
|
26
|
+
flex: 1;
|
|
27
|
+
`;
|
|
28
|
+
const typeContentCSS = `
|
|
29
|
+
flex: 1;
|
|
30
|
+
`;
|
|
31
|
+
const gapDimensions = {
|
|
32
|
+
inline: {
|
|
33
|
+
before: "margin-right",
|
|
34
|
+
after: "margin-left"
|
|
35
|
+
},
|
|
36
|
+
reverseInline: {
|
|
37
|
+
before: "margin-right",
|
|
38
|
+
after: "margin-left"
|
|
39
|
+
},
|
|
40
|
+
rows: {
|
|
41
|
+
before: "margin-bottom",
|
|
42
|
+
after: "margin-top"
|
|
43
|
+
},
|
|
44
|
+
reverseRows: {
|
|
45
|
+
before: "margin-bottom",
|
|
46
|
+
after: "margin-top"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const calculateGap = ({ direction, type, value }) => {
|
|
50
|
+
if (!direction || !type || type === "content") return void 0;
|
|
51
|
+
return `${gapDimensions[direction][type]}: ${value};`;
|
|
52
|
+
};
|
|
53
|
+
const styles$2 = ({ css, theme: t, rootSize }) => css`
|
|
54
|
+
${alignContent({
|
|
55
|
+
direction: t.direction,
|
|
56
|
+
alignX: t.alignX,
|
|
57
|
+
alignY: t.alignY
|
|
58
|
+
})};
|
|
59
|
+
|
|
60
|
+
${t.equalCols && equalColsCSS};
|
|
61
|
+
|
|
62
|
+
${t.gap && t.contentType && calculateGap({
|
|
63
|
+
direction: t.parentDirection,
|
|
64
|
+
type: t.contentType,
|
|
65
|
+
value: value(t.gap, rootSize)
|
|
66
|
+
})};
|
|
67
|
+
|
|
68
|
+
${t.extraStyles && extendCss(t.extraStyles)};
|
|
69
|
+
`;
|
|
70
|
+
const StyledComponent = styled$2(component$2)`
|
|
71
|
+
${""};
|
|
72
|
+
|
|
73
|
+
display: flex;
|
|
74
|
+
align-self: stretch;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
|
|
77
|
+
${({ $contentType }) => $contentType === "content" && typeContentCSS};
|
|
78
|
+
|
|
79
|
+
${makeItResponsive({
|
|
80
|
+
key: "$element",
|
|
81
|
+
styles: styles$2,
|
|
82
|
+
css: css$2,
|
|
83
|
+
normalize: true
|
|
84
|
+
})};
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/Content/component.tsx
|
|
89
|
+
/**
|
|
90
|
+
* Memoized content area used inside Element to render one of the three
|
|
91
|
+
* layout slots (before, content, after). Passes alignment, direction,
|
|
92
|
+
* gap, and equalCols styling props to the underlying styled component.
|
|
93
|
+
* Adds a `data-vl-element` attribute in development for debugging.
|
|
94
|
+
*
|
|
95
|
+
* Children are passed as raw content and rendered inside the memo boundary
|
|
96
|
+
* via core `render()` — this lets React.memo skip re-renders when the
|
|
97
|
+
* content reference is stable (common for component-type or string content).
|
|
98
|
+
*/
|
|
99
|
+
const Component$9 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, children, ...props }) => {
|
|
100
|
+
const debugProps = IS_DEVELOPMENT ? { "data-vl-element": contentType } : {};
|
|
101
|
+
return /* @__PURE__ */ jsx(StyledComponent, {
|
|
102
|
+
as: tag,
|
|
103
|
+
$contentType: contentType,
|
|
104
|
+
$element: useMemo(() => ({
|
|
105
|
+
contentType,
|
|
106
|
+
parentDirection,
|
|
107
|
+
direction,
|
|
108
|
+
alignX,
|
|
109
|
+
alignY,
|
|
110
|
+
equalCols,
|
|
111
|
+
gap,
|
|
112
|
+
extraStyles: extendCss
|
|
113
|
+
}), [
|
|
114
|
+
contentType,
|
|
115
|
+
parentDirection,
|
|
116
|
+
direction,
|
|
117
|
+
alignX,
|
|
118
|
+
alignY,
|
|
119
|
+
equalCols,
|
|
120
|
+
gap,
|
|
121
|
+
extendCss
|
|
122
|
+
]),
|
|
123
|
+
...debugProps,
|
|
124
|
+
...props,
|
|
125
|
+
children: render(children)
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var component_default$1 = memo(Component$9);
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/helpers/Content/index.ts
|
|
132
|
+
var Content_default = component_default$1;
|
|
133
|
+
|
|
15
134
|
//#endregion
|
|
16
135
|
//#region src/helpers/Wrapper/styled.ts
|
|
17
136
|
/**
|
|
@@ -123,73 +242,6 @@ const Component$8 = forwardRef(({ children, tag, block, extendCss, direction, al
|
|
|
123
242
|
//#region src/helpers/Wrapper/index.ts
|
|
124
243
|
var Wrapper_default = Component$8;
|
|
125
244
|
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/Element/slotStyles.ts
|
|
128
|
-
/**
|
|
129
|
-
* Slot styling logic extracted from Content/styled.ts for use with the
|
|
130
|
-
* useCSS hook. Handles responsive flex alignment, gap spacing, equalCols,
|
|
131
|
-
* and extendCss injection for before/content/after slots.
|
|
132
|
-
*/
|
|
133
|
-
const gapDimensions = {
|
|
134
|
-
inline: {
|
|
135
|
-
before: "margin-right",
|
|
136
|
-
after: "margin-left"
|
|
137
|
-
},
|
|
138
|
-
reverseInline: {
|
|
139
|
-
before: "margin-right",
|
|
140
|
-
after: "margin-left"
|
|
141
|
-
},
|
|
142
|
-
rows: {
|
|
143
|
-
before: "margin-bottom",
|
|
144
|
-
after: "margin-top"
|
|
145
|
-
},
|
|
146
|
-
reverseRows: {
|
|
147
|
-
before: "margin-bottom",
|
|
148
|
-
after: "margin-top"
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const calculateGap = ({ direction, type, value: v }) => {
|
|
152
|
-
if (!direction || !type || type === "content") return void 0;
|
|
153
|
-
return `${gapDimensions[direction][type]}: ${v};`;
|
|
154
|
-
};
|
|
155
|
-
const slotStyles = ({ css, theme: t, rootSize }) => css`
|
|
156
|
-
${alignContent({
|
|
157
|
-
direction: t.direction,
|
|
158
|
-
alignX: t.alignX,
|
|
159
|
-
alignY: t.alignY
|
|
160
|
-
})};
|
|
161
|
-
|
|
162
|
-
${t.equalCols && "flex: 1;"};
|
|
163
|
-
|
|
164
|
-
${t.gap && t.contentType && calculateGap({
|
|
165
|
-
direction: t.parentDirection,
|
|
166
|
-
type: t.contentType,
|
|
167
|
-
value: value(t.gap, rootSize)
|
|
168
|
-
})};
|
|
169
|
-
|
|
170
|
-
${t.extraStyles && extendCss(t.extraStyles)};
|
|
171
|
-
`;
|
|
172
|
-
let _template = null;
|
|
173
|
-
const getSlotTemplate = () => {
|
|
174
|
-
if (!_template) {
|
|
175
|
-
const { css } = config;
|
|
176
|
-
_template = css`
|
|
177
|
-
${""};
|
|
178
|
-
display: flex;
|
|
179
|
-
align-self: stretch;
|
|
180
|
-
flex-wrap: wrap;
|
|
181
|
-
${({ $contentType }) => $contentType === "content" && "flex: 1;"};
|
|
182
|
-
${makeItResponsive({
|
|
183
|
-
key: "$element",
|
|
184
|
-
styles: slotStyles,
|
|
185
|
-
css,
|
|
186
|
-
normalize: true
|
|
187
|
-
})};
|
|
188
|
-
`;
|
|
189
|
-
}
|
|
190
|
-
return _template;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
245
|
//#endregion
|
|
194
246
|
//#region src/Element/component.tsx
|
|
195
247
|
/**
|
|
@@ -199,11 +251,7 @@ const getSlotTemplate = () => {
|
|
|
199
251
|
* to avoid an unnecessary nesting layer. Handles HTML-specific edge cases
|
|
200
252
|
* like void elements (input, img) and inline elements (span, a) by
|
|
201
253
|
* skipping children or switching sub-tags accordingly.
|
|
202
|
-
*
|
|
203
|
-
* Slot elements (before/content/after) use `useCSS` for direct className
|
|
204
|
-
* injection — no styled component wrapper overhead per slot.
|
|
205
254
|
*/
|
|
206
|
-
const { useCSS } = config;
|
|
207
255
|
const defaultDirection = "inline";
|
|
208
256
|
const defaultContentDirection = "rows";
|
|
209
257
|
const defaultAlignX = "left";
|
|
@@ -212,7 +260,7 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
212
260
|
const isSimpleElement = !beforeContent && !afterContent;
|
|
213
261
|
const CHILDREN = children ?? content ?? label;
|
|
214
262
|
const isInline = false;
|
|
215
|
-
const SUB_TAG =
|
|
263
|
+
const SUB_TAG = void 0;
|
|
216
264
|
const { wrapperDirection, wrapperAlignX, wrapperAlignY } = useMemo(() => {
|
|
217
265
|
let wrapperDirection = direction;
|
|
218
266
|
let wrapperAlignX = alignX;
|
|
@@ -237,45 +285,6 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
237
285
|
alignY,
|
|
238
286
|
direction
|
|
239
287
|
]);
|
|
240
|
-
const slotTemplate = getSlotTemplate();
|
|
241
|
-
const beforeClass = useCSS(slotTemplate, {
|
|
242
|
-
$element: {
|
|
243
|
-
contentType: "before",
|
|
244
|
-
parentDirection: wrapperDirection,
|
|
245
|
-
direction: beforeContentDirection,
|
|
246
|
-
alignX: beforeContentAlignX,
|
|
247
|
-
alignY: beforeContentAlignY,
|
|
248
|
-
equalCols,
|
|
249
|
-
gap,
|
|
250
|
-
extraStyles: beforeContentCss
|
|
251
|
-
},
|
|
252
|
-
$contentType: "before"
|
|
253
|
-
});
|
|
254
|
-
const contentClass = useCSS(slotTemplate, {
|
|
255
|
-
$element: {
|
|
256
|
-
contentType: "content",
|
|
257
|
-
parentDirection: wrapperDirection,
|
|
258
|
-
direction: contentDirection,
|
|
259
|
-
alignX: contentAlignX,
|
|
260
|
-
alignY: contentAlignY,
|
|
261
|
-
equalCols,
|
|
262
|
-
extraStyles: contentCss
|
|
263
|
-
},
|
|
264
|
-
$contentType: "content"
|
|
265
|
-
});
|
|
266
|
-
const afterClass = useCSS(slotTemplate, {
|
|
267
|
-
$element: {
|
|
268
|
-
contentType: "after",
|
|
269
|
-
parentDirection: wrapperDirection,
|
|
270
|
-
direction: afterContentDirection,
|
|
271
|
-
alignX: afterContentAlignX,
|
|
272
|
-
alignY: afterContentAlignY,
|
|
273
|
-
equalCols,
|
|
274
|
-
gap,
|
|
275
|
-
extraStyles: afterContentCss
|
|
276
|
-
},
|
|
277
|
-
$contentType: "after"
|
|
278
|
-
});
|
|
279
288
|
const WRAPPER_PROPS = {
|
|
280
289
|
ref: ref ?? innerRef,
|
|
281
290
|
extendCss: css,
|
|
@@ -286,24 +295,46 @@ const Component$7 = forwardRef(({ innerRef, tag, label, content, children, befor
|
|
|
286
295
|
alignY: wrapperAlignY,
|
|
287
296
|
as: void 0
|
|
288
297
|
};
|
|
289
|
-
const contentRenderOutput = render(CHILDREN);
|
|
290
298
|
return /* @__PURE__ */ jsxs(Wrapper_default, {
|
|
291
299
|
...props,
|
|
292
300
|
...WRAPPER_PROPS,
|
|
293
301
|
isInline,
|
|
294
302
|
children: [
|
|
295
|
-
beforeContent &&
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
},
|
|
303
|
+
beforeContent && /* @__PURE__ */ jsx(Content_default, {
|
|
304
|
+
tag: SUB_TAG,
|
|
305
|
+
contentType: "before",
|
|
306
|
+
parentDirection: wrapperDirection,
|
|
307
|
+
extendCss: beforeContentCss,
|
|
308
|
+
direction: beforeContentDirection,
|
|
309
|
+
alignX: beforeContentAlignX,
|
|
310
|
+
alignY: beforeContentAlignY,
|
|
311
|
+
equalCols,
|
|
312
|
+
gap,
|
|
313
|
+
children: beforeContent
|
|
314
|
+
}),
|
|
315
|
+
isSimpleElement ? render(CHILDREN) : /* @__PURE__ */ jsx(Content_default, {
|
|
316
|
+
tag: SUB_TAG,
|
|
317
|
+
contentType: "content",
|
|
318
|
+
parentDirection: wrapperDirection,
|
|
319
|
+
extendCss: contentCss,
|
|
320
|
+
direction: contentDirection,
|
|
321
|
+
alignX: contentAlignX,
|
|
322
|
+
alignY: contentAlignY,
|
|
323
|
+
equalCols,
|
|
324
|
+
children: CHILDREN
|
|
325
|
+
}),
|
|
326
|
+
afterContent && /* @__PURE__ */ jsx(Content_default, {
|
|
327
|
+
tag: SUB_TAG,
|
|
328
|
+
contentType: "after",
|
|
329
|
+
parentDirection: wrapperDirection,
|
|
330
|
+
extendCss: afterContentCss,
|
|
331
|
+
direction: afterContentDirection,
|
|
332
|
+
alignX: afterContentAlignX,
|
|
333
|
+
alignY: afterContentAlignY,
|
|
334
|
+
equalCols,
|
|
335
|
+
gap,
|
|
336
|
+
children: afterContent
|
|
337
|
+
})
|
|
307
338
|
]
|
|
308
339
|
});
|
|
309
340
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/elements",
|
|
3
|
-
"version": "1.4.3-alpha.
|
|
3
|
+
"version": "1.4.3-alpha.3+16703b4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -61,15 +61,15 @@
|
|
|
61
61
|
"react-dom": ">= 19"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@vitus-labs/core": "1.4.3-alpha.
|
|
65
|
-
"@vitus-labs/rocketstyle": "1.4.3-alpha.
|
|
64
|
+
"@vitus-labs/core": "1.4.3-alpha.3+16703b4",
|
|
65
|
+
"@vitus-labs/rocketstyle": "1.4.3-alpha.3+16703b4",
|
|
66
66
|
"@vitus-labs/tools-rolldown": "^1.6.0",
|
|
67
67
|
"@vitus-labs/tools-storybook": "^1.6.0",
|
|
68
68
|
"@vitus-labs/tools-typescript": "^1.6.0",
|
|
69
|
-
"@vitus-labs/unistyle": "1.4.3-alpha.
|
|
69
|
+
"@vitus-labs/unistyle": "1.4.3-alpha.3+16703b4"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"react-is": "^19.2.3"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "16703b4c8dc0525bd504c531aeb082bf593579cc"
|
|
75
75
|
}
|