deprecate / metal-clay-components

10 stars 14 forks source link

Passing parameters `data` to ClayLink #144

Closed matuzalemsteles closed 6 years ago

matuzalemsteles commented 6 years ago

In JSP some users need to pass attributes to their components and one way was to use the data parameter like HashMap, Use cases like when you want a link not to use the SPA, passing data-senna-off.

carloslancha commented 6 years ago

We need to define a convention for this. My suggestion would be to make components accept a param named "dataAttributes" containing a map.

{call Component.render}
   {param dataAttributes: [
      'id': '23',
      'myAttribute': 'myValue',
      ....
   ] /}
   ...
{/call}

and in the component use it just like elementClasses:


{let $attributes kind="attributes"}
   {if $dataAttributes}
      {foreach $attributeKey in keys($dataAttributes)}
         data-{$attributeKey}="{$dataAttributes[$attributeKey]}"
      {/foreach}
   {/if}

   {if $elementClasses}
      {$elementClasses}
   {/if}

   ...
{/let}
matuzalemsteles commented 6 years ago

Hey @carloslancha, Sounds good to me, do you think we should use in more other components?

carloslancha commented 6 years ago

@matuzalemsteles maybe is a good idea to add elementClasses, id and dataAttributes to all components by default and add it as a good practice to the guidelines.

matuzalemsteles commented 6 years ago

@carloslancha I like this idea, I think we can do it.

matuzalemsteles commented 6 years ago

Hey @carloslancha, The SoyToIncrementalDomSrcCompiler does not support using variables to transform into attributes. There is a question about this https://github.com/google/closure-templates/issues/112.

carloslancha commented 6 years ago

facepalm

carloslancha commented 6 years ago

Hey @matuzalemsteles

@jbalsas had an idea about how to handle this, I'm working on it!