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

feat(StyledSystem): Adds styled-system components to map to Core glob… #836

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/patternfly-4/react-core/package.json
Expand Up @@ -27,7 +27,10 @@
"dependencies": {
"@patternfly/react-icons": "^2.5.3",
"@patternfly/react-styles": "^2.3.0",
"emotion-theming": "^9.2.9",
"exenv": "^1.2.2",
"react-emotion": "^9.2.12",
"styled-system": "^3.1.11",
"focus-trap-react": "^4.0.1"
},
"peerDependencies": {
Expand All @@ -53,4 +56,4 @@
"glob": "^7.1.2",
"npmlog": "^4.1.2"
}
}
}
@@ -0,0 +1,62 @@
import { SFC, HTMLProps, ReactNode } from 'react';

export interface StyledBoxProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be available from styled-system @types/styled-system I am still not sure the best way to handle that though. That can either be listed as a peerDependency, and optional, or a straight dependency. @priley86 might have a better idea for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay cool, I can extend my interface with those typings. (just fixing a small issue with them here as well DefinitelyTyped/DefinitelyTyped#30170).
I am adding it as an optional dependency for now, sound good?

className: string,
children?: ReactNode,
component: string,
m?: number | string | Array<any>,
mb?: number | string | Array<any>,
ml?: number | string | Array<any>,
mr?: number | string | Array<any>,
mt?: number | string | Array<any>,
mx?: number | string | Array<any>,
my?: number | string | Array<any>,
p?: number | string | Array<any>,
pb?: number | string | Array<any>,
pl?: number | string | Array<any>,
pr?: number | string | Array<any>,
pt?: number | string | Array<any>,
px?: number | string | Array<any>,
py?: number | string | Array<any>,
height?: number | string | Array<any>,
width?: number | string | Array<any>,
fontSize?: number | string | Array<any>,
bg?: number | string | Array<any>,
color?: number | string | Array<any>,
flex?: number | string | Array<any>,
order?: number | string | Array<any>,
alignSelf?: number | string | Array<any>,
border?: number | string | Array<any>,
borderBottom?: number | string | Array<any>,
borderLeft?: number | string | Array<any>,
borderRight?: number | string | Array<any>,
borderTop?: number | string | Array<any>,
borderColor?: number | string | Array<any>,
borderRadius?: number | string | Array<any>,
boxShadow?: number | string | Array<any>,
maxWidth?: number | string | Array<any>,
minWidth?: number | string | Array<any>,
maxHeight?: number | string | Array<any>,
minHeight?: number | string | Array<any>,
display?: number | string | Array<any>,
verticalAlign?: number | string | Array<any>,
opacity?: number | string | Array<any>,
overflow?: number | string | Array<any>,
ratio?: number | string | Array<any>,
flexBasis?: number | string | Array<any>,
background?: number | string | Array<any>,
backgroundImage?: number | string | Array<any>,
backgroundSize?: number | string | Array<any>,
backgroundPosition?: number | string | Array<any>,
backgroundRepeat?: number | string | Array<any>,
position?: number | string | Array<any>,
zIndex?: number | string | Array<any>,
left?: number | string | Array<any>,
top?: number | string | Array<any>,
right?: number | string | Array<any>,
bottom?: number | string | Array<any>
}

declare const StyledBox: SFC<StyledBoxProps>;

export default StyledBox;
@@ -0,0 +1,285 @@
import React from 'react';
import { css } from '@patternfly/react-styles';
import PropTypes from 'prop-types';
import styled from 'react-emotion';
import { ThemeProvider } from 'emotion-theming';
import {
space,
color,
display,
maxWidth,
minWidth,
width,
height,
maxHeight,
minHeight,
verticalAlign,
flex,
order,
flexBasis,
alignSelf,
fontSize,
borders,
borderColor,
borderRadius,
boxShadow,
opacity,
overflow,
ratio,
background,
backgroundImage,
backgroundSize,
backgroundPosition,
backgroundRepeat,
position,
zIndex,
left,
top,
right,
bottom
} from 'styled-system';
import { StyledTheme } from './StyledTheme';

