-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathReactionsRow.stories.tsx
More file actions
128 lines (110 loc) Ā· 3.51 KB
/
ReactionsRow.stories.tsx
File metadata and controls
128 lines (110 loc) Ā· 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* 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, type ReactNode } from "react";
import { fn } from "storybook/test";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { ReactionsRowButtonView } from "../ReactionsRowButton";
import { useMockedViewModel } from "../../../../../core/viewmodel";
import { withViewDocs } from "../../../../../../.storybook/withViewDocs";
import { ReactionsRowView, type ReactionsRowViewActions, type ReactionsRowViewSnapshot } from "./ReactionsRowView";
interface MockReactionButtonProps {
content: string;
count: number;
isSelected?: boolean;
}
const MockReactionButton = ({ content, count, isSelected }: Readonly<MockReactionButtonProps>): JSX.Element => {
const tooltipVm = useMockedViewModel(
{
formattedSenders: "Alice and Bob",
caption: undefined,
tooltipOpen: false,
},
{},
);
const vm = useMockedViewModel(
{
content,
count,
"isSelected": !!isSelected,
"isDisabled": false,
tooltipVm,
"aria-label": `${count} reactions for ${content}`,
},
{
onClick: fn(),
},
);
return <ReactionsRowButtonView vm={vm} />;
};
const DefaultReactionButtons = (): JSX.Element => (
<>
<MockReactionButton content="š" count={4} isSelected />
<MockReactionButton content="š" count={2} />
<MockReactionButton content="š" count={1} />
</>
);
type WrapperProps = ReactionsRowViewSnapshot & Partial<ReactionsRowViewActions>;
const ReactionsRowViewWrapperImpl = ({
onShowAllClick,
onAddReactionClick,
onAddReactionContextMenu,
children,
className,
...snapshotProps
}: WrapperProps & { children?: ReactNode; className?: string }): JSX.Element => {
const vm = useMockedViewModel(snapshotProps, {
onShowAllClick: onShowAllClick ?? fn(),
onAddReactionClick: onAddReactionClick ?? fn(),
onAddReactionContextMenu: onAddReactionContextMenu ?? fn(),
});
return (
<ReactionsRowView vm={vm} className={className}>
{children}
</ReactionsRowView>
);
};
const ReactionsRowViewWrapper = withViewDocs(ReactionsRowViewWrapperImpl, ReactionsRowView);
const meta = {
title: "Timeline/Timeline Reaction/ReactionsRow",
component: ReactionsRowViewWrapper,
tags: ["autodocs"],
args: {
ariaLabel: "Reactions",
isVisible: true,
children: <DefaultReactionButtons />,
showAllButtonVisible: false,
showAllButtonLabel: "Show all",
showAddReactionButton: true,
addReactionButtonLabel: "Add reaction",
addReactionButtonVisible: true,
addReactionButtonActive: false,
addReactionButtonDisabled: false,
},
} satisfies Meta<typeof ReactionsRowViewWrapper>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {};
export const WithShowAllButton: Story = {
args: {
showAllButtonVisible: true,
},
};
export const AddReactionButtonActive: Story = {
args: {
addReactionButtonActive: true,
},
};
export const AddReactionButtonHiddenUntilHover: Story = {
args: {
addReactionButtonVisible: false,
},
};
export const Hidden: Story = {
args: {
isVisible: false,
},
};