@hive-ui/stack 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ import { BoxProps } from "@hive-ui/box";
2
+ import * as _$react from "react";
3
+ import { ResponsiveValue, SpaceOptions } from "@hive-ui/style-props";
4
+
5
+ //#region src/Stack.d.ts
6
+ type StackProps = Pick<BoxProps<"div">, "element" | "children" | "alignItems" | "flexWrap"> & {
7
+ orientation: ResponsiveValue<"horizontal" | "vertical">;
8
+ spacing: SpaceOptions;
9
+ };
10
+ declare const Stack: _$react.ForwardRefExoticComponent<Pick<BoxProps<"div">, "alignItems" | "children" | "element" | "flexWrap"> & {
11
+ orientation: ResponsiveValue<"horizontal" | "vertical">;
12
+ spacing: SpaceOptions;
13
+ } & _$react.RefAttributes<HTMLElement>>;
14
+ //#endregion
15
+ export { Stack, type StackProps };
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import { Box } from "@hive-ui/box";
2
+ import { Children, createElement, forwardRef, isValidElement, useMemo } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/Stack.tsx
5
+ const getStackDisplay = (orientation) => {
6
+ if (Array.isArray(orientation)) return orientation.map((value) => {
7
+ if (value === "horizontal") return "flex";
8
+ return "block";
9
+ });
10
+ if (orientation === "horizontal") return "flex";
11
+ return "block";
12
+ };
13
+ const Stack = forwardRef(({ element = "STACK", children, orientation, spacing, ...props }, ref) => {
14
+ const [childrenCount, validChildren] = useMemo(() => {
15
+ const filteredChildren = Children.toArray(children).filter((child) => isValidElement(child) || typeof child === "string");
16
+ return [filteredChildren.length, filteredChildren];
17
+ }, [children]);
18
+ const stackStyles = useMemo(() => {
19
+ return {
20
+ display: getStackDisplay(orientation),
21
+ alignItems: "center",
22
+ flexWrap: "wrap"
23
+ };
24
+ }, [orientation]);
25
+ const childMargins = useMemo(() => {
26
+ let styles = {};
27
+ if (Array.isArray(orientation)) {
28
+ const marginRight = [];
29
+ const marginBottom = [];
30
+ orientation.forEach((value, i) => {
31
+ marginRight[i] = value === "horizontal" ? spacing : "space0";
32
+ marginBottom[i] = value === "horizontal" ? "space0" : spacing;
33
+ });
34
+ styles = {
35
+ marginRight,
36
+ marginBottom
37
+ };
38
+ }
39
+ if (orientation === "horizontal") styles = { marginRight: spacing };
40
+ if (orientation === "vertical") styles = { marginBottom: spacing };
41
+ return styles;
42
+ }, [orientation, spacing]);
43
+ return /* @__PURE__ */ jsx(Box, {
44
+ ...props,
45
+ ...stackStyles,
46
+ as: "div",
47
+ element,
48
+ ref,
49
+ children: validChildren.map((child, index) => {
50
+ const childKey = isValidElement(child) && child.key != null ? child.key : `stack-${index}`;
51
+ return /* @__PURE__ */ createElement(Box, {
52
+ element: `${element}_CHILD`,
53
+ ...childrenCount !== index + 1 ? childMargins : null,
54
+ key: childKey
55
+ }, child);
56
+ })
57
+ });
58
+ });
59
+ //#endregion
60
+ export { Stack };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@hive-ui/stack",
3
+ "version": "0.1.0",
4
+ "description": "Hive UI Stack Component",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./dist/index.mjs",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "build": "vp pack",
18
+ "dev": "vp pack --watch",
19
+ "test": "vp test",
20
+ "check": "vp check",
21
+ "prepublishOnly": "vp run build"
22
+ },
23
+ "dependencies": {
24
+ "@hive-ui/box": "^0.1.0",
25
+ "@hive-ui/style-props": "^0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^25.6.2",
29
+ "@typescript/native-preview": "7.0.0-dev.20260509.2",
30
+ "bumpp": "^11.1.0",
31
+ "typescript": "^6.0.3",
32
+ "vite-plus": "^0.1.20",
33
+ "vitest": "npm:@voidzero-dev/vite-plus-test@^0.1.20"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "19.2.6"
37
+ }
38
+ }