-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathProviderDemo.story.tsx
51 lines (45 loc) · 1.22 KB
/
ProviderDemo.story.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
import React, { useState } from 'react';
import Badge from '@leafygreen-ui/badge';
import Button from '@leafygreen-ui/button';
import Card from '@leafygreen-ui/card';
import LeafyGreenProvider, {
useDarkMode,
} from '@leafygreen-ui/leafygreen-provider';
import { Body } from '@leafygreen-ui/typography';
export default {
title: 'LeafyGreen Provider/DarkMode',
parameters: {
chromatic: { disableSnapshot: true },
},
};
const DarkModeComponent = () => {
const { darkMode, theme, setDarkMode } = useDarkMode();
return (
<Card darkMode={darkMode}>
<Body>
Currently in <Badge>{`${theme}`}</Badge> mode
</Body>
<br />
<Button onClick={() => setDarkMode(!darkMode)}>Toggle context</Button>
</Card>
);
};
export const DarkModeDemo = () => {
const [darkMode, setDarkMode] = useState(false);
return (
<>
<LeafyGreenProvider darkMode={darkMode}>
<DarkModeComponent />
</LeafyGreenProvider>
<br />
<Button onClick={() => setDarkMode(!darkMode)}>Toggle outer state</Button>
<br />
<div>
Outer state darkMode: <Badge>{`${darkMode}`}</Badge>
</div>
</>
);
};
DarkModeDemo.parameters = {
chromatic: { disableSnapshot: true },
};