Files
healthchat-web/packages/shared-components/src/room-list/RoomListSectionHeaderView/RoomListSectionHeaderView.stories.tsx
T
Florian Duros ee5d2609df Room list: add sections to shared components (#32735)
* feat: add section header

* refactor: remove index and role related to list box from RoomListItemView

* feat: add wrapper to RoomListItemView to handle different accessiblity pattern

* feat: add section support to VirtualizedRoomListView

* feat: add sections support to RoomListView

* test: add screenshot for sections header

* test: add/update screenshots for sections

* feat: force flat list on view model

This is an intermediary step before implementing sections in the vm. We
force the flat list but we use the underneath the view supporting
sections.

* test: update RoomListViewModel test

* test: fix breaking test

* chore: rename `getSectionViewModel` to `getSectionHeaderViewModel`

* chore: add missing `RoomListItemAccessibilityWrapper` export

* chore: merge `react` imports

* chore: simplify and add comment to `getItemKey` and `getHeaderKey`

* chore add comments to `getItemComponent` variants

* chore: fix typo in example doc
2026-03-16 16:40:12 +00:00

110 lines
2.8 KiB
TypeScript

/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import React, { type JSX } from "react";
import { fn } from "storybook/test";
import type { Meta, StoryObj } from "@storybook/react-vite";
import {
RoomListSectionHeaderView,
type RoomListSectionHeaderViewSnapshot,
type RoomListSectionHeaderActions,
type RoomListSectionHeaderViewProps,
} from "./RoomListSectionHeaderView";
import { useMockedViewModel } from "../../viewmodel";
import { withViewDocs } from "../../../.storybook/withViewDocs";
type RoomListSectionHeaderProps = RoomListSectionHeaderViewSnapshot &
RoomListSectionHeaderActions &
Omit<RoomListSectionHeaderViewProps, "vm">;
const RoomListSectionHeaderViewWrapperImpl = ({
onClick,
onFocus,
isFocused,
sectionIndex,
sectionCount,
indexInList,
roomCountInSection,
...rest
}: RoomListSectionHeaderProps): JSX.Element => {
const vm = useMockedViewModel(rest, { onClick });
return (
<RoomListSectionHeaderView
vm={vm}
onFocus={onFocus}
isFocused={isFocused}
sectionIndex={sectionIndex}
sectionCount={sectionCount}
indexInList={indexInList}
roomCountInSection={roomCountInSection}
/>
);
};
const RoomListSectionHeaderViewWrapper = withViewDocs(RoomListSectionHeaderViewWrapperImpl, RoomListSectionHeaderView);
const meta = {
title: "Room List/RoomListSectionHeaderView",
component: RoomListSectionHeaderViewWrapper,
tags: ["autodocs"],
args: {
id: "favourites",
title: "Favourites",
isExpanded: true,
isFocused: false,
onClick: fn(),
onFocus: fn(),
sectionIndex: 1,
sectionCount: 3,
roomCountInSection: 5,
indexInList: 3,
},
decorators: [
(Story) => (
<div role="treegrid" style={{ width: "320px" }}>
<Story />
</div>
),
],
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/design/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?node-id=10657-20703&p=f",
},
},
} satisfies Meta<typeof RoomListSectionHeaderViewWrapper>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {};
export const Collapsed: Story = {
args: {
isExpanded: false,
},
};
export const LongTitle: Story = {
args: {
title: "This is a very long title that should be truncated with an ellipsis",
},
};
export const FirstHeader: Story = {
args: {
sectionIndex: 0,
},
};
export const LastHeaderCollapsed: Story = {
args: {
isExpanded: false,
sectionIndex: 2,
},
};