-
Notifications
You must be signed in to change notification settings - Fork 178
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
Style presets #1277
Merged
Merged
Style presets #1277
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
ab712f4
Add displaying style presets.
miina 3f387a0
Add displaying style presets.
miina 2bcf720
Add applying style presets.
miina 992a502
Add support for highlight.
miina 2a68f3a
Refactor code a bit.
miina b9fec0d
Adjust style.
miina abbbb02
Use real text content in prset display.
miina 0a16269
Use resizing handle for presets panel.
miina ea9db0d
Create panel.js file.
miina 159015f
Use custom title for presets.
miina ef84af7
Re-arrange code a bit.
miina 3182186
Add keydown logic.
miina 3d34d17
Use one line of text in presets.
miina a51ea8a
Remove some comments.
miina 2cd76c5
Replace 'styles' with 'textStyles'
miina acbe164
Finish up replacing styles.
miina 186228f
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina f7bae7e
Adjust tests to count with textStyles
miina 614f8ac
Add test for exiting edit mode.
miina 42f3873
Add tests for adding presets.
miina 09649fb
Improve test for deleting presets.
miina eb8208c
Add test for highlight.
miina a75db23
Add more tests for utils.
miina f6db33c
Todo
miina c40e750
Use objectPick.
miina d10fbe7
Remove redundant 'shift' from keydowneffect
miina 72c56cb
Reuse panel title again.
miina 6a55c41
Rearrange tags a bit.
miina 76ad91d
Split up presetgroup into a separate file.
miina d893a31
Remove padding from presets as requested by UX
miina 4a55548
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina 0369d32
Add Storybook.
miina 9fad1ca
Add a font to storybook, too.
miina 6fec2a1
Add tests for keydown events.
miina 073caf2
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina e3ca7a4
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina 7a7cbf2
Remove redundant keyhandlers.
miina 233fe37
Add explaining comments.
miina ca52172
More comments.
miina 2a5dc91
Use CSS to handle displaying text in preset.
miina 93222c1
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina 0175693
Merge + resolve conflicts.
miina a79a29e
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina 5d4aa58
focus when setting active index.
miina 38a53eb
Adjust tests to new font object.
miina 06faceb
Reset mock between testing.
miina bd43a39
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina 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
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
137 changes: 137 additions & 0 deletions
137
assets/src/edit-story/components/panels/stylePreset/header.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,137 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import styled, { css } from 'styled-components'; | ||
import { rgba } from 'polished'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import { ReactComponent as Edit } from '../../../icons/edit_pencil.svg'; | ||
import { ReactComponent as Add } from '../../../icons/add_page.svg'; | ||
import { PanelTitle } from '../panel'; | ||
|
||
const buttonCSS = css` | ||
border: none; | ||
background: transparent; | ||
width: 30px; | ||
height: 28px; | ||
color: ${({ theme }) => rgba(theme.colors.fg.v1, 0.84)}; | ||
cursor: pointer; | ||
padding: 0; | ||
`; | ||
|
||
const AddColorPresetButton = styled.button` | ||
${buttonCSS} | ||
svg { | ||
width: 26px; | ||
height: 28px; | ||
} | ||
`; | ||
|
||
const ExitEditMode = styled.button` | ||
${buttonCSS} | ||
color: ${({ theme }) => theme.colors.fg.v1}; | ||
font-size: 12px; | ||
line-height: 14px; | ||
padding: 7px; | ||
height: initial; | ||
`; | ||
|
||
const EditModeButton = styled.button` | ||
${buttonCSS} | ||
height: 20px; | ||
svg { | ||
width: 16px; | ||
height: 20px; | ||
} | ||
`; | ||
|
||
function PresetsHeader({ | ||
miina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
handleAddColorPreset, | ||
isEditMode, | ||
setIsEditMode, | ||
stylePresets, | ||
}) { | ||
const { fillColors, textColors, textStyles } = stylePresets; | ||
const hasPresets = | ||
fillColors.length > 0 || textColors.length > 0 || textStyles.length > 0; | ||
|
||
const getActions = () => { | ||
return !isEditMode ? ( | ||
<> | ||
{hasPresets && ( | ||
<EditModeButton | ||
onClick={(evt) => { | ||
evt.stopPropagation(); | ||
setIsEditMode(true); | ||
}} | ||
aria-label={__('Edit presets', 'web-stories')} | ||
> | ||
<Edit /> | ||
</EditModeButton> | ||
)} | ||
<AddColorPresetButton | ||
onClick={handleAddColorPreset} | ||
aria-label={__('Add preset', 'web-stories')} | ||
> | ||
<Add /> | ||
</AddColorPresetButton> | ||
</> | ||
) : ( | ||
<ExitEditMode | ||
onClick={(evt) => { | ||
evt.stopPropagation(); | ||
setIsEditMode(false); | ||
}} | ||
aria-label={__('Exit edit mode', 'web-stories')} | ||
> | ||
{__('Exit', 'web-stories')} | ||
</ExitEditMode> | ||
); | ||
}; | ||
|
||
return ( | ||
<PanelTitle | ||
secondaryAction={getActions()} | ||
canCollapse={!isEditMode && hasPresets} | ||
> | ||
{__('Presets', 'web-stories')} | ||
</PanelTitle> | ||
); | ||
} | ||
|
||
PresetsHeader.propTypes = { | ||
stylePresets: PropTypes.shape({ | ||
miina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fillColors: PropTypes.array, | ||
textColors: PropTypes.array, | ||
textStyles: PropTypes.array, | ||
}).isRequired, | ||
isEditMode: PropTypes.bool.isRequired, | ||
handleAddColorPreset: PropTypes.func.isRequired, | ||
setIsEditMode: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default PresetsHeader; |
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.
Why is this one here? I mean, it does make sense, but it doesn't really fit this PR?
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.
Since I work on a 13'' screen it's just seriously annoying having to resize this panel after every refresh to see anything else at all, especially with dev tools open.
Can change it back before finishing the PR though (or leave it as it is + create a new issue for it)
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.
I think #227 and #825 cover this already