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

Add visual representation for filters #3045

Merged
merged 1 commit into from
Oct 19, 2023
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
84 changes: 71 additions & 13 deletions assets/component-facets.css
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,42 @@
padding: 0.5rem 2rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

The new filters dont show on the search template: https://screenshot.click/12-43-0fizq-qn1ea.mp4

Is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're looking at the wrong "Color" filter, remember you had two set up? Since you've searched for "bag", that doesn't match the product you attached the visual filter to, so it won't show up.

You could search for "*" instead and you should see it.

}

.facets-layout-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
text-align: center;
padding: 2rem 2.4rem;
gap: 3rem 1rem;
}

.facets-layout-grid.facets__list--vertical {
padding: 1rem 0;
}

.facets__item {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we thought about what happens if one of the colors match the background color? If the background is red for instance, and the colors have one color that is red.

https://screenshot.click/12-46-op07v-btf47.png

Copy link
Contributor

Choose a reason for hiding this comment

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

I see we have the special case for white, but we should ensure it works for whatever the background color is 👀
https://screenshot.click/12-20-93gyq-vif08.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm we don't have any special casing for white, it should work the same no matter the background color. We put a border around it like we can see in your screenshot, and the hover/focus/active states will make it stand out as well. Do you have any suggestions for any changes? I'd think the border around the swatch/thumbnail is all we need. https://screenshot.click/12-58-s8ep1-tb2lw.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is that the border around the white is dotted while the others arent. That works when the background is white, but not when you change it to a different color 🤔

@melissaperreault thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dotted border is what shows for the empty state. In your video, you must not have a valid visual representation for "Greens" or "White", it isn't special cased for white. For example, if you look at the app you can see you don't have those two properly set.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see that makes sense 👍

Copy link
Contributor

@melissaperreault melissaperreault Oct 13, 2023

Choose a reason for hiding this comment

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

@al-mcquiston and I am aligned it was the right UI visual to illustrate a missing value. Thanks for double checking @sofiamatulis !

display: flex;
align-items: center;
}

/* Hover/focus state */
.facets-layout-list .facets__label:hover .facet-checkbox__text,
.facets-layout-list input:focus ~ .facet-checkbox__text {
text-decoration: underline;
}
Comment on lines +293 to +296
Copy link
Contributor

Choose a reason for hiding this comment

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

(remark) Although this is fine IMO, I just wanted to point out that before, the hover state on the drawer/mobile mode wouldn't apply and underline to the filter values. Now this new selectors does have the side-effect of adding an underline style to thoses displays as well.

I do think this is a good change thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the non-mobile didn't have an underline before either. Al wanted to add it, he didn't specify if it should only be applied to desktop, but I don't think we should have different styles between the two (or else we'll continue to have spaghetti code in the future)


.facets-layout-grid > * {
align-items: flex-start;
}

.facets-layout-grid .visual-display-parent {
display: flex;
flex-direction: column;
gap: 0.8rem;
padding: 0;
height: 100%;
font-size: 1.3rem;
}

.facets__item label,
Copy link
Contributor

Choose a reason for hiding this comment

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

When showing multiple colors, it's showing as white. Is that expected? https://screenshot.click/12-00-qb4vh-ppeei.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because when we set up the filter, we set the override to Image (which doesn't look like you're using).

image

Instead, you can click the pencil/edit icon and change Swatch override to Colors and save.

