@alauda/doom 1.18.3 → 1.19.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.
- package/lib/theme/AutoExpandable.d.ts +5 -0
- package/lib/theme/AutoExpandable.js +28 -0
- package/lib/theme/CodeBlock.d.ts +2 -0
- package/lib/theme/CodeBlock.js +4 -0
- package/lib/theme/index.d.ts +1 -0
- package/lib/theme/index.js +1 -0
- package/package.json +1 -1
- package/styles/auto-expandable.module.scss +77 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { IconDown, SvgWrapper } from '@rspress/core/theme';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import classes from '@alauda/doom/styles/auto-expandable.module.scss';
|
|
6
|
+
export const AutoExpandable = ({ threshold = 240, children, }) => {
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const [expandable, setExpandable] = useState(false);
|
|
9
|
+
const [expanded, setExpanded] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!ref.current) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (ref.current.scrollHeight > threshold) {
|
|
15
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect, @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
|
|
16
|
+
setExpandable(true);
|
|
17
|
+
}
|
|
18
|
+
}, [threshold]);
|
|
19
|
+
const onExpandChange = useCallback(() => {
|
|
20
|
+
setExpanded((expanded) => !expanded);
|
|
21
|
+
}, []);
|
|
22
|
+
return (_jsxs("div", { ref: ref, className: classes.container, children: [_jsx("div", { className: clsx({
|
|
23
|
+
[classes.expandable]: expandable,
|
|
24
|
+
[classes.expanded]: expanded,
|
|
25
|
+
}), children: children }), expandable && (_jsx("div", { className: classes.actionContainer, children: _jsxs("button", { className: classes.action, type: "button", onClick: onExpandChange, "aria-expanded": expanded, children: ["Show ", expanded ? 'less' : 'more', _jsx(SvgWrapper, { className: clsx(classes.arrow, {
|
|
26
|
+
[classes.expanded]: expanded,
|
|
27
|
+
}), icon: IconDown })] }) }))] }));
|
|
28
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CodeBlock as OriginalCodeBlock, } from '@rspress/core/theme-original';
|
|
3
|
+
import { AutoExpandable } from './AutoExpandable.js';
|
|
4
|
+
export const CodeBlock = (props) => (_jsx(AutoExpandable, { children: _jsx(OriginalCodeBlock, { ...props }) }));
|
package/lib/theme/index.d.ts
CHANGED
package/lib/theme/index.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
&:has(.expandable :global .rp-codeblock) {
|
|
3
|
+
border: var(--rp-code-block-border);
|
|
4
|
+
border-radius: var(--rp-radius);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.expandable {
|
|
8
|
+
max-height: 200px;
|
|
9
|
+
overflow: auto;
|
|
10
|
+
|
|
11
|
+
:global .rp-codeblock {
|
|
12
|
+
border: 0;
|
|
13
|
+
margin: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&.expanded {
|
|
17
|
+
max-height: none;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.action-container {
|
|
23
|
+
display: flex;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.action {
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
align-items: center;
|
|
31
|
+
height: 36px;
|
|
32
|
+
padding: 0 12px;
|
|
33
|
+
gap: 6px;
|
|
34
|
+
margin: 1rem 0;
|
|
35
|
+
|
|
36
|
+
border-radius: 8px;
|
|
37
|
+
border: 1px solid var(--rp-c-divider-light);
|
|
38
|
+
background: var(--rp-c-bg);
|
|
39
|
+
color: var(--rp-c-text-2);
|
|
40
|
+
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
font-weight: 500;
|
|
43
|
+
line-height: normal;
|
|
44
|
+
|
|
45
|
+
user-select: none;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
|
|
48
|
+
transition:
|
|
49
|
+
background 0.2s,
|
|
50
|
+
border-color 0.2s,
|
|
51
|
+
color 0.2s,
|
|
52
|
+
box-shadow 0.2s,
|
|
53
|
+
transform 0.1s,
|
|
54
|
+
opacity 0.2s;
|
|
55
|
+
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
|
|
58
|
+
&:hover {
|
|
59
|
+
background: var(--rp-c-bg-soft);
|
|
60
|
+
border-color: var(--rp-c-divider);
|
|
61
|
+
color: var(--rp-c-text-1);
|
|
62
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&:active {
|
|
66
|
+
background: var(--rp-c-bg-soft);
|
|
67
|
+
box-shadow: none;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.arrow {
|
|
72
|
+
transition: transform 0.2s;
|
|
73
|
+
|
|
74
|
+
&.expanded {
|
|
75
|
+
transform: rotate(180deg);
|
|
76
|
+
}
|
|
77
|
+
}
|