mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
@@ -129,7 +129,7 @@ Set a matching width and height to make a circle, square, or rounded avatar skel
|
||||
|
||||
<style>
|
||||
.skeleton-avatars wa-skeleton {
|
||||
display: inline-block;
|
||||
display: inline-flex;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
margin-right: 0.5rem;
|
||||
|
||||
12
src/components/skeleton/skeleton.css
vendored
12
src/components/skeleton/skeleton.css
vendored
@@ -1,14 +1,10 @@
|
||||
:host {
|
||||
--border-radius: var(--wa-border-radius-pill);
|
||||
--color: var(--wa-color-neutral-fill-normal);
|
||||
--sheen-color: color-mix(in oklab, var(--wa-color-neutral-fill-normal), var(--wa-color-surface-raised));
|
||||
--sheen-color: color-mix(in oklab, var(--color), var(--wa-color-surface-raised));
|
||||
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.skeleton {
|
||||
display: flex;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 1rem;
|
||||
@@ -20,13 +16,13 @@
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.skeleton--sheen .indicator {
|
||||
:host([effect='sheen']) .indicator {
|
||||
background: linear-gradient(270deg, var(--sheen-color), var(--color), var(--color), var(--sheen-color));
|
||||
background-size: 400% 100%;
|
||||
animation: sheen 8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.skeleton--pulse .indicator {
|
||||
:host([effect='pulse']) .indicator {
|
||||
animation: pulse 2s ease-in-out 0.5s infinite;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,27 +11,37 @@ describe('<wa-skeleton>', () => {
|
||||
|
||||
await expect(el).to.be.accessible();
|
||||
|
||||
const base = el.shadowRoot!.querySelector<HTMLElement>('[part~="base"]')!;
|
||||
const indicator = el.shadowRoot!.querySelector<HTMLElement>('[part~="indicator"]')!;
|
||||
|
||||
expect(base.getAttribute('class')).to.equal(' skeleton ');
|
||||
expect(el.getAttribute('effect')).to.equal(null);
|
||||
expect(indicator.getAttribute('class')).to.equal('indicator');
|
||||
});
|
||||
|
||||
it('should set pulse effect by attribute', async () => {
|
||||
const el = await fixture<WaSkeleton>(html` <wa-skeleton effect="none"></wa-skeleton> `);
|
||||
const indicator = el.shadowRoot!.querySelector<HTMLElement>('[part~="indicator"]')!;
|
||||
const cs = getComputedStyle(indicator);
|
||||
|
||||
expect(el.getAttribute('effect')).to.equal(null);
|
||||
expect(cs.animationName).to.equal('none');
|
||||
});
|
||||
|
||||
it('should set pulse effect by attribute', async () => {
|
||||
const el = await fixture<WaSkeleton>(html` <wa-skeleton effect="pulse"></wa-skeleton> `);
|
||||
const indicator = el.shadowRoot!.querySelector<HTMLElement>('[part~="indicator"]')!;
|
||||
const cs = getComputedStyle(indicator);
|
||||
|
||||
const base = el.shadowRoot!.querySelector<HTMLElement>('[part~="base"]')!;
|
||||
|
||||
expect(base.getAttribute('class')).to.equal(' skeleton skeleton--pulse ');
|
||||
expect(el.getAttribute('effect')).to.equal('pulse');
|
||||
expect(cs.animationName).to.equal('pulse');
|
||||
});
|
||||
|
||||
it('should set sheen effect by attribute', async () => {
|
||||
const el = await fixture<WaSkeleton>(html` <wa-skeleton effect="sheen"></wa-skeleton> `);
|
||||
const indicator = el.shadowRoot!.querySelector<HTMLElement>('[part~="indicator"]')!;
|
||||
const cs = getComputedStyle(indicator);
|
||||
|
||||
const base = el.shadowRoot!.querySelector<HTMLElement>('[part~="base"]')!;
|
||||
|
||||
expect(base.getAttribute('class')).to.equal(' skeleton skeleton--sheen ');
|
||||
expect(el.getAttribute('effect')).to.equal('sheen');
|
||||
expect(cs.animationName).to.equal('sheen');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { html } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import WebAwesomeElement from '../../internal/webawesome-element.js';
|
||||
import styles from './skeleton.css';
|
||||
|
||||
@@ -10,7 +9,6 @@ import styles from './skeleton.css';
|
||||
* @status stable
|
||||
* @since 2.0
|
||||
*
|
||||
* @csspart base - The component's base wrapper.
|
||||
* @csspart indicator - The skeleton's indicator which is responsible for its color and animation.
|
||||
*
|
||||
* @cssproperty --border-radius - The skeleton's border radius.
|
||||
@@ -22,21 +20,10 @@ export default class WaSkeleton extends WebAwesomeElement {
|
||||
static shadowStyle = styles;
|
||||
|
||||
/** Determines which effect the skeleton will use. */
|
||||
@property() effect: 'pulse' | 'sheen' | 'none' = 'none';
|
||||
@property({ reflect: true, default: 'none' }) effect: 'pulse' | 'sheen' | 'none' = 'none';
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<div
|
||||
part="base"
|
||||
class=${classMap({
|
||||
skeleton: true,
|
||||
'skeleton--pulse': this.effect === 'pulse',
|
||||
'skeleton--sheen': this.effect === 'sheen',
|
||||
})}
|
||||
>
|
||||
<div part="indicator" class="indicator"></div>
|
||||
</div>
|
||||
`;
|
||||
return html` <div part="indicator" class="indicator"></div> `;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user