forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecorators.tsx
More file actions
88 lines (77 loc) · 3.03 KB
/
decorators.tsx
File metadata and controls
88 lines (77 loc) · 3.03 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
import { ClusterProvider } from '@providers/cluster';
import { TransactionsProvider } from '@providers/transactions';
import type { Decorator, Parameters } from '@storybook/react';
import React from 'react';
import { fn } from 'storybook/test';
import { MockAccountsProvider } from './__mocks__/MockAccountsProvider';
import { MockTokenInfoBatchProvider } from './__mocks__/MockTokenInfoBatchProvider';
/** Wraps stories with ClusterProvider. Usage: `decorators: [withCluster]` */
export const withCluster: Decorator = Story => (
<ClusterProvider>
<Story />
</ClusterProvider>
);
/** Wraps stories with ClusterProvider and MockAccountsProvider. Usage: `decorators: [withClusterAndAccounts]` */
export const withClusterAndAccounts: Decorator = Story => (
<ClusterProvider>
<MockAccountsProvider>
<Story />
</MockAccountsProvider>
</ClusterProvider>
);
/** Decorator for card table field components. Usage: `decorators: [withCardTableField]` */
export const withCardTableField: Decorator = Story => (
<ClusterProvider>
<MockAccountsProvider>
<div className="card">
<div className="table-responsive mb-0">
<style>{`.card-table tbody tr:first-child td { border-top: none !important; }`}</style>
<table className="table table-sm table-nowrap card-table">
<tbody>
<Story />
</tbody>
</table>
</div>
</div>
</MockAccountsProvider>
</ClusterProvider>
);
/** Wraps stories with ClusterProvider, TransactionsProvider, and MockAccountsProvider. Usage: `decorators: [withTransactions]` */
export const withTransactions: Decorator = Story => (
<ClusterProvider>
<TransactionsProvider>
<MockAccountsProvider>
<Story />
</MockAccountsProvider>
</TransactionsProvider>
</ClusterProvider>
);
/** Wraps stories with MockTokenInfoBatchProvider. Usage: `decorators: [withTokenInfoBatch]` */
export const withTokenInfoBatch: Decorator = Story => (
<MockTokenInfoBatchProvider>
<Story />
</MockTokenInfoBatchProvider>
);
type NextjsNavigationOptions = {
pathname?: string;
query?: Record<string, string>;
};
/** Creates parameters for components using Next.js navigation */
export const createNextjsParameters = (options?: NextjsNavigationOptions): Parameters => ({
nextjs: {
appDirectory: true,
navigation: {
pathname: options?.pathname ?? '/',
query: options?.query ?? {},
},
},
});
export const nextjsParameters: Parameters = createNextjsParameters();
/** Mocks navigator.clipboard.writeText for stories that copy text. Usage: `decorators: [withClipboardMock]` */
export const withClipboardMock: Decorator = Story => {
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText: fn().mockResolvedValue(undefined) },
});
return <Story />;
};