@damarkuncoro/layout-engine-react 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.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # layout-engine-react
2
+
3
+ Adaptor React untuk `layout-engine`. Mengubah headless nodes menjadi komponen React untuk dipakai di aplikasi.
4
+
5
+ ## Instalasi
6
+
7
+ ```bash
8
+ npm install @damarkuncoro/layout-engine-react
9
+ ```
10
+
11
+ Pastikan `react` dan `react-dom` tersedia.
12
+
13
+ ## Penggunaan
14
+
15
+ ```jsx
16
+ import React from "react"
17
+ import { SidebarLayout, Stack, Box } from "layout-engine-react"
18
+
19
+ export default function App() {
20
+ const sidebar = Box({ children: "Sidebar" })
21
+ const content = Stack({ gap: 16, children: [Box({ children: "Card 1" }), Box({ children: "Card 2" })] })
22
+ return React.createElement(SidebarLayout, {
23
+ sidebar,
24
+ children: content,
25
+ sidebarWidth: { base: 120, md: 200, xl: 280 }
26
+ })
27
+ }
28
+ ```
29
+
30
+ ## Fitur
31
+ - Komponen: Box, Flex, Stack, Grid, SidebarLayout, DashboardLayout.
32
+ - Otomatisasi key untuk child React agar aman dari warning.
33
+ - ESM-only, tipe tersedia.
34
+
35
+ ## Lisensi
36
+ MIT
@@ -0,0 +1,18 @@
1
+ import * as H from "layout-engine";
2
+ export type { CSSLength, LayoutProps, HeadlessNode, SidebarLayoutContract, DashboardLayoutContract, FlexProps, StackProps, GridProps, ResponsiveValue, BreakpointKey } from "layout-engine";
3
+ export { resolveResponsive, breakpoints } from "layout-engine";
4
+ export declare function Box(props: H.LayoutProps & {
5
+ children?: any;
6
+ }): any;
7
+ export declare function Flex(props: H.FlexProps & {
8
+ children?: any;
9
+ }): any;
10
+ export declare function Stack(props: H.StackProps & {
11
+ children?: any;
12
+ }): any;
13
+ export declare function Grid(props: H.GridProps & {
14
+ children?: any;
15
+ }): any;
16
+ export declare function SidebarLayout(props: any): any;
17
+ export declare function DashboardLayout(props: H.DashboardLayoutContract): any;
18
+ export { renderNodeToReact } from "./renderReact.js";
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import * as H from "layout-engine";
2
+ import { renderNodeToReact } from "./renderReact.js";
3
+ export { resolveResponsive, breakpoints } from "layout-engine";
4
+ export function Box(props) {
5
+ const node = H.Box(props);
6
+ return renderNodeToReact(node);
7
+ }
8
+ export function Flex(props) {
9
+ const node = H.Flex(props);
10
+ return renderNodeToReact(node);
11
+ }
12
+ export function Stack(props) {
13
+ const node = H.Stack(props);
14
+ return renderNodeToReact(node);
15
+ }
16
+ export function Grid(props) {
17
+ const node = H.Grid(props);
18
+ return renderNodeToReact(node);
19
+ }
20
+ export function SidebarLayout(props) {
21
+ const node = H.SidebarLayout(props);
22
+ return renderNodeToReact(node);
23
+ }
24
+ export function DashboardLayout(props) {
25
+ const node = H.DashboardLayout(props);
26
+ return renderNodeToReact(node);
27
+ }
28
+ export { renderNodeToReact } from "./renderReact.js";
@@ -0,0 +1,6 @@
1
+ type HeadlessNode = {
2
+ type: string;
3
+ props: Record<string, any>;
4
+ };
5
+ export declare const renderNodeToReact: (node: HeadlessNode) => any;
6
+ export {};
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ const toChild = (c) => {
3
+ if (c === null || c === undefined || c === false)
4
+ return null;
5
+ if (Array.isArray(c))
6
+ return c.map((item, idx) => {
7
+ const v = toChild(item);
8
+ if (React.isValidElement(v)) {
9
+ if (v.key == null) {
10
+ return React.cloneElement(v, { key: idx });
11
+ }
12
+ return v;
13
+ }
14
+ return React.createElement(React.Fragment, { key: idx }, v);
15
+ });
16
+ if (typeof c === "object" && c.type && c.props)
17
+ return renderNodeToReact(c);
18
+ return c;
19
+ };
20
+ export const renderNodeToReact = (node) => {
21
+ const { type, props } = node;
22
+ const { children, className, style, ...rest } = props || {};
23
+ // Merge className and style like standard React
24
+ const mergedProps = { ...rest };
25
+ if (className)
26
+ mergedProps.className = className;
27
+ if (style)
28
+ mergedProps.style = { ...style };
29
+ const child = toChild(children);
30
+ return React.createElement(type, mergedProps, child);
31
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@damarkuncoro/layout-engine-react",
3
+ "version": "0.1.0",
4
+ "description": "React adapter for layout-engine (headless → React components)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "sideEffects": false,
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "keywords": [
15
+ "layout",
16
+ "react",
17
+ "headless",
18
+ "responsive",
19
+ "primitives"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.json",
32
+ "typecheck": "tsc -p tsconfig.json --noEmit"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^18.0.0",
36
+ "react-dom": "^18.0.0"
37
+ },
38
+ "dependencies": {
39
+ "@damarkuncoro/layout-engine": "^0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.4.0",
43
+ "@damarkuncoro/layout-engine": "file:../layout-engine"
44
+ }
45
+ }