Skip to content
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 47 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ab712f4
Add displaying style presets.
miina Apr 17, 2020
3f387a0
Add displaying style presets.
miina Apr 17, 2020
2bcf720
Add applying style presets.
miina Apr 17, 2020
992a502
Add support for highlight.
miina Apr 17, 2020
2a68f3a
Refactor code a bit.
miina Apr 17, 2020
b9fec0d
Adjust style.
miina Apr 20, 2020
abbbb02
Use real text content in prset display.
miina Apr 20, 2020
0a16269
Use resizing handle for presets panel.
miina Apr 20, 2020
ea9db0d
Create panel.js file.
miina Apr 20, 2020
159015f
Use custom title for presets.
miina Apr 20, 2020
ef84af7
Re-arrange code a bit.
miina Apr 20, 2020
3182186
Add keydown logic.
miina Apr 20, 2020
3d34d17
Use one line of text in presets.
miina Apr 20, 2020
a51ea8a
Remove some comments.
miina Apr 20, 2020
2cd76c5
Replace 'styles' with 'textStyles'
miina Apr 20, 2020
acbe164
Finish up replacing styles.
miina Apr 20, 2020
186228f
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 21, 2020
f7bae7e
Adjust tests to count with textStyles
miina Apr 21, 2020
614f8ac
Add test for exiting edit mode.
miina Apr 21, 2020
42f3873
Add tests for adding presets.
miina Apr 21, 2020
09649fb
Improve test for deleting presets.
miina Apr 21, 2020
eb8208c
Add test for highlight.
miina Apr 21, 2020
a75db23
Add more tests for utils.
miina Apr 21, 2020
f6db33c
Todo
miina Apr 21, 2020
c40e750
Use objectPick.
miina Apr 22, 2020
d10fbe7
Remove redundant 'shift' from keydowneffect
miina Apr 22, 2020
72c56cb
Reuse panel title again.
miina Apr 22, 2020
6a55c41
Rearrange tags a bit.
miina Apr 22, 2020
76ad91d
Split up presetgroup into a separate file.
miina Apr 22, 2020
d893a31
Remove padding from presets as requested by UX
miina Apr 23, 2020
4a55548
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 23, 2020
0369d32
Add Storybook.
miina Apr 23, 2020
9fad1ca
Add a font to storybook, too.
miina Apr 23, 2020
6fec2a1
Add tests for keydown events.
miina Apr 23, 2020
073caf2
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 24, 2020
e3ca7a4
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 27, 2020
7a7cbf2
Remove redundant keyhandlers.
miina Apr 28, 2020
233fe37
Add explaining comments.
miina Apr 28, 2020
ca52172
More comments.
miina Apr 28, 2020
2a5dc91
Use CSS to handle displaying text in preset.
miina Apr 28, 2020
93222c1
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 28, 2020
0175693
Merge + resolve conflicts.
miina Apr 29, 2020
a79a29e
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 29, 2020
5d4aa58
focus when setting active index.
miina Apr 29, 2020
38a53eb
Adjust tests to new font object.
miina Apr 29, 2020
06faceb
Reset mock between testing.
miina Apr 29, 2020
bd43a39
Merge remote-tracking branch 'origin/master' into add/279-style-presets
miina Apr 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/src/edit-story/app/story/effects/useLoadStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function useLoadStory({ storyId, shouldLoad, restore }) {
if (!stylePresets.textColors) {
stylePresets.textColors = [];
}
if (!stylePresets.textStyles) {
stylePresets.textStyles = [];
}

// Set story-global variables.
const story = {
Expand Down
5 changes: 4 additions & 1 deletion assets/src/edit-story/components/panels/layer/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ function LayerPanel() {
return (
<Panel
name="layers"
initialHeight={numLayersVisible * LAYER_HEIGHT}
initialHeight={Math.min(
numLayersVisible * LAYER_HEIGHT,
window.innerHeight / 3
)}
Comment on lines +39 to +42
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Collaborator

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

resizeable
>
<PanelTitle isSecondary isResizable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { useRef } from 'react';
import { rgba } from 'polished';

/**
* WordPress dependencies
Expand All @@ -34,7 +33,6 @@ import useDragHandlers from '../useDragHandlers';
import useKeyboardHandlers from '../useKeyboardHandlers';

const Handle = styled.div`
background-color: ${({ theme }) => rgba(theme.colors.bg.v0, 0.07)};
border: 0;
padding: 0;
height: 6px;
Expand All @@ -46,10 +44,10 @@ const Handle = styled.div`
user-select: none;
`;

// @todo This needs blue outline when in focus.
const Bar = styled.div.attrs({
tabIndex: 0,
})`
background-color: ${({ theme }) => rgba(theme.colors.fg.v1, 0.1)};
width: 36px;
height: 4px;
border-radius: 2px;
Expand Down
29 changes: 17 additions & 12 deletions assets/src/edit-story/components/panels/panel/shared/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ const Header = styled.h2`
user-select: none;
`;

const HeaderButton = styled.button.attrs({ type: 'button' })`
const HeaderButton = styled.div.attrs({ role: 'button' })`
color: inherit;
border: 0;
padding: 10px 20px;
background: transparent;
display: flex;
justify-content: space-between;
align-items: center;
Expand All @@ -87,12 +85,15 @@ const HeaderActions = styled.div`
align-items: center;
`;

const Collapse = styled.span`
const Collapse = styled.button`
border: none;
background: transparent;
color: inherit;
width: 28px;
height: 28px;
display: flex; /* removes implicit line-height padding from child element */

padding: 0;
cursor: pointer;
svg {
width: 28px;
height: 28px;
Expand Down Expand Up @@ -155,17 +156,21 @@ function Title({
handleDoubleClick={resetHeight}
/>
)}
<HeaderButton
onClick={isCollapsed ? expand : collapse}
aria-label={titleLabel}
aria-expanded={!isCollapsed}
aria-controls={panelContentId}
>
<HeaderButton onClick={isCollapsed ? expand : collapse}>
<Heading>{children}</Heading>
<HeaderActions>
{secondaryAction}
{canCollapse && (
<Collapse isCollapsed={isCollapsed}>
<Collapse
isCollapsed={isCollapsed}
onClick={(evt) => {
evt.stopPropagation();
isCollapsed ? expand() : collapse();
}}
aria-label={titleLabel}
aria-expanded={!isCollapsed}
aria-controls={panelContentId}
>
<Arrow />
</Collapse>
)}
Expand Down
134 changes: 134 additions & 0 deletions assets/src/edit-story/components/panels/stylePreset/header.js
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;
Loading