-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add shimmer effect component
- Loading branch information
1 parent
d0f2eb1
commit 6abbbfd
Showing
12 changed files
with
288 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# b2b-shimmer | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| --------- | --------- | ------------------------------------------- | --------- | ----------- | | ||
| `height` | `height` | The height of the shimmer effect in px. | `number` | `undefined` | | ||
| `loading` | `loading` | Whether the shimmer effect is shown or not. | `boolean` | `undefined` | | ||
| `width` | `width` | The width of the shimmer effect im px. | `number` | `undefined` | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
15 changes: 15 additions & 0 deletions
15
packages/core-components/src/components/shimmer/shimmer.docs.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ArgsTable, PRIMARY_STORY, Primary, Meta } from '@storybook/blocks'; | ||
|
||
import * as ShimmerStories from './shimmer.stories'; | ||
|
||
<Meta of={ShimmerStories} /> | ||
|
||
# Shimmer | ||
|
||
The shimmer effect is an animated placeholder shown while the actual content is being loaded. | ||
|
||
## Attributes | ||
|
||
<ArgsTable story={PRIMARY_STORY} /> | ||
Changes made to the attributes in the above table will reflect in the example below: | ||
<Primary /> |
25 changes: 25 additions & 0 deletions
25
packages/core-components/src/components/shimmer/shimmer.e2e.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('B2B-Shimmer', () => { | ||
let page; | ||
beforeEach(async () => { | ||
page = await newE2EPage(); | ||
await page.setContent( | ||
'<b2b-shimmer loading="true" width="100" height="100"></b2b-shimmer>', | ||
); | ||
}); | ||
|
||
it('should render shimmer component', async () => { | ||
const element = await page.find('b2b-shimmer'); | ||
expect(element).toBeDefined(); | ||
}); | ||
|
||
it('should show slot content if loading is false', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<b2b-shimmer><h1>dummy content</h1></b2b-shimmer>'); | ||
|
||
const element = await page.find('h1'); | ||
|
||
expect(element).toEqualText('dummy content'); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/core-components/src/components/shimmer/shimmer.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@use '../../global/b2b-styles'; | ||
|
||
.b2b-shimmer { | ||
position: relative; | ||
overflow: hidden; | ||
border-radius: 3px; | ||
|
||
&::before { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: var(--b2b-color-grey-150); | ||
animation: b2b-shimmer 2s infinite; | ||
} | ||
} | ||
|
||
@keyframes b2b-shimmer { | ||
0%, | ||
100% { | ||
opacity: 1; | ||
} | ||
|
||
50% { | ||
opacity: 0.5; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/core-components/src/components/shimmer/shimmer.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { ShimmerComponent } from './shimmer'; | ||
import { h } from '@stencil/core'; | ||
|
||
describe('B2B-Shimmer', () => { | ||
async function renderPage(template) { | ||
return newSpecPage({ | ||
components: [ShimmerComponent], | ||
template: () => template, | ||
}); | ||
} | ||
|
||
it('should render shimmer effect with width 100 and height 100 attributes', async () => { | ||
const dummyContent = 'Dummy content'; | ||
const page = await renderPage( | ||
<b2b-shimmer loading={true} width={100} height={100}> | ||
{dummyContent} | ||
</b2b-shimmer>, | ||
); | ||
expect(page.root).toEqualHtml(` | ||
<b2b-shimmer> | ||
<mock:shadow-root> | ||
<div class="b2b-shimmer" style="width: 100px; height: 100px;"></div> | ||
</mock:shadow-root> | ||
${dummyContent} | ||
</b2b-shimmer> | ||
`); | ||
}); | ||
|
||
it('should show slot content and hide shimmer effect', async () => { | ||
const dummyContent = 'Dummy content'; | ||
const page = await renderPage( | ||
<b2b-shimmer loading={false} width={100} height={100}> | ||
{dummyContent} | ||
</b2b-shimmer>, | ||
); | ||
expect(page.root).toEqualHtml(` | ||
<b2b-shimmer> | ||
<mock:shadow-root> | ||
<slot></slot> | ||
</mock:shadow-root> | ||
${dummyContent} | ||
</b2b-shimmer> | ||
`); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/core-components/src/components/shimmer/shimmer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Meta, StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit-html'; | ||
import { getArgTypes } from '../../docs/config/utils'; | ||
|
||
type Story = StoryObj; | ||
|
||
const meta: Meta = { | ||
title: 'Components/Status & Feedback/Shimmer', | ||
component: 'b2b-shimmer', | ||
args: { | ||
loading: true, | ||
width: 400, | ||
height: 25, | ||
}, | ||
argTypes: { | ||
...getArgTypes('b2b-shimmer'), | ||
}, | ||
render: ({ ...args }) => html`<b2b-shimmer | ||
loading="${args.loading}" | ||
width="${args.width}" | ||
height="${args.height}"> | ||
This is the mean content which takes a while to load. | ||
</b2b-shimmer>`, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const story010Default: Story = { | ||
name: 'Default', | ||
args: { | ||
...meta.args, | ||
}, | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/core-components/src/components/shimmer/shimmer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component, Prop, h, Host } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'b2b-shimmer', | ||
styleUrl: 'shimmer.scss', | ||
shadow: true, | ||
}) | ||
export class ShimmerComponent { | ||
/** Whether the shimmer effect is shown or not. */ | ||
@Prop() loading: boolean; | ||
|
||
/** The width of the shimmer effect im px. */ | ||
@Prop() width: number; | ||
|
||
/** The height of the shimmer effect in px. */ | ||
@Prop() height: number; | ||
|
||
render() { | ||
const shimmerStyle = { | ||
width: `${this.width}px`, | ||
height: `${this.height}px`, | ||
}; | ||
|
||
return ( | ||
<Host> | ||
{this.loading ? ( | ||
<div class="b2b-shimmer" style={shimmerStyle} /> | ||
) : ( | ||
<slot /> | ||
)} | ||
</Host> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.