create-tina-app 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/{examples/tina-tailwind-sidebar-demo/LICENSE → LICENSE} +1 -26
  2. package/dist/index.js +19 -11
  3. package/{examples/tina-tailwind-sidebar-demo/next-env.d.ts → dist/util/preRunChecks.d.ts} +1 -3
  4. package/package.json +11 -10
  5. package/CHANGELOG.md +0 -38
  6. package/examples/tina-tailwind-sidebar-demo/.tina/PageTemplate.ts +0 -427
  7. package/examples/tina-tailwind-sidebar-demo/.tina/ThemeTemplate.ts +0 -42
  8. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/_graphql.json +0 -4180
  9. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/_lookup.json +0 -68
  10. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/_schema.json +0 -851
  11. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/config/schema.json +0 -479
  12. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/schema.gql +0 -391
  13. package/examples/tina-tailwind-sidebar-demo/.tina/__generated__/types.ts +0 -520
  14. package/examples/tina-tailwind-sidebar-demo/.tina/schema.ts +0 -35
  15. package/examples/tina-tailwind-sidebar-demo/CHANGELOG.md +0 -95
  16. package/examples/tina-tailwind-sidebar-demo/README.md +0 -10
  17. package/examples/tina-tailwind-sidebar-demo/components/PageBlocks.tsx +0 -25
  18. package/examples/tina-tailwind-sidebar-demo/components/actions.js +0 -114
  19. package/examples/tina-tailwind-sidebar-demo/components/features.tsx +0 -171
  20. package/examples/tina-tailwind-sidebar-demo/components/footer.tsx +0 -247
  21. package/examples/tina-tailwind-sidebar-demo/components/hero.js +0 -156
  22. package/examples/tina-tailwind-sidebar-demo/components/icon.js +0 -264
  23. package/examples/tina-tailwind-sidebar-demo/components/modal.js +0 -79
  24. package/examples/tina-tailwind-sidebar-demo/components/nav.tsx +0 -121
  25. package/examples/tina-tailwind-sidebar-demo/components/section.js +0 -53
  26. package/examples/tina-tailwind-sidebar-demo/components/testimonial.tsx +0 -87
  27. package/examples/tina-tailwind-sidebar-demo/components/theme.tsx +0 -81
  28. package/examples/tina-tailwind-sidebar-demo/components/tina-wrapper.js +0 -85
  29. package/examples/tina-tailwind-sidebar-demo/content/data/homepage.json +0 -186
  30. package/examples/tina-tailwind-sidebar-demo/content/theme/NormalTheme.json +0 -5
  31. package/examples/tina-tailwind-sidebar-demo/graphql.config.js +0 -24
  32. package/examples/tina-tailwind-sidebar-demo/package.json +0 -41
  33. package/examples/tina-tailwind-sidebar-demo/pages/_app.js +0 -48
  34. package/examples/tina-tailwind-sidebar-demo/pages/admin.tsx +0 -26
  35. package/examples/tina-tailwind-sidebar-demo/pages/index.tsx +0 -186
  36. package/examples/tina-tailwind-sidebar-demo/postcss.config.js +0 -19
  37. package/examples/tina-tailwind-sidebar-demo/public/canal.jpg +0 -0
  38. package/examples/tina-tailwind-sidebar-demo/public/index.html +0 -42
  39. package/examples/tina-tailwind-sidebar-demo/styles.css +0 -20
  40. package/examples/tina-tailwind-sidebar-demo/tailwind.config.js +0 -83
  41. package/examples/tina-tailwind-sidebar-demo/tsconfig.json +0 -19
