Shopify / Shopify/liquid

[Feature] Improve transparency support for colors

Open
#1,587 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hi,

Sorry if this is not the correct place for Shopify features, but as there is no dedicated repo (we have a repo for Theme Partners but it does not seem to be read), I am posting it here. If there is a better way let me know.

As of today, dealing with colors in Shopify is extremely inconvenient because of the specific case of transparent color.

When you define a color like this:

{
  "type": "color",
  "id": "color"
}

The default value is blank. This means that you can easily use a default value:

{% assign color = section.settings.color | default: settings.background %}

However, if the merchant change the color, and then remove it back, then the value is not initialized to blank but to... the string rgba(0,0,0,0).

The consequence is that the default filter no longer works. Also, we have to pollute our code with dozen and dozen of code that needs to check both rgba and blank:

{% if section.settings.color == 'rgba(0,0,0,0)' or section.settings.color == blank %}
{% endif %}

I suggest several improvements:

Improvement 1

The first improvement would be to add a new transparent keyword that would handle both the cases. This can be done in a non BC way and ensure we have a unified way:

{% if section.settings.color == transparent %}
{% endif %}

Improvement 2

The second improvement would be to have Shopify restore more consistently the value when restored. For instance, if we explicitly define a rgba(0,0,0,0) as a default value:

{
  "type": "color",
  "id": "color",
  "default": "rgba(0,0,0,0)"
}

Then Shopify would restore the value back to this if removed. If no default is provided or a default different from rgba(0,0,0,0), then Shopify would restore it to blank, to allow the usage of default filter.

This would be a potential BC though.

Improvement 3

If 2 is not possible, then I think adding a new default property would allow to do that cleanly:

{% assign color = section.settings.color | default: settings.color, allow_transparent: false %}

If allow_transaprent is set to false, the default filter would use the default value if it is rgba(0,0,0,0).

This would map nicely with the existing allow_false option.

Here as well, this sounds like an easy win that would make code much much simpler. Our themes allow each section to have different color with fallback for theme settings, and due to this, this add nearly 200 lines of code of useless code (the color detection taking more line of code than actual section code most of the time!).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are identified. Start by tracing how Liquid color settings, blank values, rgba(0,0,0,0), and the default filter are handled; done requires choosing and implementing a consistent transparency behavior from the alternatives described, with coverage for the stated color cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.