1.0.2 • Published 2 years ago

react-mustache-component v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Latest build Master Build contributions welcome dependencies Status devDependencies Status

react-mustache-template-component - React Mustache Template Component

https://nodei.co/npm/react-mustache-template-component.png?downloads=true&downloadRank=true&stars=true

The Template component that uses Mustache.js to render the a component, sanitized by dompurify.

Demo

See Storybook for examples.

Installation and Usage

$ npm install react-mustache-template-component

The use it in your app:

import TemplateComponent from 'react-mustache-template-component'

...
const template = `<img class="img" src="{{url}}" />`;
const data = { url: 'http://example.com/img' };

<TemplateComponent template={template} data={data} />

This will be rendered as

<div><img class="img" src="http://example.com/img" /></div>

Notes

  • Input is properly sanitized by dompurify. This can be switched off (... sanitize={false} ...) but is highly discouraged, as this might introduce XSS issues

Props

Props that are used:

NameRequiredTypeDefaultComments
templateYesstring-Mustache template string that is used in your template component
dataNoobject{}Data used by Mustache to replace placeholders (marked by {{}})
typeNostring"div"Type of container. Can be "div" or "span"
sanitizeNobooleantrueSanitize the result using dompurify
sanitizeOptionsNoobject{}Sanitation can be changed by Dompurify.Config options
classNameNostring""Class name of container
styleNoobject{}Extra style options for the container
onClickNofunctionvoidOnClick handler, executed when clicking on the container
onDblClickNofunctionvoidOnDoubleClick handler, executed when double clicking on the container

Development

To install dependencies

$ npm install

To build

$ npm run build

To run tests

$ npm run test

To run Storybook

$ npm run storybook

License

MIT Licensed. Copyright (c) Jelte Lagendijk 2020.