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

feat(drawing): add color picker component #1300

Merged
merged 32 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8a7294c
feat(drawing): add color picker component
ChenCodes Dec 1, 2020
dd420a0
chore(drawing): remove magic number
ChenCodes Dec 2, 2020
7001a2a
chore(drawing): use sibling selector
ChenCodes Dec 2, 2020
0c80c2a
chore(drawing): group imports / remove log
ChenCodes Dec 2, 2020
b231a3f
chore(drawing): flatten styles / do not style ControlsBar
ChenCodes Dec 2, 2020
817eb1d
chore(drawing): move ColorPickerPalette styles to its designated file
ChenCodes Dec 2, 2020
16657da
chore(drawing): fix eslint issues
ChenCodes Dec 2, 2020
0471d7f
chore(drawing): fix remaining lint issues
ChenCodes Dec 2, 2020
83187a6
chore(drawing): clean up styles / unused imports
ChenCodes Dec 2, 2020
68394ec
chore(drawing): add ColorPickerPalette test
ChenCodes Dec 3, 2020
fdf5cff
chore(drawing): add ColorPickerToggle test
ChenCodes Dec 3, 2020
011df39
chore(drawing): use hasClass
ChenCodes Dec 3, 2020
efc5e41
chore(drawing): rename as ColorPickerControl
ChenCodes Dec 3, 2020
589d2d2
chore(drawing): simplify sibling selector
ChenCodes Dec 3, 2020
731eec9
chore(drawing): pass color up through tree
ChenCodes Dec 3, 2020
2c90cdd
chore(drawing): add jest fn to test
ChenCodes Dec 3, 2020
c9ed901
chore(drawing): update DocBaseViewer test
ChenCodes Dec 3, 2020
9799954
chore(drawing): remove ControlsBar from ColorPickerPalette
ChenCodes Dec 3, 2020
4084bc5
chore(drawing): remove the explicit height
ChenCodes Dec 3, 2020
33fd6ee
chore(drawing): add shared variable
ChenCodes Dec 3, 2020
333800d
chore(drawing): update ColorPickerControl test
ChenCodes Dec 3, 2020
05763d8
chore(drawing): use border instead of box shadow
ChenCodes Dec 3, 2020
b64b1a7
chore(drawing): style the class instead of element
ChenCodes Dec 3, 2020
8d549cb
chore(drawing): revert back to using box shadow
ChenCodes Dec 3, 2020
261831e
chore(drawing): revert controls changes
ChenCodes Dec 3, 2020
53afaf1
chore(drawing): define bp-controls-background in styles file
ChenCodes Dec 3, 2020
8e5cedb
chore(drawing): refactor control / palette styles
ChenCodes Dec 3, 2020
a2f2636
chore(drawing): remove unused properties
ChenCodes Dec 3, 2020
c487c4d
chore(drawing): use #fff instead of white
ChenCodes Dec 3, 2020
1e4b91b
chore(drawing): set width and height as 18px instead of 16px
ChenCodes Dec 3, 2020
dcb5829
chore(drawing): remove unused import
ChenCodes Dec 3, 2020
e6017f1
Merge branch 'master' into add-color-picker-component
ChenCodes Dec 3, 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
46 changes: 46 additions & 0 deletions src/lib/viewers/controls/color-picker/ColorPickerPalette.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.bp-ColorPickerPalette {
position: absolute;
left: -55px;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
height: 35px;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
margin-bottom: 125px;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
background: inherit;
border-radius: 5px;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved

&::after {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
top: 75%;
width: 18px;
height: 18px;
background: inherit;
border-radius: 0 0 0 6px;
transform: rotate(-45deg);
content: '';
clip-path: polygon(0% 0%, 100% 100%, 0% 100%);
}
}

.bp-ColorPickerPalette-button {
width: 20px;
height: 20px;
margin-right: 2px;
margin-left: 2px;
border: none;
border-radius: 4px;
cursor: pointer;

&:first-child {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
margin-left: 8px;
}

&:hover {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
box-shadow: 0 0 0 2px white;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
}

&:last-child {
margin-right: 8px;
}
}
31 changes: 31 additions & 0 deletions src/lib/viewers/controls/color-picker/ColorPickerPalette.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import ControlsBar from '../controls-bar';
import './ColorPickerPalette.scss';

export type Props = {
onColorSelect: () => void; // TODO: this method wil need to take in a color string param
};

export default function ColorPickerPalette({ onColorSelect }: Props): JSX.Element {
const colors = ['#0061d5', '#26c281', '#ed3757', '#f5b31b', '#ffd700', '#4826c2'];
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these colors be moved outside of the function?


return (
<ControlsBar>
jstoffan marked this conversation as resolved.
Show resolved Hide resolved
<div className="bp-ColorPickerPalette">
{colors.map(color => {
return (
<button
key={color}
className="bp-ColorPickerPalette-button"
onClick={(): void => onColorSelect()}
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
style={{
backgroundColor: color,
}}
type="button"
/>
);
})}
</div>
</ControlsBar>
);
}
21 changes: 21 additions & 0 deletions src/lib/viewers/controls/color-picker/ColorPickerToggle.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@import '~box-ui-elements/es/styles/variables';
@import '../styles';

