From 7749da5555b9bd0d9897c6645ed275b2468fe70b Mon Sep 17 00:00:00 2001 From: Rodrigo Antinarelli Date: Tue, 3 Mar 2020 19:30:24 -0300 Subject: [PATCH] feat: Typography component --- .../src/components/Typography/Typography.jsx | 142 ++++++++++++++++++ .../src/components/Typography/Typography.mdx | 65 ++++++++ .../ui/src/components/Typography/index.js | 2 + 3 files changed, 209 insertions(+) create mode 100644 platform/ui/src/components/Typography/Typography.jsx create mode 100644 platform/ui/src/components/Typography/Typography.mdx create mode 100644 platform/ui/src/components/Typography/index.js diff --git a/platform/ui/src/components/Typography/Typography.jsx b/platform/ui/src/components/Typography/Typography.jsx new file mode 100644 index 000000000..de58b23bd --- /dev/null +++ b/platform/ui/src/components/Typography/Typography.jsx @@ -0,0 +1,142 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import classnames from 'classnames'; + +const baseClasses = 'm-0 leading-tight'; + +const defaultVariantMapping = { + h1: 'h1', + h2: 'h2', + h3: 'h3', + h4: 'h4', + h5: 'h5', + h6: 'h6', + subtitle: 'h6', + body: 'p', +}; + +const defaults = { + align: 'inherit', + color: 'initial', + display: 'initial', + gutterBottom: false, + noWrap: false, + paragraph: false, + variant: 'body', +}; + +const classes = { + variant: { + h1: 'text-6xl', + h2: 'text-5xl', + h3: 'text-4xl', + h4: 'text-3xl', + h5: 'text-2xl', + h6: 'text-xl', + subtitle: 'text-lg', + body: 'text-base', + caption: 'text-xs', + button: 'text-sm uppercase', + overline: 'text-xs uppercase', + srOnly: 'absolute h-0 w-0 hidden', + inherit: '', + }, + color: { + initial: 'text-white', + inherit: 'text-inherit', + primary: 'text-primary-main', + secondary: 'text-secondary-main', + error: 'text-red-600', + }, + align: { + inherit: '', + left: 'text-left', + center: 'text-center', + right: 'text-right', + justify: 'text-justify', + }, + display: { + initial: '', + block: 'block', + inline: 'inline', + }, + gutterBottom: { + true: 'mb-3', + false: '', + }, + paragraph: { + true: 'mb-3', + false: '', + }, + noWrap: { + true: 'truncate', + false: '', + }, +}; + +const Typography = ({ + align = defaults.align, + color = defaults.color, + display = defaults.display, + gutterBottom = defaults.gutterBottom, + noWrap = defaults.noWrap, + paragraph = defaults.paragraph, + variant = defaults.variant, + component, + className, + ...rest +}) => { + const Component = + component || (paragraph ? 'p' : defaultVariantMapping[variant]) || 'span'; + return ( + + ); +}; + +Typography.propTypes = { + component: PropTypes.elementType, + paragraph: PropTypes.bool, + display: PropTypes.oneOf(['initial', 'block', 'inline']), + variant: PropTypes.oneOf([ + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'subtitle', + 'body', + 'caption', + 'button', + 'overline', + 'srOnly', + 'inherit', + ]), + color: PropTypes.oneOf([ + 'initial', + 'inherit', + 'primary', + 'secondary', + 'error', + ]), + className: PropTypes.string, + children: PropTypes.node, + align: PropTypes.oneOf(['inherit', 'left', 'center', 'right', 'justify']), + gutterBottom: PropTypes.bool, + noWrap: PropTypes.bool, +}; + +export default Typography; diff --git a/platform/ui/src/components/Typography/Typography.mdx b/platform/ui/src/components/Typography/Typography.mdx new file mode 100644 index 000000000..7859c5d40 --- /dev/null +++ b/platform/ui/src/components/Typography/Typography.mdx @@ -0,0 +1,65 @@ +--- +name: Typography +menu: Components +route: components/typography +--- + +import { Playground, Props } from 'docz'; +import Typography from './'; + +# Typography + +Use typography to display text using the available props for customizing your +content. + +## Import + +```javascript +import { Typography } from '@ohfi/ui'; +``` + +## Properties + + + +## Basic usage + + + + h1. The five boxing wizards jump quickly. + + + h2. The five boxing wizards jump quickly. + + + h3. The five boxing wizards jump quickly. + + + h4. The five boxing wizards jump quickly. + + + h5. The five boxing wizards jump quickly. + + + h6. The five boxing wizards jump quickly. + + + subtitle. The five boxing wizards jump quickly. + + + body. The five boxing wizards jump quickly. + + + +## Changing the HTML element + +There are different semantic elements to be used in the Typography component. +You can use the prop `component` to associate the component to be rendered with +a semantic element. The style of a Typography is independent of the semantic +element. + + + + This is a h2 using the h1 styles. + + diff --git a/platform/ui/src/components/Typography/index.js b/platform/ui/src/components/Typography/index.js new file mode 100644 index 000000000..f85589f13 --- /dev/null +++ b/platform/ui/src/components/Typography/index.js @@ -0,0 +1,2 @@ +import Typography from './Typography'; +export default Typography;