-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Experimental] Cross platform Box
component to replace div
#17614
Changes from all commits
d9de3ef
fb3403e
0903f8d
e409523
8373764
88490fb
7711806
6d17490
30f7828
7e3a0bf
8f0a152
9545777
4c0d8ae
7b1336d
8bb7dfa
6dbbfd9
52791f6
af23aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Box } from '@wordpress/components'; | ||
|
||
const MenuBox = ( { right, isSelected, isCompact, children, className } ) => { | ||
const side = right ? { right: '-2px' } : { left: '-2px' }; | ||
return ( | ||
<Box | ||
className={ className } | ||
display={ 'inline-flex' } | ||
padding={ isCompact ? 0 : 'small' } | ||
position="absolute" | ||
zIndex={ 'block-library-gallery-item__inline-menu' } | ||
bg={ isSelected ? '#ffffff' : 'inherit' } | ||
top="-2px" | ||
{ ...side } | ||
> | ||
{ children } | ||
</Box> | ||
); | ||
}; | ||
|
||
export default MenuBox; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import styled from 'styled-components'; | ||
import { color, space, layout, flexbox, background, border, position, shadow } | ||
from 'styled-system'; | ||
|
||
const Box = styled.div` | ||
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. Does this automatically translate to 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. no, we'll need a sparate box/index.native.js for that. Planning to open a separate PR for mobile 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. Oh, I was hoping styled-components would bring more reusability there. I imagine the implementation of that would be exactly the same except using How would we implement other components, like the one to replace the Borrowing from the previous I think the syntax of styled-components would allow for this, but I'm not sure what that looks like yet 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.
Right, that's also an option. We can do a platform check and call
yes, you can either use a valid react/react-native component or a tagname like div, figure, h1 etc. |
||
${ color } | ||
${ space } | ||
${ layout } | ||
${ flexbox } | ||
${ background } | ||
${ border } | ||
${ position } | ||
${ shadow } | ||
`; | ||
|
||
export default Box; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { ThemeProvider } from 'styled-components'; | ||
|
||
export { withTheme as withTheme } from 'styled-components'; | ||
|
||
const getTheme = ( theme ) => ( { | ||
fontSizes: { | ||
small: 12, | ||
medium: 18, | ||
big: 22, | ||
}, | ||
space: { | ||
small: 4, | ||
medium: 8, | ||
large: 16, | ||
xlarge: 24, | ||
}, | ||
zIndices: { | ||
'block-library-gallery-item__inline-menu': 20, | ||
}, | ||
colors: themes[ theme || '' ] || themes.default, | ||
} ); | ||
|
||
const themes = { | ||
default: { | ||
primary: '#0085ba', | ||
secondary: '#11a0d2', | ||
toggle: '#11a0d2', | ||
button: '#0085ba', | ||
outlines: '#007cba', | ||
}, | ||
'admin-color-light': { | ||
primary: '#0085ba', | ||
secondary: '#c75726', | ||
toggle: '#11a0d2', | ||
button: '#0085ba', | ||
outlines: '#007cba', | ||
}, | ||
'admin-color-blue': { | ||
primary: '#82b4cb', | ||
secondary: '#d9ab59', | ||
toggle: '#82b4cb', | ||
button: '#d9ab59', | ||
outlines: '#417e9B', | ||
}, | ||
'admin-color-coffee': { | ||
primary: '#c2a68c', | ||
secondary: '#9fa47b', | ||
toggle: '#c2a68c', | ||
button: '#c2a68c', | ||
outlines: '#59524c', | ||
}, | ||
'admin-color-ectoplasm': { | ||
primary: '#a7b656', | ||
secondary: '#c77430', | ||
toggle: '#a7b656', | ||
button: '#a7b656', | ||
outlines: '#523f6d', | ||
}, | ||
'admin-color-midnight': { | ||
primary: '#e14d43', | ||
secondary: '#77a6b9', | ||
toggle: '#77a6b9', | ||
button: '#e14d43', | ||
outlines: '#497b8d', | ||
}, | ||
'admin-color-ocean': { | ||
primary: '#a3b9a2', | ||
secondary: '#a89d8a', | ||
toggle: '#a3b9a2', | ||
button: '#a3b9a2', | ||
outlines: '#5e7d5e', | ||
}, | ||
'admin-color-sunrise': { | ||
primary: '#d1864a', | ||
secondary: '#c8b03c', | ||
toggle: '#c8b03c', | ||
button: '#d1864a', | ||
outlines: '#837425', | ||
}, | ||
}; | ||
|
||
export default ( { theme, children } ) => ( | ||
<ThemeProvider theme={ getTheme( theme ) }> | ||
{ children } | ||
</ThemeProvider> | ||
); |
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.
Note: this line is just for demonstrating that it is possible to override this value with custom CSS from outer place. You'll see #ffffff is not getting effective since we pass
block-library-gallery-item__move-menu
andblock-library-gallery-item__inline-menu
toBox
component.