@redocly/theme-experimental 0.0.8 → 0.74.2-pingfed.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.
- package/markdoc/CodeStep/CodeStep.tsx +67 -0
- package/markdoc/components.tsx +1 -0
- package/markdoc/schema.ts +8 -0
- package/package.json +2 -5
- package/lib/layouts/CodeGuide/CodeDemo.d.ts +0 -2
- package/lib/layouts/CodeGuide/CodeDemo.js +0 -40
- package/lib/layouts/CodeGuide/CodeGuide.d.ts +0 -2
- package/lib/layouts/CodeGuide/CodeGuide.js +0 -39
- package/lib/mocks/CodeGuide/index.d.ts +0 -36
- package/lib/mocks/CodeGuide/index.js +0 -60
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useRef, useContext, useEffect, useCallback } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { PropsWithChildren } from 'react';
|
|
5
|
+
|
|
6
|
+
import { CodeGuideContext, useCodeStepHandlers } from '@portal/CodeGuide';
|
|
7
|
+
|
|
8
|
+
interface CodeStepProps {
|
|
9
|
+
bindTo: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function CodeStep({ bindTo, children }: PropsWithChildren<CodeStepProps>) {
|
|
13
|
+
const context = useContext(CodeGuideContext);
|
|
14
|
+
|
|
15
|
+
const node = useRef<HTMLDivElement | null>(null);
|
|
16
|
+
|
|
17
|
+
const isSectionActive = context.activeDocsSection === bindTo;
|
|
18
|
+
const [file, lines] = bindTo.split('#');
|
|
19
|
+
|
|
20
|
+
const { onScroll, activateSection } = useCodeStepHandlers({
|
|
21
|
+
nodeRef: node,
|
|
22
|
+
bindTo,
|
|
23
|
+
context: context,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const scrollListener = useCallback(() => {
|
|
27
|
+
onScroll(context.codeBlock);
|
|
28
|
+
}, [context.codeBlock, onScroll]);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
window.addEventListener('scroll', scrollListener);
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
window.removeEventListener('scroll', scrollListener);
|
|
35
|
+
};
|
|
36
|
+
}, [context.codeBlock, scrollListener]);
|
|
37
|
+
|
|
38
|
+
const setRef = (instance?: HTMLDivElement | null) => {
|
|
39
|
+
if (instance) {
|
|
40
|
+
node.current = instance;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Wrapper
|
|
46
|
+
onClick={() => activateSection(file, lines, context.codeBlock)}
|
|
47
|
+
active={isSectionActive}
|
|
48
|
+
ref={setRef}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</Wrapper>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const Wrapper = styled.div<{ active: boolean }>`
|
|
56
|
+
padding: 0 32px 16px;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
border-left: 3px solid;
|
|
59
|
+
border-left-color: ${({ active }) => (active ? 'var(--color-primary-base)' : 'transparent')};
|
|
60
|
+
background-color: ${({ active }) => (active ? 'var(--bg-raised)' : 'transparent')};
|
|
61
|
+
border-top: 1px solid #cbccd1;
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
|
|
64
|
+
&:hover {
|
|
65
|
+
border-left-color: ${({ active }) => (active ? 'var(--color-primary-base)' : '#cbccd1')};
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CodeStep } from './CodeStep/CodeStep';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/theme-experimental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.2-pingfed.1",
|
|
4
4
|
"description": "Experimental UI components lib",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme-experimental",
|
|
@@ -8,11 +8,8 @@
|
|
|
8
8
|
],
|
|
9
9
|
"author": "team@redocly.com",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
|
-
"main": "lib/index.js",
|
|
12
|
-
"types": "lib/index.d.ts",
|
|
13
11
|
"exports": {
|
|
14
12
|
"./package.json": "./package.json",
|
|
15
|
-
".": "./lib/index.js",
|
|
16
13
|
"./src/": "./src/"
|
|
17
14
|
},
|
|
18
15
|
"peerDependencies": {
|
|
@@ -80,7 +77,7 @@
|
|
|
80
77
|
"@redocly/portal-types": "1.2.1"
|
|
81
78
|
},
|
|
82
79
|
"dependencies": {
|
|
83
|
-
"@redocly/theme": "^0.
|
|
80
|
+
"@redocly/theme": "^0.74.2-pingfed.1"
|
|
84
81
|
},
|
|
85
82
|
"scripts": {
|
|
86
83
|
"start": "npm-run-all --parallel storybook storybook:tokens:watch",
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CodeDemo = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
-
const CodeBlock_1 = require("@theme/components/CodeBlock/CodeBlock");
|
|
10
|
-
const CodeGuide_1 = require("../../mocks/CodeGuide");
|
|
11
|
-
function CodeDemo() {
|
|
12
|
-
const { highlightedLines, activeCodeTab, setCurrentCodeSample, setCodeNode, codeGuideFiles } = react_1.default.useContext(CodeGuide_1.CodeGuideContext);
|
|
13
|
-
(0, CodeGuide_1.useCodeGuideHighlightLines)(highlightedLines);
|
|
14
|
-
const codeBlockRef = react_1.default.useRef(null);
|
|
15
|
-
const setRef = (instance) => {
|
|
16
|
-
if (instance) {
|
|
17
|
-
codeBlockRef.current = instance;
|
|
18
|
-
setCodeNode(codeBlockRef);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const activeCodeExample = codeGuideFiles.find(({ name }) => activeCodeTab === name);
|
|
22
|
-
return (react_1.default.createElement(CodeDemoWrapper, null,
|
|
23
|
-
react_1.default.createElement(CodeBlock_1.CodeBlock, { source: activeCodeExample === null || activeCodeExample === void 0 ? void 0 : activeCodeExample.content, lang: activeCodeExample === null || activeCodeExample === void 0 ? void 0 : activeCodeExample.lang, withLineNumbers: true, header: {
|
|
24
|
-
controls: {
|
|
25
|
-
copy: {},
|
|
26
|
-
},
|
|
27
|
-
}, codeBlockRef: setRef, codeBlockMaxHeight: "75vh", hideCodeColors: true, tabs: {
|
|
28
|
-
files: codeGuideFiles,
|
|
29
|
-
activeTabName: activeCodeTab,
|
|
30
|
-
handleTabSwitch: setCurrentCodeSample,
|
|
31
|
-
} })));
|
|
32
|
-
}
|
|
33
|
-
exports.CodeDemo = CodeDemo;
|
|
34
|
-
const CodeDemoWrapper = styled_components_1.default.div `
|
|
35
|
-
background-color: var(--samples-panel-controls-background-color);
|
|
36
|
-
border-radius: 0 var(--global-border-radius);
|
|
37
|
-
padding: 32px 0;
|
|
38
|
-
min-height: 85vh;
|
|
39
|
-
`;
|
|
40
|
-
//# sourceMappingURL=CodeDemo.js.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
-
const CodeDemo_1 = require("../../layouts/CodeGuide/CodeDemo");
|
|
9
|
-
const MarkdownWrapper_1 = require("@theme/components/Markdown/MarkdownWrapper");
|
|
10
|
-
const CodeGuide_1 = require("../../mocks/CodeGuide");
|
|
11
|
-
function CodeGuide(props) {
|
|
12
|
-
var _a;
|
|
13
|
-
const { pageProps: { codeGuideFiles }, children, } = props;
|
|
14
|
-
const initialState = {
|
|
15
|
-
codeGuideFiles,
|
|
16
|
-
highlightedLines: '',
|
|
17
|
-
activeCodeTab: ((_a = codeGuideFiles === null || codeGuideFiles === void 0 ? void 0 : codeGuideFiles[0]) === null || _a === void 0 ? void 0 : _a.name) || '',
|
|
18
|
-
};
|
|
19
|
-
return (react_1.default.createElement(CodeGuide_1.CodeGuideProvider, { initialState: initialState },
|
|
20
|
-
react_1.default.createElement(Wrapper, { "data-component-name": "layouts/CodeGuide" },
|
|
21
|
-
react_1.default.createElement(MarkdownWrapper_1.MarkdownWrapper, null, children),
|
|
22
|
-
react_1.default.createElement("div", null,
|
|
23
|
-
react_1.default.createElement(StickyPosition, null,
|
|
24
|
-
react_1.default.createElement(CodeDemo_1.CodeDemo, null))))));
|
|
25
|
-
}
|
|
26
|
-
exports.default = CodeGuide;
|
|
27
|
-
const Wrapper = styled_components_1.default.div `
|
|
28
|
-
padding-left: 24px;
|
|
29
|
-
display: grid;
|
|
30
|
-
grid-template-columns: 40% 55%;
|
|
31
|
-
grid-column-gap: 45px;
|
|
32
|
-
height: 100%;
|
|
33
|
-
`;
|
|
34
|
-
const StickyPosition = styled_components_1.default.div `
|
|
35
|
-
position: sticky;
|
|
36
|
-
top: 50px;
|
|
37
|
-
left: 0;
|
|
38
|
-
`;
|
|
39
|
-
//# sourceMappingURL=CodeGuide.js.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare const CodeGuideContext: React.Context<{
|
|
3
|
-
highlightedLines: string;
|
|
4
|
-
activeCodeTab: string;
|
|
5
|
-
activeDocsSection: string;
|
|
6
|
-
codeBlock: undefined;
|
|
7
|
-
codeGuideFiles: CodeGuideFile[];
|
|
8
|
-
updateHighlightedLines: (_lines: string) => void;
|
|
9
|
-
setCurrentCodeSample: (_fileName: string) => void;
|
|
10
|
-
setActiveDocumentationSection: (_sectionId: string) => void;
|
|
11
|
-
setCodeNode: (_node: React.MutableRefObject<HTMLPreElement | null>) => void;
|
|
12
|
-
}>;
|
|
13
|
-
export type CodeGuideFile = {
|
|
14
|
-
name: string;
|
|
15
|
-
lang?: string;
|
|
16
|
-
content: string;
|
|
17
|
-
};
|
|
18
|
-
export interface CodeGuideProviderProps {
|
|
19
|
-
initialState: {
|
|
20
|
-
codeGuideFiles: CodeGuideFile[];
|
|
21
|
-
highlightedLines: string;
|
|
22
|
-
activeCodeTab: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export declare const CodeGuideProvider: ({ children, initialState, }: React.PropsWithChildren<CodeGuideProviderProps>) => React.JSX.Element;
|
|
26
|
-
export declare function useCodeGuideHighlightLines(highlightedLines: string): void;
|
|
27
|
-
type CodeStepHandlersProps = {
|
|
28
|
-
nodeRef: React.RefObject<HTMLDivElement>;
|
|
29
|
-
bindTo: string;
|
|
30
|
-
context: typeof CodeGuideContext.Provider.prototype.value;
|
|
31
|
-
};
|
|
32
|
-
export declare function useCodeStepHandlers({ nodeRef, bindTo, context }: CodeStepHandlersProps): {
|
|
33
|
-
onScroll: (codeBlock: HTMLPreElement | undefined) => void;
|
|
34
|
-
activateSection: (file: string, lines: string, codeBlock: HTMLPreElement | undefined) => void;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useCodeStepHandlers = exports.useCodeGuideHighlightLines = exports.CodeGuideProvider = exports.CodeGuideContext = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
exports.CodeGuideContext = react_1.default.createContext({
|
|
9
|
-
highlightedLines: '',
|
|
10
|
-
activeCodeTab: '',
|
|
11
|
-
activeDocsSection: '',
|
|
12
|
-
codeBlock: undefined,
|
|
13
|
-
codeGuideFiles: [],
|
|
14
|
-
updateHighlightedLines: (_lines) => { },
|
|
15
|
-
setCurrentCodeSample: (_fileName) => { },
|
|
16
|
-
setActiveDocumentationSection: (_sectionId) => { },
|
|
17
|
-
setCodeNode: (_node) => { },
|
|
18
|
-
});
|
|
19
|
-
const CodeGuideProvider = ({ children, initialState, }) => {
|
|
20
|
-
const contextValue = {
|
|
21
|
-
highlightedLines: initialState.highlightedLines,
|
|
22
|
-
activeCodeTab: initialState.activeCodeTab,
|
|
23
|
-
activeDocsSection: '',
|
|
24
|
-
codeBlock: undefined,
|
|
25
|
-
codeGuideFiles: [],
|
|
26
|
-
updateHighlightedLines: (_lines) => { },
|
|
27
|
-
setCurrentCodeSample: (_fileName) => { },
|
|
28
|
-
setActiveDocumentationSection: (_sectionId) => { },
|
|
29
|
-
setCodeNode: (_node) => { },
|
|
30
|
-
};
|
|
31
|
-
return react_1.default.createElement(exports.CodeGuideContext.Provider, { value: contextValue }, children);
|
|
32
|
-
};
|
|
33
|
-
exports.CodeGuideProvider = CodeGuideProvider;
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
-
function useCodeGuideHighlightLines(highlightedLines) { }
|
|
37
|
-
exports.useCodeGuideHighlightLines = useCodeGuideHighlightLines;
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
-
function useCodeStepHandlers({ nodeRef, bindTo, context }) {
|
|
41
|
-
const onScroll = (codeBlock) => {
|
|
42
|
-
if (nodeRef.current) {
|
|
43
|
-
const offsetTop = nodeRef.current.getBoundingClientRect().top;
|
|
44
|
-
if (offsetTop < 300 && offsetTop > 150) {
|
|
45
|
-
activateSection('', '', codeBlock);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
-
const activateSection = (file, lines, codeBlock) => {
|
|
52
|
-
codeBlock === null || codeBlock === void 0 ? void 0 : codeBlock.scrollTo(0, 0);
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
onScroll,
|
|
56
|
-
activateSection,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
exports.useCodeStepHandlers = useCodeStepHandlers;
|
|
60
|
-
//# sourceMappingURL=index.js.map
|