Code component prop defaults, override default text max widths

Couple of things I’d love:

• Code Components can set a prop as default. When the code component is loaded in studio, it looks for the prop (e.g. An id) on the page, and defaults to a fallback if not applicable. Additionally once a prop of that name is added, the component finds it and updates!
• A way to turn off the default 800px max-width on headings and text objects, it causes me so many problems. It feels like something that should be managed by default styles?

Hi @native_woodpecker, you should already be able to specify defaults on code component props like this:

registerComponent(Comp, {
  name: 'Comp',
  props: {
    myprop: {
      type: 'string',
      defaultValue: 'a default value',
    }
  }
})

Is that what you’re looking for?

Not quite! That works fine, but I’d like to have a page defined meta-prop that a component knows to look for by default.

eg.

image.png

(Also great would be the ability to define a default coming from a data provider or rest api call, but I haven’t experimented with those too much yet

Got it - can you have the component then just get the data from the context instead? That way your default ID can come from any data-providing component including fetchers etc.

function Comp() {
  const defaultId = useSelector('defaultId'); // name your context variable defaultId
  return ...
}

Not always, because the id needs to be something the Plasmic Studio user selects.

The use case is that we have multiple pages with different code components, and each page corresponds to a particular id (provided in Plasmic Studio by the content creator). Nearly all code components on a given page show data particular to the provided id.

Our content creators sometimes forget to assign the id to newly added code components. I’m basically looking to reduce the human element in this as much as possible. :wink:

That makes sense - very helpful, thanks! Will take this back to the product team and think on it…

In the meantime, at least for now, you could have a wrapper DataProvider component (perhaps part of a common page layout component or some such), which lets the editor specify an ID…

That’s a good workaround, but far down the backlog, alas :laughing:. Still if I get to it before you get to this potential feature, it’s good to have it as an option!