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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions etc/lime-elements.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export interface ColumnSorter {
//
// @public (undocumented)
export namespace Components {
export interface Limel3dHoverEffectGlow {
}
export interface LimelActionBar {
"accessibleLabel"?: string;
"actions": Array<ActionBarItem | ListSeparator>;
Expand Down Expand Up @@ -981,6 +983,8 @@ export type InputType = 'date' | 'datetime-local' | 'email' | 'month' | 'number'
namespace JSX_2 {
// (undocumented)
interface IntrinsicElements {
// (undocumented)
"limel-3d-hover-effect-glow": Limel3dHoverEffectGlow;
// (undocumented)
"limel-action-bar": LimelActionBar;
// (undocumented)
Expand Down Expand Up @@ -1132,6 +1136,8 @@ namespace JSX_2 {
// (undocumented)
"limel-tooltip-content": LimelTooltipContent;
}
interface Limel3dHoverEffectGlow {
}
interface LimelActionBar {
"accessibleLabel"?: string;
"actions"?: Array<ActionBarItem | ListSeparator>;
Expand Down
28 changes: 28 additions & 0 deletions src/components/3d-hover-effect-glow/3d-hover-effect-glow.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
:host(limel-3d-hover-effect-glow) {
display: block;
pointer-events: none;

position: absolute;
inset: 0;

mix-blend-mode: plus-lighter;
}

div {
position: absolute;
inset: 0;

transition: background, opacity;
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

border-radius: inherit;

opacity: var(--limel-3d-hover-effect-glow-opacity, 0.1);

background-image: radial-gradient(
circle at var(--limel-3d-hover-effect-glow-position, 50% -20%),
rgb(var(--color-white), 0.3),
rgb(var(--color-white), 0)
);
}
26 changes: 26 additions & 0 deletions src/components/3d-hover-effect-glow/3d-hover-effect-glow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, h } from '@stencil/core';
/**
* This component enhances the visual effects, when the `tiltFollowingTheCursor`
* utility function from `3d-tilt-hover-effect.ts` is implemented in a component.
*
* This component should be added to the HTML structure of the consumer component.
*
* This component carries its own styles which are needed to create a glow effect on the
* 3D element within the parent element, when the parent is hovered.
*
* The parent element must be using the `tiltFollowingTheCursor` utility function
* imported from `3d-tilt-hover-effect.ts`. This function will dynamically
* affect parts of the styles of this 3D glow effect.
*
* @private
*/
@Component({
tag: 'limel-3d-hover-effect-glow',
shadow: true,
styleUrl: '3d-hover-effect-glow.scss',
})
export class HoverEffectGlowComponent {
public render() {
return <div />;
}
}
7 changes: 3 additions & 4 deletions src/components/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ limel-action-bar {
}

// The 3D effect
@include mixins.limel-3d-hover-effect-glow(
section,
var(--card-border-radius, $default-border-radius)
);
limel-3d-hover-effect-glow {
border-radius: var(--card-border-radius, $default-border-radius);
}

:host(limel-card) {
@include mixins.parent-of-the-3d-element;
Expand Down
2 changes: 1 addition & 1 deletion src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Card {
{this.renderValue()}
{this.renderActionBar()}
</div>
<div class="limel-3d-hover-effect-glow" />
<limel-3d-hover-effect-glow />
</section>
</Host>
);
Expand Down
7 changes: 3 additions & 4 deletions src/components/info-tile/info-tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,9 @@ $l: 62.5rem; //1000px
}

// The 3D effect
@include mixins.limel-3d-hover-effect-glow(
a,
var(--info-tile-border-radius, 1rem)
);
limel-3d-hover-effect-glow {
border-radius: var(--info-tile-border-radius, 1rem);
}

:host(limel-info-tile) {
@include mixins.parent-of-the-3d-element;
Expand Down
2 changes: 1 addition & 1 deletion src/components/info-tile/info-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class InfoTile {
{this.renderLabel()}
</a>
{this.renderNotification()}
<div class="limel-3d-hover-effect-glow" />
<limel-3d-hover-effect-glow />
</Host>
);
}
Expand Down
30 changes: 19 additions & 11 deletions src/components/shortcut/shortcut.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,17 @@

a {
all: unset;
@include mixins.is-elevated-clickable(
$background-color: var(
--shortcut-background-color,
var(--lime-elevated-surface-background-color)
),
$background-color--hovered: var(
--shortcut-background-color,
var(--lime-elevated-surface-background-color)
)
);
@include mixins.visualize-keyboard-focus;
text-align: center;

height: calc(100% - 1rem);
width: calc(100% - 1rem);
padding: 0.5rem;

border-radius: var(--shortcut-border-radius, 1rem);
background-color: var(
--shortcut-background-color,
var(--lime-elevated-surface-background-color)
);
}

limel-icon {
Expand All @@ -82,3 +75,18 @@ limel-badge {
top: -0.25rem;
right: 0.125rem;
}

// The 3D effect
limel-3d-hover-effect-glow {
border-radius: var(--shortcut-border-radius, 1rem);
}

:host(limel-shortcut) {
@include mixins.parent-of-the-3d-element;
}

a {
@include mixins.the-3d-element;

@include mixins.the-3d-element--clickable;
}
49 changes: 35 additions & 14 deletions src/components/shortcut/shortcut.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Prop, h } from '@stencil/core';
import { Component, Prop, h, Element, Host } from '@stencil/core';
import { Link } from '../../global/shared-types/link.types';
import { getMouseEventHandlers } from '../../util/3d-tilt-hover-effect';

/**
* This component can be used on places such as a start page or a dashboard.
Expand Down Expand Up @@ -53,21 +54,41 @@ export class Shortcut {
@Prop()
public link?: Link;

@Element()
private host: HTMLElement;

private handleMouseEnter: () => void;
private handleMouseLeave: () => void;

public componentWillLoad() {
const { handleMouseEnter, handleMouseLeave } = getMouseEventHandlers(
this.host,
);
this.handleMouseEnter = handleMouseEnter;
this.handleMouseLeave = handleMouseLeave;
}

public render() {
return [
<a
aria-disabled={this.disabled}
href={this.link?.href}
target={this.link?.target}
tabindex="0"
aria-label={this.getAriaLabel()}
title={this.link?.title}
return (
<Host
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
>
<limel-icon name={this.icon} />
</a>,
this.renderLabel(),
this.renderNotification(),
];
<a
aria-disabled={this.disabled}
href={this.link?.href}
target={this.link?.target}
tabindex="0"
aria-label={this.getAriaLabel()}
title={this.link?.title}
>
<limel-icon name={this.icon} />
<limel-3d-hover-effect-glow />
</a>
{this.renderLabel()}
{this.renderNotification()}
</Host>
);
}

private renderLabel = () => {
Expand Down
45 changes: 9 additions & 36 deletions src/style/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -457,42 +457,6 @@ $clickable-normal-state-transitions: (
white-space: nowrap;
}

// This mixin designed to enhance the visual effects,
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
// is implemented in a component.
// This adds styles to a `<div class"limel-3d-hover-effect-glow" />`, needed to create
// a glow effect on a 3D element when the parent element is hovered.
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
// Parts of these styles are controlled by the `titleFollowingTheCursor` function.
@mixin limel-3d-hover-effect-glow($the3dElement, $border-radius) {
.limel-3d-hover-effect-glow {
transition:
background 0.4s ease,
opacity 0.4s ease;
pointer-events: none;

position: absolute;
inset: 0;
border-radius: $border-radius;

opacity: 0.1;
#{$the3dElement}:hover & {
opacity: 0.5;
@media (prefers-reduced-motion) {
opacity: 0.2;
}
}

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

mix-blend-mode: plus-lighter;
}
}

// These mixins below are designed to apply the necessary visual effects,
// when the `tiltFollowingTheCursor` utility function from `3d-tilt-hover-effect.ts`
// is implemented in a component.
Expand Down Expand Up @@ -545,6 +509,15 @@ $clickable-normal-state-transitions: (
outline: none;
transform: scale3d(1.01, 1.01, 1.01);
}

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

@mixin the-3d-element--clickable {
Expand Down
6 changes: 1 addition & 5 deletions src/util/3d-tilt-hover-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@
* @include the-3d-element--clickable;
* ```
* - **For the glow effect**:
* Add a `<div class="limel-3d-hover-effect-glow" />` inside "the-3d-element",
* and use the following SCSS mixin:
* ```scss
* @include limel-3d-hover-effect-glow($selector, $border-radius);
* ```
* Add a `<limel-3d-hover-effect-glow />` inside "the-3d-element".
*
* 3. **Initialize in your component**:
*
Expand Down
Loading