From c048ef52a35a8a60a6c76462586044a1220806e1 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Thu, 14 Nov 2024 15:09:20 +0200 Subject: [PATCH] refactor: extract avatar-group styles into reusable css literal (#8146) --- .../src/vaadin-avatar-group-styles.d.ts | 8 +++ .../src/vaadin-avatar-group-styles.js | 51 +++++++++++++++++++ .../avatar-group/src/vaadin-avatar-group.js | 51 ++----------------- 3 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 packages/avatar-group/src/vaadin-avatar-group-styles.d.ts create mode 100644 packages/avatar-group/src/vaadin-avatar-group-styles.js diff --git a/packages/avatar-group/src/vaadin-avatar-group-styles.d.ts b/packages/avatar-group/src/vaadin-avatar-group-styles.d.ts new file mode 100644 index 0000000000..2f2905c003 --- /dev/null +++ b/packages/avatar-group/src/vaadin-avatar-group-styles.d.ts @@ -0,0 +1,8 @@ +/** + * @license + * Copyright (c) 2020 - 2024 Vaadin Ltd. + * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ + */ +import type { CSSResult } from 'lit'; + +export const avatarGroupStyles: CSSResult; diff --git a/packages/avatar-group/src/vaadin-avatar-group-styles.js b/packages/avatar-group/src/vaadin-avatar-group-styles.js new file mode 100644 index 0000000000..6048c47b08 --- /dev/null +++ b/packages/avatar-group/src/vaadin-avatar-group-styles.js @@ -0,0 +1,51 @@ +/** + * @license + * Copyright (c) 2020 - 2024 Vaadin Ltd. + * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ + */ +import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; + +export const avatarGroupStyles = css` + :host { + display: block; + width: 100%; /* prevent collapsing inside non-stretching column flex */ + --vaadin-avatar-group-overlap: 8px; + --vaadin-avatar-group-overlap-border: 2px; + } + + :host([hidden]) { + display: none !important; + } + + [part='container'] { + display: flex; + position: relative; + width: 100%; + flex-wrap: nowrap; + } + + ::slotted(vaadin-avatar:not(:first-child)) { + -webkit-mask-image: url('data:image/svg+xml;utf8,'); + mask-image: url('data:image/svg+xml;utf8,'); + -webkit-mask-size: calc( + 300% + var(--vaadin-avatar-group-overlap-border) * 6 - var(--vaadin-avatar-outline-width) * 6 + ); + mask-size: calc(300% + var(--vaadin-avatar-group-overlap-border) * 6 - var(--vaadin-avatar-outline-width) * 6); + } + + ::slotted(vaadin-avatar:not([dir='rtl']):not(:first-child)) { + margin-left: calc(var(--vaadin-avatar-group-overlap) * -1 - var(--vaadin-avatar-outline-width)); + -webkit-mask-position: calc(50% - var(--vaadin-avatar-size) + var(--vaadin-avatar-group-overlap)); + mask-position: calc(50% - var(--vaadin-avatar-size) + var(--vaadin-avatar-group-overlap)); + } + + ::slotted(vaadin-avatar[dir='rtl']:not(:first-child)) { + margin-right: calc(var(--vaadin-avatar-group-overlap) * -1); + -webkit-mask-position: calc( + 50% + var(--vaadin-avatar-size) - var(--vaadin-avatar-group-overlap) + var(--vaadin-avatar-outline-width) + ); + mask-position: calc( + 50% + var(--vaadin-avatar-size) - var(--vaadin-avatar-group-overlap) + var(--vaadin-avatar-outline-width) + ); + } +`; diff --git a/packages/avatar-group/src/vaadin-avatar-group.js b/packages/avatar-group/src/vaadin-avatar-group.js index 64b0c88bdb..87ae725cec 100644 --- a/packages/avatar-group/src/vaadin-avatar-group.js +++ b/packages/avatar-group/src/vaadin-avatar-group.js @@ -19,7 +19,10 @@ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js'; import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js'; import { SlotController } from '@vaadin/component-base/src/slot-controller.js'; -import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; +import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; +import { avatarGroupStyles } from './vaadin-avatar-group-styles.js'; + +registerStyles('vaadin-avatar-group', avatarGroupStyles, { moduleId: 'vaadin-avatar-group-styles' }); const MINIMUM_DISPLAYED_AVATARS = 2; @@ -74,52 +77,6 @@ const MINIMUM_DISPLAYED_AVATARS = 2; class AvatarGroup extends ResizeMixin(OverlayClassMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerElement))))) { static get template() { return legacyHtml` -