#Possible to override the "custom" field type?

1 messages · Page 1 of 1 (latest)

signal kelp
high lance
#

Hey @signal kelp,

Interesting request, I'm curious about when you'd want to override the custom field instead of creating your own field type, since it's intended for specific cases.

Just to clarify: after checking if field.render doesn't exist, you'd like to see if the custom field is being overridden, and return that if available, correct?

In terms of use, you'd use custom fields like this then?

myField: { type: "custom" } // Uses the override version

Would you mind opening a feature request for this? I'd like to better understand the use case, and it might be easier to discuss it there before moving forward with a PR.

signal kelp
#

Hey man!

  Config<{
    fields: FieldDefinition;
  }>
> => {
  return {
    overrides: {
      ...
      fieldTypes: {
        unit: FieldWrapper,
        switch: FieldWrapper,
        radio: FieldWrapper,
        select: FieldWrapper,
        number: FieldWrapper,
        text: FieldWrapper,
        textarea: FieldWrapper,
        imageUpload: FieldWrapper,
        page: FieldWrapper,
        pages: FieldWrapper,
        entity: FieldWrapper,
        service: FieldWrapper,
        slider: FieldWrapper,
        color: FieldWrapper,
        code: FieldWrapper,
        object: ({ children, ...props }) => {
          if (props.field.metadata?.override === true) {
            return children;
          }
          return <FieldWrapper {...props}>{children}</FieldWrapper>;
        },
        array: ({ children, ...props }) => {
          if (props.field.metadata?.override === true) {
            return children;
          }
          return <FieldWrapper {...props}>{children}</FieldWrapper>;
        },
        hidden: FieldWrapper,
      },
    },
  };
};

I have a "FieldWrapper" that i wrap all field types with, as I have a custom UI for all field types that get's added in automatically for all configurations, this means i can expose custom field configuration options (for example, different values for different viewports), and currently, i cannot do this for custom fields as it just renders whatever is provided in the render function of the custom field

But yes, by providing an override for "custom", internally, i can still call field.render with the expected arguments (like puck does internally) but provide my custom functionality for custom fields

high lance
#

I see! Thanks for the context. If you could open that feature request, I can bring it up with the team and get back to you as soon as possible so we can figure out the best approach 🙏

signal kelp
#

No problems, I did test this locally and as it's something that simply doesn't exist at the moment, it's pretty low level risk, but I'm also happy to make the PR for it, I will do it when i get a chance!

high lance
#

Thank you!

signal kelp
#

(linked the issue too)