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

Color picker – Add full gradient support #497

Merged
merged 98 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
7609ca8
WIP gradient picker
Mar 2, 2020
f4ec203
Merge branch 'master' into feature/263-gradient-picker
Mar 2, 2020
1df5841
Added types for color and converted color picker to use new type format
Mar 3, 2020
71964ab
Added CSS generator and unit tests for same
Mar 3, 2020
e9d7d57
Merge branch 'master' into feature/263-gradient-picker
Mar 3, 2020
d6eed70
Converted color picker to new format and added migrations
Mar 4, 2020
c8066c2
WIP update color editing component
Mar 4, 2020
1170c8e
Now displaying color picker next to design panel
Mar 4, 2020
14b53d7
Fix color input for texts
Mar 4, 2020
a45421b
Fix color for square too, plus fix text output
Mar 4, 2020
ec75c2f
Fix generated page background
Mar 4, 2020
04476b8
Merge branch 'master' into feature/263-gradient-picker
Mar 4, 2020
cd91392
Fix all unit tests involving color picker and panels
Mar 4, 2020
8274a80
Added object-to-css convert and made generator only create object
Mar 4, 2020
d16a4c1
Added solid creator helper
Mar 4, 2020
11b6291
Added reducer logic to color picker
Mar 4, 2020
3c70b07
Refactor color picker header, add reverse and rotate
Mar 5, 2020
1c1b3d5
Fix gradient ends
Mar 5, 2020
ac2af82
Fade in color picker
Mar 5, 2020
e79a824
Added labels to buttons in color picker
Mar 5, 2020
e5e31d9
Use better package for css transition
Mar 5, 2020
2697481
Added a lot of keyboard interaction for gradient stop manipulation
Mar 5, 2020
e98c931
Fix some bugs and generators
Mar 5, 2020
024f138
Fixeda number of bugs related to gradients
Mar 5, 2020
3a5519a
Limit gradient stops to [0;1]
Mar 5, 2020
6d3c02a
Update color component and make sure all tests pass
Mar 5, 2020
1bfefca
Fix pattern generator and tests
Mar 5, 2020
05573cc
Fix some broken types
Mar 5, 2020
88d64b3
Merge branch 'master' into feature/263-gradient-picker
Mar 5, 2020
dbba2de
Generalized sidebar to app level
Mar 5, 2020
483bd3f
Rename generatePatternCSS to generatePatternStyles
Mar 5, 2020
152d3ba
Fix generator jsdoc
Mar 5, 2020
d91f09a
Fix circular imports by importing directly
Mar 5, 2020
980514b
Allow create solid to take strings
Mar 6, 2020
a670ea4
Better helper util for creating solids from string
Mar 6, 2020
7e104a7
Added `hasGradient` flag to color component (still unused)
Mar 6, 2020
30884d7
Fix typo
Mar 6, 2020
aaa47b0
Fix sidebar layering
Mar 6, 2020
26c6788
Reorganize color input component to smaller parts
Mar 6, 2020
d1739a5
Added unit test for color input sub-components
Mar 6, 2020
a272ed4
Added tests for two util functions
Mar 6, 2020
7d10e08
Added test for last util function
Mar 6, 2020
3d254d9
erge branch 'master' into feature/263-gradient-picker
Mar 6, 2020
c94975a
Add use-reduction as dependency
Mar 6, 2020
171f469
Fix text color
Mar 6, 2020
34c632b
Fix missing opacity
Mar 6, 2020
dd0f2bc
Memoize default color to avoid constant rerenders
Mar 6, 2020
b5a3381
Move useReduction to general utils
Mar 6, 2020
54ff425
Some focus management - close colorpicker and re-focus old
Mar 6, 2020
246df35
Require text color
Mar 6, 2020
a4e6398
Fix test warnings by adding colors to test text elements
Mar 6, 2020
1c45d3e
Add docs to generatePatternStyles
Mar 6, 2020
fe4b3f5
Always hide color picker on color input unmount
Mar 6, 2020
3959004
Merge branch 'master' into feature/263-gradient-picker
Mar 6, 2020
d5e6a3e
Make sure default context for sidebar provider has dummy functions
Mar 6, 2020
167dff3
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 6, 2020
1994b9a
Fix gradient picker post merge
Mar 6, 2020
674c196
Generalized some constants and moved gradient line to independent com…
Mar 6, 2020
9d509f2
Add gradient stop with pointer
Mar 6, 2020
6a1ee8b
Add gradient stop on pointer down rather than click
Mar 6, 2020
3391b65
Added mouse-based gradient stop move and remove
Mar 7, 2020
cd02bc3
Fix editable hex input
Mar 9, 2020
ee56bc8
Use editable preview for opacity too
Mar 9, 2020
cc75caf
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 9, 2020
09b73db
Some minor visual corrections to previews
Mar 9, 2020
e729f1e
Better handling of opacity in color input component
Mar 9, 2020
b131854
Fix editable hex input
Mar 9, 2020
630110b
Use editable preview for opacity too
Mar 9, 2020
fda1942
Some minor visual corrections to previews
Mar 9, 2020
e15b549
Better handling of opacity in color input component
Mar 9, 2020
16275c6
Restructure useFocusOut to take a ref and deps array
Mar 9, 2020
d327533
Remove debug defaults
Mar 9, 2020
83c6e64
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 9, 2020
bc05c51
Use `delete` key shortcut
Mar 9, 2020
710b51c
Fix stop direction movement
Mar 9, 2020
1dcac6b
Merge branch 'master' into feature/263-gradient-picker
Mar 9, 2020
ba843e7
Fix bug in escape handler
Mar 9, 2020
015f7e4
Merge branch 'master' into feature/263-gradient-picker
Mar 9, 2020
d8042ce
Fix layout in non-gradient color picker
Mar 9, 2020
3171e95
Fix tests and a11y for opacity preview
Mar 9, 2020
26b4876
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 9, 2020
95374f8
Fix color picker layout for gradient
Mar 9, 2020
5feec60
Adding pattern-global alpha for gradients
Mar 9, 2020
27e0152
Removing option of adding opacity to background
Mar 9, 2020
8d750b3
Added some unit tests ofor excluding opacity
Mar 9, 2020
ab3126f
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 9, 2020
4855fe6
Only allow gradieent types if enabled
Mar 9, 2020
b55ef0f
Merge branch 'master' into feature/263-gradient-picker
Mar 10, 2020
0e78aa1
Merge branch 'feature/263-gradient-picker' into feature/263-gradient-…
Mar 10, 2020
6ee818f
Merge branch 'master' into feature/263-gradient-implementation
Mar 10, 2020
654e6a6
Started integration test suite for color picker
Mar 10, 2020
941a57e
Minor test changes
Mar 10, 2020
fb72e56
Merge branch 'master' into feature/263-gradient-implementation
Mar 10, 2020
961dfc6
Added a bunch of integration tests for color picker
Mar 10, 2020
a3d66e2
A lot more integration tests for color picker
Mar 11, 2020
d1eb64e
Added final unit tests and some minor tweaks to get color picker cove…
Mar 11, 2020
410c1df
Fix some other missing test coverage now that we have gradients
Mar 11, 2020
2c727a4
Fix translator comments
swissspidy Mar 11, 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
9 changes: 3 additions & 6 deletions assets/src/edit-story/components/canvas/displayLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ import styled from 'styled-components';
*/
import { useStory } from '../../app';
import generatePatternStyles from '../../utils/generatePatternStyles';
import convertToCSS from '../../utils/convertToCSS';
import createSolid from '../../utils/createSolid';
import useCanvas from './useCanvas';
import DisplayElement from './displayElement';
import { Layer, PageArea } from './layout';

