@xyd-js/components 0.1.0-xyd.7 → 0.1.0-xyd.94

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 (251) hide show
  1. package/.idea/git_toolbox_blame.xml +6 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/.idea/xyd-components.iml +12 -0
  5. package/CHANGELOG.md +718 -0
  6. package/LICENSE +21 -0
  7. package/TODO.md +1 -0
  8. package/content.ts +0 -2
  9. package/dist/CTABanner-Bc77pnms.js +2 -0
  10. package/dist/CTABanner-Bc77pnms.js.map +1 -0
  11. package/dist/CTABanner-DzO62aGj.js +2 -0
  12. package/dist/CTABanner-DzO62aGj.js.map +1 -0
  13. package/dist/CodeSample-BWPDgd2G.js +2 -0
  14. package/dist/CodeSample-BWPDgd2G.js.map +1 -0
  15. package/dist/CodeSample-DLnR-knP.js +2 -0
  16. package/dist/CodeSample-DLnR-knP.js.map +1 -0
  17. package/dist/HomeView-C8QlNdKh.js +2 -0
  18. package/dist/HomeView-C8QlNdKh.js.map +1 -0
  19. package/dist/HomeView-ZAP5saNy.js +2 -0
  20. package/dist/HomeView-ZAP5saNy.js.map +1 -0
  21. package/dist/Icon-BESh23UN.js +2 -0
  22. package/dist/Icon-BESh23UN.js.map +1 -0
  23. package/dist/Icon-xNucOqd2.js +2 -0
  24. package/dist/Icon-xNucOqd2.js.map +1 -0
  25. package/dist/Text-CfN9RkYA.js +2 -0
  26. package/dist/Text-CfN9RkYA.js.map +1 -0
  27. package/dist/Text-DKycD2zu.js +2 -0
  28. package/dist/Text-DKycD2zu.js.map +1 -0
  29. package/dist/Update-0XruJHjj.js +2 -0
  30. package/dist/Update-0XruJHjj.js.map +1 -0
  31. package/dist/Update-DKOAw8p9.js +2 -0
  32. package/dist/Update-DKOAw8p9.js.map +1 -0
  33. package/dist/VideoGuide-BUyomFVz.js +2 -0
  34. package/dist/VideoGuide-BUyomFVz.js.map +1 -0
  35. package/dist/VideoGuide-B_iUKKv7.js +2 -0
  36. package/dist/VideoGuide-B_iUKKv7.js.map +1 -0
  37. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js +4 -0
  38. package/dist/_rollupPluginBabelHelpers-CxSUtGup.js.map +1 -0
  39. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js +4 -0
  40. package/dist/_rollupPluginBabelHelpers-DZ-ucadG.js.map +1 -0
  41. package/dist/brand.d.ts +9 -9
  42. package/dist/brand.js +1 -1
  43. package/dist/brand.js.map +1 -1
  44. package/dist/coder/themes/cosmo-light.js.map +1 -1
  45. package/dist/coder.d.ts +29 -9
  46. package/dist/coder.js +1 -1
  47. package/dist/coder.js.map +1 -1
  48. package/dist/content.d.ts +268 -204
  49. package/dist/content.js +1 -1
  50. package/dist/content.js.map +1 -1
  51. package/dist/index.css +267 -216
  52. package/dist/layouts.d.ts +20 -21
  53. package/dist/layouts.js +1 -1
  54. package/dist/layouts.js.map +1 -1
  55. package/dist/pages.js +1 -1
  56. package/dist/pages.js.map +1 -1
  57. package/dist/system.d.ts +10 -0
  58. package/dist/system.js +2 -0
  59. package/dist/system.js.map +1 -0
  60. package/dist/tslib.es6-DyL9kPq9.js +2 -0
  61. package/dist/{tslib.es6-DDIOdJiV.js.map → tslib.es6-DyL9kPq9.js.map} +1 -1
  62. package/dist/tslib.es6-Hqk-Mdr9.js +2 -0
  63. package/dist/{tslib.es6-DUrRPhZd.js.map → tslib.es6-Hqk-Mdr9.js.map} +1 -1
  64. package/dist/views.js +1 -1
  65. package/dist/writer.d.ts +411 -78
  66. package/dist/writer.js +1 -1
  67. package/dist/writer.js.map +1 -1
  68. package/docs/.nojekyll +1 -0
  69. package/docs/assets/hierarchy.js +1 -0
  70. package/docs/assets/highlight.css +22 -0
  71. package/docs/assets/icons.js +18 -0
  72. package/docs/assets/icons.svg +1 -0
  73. package/docs/assets/main.js +60 -0
  74. package/docs/assets/navigation.js +1 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1640 -0
  77. package/docs/functions/GuideCard.html +6 -0
  78. package/docs/hierarchy.html +1 -0
  79. package/docs/index.html +2 -0
  80. package/docs/interfaces/GuideCardProps.html +18 -0
  81. package/docs/modules.html +1 -0
  82. package/index.ts +0 -1
  83. package/package.json +13 -18
  84. package/project.json +677 -0
  85. package/rollup.config.js +32 -3
  86. package/src/brand/Button/Button.styles.tsx +28 -0
  87. package/src/brand/Button/Button.tsx +3 -35
  88. package/src/brand/CTABanner/CTABanner.styles.tsx +80 -0
  89. package/src/brand/CTABanner/CTABanner.tsx +34 -112
  90. package/src/brand/Footer/Footer.styles.tsx +18 -0
  91. package/src/brand/Footer/Footer.tsx +4 -24
  92. package/src/brand/TODO.md +1 -0
  93. package/src/coder/Code/Code.styles.tsx +134 -35
  94. package/src/coder/Code/Code.tsx +131 -40
  95. package/src/coder/Code/CodeLoader.tsx +4 -4
  96. package/src/coder/Code/annotations.tsx +28 -8
  97. package/src/coder/Code/highlight.ts +38 -0
  98. package/src/coder/Code/index.ts +2 -1
  99. package/src/coder/CodeCopy/{CodeCopy.style.tsx → CodeCopy.styles.tsx} +6 -6
  100. package/src/coder/CodeCopy/CodeCopy.tsx +6 -6
  101. package/src/coder/CodeSample/CodeSample.tsx +83 -27
  102. package/src/coder/CodeTabs/CodeTabs.styles.tsx +99 -78
  103. package/src/coder/CodeTabs/CodeTabs.tsx +71 -56
  104. package/src/coder/CodeTheme/CodeTheme.tsx +89 -49
  105. package/src/coder/CodeTheme/index.ts +0 -1
  106. package/src/coder/CoderProvider.tsx +26 -0
  107. package/src/coder/index.ts +8 -4
  108. package/src/content/ContentDecoator.styles.tsx +113 -0
  109. package/src/content/ContentDecorator.tsx +17 -0
  110. package/src/content/GridDecorator.styles.tsx +67 -0
  111. package/src/content/GridDecorator.tsx +21 -0
  112. package/src/content/ReactContent.tsx +575 -0
  113. package/src/content/index.ts +10 -2
  114. package/src/icons/index.ts +0 -0
  115. package/src/kit/Loader/Loader.styles.tsx +53 -0
  116. package/src/kit/Loader/Loader.tsx +22 -0
  117. package/src/kit/TODO.md +2 -0
  118. package/src/kit/index.ts +1 -0
  119. package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +263 -278
  120. package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +173 -96
  121. package/src/layouts/LayoutPrimary/index.ts +0 -2
  122. package/src/layouts/index.ts +0 -7
  123. package/src/pages/HomePage/HomePage.styles.tsx +16 -0
  124. package/src/pages/HomePage/HomePage.tsx +7 -21
  125. package/src/pages/TODO.md +1 -0
  126. package/src/system/SearchButton/SearchButton.styles.tsx +86 -0
  127. package/src/system/SearchButton/SearchButton.tsx +116 -0
  128. package/src/system/SearchButton/index.ts +1 -0
  129. package/src/system/index.ts +1 -0
  130. package/src/utils/useStyle.ts +19 -0
  131. package/src/views/HomeView/HomeView.styles.tsx +37 -0
  132. package/src/views/HomeView/HomeView.tsx +5 -45
  133. package/src/views/TODO.md +1 -0
  134. package/src/writer/Anchor/Anchor.styles.tsx +11 -0
  135. package/src/writer/Anchor/Anchor.tsx +51 -0
  136. package/src/writer/Anchor/index.tsx +1 -0
  137. package/src/writer/Badge/Badge.styles.tsx +39 -28
  138. package/src/writer/Badge/Badge.tsx +37 -20
  139. package/src/writer/Banner/Banner.styles.tsx +91 -0
  140. package/src/writer/Banner/Banner.tsx +70 -0
  141. package/src/writer/Banner/index.ts +1 -0
  142. package/src/writer/Blockquote/Blockquote.styles.tsx +4 -4
  143. package/src/writer/Blockquote/Blockquote.tsx +6 -3
  144. package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +22 -21
  145. package/src/writer/Breadcrumbs/Breadcrumbs.tsx +19 -13
  146. package/src/writer/Button/Button.styles.tsx +137 -0
  147. package/src/writer/Button/Button.tsx +75 -0
  148. package/src/writer/Button/index.ts +2 -0
  149. package/src/writer/Callout/Callout.styles.tsx +29 -40
  150. package/src/writer/Callout/Callout.tsx +31 -16
  151. package/src/writer/Card/Card.styles.tsx +47 -0
  152. package/src/writer/Card/Card.tsx +69 -0
  153. package/src/writer/Card/index.ts +1 -0
  154. package/src/writer/Code/Code.styles.tsx +10 -11
  155. package/src/writer/Code/Code.tsx +7 -4
  156. package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +172 -0
  157. package/src/writer/ColorSchemeButton/index.ts +1 -0
  158. package/src/writer/Details/Details.styles.tsx +84 -84
  159. package/src/writer/Details/Details.tsx +71 -51
  160. package/src/writer/Example/index.tsx +5 -0
  161. package/src/writer/GuideCard/GuideCard.styles.tsx +108 -107
  162. package/src/writer/GuideCard/GuideCard.tsx +72 -37
  163. package/src/writer/Heading/Heading.styles.tsx +69 -49
  164. package/src/writer/Heading/Heading.tsx +92 -22
  165. package/src/writer/Hr/Hr.styles.tsx +5 -5
  166. package/src/writer/Hr/Hr.tsx +3 -6
  167. package/src/writer/Icon/Icon.tsx +48 -0
  168. package/src/writer/Icon/index.ts +1 -0
  169. package/src/writer/Image/Image.styles.tsx +9 -0
  170. package/src/writer/Image/Image.tsx +19 -0
  171. package/src/writer/Image/index.ts +1 -0
  172. package/src/writer/List/List.styles.tsx +47 -0
  173. package/src/writer/List/List.tsx +29 -0
  174. package/src/writer/List/index.ts +4 -0
  175. package/src/writer/NavLinks/NavLinks.styles.ts +23 -24
  176. package/src/writer/NavLinks/NavLinks.tsx +66 -19
  177. package/src/writer/Pre/Pre.styles.tsx +5 -5
  178. package/src/writer/Pre/Pre.tsx +4 -3
  179. package/src/writer/Steps/Steps.styles.tsx +14 -12
  180. package/src/writer/Steps/Steps.tsx +39 -10
  181. package/src/writer/Table/Table.styles.tsx +62 -30
  182. package/src/writer/Table/Table.tsx +121 -11
  183. package/src/writer/Table/index.ts +0 -11
  184. package/src/writer/Tabs/Tabs.styles.tsx +63 -70
  185. package/src/writer/Tabs/Tabs.tsx +31 -29
  186. package/src/writer/Text/Text.styles.tsx +66 -0
  187. package/src/writer/Text/Text.tsx +79 -0
  188. package/src/writer/Text/index.ts +3 -0
  189. package/src/writer/TocCard/TocCard.module.css +44 -0
  190. package/src/writer/TocCard/TocCard.tsx +42 -0
  191. package/src/writer/TocCard/index.ts +3 -0
  192. package/src/writer/UnderlineNav/Tabs.tsx +51 -0
  193. package/src/writer/UnderlineNav/TabsPrimary.styles.tsx +184 -0
  194. package/src/writer/UnderlineNav/TabsPrimary.tsx +209 -0
  195. package/src/writer/UnderlineNav/TabsSecondary.styles.tsx +77 -0
  196. package/src/writer/UnderlineNav/TabsSecondary.tsx +171 -0
  197. package/src/writer/UnderlineNav/UnderlineNav.styles.tsx +181 -45
  198. package/src/writer/UnderlineNav/UnderlineNav.tsx +258 -23
  199. package/src/writer/UnderlineNav/index.ts +2 -1
  200. package/src/writer/UnderlineNav/useValueChange.ts +60 -0
  201. package/src/writer/Update/Update.styles.tsx +33 -0
  202. package/src/writer/Update/Update.tsx +37 -0
  203. package/src/writer/Update/index.ts +1 -0
  204. package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
  205. package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
  206. package/src/writer/VideoGuide/index.ts +1 -0
  207. package/src/writer/index.ts +23 -1
  208. package/tsconfig.json +11 -6
  209. package/types.d.ts +50 -0
  210. package/writer.ts +1 -1
  211. package/dist/CTABanner-BrdYlhnD.js +0 -2
  212. package/dist/CTABanner-BrdYlhnD.js.map +0 -1
  213. package/dist/CTABanner-XQNnnpUx.js +0 -2
  214. package/dist/CTABanner-XQNnnpUx.js.map +0 -1
  215. package/dist/CodeSample-Cp42Adjc.js +0 -2
  216. package/dist/CodeSample-Cp42Adjc.js.map +0 -1
  217. package/dist/CodeSample-DxPp80ID.js +0 -2
  218. package/dist/CodeSample-DxPp80ID.js.map +0 -1
  219. package/dist/HomeView-BN9mZXh9.js +0 -2
  220. package/dist/HomeView-BN9mZXh9.js.map +0 -1
  221. package/dist/HomeView-BVaaV0uE.js +0 -2
  222. package/dist/HomeView-BVaaV0uE.js.map +0 -1
  223. package/dist/UnderlineNav-Bs7Ot9Ch.js +0 -2
  224. package/dist/UnderlineNav-Bs7Ot9Ch.js.map +0 -1
  225. package/dist/UnderlineNav-C2aEVraN.js +0 -2
  226. package/dist/UnderlineNav-C2aEVraN.js.map +0 -1
  227. package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js +0 -2
  228. package/dist/_rollupPluginBabelHelpers-BMmCG_qQ.js.map +0 -1
  229. package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js +0 -2
  230. package/dist/_rollupPluginBabelHelpers-DsEzE6Ab.js.map +0 -1
  231. package/dist/index-BVUz77Tm.js +0 -2
  232. package/dist/index-BVUz77Tm.js.map +0 -1
  233. package/dist/index-jxd3nv2J.js +0 -2
  234. package/dist/index-jxd3nv2J.js.map +0 -1
  235. package/dist/tslib.es6-DDIOdJiV.js +0 -2
  236. package/dist/tslib.es6-DUrRPhZd.js +0 -2
  237. package/src/content/Anchor/Anchor.tsx +0 -63
  238. package/src/content/Anchor/index.tsx +0 -3
  239. package/src/content/Content/Content.tsx +0 -21
  240. package/src/content/Content/index.tsx +0 -3
  241. package/src/content/Content.tsx +0 -180
  242. package/src/content/Subtitle/Subtitle.tsx +0 -21
  243. package/src/content/Subtitle/index.tsx +0 -3
  244. package/src/layouts/Layout.styles.tsx +0 -151
  245. package/src/layouts/Layout.tsx +0 -121
  246. package/src/ui/Loader/Loader.styles.tsx +0 -52
  247. package/src/ui/Loader/Loader.tsx +0 -26
  248. package/src/ui/index.ts +0 -1
  249. package/src/writer/Icon/index.tsx +0 -355
  250. package/src/writer/Table/TableV2.styles.tsx +0 -117
  251. package/src/writer/Table/TableV2.tsx +0 -83
