Skip to content

Commit

Permalink
export boxprops
Browse files Browse the repository at this point in the history
  • Loading branch information
hennessyevan committed Jul 2, 2019
1 parent 15d010c commit 8d2d6bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
47 changes: 22 additions & 25 deletions src/box.tsx
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;
26 changes: 14 additions & 12 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as cache from './cache'
import * as styles from './styles'
import * as cache from "./cache";
import * as styles from "./styles";

export {default} from './box'
export {default as splitProps} from './utils/split-props'
export {default as splitBoxProps} from './utils/split-box-props'
export { default } from "./box";
export { default as splitProps } from "./utils/split-props";
export { default as splitBoxProps } from "./utils/split-box-props";

export {
background,
Expand All @@ -25,20 +25,22 @@ export {
propNames,
propAliases,
propEnhancers
} from './enhancers/index'
} from "./enhancers/index";

export const hydrate = cache.hydrate
export const hydrate = cache.hydrate;

export * from "./types/box-types";

export function extractStyles() {
const output = {
cache: cache.entries(),
styles: styles.getAll()
}
clearStyles()
return output
};
clearStyles();
return output;
}

export function clearStyles() {
cache.clear()
styles.clear()
cache.clear();
styles.clear();
}

0 comments on commit 8d2d6bc

Please sign in to comment.