From 268a71acb01a2e5ecdbe8ff4422e6e2d5e30b80d Mon Sep 17 00:00:00 2001 From: Vendeville Antoine Date: Thu, 28 Sep 2023 09:49:04 +0200 Subject: [PATCH 1/5] feat(@vtmn/svelte): export vtmnalertitem --- .../VtmnAlert/VtmnAlert.stories.svelte | 33 +++++++++++++++++-- .../overlays/VtmnAlert/VtmnAlert.tsx | 8 ++++- .../sources/svelte/src/components/index.js | 1 + .../overlays/VtmnAlert/VtmnAlertItem.svelte | 32 +++++++++++++----- .../test/VtmnAlertItemWithSlots.test.svelte | 8 +++++ .../VtmnAlert/test/vtmnAlertItem.spec.js | 9 +++++ .../overlays/VtmnAlert/vtmnAlertStore.js | 10 +++++- .../overlays/VtmnAlert/VtmnAlert.vue | 5 ++- 8 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 packages/sources/svelte/src/components/overlays/VtmnAlert/test/VtmnAlertItemWithSlots.test.svelte diff --git a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte index 97d54b9a1..2ed1ee2dd 100644 --- a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte +++ b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte @@ -1,12 +1,17 @@ + + + Slot title + Slot description + diff --git a/packages/sources/svelte/src/components/overlays/VtmnAlert/test/vtmnAlertItem.spec.js b/packages/sources/svelte/src/components/overlays/VtmnAlert/test/vtmnAlertItem.spec.js index baced4cf8..031fd9f6d 100644 --- a/packages/sources/svelte/src/components/overlays/VtmnAlert/test/vtmnAlertItem.spec.js +++ b/packages/sources/svelte/src/components/overlays/VtmnAlert/test/vtmnAlertItem.spec.js @@ -1,6 +1,7 @@ import '@testing-library/jest-dom'; import { fireEvent, render, waitFor } from '@testing-library/svelte'; import VtmnAlertItem from '../VtmnAlertItem.svelte'; +import VtmnAlertItemWithSlot from './VtmnAlertItemWithSlots.test.svelte'; const timeout = 5000; @@ -138,6 +139,7 @@ describe('VtmnAlertItem', () => { const { getByLabelText } = render(VtmnAlertItem, { title: 'Alert unit-test', timeout, + ariaLabelButton: 'Close alert', withCloseButton: true, }); expect(getByLabelText('Close alert')).toBeVisible(); @@ -147,6 +149,7 @@ describe('VtmnAlertItem', () => { const { getByLabelText, component } = render(VtmnAlertItem, { title: 'Alert unit-test', timeout, + ariaLabelButton: 'Close alert', withCloseButton: true, }); await expectedCloseOnElement(getByLabelText('Close alert'), component, 1); @@ -165,4 +168,10 @@ describe('VtmnAlertItem', () => { timeout: 100, }); }); + + test('Should display the component with the slots', async () => { + const { getByText } = render(VtmnAlertItemWithSlot, {}); + expect(getByText('Slot title')).toBeVisible(); + expect(getByText('Slot description')).toBeVisible(); + }); }); diff --git a/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js b/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js index 111c1c141..ea48eeb9e 100644 --- a/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js +++ b/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js @@ -6,7 +6,14 @@ class VtmnAlertStore { this._alerts = writable([]); } - send({ variant, title, description, withCloseButton, ...attributes }) { + send({ + variant, + title, + description, + withCloseButton, + ariaLabelButton, + ...attributes + }) { this._alerts.update((state) => [ ...state, { @@ -15,6 +22,7 @@ class VtmnAlertStore { title, description, withCloseButton, + ariaLabelButton, id: `vtmn-alert-${uuid()}`, }, ]); diff --git a/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue b/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue index bf9395ed3..aa9b0aada 100644 --- a/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue +++ b/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue @@ -26,6 +26,9 @@ export default /*#__PURE__*/ defineComponent({ type: Boolean as PropType, default: false, }, + ariaLabelButton: { + type: String as PropType, + }, timeout: { type: Number as PropType, default: 8000, @@ -64,7 +67,7 @@ export default /*#__PURE__*/ defineComponent({ iconAlone="close-line" variant="ghost-reversed" size="small" - aria-label="close" + :aria-label="ariaLabelButton" @click.prevent="handleClose" /> From e32f25b392287bed1f04e2e60c37f141af1a409f Mon Sep 17 00:00:00 2001 From: Vendeville Antoine Date: Thu, 28 Sep 2023 09:56:03 +0200 Subject: [PATCH 2/5] feat(vtmnalert): rename aria-label --- .../components/overlays/VtmnAlert/VtmnAlert.stories.svelte | 6 +++--- .../react/src/components/overlays/VtmnAlert/VtmnAlert.tsx | 6 +++--- .../src/components/overlays/VtmnAlert/VtmnAlertItem.svelte | 4 ++-- .../overlays/VtmnAlert/test/vtmnAlertItem.spec.js | 4 ++-- .../src/components/overlays/VtmnAlert/vtmnAlertStore.js | 4 ++-- .../vue/src/components/overlays/VtmnAlert/VtmnAlert.vue | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte index 2ed1ee2dd..fc4c303eb 100644 --- a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte +++ b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte @@ -31,7 +31,7 @@ type: 'boolean', }, }, - ariaLabelButton: { + ariaLabelCloseButton: { type: { name: 'string', required: false }, description: 'Aria label displayed for the close button', control: { @@ -68,7 +68,7 @@ on:click={() => { vtmnAlertStore.send({ ...args, - ariaLabelButton: 'Close alert', + ariaLabelCloseButton: 'Close alert', 'aria-labelledby': 'Storybook', 'aria-describedby': args.variant, }); @@ -85,7 +85,7 @@ timeout: undefined, title: undefined, description: undefined, - ariaLabelButton: 'Close alert', + ariaLabelCloseButton: 'Close alert', }} let:args > diff --git a/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx b/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx index 878866729..f8790af9e 100644 --- a/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx +++ b/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx @@ -24,7 +24,7 @@ export interface VtmnAlertProps /** * Aria label applied on the close button */ - ariaLabelButton: string; + ariaLabelCloseButton: string; /** * The alert callback close function @@ -38,7 +38,7 @@ export const VtmnAlert = ({ title, message, onClose, - ariaLabelButton, + ariaLabelCloseButton, className, }: VtmnAlertProps) => { return ( @@ -60,7 +60,7 @@ export const VtmnAlert = ({ size="small" variant="ghost-reversed" iconAlone="close-line" - aria-label={ariaLabelButton} + aria-label={ariaLabelCloseButton} onClick={onClose} > )} diff --git a/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte b/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte index 681e89f05..00a08dbb5 100644 --- a/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte +++ b/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte @@ -35,7 +35,7 @@ /** * @type {string} aria label on the button */ - export let ariaLabelButton; + export let ariaLabelCloseButton; let className = undefined; /** @@ -68,7 +68,7 @@ {/if} {#if withCloseButton} { const { getByLabelText } = render(VtmnAlertItem, { title: 'Alert unit-test', timeout, - ariaLabelButton: 'Close alert', + ariaLabelCloseButton: 'Close alert', withCloseButton: true, }); expect(getByLabelText('Close alert')).toBeVisible(); @@ -149,7 +149,7 @@ describe('VtmnAlertItem', () => { const { getByLabelText, component } = render(VtmnAlertItem, { title: 'Alert unit-test', timeout, - ariaLabelButton: 'Close alert', + ariaLabelCloseButton: 'Close alert', withCloseButton: true, }); await expectedCloseOnElement(getByLabelText('Close alert'), component, 1); diff --git a/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js b/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js index ea48eeb9e..88aff878d 100644 --- a/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js +++ b/packages/sources/svelte/src/components/overlays/VtmnAlert/vtmnAlertStore.js @@ -11,7 +11,7 @@ class VtmnAlertStore { title, description, withCloseButton, - ariaLabelButton, + ariaLabelCloseButton, ...attributes }) { this._alerts.update((state) => [ @@ -22,7 +22,7 @@ class VtmnAlertStore { title, description, withCloseButton, - ariaLabelButton, + ariaLabelCloseButton, id: `vtmn-alert-${uuid()}`, }, ]); diff --git a/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue b/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue index aa9b0aada..683ffb2f8 100644 --- a/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue +++ b/packages/sources/vue/src/components/overlays/VtmnAlert/VtmnAlert.vue @@ -26,7 +26,7 @@ export default /*#__PURE__*/ defineComponent({ type: Boolean as PropType, default: false, }, - ariaLabelButton: { + ariaLabelCloseButton: { type: String as PropType, }, timeout: { @@ -67,7 +67,7 @@ export default /*#__PURE__*/ defineComponent({ iconAlone="close-line" variant="ghost-reversed" size="small" - :aria-label="ariaLabelButton" + :aria-label="ariaLabelCloseButton" @click.prevent="handleClose" /> From 0b20119545dc0327b317c62628c9263f792b7317 Mon Sep 17 00:00:00 2001 From: Vendeville Antoine Date: Thu, 28 Sep 2023 10:38:41 +0200 Subject: [PATCH 3/5] feat(vtmnalert): some clean --- .../overlays/VtmnAlert/VtmnAlert.stories.tsx | 11 +++++++++++ .../VtmnAlert/VtmnAlert.stories.svelte | 2 +- .../overlays/VtmnAlert/VtmnAlert.stories.js | 15 +++++++++++++++ .../overlays/VtmnAlert/VtmnAlert.tsx | 9 ++++++++- .../overlays/VtmnAlert/VtmnAlertItem.svelte | 18 +++++++++++++----- .../overlays/VtmnAlert/VtmnAlert.vue | 6 +++--- 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/packages/showcases/react/stories/components/overlays/VtmnAlert/VtmnAlert.stories.tsx b/packages/showcases/react/stories/components/overlays/VtmnAlert/VtmnAlert.stories.tsx index 5e08d0b5b..a4374154b 100644 --- a/packages/showcases/react/stories/components/overlays/VtmnAlert/VtmnAlert.stories.tsx +++ b/packages/showcases/react/stories/components/overlays/VtmnAlert/VtmnAlert.stories.tsx @@ -36,3 +36,14 @@ const OverviewTemplate: Story = (args) => { export const Overview = OverviewTemplate.bind({}); Overview.args = {}; + +const AlertItemTemplate: Story = (args) => { + return ( +
+ +
+ ); +}; + +export const AlertItem = AlertItemTemplate.bind({}); +AlertItem.args = {}; diff --git a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte index fc4c303eb..f6c14bbdf 100644 --- a/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte +++ b/packages/showcases/svelte/stories/components/overlays/VtmnAlert/VtmnAlert.stories.svelte @@ -82,9 +82,9 @@ ({ export const Overview = Template.bind({}); Overview.args = {}; + +const AlertItemTemplate = (args) => ({ + components: { VtmnAlert }, + setup() { + return { + args, + }; + }, + template: ``, +}); + +export const AlertItem = AlertItemTemplate.bind({}); +AlertItem.args = { + timeout: 0, +}; diff --git a/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx b/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx index f8790af9e..0cfba6023 100644 --- a/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx +++ b/packages/sources/react/src/components/overlays/VtmnAlert/VtmnAlert.tsx @@ -26,6 +26,12 @@ export interface VtmnAlertProps */ ariaLabelCloseButton: string; + /** + * time (ms) before the alert disappears + * Set to 0 to keep the alert visible + */ + timeout: number; + /** * The alert callback close function * @type {function} @@ -39,6 +45,7 @@ export const VtmnAlert = ({ message, onClose, ariaLabelCloseButton, + timeout = 8000, className, }: VtmnAlertProps) => { return ( @@ -48,7 +55,7 @@ export const VtmnAlert = ({ className={clsx( 'vtmn-alert', `vtmn-alert_variant--${variant}`, - 'show', + timeout > 0 && 'show', className, )} > diff --git a/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte b/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte index 00a08dbb5..5d1c79862 100644 --- a/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte +++ b/packages/sources/svelte/src/components/overlays/VtmnAlert/VtmnAlertItem.svelte @@ -3,6 +3,12 @@ import { createEventDispatcher, onDestroy, onMount } from 'svelte'; import { cn } from '../../../utils/classnames'; import { VTMN_ALERT_VARIANT } from './enums'; + import { uuid } from '../../../utils/math'; + + /** + * @type {string} unique id suffix for the component + */ + export let id = uuid(); /** * @type {'info'|'success'|'danger'|'warning'} variant of the alert @@ -29,8 +35,10 @@ /** * @type {number} time (ms) before the alert disappears + * Can't be above 8000ms. + * Set to 0 to keep the alert visible */ - export let timeout = undefined; + export let timeout = 8000; /** * @type {string} aria label on the button @@ -52,7 +60,7 @@ onMount(_setTimeout); $: componentClass = cn( 'vtmn-alert', - timeout && 'show', + timeout > 0 && 'show', variant && `vtmn-alert_variant--${variant}`, className, ); @@ -60,7 +68,7 @@