Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OnyxDataGrid): Render icons in flyout #2322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import bus from "@sit-onyx/icons/bus.svg?raw";
import carCheck from "@sit-onyx/icons/car-check.svg?raw";
import sort from "@sit-onyx/icons/sort.svg?raw";
import walking from "@sit-onyx/icons/walking.svg?raw";
import type { Meta, StoryObj } from "@storybook/vue3";
import { h } from "vue";
import OnyxListItem from "../OnyxListItem/OnyxListItem.vue";
Expand Down Expand Up @@ -36,27 +39,52 @@ export const HeaderInteractions = {
name: Symbol("More actions"),
watch: [],
header: {
actions: () => [
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: sort,
color: "medium",
}),
listItems: [
h(OnyxListItem, () => "Pin column"),
h(OnyxListItem, () => "Unpin column"),
],
},
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: sort,
color: "medium",
}),
listItems: [h(OnyxListItem, () => "Remove column")],
},
],
actions: (column) =>
column !== "name"
? [
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: sort,
color: "medium",
}),
listItems: [
h(OnyxListItem, () => "Pin column"),
h(OnyxListItem, () => "Unpin column"),
],
},
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: sort,
color: "medium",
}),
listItems: [h(OnyxListItem, () => "Remove column")],
},
]
: [
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: walking,
color: "soft",
}),
},
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: carCheck,
color: "soft",
}),
},
{
iconComponent: h(OnyxSystemButton, {
label: "Column options",
icon: bus,
color: "soft",
}),
},
],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const slots = defineSlots<{

&__actions {
display: inline-flex;

.onyx-flyout-menu__list {
min-width: auto;
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ export const useDataGridFeatures = <

return columns.map((column) => {
const actions = headerActions.flatMap((actionFactory) => actionFactory(column));
const iconComponent = actions.map(({ iconComponent }) => iconComponent);

if (actions.length > 1) {
const { t } = injectI18n();
const listItems = headerActions
.flatMap((actionFactory) => actionFactory(column))
.map(({ listItems }) => listItems);
const listItems = actions.map(({ listItems }) => listItems).filter((item) => !!item);

const options =
listItems.length > 0
? listItems
: iconComponent.map((icon) => h(OnyxListItem, () => icon));

const flyoutMenu = h(
OnyxFlyoutMenu,
Expand All @@ -144,7 +148,7 @@ export const useDataGridFeatures = <
icon: moreHorizontal,
...trigger,
}),
options: () => listItems,
options: () => options,
} satisfies ComponentSlots<typeof OnyxFlyoutMenu>,
);

Expand All @@ -155,10 +159,6 @@ export const useDataGridFeatures = <
};
}

const iconComponent = headerActions
.flatMap((actionFactory) => actionFactory(column))
.map(({ iconComponent }) => iconComponent);

return {
key: column,
component: () => h(HeaderCell, { label: String(column) }, { actions: () => iconComponent }),
Expand Down
Loading