.facets__item input[type='checkbox'] {
cursor: pointer;
Expand All @@ -291,6 +322,18 @@
word-break: break-word;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we have a different threshold for colors in terms of show more? For text, 10 makes sense because the list is long, but for color I feel like we could have more rows before showing show more?

https://screenshot.click/12-02-15hgf-y47n7.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a good idea. I'm thinking 24 since it's divisible by 3 and feels like it has a good balance between not TOO many, but not too few. I'd only do this for things that have a "visual display", it wouldn't be attached to "color" in any way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense 👍 Ill let @melissaperreault confirm

Copy link
Contributor

Choose a reason for hiding this comment

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

  • +1 for using a multiple of 3, it's great to have some rules here to structure the scannability.
  • For the limit I'll let @al-mcquiston provide the guidance. 24 seems a lot considering the color labels length and how they wrap on multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use 15 for swatch (5 rows), 12 for thumbnail (4 rows)

/* Hover, active, and focus states */
:is(.facets__label:hover, .facets__label.active, .facets__label:has(:focus-visible)) {
color: rgba(var(--color-foreground), 1);
}

/* Focus states for older browsers */
@supports not selector(:has(a, b)) {
.facets__label:focus-within {
color: rgba(var(--color-foreground), 1);
}
}
Comment on lines +331 to +335
Copy link
Contributor

Choose a reason for hiding this comment

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

(question) Couldn't we just put the rule as one of the rules in the :where since where is a forgiving selector parsing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because we don't want this to apply by default. If we did this, when you click on a filter, it has the focus-within pseudoclass. In this specific example, it's very subtle, but notice that the "Camo" is darker even though it's not selected or focused.

image


.facet-checkbox input[type='checkbox'] {
position: absolute;
opacity: 1;
Expand All @@ -303,6 +346,23 @@
-webkit-appearance: none;
}

.facets-layout-grid input[type='checkbox'] {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
opacity: 0;
}

.facets__visual-display-wrapper {
display: flex;
justify-content: center;
flex-shrink: 0;
}

.no-js .facet-checkbox input[type='checkbox'] {
z-index: 0;
}
Expand Down Expand Up @@ -336,8 +396,10 @@
}
}

