Skip to content

Commit 9812caa

Browse files
nitzanyizadids1221
andauthored
Docs - Component example code snippet (#3555)
* Added show code and code snippet to component example Co-authored-by: Adi Mordo <adids1221@gmail.com> --------- Co-authored-by: Adi Mordo <adids1221@gmail.com>
1 parent 90e75c9 commit 9812caa

File tree

14 files changed

+186
-20
lines changed

14 files changed

+186
-20
lines changed

docuilib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"clsx": "^1.1.1",
3131
"docusaurus-plugin-sass": "^0.2.1",
3232
"file-loader": "^6.2.0",
33+
"prettier": "2.8.8",
3334
"prism-react-renderer": "^2.1.0",
3435
"react-html-parser": "^2.0.2",
3536
"react-native-web": "^0.19.12",

docuilib/src/assets/icons/code.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
const CodeIcon = (props: React.ComponentProps<'svg'>) => {
4+
return (
5+
<svg {...props} viewBox="0 0 18 18" fill="currentColor" width="18" height="18">
6+
<path d="M10,6.00254473 L11,6.00254473 L8,13 L7,13 L10,6.00254473 Z M6,12 L5.74819324,12 L1.99934428,9.78978657 L2.00158404,9.20893357 L5.74819324,7 L6.00018511,7 L6.00018511,8 L3.50778222,9.5 L6,11 L6,12 Z M11.9995294,12 L11.9995294,11 L14.4917472,9.5 L11.9993443,8 L11.9993443,7 L12.2513362,7 L15.9979454,9.20893357 L16.0001851,9.78978657 L12.2513362,12 L11.9995294,12 Z"/>
7+
</svg>
8+
);
9+
};
10+
11+
export default CodeIcon;

docuilib/src/assets/icons/copy.png

-286 Bytes
Binary file not shown.
-448 Bytes
Binary file not shown.
-554 Bytes
Binary file not shown.
-871 Bytes
Binary file not shown.
-1.22 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.codeBlock {
2+
margin: 0;
3+
text-align: 'left';
4+
height: 100%;
5+
}
6+
7+
.codeBlockContainer {
8+
height: 100%;
9+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, {useMemo, ComponentProps} from 'react';
2+
import {default as ThemeCodeBlock, Props} from '@theme/CodeBlock';
3+
import styles from './CodeBlock.module.scss';
4+
import useFormattedCode from '../hooks/useFormattedCode';
5+
6+
type CodeBlockProps = {
7+
snippet: string;
8+
printWidth?: number;
9+
fontSize?: number;
10+
} & Omit<Props, 'children'>;
11+
12+
const CodeBlock: React.FC<CodeBlockProps> = ({
13+
snippet,
14+
language,
15+
printWidth = 35,
16+
fontSize = 14,
17+
showLineNumbers,
18+
...others
19+
}) => {
20+
const {code} = useFormattedCode(snippet, {printWidth});
21+
22+
const containerStyle = useMemo<ComponentProps<'div'>['style']>(() => {
23+
return {
24+
fontSize,
25+
maxWidth: printWidth * fontSize
26+
};
27+
}, [fontSize, printWidth]);
28+
29+
return (
30+
<div style={containerStyle} className={styles.codeBlockContainer}>
31+
<ThemeCodeBlock
32+
className={styles.codeBlock}
33+
language={language ?? 'jsx'}
34+
showLineNumbers={showLineNumbers ?? true}
35+
{...others}
36+
>
37+
{code}
38+
</ThemeCodeBlock>
39+
</div>
40+
);
41+
};
42+
43+
export default CodeBlock;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.showCodeButton {
2+
position: absolute;
3+
border: 0;
4+
background: none;
5+
color: rgb(56, 153, 236);
6+
cursor: pointer;
7+
display: flex;
8+
align-items: center;
9+
right: 0px;
10+
top: 0px;
11+
}
12+
13+
.componentExample {
14+
display: flex;
15+
justify-content: space-between;
16+
}
17+
18+
.componentItemContainer {
19+
position: relative;
20+
height: 100%;
21+
}
22+
23+
.componentSpotlightStyle {
24+
display: flex;
25+
justify-content: center;
26+
align-items: center;
27+
}
28+
29+
.image {
30+
display: flex;
31+
justify-content: center;
32+
align-items: center;
33+
}

0 commit comments

Comments
 (0)