@xyd-js/components 0.1.0-xyd.11 → 0.1.0-xyd.13
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/.idea/git_toolbox_blame.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/xyd-components.iml +12 -0
- package/CHANGELOG.md +16 -0
- package/TODO.md +1 -0
- package/content.ts +0 -2
- package/dist/CTABanner-BD4wweO5.js +2 -0
- package/dist/CTABanner-BD4wweO5.js.map +1 -0
- package/dist/CTABanner-DLG0_gv8.js +2 -0
- package/dist/CTABanner-DLG0_gv8.js.map +1 -0
- package/dist/CTABanner-DpPtA-FL.js +2 -0
- package/dist/CTABanner-DpPtA-FL.js.map +1 -0
- package/dist/CodeSample--qfqZ1hL.js +2 -0
- package/dist/CodeSample--qfqZ1hL.js.map +1 -0
- package/dist/CodeSample-CqFaFwwz.js +2 -0
- package/dist/CodeSample-CqFaFwwz.js.map +1 -0
- package/dist/CodeSample-GbqwRbcO.js +2 -0
- package/dist/CodeSample-GbqwRbcO.js.map +1 -0
- package/dist/HomeView-BZdY0g_7.js +2 -0
- package/dist/{HomeView-DHdqouwJ.js.map → HomeView-BZdY0g_7.js.map} +1 -1
- package/dist/HomeView-C_mEMzjV.js +2 -0
- package/dist/{HomeView-TDx2tcP_.js.map → HomeView-C_mEMzjV.js.map} +1 -1
- package/dist/HomeView-RATm-3zT.js +2 -0
- package/dist/HomeView-RATm-3zT.js.map +1 -0
- package/dist/Icon-BkXdTctK.js +2 -0
- package/dist/Icon-BkXdTctK.js.map +1 -0
- package/dist/Icon-BoKcRZAF.js +2 -0
- package/dist/Icon-BoKcRZAF.js.map +1 -0
- package/dist/Icon-CouPZRkJ.js +2 -0
- package/dist/Icon-CouPZRkJ.js.map +1 -0
- package/dist/Text-B-E3eaWW.js +2 -0
- package/dist/Text-B-E3eaWW.js.map +1 -0
- package/dist/Text-B5Ba_pci.js +2 -0
- package/dist/Text-B5Ba_pci.js.map +1 -0
- package/dist/Text-QH4jjPUM.js +2 -0
- package/dist/Text-QH4jjPUM.js.map +1 -0
- package/dist/Update-BlhP2VFR.js +2 -0
- package/dist/Update-BlhP2VFR.js.map +1 -0
- package/dist/Update-CMM38Snc.js +2 -0
- package/dist/Update-CMM38Snc.js.map +1 -0
- package/dist/Update-D5e_yqty.js +2 -0
- package/dist/Update-D5e_yqty.js.map +1 -0
- package/dist/VideoGuide-C5aW4OXW.js +2 -0
- package/dist/VideoGuide-C5aW4OXW.js.map +1 -0
- package/dist/VideoGuide-CoQXlHjQ.js +2 -0
- package/dist/VideoGuide-CoQXlHjQ.js.map +1 -0
- package/dist/VideoGuide-CwkedH8b.js +2 -0
- package/dist/VideoGuide-CwkedH8b.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-9wcO9jN6.js +4 -0
- package/dist/_rollupPluginBabelHelpers-9wcO9jN6.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-CiqSP2w-.js +4 -0
- package/dist/_rollupPluginBabelHelpers-CiqSP2w-.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-DmvUE1MU.js +4 -0
- package/dist/_rollupPluginBabelHelpers-DmvUE1MU.js.map +1 -0
- package/dist/brand.js +1 -1
- package/dist/brand.js.map +1 -1
- package/dist/coder/themes/cosmo-light.js.map +1 -1
- package/dist/coder.d.ts +32 -10
- package/dist/coder.js +1 -1
- package/dist/coder.js.map +1 -1
- package/dist/content.d.ts +264 -201
- package/dist/content.js +1 -1
- package/dist/content.js.map +1 -1
- package/dist/index.css +260 -210
- package/dist/layouts.d.ts +20 -21
- package/dist/layouts.js +1 -1
- package/dist/layouts.js.map +1 -1
- package/dist/pages.js +1 -1
- package/dist/pages.js.map +1 -1
- package/dist/system.d.ts +10 -0
- package/dist/system.js +2 -0
- package/dist/system.js.map +1 -0
- package/dist/tslib.es6-Bb9zBh0L.js +2 -0
- package/dist/{tslib.es6-BI9zka_a.js.map → tslib.es6-Bb9zBh0L.js.map} +1 -1
- package/dist/tslib.es6-Bd9lzVn6.js +2 -0
- package/dist/{tslib.es6-sxmRJynD.js.map → tslib.es6-Bd9lzVn6.js.map} +1 -1
- package/dist/tslib.es6-DwnOrHRg.js +2 -0
- package/dist/tslib.es6-DwnOrHRg.js.map +1 -0
- package/dist/views.js +1 -1
- package/dist/writer.d.ts +409 -77
- package/dist/writer.js +1 -1
- package/dist/writer.js.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1640 -0
- package/docs/functions/GuideCard.html +6 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +2 -0
- package/docs/interfaces/GuideCardProps.html +18 -0
- package/docs/modules.html +1 -0
- package/index.ts +0 -1
- package/package.json +10 -6
- package/project.json +677 -0
- package/rollup.config.js +30 -20
- package/src/brand/Button/Button.styles.tsx +0 -3
- package/src/brand/CTABanner/CTABanner.styles.tsx +2 -4
- package/src/brand/Footer/Footer.styles.tsx +0 -3
- package/src/coder/Code/Code.styles.tsx +132 -33
- package/src/coder/Code/Code.tsx +129 -38
- package/src/coder/Code/CodeLoader.tsx +3 -3
- package/src/coder/Code/annotations.tsx +28 -8
- package/src/coder/Code/highlight.ts +38 -0
- package/src/coder/Code/index.ts +2 -1
- package/src/coder/CodeCopy/CodeCopy.styles.tsx +13 -11
- package/src/coder/CodeCopy/CodeCopy.tsx +5 -3
- package/src/coder/CodeSample/CodeSample.tsx +83 -27
- package/src/coder/CodeTabs/CodeTabs.styles.tsx +111 -94
- package/src/coder/CodeTabs/CodeTabs.tsx +69 -51
- package/src/coder/CodeTheme/CodeTheme.tsx +89 -49
- package/src/coder/CodeTheme/index.ts +0 -1
- package/src/coder/CoderProvider.tsx +26 -0
- package/src/coder/index.ts +8 -4
- package/src/content/ContentDecoator.styles.tsx +113 -0
- package/src/content/ContentDecorator.tsx +17 -0
- package/src/content/GridDecorator.styles.tsx +67 -0
- package/src/content/GridDecorator.tsx +21 -0
- package/src/content/ReactContent.tsx +575 -0
- package/src/content/index.ts +10 -2
- package/src/icons/index.ts +0 -0
- package/src/kit/Loader/Loader.styles.tsx +53 -0
- package/src/kit/Loader/Loader.tsx +22 -0
- package/src/kit/index.ts +1 -0
- package/src/layouts/LayoutPrimary/LayoutPrimary.styles.tsx +270 -306
- package/src/layouts/LayoutPrimary/LayoutPrimary.tsx +171 -91
- package/src/layouts/LayoutPrimary/index.ts +0 -2
- package/src/layouts/index.ts +0 -7
- package/src/system/SearchButton/SearchButton.styles.tsx +86 -0
- package/src/system/SearchButton/SearchButton.tsx +116 -0
- package/src/system/SearchButton/index.ts +1 -0
- package/src/system/index.ts +1 -0
- package/src/writer/Anchor/Anchor.styles.tsx +11 -0
- package/src/{content → writer}/Anchor/Anchor.tsx +20 -22
- package/src/writer/Anchor/index.tsx +1 -0
- package/src/writer/Badge/Badge.styles.tsx +37 -27
- package/src/writer/Badge/Badge.tsx +34 -48
- package/src/writer/Banner/Banner.styles.tsx +91 -0
- package/src/writer/Banner/Banner.tsx +70 -0
- package/src/writer/Banner/index.ts +1 -0
- package/src/writer/Blockquote/Blockquote.styles.tsx +6 -4
- package/src/writer/Blockquote/Blockquote.tsx +5 -2
- package/src/writer/Breadcrumbs/Breadcrumbs.styles.ts +25 -25
- package/src/writer/Breadcrumbs/Breadcrumbs.tsx +18 -12
- package/src/writer/Button/Button.styles.tsx +137 -0
- package/src/writer/Button/Button.tsx +75 -0
- package/src/writer/Button/index.ts +2 -0
- package/src/writer/Callout/Callout.styles.tsx +35 -42
- package/src/writer/Callout/Callout.tsx +30 -15
- package/src/writer/Card/Card.styles.tsx +47 -0
- package/src/writer/Card/Card.tsx +69 -0
- package/src/writer/Card/index.ts +1 -0
- package/src/writer/Code/Code.styles.tsx +12 -11
- package/src/writer/Code/Code.tsx +6 -3
- package/src/writer/ColorSchemeButton/ColorSchemeButton.tsx +172 -0
- package/src/writer/ColorSchemeButton/index.ts +1 -0
- package/src/writer/Details/Details.styles.tsx +87 -98
- package/src/writer/Details/Details.tsx +65 -44
- package/src/writer/Example/index.tsx +5 -0
- package/src/writer/GuideCard/GuideCard.styles.tsx +100 -103
- package/src/writer/GuideCard/GuideCard.tsx +72 -37
- package/src/writer/Heading/Heading.styles.tsx +76 -60
- package/src/writer/Heading/Heading.tsx +92 -22
- package/src/writer/Hr/Hr.styles.tsx +3 -1
- package/src/writer/Hr/Hr.tsx +2 -5
- package/src/writer/Icon/Icon.tsx +48 -0
- package/src/writer/Icon/index.ts +1 -0
- package/src/writer/Image/Image.styles.tsx +9 -0
- package/src/writer/Image/Image.tsx +19 -0
- package/src/writer/Image/index.ts +1 -0
- package/src/writer/List/List.styles.tsx +47 -0
- package/src/writer/List/List.tsx +29 -0
- package/src/writer/List/index.ts +4 -0
- package/src/writer/NavLinks/NavLinks.styles.ts +26 -26
- package/src/writer/NavLinks/NavLinks.tsx +65 -18
- package/src/writer/Pre/Pre.styles.tsx +8 -6
- package/src/writer/Pre/Pre.tsx +3 -2
- package/src/writer/Steps/Steps.styles.tsx +27 -24
- package/src/writer/Steps/Steps.tsx +38 -8
- package/src/writer/Table/Table.styles.tsx +65 -34
- package/src/writer/Table/Table.tsx +121 -11
- package/src/writer/Table/index.ts +0 -11
- package/src/writer/Tabs/Tabs.styles.tsx +51 -55
- package/src/writer/Tabs/Tabs.tsx +30 -23
- package/src/writer/Text/Text.styles.tsx +66 -0
- package/src/writer/Text/Text.tsx +79 -0
- package/src/writer/Text/index.ts +3 -0
- package/src/writer/TocCard/TocCard.module.css +44 -0
- package/src/writer/TocCard/TocCard.tsx +42 -0
- package/src/writer/TocCard/index.ts +3 -0
- package/src/writer/UnderlineNav/Tabs.tsx +51 -0
- package/src/writer/UnderlineNav/TabsPrimary.styles.tsx +184 -0
- package/src/writer/UnderlineNav/TabsPrimary.tsx +209 -0
- package/src/writer/UnderlineNav/TabsSecondary.styles.tsx +77 -0
- package/src/writer/UnderlineNav/TabsSecondary.tsx +171 -0
- package/src/writer/UnderlineNav/UnderlineNav.styles.tsx +165 -31
- package/src/writer/UnderlineNav/UnderlineNav.tsx +257 -22
- package/src/writer/UnderlineNav/index.ts +2 -1
- package/src/writer/UnderlineNav/useValueChange.ts +60 -0
- package/src/writer/Update/Update.styles.tsx +33 -0
- package/src/writer/Update/Update.tsx +37 -0
- package/src/writer/Update/index.ts +1 -0
- package/src/writer/VideoGuide/VideoGuide.module.css +105 -0
- package/src/writer/VideoGuide/VideoGuide.tsx +75 -0
- package/src/writer/VideoGuide/index.ts +1 -0
- package/src/writer/index.ts +23 -1
- package/tsconfig.json +9 -3
- package/types.d.ts +50 -0
- package/writer.ts +1 -1
- package/dist/CTABanner-BLDHbq5h.js +0 -2
- package/dist/CTABanner-BLDHbq5h.js.map +0 -1
- package/dist/CTABanner-n3vc4xW5.js +0 -2
- package/dist/CTABanner-n3vc4xW5.js.map +0 -1
- package/dist/CodeSample-CVki5fdQ.js +0 -2
- package/dist/CodeSample-CVki5fdQ.js.map +0 -1
- package/dist/CodeSample-Dkob5gWa.js +0 -2
- package/dist/CodeSample-Dkob5gWa.js.map +0 -1
- package/dist/HomeView-DHdqouwJ.js +0 -2
- package/dist/HomeView-TDx2tcP_.js +0 -2
- package/dist/UnderlineNav-9lJPvnIp.js +0 -2
- package/dist/UnderlineNav-9lJPvnIp.js.map +0 -1
- package/dist/UnderlineNav-VqB7jDQD.js +0 -2
- package/dist/UnderlineNav-VqB7jDQD.js.map +0 -1
- package/dist/_rollupPluginBabelHelpers-C8nLsqZ7.js +0 -2
- package/dist/_rollupPluginBabelHelpers-C8nLsqZ7.js.map +0 -1
- package/dist/_rollupPluginBabelHelpers-CrdNG0jb.js +0 -2
- package/dist/_rollupPluginBabelHelpers-CrdNG0jb.js.map +0 -1
- package/dist/index-TkBHKzGT.js +0 -2
- package/dist/index-TkBHKzGT.js.map +0 -1
- package/dist/index-YH6Q3iH2.js +0 -2
- package/dist/index-YH6Q3iH2.js.map +0 -1
- package/dist/tslib.es6-BI9zka_a.js +0 -2
- package/dist/tslib.es6-sxmRJynD.js +0 -2
- package/src/content/Anchor/Anchor.styles.tsx +0 -5
- package/src/content/Anchor/index.tsx +0 -3
- package/src/content/Content/Content.styles.tsx +0 -9
- package/src/content/Content/Content.tsx +0 -13
- package/src/content/Content/index.tsx +0 -3
- package/src/content/Content.tsx +0 -179
- package/src/content/Subtitle/Subtitle.styles.ts +0 -8
- package/src/content/Subtitle/Subtitle.tsx +0 -12
- package/src/content/Subtitle/index.tsx +0 -3
- package/src/layouts/Layout.styles.tsx +0 -155
- package/src/layouts/Layout.tsx +0 -119
- package/src/ui/Loader/Loader.styles.tsx +0 -54
- package/src/ui/Loader/Loader.tsx +0 -26
- package/src/ui/index.ts +0 -1
- package/src/writer/Icon/index.tsx +0 -355
- package/src/writer/Table/TableV2.styles.tsx +0 -117
- package/src/writer/Table/TableV2.tsx +0 -83
- /package/src/{ui → kit}/TODO.md +0 -0
|
@@ -1,155 +1,235 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from "react"
|
|
3
|
+
|
|
4
|
+
import { PageLayout } from '@xyd-js/core';
|
|
2
5
|
|
|
3
6
|
import * as cn from "./LayoutPrimary.styles"
|
|
4
7
|
|
|
5
8
|
export interface LayoutPrimaryProps {
|
|
6
|
-
|
|
7
|
-
aside: React.ReactNode;
|
|
8
|
-
content: React.ReactNode;
|
|
9
|
-
contentNav?: React.ReactNode;
|
|
9
|
+
children: React.ReactNode;
|
|
10
10
|
|
|
11
|
-
subheader?:
|
|
12
|
-
|
|
11
|
+
subheader?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
layout?: PageLayout
|
|
14
|
+
scrollKey?: string
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
const LayoutPrimaryContext = React.createContext<{
|
|
18
|
+
scrollRef: React.RefObject<HTMLDivElement | Window | null>;
|
|
19
|
+
isMobileNavOpen: boolean;
|
|
20
|
+
setIsMobileNavOpen: (isOpen: boolean) => void;
|
|
21
|
+
}>({
|
|
22
|
+
scrollRef: React.createRef(),
|
|
23
|
+
isMobileNavOpen: false,
|
|
24
|
+
setIsMobileNavOpen: () => { },
|
|
25
|
+
})
|
|
26
|
+
|
|
15
27
|
// TODO: move scroller to xyd-foo
|
|
16
28
|
export function LayoutPrimary(props: LayoutPrimaryProps) {
|
|
29
|
+
const scrollRef = useRef<HTMLDivElement | Window>(null)
|
|
17
30
|
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false)
|
|
31
|
+
const { hideMainHeader } = useSubHeader(props.subheader ? scrollRef : null, props.scrollKey)
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
scrollRef.current = window
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
return <LayoutPrimaryContext value={{
|
|
38
|
+
scrollRef,
|
|
39
|
+
isMobileNavOpen,
|
|
40
|
+
setIsMobileNavOpen
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<xyd-layout-primary
|
|
44
|
+
className={`${cn.LayoutPrimaryHost} ${props.className || ""}`}
|
|
45
|
+
data-subheader={String(!!props.subheader)}
|
|
46
|
+
data-hide-subheader={String(hideMainHeader)}
|
|
47
|
+
data-layout={props.layout}
|
|
48
|
+
>
|
|
49
|
+
{props.children}
|
|
50
|
+
</xyd-layout-primary>
|
|
51
|
+
</LayoutPrimaryContext>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface LayoutPrimaryHeaderProps {
|
|
55
|
+
header: React.ReactNode;
|
|
20
56
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
subheader?: React.ReactNode;
|
|
58
|
+
}
|
|
59
|
+
LayoutPrimary.Header = function LayoutPrimaryHeader(props: LayoutPrimaryHeaderProps) {
|
|
60
|
+
const { isMobileNavOpen, setIsMobileNavOpen } = useContext(LayoutPrimaryContext)
|
|
61
|
+
|
|
62
|
+
return <>
|
|
63
|
+
<header part="header">
|
|
64
|
+
<div part="header-content">
|
|
28
65
|
{props.header}
|
|
29
66
|
<button
|
|
30
|
-
|
|
31
|
-
onClick={() => setIsMobileNavOpen(!isMobileNavOpen)}
|
|
67
|
+
part="hamburger-button"
|
|
32
68
|
aria-label="Toggle navigation menu"
|
|
69
|
+
onClick={() => setIsMobileNavOpen(!isMobileNavOpen)}
|
|
33
70
|
>
|
|
34
|
-
<div
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
className={`${cn.LayoutPrimaryHamburgerLine} ${isMobileNavOpen ? cn.LayoutPrimaryHamburgerLineOpen : ''}`}/>
|
|
39
|
-
<span
|
|
40
|
-
className={`${cn.LayoutPrimaryHamburgerLine} ${isMobileNavOpen ? cn.LayoutPrimaryHamburgerLineOpen : ''}`}/>
|
|
71
|
+
<div part="hamburger-icon">
|
|
72
|
+
<$HamburgerLine active={isMobileNavOpen} />
|
|
73
|
+
<$HamburgerLine active={isMobileNavOpen} />
|
|
74
|
+
<$HamburgerLine active={isMobileNavOpen} />
|
|
41
75
|
</div>
|
|
42
76
|
</button>
|
|
43
77
|
</div>
|
|
78
|
+
|
|
44
79
|
{props.subheader}
|
|
45
80
|
</header>
|
|
81
|
+
</>
|
|
82
|
+
}
|
|
46
83
|
|
|
47
|
-
|
|
84
|
+
interface LayoutPrimaryMobileAsideProps {
|
|
85
|
+
aside: React.ReactNode;
|
|
86
|
+
}
|
|
87
|
+
LayoutPrimary.MobileAside = function LayoutPrimaryAside(props: LayoutPrimaryMobileAsideProps) {
|
|
88
|
+
const { isMobileNavOpen, setIsMobileNavOpen } = useContext(LayoutPrimaryContext)
|
|
89
|
+
return <>
|
|
48
90
|
<div
|
|
49
|
-
|
|
91
|
+
part="mobile-overlay"
|
|
92
|
+
data-active={isMobileNavOpen}
|
|
50
93
|
onClick={() => setIsMobileNavOpen(false)}
|
|
51
94
|
/>
|
|
52
|
-
<aside
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<div
|
|
95
|
+
<aside
|
|
96
|
+
part="mobile-sidebar"
|
|
97
|
+
data-active={isMobileNavOpen}
|
|
98
|
+
>
|
|
99
|
+
<div part="mobile-sidebar-aside">
|
|
57
100
|
{props.aside}
|
|
58
101
|
</div>
|
|
59
102
|
<button
|
|
60
|
-
|
|
61
|
-
onClick={() => setIsMobileNavOpen(false)}
|
|
103
|
+
part="mobile-sidebar-close-button"
|
|
62
104
|
aria-label="Close navigation menu"
|
|
105
|
+
onClick={() => setIsMobileNavOpen(false)}
|
|
63
106
|
>
|
|
64
|
-
<div
|
|
107
|
+
<div part="mobile-sidebar-close-icon" />
|
|
65
108
|
</button>
|
|
66
109
|
</aside>
|
|
110
|
+
</>
|
|
111
|
+
}
|
|
67
112
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
</section>
|
|
88
|
-
</article>
|
|
89
|
-
{props.contentNav && <nav className={cn.LayoutPrimaryArticleNav}>
|
|
113
|
+
interface LayoutPrimaryPageProps {
|
|
114
|
+
children: React.ReactNode;
|
|
115
|
+
contentNav?: React.ReactNode;
|
|
116
|
+
}
|
|
117
|
+
LayoutPrimary.Page = function LayoutPrimaryPage(props: LayoutPrimaryPageProps) {
|
|
118
|
+
return <>
|
|
119
|
+
<div part="page">
|
|
120
|
+
<div part="page-scroll">
|
|
121
|
+
<div part="page-container">
|
|
122
|
+
<div part="page-article-container">
|
|
123
|
+
|
|
124
|
+
<article part="page-article">
|
|
125
|
+
<section part="page-article-content">
|
|
126
|
+
{props.children}
|
|
127
|
+
</section>
|
|
128
|
+
</article>
|
|
129
|
+
|
|
130
|
+
{
|
|
131
|
+
props.contentNav && <nav part="page-article-nav">
|
|
90
132
|
{props.contentNav}
|
|
91
|
-
</nav>
|
|
92
|
-
|
|
133
|
+
</nav>
|
|
134
|
+
}
|
|
93
135
|
</div>
|
|
94
136
|
</div>
|
|
95
137
|
</div>
|
|
96
|
-
</
|
|
97
|
-
|
|
138
|
+
</div>
|
|
139
|
+
</>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function $HamburgerLine({ active }: { active: boolean }) {
|
|
143
|
+
return <span
|
|
144
|
+
part="hamburger-line"
|
|
145
|
+
data-active={active}
|
|
146
|
+
/>
|
|
98
147
|
}
|
|
99
148
|
|
|
149
|
+
const SCROLL_DOWN_TRIGGER_THRESHOLD = 200;
|
|
150
|
+
const SCROLL_UP_TRIGGER_THRESHOLD = 100;
|
|
151
|
+
|
|
100
152
|
// TODO: move to `xyd-foo` or somewhere else
|
|
101
|
-
|
|
153
|
+
// TODO better solution than `key`
|
|
154
|
+
function useSubHeader(ref: React.RefObject<HTMLDivElement | Window | null> | null, key?: any) {
|
|
102
155
|
const [hideMainHeader, setHideMainHeader] = useState(false)
|
|
103
|
-
const [
|
|
104
|
-
const [
|
|
156
|
+
const [lastScrollTop, setLastScrollTop] = useState(0)
|
|
157
|
+
const [scrollDirection, setScrollDirection] = useState<'up' | 'down' | null>(null)
|
|
158
|
+
const [scrollThreshold, setScrollThreshold] = useState(0)
|
|
159
|
+
const [scrollStartPosition, setScrollStartPosition] = useState(0)
|
|
160
|
+
const [isScrolling, setIsScrolling] = useState(false)
|
|
161
|
+
|
|
162
|
+
function reset() {
|
|
163
|
+
setHideMainHeader(false)
|
|
164
|
+
setLastScrollTop(0)
|
|
165
|
+
setScrollDirection(null)
|
|
166
|
+
setScrollThreshold(0)
|
|
167
|
+
setScrollStartPosition(0)
|
|
168
|
+
setIsScrolling(false)
|
|
169
|
+
}
|
|
105
170
|
|
|
106
171
|
useEffect(() => {
|
|
107
|
-
|
|
172
|
+
reset()
|
|
173
|
+
}, [key])
|
|
174
|
+
|
|
175
|
+
function onScroll(e: Event) {
|
|
176
|
+
if (!(e.target instanceof HTMLElement)) {
|
|
108
177
|
return
|
|
109
178
|
}
|
|
110
179
|
|
|
111
|
-
const
|
|
112
|
-
const diff = scrollTop - controlScrollPos
|
|
113
|
-
const reversePosDiff = Math.abs(scrollTop - controlScrollPos)
|
|
180
|
+
const currentScrollTop = e.target.scrollTop
|
|
114
181
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
} else if (reversePosDiff > checkpoint) {
|
|
182
|
+
// Always show header when near the top of the page
|
|
183
|
+
if (currentScrollTop < SCROLL_UP_TRIGGER_THRESHOLD) {
|
|
118
184
|
setHideMainHeader(false)
|
|
185
|
+
setScrollThreshold(0)
|
|
186
|
+
setLastScrollTop(currentScrollTop)
|
|
187
|
+
setIsScrolling(false)
|
|
188
|
+
return
|
|
119
189
|
}
|
|
120
|
-
}, [
|
|
121
|
-
scrollTop,
|
|
122
|
-
controlScrollPos,
|
|
123
|
-
]);
|
|
124
190
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
191
|
+
// Determine scroll direction
|
|
192
|
+
const direction = currentScrollTop > lastScrollTop ? 'down' : 'up'
|
|
193
|
+
|
|
194
|
+
// If direction changed, reset scroll tracking
|
|
195
|
+
if (direction !== scrollDirection) {
|
|
196
|
+
setScrollDirection(direction)
|
|
197
|
+
setScrollStartPosition(currentScrollTop)
|
|
198
|
+
setIsScrolling(true)
|
|
128
199
|
}
|
|
129
200
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
201
|
+
// Calculate total scroll distance from start position
|
|
202
|
+
const totalScrollDistance = Math.abs(currentScrollTop - scrollStartPosition)
|
|
133
203
|
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
204
|
+
// Only trigger header changes if we've scrolled enough distance in the current direction
|
|
205
|
+
if (direction === 'down' && totalScrollDistance > SCROLL_DOWN_TRIGGER_THRESHOLD) {
|
|
206
|
+
// When scrolling down, hide header
|
|
207
|
+
setHideMainHeader(true)
|
|
208
|
+
setScrollThreshold(currentScrollTop)
|
|
209
|
+
// Reset scroll tracking after triggering
|
|
210
|
+
setScrollStartPosition(currentScrollTop)
|
|
211
|
+
} else if (direction === 'up' && totalScrollDistance > SCROLL_UP_TRIGGER_THRESHOLD) {
|
|
212
|
+
// When scrolling up, show header
|
|
213
|
+
setHideMainHeader(false)
|
|
214
|
+
setScrollThreshold(currentScrollTop)
|
|
215
|
+
// Reset scroll tracking after triggering
|
|
216
|
+
setScrollStartPosition(currentScrollTop)
|
|
137
217
|
}
|
|
138
218
|
|
|
139
|
-
|
|
219
|
+
setLastScrollTop(currentScrollTop)
|
|
140
220
|
}
|
|
141
221
|
|
|
142
|
-
// TODO: by ref?
|
|
143
|
-
// TODO: MOVE SOMEWHERE ELSE BECAUSE IT DECREASE PERFORMANCE (RERENDER)
|
|
144
222
|
useEffect(() => {
|
|
145
|
-
|
|
146
|
-
|
|
223
|
+
if (!ref?.current) {
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
ref.current.addEventListener("scroll", onScroll)
|
|
147
228
|
|
|
148
229
|
return () => {
|
|
149
|
-
|
|
150
|
-
document.querySelector(`.${cn.LayoutPrimaryPageScroll}`)?.removeEventListener("scrollend", onScrollFinish)
|
|
230
|
+
ref.current?.removeEventListener("scroll", onScroll)
|
|
151
231
|
}
|
|
152
|
-
}, []);
|
|
232
|
+
}, [ref, key, lastScrollTop, scrollDirection, scrollThreshold, scrollStartPosition]);
|
|
153
233
|
|
|
154
234
|
return {
|
|
155
235
|
hideMainHeader,
|
package/src/layouts/index.ts
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { css } from "@linaria/core";
|
|
2
|
+
|
|
3
|
+
export const SearchButton = css`
|
|
4
|
+
@layer defaults {
|
|
5
|
+
background-color: transparent;
|
|
6
|
+
border-radius: 8px;
|
|
7
|
+
border: 1px solid var(--dark32);
|
|
8
|
+
color: var(--text-primary);
|
|
9
|
+
background: var(--dark16);
|
|
10
|
+
font-size: var(--xyd-font-size-small);
|
|
11
|
+
font-weight: var(--xyd-font-weight-semibold);
|
|
12
|
+
height: 36px;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
flex: 1;
|
|
17
|
+
|
|
18
|
+
padding: 0 8px;
|
|
19
|
+
margin: 12px 0 0;
|
|
20
|
+
user-select: none;
|
|
21
|
+
width: 100%;
|
|
22
|
+
transition: border-color .15s ease;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
max-width: 300px;
|
|
26
|
+
margin: 0;
|
|
27
|
+
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
background: var(--dark16);
|
|
32
|
+
box-shadow: none;
|
|
33
|
+
color: var(--dark48);
|
|
34
|
+
outline: none;
|
|
35
|
+
|
|
36
|
+
box-shadow: none;
|
|
37
|
+
border-color: var(--dark48);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[part="container"] {
|
|
41
|
+
align-items: center;
|
|
42
|
+
display: flex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[part="placeholder"] {
|
|
46
|
+
display: block !important;
|
|
47
|
+
font-size: var(--xyd-font-size-small);
|
|
48
|
+
color: var(--dark48);
|
|
49
|
+
font-weight: var(--xyd-font-weight-normal);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
[part="icon"] {
|
|
53
|
+
stroke-width: 1.4;
|
|
54
|
+
color: var(--dark48) !important;
|
|
55
|
+
height: 15px;
|
|
56
|
+
transition: color .15s var(--cubic-enter);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
[part="keys"] {
|
|
61
|
+
display: flex;
|
|
62
|
+
gap: 4px;
|
|
63
|
+
min-width: auto;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[part="key"] {
|
|
67
|
+
align-items: center;
|
|
68
|
+
background: var(--dark16);
|
|
69
|
+
border-radius: 3px;
|
|
70
|
+
box-shadow: none;
|
|
71
|
+
color: var(--dark48);
|
|
72
|
+
display: flex;
|
|
73
|
+
height: 18px;
|
|
74
|
+
line-height: 18px;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
font-size: 12px;
|
|
77
|
+
letter-spacing: 1px;
|
|
78
|
+
position: relative;
|
|
79
|
+
padding: 0;
|
|
80
|
+
margin: 0;
|
|
81
|
+
border: 0px;
|
|
82
|
+
top: 0;
|
|
83
|
+
width: 20px;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
`
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import * as cn from "./SearchButton.styles";
|
|
4
|
+
|
|
5
|
+
interface SearchButtonProps {
|
|
6
|
+
onClick?: () => void;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
shortcutKeys?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function SearchButton({
|
|
12
|
+
shortcutKeys = ['⌘', 'K'],
|
|
13
|
+
...props
|
|
14
|
+
}: SearchButtonProps) {
|
|
15
|
+
useShortcuts(shortcutKeys, () => props.onClick?.());
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
// @ts-ignore - !!! FIX IN THE FUTURE !!! its a fix for loading virtual-component:Search twice? original and from plugin - check if exists on prod
|
|
19
|
+
window.__UNSAFE_xyd_search_button_inited = true
|
|
20
|
+
|
|
21
|
+
return () => {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
window.__UNSAFE_xyd_search_button_inited = false
|
|
24
|
+
}
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<xyd-search-button
|
|
29
|
+
className={cn.SearchButton}
|
|
30
|
+
aria-label="Search"
|
|
31
|
+
onClick={props.onClick}
|
|
32
|
+
>
|
|
33
|
+
<span part="container">
|
|
34
|
+
<svg
|
|
35
|
+
width={20}
|
|
36
|
+
height={20}
|
|
37
|
+
part="icon"
|
|
38
|
+
viewBox="0 0 20 20"
|
|
39
|
+
>
|
|
40
|
+
<path
|
|
41
|
+
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
|
|
42
|
+
stroke="currentColor"
|
|
43
|
+
fill="none"
|
|
44
|
+
fillRule="evenodd"
|
|
45
|
+
strokeLinecap="round"
|
|
46
|
+
strokeLinejoin="round"
|
|
47
|
+
/>
|
|
48
|
+
</svg>
|
|
49
|
+
<span part="placeholder">{props.placeholder || "Search"}</span>
|
|
50
|
+
</span>
|
|
51
|
+
|
|
52
|
+
{
|
|
53
|
+
shortcutKeys.length > 0 && (
|
|
54
|
+
<span part="keys">
|
|
55
|
+
{shortcutKeys.map((key, index) => (
|
|
56
|
+
<kbd key={index} part="key">{key}</kbd>
|
|
57
|
+
))}
|
|
58
|
+
</span>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
</xyd-search-button>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function useShortcuts(shortcutKeys: string[], onTrigger: () => void): void {
|
|
66
|
+
// Keep latest handler reference to avoid stale closures
|
|
67
|
+
const savedHandler = useRef(onTrigger);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
savedHandler.current = onTrigger;
|
|
71
|
+
}, [onTrigger]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
if (window.__UNSAFE_xyd_search_button_inited) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const listener = (event: KeyboardEvent) => {
|
|
80
|
+
// For single key shortcuts
|
|
81
|
+
if (shortcutKeys.length === 1) {
|
|
82
|
+
if (event.key.toLowerCase() === shortcutKeys[0].toLowerCase()) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
|
|
85
|
+
savedHandler.current();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// For modifier combinations
|
|
91
|
+
if (shortcutKeys.length === 2) {
|
|
92
|
+
const [modifier, key] = shortcutKeys;
|
|
93
|
+
const pressedKey = event.key.toLowerCase();
|
|
94
|
+
|
|
95
|
+
const isModifierMatch =
|
|
96
|
+
(modifier === '⌘' && event.metaKey) ||
|
|
97
|
+
(modifier === 'Ctrl' && event.ctrlKey);
|
|
98
|
+
|
|
99
|
+
if (isModifierMatch && pressedKey === key.toLowerCase()) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
|
|
102
|
+
savedHandler.current();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Use capture phase and listen to both keydown and keyup
|
|
108
|
+
window.addEventListener('keydown', listener, { capture: true });
|
|
109
|
+
window.addEventListener('keyup', listener, { capture: true });
|
|
110
|
+
|
|
111
|
+
return () => {
|
|
112
|
+
window.removeEventListener('keydown', listener, { capture: true });
|
|
113
|
+
window.removeEventListener('keyup', listener, { capture: true });
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SearchButton } from "./SearchButton";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SearchButton } from "./SearchButton";
|
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
import React, {forwardRef} from 'react'
|
|
2
|
-
import type {ComponentProps, ReactElement} from 'react'
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import type { ComponentProps, ReactElement } from 'react'
|
|
3
|
+
|
|
3
4
|
import * as cn from "./Anchor.styles";
|
|
4
5
|
|
|
5
6
|
export type AnchorProps = Omit<ComponentProps<'a'>, 'ref'> & {
|
|
6
7
|
newWindow?: boolean
|
|
8
|
+
as?: React.ElementType
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
// TODO: where react-router?
|
|
10
|
-
|
|
11
11
|
export const Anchor = forwardRef<HTMLAnchorElement, AnchorProps>(function (
|
|
12
|
-
{href = '', children, newWindow},
|
|
12
|
+
{ href = '', children, newWindow, as, ...props },
|
|
13
13
|
// ref is used in <NavbarMenu />
|
|
14
14
|
forwardedRef
|
|
15
15
|
): ReactElement {
|
|
16
|
+
const Link = as || $Anchor
|
|
17
|
+
|
|
16
18
|
if (newWindow) {
|
|
17
19
|
return (
|
|
18
|
-
<
|
|
20
|
+
<Link
|
|
19
21
|
ref={forwardedRef}
|
|
20
22
|
href={href}
|
|
21
23
|
target="_blank"
|
|
22
24
|
rel="noreferrer"
|
|
23
25
|
className={cn.AnchorHost}
|
|
26
|
+
{...props}
|
|
24
27
|
>
|
|
25
28
|
{children}
|
|
26
|
-
</
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!href) {
|
|
31
|
-
return (
|
|
32
|
-
<a
|
|
33
|
-
ref={forwardedRef}
|
|
34
|
-
href={href}
|
|
35
|
-
className={cn.AnchorHost}
|
|
36
|
-
>
|
|
37
|
-
{children}
|
|
38
|
-
</a>
|
|
29
|
+
</Link>
|
|
39
30
|
)
|
|
40
31
|
}
|
|
41
32
|
|
|
42
33
|
return (
|
|
43
|
-
<
|
|
34
|
+
<Link
|
|
44
35
|
ref={forwardedRef}
|
|
45
|
-
href={href}
|
|
46
36
|
className={cn.AnchorHost}
|
|
37
|
+
href={href || undefined}
|
|
38
|
+
{...props}
|
|
47
39
|
>
|
|
48
40
|
{children}
|
|
49
|
-
</
|
|
41
|
+
</Link>
|
|
50
42
|
)
|
|
51
43
|
})
|
|
52
44
|
|
|
53
45
|
Anchor.displayName = 'Anchor'
|
|
46
|
+
|
|
47
|
+
function $Anchor({ children, ...rest }) {
|
|
48
|
+
return <a {...rest}>
|
|
49
|
+
{children}
|
|
50
|
+
</a>
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {Anchor} from "./Anchor";
|