Skip to content

Commit 6f538b3

Browse files
authored
v0.1.4
2 parents e6206b9 + ecdff27 commit 6f538b3

File tree

668 files changed

+7241
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

668 files changed

+7241
-111
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/components/Icon/generated/*.tsx

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
.AppleDouble
2020
.LSOverride
2121

22-
# Icon must end with two \r
23-
Icon
24-
2522
# Thumbnails
2623
._*
2724

.svgrrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"icon": true,
3+
"typescript": true,
4+
"singleQuote": true,
5+
"replaceAttrValues": {
6+
"#65676A": "currentColor"
7+
},
8+
"prettier": true,
9+
"prettierConfig": {
10+
"dimensions": false,
11+
"semi": false,
12+
"endOfLine": "lf",
13+
"singleQuote": true
14+
}
15+
}

package-lock.json

Lines changed: 346 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@channel.io/design-system",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Design System by Channel",
55
"repository": {
66
"type": "git",
@@ -26,6 +26,7 @@
2626
"build": "rollup -c",
2727
"prepublishOnly": "npm run build",
2828
"build:storybook": "build-storybook",
29+
"build:icon": "./scripts/build-icon.sh",
2930
"deploy:storybook": "storybook-to-ghpages --remote=upstream"
3031
},
3132
"husky": {
@@ -63,6 +64,7 @@
6364
"@storybook/addon-knobs": "^5.3.19",
6465
"@storybook/react": "^5.3.18",
6566
"@storybook/storybook-deployer": "^2.8.6",
67+
"@svgr/cli": "^5.4.0",
6668
"@testing-library/jest-dom": "^5.5.0",
6769
"@testing-library/react": "^10.0.4",
6870
"@types/jest": "^25.2.1",

scripts/build-icon.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
./node_modules/@svgr/cli/bin/svgr \
4+
-d ./src/components/Icon/generated \
5+
--template ./scripts/icon-template.js \
6+
--index-template ./scripts/icon-index-template.js \
7+
./src/components/Icon/assets

scripts/icon-index-template.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const _ = require('lodash')
2+
const path = require('path')
3+
4+
function defaultIndexTemplate(filePaths) {
5+
const importEntries = []
6+
const mappedFies = []
7+
8+
filePaths.forEach(filePath => {
9+
const basename = path.basename(filePath, path.extname(filePath))
10+
const exportName = /^\d/.test(basename) ? `Svg${basename}` : basename
11+
importEntries.push(`import ${exportName} from './${basename}'`)
12+
mappedFies.push(` '${_.kebabCase(basename)}': ${exportName},`)
13+
})
14+
15+
const icons = `/* eslint-disable */
16+
17+
const icons = {
18+
${mappedFies.join('\n')}
19+
}
20+
`
21+
22+
return `
23+
${importEntries.join('\n')}
24+
${icons}
25+
export type IconName = keyof typeof icons
26+
27+
/* eslint-enable */
28+
export default icons
29+
`
30+
}
31+
32+
module.exports = defaultIndexTemplate

scripts/icon-template.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function iconTemplate(
2+
{ template },
3+
options,
4+
{ componentName, props, jsx },
5+
) {
6+
return template.ast`
7+
import React from 'react'
8+
9+
function ${componentName}(${props}) {
10+
return (
11+
${jsx}
12+
)
13+
}
14+
15+
export default ${componentName}
16+
`
17+
}
18+
19+
module.exports = iconTemplate
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* External dependencies */
2+
import React from 'react'
3+
import { withKnobs, select, color, number } from '@storybook/addon-knobs'
4+
import styled from 'styled-components'
5+
6+
/* Internal dependencies */
7+
import Pallette from '../../styling/Palette'
8+
import icons, { IconName } from './generated'
9+
import Icon from './Icon'
10+
11+
export default {
12+
title: 'Icon',
13+
decorators: [withKnobs],
14+
}
15+
16+
const iconList: IconName[] = Object.keys(icons) as IconName[]
17+
18+
const IconSize = {
19+
L: 34,
20+
Normal: 24,
21+
S: 20,
22+
XS: 16,
23+
XXS: 12,
24+
}
25+
26+
const IconInfo = styled.div`
27+
width: 120px;
28+
height: 120px;
29+
display: inline-flex;
30+
flex-direction: column;
31+
align-items: center;
32+
justify-content: center;
33+
`
34+
35+
const Name = styled.p`
36+
text-align: center;
37+
`
38+
39+
export const AllIcons = () => {
40+
const size = select('size', IconSize, IconSize.Normal)
41+
const selectedColor = color('color', Pallette.grey700)
42+
43+
return (
44+
<>
45+
{ iconList.map((iconName) => (
46+
<IconInfo key={iconName}>
47+
<Icon
48+
name={iconName}
49+
color={selectedColor}
50+
size={size}
51+
/>
52+
<Name>{ iconName }</Name>
53+
</IconInfo>
54+
)) }
55+
</>
56+
)
57+
}
58+
59+
export const Primary = () => (
60+
<Icon
61+
name={select('name', iconList, 'zoyi') as IconName}
62+
color={color('color', Pallette.grey700)}
63+
size={select('size', IconSize, IconSize.Normal)}
64+
marginTop={number('marginTop', 0)}
65+
marginRight={number('marginRight', 0)}
66+
marginBottom={number('marginBottom', 0)}
67+
marginLeft={number('marginLeft', 0)}
68+
/>
69+
)
70+
71+
export const WithText = () => (
72+
<h1>
73+
<Icon
74+
name={select('name', iconList, 'zoyi') as IconName}
75+
color={color('color', Pallette.grey700)}
76+
size={select('size', IconSize, IconSize.Normal)}
77+
marginTop={number('marginTop', 0)}
78+
marginRight={number('marginRight', 0)}
79+
marginBottom={number('marginBottom', 0)}
80+
marginLeft={number('marginLeft', 0)}
81+
/>
82+
Hello World!
83+
</h1>
84+
)

src/components/Icon/Icon.styled.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* External dependencies */
2+
import styled from 'styled-components'
3+
4+
/* Internal dependencies */
5+
import { IconStyledProps } from './Icon.types'
6+
7+
function getMargin({
8+
marginTop,
9+
marginRight,
10+
marginBottom,
11+
marginLeft,
12+
}: IconStyledProps): string {
13+
return `${marginTop}px ${marginRight}px ${marginBottom}px ${marginLeft}px`
14+
}
15+
16+
const Icon = styled.svg<IconStyledProps>`
17+
fill: ${props => props.color || props.theme?.colors?.iconBase};
18+
margin: ${getMargin};
19+
`
20+
21+
export default Icon

0 commit comments

Comments
 (0)