-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
OnyxAlertDialog
component (#2329)
Relates to #2306 Implement `OnyxAlertDialog` component
- Loading branch information
1 parent
62ee690
commit b2a99a9
Showing
47 changed files
with
272 additions
and
2 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"sit-onyx": minor | ||
--- | ||
|
||
feat: implement `OnyxAlertDialog` component |
Binary file added
BIN
+15.5 KB
...x/playwright/snapshots/components/OnyxAlertDialog/breakpoint-2xs-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19 KB
...laywright/snapshots/components/OnyxAlertDialog/breakpoint-2xs-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.2 KB
...playwright/snapshots/components/OnyxAlertDialog/breakpoint-2xs-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.4 KB
...yx/playwright/snapshots/components/OnyxAlertDialog/breakpoint-sm-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+25.3 KB
...playwright/snapshots/components/OnyxAlertDialog/breakpoint-sm-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.9 KB
.../playwright/snapshots/components/OnyxAlertDialog/breakpoint-sm-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.5 KB
...yx/playwright/snapshots/components/OnyxAlertDialog/breakpoint-xs-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.2 KB
...playwright/snapshots/components/OnyxAlertDialog/breakpoint-xs-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.9 KB
.../playwright/snapshots/components/OnyxAlertDialog/breakpoint-xs-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+867 Bytes
(110%)
...t-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-2xs-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.07 KB
(110%)
...nyx/playwright/snapshots/components/OnyxDialog/breakpoint-2xs-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.03 KB
(120%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-2xs-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.21 KB
(120%)
...it-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-lg-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.71 KB
(120%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-lg-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.67 KB
(120%)
...-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-lg-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.12 KB
(120%)
...it-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-md-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.65 KB
(120%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-md-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.53 KB
(120%)
...-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-md-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+952 Bytes
(120%)
...it-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-sm-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.35 KB
(110%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-sm-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.14 KB
(120%)
...-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-sm-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.25 KB
(120%)
...it-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xl-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.94 KB
(120%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xl-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.64 KB
(120%)
...-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xl-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+921 Bytes
(120%)
...it-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xs-edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.42 KB
(120%)
...onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xs-firefox-linux.png
Oops, something went wrong.
Binary file modified
BIN
+1.07 KB
(120%)
...-onyx/playwright/snapshots/components/OnyxDialog/breakpoint-xs-webkit-linux.png
Oops, something went wrong.
Binary file modified
BIN
+545 Bytes
(120%)
...sit-onyx/playwright/snapshots/components/OnyxDialog/long-content-edge-linux.png
Oops, something went wrong.
Binary file modified
BIN
+129 Bytes
(100%)
...-onyx/playwright/snapshots/components/OnyxDialog/long-content-firefox-linux.png
Oops, something went wrong.
Binary file modified
BIN
+621 Bytes
(120%)
...t-onyx/playwright/snapshots/components/OnyxDialog/long-content-webkit-linux.png
Oops, something went wrong.
Binary file modified
BIN
+1.05 KB
(150%)
packages/sit-onyx/playwright/snapshots/components/OnyxDialog/modal-edge-linux.png
Oops, something went wrong.
Binary file modified
BIN
+1.89 KB
(160%)
...ges/sit-onyx/playwright/snapshots/components/OnyxDialog/modal-firefox-linux.png
Oops, something went wrong.
Binary file modified
BIN
+1.32 KB
(160%)
...ages/sit-onyx/playwright/snapshots/components/OnyxDialog/modal-webkit-linux.png
Oops, something went wrong.
Binary file modified
BIN
+4.01 KB
(100%)
...nts/OnyxNavBar/modules/OnyxColorSchemeDialog/Color-scheme-dialog-edge-linux.png
Oops, something went wrong.
Binary file modified
BIN
+6.43 KB
(100%)
.../OnyxNavBar/modules/OnyxColorSchemeDialog/Color-scheme-dialog-firefox-linux.png
Oops, something went wrong.
Binary file modified
BIN
+33.3 KB
(120%)
...s/OnyxNavBar/modules/OnyxColorSchemeDialog/Color-scheme-dialog-webkit-linux.png
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
packages/sit-onyx/src/components/OnyxAlertDialog/OnyxAlertDialog.ct.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,37 @@ | ||
import { ONYX_BREAKPOINTS } from "@sit-onyx/shared/breakpoints"; | ||
import { expect, test } from "../../playwright/a11y"; | ||
import TestWrapperCt from "./TestWrapper.ct.vue"; | ||
|
||
test.describe("Screenshot tests", () => { | ||
for (const breakpoint of ["2xs", "xs", "sm"] as const) { | ||
test(`Screenshot ${breakpoint}`, async ({ mount, makeAxeBuilder, page }) => { | ||
await page.setViewportSize({ width: ONYX_BREAKPOINTS[breakpoint] + 1, height: 256 }); | ||
|
||
// ARRANGE | ||
await mount(<TestWrapperCt />); | ||
|
||
// ASSERT | ||
await expect(page).toHaveScreenshot(`breakpoint-${breakpoint}.png`); | ||
|
||
// ACT | ||
const accessibilityScanResults = await makeAxeBuilder().analyze(); | ||
|
||
// ASSERT | ||
expect(accessibilityScanResults.violations).toEqual([]); | ||
}); | ||
} | ||
}); | ||
|
||
test("should behave correctly", async ({ mount }) => { | ||
let closeEventCount = 0; | ||
|
||
// ARRANGE | ||
const component = await mount(<TestWrapperCt onClose={() => closeEventCount++} />); | ||
const closeButton = component.getByRole("button", { name: "Close dialog" }); | ||
|
||
// ACT | ||
await closeButton.click(); | ||
|
||
// ASSERT | ||
expect(closeEventCount).toBe(1); | ||
}); |
55 changes: 55 additions & 0 deletions
55
packages/sit-onyx/src/components/OnyxAlertDialog/OnyxAlertDialog.stories.ts
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,55 @@ | ||
import circleAttention from "@sit-onyx/icons/circle-attention.svg?raw"; | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import { h, ref, watchEffect } from "vue"; | ||
import OnyxButton from "../OnyxButton/OnyxButton.vue"; | ||
import OnyxAlertDialog from "./OnyxAlertDialog.vue"; | ||
|
||
/** | ||
* The alert dialog is used to provide important information to the user. | ||
* Note that this dialog is an [alert dialog](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/). | ||
* It interrupts the user's workflow to communicate an important message and acquires a response, e.g. a delete confirmation. | ||
* | ||
* You can also implement a custom dialog using the [OnyxDialog](/docs/support-dialog--docs) component. | ||
*/ | ||
const meta: Meta<typeof OnyxAlertDialog> = { | ||
title: "Feedback/AlertDialog", | ||
component: OnyxAlertDialog, | ||
argTypes: { | ||
default: { control: { type: "text" } }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof OnyxAlertDialog>; | ||
|
||
export const Default = { | ||
args: { | ||
label: "Confirm deletion", | ||
default: | ||
"Are you sure that you want to delete the selected item? This action can not be reverted.", | ||
icon: { | ||
icon: circleAttention, | ||
color: "danger", | ||
}, | ||
actions: [ | ||
h(OnyxButton, { label: "Cancel", color: "neutral", mode: "plain", autofocus: true }), | ||
h(OnyxButton, { label: "Delete", color: "danger" }), | ||
], | ||
}, | ||
decorators: [ | ||
(story, ctx) => ({ | ||
components: { story, OnyxButton }, | ||
setup: () => { | ||
const isOpen = ref(false); | ||
watchEffect(() => { | ||
ctx.args.open = isOpen.value; | ||
}); | ||
return { isOpen }; | ||
}, | ||
template: `<div> | ||
<OnyxButton label="Show alert modal" @click="isOpen = true" /> | ||
<story :open="isOpen" @close="isOpen = false;" /> | ||
</div>`, | ||
}), | ||
], | ||
} satisfies Story; |
129 changes: 129 additions & 0 deletions
129
packages/sit-onyx/src/components/OnyxAlertDialog/OnyxAlertDialog.vue
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,129 @@ | ||
<script lang="ts" setup> | ||
import xSmall from "@sit-onyx/icons/x-small.svg?raw"; | ||
import { useDensity } from "../../composables/density"; | ||
import { injectI18n } from "../../i18n"; | ||
import OnyxDialog from "../OnyxDialog/OnyxDialog.vue"; | ||
import OnyxHeadline from "../OnyxHeadline/OnyxHeadline.vue"; | ||
import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; | ||
import OnyxSystemButton from "../OnyxSystemButton/OnyxSystemButton.vue"; | ||
import type { OnyxAlertDialogProps } from "./types"; | ||
const props = defineProps<OnyxAlertDialogProps>(); | ||
const emit = defineEmits<{ | ||
/** | ||
* Emitted when the dialog should be closed. | ||
*/ | ||
close: []; | ||
}>(); | ||
defineSlots<{ | ||
/** | ||
* Dialog content. | ||
*/ | ||
default(): unknown; | ||
/** | ||
* Optional slot to override the headline with custom content. | ||
*/ | ||
headline?(bindings: Pick<OnyxAlertDialogProps, "label">): unknown; | ||
/** | ||
* Slot to display custom actions at the bottom of the dialog, e.g. buttons for confirm or cancelling the current user workflow. | ||
* For accessibility purposes it is recommended to set autofocus on one button, preferably the "cancel" button if one exists. | ||
* | ||
* @example | ||
* ```vue | ||
* <OnyxButton label="Cancel" color="neutral" mode="plain" autofocus /> | ||
* ``` | ||
*/ | ||
actions?(): unknown; | ||
}>(); | ||
const { t } = injectI18n(); | ||
const { densityClass } = useDensity(props); | ||
</script> | ||
|
||
<template> | ||
<OnyxDialog | ||
:class="['onyx-alert-dialog', densityClass]" | ||
v-bind="props" | ||
modal | ||
alert | ||
@close="emit('close')" | ||
> | ||
<div class="onyx-alert-dialog__content"> | ||
<OnyxIcon v-if="props.icon" class="onyx-alert-dialog__icon" v-bind="props.icon" size="64px" /> | ||
|
||
<div> | ||
<div class="onyx-alert-dialog__headline"> | ||
<slot name="headline" :label="props.label"> | ||
<OnyxHeadline is="h2">{{ props.label }}</OnyxHeadline> | ||
</slot> | ||
|
||
<OnyxSystemButton | ||
class="onyx-alert-dialog__close" | ||
:label="t('dialog.close')" | ||
:icon="xSmall" | ||
@click="emit('close')" | ||
/> | ||
</div> | ||
|
||
<div class="onyx-alert-dialog__body onyx-truncation"> | ||
<slot></slot> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="onyx-alert-dialog__actions"> | ||
<slot name="actions"></slot> | ||
</div> | ||
</OnyxDialog> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@use "../../styles/mixins/layers.scss"; | ||
@use "../../styles/breakpoints.scss"; | ||
.onyx-alert-dialog { | ||
@include layers.component() { | ||
--max-width: 26rem; | ||
&__content { | ||
max-width: var(--max-width); | ||
display: flex; | ||
align-items: center; | ||
gap: var(--onyx-density-sm); | ||
} | ||
&__headline { | ||
display: flex; | ||
align-items: flex-start; | ||
justify-content: space-between; | ||
gap: var(--onyx-density-xs); | ||
} | ||
&__body { | ||
margin-top: var(--onyx-density-sm); | ||
white-space: pre-line; | ||
} | ||
&__actions { | ||
margin-top: var(--onyx-density-md); | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
gap: var(--onyx-density-xs); | ||
max-width: var(--max-width); | ||
} | ||
&__icon { | ||
@include breakpoints.screen(max, md) { | ||
--icon-size: 3rem; | ||
} | ||
@include breakpoints.screen(max, sm) { | ||
--icon-size: 2rem; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
25 changes: 25 additions & 0 deletions
25
packages/sit-onyx/src/components/OnyxAlertDialog/TestWrapper.ct.vue
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 @@ | ||
<script lang="ts" setup> | ||
import circleAttention from "@sit-onyx/icons/circle-attention.svg?raw"; | ||
import OnyxButton from "../OnyxButton/OnyxButton.vue"; | ||
import OnyxAlertDialog from "./OnyxAlertDialog.vue"; | ||
const emit = defineEmits<{ | ||
close: []; | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<OnyxAlertDialog | ||
label="Confirm deletion" | ||
:icon="{ icon: circleAttention, color: 'danger' }" | ||
open | ||
@close="emit('close')" | ||
> | ||
Are you sure that you want to delete the selected item? This action can not be reverted. | ||
|
||
<template #actions> | ||
<OnyxButton label="Cancel" color="neutral" autofocus /> | ||
<OnyxButton label="Delete" color="danger" /> | ||
</template> | ||
</OnyxAlertDialog> | ||
</template> |
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,9 @@ | ||
import type { OnyxDialogProps } from "../OnyxDialog/types"; | ||
import type { OnyxIconProps } from "../OnyxIcon/types"; | ||
|
||
export type OnyxAlertDialogProps = Omit<OnyxDialogProps, "modal" | "alert"> & { | ||
/** | ||
* Optional icon to show. | ||
*/ | ||
icon?: Omit<OnyxIconProps, "size">; | ||
}; |
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
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 |
---|---|---|
|
@@ -128,5 +128,8 @@ | |
}, | ||
"input": { | ||
"clear": "Eingabe löschen" | ||
}, | ||
"dialog": { | ||
"close": "Dialog schließen" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -137,5 +137,8 @@ | |
}, | ||
"input": { | ||
"clear": "Clear input" | ||
}, | ||
"dialog": { | ||
"close": "Close dialog" | ||
} | ||
} |
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