@xyd-js/themes 0.1.1-xyd.2 → 0.1.1-xyd.44

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.
package/src/BaseTheme.tsx CHANGED
@@ -1,11 +1,12 @@
1
1
  import * as React from 'react'
2
+ import { useLocation } from 'react-router'
3
+ import GitHubButton from 'react-github-btn'
2
4
 
5
+ import { TocCard, Text, VideoGuide, useColorScheme } from '@xyd-js/components/writer';
6
+ import { ContentDecorator } from "@xyd-js/components/content";
3
7
  import {
4
8
  LayoutPrimary
5
9
  } from "@xyd-js/components/layouts";
6
- import {
7
- helperContent
8
- } from "@xyd-js/components/content"
9
10
  import {
10
11
  FwNav,
11
12
  FwNavLinks,
@@ -13,82 +14,212 @@ import {
13
14
  FwSubNav,
14
15
  FwSidebarGroups,
15
16
 
16
- useMatchedSubNav
17
+ useMatchedSubNav,
18
+ useMetadata,
19
+ useSettings,
17
20
  } from "@xyd-js/framework/react";
18
21
 
19
- import {BaseThemeSettings} from "./settings";
20
- import {ThemeProps} from "./types";
22
+ import { Theme } from "./Theme";
23
+
24
+ export class BaseTheme extends Theme {
25
+ constructor() {
26
+ super()
27
+
28
+ this.Page = this.Page.bind(this)
29
+ this.Layout = this.Layout.bind(this)
30
+ this.Navbar = this.Navbar.bind(this)
31
+ this.Sidebar = this.Sidebar.bind(this)
32
+ this.Content = this.Content.bind(this)
33
+ this.ContentNav = this.ContentNav.bind(this)
34
+ this.TocTop = this.TocTop.bind(this)
35
+ this.TocBottom = this.TocBottom.bind(this)
36
+ this.PageFooter = this.PageFooter.bind(this)
37
+ }
21
38
 
22
- interface BaseThemeRenderProps {
23
- children: React.ReactNode;
24
- }
39
+ public Page({ children }: { children: React.ReactNode }) {
40
+ const {
41
+ Content: $Content,
42
+ ContentNav: $ContentNav,
43
+ PageFooter: $PageFooter,
44
+ } = this
45
+
46
+ const hideToc = this.useHideToc()
47
+ let contentNav = hideToc ? undefined : <$ContentNav />
25
48
 
26
- const {
27
- Content: HelperContent
28
- } = helperContent()
49
+ return <LayoutPrimary.Page contentNav={contentNav}>
50
+ <$Content>
51
+ {children}
52
+ </$Content>
53
+
54
+ <$PageFooter>
55
+ <$BuiltWithXYD />
56
+ </$PageFooter>
57
+ </LayoutPrimary.Page>
58
+ }
29
59
 
30
- export abstract class BaseTheme extends BaseThemeSettings {
31
- protected render(props: BaseThemeRenderProps): React.JSX.Element {
60
+ public Layout({ children }: { children: React.ReactNode }) {
32
61
  const {
33
62
  Navbar: $Navbar,
34
63
  Sidebar: $Sidebar,
35
- Content: $Content,
36
- ContentNav: $ContentNav
37
64
  } = this
38
65
 
39
- const subheader = useMatchedSubNav() ? <FwSubNav/> : null
40
- const contentNav = this.toc.isHidden() ? undefined : <$ContentNav/>
66
+ const location = useLocation()
67
+ const matchedSubNav = useMatchedSubNav()
68
+ const meta = useMetadata()
69
+
70
+ const subheader = matchedSubNav ? <FwSubNav /> : null
71
+ const sidebar = <$Sidebar />
41
72
 
42
73
  return <LayoutPrimary
43
- header={<$Navbar/>}
44
- subheader={subheader}
45
- aside={<$Sidebar/>}
46
- content={<$Content>{props.children}</$Content>}
47
- contentNav={contentNav}
48
- layoutSize={this?.layout.getSize() as "large" || undefined}
49
- />
74
+ subheader={!!subheader}
75
+ layout={meta?.layout}
76
+ scrollKey={location.pathname}
77
+ >
78
+ <LayoutPrimary.Header
79
+ header={<$Navbar />}
80
+ subheader={subheader}
81
+ />
82
+ <LayoutPrimary.MobileAside
83
+ aside={sidebar}
84
+ />
85
+
86
+ <main part="main">
87
+ <aside part="sidebar">
88
+ {sidebar}
89
+ </aside>
90
+
91
+ {children}
92
+ </main>
93
+ </LayoutPrimary>
50
94
  }
51
95
 
52
- // TODO: it should be protected and passed via withTheme?
53
- protected mergeSettings(props: ThemeProps<BaseThemeSettings>) {
54
- if (props.settings) {
55
- Object.assign(this, props.settings);
56
- }
96
+ public reactContentComponents(): { [component: string]: (props: any) => React.JSX.Element | null } {
97
+ return this.reactContent.components()
57
98
  }
58
99
 
59
100
  protected Navbar() {
60
101
  return <>
61
- <FwNav kind="middle"/>
102
+ <FwNav kind="middle" />
62
103
  </>
63
104
  }
64
105
 
65
106
  protected Sidebar() {
66
- return <FwSidebarGroups
67
- // onePathBehaviour={this?.sidebar?.onePathBehaviour} TODO: finish
68
- clientSideRouting={this?.sidebar?.getClientSideRouting()}
69
- />
107
+ return <FwSidebarGroups />
70
108
  }
71
109
 
72
- protected Content({children}: { children: React.ReactNode }) {
110
+ protected Content({ children }: { children: React.ReactNode }) {
111
+ const meta = useMetadata()
112
+
73
113
  return <>
74
114
  {/*TODO: optional breadcrumbs*/}
75
115
  {/*{props.breadcrumbs ? <FwBreadcrumbs/> : undefined}*/}
76
116
 
77
- <HelperContent>
117
+ <ContentDecorator metaComponent={meta?.component || undefined}>
78
118
  {children}
79
- </HelperContent>
119
+ </ContentDecorator>
80
120
 
81
- <FwNavLinks/>
121
+ <FwNavLinks />
82
122
  </>
83
123
  }
84
124
 
85
125
  protected ContentNav() {
86
- const toc = this?.toc?.get()
126
+ const { TocTop, TocBottom } = this
127
+
128
+ // TODO: toc top and bottom in the future
129
+ return <>
130
+ {/* <TocTop /> */}
131
+
132
+ <div>
133
+ <FwToc />
134
+ </div>
87
135
 
88
- if (toc) {
89
- return toc
136
+ <TocBottom />
137
+ </>
138
+ }
139
+
140
+ protected TocTop() {
141
+ return <div>
142
+ <VideoGuide.Miniature />
143
+ </div>
144
+ }
145
+
146
+ protected TocBottom() {
147
+ const meta = useMetadata()
148
+ const tocCard = meta?.tocCard
149
+ const isEmpty = !tocCard || !tocCard.link || !tocCard.title || !tocCard.description
150
+ if (isEmpty) {
151
+ return null
90
152
  }
91
153
 
92
- return <FwToc/>
154
+ return <div>
155
+ <TocCard
156
+ title={tocCard.title}
157
+ description={tocCard.description}
158
+ href={tocCard.link}
159
+ icon={tocCard.icon}
160
+ />
161
+ </div>
162
+ }
163
+
164
+ protected PageFooter({ children }: { children: React.ReactNode }) {
165
+ const settings = useSettings()
166
+
167
+ let pageFooterBottom: React.ReactNode | null = null
168
+
169
+ if (settings.integrations?.apps?.githubStar) {
170
+ pageFooterBottom = <div part="github-button-container">
171
+ <Text size="small">
172
+ {settings.integrations.apps.githubStar.label}
173
+ </Text>
174
+
175
+ <GitHubButton
176
+ href={settings.integrations.apps.githubStar.href}
177
+ data-icon={settings.integrations.apps.githubStar.dataIcon || "octicon-star"}
178
+ data-size={settings.integrations.apps.githubStar.dataSize || "large"}
179
+ data-show-count={settings.integrations.apps.githubStar.dataShowCount || true}
180
+ aria-label={settings.integrations.apps.githubStar.ariaLabel}
181
+ >
182
+ {settings.integrations.apps.githubStar.title}
183
+ </GitHubButton>
184
+ </div>
185
+
186
+ }
187
+
188
+ return <>
189
+ <xyd-page-footer>
190
+ {children}
191
+
192
+ {/* TODO: in the future */}
193
+ {/* <Surface target="page.footer.bottom"/> */}
194
+ {pageFooterBottom}
195
+
196
+ </xyd-page-footer>
197
+ </>
93
198
  }
94
199
  }
200
+
201
+ function $BuiltWithXYD() {
202
+ const [colorScheme] = useColorScheme()
203
+
204
+ const fill = colorScheme === "dark" ? "white" : "black"
205
+
206
+ return <a href="https://xyd.dev" target="_blank">
207
+ <xyd-built-with>
208
+ <div part="text">Built with</div>
209
+ <div part="logo">
210
+ <svg xmlns="http://www.w3.org/2000/svg" width={64} height={18} viewBox="0 0 64 18" fill="none">
211
+ <g clipPath="url(#clip0_3_18)">
212
+ <path fillRule="evenodd" clipRule="evenodd"
213
+ 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"
214
+ fill={fill} stroke={fill} strokeWidth="0.944882" strokeLinecap="round" />
215
+ </g>
216
+ <defs>
217
+ <clipPath id="clip0_3_18">
218
+ <rect width={64} height={18} fill="white" />
219
+ </clipPath>
220
+ </defs>
221
+ </svg>
222
+ </div>
223
+ </xyd-built-with>
224
+ </a>
225
+ }
package/src/Theme.tsx ADDED
@@ -0,0 +1,58 @@
1
+ import * as React from "react"
2
+ import { useMetadata } from "@xyd-js/framework/react";
3
+ import { Surfaces } from "@xyd-js/framework"
4
+ import { type Theme as ThemeSettings } from "@xyd-js/core"
5
+
6
+ import { ReactContent } from "@xyd-js/components/content";
7
+
8
+ export abstract class Theme {
9
+ constructor() {
10
+ // TODO: !!!better API for this!!!
11
+ this.settings = globalThis.__xydThemeSettings
12
+ this.theme = globalThis.__xydThemeSettings
13
+
14
+ this.surfaces = globalThis.__xydSurfaces
15
+ this.reactContent = globalThis.__xydReactContent
16
+ }
17
+
18
+ protected settings: ThemeSettings
19
+ protected theme: ThemeSettings
20
+ protected readonly reactContent: ReactContent
21
+ protected readonly surfaces: Surfaces
22
+
23
+ public abstract Page({ children }: { children: React.ReactNode })
24
+ public abstract Layout({ children }: { children: React.ReactNode })
25
+ public abstract reactContentComponents(): { [component: string]: (props: any) => React.JSX.Element | null }
26
+
27
+ protected useHideToc() {
28
+ const meta = useMetadata()
29
+
30
+ if (!meta) {
31
+ return false
32
+ }
33
+
34
+ switch (meta.layout) {
35
+ case "wide":
36
+ return true
37
+ case "center":
38
+ return true
39
+ default:
40
+ return false
41
+ }
42
+ }
43
+
44
+ protected useLayoutSize() {
45
+ const meta = useMetadata()
46
+
47
+ if (!meta) {
48
+ return undefined
49
+ }
50
+
51
+ switch (meta.layout) {
52
+ case "wide":
53
+ return "large"
54
+ default:
55
+ return undefined
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,9 @@
1
+ import { createContext } from "react";
2
+
3
+ import { BaseTheme } from "./BaseTheme";
4
+
5
+ export const PageContext = createContext<{
6
+ theme: BaseTheme | null
7
+ }>({
8
+ theme: null
9
+ })
package/src/index.ts CHANGED
@@ -3,13 +3,6 @@ export {
3
3
  } from "./BaseTheme"
4
4
 
5
5
  export {
6
- BaseThemeSettings
7
- } from "./settings"
6
+ type Theme
7
+ } from "./Theme"
8
8
 
9
- export type {
10
- ThemeProps
11
- } from "./types"
12
-
13
- export {
14
- withTheme,
15
- } from "./withTheme"
@@ -1,5 +1,77 @@
1
+ /* CSS Layer Hierarchy
2
+ * @layer reset - Base style resets to normalize browser defaults
3
+ * @layer defaults - Basic component styles for UI, writer, and coder components
4
+ * @layer components - Composite styles built on top of base components
5
+ * @layer fabric - Fabric styles after components
6
+ * @layer templates - Template-specific styles like Atlas
7
+ * @layer themes - Theme-level CSS modifications
8
+ * @layer overrides - Final override layer for styles not applicable in other layers
9
+ */
10
+ @layer reset, defaults, components, fabric,templates, themes, overrides;
11
+
1
12
  @import "@xyd-js/ui/dist/index.css";
13
+ @import "@xyd-js/components/dist/index.css";
2
14
  @import "@xyd-js/atlas/dist/tokens.css";
3
15
  @import "@xyd-js/atlas/dist/index.css";
4
- @import "@xyd-js/components/dist/index.css";
16
+ @import "@xyd-js/atlas/dist/styles.css";
17
+
18
+ @import "./tokens.css";
19
+ @import "./reset.css";
20
+
21
+ @layer defaults {
22
+ body {
23
+ font-size: var(--xyd-font-size-small);
24
+ line-height: var(--xyd-line-height-small);
25
+ color: var(--text-primary);
26
+ background: var(--white);
27
+ }
28
+
29
+ xyd-page-footer {
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ flex-direction: column;
34
+
35
+ [part="github-button-container"] {
36
+ display: flex;
37
+ align-items: center;
38
+ justify-content: center;
39
+ flex-direction: column;
40
+ gap: 8px;
41
+ padding: 15px;
42
+ }
43
+ }
44
+
45
+ xyd-built-with {
46
+ display: flex;
47
+ gap: 8px;
48
+ padding: 15px;
49
+ justify-content: center;
50
+
51
+ [part="text"] {
52
+ font-size: var(--xyd-font-size-xsmall);
53
+ color: var(--dark48);
54
+ letter-spacing: 0.5px;
55
+ }
56
+
57
+ [part="logo"] {
58
+ a {
59
+ margin: 0;
60
+ padding: 0;
61
+ }
62
+
63
+ svg {
64
+ width: 48px;
65
+ height: 100%;
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ @layer components {
72
+ xyd-nav xyd-search-button {
73
+ max-width: 200px;
74
+ }
75
+ }
76
+
5
77
 
@@ -1,55 +1,56 @@
1
1
  /*TODO: in the future not needed cuz every component would have have default styles itself?*/
2
2
 
3
- body {
4
- margin: 0;
5
- }
6
-
7
- ol, ul, menu {
8
- list-style: none;
9
- margin: 0;
10
- padding: 0;
11
- }
12
-
13
- button, input:where([type=button]), input:where([type=reset]), input:where([type=submit]) {
14
- -webkit-appearance: button;
15
- background-color: transparent;
16
- background-image: none;
17
- }
18
-
19
- button, [role=button] {
20
- cursor: pointer;
21
- }
22
-
23
- button, select {
24
- text-transform: none;
25
- }
26
-
27
- button, input, optgroup, select, textarea {
28
- font-family: inherit;
29
- font-feature-settings: inherit;
30
- font-variation-settings: inherit;
31
- font-size: 100%;
32
- font-weight: inherit;
33
- line-height: inherit;
34
- letter-spacing: inherit;
35
- color: inherit;
36
- margin: 0;
37
- padding: 0;
38
- }
39
-
40
- a {
41
- color: inherit;
42
- text-decoration: inherit;
43
- }
44
-
45
- *, :before, :after {
46
- box-sizing: border-box;
47
- border-width: 0;
48
- border-style: solid;
49
- }
50
-
51
- p {
52
- padding: 0;
53
- margin: 0;
54
- }
55
-
3
+ @layer reset {
4
+ body {
5
+ margin: 0;
6
+ }
7
+
8
+ ol, ul, menu {
9
+ list-style: none;
10
+ margin: 0;
11
+ padding: 0;
12
+ }
13
+
14
+ button, input:where([type=button]), input:where([type=reset]), input:where([type=submit]) {
15
+ -webkit-appearance: button;
16
+ background-color: transparent;
17
+ background-image: none;
18
+ }
19
+
20
+ button, [role=button] {
21
+ cursor: pointer;
22
+ }
23
+
24
+ button, select {
25
+ text-transform: none;
26
+ }
27
+
28
+ button, input, optgroup, select, textarea {
29
+ font-family: inherit;
30
+ font-feature-settings: inherit;
31
+ font-variation-settings: inherit;
32
+ font-size: 100%;
33
+ font-weight: inherit;
34
+ line-height: inherit;
35
+ letter-spacing: inherit;
36
+ color: inherit;
37
+ margin: 0;
38
+ padding: 0;
39
+ }
40
+
41
+ a {
42
+ color: inherit;
43
+ text-decoration: inherit;
44
+ }
45
+
46
+ *, :before, :after {
47
+ box-sizing: border-box;
48
+ border-width: 0;
49
+ border-style: solid;
50
+ }
51
+
52
+ p {
53
+ padding: 0;
54
+ margin: 0;
55
+ }
56
+ }