const DEFAULT_COLOR = createSolid(255, 255, 255);

const DisplayPageArea = styled(PageArea).attrs({
const DisplayPageArea = styled(PageArea).attrs(({ backgroundColor }) => ({
className: 'container',
overflowAllowed: false,
})`
${({ backgroundColor }) =>
convertToCSS(generatePatternStyles(backgroundColor || DEFAULT_COLOR))};
`;
style: generatePatternStyles(backgroundColor || DEFAULT_COLOR),
}))``;

function DisplayLayer() {
const {
Expand Down
15 changes: 6 additions & 9 deletions assets/src/edit-story/components/canvas/pagepreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ import PropTypes from 'prop-types';
*/
import useStory from '../../../app/story/useStory';
import generatePatternStyles from '../../../utils/generatePatternStyles';
import convertToCSS from '../../../utils/convertToCSS';
import createSolidFromString from '../../../utils/createSolidFromString';
import createSolid from '../../../utils/createSolid';
import { TransformProvider } from '../../transform';
import { UnitsProvider } from '../../../units';
import DisplayElement from '../displayElement';

const PAGE_THUMB_OUTLINE = 2;

const Page = styled.button`
const DEFAULT_COLOR = createSolid(255, 255, 255);

const Page = styled.button.attrs(({ backgroundColor }) => ({
style: generatePatternStyles(backgroundColor || DEFAULT_COLOR),
}))`
padding: 0;
margin: 0;
border: none;
Expand All @@ -42,12 +45,6 @@ const Page = styled.button`
isActive ? theme.colors.selection : theme.colors.bg.v1};
height: ${({ height }) => height}px;
width: ${({ width }) => width}px;
${({ backgroundColor, theme }) =>
convertToCSS(
generatePatternStyles(
backgroundColor || createSolidFromString(theme.colors.fg.v1)
)
)};
flex: none;
transition: width 0.2s ease, height 0.2s ease;

Expand Down
175 changes: 175 additions & 0 deletions assets/src/edit-story/components/colorPicker/colorPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* 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 { CSSTransition } from 'react-transition-group';
import { useEffect, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { rgba } from 'polished';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { PatternPropType } from '../../types';
import { useKeyDownEffect } from '../keyboard';
import useFocusOut from '../../utils/useFocusOut';
import CurrentColorPicker from './currentColorPicker';
import GradientPicker from './gradientPicker';
import Header from './header';
import useColor from './useColor';

const CONTAINER_PADDING = 15;

const Container = styled.div`
border-radius: 4px;
background: ${({ theme }) => theme.colors.bg.v7};
color: ${({ theme }) => theme.colors.fg.v1};
width: 240px;
font-family: ${({ theme }) => theme.fonts.body1.family};
font-style: normal;
font-weight: normal;
font-size: 12px;
user-select: none;
display: flex;
flex-direction: column;
align-items: stretch;

&.picker-appear {
opacity: 0.01;
margin-top: -10px;

&.picker-appear-active {
opacity: 1;
margin-top: 0;
transition: 300ms ease-out;
transition-property: opacity, margin-top;
}
}
`;

const Body = styled.div`
border-top: 1px solid ${({ theme }) => rgba(theme.colors.fg.v2, 0.2)};
padding: ${CONTAINER_PADDING}px;
`;

function ColorPicker({ color, hasGradient, hasOpacity, onChange, onClose }) {
const {
state: { type, stops, currentStopIndex, currentColor, generatedColor },
actions: {
load,
updateCurrentColor,
reverseStops,
selectStop,
addStopAt,
removeCurrentStop,
rotateClockwise,
moveCurrentStopBy,
setToSolid,
setToGradient,
},
} = useColor();

useEffect(() => {
if (generatedColor) {
onChange(generatedColor);
}
}, [color, generatedColor, onChange]);

useEffect(() => {
if (color) {
load(color);
}
}, [color, load]);

// Detect focus out of color picker (clicks or focuses outside)
const containerRef = useRef();
useFocusOut(containerRef, onClose);

// Re-establish focus when actively exiting by button or key press
const previousFocus = useRef(document.activeElement);
const handleCloseAndRefocus = useCallback(() => {
if (previousFocus.current) {
previousFocus.current.focus();
}
onClose();
}, [onClose]);

useKeyDownEffect(containerRef, 'esc', handleCloseAndRefocus);

return (
<CSSTransition in appear={true} classNames="picker" timeout={300}>
<Container
role="dialog"
aria-label={__('Color and gradient picker', 'web-stories')}
ref={containerRef}
>
<Header
hasGradient={hasGradient}
type={type}
setToGradient={setToGradient}
setToSolid={setToSolid}
onClose={handleCloseAndRefocus}
/>
{type !== 'solid' && (
<Body>
<GradientPicker
stops={stops}
currentStopIndex={currentStopIndex}
onSelect={selectStop}
onReverse={reverseStops}
onAdd={addStopAt}
onDelete={removeCurrentStop}
onRotate={rotateClockwise}
onMove={moveCurrentStopBy}
/>
</Body>
)}
<Body>
<CurrentColorPicker
color={currentColor}
onChange={updateCurrentColor}
showOpacity={hasOpacity}
/>
</Body>
</Container>
</CSSTransition>
);
}

ColorPicker.propTypes = {
onChange: PropTypes.func.isRequired,
onClose: PropTypes.func,
hasGradient: PropTypes.bool,
hasOpacity: PropTypes.bool,
color: PatternPropType,
};

ColorPicker.defaultProps = {
color: null,
onClose: () => {},
hasGradient: false,
hasOpacity: true,
};

export default ColorPicker;
18 changes: 18 additions & 0 deletions assets/src/edit-story/components/colorPicker/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/

export const LINE_LENGTH = 155;
export const LINE_WIDTH = 12;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const Container = styled.div`
`;

const Body = styled.div`
padding: ${CONTAINER_PADDING}px;
padding-bottom: 0;
display: grid;
grid: 'saturation hue alpha' ${BODY_HEIGHT}px / 1fr ${CONTROLS_WIDTH}px ${CONTROLS_WIDTH}px;
Expand Down Expand Up @@ -91,7 +90,7 @@ const Footer = styled.div`

const EyedropperWrapper = styled.div`
position: absolute;
left: ${CONTAINER_PADDING}px;
left: 0;
bottom: ${CONTAINER_PADDING}px;
`;

Expand All @@ -109,7 +108,7 @@ const CurrentWrapper = styled.div`

const CurrentAlphaWrapper = styled.div`
position: absolute;
right: ${CONTAINER_PADDING}px;
right: 0;
bottom: ${CONTAINER_PADDING}px;
`;

Expand Down
Loading