@xyd-js/ui 0.1.0-xyd.4 → 0.1.0-xyd.6
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/dist/index.js +222 -1
- package/package.json +10 -6
- package/check.json +0 -8795
- package/index.ts +0 -3
- package/rollup.config.js +0 -79
- package/src/components/Anchor/Anchor.styles.ts +0 -7
- package/src/components/Anchor/Anchor.tsx +0 -57
- package/src/components/Anchor/index.ts +0 -7
- package/src/components/Nav/Nav.styles.tsx +0 -87
- package/src/components/Nav/Nav.tsx +0 -56
- package/src/components/Nav/index.ts +0 -8
- package/src/components/Sidebar/Collapse.styles.tsx +0 -24
- package/src/components/Sidebar/Collapse.tsx +0 -84
- package/src/components/Sidebar/Sidebar.styles.tsx +0 -117
- package/src/components/Sidebar/Sidebar.tsx +0 -121
- package/src/components/Sidebar/index.ts +0 -11
- package/src/components/SubNav/SubNav.styles.tsx +0 -81
- package/src/components/SubNav/SubNav.tsx +0 -42
- package/src/components/SubNav/index.ts +0 -7
- package/src/components/Toc/Toc.styles.tsx +0 -56
- package/src/components/Toc/Toc.tsx +0 -152
- package/src/components/Toc/index.ts +0 -1
- package/src/components/index.ts +0 -13
- package/src/types/index.ts +0 -23
- package/tsconfig.json +0 -41
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {css} from "@linaria/core";
|
|
2
|
-
|
|
3
|
-
export const $subNav = {
|
|
4
|
-
host: css`
|
|
5
|
-
align-items: center;
|
|
6
|
-
background-color: #f6f6f7;
|
|
7
|
-
border-radius: 0.50rem;
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: row;
|
|
10
|
-
|
|
11
|
-
width: 100%;
|
|
12
|
-
height: 44px;
|
|
13
|
-
margin-top: 3px;
|
|
14
|
-
padding: 0 0.25rem;
|
|
15
|
-
`,
|
|
16
|
-
prefix: css`
|
|
17
|
-
color: #44474a;
|
|
18
|
-
//font: var(--font-sans-font-nav-category-base);
|
|
19
|
-
font-size: 12px;
|
|
20
|
-
font-weight: 600;
|
|
21
|
-
padding-left: 0.50rem;
|
|
22
|
-
padding-right: 1.50rem;
|
|
23
|
-
position: relative;
|
|
24
|
-
text-transform: uppercase;
|
|
25
|
-
|
|
26
|
-
&:after {
|
|
27
|
-
background: #d2d5d8;
|
|
28
|
-
border-radius: 1px;
|
|
29
|
-
content: " ";
|
|
30
|
-
height: 0.75rem;
|
|
31
|
-
position: absolute;
|
|
32
|
-
right: 0.50rem;
|
|
33
|
-
top: 50%;
|
|
34
|
-
transform: translateY(-50%);
|
|
35
|
-
width: 2px;
|
|
36
|
-
}
|
|
37
|
-
`,
|
|
38
|
-
ul: css`
|
|
39
|
-
display: flex;
|
|
40
|
-
flex-direction: row;
|
|
41
|
-
height: 100%;
|
|
42
|
-
`,
|
|
43
|
-
li: css`
|
|
44
|
-
display: flex;
|
|
45
|
-
height: 100%;
|
|
46
|
-
|
|
47
|
-
align-items: center;
|
|
48
|
-
position: relative;
|
|
49
|
-
|
|
50
|
-
&[data-state="active"] {
|
|
51
|
-
font-weight: 500;
|
|
52
|
-
|
|
53
|
-
a {
|
|
54
|
-
color: #202223;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
a:after {
|
|
58
|
-
background-color: #7051d4;
|
|
59
|
-
border-radius: 1px;
|
|
60
|
-
bottom: 0;
|
|
61
|
-
content: " ";
|
|
62
|
-
height: 2px;
|
|
63
|
-
left: 0;
|
|
64
|
-
position: absolute;
|
|
65
|
-
width: 100%;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`,
|
|
69
|
-
link: css`
|
|
70
|
-
color: #4b5563;
|
|
71
|
-
//font: var(--font-sans-font-nav-item-active-base);
|
|
72
|
-
line-height: 2.75rem;
|
|
73
|
-
display: block;
|
|
74
|
-
height: 100%;
|
|
75
|
-
padding: 0 0.50rem;
|
|
76
|
-
|
|
77
|
-
&:hover {
|
|
78
|
-
color: #202223;
|
|
79
|
-
}
|
|
80
|
-
`
|
|
81
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import * as RadixTabs from "@radix-ui/react-tabs";
|
|
3
|
-
|
|
4
|
-
import {$subNav} from "./SubNav.styles";
|
|
5
|
-
|
|
6
|
-
export interface SubNavProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
title: string
|
|
9
|
-
value: string
|
|
10
|
-
onChange: (value: string) => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function SubNav({children, title, value, onChange}: SubNavProps) {
|
|
14
|
-
return <RadixTabs.Root asChild value={value} onValueChange={onChange}>
|
|
15
|
-
<nav className={$subNav.host}>
|
|
16
|
-
<div className={$subNav.prefix}>
|
|
17
|
-
{title}
|
|
18
|
-
</div>
|
|
19
|
-
<RadixTabs.List asChild>
|
|
20
|
-
<ul className={$subNav.ul}>
|
|
21
|
-
{children}
|
|
22
|
-
</ul>
|
|
23
|
-
</RadixTabs.List>
|
|
24
|
-
</nav>
|
|
25
|
-
</RadixTabs.Root>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface SubNavItemProps {
|
|
29
|
-
children: React.ReactNode
|
|
30
|
-
value: string
|
|
31
|
-
href?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
SubNav.Item = function SubNavItem({children, value, href}: SubNavItemProps) {
|
|
35
|
-
return <RadixTabs.Trigger asChild value={value}>
|
|
36
|
-
<li className={$subNav.li}>
|
|
37
|
-
<a href={href} className={`${$subNav.link}`}>
|
|
38
|
-
{children}
|
|
39
|
-
</a>
|
|
40
|
-
</li>
|
|
41
|
-
</RadixTabs.Trigger>
|
|
42
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {css} from '@linaria/core';
|
|
2
|
-
|
|
3
|
-
export const $toc = {
|
|
4
|
-
host: css`
|
|
5
|
-
position: relative;
|
|
6
|
-
padding-left: 16px;
|
|
7
|
-
`,
|
|
8
|
-
ul: css`
|
|
9
|
-
margin: 0;
|
|
10
|
-
padding: 0;
|
|
11
|
-
list-style: none;
|
|
12
|
-
`,
|
|
13
|
-
li: css`
|
|
14
|
-
position: relative;
|
|
15
|
-
line-height: 1.5;
|
|
16
|
-
|
|
17
|
-
margin: 0 0 10px;
|
|
18
|
-
padding: 0;
|
|
19
|
-
`,
|
|
20
|
-
link: css`
|
|
21
|
-
display: inline-block;
|
|
22
|
-
font-size: 14px;
|
|
23
|
-
color: #6e6e80;
|
|
24
|
-
line-height: 1.4;
|
|
25
|
-
text-wrap: pretty;
|
|
26
|
-
transition: color .15s ease;
|
|
27
|
-
`,
|
|
28
|
-
link$$active: css`
|
|
29
|
-
font-weight: 500;
|
|
30
|
-
color: #353740;
|
|
31
|
-
`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const cubizEnter = 'cubic-bezier(.19, 1, .22, 1)';
|
|
35
|
-
|
|
36
|
-
export const $scroller = {
|
|
37
|
-
host: css`
|
|
38
|
-
position: absolute;
|
|
39
|
-
top: 0;
|
|
40
|
-
bottom: 0;
|
|
41
|
-
left: 0;
|
|
42
|
-
width: 2px;
|
|
43
|
-
|
|
44
|
-
background-color: #ececf1;
|
|
45
|
-
`,
|
|
46
|
-
scroll: css`
|
|
47
|
-
position: absolute;
|
|
48
|
-
top: 0;
|
|
49
|
-
left: 0;
|
|
50
|
-
width: 2px;
|
|
51
|
-
height: var(--active-track-height); // TODO: this must be dynamic
|
|
52
|
-
transform: translateY(var(--active-track-top)); // TODO: this must be dynamic
|
|
53
|
-
background-color: #353740;
|
|
54
|
-
transition: height .4s ${cubizEnter}, transform .4s ${cubizEnter};
|
|
55
|
-
`
|
|
56
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import React, {useState, useEffect, useContext} from "react"
|
|
2
|
-
|
|
3
|
-
import {$toc, $scroller} from "./Toc.styles";
|
|
4
|
-
|
|
5
|
-
export interface TocProps {
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
defaultValue?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Context = React.createContext({
|
|
11
|
-
value: "",
|
|
12
|
-
onChange: (v: string) => {
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
// TODO: based on scroller?
|
|
17
|
-
export function Toc({children, defaultValue}: TocProps) {
|
|
18
|
-
const [activeTrackHeight, setActiveTrackHeight] = useState(0)
|
|
19
|
-
const [activeTrackTop, setActiveTrackTop] = useState(0)
|
|
20
|
-
|
|
21
|
-
const [value, setValue] = useState(defaultValue || "")
|
|
22
|
-
|
|
23
|
-
// TODO: more reactish implt?
|
|
24
|
-
function handleScroll() {
|
|
25
|
-
const activeElement = document.querySelector(`.${$toc.link$$active}`);
|
|
26
|
-
if (!activeElement) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const {offsetHeight} = activeElement as HTMLElement;
|
|
31
|
-
setActiveTrackHeight(offsetHeight);
|
|
32
|
-
|
|
33
|
-
if (!activeElement?.parentElement) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const {offsetTop} = activeElement.parentElement as HTMLElement;
|
|
38
|
-
setActiveTrackTop(offsetTop);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function onChange(v: string) {
|
|
42
|
-
setValue(v)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// TODO: more reactish
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
const observer = new IntersectionObserver(
|
|
49
|
-
(entries) => {
|
|
50
|
-
let set = false
|
|
51
|
-
entries.forEach(entry => {
|
|
52
|
-
if (set) {
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
if (!entry.isIntersecting) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (entry.target instanceof HTMLHeadingElement) {
|
|
60
|
-
const rect = entry.target.getBoundingClientRect();
|
|
61
|
-
const isVisible = rect.top >= 0 && rect.bottom <= window.innerHeight;
|
|
62
|
-
|
|
63
|
-
if (isVisible) {
|
|
64
|
-
set = true
|
|
65
|
-
setValue(entry.target.innerText);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
{threshold: 0.3}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
document.querySelectorAll("h2").forEach(ref => {
|
|
74
|
-
if (ref) observer.observe(ref);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return () => {
|
|
78
|
-
observer.disconnect();
|
|
79
|
-
};
|
|
80
|
-
}, []);
|
|
81
|
-
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
handleScroll(); // Initial call to set the values
|
|
84
|
-
}, [value]);
|
|
85
|
-
|
|
86
|
-
return <Context.Provider value={{
|
|
87
|
-
value: value,
|
|
88
|
-
onChange
|
|
89
|
-
}}>
|
|
90
|
-
<div className={$toc.host}>
|
|
91
|
-
<div className={$scroller.host}>
|
|
92
|
-
<div
|
|
93
|
-
style={{
|
|
94
|
-
// @ts-ignore
|
|
95
|
-
"--active-track-height": `${activeTrackHeight}px`,
|
|
96
|
-
"--active-track-top": `${activeTrackTop}px`,
|
|
97
|
-
}}
|
|
98
|
-
className={$scroller.scroll}
|
|
99
|
-
/>
|
|
100
|
-
</div>
|
|
101
|
-
<ul className={$toc.ul}>
|
|
102
|
-
{children}
|
|
103
|
-
</ul>
|
|
104
|
-
</div>
|
|
105
|
-
</Context.Provider>
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface TocItemProps {
|
|
109
|
-
children: React.ReactNode;
|
|
110
|
-
value: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Toc.Item = function TocItem({
|
|
114
|
-
children,
|
|
115
|
-
value = "#",
|
|
116
|
-
}: TocItemProps) {
|
|
117
|
-
const {
|
|
118
|
-
value: rootValue,
|
|
119
|
-
onChange
|
|
120
|
-
} = useContext(Context);
|
|
121
|
-
|
|
122
|
-
const href = "#" + value
|
|
123
|
-
const active = rootValue === value;
|
|
124
|
-
|
|
125
|
-
return <li className={$toc.li}>
|
|
126
|
-
<a
|
|
127
|
-
className={`${$toc.link} ${active && $toc.link$$active}`}
|
|
128
|
-
href={href}
|
|
129
|
-
onClick={(e) => {
|
|
130
|
-
// TODO: use react-router but for some reason does not work
|
|
131
|
-
e.preventDefault()
|
|
132
|
-
onChange(value)
|
|
133
|
-
|
|
134
|
-
let found = false
|
|
135
|
-
|
|
136
|
-
// TODO: below is only a temporary solution
|
|
137
|
-
document.querySelectorAll("h2").forEach(e => {
|
|
138
|
-
if (found) {
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (e.innerText === value) {
|
|
143
|
-
found = true
|
|
144
|
-
e.scrollIntoView()
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
}}
|
|
148
|
-
>
|
|
149
|
-
{children}
|
|
150
|
-
</a>
|
|
151
|
-
</li>
|
|
152
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {Toc} from "./Toc";
|
package/src/components/index.ts
DELETED
package/src/types/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface ITOC {
|
|
2
|
-
depth: number
|
|
3
|
-
value: string
|
|
4
|
-
children: ITOC[]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IBreadcrumb {
|
|
8
|
-
title: string,
|
|
9
|
-
href: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface INavLinks {
|
|
13
|
-
prev?: {
|
|
14
|
-
title: string,
|
|
15
|
-
href: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
next?: {
|
|
19
|
-
title: string,
|
|
20
|
-
href: string
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "esnext",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"moduleResolution": "bundler", // Update this line
|
|
6
|
-
"target": "ES6",
|
|
7
|
-
"lib": [
|
|
8
|
-
"dom",
|
|
9
|
-
"dom.iterable",
|
|
10
|
-
"esnext"
|
|
11
|
-
],
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"strict": false,
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
"incremental": false,
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"isolatedModules": true,
|
|
19
|
-
"jsx": "react",
|
|
20
|
-
"plugins": [
|
|
21
|
-
{
|
|
22
|
-
"name": "next"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"strictNullChecks": true,
|
|
26
|
-
"allowImportingTsExtensions": true,
|
|
27
|
-
"baseUrl": ".",
|
|
28
|
-
"paths": {
|
|
29
|
-
"*": ["*", "*.ts"]
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"include": [
|
|
33
|
-
"next-env.d.ts",
|
|
34
|
-
"**/*.ts",
|
|
35
|
-
"**/*.tsx",
|
|
36
|
-
".next/types/**/*.ts"
|
|
37
|
-
],
|
|
38
|
-
"exclude": [
|
|
39
|
-
"node_modules"
|
|
40
|
-
]
|
|
41
|
-
}
|