@xyd-js/themes 0.0.0-build

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/CHANGELOG.md +14 -0
  2. package/LICENSE +21 -0
  3. package/README.md +7 -0
  4. package/dist/decorators/atlas-vars.css +29 -0
  5. package/dist/decorators/header-sketch.css +23 -0
  6. package/dist/decorators/page-layout.css +11 -0
  7. package/dist/decorators/page-leftpad.css +46 -0
  8. package/dist/decorators/page-sketch.css +52 -0
  9. package/dist/decorators/sidebar-pad.css +24 -0
  10. package/dist/decorators/sidebar-scroll.css +51 -0
  11. package/dist/index.css +1259 -0
  12. package/dist/index.d.ts +116 -0
  13. package/dist/index.js +669 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/reset.css +56 -0
  16. package/dist/rollup.d.ts +28 -0
  17. package/dist/rollup.js +139 -0
  18. package/dist/rollup.js.map +1 -0
  19. package/package.json +60 -0
  20. package/postcss.config.cjs +7 -0
  21. package/scripts/build-css.js +73 -0
  22. package/src/BaseTheme.tsx +471 -0
  23. package/src/Theme.tsx +363 -0
  24. package/src/context.tsx +9 -0
  25. package/src/copyPresetsPlugin.ts +124 -0
  26. package/src/index.ts +11 -0
  27. package/src/rollup.ts +91 -0
  28. package/src/styles/decorators/atlas-vars.css +32 -0
  29. package/src/styles/decorators/header-sketch.css +23 -0
  30. package/src/styles/decorators/page-layout.css +11 -0
  31. package/src/styles/decorators/page-leftpad.css +46 -0
  32. package/src/styles/decorators/page-sketch.css +30 -0
  33. package/src/styles/decorators/sidebar-pad.css +24 -0
  34. package/src/styles/decorators/sidebar-scroll.css +51 -0
  35. package/src/styles/index.css +26 -0
  36. package/src/styles/reset.css +56 -0
  37. package/src/styles/styles.css +156 -0
  38. package/src/styles/tokens.css +472 -0
  39. package/tsconfig.json +51 -0
  40. package/tsup.config.ts +38 -0
  41. package/types.d.ts +13 -0
