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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
62 changes: 62 additions & 0 deletions
62
packages/patternfly-4/react-core/src/components/StyledSystem/StyledBox.d.ts
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,62 @@ | ||
import { SFC, HTMLProps, ReactNode } from 'react'; | ||
|
||
export interface StyledBoxProps { | ||
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; |
285 changes: 285 additions & 0 deletions
285
packages/patternfly-4/react-core/src/components/StyledSystem/StyledBox.js
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,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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if we should take the time to add a |
||
<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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?