@rspress/core 1.2.0 → 1.3.0

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 (158) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +53 -40
  3. package/dist/index.js.map +1 -1
  4. package/dist/loader.d.ts +1 -1
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.js +8 -4
  7. package/dist/runtime/clientEntry.js +7 -4
  8. package/dist/runtime/ssrEntry.js +2 -2
  9. package/package.json +19 -15
  10. package/runtime.ts +1 -1
  11. package/src/runtime/App.tsx +8 -4
  12. package/src/runtime/clientEntry.tsx +7 -4
  13. package/src/runtime/ssrEntry.tsx +2 -2
  14. package/theme.ts +2 -2
  15. package/dist/runtime/Content.d.ts +0 -6
  16. package/dist/runtime/Content.js +0 -33
  17. package/dist/runtime/NoSSR.d.ts +0 -4
  18. package/dist/runtime/NoSSR.js +0 -17
  19. package/dist/runtime/hooks.d.ts +0 -39
  20. package/dist/runtime/hooks.js +0 -54
  21. package/dist/runtime/index.d.ts +0 -6
  22. package/dist/runtime/index.js +0 -34
  23. package/dist/runtime/utils.d.ts +0 -8
  24. package/dist/runtime/utils.js +0 -45
  25. package/dist/theme/bundle.css +0 -2691
  26. package/dist/theme/bundle.d.ts +0 -176
  27. package/dist/theme/bundle.js +0 -4433
  28. package/dist/theme/bundle.js.map +0 -1
  29. package/dist/theme/index.js +0 -6
  30. package/src/runtime/Content.tsx +0 -43
  31. package/src/runtime/NoSSR.tsx +0 -16
  32. package/src/runtime/hooks.ts +0 -110
  33. package/src/runtime/index.ts +0 -17
  34. package/src/runtime/utils.ts +0 -46
  35. package/src/theme-default/assets/arrow-down.svg +0 -1
  36. package/src/theme-default/assets/arrow-right.svg +0 -1
  37. package/src/theme-default/assets/copy.svg +0 -1
  38. package/src/theme-default/assets/down.svg +0 -1
  39. package/src/theme-default/assets/github.svg +0 -1
  40. package/src/theme-default/assets/loading.svg +0 -1
  41. package/src/theme-default/assets/menu.svg +0 -1
  42. package/src/theme-default/assets/moon.svg +0 -3
  43. package/src/theme-default/assets/right.svg +0 -1
  44. package/src/theme-default/assets/small-menu.svg +0 -1
  45. package/src/theme-default/assets/success.svg +0 -1
  46. package/src/theme-default/assets/sun.svg +0 -11
  47. package/src/theme-default/assets/translator.svg +0 -1
  48. package/src/theme-default/components/Aside/index.css +0 -22
  49. package/src/theme-default/components/Aside/index.tsx +0 -75
  50. package/src/theme-default/components/BackDrop/index.module.scss +0 -14
  51. package/src/theme-default/components/BackDrop/index.tsx +0 -13
  52. package/src/theme-default/components/Button/index.module.scss +0 -68
  53. package/src/theme-default/components/Button/index.tsx +0 -40
  54. package/src/theme-default/components/DocFooter/index.module.scss +0 -60
  55. package/src/theme-default/components/DocFooter/index.tsx +0 -66
  56. package/src/theme-default/components/EditLink/index.module.scss +0 -11
  57. package/src/theme-default/components/EditLink/index.tsx +0 -18
  58. package/src/theme-default/components/HomeFeatures/index.module.scss +0 -50
  59. package/src/theme-default/components/HomeFeatures/index.tsx +0 -65
  60. package/src/theme-default/components/HomeFooter/index.tsx +0 -15
  61. package/src/theme-default/components/HomeHero/index.module.scss +0 -42
  62. package/src/theme-default/components/HomeHero/index.tsx +0 -75
  63. package/src/theme-default/components/Link/index.module.scss +0 -9
  64. package/src/theme-default/components/Link/index.tsx +0 -90
  65. package/src/theme-default/components/LocalSideBar/index.scss +0 -40
  66. package/src/theme-default/components/LocalSideBar/index.tsx +0 -39
  67. package/src/theme-default/components/Nav/NavBarTitle.tsx +0 -43
  68. package/src/theme-default/components/Nav/NavMenuGroup.tsx +0 -156
  69. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +0 -40
  70. package/src/theme-default/components/Nav/NavTranslations.tsx +0 -16
  71. package/src/theme-default/components/Nav/NavVersions.tsx +0 -16
  72. package/src/theme-default/components/Nav/index.module.scss +0 -115
  73. package/src/theme-default/components/Nav/index.tsx +0 -150
  74. package/src/theme-default/components/Nav/menuDataHooks.tsx +0 -75
  75. package/src/theme-default/components/NavHambmger/index.module.scss +0 -81
  76. package/src/theme-default/components/NavHambmger/index.tsx +0 -39
  77. package/src/theme-default/components/NavScreen/NavScreenMenuGroup.tsx +0 -95
  78. package/src/theme-default/components/NavScreen/index.module.scss +0 -88
  79. package/src/theme-default/components/NavScreen/index.tsx +0 -123
  80. package/src/theme-default/components/Overview/index.module.scss +0 -154
  81. package/src/theme-default/components/Overview/index.tsx +0 -136
  82. package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +0 -101
  83. package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +0 -16
  84. package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
  85. package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
  86. package/src/theme-default/components/PackageManagerTabs/index.scss +0 -5
  87. package/src/theme-default/components/PackageManagerTabs/index.tsx +0 -110
  88. package/src/theme-default/components/Search/NoSearchResult.tsx +0 -13
  89. package/src/theme-default/components/Search/SearchPanel.tsx +0 -340
  90. package/src/theme-default/components/Search/SuggestItem.tsx +0 -135
  91. package/src/theme-default/components/Search/assets/close.svg +0 -1
  92. package/src/theme-default/components/Search/assets/file.svg +0 -1
  93. package/src/theme-default/components/Search/assets/header.svg +0 -1
  94. package/src/theme-default/components/Search/assets/jump.svg +0 -1
  95. package/src/theme-default/components/Search/assets/loading.svg +0 -1
  96. package/src/theme-default/components/Search/assets/search.svg +0 -1
  97. package/src/theme-default/components/Search/assets/title.svg +0 -1
  98. package/src/theme-default/components/Search/empty.svg +0 -4
  99. package/src/theme-default/components/Search/index.module.scss +0 -236
  100. package/src/theme-default/components/Search/index.tsx +0 -39
  101. package/src/theme-default/components/Search/logic/Provider.ts +0 -35
  102. package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +0 -102
  103. package/src/theme-default/components/Search/logic/providers/RemoteProvider.ts +0 -40
  104. package/src/theme-default/components/Search/logic/search.ts +0 -341
  105. package/src/theme-default/components/Search/logic/util.test.ts +0 -21
  106. package/src/theme-default/components/Search/logic/util.ts +0 -127
  107. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +0 -180
  108. package/src/theme-default/components/Sidebar/SidebarItem.tsx +0 -61
  109. package/src/theme-default/components/Sidebar/index.module.scss +0 -142
  110. package/src/theme-default/components/Sidebar/index.tsx +0 -156
  111. package/src/theme-default/components/SocialLinks/HiddenLinks.tsx +0 -30
  112. package/src/theme-default/components/SocialLinks/LinkContent.tsx +0 -90
  113. package/src/theme-default/components/SocialLinks/ShownLinks.tsx +0 -32
  114. package/src/theme-default/components/SocialLinks/index.module.scss +0 -18
  115. package/src/theme-default/components/SocialLinks/index.tsx +0 -36
  116. package/src/theme-default/components/SocialLinks/presetIcons.tsx +0 -165
  117. package/src/theme-default/components/SwitchAppearance/index.module.scss +0 -15
  118. package/src/theme-default/components/SwitchAppearance/index.tsx +0 -35
  119. package/src/theme-default/components/Tabs/index.module.scss +0 -46
  120. package/src/theme-default/components/Tabs/index.tsx +0 -123
  121. package/src/theme-default/components/Tag/index.tsx +0 -18
  122. package/src/theme-default/components/Toc/index.css +0 -18
  123. package/src/theme-default/components/Toc/index.tsx +0 -42
  124. package/src/theme-default/index.ts +0 -26
  125. package/src/theme-default/layout/DocLayout/docComponents/code.tsx +0 -112
  126. package/src/theme-default/layout/DocLayout/docComponents/hr.tsx +0 -10
  127. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +0 -69
  128. package/src/theme-default/layout/DocLayout/docComponents/index.tsx +0 -33
  129. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +0 -22
  130. package/src/theme-default/layout/DocLayout/docComponents/list.tsx +0 -13
  131. package/src/theme-default/layout/DocLayout/docComponents/paragraph.tsx +0 -19
  132. package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +0 -37
  133. package/src/theme-default/layout/DocLayout/docComponents/prisim-theme.ts +0 -73
  134. package/src/theme-default/layout/DocLayout/docComponents/table.tsx +0 -37
  135. package/src/theme-default/layout/DocLayout/docComponents/title.tsx +0 -40
  136. package/src/theme-default/layout/DocLayout/index.module.scss +0 -138
  137. package/src/theme-default/layout/DocLayout/index.tsx +0 -125
  138. package/src/theme-default/layout/HomeLayout/index.css +0 -18
  139. package/src/theme-default/layout/HomeLayout/index.tsx +0 -39
  140. package/src/theme-default/layout/Layout/index.tsx +0 -176
  141. package/src/theme-default/layout/NotFountLayout/index.tsx +0 -40
  142. package/src/theme-default/logic/TabDataContext.ts +0 -14
  143. package/src/theme-default/logic/index.ts +0 -8
  144. package/src/theme-default/logic/sideEffects.ts +0 -174
  145. package/src/theme-default/logic/useAppearance.ts +0 -57
  146. package/src/theme-default/logic/useEditLink.ts +0 -33
  147. package/src/theme-default/logic/useHiddenNav.ts +0 -58
  148. package/src/theme-default/logic/useLocaleSiteData.ts +0 -26
  149. package/src/theme-default/logic/useNav.ts +0 -36
  150. package/src/theme-default/logic/usePathUtils.ts +0 -73
  151. package/src/theme-default/logic/usePrevNextPage.ts +0 -40
  152. package/src/theme-default/logic/useSidebarData.ts +0 -73
  153. package/src/theme-default/logic/utils.ts +0 -38
  154. package/src/theme-default/styles/base.css +0 -102
  155. package/src/theme-default/styles/code.css +0 -177
  156. package/src/theme-default/styles/index.ts +0 -7
  157. package/src/theme-default/styles/scrollbar.css +0 -28
  158. package/src/theme-default/styles/vars.css +0 -81
