-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Closed
dratwas
wants to merge
18
commits into
WordPress:rnmobile/master
from
callstack:experimental/styled-components
Closed
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d9de3ef
Install styled-system and styled-components packages
mkevins fb3403e
Add simple Box component
mkevins 0903f8d
Add experimental Box to spacer block
mkevins e409523
Export some grid size constants
mkevins 8373764
Try experimental Box with gallery image mover buttons
mkevins 88490fb
add theme provider and fix styles
dratwas 7711806
fix theme provider
dratwas 6d17490
fix lint
dratwas 30f7828
Little refactor
dratwas 7e3a0bf
remove unused code
dratwas 8f0a152
fix styles
dratwas 9545777
remove unused changes
dratwas 4c0d8ae
remove compose
dratwas 7b1336d
remove sass from deps
dratwas 8bb7dfa
add isCompact prop
dratwas 6dbbfd9
use themeprovider values
dratwas 52791f6
use z-index from the theme
dratwas af23aee
use className
dratwas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Box } from '@wordpress/components'; | ||
|
||
const MenuBox = ( { right, isSelected, isCompact, children } ) => { | ||
const side = right ? { right: '-2px' } : { left: '-2px' }; | ||
return ( | ||
<Box | ||
display={ 'inline-flex' } | ||
padding={ isCompact ? 0 : 'small' } | ||
position="absolute" | ||
zIndex={ 'block-library-gallery-item__inline-menu' } | ||
bg={ isSelected ? 'primary' : 'inherit' } | ||
top="-2px" | ||
{ ...side } | ||
> | ||
{ children } | ||
</Box> | ||
); | ||
}; | ||
|
||
export default MenuBox; |
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
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,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import styled from 'styled-components'; | ||
import { color, space, layout, flexbox, background, border, position, shadow } | ||
from 'styled-system'; | ||
|
||
const Box = styled.div` | ||
${ color } | ||
${ space } | ||
${ layout } | ||
${ flexbox } | ||
${ background } | ||
${ border } | ||
${ position } | ||
${ shadow } | ||
`; | ||
|
||
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
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,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> | ||
); |
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
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.
Does this automatically translate to
View
on native or would we need a separate implementation?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.
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 comment
The 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
styled.View
instead ofstyled.div
?How would we implement other components, like the one to replace the
<figure>
inGalleryImage
? Would that also be the same as this but astyled.figure
?Borrowing from the previous
HTMLElement
experiment, I would expectBox
to be a more generic container thing that would accept atagName
prop to be used on the web implementation.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 comment
The 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
styled.View
if it is mobile.yes, you can either use a valid react/react-native component or a tagname like div, figure, h1 etc.