From 20efa1587ec8053b4a32c7f9d5337a6e1cd9529c Mon Sep 17 00:00:00 2001 From: Korey Kassir Date: Wed, 6 Mar 2024 15:26:13 -0800 Subject: [PATCH] feat(react): update logic for prop slots (#1377) * feat(react): update logic for prop slots * fix builds * Create quick-pans-rush.md --------- Co-authored-by: Sami Jaber --- .changeset/quick-pans-rush.md | 5 + .../__snapshots__/builder.test.ts.snap | 203 +++++++++++++++++- packages/core/src/__tests__/builder.test.ts | 14 ++ .../custom-component-slot-property.json | 105 +++++++++ packages/core/src/generators/react/blocks.ts | 13 ++ packages/core/src/parsers/builder/builder.ts | 21 +- packages/core/src/types/mitosis-node.ts | 5 + 7 files changed, 345 insertions(+), 21 deletions(-) create mode 100644 .changeset/quick-pans-rush.md create mode 100644 packages/core/src/__tests__/data/builder/custom-component-slot-property.json diff --git a/.changeset/quick-pans-rush.md b/.changeset/quick-pans-rush.md new file mode 100644 index 0000000000..74a4f94b4a --- /dev/null +++ b/.changeset/quick-pans-rush.md @@ -0,0 +1,5 @@ +--- +"@builder.io/mitosis": patch +--- + +feat: add slots property for nodes. add support for it in react generator. diff --git a/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap b/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap index d7bec0fb48..d4a692afa8 100644 --- a/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/builder.test.ts.snap @@ -1033,6 +1033,7 @@ exports[`Builder > Regenerate custom Hero 3`] = ` "title": "Your Title Here", }, "scope": {}, + "slots": {}, }, ], "context": { @@ -1642,6 +1643,170 @@ export default function MyComponent(props) { " `; +exports[`Builder > customComponentSlotProperty 1`] = ` +{ + "@type": "@builder.io/mitosis/component", + "children": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{\\"position\\":\\"relative\\",\\"width\\":\\"100%\\",\\"@media (max-width: 991px)\\":{\\"maxWidth\\":\\"100%\\"}}", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "Navigation", + "properties": { + "$tagName": undefined, + }, + "scope": {}, + "slots": { + "logo": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{\\"alignItems\\":\\"flex-start\\",\\"alignSelf\\":\\"stretch\\",\\"display\\":\\"flex\\",\\"flexBasis\\":\\"0%\\",\\"flexDirection\\":\\"column\\",\\"justifyContent\\":\\"center\\"}", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "Logo", + "properties": {}, + "scope": {}, + "slots": {}, + }, + ], + "logoMultiple": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{\\"alignItems\\":\\"flex-start\\",\\"alignSelf\\":\\"stretch\\",\\"display\\":\\"flex\\",\\"flexBasis\\":\\"0%\\",\\"flexDirection\\":\\"column\\",\\"justifyContent\\":\\"center\\"}", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "Logo", + "properties": {}, + "scope": {}, + "slots": {}, + }, + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{\\"alignItems\\":\\"flex-start\\",\\"alignSelf\\":\\"stretch\\",\\"display\\":\\"flex\\",\\"flexBasis\\":\\"0%\\",\\"flexDirection\\":\\"column\\",\\"justifyContent\\":\\"center\\"}", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "LogoTwo", + "properties": {}, + "scope": {}, + "slots": {}, + }, + ], + "logoSingle": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": { + "css": { + "code": "{\\"alignItems\\":\\"flex-start\\",\\"alignSelf\\":\\"stretch\\",\\"display\\":\\"flex\\",\\"flexBasis\\":\\"0%\\",\\"flexDirection\\":\\"column\\",\\"justifyContent\\":\\"center\\"}", + "type": "single", + }, + }, + "children": [], + "meta": {}, + "name": "Logo", + "properties": {}, + "scope": {}, + "slots": {}, + }, + ], + }, + }, + ], + "context": { + "get": {}, + "set": {}, + }, + "exports": {}, + "hooks": { + "onEvent": [], + "onMount": [], + }, + "imports": [], + "inputs": undefined, + "meta": { + "useMetadata": { + "httpRequests": undefined, + }, + }, + "name": "MyComponent", + "refs": {}, + "state": {}, + "subComponents": [], +} +`; + +exports[`Builder > customComponentSlotProperty 2`] = ` +"import * as React from \\"react\\"; + +function MyComponent(props) { + return ( + <> + } + logoSingle={} + logoMultiple={ + <> + + + + } + /> + + + ); +} + +export default MyComponent; +" +`; + exports[`Builder > extractStateHook 1`] = ` { "code": "alert('hi');", @@ -1662,10 +1827,6 @@ exports[`Builder > slots 1`] = ` { "@type": "@builder.io/mitosis/node", "bindings": { - "avatar": { - "code": "", - "type": "single", - }, "css": { "code": "{\\"width\\":\\"100%\\",\\"@media (max-width: 991px)\\":{\\"maxWidth\\":\\"100%\\"}}", "type": "single", @@ -1680,6 +1841,20 @@ exports[`Builder > slots 1`] = ` "title": "The Burgler", }, "scope": {}, + "slots": { + "avatar": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "Avatar", + "properties": {}, + "scope": {}, + "slots": {}, + }, + ], + }, }, ], "context": { @@ -1741,10 +1916,6 @@ exports[`Builder > slots2 1`] = ` { "@type": "@builder.io/mitosis/node", "bindings": { - "control": { - "code": "", - "type": "single", - }, "css": { "code": "{\\"fontStyle\\":\\"italic\\"}", "type": "single", @@ -1763,6 +1934,20 @@ exports[`Builder > slots2 1`] = ` "labelPlacement": "end", }, "scope": {}, + "slots": { + "control": [ + { + "@type": "@builder.io/mitosis/node", + "bindings": {}, + "children": [], + "meta": {}, + "name": "Radio", + "properties": {}, + "scope": {}, + "slots": {}, + }, + ], + }, }, ], "context": { @@ -1798,8 +1983,8 @@ function MyComponent(props) { label=\\"Label\\" labelPlacement=\\"end\\" className=\\"form-control-label\\" - control={} disabled={false} + control={} />