.facet-checkbox--disabled {
color: rgba(var(--color-foreground), 0.4);
.facet-checkbox--disabled,
.mobile-facets__label--disabled {
opacity: 0.4;
pointer-events: none;
}

.facets__price {
Expand Down Expand Up @@ -744,20 +806,20 @@ details.menu-opening .mobile-facets__close svg {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is happening on mobile: https://screenshot.click/12-04-wo88b-bk2tr.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call out. I had added some styles that are no longer necessary. Instead, I got rid of those styles and set the width to 100% (to match the grid cell) in the case that we're inside of the .facets-layout-grid. That way, if it's used by itself it should have the 9rem, otherwise it fills the full width.

Note: the reason this is necessary is our "default" should be 9rem (if this is used outside of filters), but that doesn't actually fill the width for our desktop filters. If we don't force it to 100% there, we will get extra spacing on the left/right, which we don't want, so I can just force it to 100% width.

image


.mobile-facets__highlight {
opacity: 0;
visibility: hidden;
}

.mobile-facets__checkbox:checked + .mobile-facets__highlight {
visibility: visible;
opacity: 1;
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
display: block;
background-color: rgba(var(--color-foreground), 0.04);
opacity: 0;
visibility: hidden;
}

.mobile-facets__checkbox:checked + .mobile-facets__highlight {
opacity: 1;
visibility: visible;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why certain colors show the opacity different when unavailable while some have the /?

https://screenshot.click/12-06-17qnp-wwrsu.png

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They should all have the / - perhaps the color of it just matches the color of the swatch in that example?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're saying the contrast is not enough where at times you cant see the /?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the current foreground color at 40% opacity, along with setting the opacity of the image itself to 40%. Perhaps we could boost the opacity to make it more apparent, but the opacity itself also signifies it's disabled. Any suggestions?

Choose a reason for hiding this comment

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

I was noticing this too and think it's something we should fix. Is there a way we can just not apply the decreased opacity to the /?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We updated the / to use a static color which is visible for most colors. We tried many different options, but landed on this being the best one.

.mobile-facets__summary {
Expand Down Expand Up @@ -854,10 +916,6 @@ input.mobile-facets__checkbox {
display: block;
}

.mobile-facets__label--disabled {
opacity: 0.5;
}

.mobile-facets__footer {
border-top: 0.1rem solid rgba(var(--color-foreground), 0.08);
padding: 2rem;
Expand Down
89 changes: 89 additions & 0 deletions assets/component-visual-display.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.visual-display {
--visual-display__size: min(2.4rem, 100%);
position: relative;
width: var(--visual-display__size);
max-width: 100%;
border: 0.1rem solid rgba(var(--color-foreground), 0.2);
aspect-ratio: 1/1;
}

.visual-display.empty {
border-style: dashed;
}

.visual-display--presentation-swatch {
--visual-display__size: min(2.4rem, 100%);

border-radius: 100%;
overflow: hidden;
}

.visual-display-parent .visual-display--presentation-swatch {
outline-offset: 0.2rem;
}

/* Hover, active, and focus states */
:is(
.visual-display-parent:hover .visual-display--presentation-swatch,
.visual-display-parent.active .visual-display--presentation-swatch,
.visual-display-parent:has(:focus-visible) .visual-display--presentation-swatch
) {
outline-style: solid;
}

/* Active state */
.visual-display-parent.active .visual-display--presentation-swatch {
outline-width: 0.1rem;
outline-color: rgb(var(--color-foreground), 1);
}

/* Hover state */
.visual-display-parent:hover .visual-display--presentation-swatch {
outline-width: 0.2rem;
outline-color: rgb(var(--color-foreground), 0.4);
}

/* Focus state */
.visual-display-parent:has(:focus-visible) .visual-display--presentation-swatch {
outline-width: 0.2rem;
outline-color: rgb(var(--color-foreground), 0.4);
box-shadow: 0 0 0 0.6rem rgb(var(--color-background)), 0 0 0 0.8rem rgba(var(--color-foreground), 0.5),
0 0 1.2rem 0.4rem rgba(var(--color-foreground), 0.3);
}

/* Focus state for older browsers */
@supports not selector(:has(a, b)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a and b here? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Essentially, they don't matter. This is more just testing "does has work", not "does has with certain params/attributes work". Taken from mdn

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification. Im not sure if we need this here 🤔 Is there a reason why we are using focus-within

In Dawn, we have used focus and focus-visible historically

https://github.com/search?q=repo%3AShopify%2Fdawn+%3Afocus&type=code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is a pretty unique scenario, but I essentially want to know if anything inside of visual-display-parent has the :focus-visible (thus only visible if you use your keyboard to focus, not clicking, and then style the .visual-display inside of it. There isn't a css pseudo class that allows this, and there's a pretty good article about it.

Essentially I have this class .visual-display-parent:has(:focus-visible) .visual-display--style-swatch giving us the preferred css selector, then this @supports not style will be the fallback for browsers that don't yet support :has, giving them the less ideal :focus-within experience.

Here's a sandbox and a video showing the difference!

.visual-display-parent:focus-within .visual-display--presentation-swatch {
outline-offset: 0.2rem;
outline: 0.2rem solid rgb(var(--color-foreground), 0.4);
box-shadow: 0 0 0 0.6rem rgb(var(--color-background)), 0 0 0 0.8rem rgba(var(--color-foreground), 0.5),
0 0 1.2rem 0.4rem rgba(var(--color-foreground), 0.3);
}
}

.visual-display-parent.disabled {
opacity: 0.4;
pointer-events: none;
}

/* Used to display the disabled dash */
.visual-display-parent.disabled .visual-display::after {
display: block;
content: '';

/* 1.414 is not a magic number, it's the square root of 2, or the length of the diagonal */

Choose a reason for hiding this comment

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

It's not magic, it's math! ✨

width: calc(var(--visual-display__size) * 1.414);
border-bottom: 0.1rem solid rgb(var(--color-background-contrast));
transform: rotate(-45deg);
transform-origin: left;
}

.visual-display .visual-display__child {
display: block;
height: 100%;
width: 100%;
}

.visual-display--presentation-swatch .visual-display__image {
object-fit: cover;
}
14 changes: 14 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@
{% else %}
--gradient-background: {{ scheme.settings.background }};
{% endif %}

{% liquid
assign background_color = scheme.settings.background
assign background_color_brightness = background_color | color_brightness
if background_color_brightness <= 26
assign background_color_contrast = background_color | color_lighten: 50
elsif background_color_brightness <= 65
assign background_color_contrast = background_color | color_lighten: 5
else
assign background_color_contrast = background_color | color_darken: 25
endif
%}

--color-foreground: {{ scheme.settings.text.red }},{{ scheme.settings.text.green }},{{ scheme.settings.text.blue }};
--color-background-contrast: {{ background_color_contrast.red }},{{ background_color_contrast.green }},{{ background_color_contrast.blue }};
--color-shadow: {{ scheme.settings.shadow.red }},{{ scheme.settings.shadow.green }},{{ scheme.settings.shadow.blue }};
--color-button: {{ scheme.settings.button.red }},{{ scheme.settings.button.green }},{{ scheme.settings.button.blue }};
--color-button-text: {{ scheme.settings.button_label.red }},{{ scheme.settings.button_label.green }},{{ scheme.settings.button_label.blue }};
Expand Down
Loading