-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add displaying style presets. * Add displaying style presets. * Add applying style presets. * Add support for highlight. * Refactor code a bit. * Adjust style. * Use real text content in prset display. * Use resizing handle for presets panel. * Create panel.js file. * Use custom title for presets. * Re-arrange code a bit. * Add keydown logic. * Use one line of text in presets. * Remove some comments. * Replace 'styles' with 'textStyles' * Finish up replacing styles. * Adjust tests to count with textStyles * Add test for exiting edit mode. * Add tests for adding presets. * Improve test for deleting presets. * Add test for highlight. * Add more tests for utils. * Todo * Use objectPick. Adjust keys * Remove redundant 'shift' from keydowneffect Make code more readable. * Reuse panel title again. * Rearrange tags a bit. * Split up presetgroup into a separate file. * Remove padding from presets as requested by UX * Add Storybook. * Add a font to storybook, too. * Add tests for keydown events. * Remove redundant keyhandlers. * Add explaining comments. * More comments. * Use CSS to handle displaying text in preset. * focus when setting active index. * Adjust tests to new font object. * Reset mock between testing.
- Loading branch information
Showing
19 changed files
with
1,681 additions
and
563 deletions.
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
134 changes: 134 additions & 0 deletions
134
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,134 @@ | ||
/* | ||
* 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'; | ||
import { StylePresetPropType } from '../../../types'; | ||
|
||
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({ | ||
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: StylePresetPropType.isRequired, | ||
isEditMode: PropTypes.bool.isRequired, | ||
handleAddColorPreset: PropTypes.func.isRequired, | ||
setIsEditMode: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default PresetsHeader; |
Oops, something went wrong.