@@ -1,40 +0,0 @@
1
- import {
2
- NavItemWithLink,
3
- NavItemWithLinkAndChildren,
4
- withoutBase,
5
- } from '@rspress/shared';
6
- import { Link } from '../Link';
7
- import { Tag } from '../Tag';
8
- import styles from './index.module.scss';
9
- import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
10
-
11
- interface Props {
12
- pathname: string;
13
- langs?: string[];
14
- base: string;
15
- rightIcon?: React.ReactNode;
16
- }
17
-
18
- export function NavMenuSingleItem(
19
- item: (NavItemWithLink | NavItemWithLinkAndChildren) & Props,
20
- ) {
21
- const { pathname, base } = item;
22
- const isActive = new RegExp(item.activeMatch || item.link).test(
23
- withoutBase(pathname, base),
24
- );
25
-
26
- return (
27
- <Link href={normalizeHref(item.link)}>
28
- <div
29
- key={item.text}
30
- className={`${styles.singleItem} ${
31
- isActive ? styles.activeItem : ''
32
- } text-sm font-medium mx-1.5 px-3 py-2 flex items-center`}
33
- >
34
- <Tag tag={item.tag} />
35
- {item.text}
36
- {item.rightIcon}
37
- </div>
38
- </Link>
39
- );
40
- }
@@ -1,16 +0,0 @@
1
- import { NavMenuGroup } from './NavMenuGroup';
2
- import styles from './index.module.scss';
3
- import { useTranslationMenuData } from './menuDataHooks';
4
-
5
- export function NavTranslations() {
6
- const translationMenuData = useTranslationMenuData();
7
- return (
8
- <div
9
- className={`translation ${styles.menuItem} flex text-sm font-bold items-center px-3 py-2`}
10
- >
11
- <div>
12
- <NavMenuGroup {...translationMenuData} />
13
- </div>
14
- </div>
15
- );
16
- }
@@ -1,16 +0,0 @@
1
- import { NavMenuGroup } from './NavMenuGroup';
2
- import styles from './index.module.scss';
3
- import { useVersionMenuData } from './menuDataHooks';
4
-
5
- export function NavVersions() {
6
- const versionsMenuData = useVersionMenuData();
7
- return (
8
- <div
9
- className={`translation ${styles.menuItem} flex text-sm font-bold items-center px-3 py-2`}
10
- >
11
- <div>
12
- <NavMenuGroup {...versionsMenuData} />
13
- </div>
14
- </div>
15
- );
16
- }
@@ -1,115 +0,0 @@
1
- .hidden {
2
- transform: translate3d(0, calc(-100%), 0);
3
- background: transparent;
4
- opacity: 0;
5
- }
6
-
7
- .container {
8
- margin: auto;
9
- }
10
-
11
- .navContainer {
12
- top: 0;
13
- left: 0;
14
- transition: all 0.3s ease;
15
- transition-property: transform, opacity;
16
- background: var(--rp-c-bg);
17
- height: var(--rp-nav-height);
18
- z-index: var(--rp-z-index-nav);
19
- // Hidden the box shadow
20
- // box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
21
- }
22
-
23
- .leftNav {
24
- display: none;
25
- }
26
-
27
- .rightNav {
28
- display: none;
29
- }
30
-
31
- .activeItem,
32
- .singleItem:hover {
33
- background-color: var(--rp-c-bg-soft);
34
- cursor: pointer;
35
- color: var(--rp-c-brand-dark);
36
- border-radius: 12px;
37
- }
38
-
39
- .navContainer :deep(*) {
40
- pointer-events: all;
41
- }
42
-
43
- .social-links-icon {
44
- width: 20px;
45
- height: 100%;
46
- display: flex;
47
- fill: currentColor;
48
- color: var(--rp-c-text-2);
49
-
50
- &:hover {
51
- color: var(--rp-c-text-1);
52
- }
53
- }
54
-
55
- .menu-item {
56
- display: none;
57
- margin: 0 8px;
58
- }
59
-
60
- @media (max-width: 768px) {
61
- :root {
62
- --rp-nav-height: 56px;
63
- }
64
- .menu-item:before {
65
- display: none;
66
- }
67
- .mobileNavMenu {
68
- display: flex;
69
- }
70
- }
71
-
72
- @media (min-width: 768px) {
73
- .menu-item {
74
- display: flex;
75
- }
76
- .leftNav {
77
- display: flex;
78
- align-items: center;
79
- flex-grow: 1;
80
- margin: 0 0.5rem;
81
- }
82
- .rightNav {
83
- display: flex;
84
- align-items: center;
85
- }
86
- .mobileNavMenu {
87
- display: none;
88
- }
89
- }
90
-
91
- @media (min-width: 960px) {
92
- .mask {
93
- position: absolute;
94
- right: 0;
95
- bottom: -30px;
96
- width: 100vw;
97
- height: 30px;
98
- &.docPage {
99
- // Avoid influent the sidebar
100
- width: calc(100vw - var(--rp-sidebar-width) - 48px);
101
- }
102
- }
103
-
104
- .mask::before {
105
- display: block;
106
- width: 100%;
107
- height: 30px;
108
- background: linear-gradient(var(--rp-c-bg), transparent 60%);
109
- content: '';
110
- }
111
-
112
- .leftNav {
113
- margin: 0 2rem;
114
- }
115
- }
@@ -1,150 +0,0 @@
1
- import { NavItem } from '@rspress/shared';
2
- import { useLocation } from 'react-router-dom';
3
- import { Search } from '@theme';
4
- import { useEffect, useState } from 'react';
5
- import { isMobileDevice, useHiddenNav, useLocaleSiteData } from '../../logic';
6
- import { NavHamburger } from '../NavHambmger';
7
- import { SocialLinks } from '../SocialLinks';
8
- import { SwitchAppearance } from '../SwitchAppearance';
9
- import { NavMenuGroup } from './NavMenuGroup';
10
- import { NavMenuSingleItem } from './NavMenuSingleItem';
11
- import styles from './index.module.scss';
12
- import { NavBarTitle } from './NavBarTitle';
13
- import { NavTranslations } from './NavTranslations';
14
- import { NavVersions } from './NavVersions';
15
- import { usePageData } from '@/runtime';
16
-
17
- export interface NavProps {
18
- beforeNav?: React.ReactNode;
19
- beforeNavTitle?: React.ReactNode;
20
- afterNavTitle?: React.ReactNode;
21
- }
22
-
23
- const DEFAULT_NAV_POSTION = 'right';
24
-
25
- export function Nav(props: NavProps) {
26
- const { beforeNavTitle, afterNavTitle, beforeNav } = props;
27
- const { siteData } = usePageData();
28
- const { base } = siteData;
29
- const { pathname } = useLocation();
30
- const localeData = useLocaleSiteData();
31
- const [isMobile, setIsMobile] = useState(false);
32
- const hiddenNav = useHiddenNav();
33
- const localeLanguages = Object.values(
34
- siteData.locales || siteData.themeConfig.locales || {},
35
- );
36
- const hasMultiLanguage = localeLanguages.length > 1;
37
- const hasMutilVersion = siteData.multiVersion.versions.length > 1;
38
- const socialLinks = siteData.themeConfig.socialLinks || [];
39
- const hasSocialLinks = socialLinks.length > 0;
40
- const langs = localeLanguages.map(item => item.lang || '') || [];
41
-
42
- useEffect(() => {
43
- setIsMobile(isMobileDevice());
44
- }, []);
45
-
46
- const NavMenu = ({ menuItems }: { menuItems: NavItem[] }) => {
47
- return (
48
- <div className="rspress-nav-menu menu h-14">
49
- {menuItems.map(item => {
50
- return 'items' in item || Array.isArray(item) ? (
51
- <div key={item.text} className="mx-3 last:mr-0">
52
- <NavMenuGroup
53
- {...item}
54
- base={base}
55
- pathname={pathname}
56
- langs={langs}
57
- items={'items' in item ? item.items : item}
58
- />
59
- </div>
60
- ) : (
61
- <NavMenuSingleItem
62
- pathname={pathname}
63
- langs={langs}
64
- base={base}
65
- key={item.link}
66
- {...item}
67
- />
68
- );
69
- })}
70
- </div>
71
- );
72
- };
73
-
74
- const menuItems = localeData.nav || [];
75
-
76
- const getPosition = (menuItem: NavItem) =>
77
- menuItem.position ?? DEFAULT_NAV_POSTION;
78
- const leftMenuItems = menuItems.filter(item => getPosition(item) === 'left');
79
- const rightMenuItems = menuItems.filter(
80
- item => getPosition(item) === 'right',
81
- );
82
-
83
- const hasSearch = siteData?.themeConfig?.search !== false;
84
-
85
- const hasAppearanceSwitch = siteData.themeConfig.darkMode !== false;
86
-
87
- const leftNav = () => {
88
- return leftMenuItems.length > 0 ? (
89
- <div className={styles.leftNav}>
90
- <NavMenu menuItems={leftMenuItems} />
91
- </div>
92
- ) : null;
93
- };
94
-
95
- const rightNav = () => {
96
- return (
97
- <div className={styles.rightNav}>
98
- {hasSearch && (
99
- <div className="flex sm:flex-1 items-center sm:pl-4 sm:pr-2">
100
- <Search />
101
- </div>
102
- )}
103
- <NavMenu menuItems={rightMenuItems} />
104
- <div className="flex-center flex-row">
105
- {hasMultiLanguage && <NavTranslations />}
106
- {hasMutilVersion && <NavVersions />}
107
- {hasAppearanceSwitch && (
108
- <div className="mx-2">
109
- <SwitchAppearance />
110
- </div>
111
- )}
112
- {hasSocialLinks && <SocialLinks socialLinks={socialLinks} />}
113
- </div>
114
- </div>
115
- );
116
- };
117
- return (
118
- <>
119
- {beforeNav}
120
- <div
121
- className={`${styles.navContainer} sticky rspress-nav px-6 ${
122
- hiddenNav ? styles.hidden : ''
123
- }`}
124
- >
125
- <div
126
- className={`${styles.container} flex justify-between items-center h-full`}
127
- >
128
- {beforeNavTitle}
129
- <NavBarTitle />
130
- {afterNavTitle}
131
- <div
132
- className={`${styles.content} flex flex-1 justify-end items-center`}
133
- >
134
- {leftNav()}
135
- {rightNav()}
136
-
137
- <div className={styles.mobileNavMenu}>
138
- {isMobile && <Search />}
139
- <NavHamburger
140
- localeData={localeData}
141
- siteData={siteData}
142
- pathname={pathname}
143
- />
144
- </div>
145
- </div>
146
- </div>
147
- </div>
148
- </>
149
- );
150
- }
@@ -1,75 +0,0 @@
1
- import { replaceLang, replaceVersion } from '@rspress/shared';
2
- import Translator from '../../assets/translator.svg';
3
- import { useLocation, usePageData, useVersion } from '@/runtime';
4
-
5
- export function useTranslationMenuData() {
6
- const { siteData, page } = usePageData();
7
- const currentVersion = useVersion();
8
- const { pathname } = useLocation();
9
- const defaultLang = siteData.lang || '';
10
- const defaultVersion = siteData.multiVersion.default || '';
11
- const localeLanguages = Object.values(
12
- siteData.locales || siteData.themeConfig.locales || {},
13
- );
14
- const hasMultiLanguage = localeLanguages.length > 1;
15
- const { lang: currentLang } = page;
16
- const { base } = siteData;
17
-
18
- const translationMenuData = hasMultiLanguage
19
- ? {
20
- text: (
21
- <Translator
22
- style={{
23
- width: '18px',
24
- height: '18px',
25
- }}
26
- />
27
- ),
28
- items: localeLanguages.map(item => ({
29
- text: item?.label,
30
- link: replaceLang(
31
- pathname,
32
- {
33
- current: currentLang,
34
- target: item.lang,
35
- default: defaultLang,
36
- },
37
- {
38
- current: currentVersion,
39
- default: defaultVersion,
40
- },
41
- base,
42
- ),
43
- })),
44
- activeValue: localeLanguages.find(item => currentLang === item.lang)
45
- ?.label,
46
- }
47
- : null;
48
- return translationMenuData;
49
- }
50
-
51
- export function useVersionMenuData() {
52
- const { siteData } = usePageData();
53
- const currentVersion = useVersion();
54
- const { pathname } = useLocation();
55
- const defaultVersion = siteData.multiVersion.default || '';
56
- const versions = siteData.multiVersion.versions || [];
57
- const { base } = siteData;
58
- const versionsMenuData = {
59
- items: versions.map(version => ({
60
- text: version,
61
- link: replaceVersion(
62
- pathname,
63
- {
64
- current: currentVersion,
65
- target: version,
66
- default: defaultVersion,
67
- },
68
- base,
69
- ),
70
- })),
71
- text: currentVersion,
72
- activeValue: currentVersion,
73
- };
74
- return versionsMenuData;
75
- }
@@ -1,81 +0,0 @@
1
- .navHamburger {
2
- display: flex;
3
- justify-content: center;
4
- align-items: center;
5
- width: 36px;
6
- height: 56px;
7
- margin-left: 6px;
8
- }
9
-
10
- @media (min-width: 768px) {
11
- .navHamburger {
12
- display: none;
13
- }
14
- }
15
- .container {
16
- position: relative;
17
- width: 16px;
18
- height: 14px;
19
- overflow: hidden;
20
- }
21
-
22
- .navHamburger:hover .top {
23
- top: 0;
24
- left: 0;
25
- transform: translateX(4px);
26
- }
27
- .navHamburger:hover .middle {
28
- top: 6px;
29
- left: 0;
30
- transform: translateX(0);
31
- }
32
- .navHamburger:hover .bottom {
33
- top: 12px;
34
- left: 0;
35
- transform: translateX(8px);
36
- }
37
-
38
- .navHamburger.active .top {
39
- top: 6px;
40
- transform: translateX(0) rotate(225deg);
41
- }
42
- .navHamburger.active .middle {
43
- top: 6px;
44
- transform: translateX(16px);
45
- }
46
- .navHamburger.active .bottom {
47
- top: 6px;
48
- transform: translateX(0) rotate(135deg);
49
- }
50
-
51
- .navHamburger.active:hover .top,
52
- .navHamburger.active:hover .middle,
53
- .navHamburger.active:hover .bottom {
54
- transition: top 0.25s, background-color 0.25s, transform 0.25s;
55
- }
56
-
57
- .top,
58
- .middle,
59
- .bottom {
60
- position: absolute;
61
- width: 16px;
62
- height: 1.5px;
63
- background-color: var(--rp-c-text-2);
64
- transition: top 0.25s, background-color 0.5s, transform 0.25s;
65
- }
66
-
67
- .top {
68
- top: 0;
69
- left: 0;
70
- transform: translateX(0);
71
- }
72
- .middle {
73
- top: 6px;
74
- left: 0;
75
- transform: translateX(8px);
76
- }
77
- .bottom {
78
- top: 12px;
79
- left: 0;
80
- transform: translateX(4px);
81
- }
@@ -1,39 +0,0 @@
1
- import { Fragment } from 'react';
2
- import type {
3
- LocaleConfig,
4
- SiteData,
5
- DefaultThemeConfig,
6
- } from '@rspress/shared';
7
- import { NavScreen } from '../NavScreen';
8
- import { useNav } from '../../logic/useNav';
9
- import SmallMenu from '../../assets/small-menu.svg';
10
- import styles from './index.module.scss';
11
-
12
- interface Props {
13
- localeData: LocaleConfig;
14
- siteData: SiteData<DefaultThemeConfig>;
15
- pathname: string;
16
- }
17
-
18
- export function NavHamburger(props: Props) {
19
- const { localeData, siteData, pathname } = props;
20
- const { isScreenOpen, toggleScreen } = useNav();
21
- return (
22
- <Fragment>
23
- <NavScreen
24
- isScreenOpen={isScreenOpen}
25
- localeData={localeData}
26
- siteData={siteData}
27
- pathname={pathname}
28
- />
29
- <button
30
- onClick={toggleScreen}
31
- className={`${isScreenOpen ? styles.active : ''} ${
32
- styles.navHamburger
33
- } text-gray-500`}
34
- >
35
- <SmallMenu fill="currentColor" />
36
- </button>
37
- </Fragment>
38
- );
39
- }
@@ -1,95 +0,0 @@
1
- import {
2
- NavItem,
3
- NavItemWithChildren,
4
- NavItemWithLink,
5
- NavItemWithLinkAndChildren,
6
- } from '@rspress/shared';
7
- import { useState } from 'react';
8
- import Down from '../../assets/down.svg';
9
- import { Link } from '../Link';
10
- import styles from './index.module.scss';
11
-
12
- export interface NavScreenMenuGroupItem {
13
- text?: string | React.ReactElement;
14
- items: NavItem[];
15
- activeValue?: string;
16
- }
17
-
18
- export function NavScreenMenuGroup(item: NavScreenMenuGroupItem) {
19
- const { activeValue } = item;
20
- const [isOpen, setIsOpen] = useState(false);
21
-
22
- function ActiveGroupItem({ item }: { item: NavItemWithLink }) {
23
- return (
24
- <div className="p-1 text-center">
25
- <span className="text-brand">{item.text}</span>
26
- </div>
27
- );
28
- }
29
-
30
- function NormalGroupItem({ item }: { item: NavItemWithLink }) {
31
- return (
32
- <div className="py-1 font-medium">
33
- <Link href={item.link}>
34
- <div>
35
- <div className="flex justify-center">
36
- <span>{item.text}</span>
37
- </div>
38
- </div>
39
- </Link>
40
- </div>
41
- );
42
- }
43
-
44
- const renderLinkItem = (item: NavItemWithLink) => {
45
- if (activeValue === item.text) {
46
- return <ActiveGroupItem key={item.link} item={item} />;
47
- }
48
- return <NormalGroupItem key={item.link} item={item} />;
49
- };
50
- const renderGroup = (
51
- item: NavItemWithChildren | NavItemWithLinkAndChildren,
52
- ) => {
53
- return (
54
- <div>
55
- {'link' in item ? (
56
- renderLinkItem(item as NavItemWithLink)
57
- ) : (
58
- <p className="font-bold text-gray-400 my-1 not:first:border">
59
- {item.text}
60
- </p>
61
- )}
62
- {(item.items as NavItemWithLink[]).map(renderLinkItem)}
63
- </div>
64
- );
65
- };
66
- return (
67
- <div
68
- className={`${isOpen ? styles.open : ''} ${
69
- styles.navScreenMenuGroup
70
- } relative`}
71
- >
72
- <button
73
- className={styles.button}
74
- onClick={() => {
75
- setIsOpen(!isOpen);
76
- }}
77
- >
78
- <span className={styles.buttonSpan}>{item.text}</span>
79
- <Down className={`${isOpen ? styles.open : ''} ${styles.down} `} />
80
- </button>
81
- <div>
82
- <div className={styles.items}>
83
- {/* The item could be a link or a sub group */}
84
- {item.items.map(item => {
85
- return (
86
- <div key={item.text}>
87
- {'items' in item ? renderGroup(item) : renderLinkItem(item)}
88
- </div>
89
- );
90
- })}
91
- </div>
92
- </div>
93
- </div>
94
- );
95
- }