-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapollo-custom-template.stories.tsx
More file actions
142 lines (132 loc) · 4.05 KB
/
Copy pathapollo-custom-template.stories.tsx
File metadata and controls
142 lines (132 loc) · 4.05 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* eslint-disable react/function-component-definition */
import React from 'react';
import type { StoryFn, Meta } from '@storybook/react-webpack5';
import { HelmetProvider } from 'react-helmet-async';
import { ConfigProvider } from '../core/configProvider/ConfigProvider';
import { defaultConfig } from '../core/configProvider/defaultConfig';
import { PageContent } from './pageContent/PageContent';
import { Navigation } from './navigation/Navigation';
import { Notification } from './notification/Notification';
import { Page } from './page/Page';
import { PageContentLayout } from '../core/pageContent/PageContentLayout';
import { LanguageCodeEnum } from '../core';
import { useCmsEndpointConfig } from '../storybook-common/useCmsEndpointConfig';
import type { CmsEndpoint } from '../storybook-common/constants';
import { cmsMenuName, cmsTestPage } from '../storybook-common/constants';
import { HelmetWrapper } from '../storybook-common/HelmetWrapper';
const ExampleNavigation = ({
menuName,
currentPage,
}: {
menuName: string;
currentPage: string;
}) => (
<Navigation
menuName={menuName}
onTitleClick={() => {
// eslint-disable-next-line no-console
console.log('I should navigate');
}}
getIsItemActive={({ path }) => path === currentPage}
getPathnameForLanguage={({ slug }) => `/${slug}${currentPage}`}
/>
);
const CustomPageContentLayout: typeof PageContentLayout = ({
breadcrumbs,
content,
collections,
sidebarContent,
}) => (
<div>
<div style={{ marginBottom: 30 }}>
<div>Breadcrumbs: {breadcrumbs}</div>
</div>
<div
style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
columnGap: 30,
}}
>
<div>Content: {content}</div>
<div>Sidebar: {sidebarContent}</div>
<div>Collections: {collections}</div>
</div>
</div>
);
function getTemplate(
dataSource: keyof typeof CmsEndpoint,
): StoryFn<typeof Page> {
return function ApolloCustomTemplate(args) {
const {
apolloClient,
eventsApolloClient,
internalHrefOrigins = [],
} = useCmsEndpointConfig(dataSource);
return (
<HelmetProvider>
<ConfigProvider
config={{
...defaultConfig,
currentLanguageCode: LanguageCodeEnum.Fi,
siteName: 'RHHC Example',
internalHrefOrigins,
apolloClient,
eventsApolloClient,
venuesApolloClient: 'disabled',
components: {
...defaultConfig.components,
Head: HelmetWrapper,
},
utils: {
...defaultConfig.utils,
getRoutedInternalHref: (link) => {
let uri = '';
internalHrefOrigins.forEach((d) => {
uri = link?.replace(d, '') ?? '';
});
return uri;
},
},
}}
>
<Page {...args} />
</ConfigProvider>
</HelmetProvider>
);
};
}
export default {
title: 'Apollo examples/Custom template',
component: Page,
subcomponents: { PageContent, PageContentLayout, Notification, Navigation },
} as Meta<typeof Page>;
const ApolloCustomLayoutExample = {
args: {
notification: <Notification />,
content: (
<PageContent
breadcrumbs={[
{ title: 'Root', link: '/' },
{ title: 'Nested', link: '/nested' },
]}
PageContentLayoutComponent={CustomPageContentLayout}
/>
),
footer: <>TODO: Implement footer</>,
},
};
const getAppSpecificArgs = (dataSource: keyof typeof CmsEndpoint) => ({
uri: cmsTestPage[dataSource],
navigation: (
<ExampleNavigation
menuName={cmsMenuName[dataSource]}
currentPage={cmsTestPage[dataSource]}
/>
),
...ApolloCustomLayoutExample.args,
});
export const ExampleUsingKultusDataSource = getTemplate('kultus').bind({});
ExampleUsingKultusDataSource.args = getAppSpecificArgs('kultus');
export const ExampleUsingKukkuuDataSource = getTemplate('kukkuu').bind({});
ExampleUsingKukkuuDataSource.args = getAppSpecificArgs('kukkuu');