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 fallback when css masking is not supported #654

Merged
merged 4 commits into from
Nov 27, 2024
Merged

Conversation

hatemhosny
Copy link
Collaborator

What type of PR is this? (check all applicable)

  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation Update
  • 🎨 Style
  • ♻️ Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • πŸ“¦ Chore (Release)
  • ⏩ Revert
  • 🌐 Internationalization / Translation

Description

As discussed in #652 , CSS masking is a relatively new feature and is not yet widely supported (baseline compatibility: "newly available").

This PR adds a fallback when it is not available by using the same svg data url as a background image instead, and makes the color darker or lighter by changing filter (e.g. invert(0.8) -> invert(1)).

It does not use the currentColor like the CSS mask, however it uses shades of grey.
Not ideal, but very usable.
This will only have effect when the CSS masking is not available.

The main code added:

@supports not (mask-image: var(--svg)) {
  [class^='icon-'] {
    background-color: transparent;
    background-image: var(--svg);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    filter: var(--icon-filter);
  }

  a:hover [class^='icon-'],
  button:hover [class^='icon-'],
  [class^='icon-']:hover {
    filter: var(--icon-filter-active);
  }
}

Related Tickets & Documents

Fixes #652

Mobile & Desktop Screenshots/Recordings

If CSS masking doesn't work (before the fix):

image

Dark theme

image

Light theme

image

Share screen: light theme

image

Share screen: dark theme

image

Added tests?

  • πŸ‘ yes
  • πŸ™… no, because they aren't needed
  • πŸ™‹ no, because I need help

Added to documentations?

  • πŸ““ docs (./docs)
  • πŸ“• storybook (./storybook)
  • πŸ“œ README.md
  • πŸ™… no documentation needed

@gigamaster , would you kindly review this at your convenience?

Copy link

netlify bot commented Nov 27, 2024

βœ… Deploy Preview for livecodes ready!

Name Link
πŸ”¨ Latest commit b4384a5
πŸ” Latest deploy log https://app.netlify.com/sites/livecodes/deploys/67477bec5bd4620008e9cc7b
😎 Deploy Preview https://deploy-preview-654--livecodes.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

cloudflare-workers-and-pages bot commented Nov 27, 2024

Deploying livecodes with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: b4384a5
Status:Β βœ…Β  Deploy successful!
Preview URL: https://9dce33f1.livecodes.pages.dev
Branch Preview URL: https://css-icon-fallback.livecodes.pages.dev

View logs

@hatemhosny
Copy link
Collaborator Author

Merging as discussed in #652

@hatemhosny hatemhosny merged commit 540f29e into develop Nov 27, 2024
13 checks passed
@hatemhosny hatemhosny deleted the css-icon-fallback branch November 27, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSS icons fallback
1 participant