UNPKG

@namefully/react

Version:
78 lines 2.54 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); const React = require("react"); const namefully_1 = require("namefully"); /** * Namefully, react-based component to handle person names. * @function component or presentational react component * * @usageNotes * ```tsx * <Namefully * raw={'Person Name'} * options={{...SomeOptions}} * method={"namefully's method"} * args={['args', 'for', 'method' ...]} * tag={'html tag'} * position={'left or right of children'} * * className={'a-class'} * style={{...yourStyles}} * moreHtmlAttrs={} * > * <htmltag>content</htmltag> * </Namefully> * ``` * * @example * ```tsx * import * as React from 'react'; * import * as ReactDOM from 'react-dom'; * * import { Namefully } from '@namefully/react'; * * const App = () => { * return ( * <h1> * Hello, <Namefully raw='John Smith'/>! * </h1> * ) * }; * * ReactDOM.render(<App />, document.getElementById('example')); * ``` * Happy name-handling! */ exports.default = (props) => { const { raw, options, method, args, tag, position, children } = props, htmlAttrs = __rest(props, ["raw", "options", "method", "args", "tag", "position", "children"]); const name = new namefully_1.Namefully(raw, options); const content = executeInnerMethod(name, name[method || 'fullName'], args); const Tag = tag || 'span'; if (position === 'left' || position === 'l') { return (React.createElement(Tag, Object.assign({}, htmlAttrs), children, " ", content)); } return (React.createElement(Tag, Object.assign({}, htmlAttrs), content, " ", children)); }; // tslint:disable-next-line function executeInnerMethod(context, fn, args) { const content = fn.apply(context, args); return Array.isArray(content) ? content.join(' ') : content; } //# sourceMappingURL=Namefully.js.map