-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathGlobalStyles.stories.tsx
102 lines (97 loc) · 2.48 KB
/
GlobalStyles.stories.tsx
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
import React from 'react';
import styled from 'styled-components';
import { Story, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { FoundryProvider } from '../../context';
import Text from '../Text';
import Card from '../Card';
import Button from '../Button';
import colorsEnum from '../../enums/colors';
const Container = styled.div`
display: flex;
align-items: center;
flex-direction: column;
`;
const StyledTextContainer = styled(Text.Container)`
margin-bottom: 1rem;
`;
const StyledCardContainer = styled(Card.Container)`
margin-bottom: 1rem;
`;
interface ExampleProps {
'font-family': string;
primary: string;
grayDark: string;
}
export const Example: Story<ExampleProps> = ({
'font-family': fontFamily,
primary,
grayDark,
}: ExampleProps) => {
const globalStyles = `
font-family: ${fontFamily};
`;
const colors = {
primary,
grayDark,
};
const showAnalytics = (
componentType: string,
eventType: string,
eventArgs?: React.ChangeEvent<HTMLInputElement>,
dateTime?: Date,
deviceInfo?: Record<string, unknown>,
currentURL?: string,
props?: any,
): void => {
action(`${componentType} ${eventType}`)(
componentType,
eventType,
eventArgs,
dateTime,
deviceInfo,
currentURL,
props,
);
};
const styleConstants = {
paddingSmall: '1rem',
paddingLarge: '2rem',
};
return (
<FoundryProvider
value={{ globalStyles, colors, styleConstants, analyticsFunction: showAnalytics }}
>
<Container>
<Text StyledContainer={StyledTextContainer}>Hello!</Text>
<Card StyledContainer={StyledCardContainer} elevation={0} header="Title">
These components all have a global set of styles applied to them through React's Context
API.
</Card>
<Button onClick={action('click button')}>Example button</Button>
</Container>
</FoundryProvider>
);
};
Example.args = {
'font-family': 'Arial',
primary: colorsEnum.primary,
grayDark: colorsEnum.grayDark,
} as ExampleProps;
export default {
title: 'Global styles',
argTypes: {
'font-family': {
options: ['Arial', 'Times New Roman', 'Monospace', 'unset'],
mapping: {
Arial: 'Arial,Roboto,sans-serif',
'Times New Roman': '"Times New Roman",Times,serif',
Monospace: '"Lucida Console",Courier,monospace',
unset: 'unset',
},
control: {
type: 'radio',
},
},
},
} as Meta;