diff --git a/.changeset/fair-scissors-notice.md b/.changeset/fair-scissors-notice.md new file mode 100644 index 000000000..1627329e5 --- /dev/null +++ b/.changeset/fair-scissors-notice.md @@ -0,0 +1,5 @@ +--- +"sit-onyx": minor +--- + +feat: add `OnyxTag` component diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-chromium-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-chromium-linux.png new file mode 100644 index 000000000..d8a7060e6 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-chromium-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-firefox-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-firefox-linux.png new file mode 100644 index 000000000..db0bca51f Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-firefox-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-webkit-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-webkit-linux.png new file mode 100644 index 000000000..a1508e668 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-webkit-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--chromium-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--chromium-linux.png new file mode 100644 index 000000000..6281b6612 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--chromium-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--firefox-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--firefox-linux.png new file mode 100644 index 000000000..bd115fd59 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--firefox-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--webkit-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--webkit-linux.png new file mode 100644 index 000000000..6fd4859e8 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--webkit-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-chromium-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-chromium-linux.png new file mode 100644 index 000000000..8daff8eb5 Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-chromium-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-firefox-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-firefox-linux.png new file mode 100644 index 000000000..667017cbd Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-firefox-linux.png differ diff --git a/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-webkit-linux.png b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-webkit-linux.png new file mode 100644 index 000000000..3b5750e9f Binary files /dev/null and b/packages/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-webkit-linux.png differ diff --git a/packages/sit-onyx/src/components/OnyxTag/OnyxTag.ct.tsx b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.ct.tsx new file mode 100644 index 000000000..9ef1d0b01 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.ct.tsx @@ -0,0 +1,36 @@ +import { DENSITIES } from "../../composables/density"; +import { expect, test } from "../../playwright/a11y"; +import { executeMatrixScreenshotTest, mockPlaywrightIcon } from "../../playwright/screenshots"; +import { ONYX_COLORS } from "../../types/colors"; +import OnyxTag from "./OnyxTag.vue"; + +test.describe("Screenshot tests", () => { + executeMatrixScreenshotTest({ + name: "Tag", + columns: DENSITIES, + rows: ONYX_COLORS, + component: (column, row) => , + }); + + executeMatrixScreenshotTest({ + name: "Tag (with icon)", + columns: DENSITIES, + rows: ONYX_COLORS, + component: (column, row) => ( + + ), + }); +}); + +test("should truncate text", async ({ mount }) => { + const label = "Very long label that should be truncated"; + + // ARRANGE + const component = await mount(); + + // ASSERT + await expect(component).toContainText(label); + + // ASSERT + await expect(component).toHaveScreenshot("truncation.png"); +}); diff --git a/packages/sit-onyx/src/components/OnyxTag/OnyxTag.stories.ts b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.stories.ts new file mode 100644 index 000000000..70b0b7ce1 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.stories.ts @@ -0,0 +1,63 @@ +import check from "@sit-onyx/icons/check.svg?raw"; +import { defineStorybookActionsAndVModels } from "@sit-onyx/storybook-utils"; +import type { Meta, StoryObj } from "@storybook/vue3"; +import { + createIconSourceCodeTransformer, + createTruncationDecorator, + defineIconSelectArgType, +} from "../../utils/storybook"; +import OnyxTag from "./OnyxTag.vue"; + +/** + * Tags are succinct textual labels that provide single-worded information or hints to their related parent element. + */ +const meta: Meta = { + title: "components/Tag", + ...defineStorybookActionsAndVModels({ + component: OnyxTag, + events: [], + argTypes: { + icon: defineIconSelectArgType(), + }, + }), + parameters: { + docs: { + source: { + transform: createIconSourceCodeTransformer("icon"), + }, + }, + }, +}; + +export default meta; +type Story = StoryObj; + +/** + * This example shows the tag in primary color. + */ +export const Primary = { + args: { + label: "Tag", + }, +} satisfies Story; + +/** + * This example shows the tag with an icon. + */ +export const WithIcon = { + args: { + label: "Done", + icon: check, + color: "success", + }, +} satisfies Story; + +/** + * This example shows the tag with truncation. + */ +export const WithTruncation = { + args: { + label: "Tag with a very long text that gets truncated", + }, + decorators: createTruncationDecorator("10rem"), +} satisfies Story; diff --git a/packages/sit-onyx/src/components/OnyxTag/OnyxTag.vue b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.vue new file mode 100644 index 000000000..9fe799bb8 --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxTag/OnyxTag.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/packages/sit-onyx/src/components/OnyxTag/types.ts b/packages/sit-onyx/src/components/OnyxTag/types.ts new file mode 100644 index 000000000..054b1963c --- /dev/null +++ b/packages/sit-onyx/src/components/OnyxTag/types.ts @@ -0,0 +1,17 @@ +import type { DensityProp } from "../../composables/density"; +import type { OnyxColor } from "../../types/colors"; + +export type OnyxTagProps = DensityProp & { + /** + * The text content of the tag. + */ + label: string; + /** + * The color of the tag. + */ + color?: OnyxColor; + /** + * An icon which will be displayed on the left side of the label. + */ + icon?: string; +}; diff --git a/packages/sit-onyx/src/index.ts b/packages/sit-onyx/src/index.ts index dfcb5320c..89f4f2d36 100644 --- a/packages/sit-onyx/src/index.ts +++ b/packages/sit-onyx/src/index.ts @@ -57,6 +57,9 @@ export * from "./components/OnyxTable/types"; export { default as OnyxTooltip } from "./components/OnyxTooltip/OnyxTooltip.vue"; export * from "./components/OnyxTooltip/types"; +export { default as OnyxTag } from "./components/OnyxTag/OnyxTag.vue"; +export * from "./components/OnyxTag/types"; + export * from "./composables/density"; export * from "./composables/scrollEnd"; export type { OnyxTranslations, ProvideI18nOptions } from "./i18n";