diff --git a/src/components/index.ts b/src/components/index.ts index 8eb86635..5a7a8501 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -11,6 +11,7 @@ export * from './logo'; export * from './panel'; export * from './panel-heading'; export * from './status-panel'; +export * from './tag'; export * from './text'; export * from './theme-provider'; export * from './theme-provider/defaultTheme'; diff --git a/src/components/tag/README.md b/src/components/tag/README.md new file mode 100644 index 00000000..549038d8 --- /dev/null +++ b/src/components/tag/README.md @@ -0,0 +1,13 @@ +The Tag component displays small, inline snippets of information. + +```jsx harmony +import { ThemeProvider, Tag } from '@lapidist/components'; + + + v1.0.0 + v1.0.0 + v1.0.0 + v1.0.0 + v1.0.0 + +``` diff --git a/src/components/tag/Tag.spec.tsx b/src/components/tag/Tag.spec.tsx new file mode 100644 index 00000000..9adafd25 --- /dev/null +++ b/src/components/tag/Tag.spec.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import 'jest-styled-components'; + +import { ThemeProvider } from '../theme-provider'; +import { Tag } from './index'; + +const setup = (Tag: React.ReactElement) => + render({Tag}); + +test('it works', () => { + const { container } = setup(Hello world); + expect(container.firstChild).toMatchSnapshot(); +}); diff --git a/src/components/tag/__snapshots__/Tag.spec.tsx.snap b/src/components/tag/__snapshots__/Tag.spec.tsx.snap new file mode 100644 index 00000000..0b019b15 --- /dev/null +++ b/src/components/tag/__snapshots__/Tag.spec.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`it works 1`] = ` +.c0 { + border-style: solid; + text-align: center; + font-size: 0.75rem; + font-weight: 400; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 0.25rem; + border-width: 1px; + box-shadow: 0 1px 3px 0 rgba(0,0,0,0.1),0 1px 2px 0 rgba(0,0,0,0.06); + padding-left: 0.5rem; + padding-right: 0.5rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: #17a3a5; + color: white; + border-color: #1a8385; +} + + + Hello world + +`; diff --git a/src/components/tag/index.tsx b/src/components/tag/index.tsx new file mode 100644 index 00000000..36971f95 --- /dev/null +++ b/src/components/tag/index.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { withTheme } from 'styled-components'; +import { mergeStyles, Theme } from '@lapidist/styles'; +import { Text } from '../text'; +import { BoxProps } from '../box'; +import { TagStyles } from './styles'; + +export * from './styles'; + +export type TagPropType = BoxProps & + React.HTMLAttributes & + React.HTMLProps; + +export interface TagProps { + readonly kind: string; + readonly theme: Theme; +} + +const BaseTag: React.FC = ({ + as = 'span', + styles, + kind, + theme, + ...restProps +}) => ( + +); + +export const Tag = withTheme(BaseTag); + +Tag.displayName = 'Tag'; diff --git a/src/components/tag/styles.ts b/src/components/tag/styles.ts new file mode 100644 index 00000000..ee2b34c3 --- /dev/null +++ b/src/components/tag/styles.ts @@ -0,0 +1,55 @@ +import { ColorGroup, getProperty, Styles } from '@lapidist/styles'; +import { TagProps } from './index'; + +interface TagVariantStyles { + borderColor: ColorGroup | string; + backgroundColor: ColorGroup | string; + paddingY: string; + fontSize: string; + textColor: ColorGroup | string; +} + +const TagColors = (dark: string, base: string) => ({ + borderColor: dark, + backgroundColor: base, + textColor: { group: 'base', shade: 'light' } +}); + +const TagVariants = ({ kind, theme }: TagProps): TagVariantStyles => { + const { dark, base } = getProperty<{ + [K: string]: string; + }>(theme, 'colors', kind); + + return { + fontSize: '1', + paddingY: '2', + ...TagColors(dark, base) + }; +}; + +const TagBaseStyles: Styles = { + borderWidth: 'px', + boxShadow: '1', + textAlign: 'center', + paddingX: '2', + borderRadius: '2', + borderStyle: 'solid' +}; + +const TagVariantStyles = ({ + borderColor, + backgroundColor, + textColor, + paddingY, + fontSize +}: TagVariantStyles): Styles => ({ + ...TagBaseStyles, + borderColor, + backgroundColor, + textColor, + paddingY, + fontSize +}); + +export const TagStyles = (props: TagProps): Styles => + TagVariantStyles(TagVariants(props));