heml icon indicating copy to clipboard operation
heml copied to clipboard

Extending with own components?

Open shokurov opened this issue 8 years ago • 5 comments

As I see from the heml-elements/index.js there is no mechanism for plugging in additional components. That limits usability and, I believe, prevents real world use in large projects.

I understand that SparkPost would be having trouble allowing custom JS to be run within parse or render phases on their servers, however adding extension mechanism would have grand effect on spread of HEML as open standard.

shokurov avatar Nov 23 '17 10:11 shokurov

Hi @shokurov! Thanks for checking out HEML :) It turns out you can pass in your own elements in the options object you pass to the exported heml function:

const heml = require('heml')
heml(`<heml>...</heml>`, { elements: [ /* elements go here */ ] })

There isn't much documentation on custom elements yet (that will be coming soon I believe), but I they need to be created using the createElement function found in @heml/utils. I would look at the elements in @heml/elements for which attributes are accepted.

colestrode avatar Nov 25 '17 16:11 colestrode

Thanks for pointing out!

This definitely needs a bit more documentation..

Please, could you clarify couple more things:

  1. do components have to utilise React or is it just convenience that you use JSX in internal components?
  2. is there a description of <Style > component interface? It seems crucial for use in all other components, however I could not find a description of its interface.

shokurov avatar Nov 26 '17 12:11 shokurov

I'm not sure about the first question, I'll defer to @avigoldman on that. I imagine you do need to use React, though you don't need JSX.

For the Style element, you can find the docs here: https://heml.io/docs/elements/style/ You use it just like a regular HTML style tag.

colestrode avatar Nov 27 '17 14:11 colestrode

For the Style element, you can find the docs here: https://heml.io/docs/elements/style/ You use it just like a regular HTML style tag.

Thank you. I think I mixed it up, looking at the code fragment utilising <Style > as React component and also having an extra for attribute. Now I see it's the same one from Style.js. https://github.com/SparkPost/heml/blob/3d247d6d55472df0a5cb908e394475d6ca389a00/packages/heml-elements/src/Container.js#L45-L51

shokurov avatar Nov 27 '17 15:11 shokurov

Oh I'm sorry, you were looking for the programmatic interface. I misunderstood.

colestrode avatar Nov 29 '17 19:11 colestrode