-
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.
- Loading branch information
1 parent
7b9cba0
commit d845217
Showing
7 changed files
with
207 additions
and
51 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/sit-onyx/src/components/OnyxMore/OnyxMore.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,24 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import { h } from "vue"; | ||
import OnyxNavButton from "../OnyxNavBar/modules/OnyxNavButton/OnyxNavButton.vue"; | ||
import { NAV_BAR_BUTTONS_INJECTION_KEY } from "../OnyxNavBar/types"; | ||
import OnyxMore from "./OnyxMore.vue"; | ||
|
||
const meta: Meta<typeof OnyxMore> = { | ||
title: "Support/More", | ||
component: OnyxMore, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof OnyxMore>; | ||
|
||
export const Default = { | ||
args: { | ||
is: "div", | ||
injectionKey: NAV_BAR_BUTTONS_INJECTION_KEY, | ||
default: Array.from({ length: 24 }, (_, index) => | ||
h(OnyxNavButton, { label: `Element ${index + 1}` }), | ||
), | ||
more: ({ hiddenElements }) => h("div", `+${hiddenElements.value.length} more`), | ||
}, | ||
} 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,53 @@ | ||
<script lang="ts" setup> | ||
import { provide, reactive, ref, toRef, type Ref } from "vue"; | ||
import { useMore, type HTMLOrInstanceRef } from "../../composables/useMore"; | ||
import type { OnyxMoreProps } from "./types"; | ||
const props = defineProps<OnyxMoreProps>(); | ||
defineSlots<{ | ||
/** | ||
* List of components to render. Each child must implement the `useMoreChild()` composable. | ||
*/ | ||
default(): unknown; | ||
/** | ||
* Slot to display at the end if not all default slot elements fit in the available width. | ||
*/ | ||
more(props: typeof more): unknown; | ||
}>(); | ||
const parentRef = ref<HTMLOrInstanceRef>(); | ||
const componentRefs = reactive(new Map<string, Ref<HTMLOrInstanceRef>>()); | ||
const more = useMore({ | ||
parentRef, | ||
componentRefs, | ||
disabled: toRef(props, "disabled"), | ||
}); | ||
// eslint-disable-next-line vue/no-setup-props-reactivity-loss | ||
provide(props.injectionKey, { | ||
components: componentRefs, | ||
visibleComponents: more.visibleElements, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<component :is="props.is" ref="parentRef" class="onyx-more"> | ||
<slot></slot> | ||
<slot v-if="more.hiddenElements.value.length > 0" name="more" v-bind="more"></slot> | ||
</component> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@use "../../styles/mixins/layers.scss"; | ||
.onyx-more { | ||
@include layers.component() { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--onyx-spacing-4xs); | ||
overflow-x: clip; | ||
} | ||
} | ||
</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,18 @@ | ||
import type { MoreInjectionKey } from "../../composables/useMore"; | ||
|
||
export type OnyxMoreProps = { | ||
/** | ||
* Component to render (e.g. `<ul>` or `<div>`). | ||
*/ | ||
is: string; | ||
/** | ||
* Injection key to use. Must match the one used in the child components. | ||
* Will not be reactive so it must not be changed. | ||
*/ | ||
injectionKey: MoreInjectionKey; | ||
/** | ||
* Whether the intersection observer should be disabled (e.g. when more feature is currently not needed due to mobile layout). | ||
* Can increase performance. | ||
*/ | ||
disabled?: boolean; | ||
}; |
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.