-
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
15d010c
commit 8d2d6bc
Showing
2 changed files
with
36 additions
and
37 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,44 +1,41 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {Is, BoxProps, BoxComponent} from './types/box-types' | ||
import {propTypes} from './enhancers' | ||
import enhanceProps from './enhance-props' | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Is, BoxProps, BoxComponent } from "./types/box-types"; | ||
import { propTypes } from "./enhancers"; | ||
import enhanceProps from "./enhance-props"; | ||
|
||
type Options<T extends Is> = { | ||
is: T | ||
} | ||
is: T; | ||
}; | ||
|
||
function createComponent<T extends Is>({ is: defaultIs }: Options<T>) { | ||
const Component: BoxComponent<T> = ({ is = defaultIs, innerRef, children, ...props }: BoxProps<T>) => { | ||
// Convert the CSS props to class names (and inject the styles) | ||
const {className, enhancedProps: parsedProps} = enhanceProps(props) | ||
const { className, enhancedProps: parsedProps } = enhanceProps(props); | ||
|
||
parsedProps.className = className | ||
parsedProps.className = className; | ||
|
||
if (innerRef) { | ||
parsedProps.ref = innerRef | ||
parsedProps.ref = innerRef; | ||
} | ||
|
||
return React.createElement(is, parsedProps, children) | ||
} | ||
|
||
;(Component as any).displayName = 'Box' | ||
|
||
;(Component as any).propTypes = { | ||
return React.createElement(is, parsedProps, children); | ||
}; | ||
(Component as any).displayName = "Box"; | ||
(Component as any).propTypes = { | ||
...propTypes, | ||
innerRef: PropTypes.func, | ||
is: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | ||
} | ||
|
||
;(Component as any).defaultProps = { | ||
}; | ||
(Component as any).defaultProps = { | ||
innerRef: null, | ||
is: 'div', | ||
boxSizing: 'border-box' | ||
} | ||
is: "div", | ||
boxSizing: "border-box" | ||
}; | ||
|
||
return Component | ||
return Component; | ||
} | ||
|
||
const Box = createComponent({ is: 'div' }) | ||
const Box = createComponent({ is: "div" }); | ||
|
||
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