lucid-ui
Version:
A UI component library from Xandr.
54 lines • 1.8 kB
JavaScript
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import { lucidClassNames } from '../../util/style-helpers';
const cx = lucidClassNames.bind('&-Typography');
const { node, string, oneOf } = PropTypes;
export var ElementTypes;
(function (ElementTypes) {
ElementTypes["p"] = "p";
ElementTypes["tabular"] = "p";
ElementTypes["h1"] = "h1";
ElementTypes["h2"] = "h2";
ElementTypes["h3"] = "h3";
ElementTypes["a"] = "a";
ElementTypes["pre"] = "pre";
ElementTypes["code"] = "code";
ElementTypes["kbd"] = "kbd";
ElementTypes["samp"] = "samp";
ElementTypes["span"] = "span";
})(ElementTypes || (ElementTypes = {}));
const defaultProps = {
variant: ElementTypes.p,
};
export const Typography = (props) => {
const { children, className, variant, ...passThroughs } = props;
const Element = ElementTypes[variant ? variant : 'p'];
return React.createElement(Element, {
...passThroughs,
className: cx('&', `&-${variant}`, className),
}, children);
};
Typography.defaultProps = defaultProps;
Typography.displayName = 'Typography';
Typography.peek = {
description: `A general component for several types of textual \`HTML\` elements.`,
categories: ['text'],
};
Typography.propTypes = {
/**
Can contain elements or nested \`Typography\` components.
*/
children: node,
/**
Appended to the component-specific class names set on the root element.
*/
className: string,
/**
This prop defines the type of text that will be displayed.
It may be an actual HTML element or something with extra semantic meaning.
*/
variant: oneOf(_.keys(ElementTypes)).isRequired,
};
export default Typography;
//# sourceMappingURL=Typography.js.map