-
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.
Relates to #566 Add `OnyxTag` component --------- Co-authored-by: nerdrun <[email protected]>
- Loading branch information
1 parent
53ac6e0
commit 288afbd
Showing
15 changed files
with
191 additions
and
0 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: add `OnyxTag` component |
Binary file added
BIN
+29 KB
packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-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
+41.7 KB
packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-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
+33.1 KB
packages/sit-onyx/playwright/snapshots/components/OnyxTag/Tag-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
+35 KB
...-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--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
+51.1 KB
...t-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--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
+44.4 KB
...it-onyx/playwright/snapshots/components/OnyxTag/Tag-with-icon--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
+2.28 KB
.../sit-onyx/playwright/snapshots/components/OnyxTag/truncation-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
+2.42 KB
...s/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-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
+1.91 KB
...es/sit-onyx/playwright/snapshots/components/OnyxTag/truncation-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) => <OnyxTag label="Tag" density={column} color={row} />, | ||
}); | ||
|
||
executeMatrixScreenshotTest({ | ||
name: "Tag (with icon)", | ||
columns: DENSITIES, | ||
rows: ONYX_COLORS, | ||
component: (column, row) => ( | ||
<OnyxTag label="Tag" density={column} color={row} icon={mockPlaywrightIcon} /> | ||
), | ||
}); | ||
}); | ||
|
||
test("should truncate text", async ({ mount }) => { | ||
const label = "Very long label that should be truncated"; | ||
|
||
// ARRANGE | ||
const component = await mount(<OnyxTag label={label} style="max-width: 8rem;" />); | ||
|
||
// ASSERT | ||
await expect(component).toContainText(label); | ||
|
||
// ASSERT | ||
await expect(component).toHaveScreenshot("truncation.png"); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/sit-onyx/src/components/OnyxTag/OnyxTag.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,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<typeof OnyxTag> = { | ||
title: "components/Tag", | ||
...defineStorybookActionsAndVModels({ | ||
component: OnyxTag, | ||
events: [], | ||
argTypes: { | ||
icon: defineIconSelectArgType(), | ||
}, | ||
}), | ||
parameters: { | ||
docs: { | ||
source: { | ||
transform: createIconSourceCodeTransformer("icon"), | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof OnyxTag>; | ||
|
||
/** | ||
* 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; |
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,67 @@ | ||
<script lang="ts" setup> | ||
import { useDensity } from "../../composables/density"; | ||
import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; | ||
import type { OnyxTagProps } from "./types"; | ||
const props = withDefaults(defineProps<OnyxTagProps>(), { | ||
color: "primary", | ||
}); | ||
const { densityClass } = useDensity(props); | ||
</script> | ||
|
||
<template> | ||
<div :class="['onyx-tag', `onyx-tag--${props.color}`, densityClass]"> | ||
<OnyxIcon v-if="props.icon" :icon="props.icon" size="16px" /> | ||
<span class="onyx-text onyx-truncation-ellipsis">{{ props.label }}</span> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@use "../../styles/mixins/density.scss"; | ||
@use "../../styles/mixins/layers.scss"; | ||
.onyx-tag { | ||
@include density.compact { | ||
--onyx-tag-padding: 0 var(--onyx-spacing-3xs); | ||
} | ||
@include density.default { | ||
--onyx-tag-padding: var(--onyx-spacing-5xs) var(--onyx-spacing-2xs); | ||
} | ||
@include density.cozy { | ||
--onyx-tag-padding: var(--onyx-spacing-4xs) var(--onyx-spacing-xs); | ||
} | ||
@include layers.component() { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: var(--onyx-spacing-3xs); | ||
max-width: 100%; | ||
padding: var(--onyx-tag-padding); | ||
border-radius: var(--onyx-radius-sm); | ||
font-family: var(--onyx-font-family); | ||
color: var(--onyx-tag-color); | ||
border: var(--onyx-1px-in-rem) solid var(--onyx-tag-border-color); | ||
background-color: var(--onyx-tag-background-color); | ||
$colors: primary, secondary, neutral, danger, warning, success, info; | ||
@each $color in $colors { | ||
&--#{$color} { | ||
--onyx-tag-background-color: var(--onyx-color-base-#{$color}-200); | ||
--onyx-tag-border-color: var(--onyx-color-base-#{$color}-600); | ||
@if $color == "neutral" { | ||
// neutral does not have a bold color so we need to use medium here | ||
--onyx-tag-color: var(--onyx-color-text-icons-neutral-medium); | ||
} @else { | ||
--onyx-tag-color: var(--onyx-color-text-icons-#{$color}-bold); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</style> |
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,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; | ||
}; |
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