-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement OnyxColorSchemeMenuItem (#1465)
Implement `OnyxColorSchemeMenuItem` for easily letting the user choose light/dark/auto mode inside the user menu
- Loading branch information
1 parent
7f3332c
commit 90f9f86
Showing
20 changed files
with
197 additions
and
54 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 OnyxColorSchemeMenuItem |
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": patch | ||
--- | ||
|
||
fix(OnyxMenuItem): make whole button/anchor clickable |
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
Binary file added
BIN
+16.2 KB
...ts/components/OnyxColorSchemeMenuItem/Color-scheme-menu-item-chromium-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
+21.1 KB
...ots/components/OnyxColorSchemeMenuItem/Color-scheme-menu-item-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
+14 KB
...hots/components/OnyxColorSchemeMenuItem/Color-scheme-menu-item-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.
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
55 changes: 55 additions & 0 deletions
55
packages/sit-onyx/src/components/OnyxColorSchemeMenuItem/OnyxColorSchemeMenuItem.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,55 @@ | ||
import { expect, test } from "../../playwright/a11y"; | ||
import { executeMatrixScreenshotTest } from "../../playwright/screenshots"; | ||
import type { ColorSchemeValue } from "../OnyxColorSchemeDialog/types"; | ||
import OnyxColorSchemeMenuItem from "./OnyxColorSchemeMenuItem.vue"; | ||
|
||
test.describe("Screenshot tests", () => { | ||
executeMatrixScreenshotTest({ | ||
name: "Color scheme menu item", | ||
columns: ["default"], | ||
rows: ["default", "hover"], | ||
// TODO: remove when contrast issues are fixed in https://github.com/SchwarzIT/onyx/issues/410 | ||
disabledAccessibilityRules: ["color-contrast"], | ||
component: () => ( | ||
<ul style={{ listStyle: "none", padding: 0 }}> | ||
<OnyxColorSchemeMenuItem modelValue="auto" /> | ||
</ul> | ||
), | ||
beforeScreenshot: async (component, page, column, row) => { | ||
if (row === "hover") await component.getByText("Appearance: Auto").hover(); | ||
}, | ||
}); | ||
}); | ||
|
||
test("should behave correctly", async ({ page, mount }) => { | ||
const modelValueEvents: ColorSchemeValue[] = []; | ||
|
||
// ARRANGE | ||
const component = await mount(OnyxColorSchemeMenuItem, { | ||
props: { | ||
modelValue: "auto", | ||
}, | ||
on: { | ||
"update:modelValue": (value: ColorSchemeValue) => modelValueEvents.push(value), | ||
}, | ||
}); | ||
|
||
// ASSERT | ||
await expect(component).toContainText("Appearance: Auto"); | ||
|
||
// ACT | ||
await component.click(); | ||
|
||
// ASSERT | ||
const dialog = page.getByRole("dialog"); | ||
await expect(dialog).toBeVisible(); | ||
|
||
// ACT | ||
await dialog.getByRole("heading", { name: "Light" }).click(); | ||
await dialog.getByRole("button", { name: "Apply" }).click(); | ||
await component.update({ props: { modelValue: "light" } }); | ||
|
||
// ASSERT | ||
await expect(modelValueEvents).toStrictEqual(["light"]); | ||
await expect(component).toContainText("Appearance: Light"); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/sit-onyx/src/components/OnyxColorSchemeMenuItem/OnyxColorSchemeMenuItem.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,30 @@ | ||
import { defineStorybookActionsAndVModels } from "@sit-onyx/storybook-utils"; | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import OnyxColorSchemeMenuItem from "./OnyxColorSchemeMenuItem.vue"; | ||
|
||
/** | ||
* Pre-built menu item for the `OnyxUserMenu` that can be used inside the nav bar to | ||
* display the current color scheme to the user and allow changing it by displaying a `OnyxColorSchemeDialog`. | ||
*/ | ||
const meta: Meta<typeof OnyxColorSchemeMenuItem> = { | ||
title: "Navigation/modules/ColorSchemeMenuItem", | ||
...defineStorybookActionsAndVModels({ | ||
component: OnyxColorSchemeMenuItem, | ||
events: ["update:modelValue"], | ||
decorators: [ | ||
(story) => ({ | ||
components: { story }, | ||
template: `<div style="max-width: 16rem;"> <story /> </div>`, | ||
}), | ||
], | ||
}), | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof OnyxColorSchemeMenuItem>; | ||
|
||
export const Default = { | ||
args: { | ||
modelValue: "auto", | ||
}, | ||
} satisfies Story; |
60 changes: 60 additions & 0 deletions
60
packages/sit-onyx/src/components/OnyxColorSchemeMenuItem/OnyxColorSchemeMenuItem.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,60 @@ | ||
<script lang="ts" setup> | ||
import circleContrast from "@sit-onyx/icons/circle-contrast.svg?raw"; | ||
import { ref } from "vue"; | ||
import { injectI18n } from "../../i18n"; | ||
import OnyxColorSchemeDialog from "../OnyxColorSchemeDialog/OnyxColorSchemeDialog.vue"; | ||
import type { ColorSchemeValue } from "../OnyxColorSchemeDialog/types"; | ||
import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; | ||
import OnyxMenuItem from "../OnyxMenuItem/OnyxMenuItem.vue"; | ||
import type { OnyxColorSchemeMenuItemProps } from "./types"; | ||
const props = defineProps<OnyxColorSchemeMenuItemProps>(); | ||
const emit = defineEmits<{ | ||
"update:modelValue": [value: ColorSchemeValue]; | ||
}>(); | ||
const { t } = injectI18n(); | ||
const isOpen = ref(false); | ||
</script> | ||
|
||
<template> | ||
<OnyxMenuItem class="onyx-color-scheme-menu-item" @click="isOpen = true"> | ||
<OnyxIcon :icon="circleContrast" /> | ||
|
||
<div> | ||
{{ t("colorScheme.appearance") }}: | ||
<span class="onyx-color-scheme-menu-item__value"> | ||
{{ t(`colorScheme.${props.modelValue}.label`) }} | ||
</span> | ||
</div> | ||
|
||
<!-- the menu button renders a <li> and <button> so we need to teleport the dialog | ||
to not nest it inside the button --> | ||
<Teleport to="body"> | ||
<OnyxColorSchemeDialog | ||
:model-value="props.modelValue" | ||
:open="isOpen" | ||
@close="isOpen = false" | ||
@update:model-value="emit('update:modelValue', $event)" | ||
/> | ||
</Teleport> | ||
</OnyxMenuItem> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@use "../../styles/mixins/layers.scss"; | ||
.onyx-color-scheme-menu-item { | ||
@include layers.component() { | ||
&__value { | ||
color: var(--onyx-color-text-icons-neutral-soft); | ||
} | ||
.onyx-color-scheme-dialog { | ||
text-align: left; | ||
} | ||
} | ||
} | ||
</style> |
8 changes: 8 additions & 0 deletions
8
packages/sit-onyx/src/components/OnyxColorSchemeMenuItem/types.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,8 @@ | ||
import type { ColorSchemeValue } from "../OnyxColorSchemeDialog/types"; | ||
|
||
export type OnyxColorSchemeMenuItemProps = { | ||
/** | ||
* Currently active color scheme. | ||
*/ | ||
modelValue: ColorSchemeValue; | ||
}; |
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
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.