.bp-ColorPickerToggle {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
}

.bp-ColorPickerToggle-button {
@include bp-ControlButton;

svg {
background-color: #0061d5;
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
border-radius: 2px;
box-shadow: 0 0 0 2px white;
}
}
40 changes: 40 additions & 0 deletions src/lib/viewers/controls/color-picker/ColorPickerToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import ColorPickerPalette from './ColorPickerPalette';
import { AnnotationMode } from '../annotations/types';
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
import './ColorPickerToggle.scss';

export type Props = {
isActive?: boolean;
annotationMode?: AnnotationMode;
};

export default function ColorPickerToggle({ annotationMode, isActive = false, ...rest }: Props): JSX.Element | null {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
const [isColorPickerToggled, setIsColorPickerToggled] = useState(false);

if (annotationMode !== AnnotationMode.DRAWING) {
return null;
}

return (
<div className="bp-ColorPickerToggle">
{isColorPickerToggled && (
<ColorPickerPalette
onColorSelect={(): void => {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
setIsColorPickerToggled(false);
}}
/>
)}
<button
className={classNames('bp-ColorPickerToggle-button', {
'bp-is-active': isActive,
})}
onClick={(): void => setIsColorPickerToggled(!isColorPickerToggled)}
type="button"
{...rest}
>
<svg focusable="false" height="16" viewBox="0 0 16 16" width="16" />
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
</button>
</div>
);
}
2 changes: 2 additions & 0 deletions src/lib/viewers/controls/color-picker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ColorPickerToggle';
export { default } from './ColorPickerToggle';
4 changes: 4 additions & 0 deletions src/lib/viewers/controls/controls-bar/ControlsBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
background: fade-out($black, .2);
border-radius: 3px;
}

.bp-ControlsBar ~ .bp-ControlsBar {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
margin-left: 6px;
}
59 changes: 33 additions & 26 deletions src/lib/viewers/doc/DocControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import AnnotationsControls, { Props as AnnotationsControlsProps } from '../controls/annotations';
import ColorPickerToggle, { Props as ColorPickerToggleProps } from '../controls/color-picker';
import ControlsBar from '../controls/controls-bar';
import FindBarToggle, { Props as FindBarToggleProps } from '../controls/findbar';
import FullscreenToggle, { Props as FullscreenToggleProps } from '../controls/fullscreen';
Expand All @@ -8,6 +9,7 @@ import ThumbnailsToggle, { Props as ThumbnailsToggleProps } from '../controls/si
import ZoomControls, { Props as ZoomControlsProps } from '../controls/zoom';

export type Props = AnnotationsControlsProps &
ColorPickerToggleProps &
FindBarToggleProps &
FullscreenToggleProps &
PageControlsProps &
Expand Down Expand Up @@ -35,31 +37,36 @@ export default function DocControls({
scale,
}: Props): JSX.Element {
return (
<ControlsBar>
<ThumbnailsToggle onThumbnailsToggle={onThumbnailsToggle} />
<FindBarToggle onFindBarToggle={onFindBarToggle} />
<ZoomControls
maxScale={maxScale}
minScale={minScale}
onZoomIn={onZoomIn}
onZoomOut={onZoomOut}
scale={scale}
/>
<PageControls
onPageChange={onPageChange}
onPageSubmit={onPageSubmit}
pageCount={pageCount}
pageNumber={pageNumber}
/>
<FullscreenToggle onFullscreenToggle={onFullscreenToggle} />
<AnnotationsControls
annotationMode={annotationMode}
hasDrawing={hasDrawing}
hasHighlight={hasHighlight}
hasRegion={hasRegion}
onAnnotationModeClick={onAnnotationModeClick}
onAnnotationModeEscape={onAnnotationModeEscape}
/>
</ControlsBar>
<>
<ControlsBar>
<ThumbnailsToggle onThumbnailsToggle={onThumbnailsToggle} />
<FindBarToggle onFindBarToggle={onFindBarToggle} />
<ZoomControls
maxScale={maxScale}
minScale={minScale}
onZoomIn={onZoomIn}
onZoomOut={onZoomOut}
scale={scale}
/>
<PageControls
onPageChange={onPageChange}
onPageSubmit={onPageSubmit}
pageCount={pageCount}
pageNumber={pageNumber}
/>
<FullscreenToggle onFullscreenToggle={onFullscreenToggle} />
<AnnotationsControls
annotationMode={annotationMode}
hasDrawing={hasDrawing}
hasHighlight={hasHighlight}
hasRegion={hasRegion}
onAnnotationModeClick={onAnnotationModeClick}
onAnnotationModeEscape={onAnnotationModeEscape}
/>
</ControlsBar>
<ControlsBar>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added to the ImageControls as well?

<ColorPickerToggle annotationMode={annotationMode} />
</ControlsBar>
</>
);
}