@redocly/theme-experimental 0.2.0-next.1 → 0.2.0-next.2
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/components.tsx
CHANGED
package/markdoc/schema.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { Schema } from '@markdoc/markdoc';
|
|
2
2
|
|
|
3
|
-
export const codeStep: Schema = {
|
|
4
|
-
attributes: {
|
|
5
|
-
bindTo: { type: String, required: false },
|
|
6
|
-
},
|
|
7
|
-
render: 'CodeStep',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
3
|
export const card: Schema = {
|
|
11
4
|
attributes: {
|
|
12
5
|
title: { type: String, required: false },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/theme-experimental",
|
|
3
|
-
"version": "0.2.0-next.
|
|
3
|
+
"version": "0.2.0-next.2",
|
|
4
4
|
"description": "Experimental UI components lib",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme-experimental",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"exports": {
|
|
12
12
|
"./package.json": "./package.json",
|
|
13
|
-
"./src/": "./src/",
|
|
14
13
|
"./plugin.js": "./plugin.js"
|
|
15
14
|
},
|
|
16
15
|
"peerDependencies": {
|
|
@@ -60,8 +59,8 @@
|
|
|
60
59
|
"webpack": "5.94.0"
|
|
61
60
|
},
|
|
62
61
|
"dependencies": {
|
|
63
|
-
"@redocly/
|
|
64
|
-
"@redocly/
|
|
62
|
+
"@redocly/config": "0.21.0",
|
|
63
|
+
"@redocly/theme": "0.51.0-next.1"
|
|
65
64
|
},
|
|
66
65
|
"scripts": {
|
|
67
66
|
"watch": "tsc -p tsconfig.build.json && (concurrently \"tsc -w -p tsconfig.build.json\" \"tsc-alias -w -p tsconfig.build.json\")",
|
|
@@ -1,67 +0,0 @@
|
|
|
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-color-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
|
-
`;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
-
import { CodeBlock } from '@redocly/theme/components/CodeBlock/CodeBlock';
|
|
5
|
-
import { CodeGuideContext, useCodeGuideHighlightLines } from '@portal/CodeGuide';
|
|
6
|
-
|
|
7
|
-
export function CodeDemo() {
|
|
8
|
-
const { highlightedLines, activeCodeTab, setCurrentCodeSample, setCodeNode, codeGuideFiles } =
|
|
9
|
-
React.useContext(CodeGuideContext);
|
|
10
|
-
|
|
11
|
-
useCodeGuideHighlightLines(highlightedLines);
|
|
12
|
-
|
|
13
|
-
const codeBlockRef = React.useRef<HTMLPreElement | null>(null);
|
|
14
|
-
|
|
15
|
-
const setRef = (instance?: HTMLPreElement | null) => {
|
|
16
|
-
if (instance) {
|
|
17
|
-
codeBlockRef.current = instance;
|
|
18
|
-
setCodeNode(codeBlockRef);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const activeCodeExample = codeGuideFiles.find(({ name }) => activeCodeTab === name);
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<CodeDemoWrapper>
|
|
26
|
-
<CodeBlock
|
|
27
|
-
source={activeCodeExample?.content}
|
|
28
|
-
lang={activeCodeExample?.lang}
|
|
29
|
-
withLineNumbers
|
|
30
|
-
header={{
|
|
31
|
-
controls: {
|
|
32
|
-
copy: {},
|
|
33
|
-
},
|
|
34
|
-
}}
|
|
35
|
-
codeBlockRef={setRef}
|
|
36
|
-
codeBlockMaxHeight="75vh"
|
|
37
|
-
hideCodeColors={true}
|
|
38
|
-
tabs={{
|
|
39
|
-
files: codeGuideFiles,
|
|
40
|
-
activeTabName: activeCodeTab,
|
|
41
|
-
handleTabSwitch: setCurrentCodeSample,
|
|
42
|
-
}}
|
|
43
|
-
/>
|
|
44
|
-
</CodeDemoWrapper>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const CodeDemoWrapper = styled.div`
|
|
49
|
-
background-color: var(--samples-panel-controls-background-color);
|
|
50
|
-
border-radius: 0 var(--global-border-radius);
|
|
51
|
-
padding: 32px 0;
|
|
52
|
-
min-height: 85vh;
|
|
53
|
-
`;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
-
import { Markdown } from '@redocly/theme/components/Markdown/Markdown';
|
|
5
|
-
import { CodeGuideProvider } from '@portal/CodeGuide';
|
|
6
|
-
|
|
7
|
-
import { CodeDemo } from './CodeDemo';
|
|
8
|
-
|
|
9
|
-
export default function CodeGuide(props: React.PropsWithChildren<any>) {
|
|
10
|
-
const {
|
|
11
|
-
pageProps: { codeGuideFiles },
|
|
12
|
-
children,
|
|
13
|
-
} = props;
|
|
14
|
-
|
|
15
|
-
const initialState = {
|
|
16
|
-
codeGuideFiles,
|
|
17
|
-
highlightedLines: '',
|
|
18
|
-
activeCodeTab: codeGuideFiles?.[0]?.name || '',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<CodeGuideProvider initialState={initialState}>
|
|
23
|
-
<Wrapper data-component-name="layouts/CodeGuide">
|
|
24
|
-
<Markdown>{children}</Markdown>
|
|
25
|
-
<div>
|
|
26
|
-
<StickyPosition>
|
|
27
|
-
<CodeDemo />
|
|
28
|
-
</StickyPosition>
|
|
29
|
-
</div>
|
|
30
|
-
</Wrapper>
|
|
31
|
-
</CodeGuideProvider>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const Wrapper = styled.div`
|
|
36
|
-
padding-left: 24px;
|
|
37
|
-
display: grid;
|
|
38
|
-
grid-template-columns: 40% 55%;
|
|
39
|
-
grid-column-gap: 45px;
|
|
40
|
-
height: 100%;
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
const StickyPosition = styled.div`
|
|
44
|
-
position: sticky;
|
|
45
|
-
top: 50px;
|
|
46
|
-
left: 0;
|
|
47
|
-
`;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export const CodeGuideContext = React.createContext({
|
|
4
|
-
highlightedLines: '',
|
|
5
|
-
activeCodeTab: '',
|
|
6
|
-
activeDocsSection: '',
|
|
7
|
-
codeBlock: undefined,
|
|
8
|
-
codeGuideFiles: [] as CodeGuideFile[],
|
|
9
|
-
updateHighlightedLines: (_lines: string) => {},
|
|
10
|
-
setCurrentCodeSample: (_fileName: string) => {},
|
|
11
|
-
setActiveDocumentationSection: (_sectionId: string) => {},
|
|
12
|
-
setCodeNode: (_node: React.MutableRefObject<HTMLPreElement | null>) => {},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export type CodeGuideFile = { name: string; lang?: string; content: string };
|
|
16
|
-
|
|
17
|
-
export interface CodeGuideProviderProps {
|
|
18
|
-
initialState: {
|
|
19
|
-
codeGuideFiles: CodeGuideFile[];
|
|
20
|
-
highlightedLines: string;
|
|
21
|
-
activeCodeTab: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const CodeGuideProvider = ({
|
|
26
|
-
children,
|
|
27
|
-
initialState,
|
|
28
|
-
}: React.PropsWithChildren<CodeGuideProviderProps>) => {
|
|
29
|
-
const contextValue = {
|
|
30
|
-
highlightedLines: initialState.highlightedLines,
|
|
31
|
-
activeCodeTab: initialState.activeCodeTab,
|
|
32
|
-
activeDocsSection: '',
|
|
33
|
-
codeBlock: undefined,
|
|
34
|
-
codeGuideFiles: [] as CodeGuideFile[],
|
|
35
|
-
updateHighlightedLines: (_lines: string) => {},
|
|
36
|
-
setCurrentCodeSample: (_fileName: string) => {},
|
|
37
|
-
setActiveDocumentationSection: (_sectionId: string) => {},
|
|
38
|
-
setCodeNode: (_node: React.MutableRefObject<HTMLPreElement | null>) => {},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return <CodeGuideContext.Provider value={contextValue}>{children}</CodeGuideContext.Provider>;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
|
|
46
|
-
export function useCodeGuideHighlightLines(highlightedLines: string) {}
|
|
47
|
-
|
|
48
|
-
type CodeStepHandlersProps = {
|
|
49
|
-
nodeRef: React.RefObject<HTMLDivElement>;
|
|
50
|
-
bindTo: string;
|
|
51
|
-
context: typeof CodeGuideContext.Provider.prototype.value;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
|
|
56
|
-
export function useCodeStepHandlers({ nodeRef, bindTo, context }: CodeStepHandlersProps): {
|
|
57
|
-
onScroll: (codeBlock: HTMLPreElement | undefined) => void;
|
|
58
|
-
activateSection: (file: string, lines: string, codeBlock: HTMLPreElement | undefined) => void;
|
|
59
|
-
} {
|
|
60
|
-
const onScroll = (codeBlock: HTMLPreElement | undefined) => {
|
|
61
|
-
if (nodeRef.current) {
|
|
62
|
-
const offsetTop = nodeRef.current.getBoundingClientRect().top;
|
|
63
|
-
if (offsetTop < 300 && offsetTop > 150) {
|
|
64
|
-
activateSection('', '', codeBlock);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
|
|
71
|
-
const activateSection = (file: string, lines: string, codeBlock: HTMLPreElement | undefined) => {
|
|
72
|
-
codeBlock?.scrollTo(0, 0);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
onScroll,
|
|
77
|
-
activateSection,
|
|
78
|
-
};
|
|
79
|
-
}
|