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

SwatchTooltip component #956

Merged
merged 21 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
eeab847
Adds new SwatchTooltip component and uses it in ProductOptions
AlexeyKaryka Dec 22, 2018
a155af7
Updates unit test snapshots
supernova-at Feb 25, 2019
f650c76
Merge branch 'develop' into supernova/700
supernova-at Mar 6, 2019
e32dc68
Merge branch 'develop' into supernova/700
zetlen Mar 11, 2019
2c06482
Merge branch 'develop' into supernova/700
supernova-at Mar 12, 2019
8dea1f5
Merge branch 'develop' into supernova/700
supernova-at Mar 13, 2019
edbbbef
Removes itemIndex attribute from button rendered by Swatch component
supernova-at Mar 13, 2019
1001406
Merge branch 'develop' into supernova/700
supernova-at Mar 18, 2019
2e425af
Adds ARIA best practices to SwatchTooltip
supernova-at Mar 18, 2019
7f753ea
Improves accessibility of SwatchTooltip component
supernova-at Mar 18, 2019
9f9601a
Updates SwatchTooltip component children to be aria compliant
supernova-at Mar 19, 2019
33ff68e
Updates snapshots due to additions of aria attributes and event handl…
supernova-at Mar 19, 2019
921f95a
Removes randomness due to uuid from tests to improve stability
supernova-at Mar 19, 2019
ef014d5
Merge branch 'develop' into supernova/700
supernova-at Mar 20, 2019
3fa99ff
Reverts a change that added an erroneous className to a cloned child …
supernova-at Mar 20, 2019
1c718c2
Merge branch 'supernova/700' of github.com:magento-research/pwa-studi…
supernova-at Mar 20, 2019
215c1df
Merge branch 'develop' into supernova/700
supernova-at Mar 21, 2019
e97eead
Merge branch 'develop' into supernova/700
sirugh Mar 26, 2019
fb43b83
Merge branch 'develop' into supernova/700
sirugh Mar 26, 2019
93571ca
Add comment re: future of Tooltip component
sirugh Mar 26, 2019
1518dc2
Move tooltip to ProductOptions to discourage reuse in the interim bef…
sirugh Mar 26, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,50 @@ exports[`renders Option component correctly 1`] = `
<div
className="root"
>
<button
<div
className="root"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
>
<span
className="tooltip"
>
red
</span>
<button
className="root"
itemIndex={0}
supernova-at marked this conversation as resolved.
Show resolved Hide resolved
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
}
title="red"
/>
<button
title="red"
/>
</div>
<div
className="root"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
>
<span
className="tooltip"
>
blue
</span>
<button
className="root"
itemIndex={1}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
}
title="blue"
/>
title="blue"
/>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,89 +1,125 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`appends "_focused" to className if hasFocus is true 1`] = `
<button
className="root_focused"
style={
Object {
"--venia-swatch-bg": "123,123,123",
<div
className="root"
>
<span
className="tooltip"
>
red
</span>
<button
className="root_focused"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
}
title="red"
/>
title="red"
/>
</div>
`;

exports[`appends "_selected" to className if isSelected is true 1`] = `
<button
className="root_selected"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
title="red"
<div
className="root"
>
<span
className="root"
className="tooltip"
>
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="20 6 9 17 4 12"
/>
</svg>
red
</span>
</button>
<button
className="root_selected"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
title="red"
>
<span
className="root"
>
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="20 6 9 17 4 12"
/>
</svg>
</span>
</button>
</div>
`;

exports[`renders a Swatch correctly 1`] = `
<button
<div
className="root"
style={
Object {
"--venia-swatch-bg": "123,123,123",
>
<span
className="tooltip"
>
red
</span>
<button
className="root"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
}
title="red"
/>
title="red"
/>
</div>
`;

exports[`renders an icon if isSelected is true 1`] = `
<button
className="root_selected"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
title="red"
<div
className="root"
>
<span
className="root"
className="tooltip"
>
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="20 6 9 17 4 12"
/>
</svg>
red
</span>
</button>
<button
className="root_selected"
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
title="red"
>
<span
className="root"
>
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="20 6 9 17 4 12"
/>
</svg>
</span>
</button>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ exports[`renders SwatchList component correctly 1`] = `
<div
className="root"
>
<button
<div
className="root"
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
>
<span
className="tooltip"
>
foo
</span>
<button
className="root"
itemIndex={0}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
style={
Object {
"--venia-swatch-bg": "123,123,123",
}
}
}
title="foo"
/>
title="foo"
/>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
border-color: rgba(0, 0, 0, 0.1);
color: white;
padding: 0;
margin: 0;
--venia-swatch-bg: var(--venia-grey);
}

Expand Down
28 changes: 17 additions & 11 deletions packages/venia-concept/src/components/ProductOptions/swatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { bool, number, object, oneOfType, shape, string } from 'prop-types';

import classify from 'src/classify';
import Icon from 'src/components/Icon';
import SwatchTooltip from 'src/components/SwatchTooltip';
import CheckIcon from 'react-feather/dist/icons/check';

import defaultClasses from './swatch.css';

import { memoizedGetRandomColor } from 'src/util/getRandomColor';
Expand Down Expand Up @@ -44,32 +46,36 @@ class Swatch extends Component {
hasFocus,
isSelected,
item,
// eslint-disable-next-line
itemIndex,
style,
...restProps
} = props;

const className = classes[getClassName('root', isSelected, hasFocus)];
const { label, value_index } = item;

// TODO: use the colors from graphQL when they become available.
const randomColor = memoizedGetRandomColor(value_index);

// We really want to avoid specifying presentation within JS.
// Swatches are unusual in that their color is data, not presentation,
// but applying color *is* presentational.
// So we merely provide the color data here, and let the CSS decide
// how to use that color (e.g., background, border).
const finalStyle = Object.assign({}, style, {
'--venia-swatch-bg': memoizedGetRandomColor(value_index)
'--venia-swatch-bg': randomColor
});

return (
<button
{...restProps}
className={className}
style={finalStyle}
title={label}
>
{icon}
</button>
<SwatchTooltip text={label}>
<button
{...restProps}
className={className}
style={finalStyle}
title={label}
>
{icon}
</button>
</SwatchTooltip>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './swatchTooltip';
Loading