@@ -0,0 +1,471 @@
1
+ import * as React from 'react'
2
+ import { useEffect } from 'react'
3
+ import { useLocation, useMatches } from 'react-router'
4
+ import GitHubButton from 'react-github-btn'
5
+ import { UXNode } from "openux-js";
6
+
7
+ import {
8
+ TocCard,
9
+ Text,
10
+ VideoGuide,
11
+ useColorScheme,
12
+ IconSocial,
13
+ IconSocialProps,
14
+ Icon
15
+ } from '@xyd-js/components/writer';
16
+ import { ContentDecorator } from "@xyd-js/components/content";
17
+ import {
18
+ LayoutPrimary
19
+ } from "@xyd-js/components/layouts";
20
+ import { Footer } from "@xyd-js/components/system";
21
+
22
+ import {
23
+ FwNav,
24
+ FwNavLinks,
25
+ FwToc,
26
+ FwSubNav,
27
+ FwSidebar,
28
+ FwJsonComponent,
29
+ FwLogo,
30
+
31
+ useMatchedSubNav,
32
+ useActiveRoute,
33
+ useActivePageRoute,
34
+ useMetadata,
35
+ useSettings,
36
+ FwBanner,
37
+ useAppearance,
38
+ useContentComponent,
39
+ useContentOriginal,
40
+ FwCopyPage,
41
+ FwBreadcrumbs,
42
+ } from "@xyd-js/framework/react";
43
+
44
+ import { Theme } from "./Theme";
45
+ import { Metadata } from '@xyd-js/core';
46
+ import { useRef } from 'react';
47
+ import { useUXEvents } from '@xyd-js/analytics';
48
+ import { useUXUnreachableElementTracker } from "@xyd-js/components/uxsdk";
49
+
50
+ export class BaseTheme extends Theme {
51
+ constructor() {
52
+ super()
53
+
54
+ this.Page = this.Page.bind(this)
55
+ this.Layout = this.Layout.bind(this)
56
+ this.Navbar = this.Navbar.bind(this)
57
+ this.Sidebar = this.Sidebar.bind(this)
58
+ this.Content = this.Content.bind(this)
59
+ this.ContentSecondary = this.ContentSecondary.bind(this)
60
+ this.ContentNav = this.ContentNav.bind(this)
61
+ this.TocTop = this.TocTop.bind(this)
62
+ this.TocBottom = this.TocBottom.bind(this)
63
+ this.PageFooter = this.PageFooter.bind(this)
64
+ this.Footer = this.Footer.bind(this)
65
+ this.Breadcrumbs = this.Breadcrumbs.bind(this)
66
+ this.NavLinks = this.NavLinks.bind(this)
67
+ }
68
+
69
+ // public reactContentComponents(): { [component: string]: (props: any) => React.JSX.Element | null } {
70
+ // return this.reactContent.components()
71
+ // }
72
+
73
+ public reactContentComponents(): { [component: string]: (props: any) => React.JSX.Element | null } {
74
+ const meta = useMetadata()
75
+ const appearance = useAppearance()
76
+ const contentDecorator = appearance?.content?.contentDecorator
77
+
78
+ if (contentDecorator === "secondary") {
79
+ if (isDefaultContent(meta)) {
80
+ return this.reactContent.components()
81
+ }
82
+
83
+ return {
84
+ ...this.reactContent.components(),
85
+ h1: () => null,
86
+ Subtitle: () => null,
87
+ }
88
+ }
89
+
90
+ return this.reactContent.components()
91
+ }
92
+
93
+ // TODO: rename and better cuz its only for fixing react-components in secondary content cuz it apply to non original content
94
+ public reactFileComponents(): { [component: string]: (props: any) => React.JSX.Element | null } | false {
95
+ const appearance = useAppearance()
96
+ const contentDecorator = appearance?.content?.contentDecorator
97
+
98
+ if (contentDecorator === "secondary") {
99
+ return false
100
+ }
101
+
102
+ return {}
103
+ }
104
+
105
+ public Layout({ children }: { children: React.ReactNode }) {
106
+ const {
107
+ Navbar: $Navbar,
108
+ Sidebar: $Sidebar,
109
+ Footer: $Footer,
110
+ SubNav: $SubNav,
111
+ } = this
112
+
113
+ const location = useLocation()
114
+ const matchedSubNav = useMatchedSubNav()
115
+ const matchActivePageRout = useActivePageRoute(true)
116
+ const activeRoute = useActiveRoute()
117
+ const meta = useMetadata()
118
+ const appearance = useAppearance()
119
+ const isPage = meta?.layout === "page"
120
+
121
+ const hideSidebar = this.useHideSidebar()
122
+ const subheader = matchedSubNav && !isPage ? <$SubNav /> : null
123
+ const sidebar = <$Sidebar />
124
+
125
+ const banner = appearance?.banner?.fixed ? <FwBanner /> : null
126
+
127
+ const id = activeRoute?.id || matchActivePageRout?.id || undefined
128
+
129
+ return <UXNode name="BaseTheme.Layout" props={{}}>
130
+ <LayoutPrimary
131
+ subheader={!!subheader}
132
+ layout={meta?.layout}
133
+ scrollKey={location.pathname}
134
+ id={id}
135
+ >
136
+ <LayoutPrimary.Header
137
+ banner={banner}
138
+ header={<$Navbar />}
139
+ subheader={subheader}
140
+ />
141
+ <LayoutPrimary.MobileAside
142
+ aside={sidebar}
143
+ />
144
+
145
+ <main part="main">
146
+ {hideSidebar ? null : <aside part="sidebar">
147
+ {sidebar}
148
+ </aside>}
149
+
150
+ {children}
151
+ </main>
152
+
153
+ {appearance?.footer?.surface !== "page" ? <$Footer /> : null}
154
+ </LayoutPrimary>
155
+ </UXNode>
156
+ }
157
+
158
+ public Page({ children }: { children: React.ReactNode }) {
159
+ const {
160
+ Content: $Content,
161
+ ContentNav: $ContentNav,
162
+ PageFooter: $PageFooter,
163
+ Footer: $Footer,
164
+ } = this
165
+
166
+ const hideToc = this.useHideToc()
167
+ const appearance = useAppearance()
168
+ const meta = useMetadata()
169
+
170
+ let contentNav = hideToc ? undefined : <$ContentNav />
171
+ let footer = appearance?.footer?.surface === "page" ? <$Footer /> : null
172
+ const isPage = meta?.layout === "page"
173
+
174
+ return <UXNode name="BaseTheme.Page" props={{}}>
175
+ <LayoutPrimary.Page
176
+ after={footer}
177
+ contentNav={contentNav}
178
+ >
179
+ <$Content>
180
+ {children}
181
+ </$Content>
182
+
183
+ {isPage ? (
184
+ null
185
+ ) : <$PageFooter>
186
+ <$BuiltWithXYD />
187
+ </$PageFooter>}
188
+ </LayoutPrimary.Page>
189
+ </UXNode>
190
+ }
191
+
192
+ protected Navbar() {
193
+ return <>
194
+ <FwNav />
195
+ </>
196
+ }
197
+
198
+ protected Sidebar() {
199
+ return <FwSidebar />
200
+ }
201
+
202
+ protected Content({ children }: { children: React.ReactNode }) {
203
+ const meta = useMetadata()
204
+ const appearance = useAppearance()
205
+
206
+ const {
207
+ ContentSecondary: $ContentSecondary,
208
+ Breadcrumbs: $Breadcrumbs,
209
+ NavLinks: $NavLinks,
210
+ } = this
211
+
212
+ const contentDecorator = appearance?.content?.contentDecorator
213
+
214
+ if (contentDecorator === "secondary" && !isDefaultContent(meta)) {
215
+ return <$ContentSecondary>
216
+ {children}
217
+ </$ContentSecondary>
218
+ }
219
+
220
+ return <>
221
+ <$Breadcrumbs />
222
+
223
+ <ContentDecorator metaComponent={meta?.component || undefined}>
224
+ {children}
225
+ </ContentDecorator>
226
+
227
+ <$NavLinks />
228
+ </>
229
+ }
230
+
231
+ private ContentSecondary({ children }: { children: React.ReactNode }) {
232
+ const meta = useMetadata()
233
+ const settings = useSettings()
234
+
235
+ const ContentComponent = useContentComponent()
236
+
237
+ const { h1, Subtitle, code } = this.reactContent.components()
238
+ const {
239
+ Breadcrumbs: $Breadcrumbs,
240
+ NavLinks: $NavLinks,
241
+ } = this
242
+
243
+ let copyPageElement: React.JSX.Element | null = <FwCopyPage />
244
+
245
+ if (
246
+ meta?.copyPage !== true &&
247
+ (
248
+ meta?.copyPage === false ||
249
+ settings.theme?.writer?.copyPage === false
250
+ )
251
+ ) {
252
+ copyPageElement = null
253
+ }
254
+
255
+ return <ContentDecorator metaComponent={meta?.component || undefined}>
256
+ <main>
257
+ <xyd-secondary-content>
258
+ <div part="secondary-content-header">
259
+ <div>
260
+ <$Breadcrumbs />
261
+
262
+ <ContentComponent components={{ // TODO: !!! BETTER API !!!
263
+ ...this.reactContent.noop(),
264
+ h1,
265
+ Subtitle,
266
+ code
267
+ }} />
268
+ </div>
269
+ {copyPageElement}
270
+ </div>
271
+
272
+ <div part="secondary-content">
273
+ {children}
274
+ <$NavLinks />
275
+ </div>
276
+ </xyd-secondary-content>
277
+ </main>
278
+ </ContentDecorator>
279
+ }
280
+
281
+ protected ContentNav() {
282
+ const { TocTop, TocBottom } = this
283
+
284
+ // TODO: toc top and bottom in the future
285
+ return <>
286
+ {/* <TocTop /> */}
287
+
288
+ <div>
289
+ <FwToc />
290
+ </div>
291
+
292
+ <TocBottom />
293
+ </>
294
+ }
295
+
296
+ protected TocTop() {
297
+ return <div>
298
+ <VideoGuide.Miniature />
299
+ </div>
300
+ }
301
+
302
+ protected TocBottom() {
303
+ const meta = useMetadata()
304
+ const tocCard = meta?.tocCard
305
+ const isEmpty = !tocCard || (Array.isArray(tocCard) && tocCard.length === 0) || (!Array.isArray(tocCard) && (!tocCard.link || !tocCard.title || !tocCard.description))
306
+ if (isEmpty) {
307
+ return null
308
+ }
309
+
310
+ if (Array.isArray(tocCard)) {
311
+ return <>
312
+ {tocCard.map((card) => (
313
+ <div>
314
+ <TocCard key={card.link} href={card.link} title={card.title} description={card.description}
315
+ icon={card.icon} />
316
+ </div>
317
+ ))}
318
+ </>
319
+ }
320
+
321
+ return <div>
322
+ <TocCard
323
+ title={tocCard.title}
324
+ description={tocCard.description}
325
+ href={tocCard.link}
326
+ icon={tocCard.icon}
327
+ />
328
+ </div>
329
+ }
330
+
331
+ protected PageFooter({ children }: { children: React.ReactNode }) {
332
+ const githubButtonContainer = useRef<HTMLDivElement>(null)
333
+ const settings = useSettings()
334
+ const ux = useUXEvents()
335
+
336
+ const apps = settings.integrations?.[".apps"]
337
+
338
+ let pageFooterBottom: React.ReactNode | null = null
339
+
340
+ // TOOD: its's a hack - in the future fork github buttons?
341
+ useUXUnreachableElementTracker(githubButtonContainer, () => {
342
+ ux.docs.github_star.hover({})
343
+ }, () => {
344
+ ux.docs.github_star.click({})
345
+ })
346
+
347
+ if (apps?.githubStar) {
348
+ pageFooterBottom = <div part="github-button-container">
349
+ <Text size="small">
350
+ {apps.githubStar.label}
351
+ </Text>
352
+
353
+ <div ref={githubButtonContainer}>
354
+ <GitHubButton
355
+ href={apps.githubStar.href}
356
+ data-icon={apps.githubStar.dataIcon || "octicon-star"}
357
+ data-size={apps.githubStar.dataSize || "large"}
358
+ data-show-count={apps.githubStar.dataShowCount || true}
359
+ aria-label={apps.githubStar.ariaLabel}
360
+ >
361
+ {apps.githubStar.title}
362
+ </GitHubButton>
363
+ </div>
364
+ </div>
365
+ }
366
+
367
+ return <>
368
+ <xyd-page-footer>
369
+ {children}
370
+
371
+ {/* TODO: in the future */}
372
+ {/* <Surface target="page.footer.bottom"/> */}
373
+ {pageFooterBottom}
374
+ </xyd-page-footer>
375
+ </>
376
+ }
377
+
378
+ protected Footer() {
379
+ const settings = useSettings()
380
+
381
+ let logoElement: React.ReactNode = null;
382
+
383
+ const logo = settings?.components?.footer?.logo
384
+
385
+ if (!settings.components?.footer) {
386
+ return null
387
+ }
388
+
389
+ if (logo) {
390
+ if (typeof logo === "boolean") {
391
+ logoElement = <FwLogo />
392
+ } else {
393
+ logoElement = FwJsonComponent(logo)
394
+ }
395
+ }
396
+
397
+ return <Footer
398
+ kind={settings.components?.footer?.kind}
399
+ logo={logoElement}
400
+ footnote={FwJsonComponent(settings.components?.footer?.footnote || "")}
401
+ socials={settings.components?.footer?.social ? Object.entries(settings.components?.footer?.social).map(([key, value]) => ({
402
+ logo: <IconSocial kind={key as IconSocialProps["kind"]} />,
403
+ href: value
404
+ })) : undefined}
405
+ links={settings.components?.footer?.links}
406
+ />
407
+ }
408
+
409
+ protected Breadcrumbs() {
410
+ const appearance = useAppearance()
411
+ const hideSidebar = this.useHideSidebar()
412
+
413
+ if (!appearance?.content?.breadcrumbs) {
414
+ return null
415
+ }
416
+
417
+ if (hideSidebar) {
418
+ return null
419
+ }
420
+
421
+ return <FwBreadcrumbs />
422
+ }
423
+
424
+ protected NavLinks() {
425
+ const hideSidebar = this.useHideSidebar()
426
+
427
+ if (hideSidebar) {
428
+ return null
429
+ }
430
+ return <FwNavLinks />
431
+ }
432
+
433
+ protected SubNav() {
434
+ return <FwSubNav />
435
+ }
436
+ }
437
+
438
+ function $BuiltWithXYD() {
439
+ const [colorScheme] = useColorScheme()
440
+
441
+ const fill = colorScheme === "dark" ? "white" : "black"
442
+
443
+ return <a href="https://xyd.dev" target="_blank">
444
+ <xyd-built-with>
445
+ <div part="text">Built with</div>
446
+ <div part="logo">
447
+ <svg xmlns="http://www.w3.org/2000/svg" width={64} height={18} viewBox="0 0 64 18" fill="none">
448
+ <g clipPath="url(#clip0_3_18)">
449
+ <path fillRule="evenodd" clipRule="evenodd"
450
+ d="M12.9447 14.7921H10.6636L14.2428 9.73069L10.8861 4.9901H13.1857L14.9846 7.69901C15.0712 7.84158 15.1577 7.99307 15.2443 8.15347C15.2649 8.1918 15.2854 8.23023 15.3057 8.26877C15.3598 8.37166 15.4048 8.46149 15.4407 8.53824C15.4432 8.54364 15.4458 8.54904 15.4483 8.55446C15.4611 8.51802 15.4751 8.482 15.4904 8.44646C15.5265 8.36139 15.5743 8.26372 15.6337 8.15347C15.7203 7.99307 15.8068 7.84158 15.8934 7.69901L17.6923 4.9901H19.9919L16.6352 9.74852L20.1959 14.7921H17.8963L15.9119 11.8515C15.8254 11.7089 15.7388 11.5485 15.6523 11.3703C15.6317 11.328 15.6113 11.2857 15.5909 11.2434C15.551 11.1606 15.516 11.0873 15.4861 11.0237C15.4734 10.9967 15.4608 10.9696 15.4483 10.9426C15.3988 11.0495 15.3277 11.1921 15.235 11.3703C15.1851 11.4666 15.1319 11.5613 15.0755 11.6542C15.0349 11.7212 14.9922 11.7869 14.9476 11.8515L12.9447 14.7921ZM26.2973 18H24.1831L25.6482 14.2218L21.8464 4.9901H24.0533L26.186 10.5149C26.2523 10.6968 26.3186 10.9065 26.3848 11.1441C26.4058 11.2194 26.426 11.2947 26.4457 11.3703C26.5322 11.703 26.6064 11.9762 26.6682 12.1901C26.7125 11.9988 26.7716 11.76 26.8455 11.4737C26.8544 11.4392 26.8633 11.4047 26.8722 11.3703C26.9588 11.0376 27.0453 10.7525 27.1318 10.5149L29.1347 4.9901H31.2675L26.2973 18ZM33.5671 11.2812V8.51881C33.5671 8.5099 33.5671 8.50099 33.5671 8.49208C33.5713 7.51129 33.8055 6.70741 34.2698 6.08044C34.3394 5.98635 34.4144 5.89603 34.4943 5.8099C35.1125 5.14455 35.9347 4.81188 36.9609 4.81188C37.2432 4.80978 37.5248 4.83873 37.8002 4.89814C38.2353 4.98873 38.637 5.18972 38.9638 5.4802C39.4583 5.92574 39.7056 6.53465 39.7056 7.30693L39.279 6.86139H39.7427L39.687 4.5802V1.78218H41.6899V14.7921H39.7056V12.9208H39.279L39.7056 12.4752C39.7079 12.7346 39.6757 12.9931 39.6097 13.2446C39.5048 13.6495 39.2805 14.0166 38.9638 14.302C38.637 14.5925 38.2353 14.7935 37.8002 14.884C37.5248 14.9435 37.2432 14.9724 36.9609 14.9703C36.5745 14.9741 36.19 14.9196 35.8213 14.8087C35.3085 14.6502 34.8499 14.3611 34.4943 13.9723C33.8762 13.3069 33.5671 12.4099 33.5671 11.2812ZM2.07708 16.7525H0L6.52796 0H8.60504L2.07708 16.7525ZM64 9.92673L55.8771 13.7228V11.905L61.4222 9.35644C61.5629 9.29538 61.7054 9.23815 61.8495 9.18481C61.9412 9.15093 62.0337 9.11902 62.1269 9.08911C62.3475 9.01842 62.5134 8.97113 62.6247 8.94725C62.6257 8.94701 62.6267 8.94677 62.6276 8.94653C62.5884 8.93886 62.5495 8.93007 62.5108 8.92016C62.4265 8.89877 62.3263 8.86931 62.2102 8.83176C62.1731 8.81976 62.136 8.80752 62.0991 8.79505C61.8704 8.71782 61.6447 8.62574 61.4222 8.51881L55.8771 5.9703V4.11683L64 7.91287V9.92673ZM39.687 11.1743V8.60792C39.6886 8.39594 39.6672 8.18438 39.6231 7.97667C39.5654 7.71481 39.4687 7.48414 39.3328 7.28465C39.2758 7.20072 39.2112 7.12171 39.14 7.04852C38.8659 6.76894 38.503 6.58461 38.1083 6.52438C37.956 6.49891 37.8016 6.48645 37.6471 6.48713C37.4323 6.48547 37.218 6.50802 37.0087 6.55432C36.6672 6.62705 36.3545 6.79238 36.1078 7.03069C35.9021 7.23549 35.7516 7.48556 35.6696 7.75907C35.6117 7.94145 35.5751 8.14248 35.5598 8.36216C35.5541 8.44397 35.5514 8.52593 35.5514 8.60792V11.1743C35.55 11.3795 35.5691 11.5844 35.6086 11.7861C35.6563 12.0212 35.734 12.2299 35.8419 12.4122C35.9147 12.5359 36.0041 12.65 36.1078 12.7515C36.3578 12.9928 36.6752 13.1594 37.0217 13.2309C37.2269 13.2751 37.4367 13.2966 37.6471 13.2951C37.8632 13.2969 38.0786 13.2714 38.2878 13.2193C38.6141 13.1386 38.9098 12.9701 39.14 12.7337C39.4759 12.389 39.6571 11.9209 39.6837 11.3295C39.686 11.2778 39.6871 11.226 39.687 11.1743Z"
451
+ fill={fill} stroke={fill} strokeWidth="0.944882" strokeLinecap="round" />
452
+ </g>
453
+ <defs>
454
+ <clipPath id="clip0_3_18">
455
+ <rect width={64} height={18} fill="white" />
456
+ </clipPath>
457
+ </defs>
458
+ </svg>
459
+ </div>
460
+ </xyd-built-with>
461
+ </a>
462
+ }
463
+
464
+ function isDefaultContent(meta: Metadata) {
465
+ return meta?.openapi ||
466
+ meta?.graphql ||
467
+ meta.component === "atlas" ||
468
+ meta.uniform ||
469
+ meta.layout === "page"
470
+ }
471
+