@zpress/ui 0.4.0 → 0.4.1

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.
@@ -1,8 +1,53 @@
1
1
  import { Layout as OriginalLayout } from '@rspress/core/theme-original'
2
2
  import type React from 'react'
3
+ import { useEffect, useState } from 'react'
3
4
 
4
5
  import { BranchTag } from './branch-tag'
5
6
  import { ThemeSwitcher } from './theme-switcher'
7
+ import { VscodeTag } from './vscode-tag'
8
+
9
+ const VSCODE_OVERRIDES = [
10
+ /* Hide left sidebar and its placeholder */
11
+ '.rp-doc-layout__sidebar { display: none !important; }',
12
+ '.rp-doc-layout__sidebar-placeholder { display: none !important; }',
13
+ /* Hide right TOC and its placeholder */
14
+ '.rp-doc-layout__outline { display: none !important; }',
15
+ '.rp-doc-layout__outline-placeholder { display: none !important; }',
16
+ /* Center content at 1200px max */
17
+ '.rp-doc-layout__doc { max-width: 1200px !important; margin: 0 auto !important; }',
18
+ /* Hide nav items, social links, hamburger */
19
+ '.rp-nav-menu__item { display: none !important; }',
20
+ '.rp-social-links { display: none !important; }',
21
+ '.rp-nav-hamburger { display: none !important; }',
22
+ ].join('\n')
23
+
24
+ function useVscodeMode(): boolean {
25
+ const [active, setActive] = useState(false)
26
+
27
+ useEffect(() => {
28
+ const params = new URLSearchParams(globalThis.location.search)
29
+ const isVscode =
30
+ params.get('env') === 'vscode' || globalThis.sessionStorage.getItem('zpress-env') === 'vscode'
31
+
32
+ if (!isVscode) {
33
+ return
34
+ }
35
+
36
+ globalThis.sessionStorage.setItem('zpress-env', 'vscode')
37
+ setActive(true)
38
+ document.documentElement.dataset.zpressEnv = 'vscode'
39
+
40
+ const style = document.createElement('style')
41
+ style.textContent = VSCODE_OVERRIDES
42
+ document.head.append(style)
43
+ return () => {
44
+ style.remove()
45
+ delete document.documentElement.dataset.zpressEnv
46
+ }
47
+ }, [])
48
+
49
+ return active
50
+ }
6
51
 
7
52
  /**
8
53
  * Custom Layout override for zpress.
@@ -10,5 +55,17 @@ import { ThemeSwitcher } from './theme-switcher'
10
55
  * into `beforeNavMenu` and ThemeSwitcher into `afterNavMenu`.
11
56
  */
