-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from wacky/add-tag-component
Add tag component
- Loading branch information
Showing
10 changed files
with
481 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | false | false | Set transparent background when its true | | ||
| type | true | **enum** <br> `suuccess` | `error` | `warning` | `require` | - | Can be set type of tag | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.