@@ -1,264 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import { ThemeContext } from './theme'
16
- import {
17
- BiCodeBlock,
18
- BiLike,
19
- BiMapAlt,
20
- BiPalette,
21
- BiPieChartAlt2,
22
- BiPin,
23
- BiShield,
24
- BiSlider,
25
- BiStore,
26
- BiTennisBall,
27
- BiTestTube,
28
- BiTrophy,
29
- BiUserCircle,
30
- BiBeer,
31
- BiChat,
32
- BiCloud,
33
- BiCoffeeTogo,
34
- BiWorld,
35
- } from 'react-icons/bi'
36
- import { FiAperture } from 'react-icons/fi'
37
-
38
- const iconOptions = {
39
- BiCodeBlock: BiCodeBlock,
40
- BiLike: BiLike,
41
- BiMapAlt: BiMapAlt,
42
- BiPalette: BiPalette,
43
- BiPieChartAlt2: BiPieChartAlt2,
44
- BiPin: BiPin,
45
- BiShield: BiShield,
46
- BiSlider: BiSlider,
47
- BiStore: BiStore,
48
- BiTennisBall: BiTennisBall,
49
- BiTestTube: BiTestTube,
50
- BiTrophy: BiTrophy,
51
- BiUserCircle: BiUserCircle,
52
- BiBeer: BiBeer,
53
- BiChat: BiChat,
54
- BiCloud: BiCloud,
55
- BiCoffeeTogo: BiCoffeeTogo,
56
- BiWorld: BiWorld,
57
- FiAperture: FiAperture,
58
- }
59
-
60
- export const Icon = ({ icon }) => {
61
- const theme = React.useContext(ThemeContext)
62
- const iconSize = icon?.size ? (icon.size === 'large' ? 14 : 9) : 14
63
-
64
- const IconSVG = React.useMemo(() => {
65
- return icon?.name ? iconOptions[icon?.name] : randomProperty(iconOptions)
66
- }, [icon?.name])
67
-
68
- const Component = React.useMemo(() => {
69
- const iconColor =
70
- icon?.color === 'primary' ? theme.color : icon?.color || 'blue'
71
-
72
- if (!IconSVG) return null
73
- if (icon?.style == 'circle') {
74
- return (
75
- <div
76
- className={`relative z-10 inline-flex items-center justify-center flex-shrink-0 w-${iconSize} h-${iconSize} bg-${iconColor}-400 dark:bg-${iconColor}-500 text-${iconColor}-50 rounded-full`}
77
- style={{
78
- textShadow: '0 2px 5px rgba(0,0,0,0.1)',
79
- boxShadow: `0 0.5rem 3rem 0px rgba(var(--color-rgb-${iconColor}-600),0.35)`,
80
- }}
81
- >
82
- <IconSVG
83
- className={`w-${Math.max(iconSize - 5, 6)} h-${Math.max(
84
- iconSize - 5,
85
- 6
86
- )}`}
87
- />
88
- </div>
89
- )
90
- } else {
91
- return (
92
- <IconSVG
93
- className={`w-${iconSize} h-${iconSize} text-${iconColor}-400 dark:text-${iconColor}-500`}
94
- style={{
95
- filter: `drop-shadow(0 0.5rem 1rem rgba(var(--color-rgb-${iconColor}-600),0.4))`,
96
- }}
97
- />
98
- )
99
- }
100
- }, [icon?.style, IconSVG, icon?.color, theme.color])
101
-
102
- return Component
103
- }
104
-
105
- export const ICON_FIELDS = [
106
- {
107
- label: 'Icon',
108
- name: 'icon',
109
- component: 'group',
110
- fields: [
111
- {
112
- name: 'color',
113
- label: 'Color',
114
- component: 'select',
115
- options: [
116
- {
117
- label: 'Primary (Theme)',
118
- value: 'primary',
119
- },
120
- {
121
- label: 'Blue',
122
- value: 'blue',
123
- },
124
- {
125
- label: 'Teal',
126
- value: 'teal',
127
- },
128
- {
129
- label: 'Green',
130
- value: 'green',
131
- },
132
- {
133
- label: 'Red',
134
- value: 'red',
135
- },
136
- {
137
- label: 'Pink',
138
- value: 'pink',
139
- },
140
- {
141
- label: 'Purple',
142
- value: 'purple',
143
- },
144
- {
145
- label: 'Orange',
146
- value: 'orange',
147
- },
148
- {
149
- label: 'Yellow',
150
- value: 'yellow',
151
- },
152
- ],
153
- },
154
- {
155
- name: 'name',
156
- label: 'Icon',
157
- component: 'select',
158
- options: [
159
- {
160
- label: 'Random',
161
- value: '',
162
- },
163
- {
164
- label: 'Aperture',
165
- value: 'FiAperture',
166
- },
167
- {
168
- label: 'Code Block',
169
- value: 'BiCodeBlock',
170
- },
171
- {
172
- label: 'Like',
173
- value: 'BiLike',
174
- },
175
- {
176
- label: 'Map',
177
- value: 'BiMapAlt',
178
- },
179
- {
180
- label: 'Palette',
181
- value: 'BiPalette',
182
- },
183
- {
184
- label: 'Pie Chart',
185
- value: 'BiPieChartAlt2',
186
- },
187
- {
188
- label: 'Pin',
189
- value: 'BiPin',
190
- },
191
- {
192
- label: 'Shield',
193
- value: 'BiShield',
194
- },
195
- {
196
- label: 'Setting Sliders',
197
- value: 'BiSlider',
198
- },
199
- {
200
- label: 'Store',
201
- value: 'BiStore',
202
- },
203
- {
204
- label: 'Tennis Ball',
205
- value: 'BiTennisBall',
206
- },
207
- {
208
- label: 'Test Tube',
209
- value: 'BiTestTube',
210
- },
211
- {
212
- label: 'Trophy',
213
- value: 'BiTrophy',
214
- },
215
- {
216
- label: 'User',
217
- value: 'BiUserCircle',
218
- },
219
- {
220
- label: 'Beer',
221
- value: 'BiBeer',
222
- },
223
- {
224
- label: 'Chat',
225
- value: 'BiChat',
226
- },
227
- {
228
- label: 'Cloud',
229
- value: 'BiCloud',
230
- },
231
- {
232
- label: 'Coffee',
233
- value: 'BiCoffeeTogo',
234
- },
235
- {
236
- label: 'World',
237
- value: 'BiWorld',
238
- },
239
- ],
240
- },
241
- {
242
- name: 'style',
243
- label: 'Style',
244
- component: 'radio-group',
245
- variant: 'button',
246
- options: [
247
- {
248
- label: 'Circle',
249
- value: 'circle',
250
- },
251
- {
252
- label: 'Float',
253
- value: 'float',
254
- },
255
- ],
256
- },
257
- ],
258
- },
259
- ]
260
-
261
- const randomProperty = (obj) => {
262
- var keys = Object.keys(obj)
263
- return obj[keys[(keys.length * Math.random()) << 0]]
264
- }
@@ -1,79 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import {
16
- Modal,
17
- PopupModal,
18
- ModalHeader,
19
- ModalBody,
20
- ModalActions,
21
- FieldsGroup,
22
- } from 'tinacms'
23
- import { Button } from '@tinacms/styles'
24
-
25
- export function TinaModal({
26
- title = 'Save Changes',
27
- close = () => {},
28
- data = {},
29
- }) {
30
- function handleClose(event) {
31
- event.stopPropagation()
32
- event.preventDefault()
33
- close()
34
- }
35
-
36
- return (
37
- <Modal id="tina-modal" onClick={(e) => e.stopPropagation()}>
38
- <PopupModal>
39
- <ModalHeader close={close}>{title}</ModalHeader>
40
- <ModalBody>
41
- <FieldsGroup>
42
- <div>
43
- <h3 className="font-bold text-xl mb-3">
44
- You control what happens with your data.
45
- </h3>
46
- <p className="whitespace-normal mb-3">
47
- Currently there are packages to support Git workflows, but Tina
48
- is designed to potentially work with any data source.
49
- </p>
50
- <details className="mb-4 px-2 pt-2 bg-gray-200 border border-gray-300 rounded">
51
- <summary className="list-none display-block cursor-pointer text-blue-500 hover:text-blue-700 mb-2 outline-none select-none">
52
- View Raw JSON
53
- </summary>
54
- <pre className="mb-2 text-sm overflow-scroll">
55
- <code className="leading-none">
56
- {JSON.stringify(data, null, 2)}
57
- </code>
58
- </pre>
59
- </details>
60
- </div>
61
- </FieldsGroup>
62
- </ModalBody>
63
- <ModalActions>
64
- <Button
65
- primary
66
- onClick={() => {
67
- window.location = 'https://tina.io/docs/getting-started/backends/'
68
- }}
69
- >
70
- <span className="whitespace-nowrap inline-block">
71
- Read The Docs
72
- </span>
73
- </Button>
74
- <Button onClick={handleClose}>Close</Button>
75
- </ModalActions>
76
- </PopupModal>
77
- </Modal>
78
- )
79
- }
@@ -1,121 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import { ThemeContext } from './theme'
16
- import { Section } from './section'
17
- import { Icon, ICON_FIELDS } from './icon'
18
- import { BiSun } from 'react-icons/bi'
19
- import { RiMoonClearLine } from 'react-icons/ri'
20
- import { Homepage_Nav_Data, Maybe } from '../.tina/__generated__/types'
21
-
22
- export const Nav = ({ nav }: { nav?: Maybe<Homepage_Nav_Data> }) => {
23
- const theme = React.useContext(ThemeContext)
24
-
25
- return (
26
- <Section>
27
- <div className="relative flex flex-col flex-wrap py-8 px-8 lg:px-12 2xl:px-16 mx-auto md:items-center md:flex-row">
28
- <a
29
- href="#"
30
- className="pr-2 lg:pr-8 mb-8 md:mb-0 focus:outline-none flex items-center"
31
- >
32
- <div className="inline-flex items-center">
33
- <div className={`mr-2`}>
34
- <Icon icon={nav?.wordmark?.icon || ''} />
35
- </div>
36
- <h2 className="font-bold tracking-tight transition duration-150 ease-out transform text-blueGray-500 dark:text-blueGray-200 lg:text-md text-bold">
37
- {nav?.wordmark?.name || ''}
38
- </h2>
39
- </div>
40
- </a>
41
- <div className="flex-grow md:flex md:justify-end">
42
- <nav className="flex flex-wrap items-center justify-between sm:justify-end text-base -mx-2 sm:-mx-6 md:mx-0">
43
- {nav?.items?.map(function (item, index) {
44
- return (
45
- <a
46
- key={index}
47
- href="#"
48
- className={`mx-2 sm:mx-6 md:mx-8 text-sm tracking-wide font-semibold transition duration-150 ease-out text-gray-600 dark:text-gray-200`}
49
- >
50
- {item.label}
51
- </a>
52
- )
53
- })}
54
- </nav>
55
- <button
56
- onClick={() => {
57
- // @ts-ignore
58
- theme.toggleThemeMode()
59
- }}
60
- type="button"
61
- className="ml-8 outline-none opacity-30 hover:opacity-70 focus:opacity-100 focus:outline-none transparent absolute top-9 right-6 md:relative md:top-auto md:right-auto transition duration-150 ease-out"
62
- aria-pressed="false"
63
- >
64
- <BiSun
65
- className={`w-6 h-6 transition duration-300 ease-out transform ${
66
- // @ts-ignore
67
- theme.themeMode === 'light' && 'opacity-0 rotate-90'
68
- }`}
69
- />
70
- <RiMoonClearLine
71
- className={`w-6 h-6 absolute top-0 left-0 transition duration-300 ease-out transform ${
72
- // @ts-ignore
73
- theme.themeMode === 'dark' && 'opacity-0 -rotate-90'
74
- }`}
75
- />
76
- </button>
77
- </div>
78
- </div>
79
- </Section>
80
- )
81
- }
82
-
83
- export const NAV_FIELDS = [
84
- {
85
- label: 'Wordmark',
86
- name: 'wordmark',
87
- component: 'group',
88
- fields: [
89
- ...ICON_FIELDS,
90
- {
91
- label: 'Name',
92
- name: 'name',
93
- component: 'text',
94
- },
95
- ],
96
- },
97
- {
98
- label: 'Nav Items',
99
- name: 'items',
100
- component: 'group-list',
101
- itemProps: (item) => ({
102
- label: item.label,
103
- }),
104
- defaultItem: () => ({
105
- label: 'Nav Link',
106
- link: '/',
107
- }),
108
- fields: [
109
- {
110
- label: 'Label',
111
- name: 'label',
112
- component: 'text',
113
- },
114
- {
115
- label: 'Link',
116
- name: 'link',
117
- component: 'text',
118
- },
119
- ],
120
- },
121
- ]
@@ -1,53 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import { ThemeContext } from './theme'
16
-
17
- export const Section = ({ variant = 'default', children }) => {
18
- const theme = React.useContext(ThemeContext)
19
-
20
- let variantClasses = `relative transition duration-150 ease-out text-gray-800 dark:text-gray-100 bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-700 dark:to-gray-800 body-font overflow-hidden`
21
-
22
- if (variant === 'tint') {
23
- variantClasses = `relative transition duration-150 ease-out text-gray-700 dark:text-gray-100 bg-gradient-to-br from-gray-50 to-white dark:from-gray-900 dark:to-gray-800 body-font overflow-hidden`
24
- }
25
-
26
- if (variant === 'primary') {
27
- variantClasses = `relative transition duration-150 ease-out text-gray-700 dark:text-gray-100 bg-${theme.color}-700 bg-gradient-to-br from-${theme.color}-500 to-${theme.color}-300 dark:from-${theme.color}-500 dark:to-${theme.color}-700 body-font overflow-hidden`
28
- }
29
-
30
- return <section className={variantClasses}>{children}</section>
31
- }
32
-
33
- export const SectionFields = [
34
- {
35
- name: 'color',
36
- label: 'Color',
37
- component: 'select',
38
- options: [
39
- {
40
- label: 'Default',
41
- value: 'default',
42
- },
43
- {
44
- label: 'Tint',
45
- value: 'tint',
46
- },
47
- {
48
- label: 'Primary',
49
- value: 'primary',
50
- },
51
- ],
52
- },
53
- ]
@@ -1,87 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import { ThemeContext } from './theme'
16
- import { Section, SectionFields } from './section'
17
- import { Testimonial_Data } from '../.tina/__generated__/types'
18
-
19
- export const Testimonial = (props: Testimonial_Data) => {
20
- const theme = React.useContext(ThemeContext)
21
-
22
- return (
23
- <Section variant={props?.style?.color || 'blue'}>
24
- <div className="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24">
25
- <div className="relative">
26
- <blockquote>
27
- <div className="relative z-10 max-w-3xl mx-auto text-4xl lg:text-5xl font-extrabold tracking-normal text-center title-font text-white">
28
- <span
29
- className={`block opacity-20 text-black text-${theme.color}-700 text-8xl absolute inset-y-1/2 transform translate-y-2 -left-4 leading-4 -z-1`}
30
- >
31
- &ldquo;
32
- </span>
33
- <p className="relative opacity-95">{props.quote}</p>
34
- <span
35
- className={`block opacity-20 text-black text-${theme.color}-800 text-8xl absolute inset-y-1/2 transform translate-y-3 -right-4 leading-4 -z-1`}
36
- >
37
- &rdquo;
38
- </span>
39
- </div>
40
- <div className={`my-8 flex-grow-0`}>
41
- <span
42
- className={`block mx-auto h-0.5 w-1/6 bg-${theme.color}-300 dark:bg-${theme.color}-700 opacity-70`}
43
- ></span>
44
- </div>
45
- <footer className="text-center">
46
- <p
47
- className={`tracking-wide title-font font-bold text-base text-${theme.color}-500 dark:text-${theme.color}-300`}
48
- >
49
- {props.author}
50
- </p>
51
- </footer>
52
- </blockquote>
53
- </div>
54
- </div>
55
- </Section>
56
- )
57
- }
58
-
59
- export const testimonial_template = {
60
- label: 'Testimonial',
61
- defaultItem: {
62
- quote:
63
- 'There are only two hard things in Computer Science: cache invalidation and naming things.',
64
- author: 'Phil Karlton',
65
- style: {
66
- color: 'primary',
67
- },
68
- },
69
- fields: [
70
- {
71
- name: 'quote',
72
- label: 'Quote',
73
- component: 'textarea',
74
- },
75
- {
76
- name: 'author',
77
- label: 'Author',
78
- component: 'text',
79
- },
80
- {
81
- name: 'style',
82
- label: 'Style',
83
- component: 'group',
84
- fields: [...SectionFields],
85
- },
86
- ],
87
- }
@@ -1,81 +0,0 @@
1
- /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import * as React from 'react'
15
- import { Theme_Document } from '../.tina/__generated__/types'
16
-
17
- export const ThemeContext = React.createContext(null as any)
18
-
19
- const getInitialThemeMode = (_) => {
20
- if (typeof window !== 'undefined') {
21
- if (window.localStorage) {
22
- const storedPrefs = window.localStorage.getItem('theme-mode')
23
-
24
- if (typeof storedPrefs === 'string') {
25
- return storedPrefs
26
- }
27
- }
28
-
29
- const userMedia = window.matchMedia('(prefers-color-scheme: dark)')
30
-
31
- if (userMedia.matches) {
32
- return 'dark'
33
- }
34
- }
35
-
36
- return 'light'
37
- }
38
-
39
- const updateRenderColorMode = (themeMode) => {
40
- if (typeof window !== 'undefined') {
41
- const root = window.document.documentElement
42
- root.classList.remove('dark')
43
- root.classList.remove('light')
44
- root.classList.add(themeMode)
45
- }
46
- }
47
-
48
- export const Theme: React.FC<{
49
- theme: {
50
- getThemeDocument: Theme_Document
51
- }
52
- }> = ({ children, theme }) => {
53
- const [themeMode, setThemeMode] = React.useState(getInitialThemeMode(''))
54
-
55
- const toggleThemeMode = () => {
56
- let newMode = ''
57
-
58
- if (themeMode === 'light') {
59
- newMode = 'dark'
60
- } else {
61
- newMode = 'light'
62
- }
63
-
64
- setThemeMode(newMode)
65
-
66
- if (typeof window !== 'undefined' && window.localStorage) {
67
- window.localStorage.setItem('theme-mode', newMode)
68
- }
69
- }
70
-
71
- React.useEffect(() => {
72
- updateRenderColorMode(themeMode)
73
- }, [themeMode])
74
-
75
- const themeData = theme.getThemeDocument.data
76
- return (
77
- <ThemeContext.Provider value={{ themeMode, toggleThemeMode, ...themeData }}>
78
- {children}
79
- </ThemeContext.Provider>
80
- )
81
- }