inferno-mark
Create mark(up/down) components similar to styled-components
.
npm install --save inferno-mark
Usage
Basic
This creates two inferno
components, <Title>
and <Menu>
:
;; const Title = markdown`# Hello World, this is my first markup component!`; const Menu = markup`<ul> <li><a href="/">Home</a></li> <li><a href="https://github.com/dfrankland">Github</a></li></ul>`;
You render them like so:
<Title /><Menu />
Mapped components
Mark components can substitute components with user-defined ones:
;; // Create links with both internal and external linksconst Menu = markup`<ul> <li><a href="/">Home</a></li> <li><a href="https://github.com/dfrankland">Github</a></li></ul>`;
You can pass an object with a key of the tag name and a value of an inferno
component that it should be substituted with:
// Add `target="_blank"` to external links<Menu infernoMarkOptions= components: <a ... ...props .../^https?:\/\//gi ? target: '_blank' : {} > children </a> />
Which will render as such:
Home Github
Adapting based on props
The same powerful way that styled-components
can change styles based on
props, so can inferno-mark
! Say for example you'd like to make a more
dynamically created menu:
;; const Menu = markdown``;
Pass props like so:
<Menu items='Blog' 'Contact' 'Demo' />
Finally, see it rendered as such:
Blog Contact Demo