Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create system #43

Merged
merged 6 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = ({ config }) => {
{
loader: require.resolve('awesome-typescript-loader'),
},
// Optional
{
loader: require.resolve('react-docgen-typescript-loader'),
},
Expand Down
11 changes: 0 additions & 11 deletions doczrc.js

This file was deleted.

8 changes: 6 additions & 2 deletions src/components/Box/box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export default {

export const basic = () => <Box>Hello Button</Box>

export const asH2 = () => <Box as="h2">A box can be an h2 element</Box>
export const asH2 = () => (
<Box as="h2" mb="sm" mt="sm" pt="md">
A box can be an h2 element
</Box>
)

export const asButton = () => (
<Box as="button" onClick={() => alert('Clicked Box')}>
<Box width="sm" as="button" onClick={() => alert('Clicked Box')}>
A Box can be anything!
</Box>
)
15 changes: 5 additions & 10 deletions src/components/Box/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import styled from 'styled-components'
import { spacingSystem, SpacingSystem } from '../../tokenSystem/spacing.system'
import { sizeSystem, SizeSystem } from '../../tokenSystem/size.system'

const Box = styled.div<BoxProps>`
${({ width, height }) => `
width: ${width};
height: ${height};
`};
${spacingSystem}
${sizeSystem}
box-sizing: border-box;
`

export interface BoxProps {
/** width in percentage or px */
width?: string | number
/** height in percentage or px */
height?: string | number
}
export type BoxProps = SpacingSystem & SizeSystem

export default Box
2 changes: 1 addition & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC } from 'react'
import styled, { DefaultTheme } from 'styled-components'
import styled from 'styled-components'

import { getMeasure } from '../../helpers'
import Spinner from '../Spinner'
Expand Down
1 change: 1 addition & 0 deletions src/components/Flexible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Flexible = styled(Box)<FlexibleProps>(props => ({
alignContent: props.content,
}))

//@ts-ignore
Flexible.defaultProps = {
width: 'auto',
height: 'auto',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/forms.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
}

export const inputs = () => (
<Box width="30%">
<Box width="md">
<Input type="text" placeholder="Generic Text Input" />
<Input type="email" placeholder="Email Input" />
<Input type="search" placeholder="Search Input" />
Expand Down
10 changes: 5 additions & 5 deletions src/components/Scrollable/scrollable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
}

export const yAxis = () => (
<Scrollable axis="y" width="300px" height="200px">
<Scrollable axis="y" width="lg" height="lg">
<Heading level={6}>Start Scrolling</Heading>
<Box>
<Paragraph>
Expand All @@ -25,9 +25,9 @@ export const yAxis = () => (
)

export const xAxis = () => (
<Scrollable axis="x" width="300px" height="200px">
<Scrollable axis="x" width="lg" height="lg">
<Heading level={6}>Start Scrolling</Heading>
<Box width="600px" height="1px" style={{ backgroundColor: 'black' }} />
<Box width="md" height="sm" style={{ backgroundColor: 'black' }} />
<Box>
<Paragraph>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
Expand All @@ -43,9 +43,9 @@ export const xAxis = () => (
)

export const xyAxis = () => (
<Scrollable axis="xy" width="300px" height="200px">
<Scrollable axis="xy" width="lg" height="lg">
<Heading level={6}>Start Scrolling</Heading>
<Box width="600px" height="1px" style={{ backgroundColor: 'black' }} />
<Box width="md" height="sm" style={{ backgroundColor: 'black' }} />
<Box>
<Paragraph>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box } from '..'

const Tabs: FC<TabsProps> = ({ activeTab, onTabClick, children }) => {
return (
<Box width="100%">
<Box width="lg">
<TabsProvider
value={{
activeTab,
Expand Down
6 changes: 3 additions & 3 deletions src/components/Typography/Paragraph.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from 'styled-components'
import { TypoSystem, typoSystem } from '../../tokenSystem/typo.system'

const Paragraph = styled.p`
font-size: 1.125rem;
font-weight: 400;
const Paragraph = styled.p<TypoSystem>`
${typoSystem}
text-justify: auto;
`

Expand Down
2 changes: 1 addition & 1 deletion src/components/Typography/typography.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const heading = () => (
)

export const paragraph = () => (
<Paragraph>
<Paragraph fs="h3" fw="bold">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
Expand Down
19 changes: 19 additions & 0 deletions src/tokenSystem/__tests__/tokenBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tokenBuilder from '../index'

describe('Token Builder', () => {
it('should work as basic', () => {
const y = {
scale: {
sm: '1rem',
md: '2rem',
},
propName: {
margin: 'm',
padding: 'm',
},
}
const res = tokenBuilder(y)
const solvedResults = res.map(x => x({ m: 'sm' }))
expect(solvedResults).toEqual([{ margin: '1rem' }, { padding: '1rem' }])
})
})
27 changes: 27 additions & 0 deletions src/tokenSystem/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const tokenBuilder = (styles: Args) => {
const { propName, scale } = styles
const props = Object.keys(propName)

const styleFunctions = props.map(prop => {
const name = propName[prop]

const curriedStyleFn = (key, scale) => receivedProps => ({
[prop]: scale[receivedProps[key]],
})

return curriedStyleFn(name, scale)
})

return styleFunctions
}

type PropSet = {
[key: string]: any
}

type Args = {
scale: PropSet
propName: PropSet
}

export default tokenBuilder
22 changes: 22 additions & 0 deletions src/tokenSystem/size.system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tokenBuilder from './index'

const defaultSize = {
scale: {
sm: '50%',
md: '2rem',
lg: '3rem',
},
propName: {
width: 'width',
height: 'height',
},
}

export const sizeSystem = tokenBuilder(defaultSize) as SizeSystem

export type SizeScale = 'sm' | 'md' | 'lg'

export type SizeSystem = {
height?: SizeScale
width?: SizeScale
}
38 changes: 38 additions & 0 deletions src/tokenSystem/spacing.system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tokenBuilder from './index'

const defaultSpacing = {
scale: {
sm: '5rem',
md: '2rem',
lg: '3rem',
},
propName: {
margin: 'm',
marginTop: 'mt',
marginRight: 'mr',
marginBottom: 'mb',
marginLeft: 'ml',
padding: 'p',
paddingTop: 'pt',
paddingRight: 'pr',
paddingBottom: 'pb',
paddingLeft: 'pl',
},
}

export const spacingSystem = tokenBuilder(defaultSpacing) as SpacingSystem

export type SpacingScale = 'sm' | 'md' | 'lg'

export type SpacingSystem = {
m?: SpacingScale
mt?: SpacingScale
mr?: SpacingScale
mb?: SpacingScale
ml?: SpacingScale
p?: SpacingScale
pt?: SpacingScale
pr?: SpacingScale
pb?: SpacingScale
pl?: SpacingScale
}
37 changes: 37 additions & 0 deletions src/tokenSystem/typo.system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tokenBuilder from './index'

const fs = {
scale: {
h1: '4rem',
h2: '3rem',
h3: '2.5rem',
h4: '2rem',
h5: '1.5rem',
h6: '1rem',
body: '0.8rem',
},
propName: {
fontSize: 'fs',
},
}

const fw = {
scale: {
light: '400',
normal: '600',
bold: '700',
},
propName: {
fontWeight: 'fw',
},
}

const fontSize = tokenBuilder(fs)
const fontWeight = tokenBuilder(fw)

export const typoSystem = [fontSize, fontWeight] as TypoSystem

export type TypoSystem = {
fs?: keyof typeof fs.scale
fw?: keyof typeof fw.scale
}