12
57
  export function Layout(): React.ReactElement {
13
- return <OriginalLayout beforeNavMenu={<BranchTag />} afterNavMenu={<ThemeSwitcher />} />
58
+ const vscode = useVscodeMode()
59
+ const navSlot = (() => {
60
+ if (vscode) {
61
+ return (
62
+ <>
63
+ <BranchTag />
64
+ <VscodeTag />
65
+ </>
66
+ )
67
+ }
68
+ return <BranchTag />
69
+ })()
70
+ return <OriginalLayout beforeNavMenu={navSlot} afterNavMenu={<ThemeSwitcher />} />
14
71
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * VS Code tag pill — mode indicator badge positioned in the nav bar.
3
+ */
4
+
5
+ .vscode-tag {
6
+ display: inline-flex;
7
+ align-items: center;
8
+ gap: 5px;
9
+ margin-left: 6px;
10
+ padding: 3px 10px;
11
+ border-radius: 20px;
12
+ background: var(--zp-c-bg-soft);
13
+ border: 1px solid var(--zp-c-brand-1, #a78bfa);
14
+ color: var(--zp-c-brand-1, #a78bfa);
15
+ font-family: var(--zp-font-family-mono);
16
+ font-size: 11px;
17
+ font-weight: 600;
18
+ line-height: 1;
19
+ white-space: nowrap;
20
+ }
21
+
22
+ .vscode-tag svg {
23
+ width: 14px;
24
+ height: 14px;
25
+ flex-shrink: 0;
26
+ }
27
+
28
+ @media (max-width: 768px) {
29
+ .vscode-tag-text {
30
+ display: none;
31
+ }
32
+ }
@@ -0,0 +1,18 @@
1
+ import type React from 'react'
2
+
3
+ import './vscode-tag.css'
4
+ import { Icon } from '../shared/icon.tsx'
5
+
6
+ /**
7
+ * VS Code mode indicator — pill-shaped badge rendered next to the
8
+ * BranchTag when the page is loaded inside the VS Code webview
9
+ * (detected via `?env=vscode` query parameter).
10
+ */
11
+ export function VscodeTag(): React.ReactElement {
12
+ return (
13
+ <span className="vscode-tag" title="VS Code preview mode" aria-label="VS Code preview mode">
14
+ <Icon icon="vscode-icons:file-type-vscode" width={14} height={14} />
15
+ <span className="vscode-tag-text">vscode</span>
16
+ </span>
17
+ )
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zpress/ui",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Rspress plugin, theme components, and styles for zpress",
5
5
  "keywords": [
6
6
  "react",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@iconify-json/catppuccin": "^1.2.17",
45
- "@iconify-json/devicon": "^1.2.59",
45
+ "@iconify-json/devicon": "^1.2.60",
46
46
  "@iconify-json/logos": "^1.2.10",
47
47
  "@iconify-json/material-icon-theme": "^1.2.55",
48
48
  "@iconify-json/mdi": "^1.2.3",
@@ -1,8 +1,53 @@
1
1
  import { Layout as OriginalLayout } from '@rspress/core/theme-original'
2
2
  import type React from 'react'
3
+ import { useEffect, useState } from 'react'
3
4
 
4
5
  import { BranchTag } from './branch-tag'
5
6
  import { ThemeSwitcher } from './theme-switcher'
7
+ import { VscodeTag } from './vscode-tag'
8
+
9
+ const VSCODE_OVERRIDES = [
10
+ /* Hide left sidebar and its placeholder */
11
+ '.rp-doc-layout__sidebar { display: none !important; }',
12
+ '.rp-doc-layout__sidebar-placeholder { display: none !important; }',
13
+ /* Hide right TOC and its placeholder */
14
+ '.rp-doc-layout__outline { display: none !important; }',
15
+ '.rp-doc-layout__outline-placeholder { display: none !important; }',
16
+ /* Center content at 1200px max */
17
+ '.rp-doc-layout__doc { max-width: 1200px !important; margin: 0 auto !important; }',
18
+ /* Hide nav items, social links, hamburger */
19
+ '.rp-nav-menu__item { display: none !important; }',
20
+ '.rp-social-links { display: none !important; }',
21
+ '.rp-nav-hamburger { display: none !important; }',
22
+ ].join('\n')
23
+
24
+ function useVscodeMode(): boolean {
25
+ const [active, setActive] = useState(false)
26
+
27
+ useEffect(() => {
28
+ const params = new URLSearchParams(globalThis.location.search)
29
+ const isVscode =
30
+ params.get('env') === 'vscode' || globalThis.sessionStorage.getItem('zpress-env') === 'vscode'
31
+
32
+ if (!isVscode) {
33
+ return
34
+ }
35
+
36
+ globalThis.sessionStorage.setItem('zpress-env', 'vscode')
37
+ setActive(true)
38
+ document.documentElement.dataset.zpressEnv = 'vscode'
39
+
40
+ const style = document.createElement('style')
41
+ style.textContent = VSCODE_OVERRIDES
42
+ document.head.append(style)
43
+ return () => {
44
+ style.remove()
45
+ delete document.documentElement.dataset.zpressEnv
46
+ }
47
+ }, [])
48
+
49
+ return active
50
+ }
6
51
 
7
52
  /**
8
53
  * Custom Layout override for zpress.
@@ -10,5 +55,17 @@ import { ThemeSwitcher } from './theme-switcher'
10
55
  * into `beforeNavMenu` and ThemeSwitcher into `afterNavMenu`.
11
56
  */
12
57
  export function Layout(): React.ReactElement {
13
- return <OriginalLayout beforeNavMenu={<BranchTag />} afterNavMenu={<ThemeSwitcher />} />
58
+ const vscode = useVscodeMode()
59
+ const navSlot = (() => {
60
+ if (vscode) {
61
+ return (
62
+ <>
63
+ <BranchTag />
64
+ <VscodeTag />
65
+ </>
66
+ )
67
+ }
68
+ return <BranchTag />
69
+ })()
70
+ return <OriginalLayout beforeNavMenu={navSlot} afterNavMenu={<ThemeSwitcher />} />
14
71
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * VS Code tag pill — mode indicator badge positioned in the nav bar.
3
+ */
4
+
5
+ .vscode-tag {
6
+ display: inline-flex;
7
+ align-items: center;
8
+ gap: 5px;
9
+ margin-left: 6px;
10
+ padding: 3px 10px;
11
+ border-radius: 20px;
12
+ background: var(--zp-c-bg-soft);
13
+ border: 1px solid var(--zp-c-brand-1, #a78bfa);
14
+ color: var(--zp-c-brand-1, #a78bfa);
15
+ font-family: var(--zp-font-family-mono);
16
+ font-size: 11px;
17
+ font-weight: 600;
18
+ line-height: 1;
19
+ white-space: nowrap;
20
+ }
21
+
22
+ .vscode-tag svg {
23
+ width: 14px;
24
+ height: 14px;
25
+ flex-shrink: 0;
26
+ }
27
+
28
+ @media (max-width: 768px) {
29
+ .vscode-tag-text {
30
+ display: none;
31
+ }
32
+ }
@@ -0,0 +1,18 @@
1
+ import type React from 'react'
2
+
3
+ import './vscode-tag.css'
4
+ import { Icon } from '../shared/icon.tsx'
5
+
6
+ /**
7
+ * VS Code mode indicator — pill-shaped badge rendered next to the
8
+ * BranchTag when the page is loaded inside the VS Code webview
9
+ * (detected via `?env=vscode` query parameter).
10
+ */
11
+ export function VscodeTag(): React.ReactElement {
12
+ return (
13
+ <span className="vscode-tag" title="VS Code preview mode" aria-label="VS Code preview mode">
14
+ <Icon icon="vscode-icons:file-type-vscode" width={14} height={14} />
15
+ <span className="vscode-tag-text">vscode</span>
16
+ </span>
17
+ )
18
+ }