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

Dynamic fields #280

Closed
chrisvxd opened this issue Dec 7, 2023 · 0 comments · Fixed by #410
Closed

Dynamic fields #280

chrisvxd opened this issue Dec 7, 2023 · 0 comments · Fixed by #410

Comments

@chrisvxd
Copy link
Member

chrisvxd commented Dec 7, 2023

Similar to resolveData, we should consider a resolveFields method to allow users to dynamically set their fields based on the current props.

Alternatively, we could piggy-back off resolveData and allow it to return a dynamic fields type.

This may also resolve #188.


Edit: Showing / hiding fields is possible using field overrides, which provide a suitable intermediary solution for some use cases.

Example that hides the image object field on the demo Hero component when the align property equals "center":

<Puck
  // ...
  overrides={{
    fieldTypes: {
      object: ({ children, name }) => {
        const { selectedItem } = usePuck();

        if (selectedItem.type === "Hero") {
          if (
            selectedItem.props.align === "center" &&
            name === "image"
          ) {
            return null;
          }
        }

        return <>{children}</>;
      },
    },
  }}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant