Skip to content

Commit

Permalink
Merge pull request #166 from wacky/add-tag-component
Browse files Browse the repository at this point in the history
Add tag component
  • Loading branch information
wacky authored Jun 24, 2019
2 parents d2703cb + 8ad908b commit 0b2522d
Show file tree
Hide file tree
Showing 10 changed files with 481 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/AppBar/__snapshots__/AppBar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exports[`AppBar should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down Expand Up @@ -132,6 +133,7 @@ exports[`AppBar should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down Expand Up @@ -238,6 +240,7 @@ exports[`AppBar should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ exports[`Checkbox should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down Expand Up @@ -138,6 +139,7 @@ exports[`Checkbox should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down Expand Up @@ -245,6 +247,7 @@ exports[`Checkbox should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down Expand Up @@ -381,6 +384,7 @@ exports[`Checkbox should be match snapshot 1`] = `
"Red": "#ef475b",
"SmartHRGreen": "#00c4cc",
"White": "#fff",
"Yellow": "#fc0",
},
"size": Object {
"font": Object {
Expand Down
16 changes: 15 additions & 1 deletion src/components/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled, { css } from 'styled-components'
import { InjectedProps, withTheme } from '../../hocs/withTheme'

import { NumberInput, PasswordInput, Props as InputProps, TextInput } from '../Input'
import { Tag } from '../Tag'

interface Props {
label: string
Expand Down Expand Up @@ -43,7 +44,14 @@ const fieldFactory: (
<Wrapper width={widthStyle}>
<label>
<LabelHead theme={theme}>
<Title theme={theme}>{label}</Title>
<Title theme={theme}>
{label}
{required && (
<TagWrapper>
<Tag type="require">必須</Tag>
</TagWrapper>
)}
</Title>
{help && <Help theme={theme}>{help}</Help>}
</LabelHead>
{InputComponent ? (
Expand Down Expand Up @@ -108,3 +116,9 @@ const Error = styled.p`
line-height: 1.4;
`}
`

const TagWrapper = styled.span`
${({ theme }: InjectedProps) => css`
margin-left: ${theme.size.pxToRem(theme.size.space.xxs)};
`}
`
14 changes: 14 additions & 0 deletions src/components/Tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tag

```tsx
import { Tag } from 'smarthr-ui'

<Tag type="require">必須</Tag>
```

## props

| Name | Required | Type | DefaultValue | Description |
| ---------- | -------- | --------------------------------- | ------------ | ----------------------------------------------------------------- |
| skeleton | - | **boolean** <br> true &#124; false | false | Set transparent background when its true |
| type | true | **enum** <br> `suuccess` &#124; `error` &#124; `warning` &#124; `require` | - | Can be set type of tag |
57 changes: 57 additions & 0 deletions src/components/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { storiesOf } from '@storybook/react'
import * as React from 'react'
import styled from 'styled-components'

import { Tag } from './Tag'
import readme from './README.md'

storiesOf('Tag', module)
.addParameters({
readme: {
sidebar: readme,
},
})
.add('all', () => (
<List>
<li>
<Tag>デフォルト</Tag>
</li>
<li>
<Tag type="success">サクセス</Tag>
</li>
<li>
<Tag type="warning">警告</Tag>
</li>
<li>
<Tag type="error">エラー</Tag>
</li>
<li>
<Tag type="require">必須</Tag>
</li>
<li>
<Tag type="success" skeleton={true}>
サクセス
</Tag>
</li>
<li>
<Tag type="warning" skeleton={true}>
警告
</Tag>
</li>
<li>
<Tag type="error" skeleton={true}>
エラー
</Tag>
</li>
<li>
<Tag type="require" skeleton={true}>
必須
</Tag>
</li>
</List>
))

const List = styled.ul`
padding: 8px 24px;
list-style: none;
`
70 changes: 70 additions & 0 deletions src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from 'react'
import styled, { css } from 'styled-components'

import { InjectedProps, withTheme } from '../../hocs/withTheme'

type Type = 'success' | 'warning' | 'error' | 'require'

interface Props {
skeleton?: boolean
type?: Type
children: string
}

interface WrapperProps {
skeleton: boolean
}

type MergedProps = Props & InjectedProps

const TagComponent: React.FC<MergedProps> = ({ skeleton = false, type, children, theme }) => {
return (
<Wrapper theme={theme} className={type} skeleton={skeleton}>
{children}
</Wrapper>
)
}

const Wrapper = styled.span`
${({ theme, skeleton }: InjectedProps & WrapperProps) => {
const { frame, size, palette } = theme
const { Black, White, Blue, Red, Yellow, Orange_M30, Mono_P20 } = palette
return css`
margin: 0;
padding: 0 ${size.pxToRem(theme.size.space.xxs)};
display: inline-block;
white-space: nowrap;
font-size: ${size.font.tasting}px;
border: ${frame.border.default};
background-color: transparent;
color: ${Mono_P20};
&.success {
border: 1px solid ${Blue};
background-color: ${skeleton ? 'transparent' : Blue};
color: ${skeleton ? Blue : White};
}
&.error {
border: 1px solid ${Red};
background-color: ${skeleton ? 'transparent' : Red};
color: ${skeleton ? Red : White};
}
&.warning {
border: 1px solid ${Yellow};
background-color: ${skeleton ? 'transparent' : Yellow};
color: ${skeleton ? Yellow : Black};
}
&.require {
border: 1px solid ${Orange_M30};
background-color: ${skeleton ? 'transparent' : Orange_M30};
color: ${skeleton ? Orange_M30 : White};
}
`
}}
`

export const Tag = withTheme(TagComponent)
Loading

0 comments on commit 0b2522d

Please sign in to comment.