vmware-clarity / core

Clarity is a scalable, accessible, customizable, open-source design system built with web components. Works with any JavaScript framework, created for enterprises, and designed to be inclusive.
https://clarity.design
MIT License
166 stars 42 forks source link

Allow customizing cds-icon using CSS transform without losing rotation #124

Open kepelrs opened 2 years ago

kepelrs commented 2 years ago

Summary

cds-icon could be more flexible if the CSS transforms were applied to the svg child element instead of the host.

Use case

Current

If I have a caret pointing down, the HMTL looks like this:

<cds-icon shape="angle" direction="down"></cds-icon>

and I can see the following style being applied by the constructed stylesheet:

(source)

:host([direction="down"]) {
    transform: rotate(180deg);
}

This means that I will lose the transform: rotate(180deg); if I try to add any transformations like transform: translateY(10px);. It means I'll have to be mindful and use transform: rotate(180deg) translateY(10px); instead. And if it is a generic style for any cds-icon direction, I'll have to make extra adjustments for that as well.

Proposed

Maybe the current could be improved if cds-icon applied its transforms to the svg instead of the host.

:host([direction="down"]) {
    svg {
            transform: rotate(180deg);
    }
}

This would leave the host cds-icon without any transforms, making it possible for users to add their own without worrying about overriding clarity's transforms (eg. downward rotation).