@@ -1,100 +1,121 @@
1
- import {css} from "@linaria/core";
1
+ import { css } from "@linaria/core";
2
2
 
3
- export const $sample = {
4
- host: css`
3
+ export const CodeTabsHost = css`
4
+ display: block;
5
+ `
6
+
7
+ export const CodeTabsRoot = css`
8
+ @layer defaults {
5
9
  overflow: hidden;
6
10
  min-width: 0;
7
- //flex: 1 1 0;
8
- //max-width: 512px;
9
11
 
10
- border: 1px solid rgb(236, 236, 241);
12
+ border: 1px solid var(--xyd-codetabs-border-color);
11
13
  border-radius: 16px;
12
- `,
13
- pre$$single: css`
14
- border: none !important; // TODO: bad, find another way - CodeSample another kind?
15
- `
16
- }
17
-
18
- export const $languages = {
19
- host: css`
14
+
15
+ &[data-single="true"] [part="pre"] {
16
+ border: none;
17
+ }
18
+
19
+ &[data-nodescription="true"] {
20
+ xyd-codetabs-languages [part="languages-list"] {
21
+ justify-content: flex-start;
22
+ }
23
+ }
24
+ }
25
+ `;
26
+
27
+ export const CodeTabsLanguagesHost = css`
28
+ @layer defaults {
20
29
  display: flex;
21
30
  flex: 1 1 0%;
22
- //padding: 8px 0px;
23
31
 
24
- background: linear-gradient(45deg, rgb(247, 247, 248) 0%, rgb(247, 247, 248) 100%) !important;
32
+ background: var(--xyd-codetabs-bgcolor);
25
33
 
26
34
  border-top-right-radius: 10px;
27
35
  border-top-left-radius: 10px;
28
36
  border-bottom: 0px;
29
37
 
30
38
  min-width: 0;
31
- `,
32
- host$$single: css`
33
- height: 0;
34
- `,
35
- list: css`
36
- display: flex;
37
- flex-grow: 1;
38
- justify-content: end;
39
- gap: 8px;
40
- padding: 0 10px;
41
- `,
42
- button: css`
43
- all: unset;
44
39
 
45
- cursor: pointer;
40
+ font-weight: var(--xyd-font-weight-semibold);
41
+ font-size: var(--xyd-font-size-xsmall);
46
42
 
47
- display: flex;
48
- align-items: center;
49
- justify-content: center;
43
+ &[data-single="true"] {
44
+ height: 0;
45
+ }
50
46
 
51
- border-radius: 6px;
52
- padding: 6px;
47
+ [part="description"] {
48
+ display: flex;
49
+ align-items: center;
50
+ gap: 4px;
53
51
 
54
- font-size: 14px;
55
- color: rgb(53, 55, 64);
56
-
57
- &[data-state="active"] {
58
- color: rgb(112, 81, 212);
59
- border-bottom: 1px solid rgb(112, 81, 212);
60
- border-bottom-left-radius: 0px;
61
- border-bottom-right-radius: 0px;
52
+ color: var(--xyd-codetabs-color);
53
+
54
+ margin-left: 4px;
55
+ margin-right: 4px;
62
56
  }
63
-
64
- &:hover {
65
- transition: ease-in 0.1s;
66
- background: #e3e3eb;
57
+
58
+ [part="description-item"] {
59
+ display: flex;
60
+ padding-left: 16px;
61
+ padding-right: 16px;
62
+ flex: 1 1 0%;
63
+ gap: 16px;
64
+ border-radius: 4px;
67
65
  }
68
- `,
69
- description: css`
70
- display: flex;
71
- align-items: center;
72
- gap: 4px;
73
66
 
74
- font-size: 14px;
75
- color: rgb(53, 55, 64);
76
-
77
- margin-left: 4px;
78
- margin-right: 4px;
79
- `,
80
- description$item: css`
81
- display: flex;
82
- padding-left: 16px;
83
- padding-right: 16px;
84
- flex: 1 1 0%;
85
- gap: 16px;
86
- border-radius: 4px;
87
- `,
88
- copy: css`
89
- display: flex;
90
- padding-left: 8px;
91
- padding-right: 8px;
92
- align-items: center;
93
- `,
94
- copy$$single: css`
95
- top: 17px;
96
- position: relative;
97
- right: 5px;
98
- `
99
- }
67
+ [part="copy"] {
68
+ display: none;
69
+ }
70
+
71
+ [part="languages-list"] {
72
+ display: flex;
73
+ flex-grow: 1;
74
+ justify-content: end;
75
+ gap: 8px;
76
+ padding: 0 10px;
77
+ }
78
+
79
+ [part="language-trigger"] {
80
+ all: unset;
81
+
82
+ cursor: pointer;
83
+
84
+ display: flex;
85
+ align-items: center;
86
+ justify-content: center;
87
+
88
+ border-radius: 6px;
89
+ padding: 6px;
90
+
91
+ color: var(--xyd-codetabs-color);
92
+
93
+ &[data-state="active"] {
94
+ color: var(--xyd-codetabs-color--active);
95
+ border-bottom: 1px solid var(--xyd-codetabs-color--active);
96
+ border-bottom-left-radius: 0px;
97
+ border-bottom-right-radius: 0px;
98
+ }
99
+
100
+ &:hover {
101
+ transition: ease-in 0.1s;
102
+ background: var(--xyd-codetabs-color--hover);
103
+ }
104
+ }
105
+
106
+ [part="copy"] {
107
+ display: flex;
108
+ padding-left: 8px;
109
+ padding-right: 8px;
110
+ align-items: center;
111
+ }
112
+ &[data-single="true"] [part="copy"] {
113
+ top: 17px;
114
+ position: relative;
115
+ right: 5px;
116
+ }
117
+ }
118
+ `;
119
+
120
+
100
121
 
@@ -1,5 +1,5 @@
1
- import React, {} from "react";
2
- import * as TabsPrimitive from "@radix-ui/react-tabs";
1
+ import React, { useState, useEffect } from "react";
2
+ import {Tabs as TabsPrimitive} from "radix-ui"; // TODO: remove and use separation
3
3
  import {
4
4
  HighlightedCode,
5
5
  } from "codehike/code"
@@ -7,44 +7,57 @@ import {
7
7
  import {
8
8
  CodeCopy,
9
9
  } from "../CodeCopy";
10
- import {
11
- $sample,
12
- $languages,
13
- } from "./CodeTabs.styles.tsx"; // TODO: style by highlighted?
10
+ import * as cn from "./CodeTabs.styles"; // TODO: style by highlighted?
14
11
 
15
12
  export interface CodeTabsProps {
16
13
  description: string;
17
14
  highlighted: HighlightedCode[]
18
- size?: "full"
15
+ className?: string
16
+ controlByMeta?: boolean // TODO: BETTER IN THE FUTURE
19
17
  }
20
18
 
21
19
  export function withCodeTabs(PreComponent) {
22
20
  return function CodeTabs(props: CodeTabsProps) {
23
- const isSingle = props.highlighted.length === 1 && !props.description
21
+ const isSingle = props?.highlighted?.length === 1 && !props.description
22
+ const defaultValue = props.highlighted[0]?.meta || props.highlighted[0]?.lang
23
+ const [activeTab, setActiveTab] = useState(defaultValue)
24
+
25
+ // Reset active tab when highlighted prop changes
26
+ useEffect(() => {
27
+ setActiveTab(defaultValue)
28
+ }, [defaultValue])
29
+
30
+ if (props?.highlighted?.length === 0) {
31
+ return null
32
+ }
33
+
24
34
 
25
35
  return (
26
- <TabsPrimitive.Root
27
- className={$sample.host}
28
- style={props.highlighted[0]?.style}
29
- defaultValue={props.highlighted[0]?.meta}
30
- >
31
- <$LanguageTabSwitcher
32
- description={props.description}
33
- highlighted={props.highlighted}
34
- />
36
+ <xyd-codetabs className={`${cn.CodeTabsHost} ${props.className || ""}`}>
37
+ <TabsPrimitive.Root
38
+ part="root"
39
+ data-single={String(isSingle)}
40
+ data-nodescription={!props.description ? "true" : undefined}
41
+ className={`${cn.CodeTabsRoot}`}
42
+ style={props.highlighted[0]?.style}
43
+ value={activeTab}
44
+ onValueChange={setActiveTab}
45
+ >
46
+ <$LanguageTabSwitcher
47
+ description={props.description}
48
+ highlighted={props.highlighted}
49
+ />
35
50
 
36
- {props.highlighted?.map((codeblock, i) => (
37
- <TabsPrimitive.Content value={codeblock.meta} key={i}>
38
- <PreComponent
39
- style={codeblock?.style || codeblock?.style}
40
- codeblock={codeblock}
41
- className={`
42
- ${isSingle && $sample.pre$$single}
43
- `}
44
- />
45
- </TabsPrimitive.Content>
46
- ))}
47
- </TabsPrimitive.Root>
51
+ {props.highlighted?.map((codeblock, i) => (
52
+ <TabsPrimitive.Content value={codeblock.meta || codeblock.lang} key={i}>
53
+ <PreComponent
54
+ style={codeblock?.style || codeblock?.style}
55
+ codeblock={codeblock}
56
+ />
57
+ </TabsPrimitive.Content>
58
+ ))}
59
+ </TabsPrimitive.Root>
60
+ </xyd-codetabs>
48
61
  )
49
62
  }
50
63
  }
@@ -55,44 +68,46 @@ interface LanguageTabSwitcherProps {
55
68
  }
56
69
 
57
70
  function $LanguageTabSwitcher(props: LanguageTabSwitcherProps) {
58
- const isSingle = props.highlighted.length === 1 && !props.description
71
+ const isSingle = props?.highlighted?.length === 1 && !props.description
59
72
 
60
- return <div className={`
61
- ${$languages.host}
62
- ${isSingle && $languages.host$$single}
73
+ const highlighted = props.highlighted.filter((item, index, self) =>
74
+ index === self.findIndex((t) => (t.meta || t.lang) === (item.meta || item.lang))
75
+ );
76
+ return <xyd-codetabs-languages
77
+ data-single={String(isSingle)}
78
+ className={`
79
+ ${cn.CodeTabsLanguagesHost}
63
80
  `}>
64
- <$Description description={props.description}/>
65
81
 
66
- <TabsPrimitive.List className={$languages.list}>
67
- {props.highlighted?.map(({meta}, i) => {
82
+ {
83
+ props.description && <div part="description">
84
+ <div part="description-item">
85
+ {props.description}
86
+ </div>
87
+ </div>
88
+ }
89
+
90
+ <TabsPrimitive.List part="languages-list">
91
+ {highlighted?.map(({ meta, lang }, i) => {
68
92
  if (isSingle) {
69
93
  return null
70
94
  }
71
- return <TabsPrimitive.Trigger value={meta!} key={i} className={$languages.button}>
72
- {meta}
95
+ return <TabsPrimitive.Trigger
96
+ part="language-trigger"
97
+ value={meta || lang}
98
+ key={i}
99
+ >
100
+ {meta || lang}
73
101
  </TabsPrimitive.Trigger>
74
102
  })}
75
103
  </TabsPrimitive.List>
76
104
 
77
- <div className={`
78
- ${$languages.copy}
79
- ${isSingle && $languages.copy$$single}
80
- `}>
81
- {props.highlighted?.map((codeblock, i) => (
82
- <TabsPrimitive.Content value={codeblock.meta!} asChild key={i}>
83
- <CodeCopy text={codeblock.value}/>
105
+ <div part="copy">
106
+ {highlighted?.map((codeblock, i) => (
107
+ <TabsPrimitive.Content value={codeblock.meta || codeblock.lang} asChild key={i}>
108
+ <CodeCopy text={codeblock.value} />
84
109
  </TabsPrimitive.Content>
85
110
  ))}
86
111
  </div>
87
- </div>
112
+ </xyd-codetabs-languages>
88
113
  }
89
-
90
- function $Description(props: { description: string }) {
91
- return <div className={$languages.description}>
92
- <div className={$languages.description$item}>
93
- {props.description}
94
- </div>
95
- </div>
96
- }
97
-
98
-
@@ -1,79 +1,119 @@
1
- import React, { createContext, useState, use, useEffect } from "react";
1
+ import React, { createContext, useState, use, useEffect, Suspense } from "react";
2
2
  import { Theme } from "@code-hike/lighter";
3
3
  import { highlight } from "codehike/code";
4
4
  import type { HighlightedCode } from "codehike/code";
5
5
 
6
6
  import defaultTheme from "../themes/cosmo-light"
7
- import { Loader } from "../../ui";
7
+ import { Loader } from "../../kit";
8
8
 
9
9
  export interface CodeThemeProps {
10
- codeblocks: CodeThemeBlockProps[];
11
- children: React.ReactNode;
12
- theme?: Theme;
10
+ codeblocks?: CodeThemeBlockProps[];
11
+ theme?: Theme
12
+ children: React.ReactNode;
13
13
  }
14
14
 
15
15
  export interface CodeThemeBlockProps {
16
- /** This is the raw code. May include annotation comments. */
17
- value: string;
18
- /** The programming language. */
19
- lang: string;
20
- /** Metadata string (the content after the language name in a markdown codeblock). */
21
- meta: string;
16
+ /** This is the raw code. May include annotation comments. */
17
+ value: string;
18
+ /** The programming language. */
19
+ lang: string;
20
+ /** Metadata string (the content after the language name in a markdown codeblock). */
21
+ meta: string;
22
+
23
+ /** The highlighted code. */
24
+ highlighted?: HighlightedCode
22
25
  }
23
26
 
24
27
  const CodeThemeProvider = createContext<{
25
- highlighted: HighlightedCode[];
28
+ highlighted: HighlightedCode[];
26
29
  }>({
27
- highlighted: [],
30
+ highlighted: [],
28
31
  });
29
32
 
30
33
  export function useCodeTheme() {
31
- return use(CodeThemeProvider);
34
+ return use(CodeThemeProvider);
32
35
  }
33
36
 
37
+ // TODO: lazy-loading - some codeblocks on server and another on client
38
+ // TODO: lazdy client loading only on specific codeblock
34
39
  export function CodeTheme(props: CodeThemeProps) {
35
- const highlighted = use(
36
- fetchHighlight(props.codeblocks, props.theme || defaultTheme)
37
- );
38
-
39
- return (
40
- <CodeThemeProvider
41
- value={{
42
- highlighted,
43
- }}
44
- >
45
- {props.children}
46
- </CodeThemeProvider>
47
- );
48
- }
40
+ // Initialize with server-side highlighted codeblocks
41
+ const [highlighted, setHighlighted] = useState<HighlightedCode[] | undefined>(initializeHighlighted(props.codeblocks));
42
+ const [clientSideFetch, setClientSideFetch] = useState(true)
49
43
 
50
- // `CodeThemeSync` ?
51
- export function CodeThemeCSR(props: CodeThemeProps) {
52
- const [highlighted, setHighlighted] = useState<HighlightedCode[]>([]);
44
+ useEffect(() => {
45
+ setHighlighted(initializeHighlighted(props.codeblocks))
46
+ }, [props.codeblocks])
53
47
 
54
- useEffect(() => {
55
- fetchHighlight(props.codeblocks, props.theme || defaultTheme).then(
56
- setHighlighted
57
- );
58
- }, [props.codeblocks, props.theme]);
48
+ useEffect(() => {
49
+ if (!props.codeblocks) {
50
+ return;
51
+ }
52
+
53
+ // Check if we need to highlight any codeblocks
54
+ const needsHighlighting = props.codeblocks.some(
55
+ codeblock => !codeblock.highlighted || !codeblock.highlighted.tokens
56
+ );
57
+
58
+ if (needsHighlighting) {
59
+ clientSideHighlight();
60
+ }
61
+ }, [props.codeblocks]);
62
+
63
+ function initializeHighlighted(codeblocks: any) {
64
+ if (!codeblocks) return [];
59
65
 
60
- if (!highlighted) {
61
- return <Loader />;
62
- }
66
+ return codeblocks.map(codeblock => {
67
+ if (codeblock.highlighted && codeblock.highlighted.tokens) {
68
+ return {
69
+ ...codeblock.highlighted,
70
+ meta: codeblock.highlighted?.meta || codeblock.meta,
71
+ };
72
+ }
63
73
 
64
- return (
65
- <CodeThemeProvider
66
- value={{
67
- highlighted,
68
- }}
74
+ return null
75
+ }).filter(Boolean) as HighlightedCode[]
76
+ }
77
+
78
+ async function clientSideHighlight() {
79
+ if (!props.codeblocks) {
80
+ return;
81
+ }
82
+
83
+ const allHighlighted = props.codeblocks.every(codeblock => codeblock.highlighted)
84
+ if (allHighlighted) {
85
+ return;
86
+ }
87
+
88
+ const newHighlighted = await fetchHighlight(props.codeblocks, props.theme || defaultTheme);
89
+ setHighlighted(newHighlighted)
90
+
91
+ setClientSideFetch(false)
92
+ }
93
+
94
+ const withTheme = <CodeThemeProvider
95
+ value={{
96
+ highlighted: highlighted || [],
97
+ }}
69
98
  >
70
- {props.children}
99
+ {props.children}
71
100
  </CodeThemeProvider>
72
- );
101
+
102
+ const allHighlighted = props.codeblocks?.every(codeblock => codeblock.highlighted)
103
+ if (allHighlighted) {
104
+ return withTheme
105
+ }
106
+
107
+ if (clientSideFetch) {
108
+ return <Loader />
109
+ }
110
+
111
+ return withTheme
73
112
  }
74
113
 
114
+ // TODO: own server with grammars (codehike)
75
115
  async function fetchHighlight(codeblocks: CodeThemeBlockProps[], theme: Theme) {
76
- return await Promise.all(
77
- codeblocks?.map((codeblock) => highlight(codeblock, theme))
78
- );
116
+ return await Promise.all(
117
+ codeblocks?.map((codeblock) => highlight(codeblock, theme))
118
+ );
79
119
  }
@@ -2,7 +2,6 @@ export type {CodeThemeProps, CodeThemeBlockProps} from "./CodeTheme";
2
2
 
3
3
  export {
4
4
  CodeTheme,
5
- CodeThemeCSR,
6
5
 
7
6
  useCodeTheme
8
7
  } from "./CodeTheme";
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { createContext, useContext } from "react";
3
+
4
+ const CoderContext = createContext<{
5
+ lines?: boolean
6
+ scroll?: boolean
7
+ }>({
8
+ lines: undefined,
9
+ scroll: undefined,
10
+ })
11
+
12
+
13
+ interface CoderProviderProps {
14
+ children: React.ReactNode
15
+
16
+ lines?: boolean
17
+
18
+ scroll?: boolean
19
+ }
20
+ export function CoderProvider({ children, lines, scroll }: CoderProviderProps) {
21
+ return <CoderContext.Provider value={{ lines, scroll }}>{children}</CoderContext.Provider>
22
+ }
23
+
24
+ export function useCoder() {
25
+ return useContext(CoderContext)
26
+ }
@@ -8,12 +8,13 @@ export {
8
8
  Code,
9
9
  CodeLoader,
10
10
 
11
+ highlightAsync,
11
12
  highlight
12
13
  } from "./Code"
13
14
  //
14
15
 
15
- export type {CodeSampleProps} from "./CodeSample";
16
- export {CodeSample} from "./CodeSample";
16
+ export type { CodeSampleProps } from "./CodeSample";
17
+ export { CodeSample } from "./CodeSample";
17
18
  //
18
19
 
19
20
  export type {
@@ -24,10 +25,13 @@ export {
24
25
  } from "./CodeTabs";
25
26
  //
26
27
 
27
- export type {CodeThemeProps, CodeThemeBlockProps} from "./CodeTheme";
28
+ export type { CodeThemeProps, CodeThemeBlockProps } from "./CodeTheme";
28
29
  export {
29
30
  CodeTheme,
30
- CodeThemeCSR,
31
31
 
32
32
  useCodeTheme
33
33
  } from "./CodeTheme";
34
+
35
+ export {
36
+ CoderProvider
37
+ } from "./CoderProvider";