-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ecbe93
commit 49e0f10
Showing
44 changed files
with
811 additions
and
1,041 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"presets": ["@babel/env", "@babel/react"], | ||
"plugins": ["@babel/plugin-proposal-class-properties"] | ||
"presets": ["@babel/env", "@babel/react"], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties", | ||
["emotion", { "autoLabel": false }] | ||
] | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"singleQuote": true | ||
"singleQuote": true, | ||
"semi": false | ||
} |
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 @@ | ||
import '@storybook/addon-viewport/register' |
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 |
---|---|---|
@@ -1,40 +1,54 @@ | ||
import { css as ecss } from '@emotion/core'; | ||
import * as React from 'react'; | ||
import { BoxProps } from './box-types'; | ||
import enhanceProps from './enhance-props'; | ||
import { ClassNames } from '@emotion/core' | ||
import facepaint from 'facepaint' | ||
import * as React from 'react' | ||
import { BoxProps } from './box-types' | ||
import enhanceProps from './enhance-props' | ||
import { MediaQueryConsumer } from './media-query-context' | ||
|
||
class Box extends React.Component<BoxProps, {}> { | ||
static defaultProps = { | ||
css: null, | ||
innerRef: null, | ||
is: 'div', | ||
boxSizing: 'border-box' | ||
}; | ||
} | ||
|
||
ref = React.createRef(); | ||
ref = React.createRef() | ||
|
||
render() { | ||
const { is = 'div', css, innerRef, children, ...props } = this.props; | ||
const { is = 'div', css, innerRef, children, ...props } = this.props | ||
// Convert the CSS props to class names (and inject the styles) | ||
const { className, enhancedProps: parsedProps } = enhanceProps(props); | ||
|
||
// Add glamor class | ||
if (css) { | ||
parsedProps.className = `${className} ${ecss(css).toString()}`; | ||
} else { | ||
parsedProps.className = className; | ||
} | ||
const { className, enhancedProps: parsedProps, mqCSS } = enhanceProps(props) | ||
|
||
if (innerRef) { | ||
parsedProps.ref = (node: React.ReactNode) => { | ||
innerRef(node); | ||
}; | ||
innerRef(node) | ||
} | ||
|
||
parsedProps.ref = this.ref; | ||
parsedProps.ref = this.ref | ||
} | ||
|
||
return React.createElement(is, parsedProps, children); | ||
if (Object.keys(mqCSS).length > 0) { | ||
const mergedCSS = { ...css, ...mqCSS } | ||
// Add emotion class | ||
return React.createElement( | ||
MediaQueryConsumer, | ||
null, | ||
(breakpoints: string[]) => { | ||
const mq = facepaint(breakpoints) | ||
|
||
return React.createElement(ClassNames, null, ({ css: ecss, cx }) => | ||
React.createElement( | ||
is, | ||
{ className: cx(className, ecss(mq(mergedCSS))), ...parsedProps }, | ||
children | ||
) | ||
) | ||
} | ||
) | ||
} | ||
return React.createElement(is, parsedProps, children) | ||
} | ||
} | ||
|
||
export default Box; | ||
export default Box |
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 |
---|---|---|
@@ -1,37 +1,44 @@ | ||
export type CacheValue = string | number | boolean | object; | ||
let cache = new Map<string, CacheValue>(); | ||
export type CacheValue = string | number | boolean | object | ||
let cache = new Map<string, CacheValue>() | ||
|
||
export function get(property: string, value: CacheValue) { | ||
return cache.get(property + value); | ||
export function get( | ||
property: string, | ||
value: CacheValue | ||
): CacheValue | undefined { | ||
return cache.get(property + value) | ||
} | ||
|
||
export function set(property: string, value: CacheValue, className: string) { | ||
export function set( | ||
property: string, | ||
value: CacheValue, | ||
className: string | ||
): void { | ||
if (process.env.NODE_ENV !== 'production') { | ||
const valueType = typeof value; | ||
const valueType = typeof value | ||
if ( | ||
valueType !== 'boolean' && | ||
valueType !== 'number' && | ||
valueType !== 'string' | ||
) { | ||
const encodedValue = JSON.stringify(value); | ||
const encodedValue = JSON.stringify(value) | ||
throw new TypeError( | ||
`al- aluminum-box: invalid cache value “${encodedValue}”. Only booleans, numbers and strings are supported.` | ||
); | ||
) | ||
} | ||
} | ||
|
||
cache.set(property + value, className); | ||
cache.set(property + value, className) | ||
} | ||
|
||
export function entries() { | ||
return [...cache]; | ||
export function entries(): [string, CacheValue][] { | ||
return [...cache] | ||
} | ||
|
||
type CacheEntry = [string, CacheValue]; | ||
export function hydrate(newEntries: CacheEntry[]) { | ||
cache = new Map<string, CacheValue>([...cache, ...newEntries]); | ||
type CacheEntry = [string, CacheValue] | ||
export function hydrate(newEntries: CacheEntry[]): void { | ||
cache = new Map<string, CacheValue>([...cache, ...newEntries]) | ||
} | ||
|
||
export function clear() { | ||
cache.clear(); | ||
export function clear(): void { | ||
cache.clear() | ||
} |
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
Oops, something went wrong.