Skip to content

Commit

Permalink
[web] Introduce large variant of ColorSelector
Browse files Browse the repository at this point in the history
Summary:
In this diff we introduce `size` prop to `ColorSelector` component and implement styling/layout for `large` variant.

This is for use in the `EmojiAvatarSelection` component.

Test Plan:
Here's how it looks:

{F607941}

Also ensured that other usages of `ColorSelector` in `web` continue to appear as expected (eg ThreadSettings)

Reviewers: ashoat, ginsu, rohan

Reviewed By: rohan

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8313
  • Loading branch information
atulsmadhugiri committed Jun 27, 2023
1 parent ea5beb1 commit 30f18a8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
5 changes: 1 addition & 4 deletions web/avatars/emoji-avatar-selection-modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ div.modalBody {
}

div.tabBody {
height: 300px;
padding-top: 20px;
display: flex;
justify-content: center;
Expand All @@ -33,10 +34,6 @@ div.emojiPickerContainer {
align-items: center;
}

div.colorSelectorContainer {
margin: 20px 60px;
}

div.saveButtonContainer {
display: flex;
flex-direction: column;
Expand Down
3 changes: 2 additions & 1 deletion web/avatars/emoji-avatar-selection-modal.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ function EmojiAvatarSelectionModal(): React.Node {
</div>
</Tabs.Item>
<Tabs.Item id="color" header="Color">
<div className={css.colorSelectorContainer}>
<div className={css.tabBody}>
<ColorSelector
currentColor={pendingAvatarColor}
onColorSelection={onColorSelection}
size="large"
/>
</div>
</Tabs.Item>
Expand Down
12 changes: 12 additions & 0 deletions web/modals/threads/color-selector-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
border-radius: 24px;
}

.containerLarge {
height: 80px;
width: 80px;
border-radius: 40px;
}

.active,
.container:hover {
background-color: var(--color-selector-active-bg);
Expand All @@ -15,3 +21,9 @@ div.colorSplotch {
border-radius: 16px;
cursor: pointer;
}

div.colorSplotchLarge {
height: 60px;
width: 60px;
border-radius: 30px;
}
14 changes: 11 additions & 3 deletions web/modals/threads/color-selector-button.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ type ColorSelectorButtonProps = {
+color: string,
+currentColor: string,
+onColorSelection: (hex: string) => void,
+size?: 'small' | 'large',
};
function ColorSelectorButton(props: ColorSelectorButtonProps): React.Node {
const { color, currentColor, onColorSelection } = props;
const { color, currentColor, onColorSelection, size } = props;

const active = tinycolor.equals(color, currentColor);
const containerClassName = classNames(css.container, {
const containerClassName = classNames({
[css.container]: true,
[css.containerLarge]: size === 'large',
[css.active]: active,
});

const colorSplotchClassName = classNames({
[css.colorSplotch]: true,
[css.colorSplotchLarge]: size === 'large',
});

const colorSplotchStyle = React.useMemo(
() => ({
backgroundColor: `#${color}`,
Expand All @@ -33,7 +41,7 @@ function ColorSelectorButton(props: ColorSelectorButtonProps): React.Node {

return (
<Button onClick={onColorSplotchClicked} className={containerClassName}>
<div className={css.colorSplotch} style={colorSplotchStyle} />
<div className={colorSplotchClassName} style={colorSplotchStyle} />
</Button>
);
}
Expand Down
4 changes: 4 additions & 0 deletions web/modals/threads/color-selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ div.container {
width: 100%;
padding: 6px 0;
}

div.containerLarge {
row-gap: 36px;
}
14 changes: 11 additions & 3 deletions web/modals/threads/color-selector.react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import classNames from 'classnames';
import * as React from 'react';

import { selectedThreadColors } from 'lib/shared/color-utils.js';
Expand All @@ -10,9 +11,10 @@ import css from './color-selector.css';
type ColorSelectorProps = {
+currentColor: string,
+onColorSelection: (hex: string) => void,
+size?: 'small' | 'large',
};
function ColorSelector(props: ColorSelectorProps): React.Node {
const { currentColor, onColorSelection } = props;
const { currentColor, onColorSelection, size } = props;

const colorSelectorButtons = React.useMemo(
() =>
Expand All @@ -22,12 +24,18 @@ function ColorSelector(props: ColorSelectorProps): React.Node {
color={color}
currentColor={currentColor}
onColorSelection={onColorSelection}
size={size}
/>
)),
[currentColor, onColorSelection],
[currentColor, onColorSelection, size],
);

return <div className={css.container}>{colorSelectorButtons}</div>;
const containerClassName = classNames({
[css.container]: true,
[css.containerLarge]: size === 'large',
});

return <div className={containerClassName}>{colorSelectorButtons}</div>;
}

export default ColorSelector;

0 comments on commit 30f18a8

Please sign in to comment.