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

Fix category tile presentation #551

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -6,22 +6,21 @@
}

.imageWrapper {
background-image: var(--venia-image);
background-position: 50% 50%;
background-size: cover;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what we want.

border-radius: 50%;
border: 1px solid rgb(var(--venia-border));
box-shadow: 0 0 0 1px rgb(var(--venia-border));
display: block;
height: 5rem;
margin: 0 auto 1rem auto;
overflow: hidden;
padding: 0.1rem;
width: 5rem;
}

.image {
border-radius: 50%;
height: auto;
max-height: 100%;
max-width: 100%;
width: auto;
height: 100%;
opacity: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hide the image, but not from screen readers. It should be there, and if you right click the tile, the context menu should give you actions related to the image element (e.g., View image).

width: 100%;
}

.name {
Expand Down
32 changes: 20 additions & 12 deletions packages/venia-concept/src/components/CategoryList/categoryTile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { Component } from 'react';
import { arrayOf, string, shape } from 'prop-types';
import { Link } from 'react-router-dom';

import classify from 'src/classify';
import defaultClasses from './categoryTile.css';
import {
makeCategoryMediaPath,
makeProductMediaPath
} from 'src/util/makeMediaPath';
import defaultClasses from './categoryTile.css';

// TODO: get categoryUrlSuffix from graphql storeOptions when it is ready
const categoryUrlSuffix = '.html';
Expand All @@ -32,7 +33,8 @@ class CategoryTile extends Component {
name: string
}).isRequired
};
get previewImage() {

get imagePath() {
const { image, productImagePreview } = this.props.item;
const previewProduct = productImagePreview.items[0];
if (image) {
Expand All @@ -41,22 +43,28 @@ class CategoryTile extends Component {
return makeProductMediaPath(previewProduct.small_image);
}
}

render() {
const { classes, item } = this.props;
const imagePath = this.previewImage;
const { imagePath, props } = this;
const { classes, item } = props;

// interpolation doesn't work inside `url()` for legacy reasons
// so a custom property should wrap its value in `url()`
const imageUrl = imagePath ? `url(${imagePath})` : 'none';
const style = { '--venia-image': imageUrl };

// render an actual image element for accessibility
const imagePreview = imagePath ? (
<img className={classes.image} src={imagePath} alt={item.name} />
) : null;

return (
<Link
className={classes.root}
to={`/${item.url_key}${categoryUrlSuffix}`}
>
<span className={classes.imageWrapper}>
{imagePath && (
<img
className={classes.image}
src={imagePath}
alt={item.name}
/>
)}
<span className={classes.imageWrapper} style={style}>
{imagePreview}
</span>
<span className={classes.name}>{item.name}</span>
</Link>
Expand Down