figma / code-snippet-editor-plugin

Translate component variants, properties, and more into dynamic code snippets for your design system.
https://www.figma.com/community/plugin/1311777988952403297/code-snippet-editor
MIT License
128 stars 11 forks source link

Trim whitespace #7

Closed gossi closed 8 months ago

gossi commented 8 months ago

I do have this code editor snippet defined:

<Button
  {{!property.intent=action}}@intent="{{property.intent}}"
  {{!property.importance=supreme}}@importance="{{property.importance}}"
  {{!property.spacing=0}}@spacing="{{property.spacing}}"
  {{property.state=disabled}}@disabled={{true}}
>
  {{property.text}}
</Button>

but if none of the properties are given (ie. the default), then this is the rendered snippet for devs to copy:

<Button
>
text
</Button>

which sorta looks weird.

Probably when a couple of lines beginning with qualifiers and they all turn empty, then this is trimmable?

jake-figma commented 8 months ago

interesting case here. the quickest fix might be to detect the default state with the new operators i recently added and handle the tag conditionally. it's kinda gross, but logical for the templating language.

{{?property.intent=action&property.importance=supreme&property.spacing=0}}{{!property.state=disabled}}<Button>
{{!property.intent=action|property.importance=supreme|property.spacing=0|property.state=disabled}}<Button
...
{{!property.intent=action|property.importance=supreme|property.spacing=0|property.state=disabled}}>

the other alternative would be to use single line syntax for the whole definition, especially if its rare for all four of your props to render at once.

<Button\
{{!property.intent=action}}@intent="{{property.intent}}"\
{{!property.importance=supreme}}@importance="{{property.importance}}"\
{{!property.spacing=0}}@spacing="{{property.spacing}}"\
{{property.state=disabled}}@disabled={{true}}\
\>
  {{property.text}}
</Button>
jake-figma commented 8 months ago

closing for now, open to other ideas for ways to solve this.