export const StyledBoxBase = styled('div')(
// theme key: space
space,
// theme key: maxWidths
maxWidth,
// theme key: minWidths
minWidth,
// theme key: heights
height,
// theme key: maxHeights
maxHeight,
// theme key: minHeights
minHeight,
// theme key: fontSizes
fontSize,
// theme key: colors
color,
// theme key: borders
borders,
// theme key: colors
borderColor,
// theme key: radii
borderRadius,
// theme key: shadows
boxShadow,

// no theme keys
display,
width,
verticalAlign,
opacity,
overflow,
ratio,

// flex child props
flex,
flexBasis,
order,
alignSelf,

// background props
background,
backgroundImage,
backgroundSize,
backgroundPosition,
backgroundRepeat,

// position props
position,
zIndex,
left,
top,
right,
bottom
);

const StyledBox = ({ className, children, component, ...props }) => {
const StyledBoxBaseWithComponent = StyledBoxBase.withComponent(component);
return (
<ThemeProvider theme={StyledTheme}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should take the time to add a PatternFlyThemeProvider that contains this. That would allow people to overwrite the theme anywhere in the tree. Also, it would take some of the overhead out of this.

<StyledBoxBaseWithComponent {...props} className={css(className)}>
{children}
</StyledBoxBaseWithComponent>
</ThemeProvider>
);
};

StyledBox.propTypes = {
/** Additional classes that are passed into the StyledBox */
className: PropTypes.string,
/** Anything that can be rendered inside the StyledBox */
children: PropTypes.node,
/** HTML element to render as */
component: PropTypes.string,

// ...space.propTypes
/** margin - Maps with Maps with StyledConstants.space */
m: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-bottom - Maps with Maps with StyledConstants.space */
mb: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-left - Maps with Maps with StyledConstants.space */
ml: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-right - Maps with Maps with StyledConstants.space */
mr: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-top - Maps with Maps with StyledConstants.space */
mt: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-left and margin-right - Maps with Maps with StyledConstants.space */
mx: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** margin-top and margin-bottom - Maps with Maps with StyledConstants.space */
my: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding - Maps with Maps with StyledConstants.space */
p: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-bottom - Maps with Maps with StyledConstants.space */
pb: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-left - Maps with Maps with StyledConstants.space */
pl: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-right - Maps with Maps with StyledConstants.space */
pr: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-top - Maps with Maps with StyledConstants.space */
pt: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-left and padding-right - Maps with Maps with StyledConstants.space */
px: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** padding-top and padding-bottom - Maps with Maps with StyledConstants.space */
py: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),

// ...borders.propTypes
/** border - Maps with StyledConstants.borders */
border: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-bottom - Maps with StyledConstants.borders */
borderBottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-left - Maps with StyledConstants.borders */
borderLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-right - Maps with StyledConstants.borders */
borderRight: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-top - Maps with StyledConstants.borders */
borderTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),

// ...color.propTypes
/** background-color - Maps with StyledConstants.colors */
bg: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** color: Maps with StyledConstants.colors */
color: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),

/** height */
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** width */
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** font-size */
fontSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** flex */
flex: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** order */
order: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** align-self */
alignSelf: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-color */
borderColor: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** border-radius */
borderRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** box-shadow */
boxShadow: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** max-width */
maxWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** min-width */
minWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** max-height */
maxHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** min-height */
minHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** display */
display: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** vertical-align */
verticalAlign: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** opacity */
opacity: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** overflow */
overflow: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** ratio */
ratio: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** flex-basis */
flexBasis: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** background */
background: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** background-image */
backgroundImage: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** background-size */
backgroundSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** background-position */
backgroundPosition: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** background-repeat */
backgroundRepeat: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** position */
position: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** z-index */
zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** left */
left: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** top */
top: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** right */
right: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
/** bottom */
bottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array])
};

StyledBox.defaultProps = {
className: '',
children: null,
component: 'div',
m: null,
mb: null,
ml: null,
mr: null,
mt: null,
mx: null,
my: null,
p: null,
pb: null,
pl: null,
pr: null,
pt: null,
px: null,
py: null,
height: null,
width: null,
fontSize: null,
bg: null,
color: null,
flex: null,
order: null,
alignSelf: null,
border: null,
borderBottom: null,
borderLeft: null,
borderRight: null,
borderTop: null,
borderColor: null,
borderRadius: null,
boxShadow: null,
maxWidth: null,
minWidth: null,
maxHeight: null,
minHeight: null,
display: null,
verticalAlign: null,
opacity: null,
overflow: null,
ratio: null,
flexBasis: null,
background: null,
backgroundImage: null,
backgroundSize: null,
backgroundPosition: null,
backgroundRepeat: null,
position: null,
zIndex: null,
left: null,
top: null,
right: null,
bottom: null
};

export default StyledBox;