Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support component slots #28

Closed
wants to merge 1 commit into from
Closed

Support component slots #28

wants to merge 1 commit into from

Conversation

clarkmcc
Copy link
Owner

@clarkmcc clarkmcc commented Feb 7, 2024

No description provided.

@clarkmcc
Copy link
Owner Author

clarkmcc commented Feb 7, 2024

@sroussey here's my rough draft at slots. Not sure how I feel about it so I'm gonna sleep on it. I still am not sure if I want to support node-type-specific slots or not. I'm thinking in those cases, just use a custom node. Thoughts?

@sroussey
Copy link
Contributor

sroussey commented Feb 7, 2024

What if you did it in reverse?

When you create a custom node, ngraph sends you slots where you can reassemble the node?

function CustomNode(node: Node, slots) {
      const [isFocused, onFocus, onBlur] = useFocusBlur()
      return (
        <NodeContainer node={node} draggable={isFocused}>
          <div>
           {slots.header}
           {slots.outputs}
           {slots.inputs}
           {I do my own footer here}
          </div>
        </NodeContainer>
      )
    }

And then as icing on the cake,

const config = new GraphConfig({
        valueTypes: {
          string: {
            name: 'String',
            color: '#f43f5e',
            shape: 'circle',
            inputEditor: 'value',
            defaultValue: '',
          },
        },
        nodeKinds: {
          custom: {
            name: 'Custom',
            color: '#f43f5e',
baseNode: 'my-custom-base'
          },
        },
      })
      config.registerBaseNode(
        'My Custom Base',
        'my-custom-base',
        CustomNode,
      )
      return config.validate()

Then everything that has that kind/theme gets that base node. Maybe is reuses almost everything, maybe it reuses only a little.

The slots could be granular, like it could have the entire header slots.header but also smaller parts of it.

Or {slots.inputs} could equal
{slots.singleInputs}
{slots.groupInputs}

@clarkmcc
Copy link
Owner Author

clarkmcc commented Feb 9, 2024

I see the benefits of reverse slots for sure, the biggest downside, though is that if you want to swap out one component, you have to create a custom node and build out all of the other slottable components. And this only gets more difficult as we add additional sub components and features to the nodes.

@clarkmcc
Copy link
Owner Author

Resolved by #35

@clarkmcc clarkmcc closed this Feb 11, 2024
@clarkmcc clarkmcc deleted the component-slots branch February 11, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants