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

Make use of the theme color scheme for categories and use accessible text color depending on the background color #32

Open
2 tasks
colorfield opened this issue May 23, 2020 · 3 comments
Assignees
Labels
backend Backend related issue frontend Frontend related issue

Comments

@colorfield
Copy link
Contributor

colorfield commented May 23, 2020

Currently, we are mapping color field colors to Tailwind default color scheme.
As we will set a custom color scheme, it makes sense to use it for the categories color map.
See https://drupal.slack.com/archives/C011JF4C1M4/p1590315801406200

Each category can have a different color, if we plan to make use of the text category with the category color as a background, we need to respect a11y contrast as only the background color can be set on the admin ui and it should not be the responsibility of the content editor to pick the right contrast color.
https://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color

Screenshot 2020-05-23 at 19 21 06

Use case
As a content editor
When I select a category background color
Then the text color is set automatically with a a11y friendly contrast.

  • Alter ColorMap::getTailwindClass() and limit the color field colors based on the theme color scheme
  • Implement ColorMap::getTailwindContrastClass()
@colorfield colorfield self-assigned this May 23, 2020
@dan2k3k4 dan2k3k4 mentioned this issue May 23, 2020
10 tasks
@dan2k3k4
Copy link
Member

dan2k3k4 commented May 23, 2020

We can also just enforce the mapping of the colours in frontend without needing to rely on ColorMap functions.

The editor can select a set of predefined colours e.g.

  • blue
  • red
  • green

We would then need to check which colour was picked, and appropriately use the correct contrasting colour for text or background overlay.

In backend, the colour field was used just because it seemed a bit nicer to select a colour visually compared to using say a field list text.

Also the backend "red" may not equal the frontend "red" and that's OK. The colour red in the backend is just so that the admin editor has an idea of colours they can pick from.

We will need to update the list of colours once we finalise the colour scheme but most likely we can base our colours on Olivero

@colorfield
Copy link
Contributor Author

We could simplify this but i still find it nice to have a large variety of colors as we might end up with a few categories + the color field is working well for this use case.

Yes perhaps better to think about this once we have a defined scheme.
Meanwhile we could simplify this with black / white as contrast color (so we have only 2 contrast maps) and possibly tweak a bit the initial color map so we always have a good contrast.

@colorfield colorfield changed the title Use accessible text color depending on the category background color Make use of the theme color scheme for categories and use accessible text color depending on the background color May 24, 2020
@colorfield colorfield added backend Backend related issue frontend Frontend related issue labels May 24, 2020
@colorfield
Copy link
Contributor Author

we should be able to extend the ColorFieldWidgetBox field widget with our color scheme to remove the ColorMap and use named colors in this widget so we have one single source of truth https://git.drupalcode.org/project/color_field/-/blob/8.x-2.x/src/Plugin/Field/FieldWidget/ColorFieldWidgetBox.php#L25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related issue frontend Frontend related issue
Projects
None yet
Development

No branches or pull requests

2 participants