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 limel-3d-hover-effect-glow as a @private internal component & use it #3330

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

Kiarokh
Copy link
Contributor

@Kiarokh Kiarokh commented Nov 28, 2024

A @private component that is required for making
a 3D glow effect on some components. This
can be replaced by some internal elements and
styles, to further simplify things.

Review:

  • Commits are atomic
  • Commits have the correct type for the changes made
  • Commits with breaking changes are marked as such

Browsers tested:

(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)

Windows:

  • Chrome
  • Edge
  • Firefox

Linux:

  • Chrome
  • Firefox

macOS:

  • Chrome
  • Firefox
  • Safari

Mobile:

  • Chrome on Android
  • iOS

@Kiarokh Kiarokh added visual design Visual styling that may or may not affect usability 🦄✨ yolo labels Nov 28, 2024
@Kiarokh Kiarokh self-assigned this Nov 28, 2024
Copy link

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3330/

@Kiarokh Kiarokh mentioned this pull request Nov 28, 2024
13 tasks
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 good thing with this component is that:

  1. we can add more CSS props for it (like the color of the highlight/glow).
  2. it can be more easily used in other repos by us, if needed. It's private, but still available.
  3. together with mixins, which are also available via importing the mixins.scss from node modules folder, we can achieve the same effect way more easily this way

Copy link
Contributor

Choose a reason for hiding this comment

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

together with mixins, which are also available via importing the mixins.scss from node modules folder

Just be aware that if you import stuff like that, and we ever change something internally in lime-elements, so that file is no longer included in the same place, all repos where such an import is made will break if they update lime-elements.

So if we really want to be able to do that, we should document where that file is supposed to be in the published package, and preferably also add some kind of test for that, so we can't accidentally break it.

position: absolute;
inset: 0;

opacity: 0.1;
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with putting the styling here is that the component will be rendered before the styling applies. It won't be visible then, since it's unstyled, but it will have a default opacity of 1. Then the styling applies, which set's the opacity to 0.1. But there's also been a transition applied to the opacity, so there will be this little "lightning flash" when the component is loaded.

Copy link
Contributor

Choose a reason for hiding this comment

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

lightning-flash.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄 On my slow machine things load in a totally different way and jump around so much until the page is completely loaded, so that I can't even see this visual effect that you screen recorded.

Bu I think I can fix it. I'll adda. fixup

Copy link
Contributor Author

@Kiarokh Kiarokh Dec 2, 2024

Choose a reason for hiding this comment

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

A note for future:

There are several ways of mitigating the effect that you mentioned.

The best one would be using the @property rule to animate the x and y, and opacity values of the radial gradient. I tried it, but couldn't really make it work. I don't exactly know why. Due to lack of time, I decided to keep a copy of the code here, and do it in a simpler but dirtier way.

What I did was like below…
In 3d-hover-effect-glow.scss tried to transition the CSS custom properties, combining them with @property rule.

:host(limel-3d-hover-effect-glow) {
    @property --limel-3d-hover-effect-glow-opacity {
        syntax: '<number>';
        inherits: true;
        initial-value: 0.1;
    }

    @property --limel-3d-hover-effect-glow-position-x {
        syntax: '<percentage>';
        inherits: true;
        initial-value: 50%;
    }

    @property --limel-3d-hover-effect-glow-position-y {
        syntax: '<percentage>';
        inherits: true;
        initial-value: -20%;
    }

    transition-property: --limel-3d-hover-effect-glow-opacity,
        --limel-3d-hover-effect-glow-position-x,
        --limel-3d-hover-effect-glow-position-y;
    transition-timing-function: ease-out; // Must be the same as the 3D Element itself
    transition-duration: 0.8s; // Must be the same as the 3D Element itself

    display: block;
    pointer-events: none;

    position: absolute;
    inset: 0;

    background-image: radial-gradient(
        circle at var(--limel-3d-hover-effect-glow-position-x, 50%)
            var(--limel-3d-hover-effect-glow-position-y, -20%),
        rgb(var(--color-white), var(--limel-3d-hover-effect-glow-opacity, 0.1)),
        rgb(var(--color-white), 0)
    );

    mix-blend-mode: plus-lighter;
}

and then in the mixins.scss, I would do:

@mixin the-3d-element {
    
   //

    &:hover {
        limel-3d-hover-effect-glow {
            transition-duration: 0s;
            --limel-3d-hover-effect-glow-opacity: 0.5;
            @media (prefers-reduced-motion) {
                --limel-3d-hover-effect-glow-opacity: 0.2;
            }
        }
    }
}

and of course the JS in 3d-tilt-hover-effect.ts was updated too:

        const glowPositionX = `
    ${center.x * GLOW_POSITION_MULTIPLIER + the3dElementBounds.width / CENTER_DIVISOR}px
`;
        const glowPositionY = `
    ${center.y * GLOW_POSITION_MULTIPLIER + the3dElementBounds.height / CENTER_DIVISOR}px
`;
        element.style.setProperty(
            '--limel-3d-hover-effect-glow-position-x',
            glowPositionX,
        );
        element.style.setProperty(
            '--limel-3d-hover-effect-glow-position-y',
            glowPositionY,
        );
    };

and

    const handleMouseLeave = () => {
        document.removeEventListener('mousemove', tiltCallback);
        element.style.removeProperty('--limel-3d-hover-effect-rotate3d');
        element.style.removeProperty('--limel-3d-hover-effect-glow-position-x');
        element.style.removeProperty('--limel-3d-hover-effect-glow-position-y');
    };

Why would this way be better?

Because animating the position and opacity of the gradient itself (the glow) would result in a nicer and smoother animation, when switching between hover and default states, as compared to animating the opacity of the whole thing. Today, only very trained eyes of "animators" would notice that the location of the gradient jumps, when switching between the hover and default (due to the opacity and 3D transitions). However, the more natural these transitions are, the better of course. That is why I wanted to animate them instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I've noticed there's a bit of a jump too.

But, can we put this PR on ice until cooldown? (Or if you can convince someone appropriate that I should spend cycle time on this, then I'm happy to help out and review further 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, all is done on this PR for now. And this can go to cooldown.

But now I don't know which cooldown board 😄, since we have now several cooldown boards 🙈

@adrianschmidt adrianschmidt self-assigned this Dec 20, 2024
@adrianschmidt adrianschmidt force-pushed the limel-3d-hover-effect-glow branch 2 times, most recently from fb1196e to 29cf173 Compare January 7, 2025 12:44
@adrianschmidt adrianschmidt requested a review from a team as a code owner January 7, 2025 12:44
@adrianschmidt adrianschmidt force-pushed the limel-3d-hover-effect-glow branch from 29cf173 to af9b62c Compare January 7, 2025 12:55
@adrianschmidt adrianschmidt enabled auto-merge (rebase) January 7, 2025 12:56
@adrianschmidt adrianschmidt merged commit 66674a2 into main Jan 7, 2025
12 checks passed
@adrianschmidt adrianschmidt deleted the limel-3d-hover-effect-glow branch January 7, 2025 12:58
@lime-opensource
Copy link
Collaborator

🎉 This PR is included in version 37.78.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released visual design Visual styling that may or may not affect usability 🦄✨ yolo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants