20 |
Flex Gap Explorer
21 |
22 | This is a React component to visualize Flex gap. We have connected it to{" "}
23 |
24 | Builder.io
25 | {" "}
26 | for visual editing. View the source of this component{" "}
27 |
28 | here
29 |
30 |
31 |
32 |
43 |
44 |
52 | {range.map((_, index) => (
53 |
61 | ))}
62 |
63 |
64 | );
65 | }
66 |
67 | // Add for visual editing in Builder.io
68 | // https://www.builder.io/blog/drag-drop-react
69 | Builder.registerComponent(FlexGapExplorer, {
70 | name: "Flex Gap Explorer",
71 | inputs: [
72 | {
73 | name: "flexGap",
74 | type: "number",
75 | defaultValue: defaultGapSize,
76 | helperText: 'Edit this to change the "gap" value',
77 | },
78 | {
79 | name: "boxes",
80 | type: "number",
81 | defaultValue: defaultBoxNumber,
82 | helperText: "Number of boxes to render",
83 | },
84 | {
85 | name: "boxColor",
86 | type: "color",
87 | defaultValue: defaultBoxColor,
88 | helperText: "Color of the boxes",
89 | },
90 | ],
91 | });
92 |
--------------------------------------------------------------------------------
/components/CodeBlock.tsx:
--------------------------------------------------------------------------------
1 | import Assignment from "@mui/icons-material/Assignment";
2 | import IconButton from "@mui/material/IconButton";
3 | import Tooltip from "@mui/material/Tooltip";
4 | import { useState } from "react";
5 | import javascript from "react-syntax-highlighter/dist/cjs/languages/hljs/javascript";
6 | import html from "react-syntax-highlighter/dist/cjs/languages/hljs/xml";
7 | import SyntaxHighlighter from "react-syntax-highlighter/dist/cjs/light-async";
8 | import oneDark from "react-syntax-highlighter/dist/cjs/styles/hljs/atom-one-dark";
9 | import githubGist from "react-syntax-highlighter/dist/cjs/styles/hljs/github-gist";
10 | import { copyToClipboard } from "../functions/copy-to-clipboard";
11 |
12 | SyntaxHighlighter.registerLanguage("html", html);
13 | SyntaxHighlighter.registerLanguage("xml", html);
14 | SyntaxHighlighter.registerLanguage("javascript", javascript);
15 | SyntaxHighlighter.registerLanguage("js", javascript);
16 | SyntaxHighlighter.registerLanguage("jsx", javascript);
17 |
18 | // Adapted from https://github.com/dpeek/highlightjs-graphql/blob/master/graphql.js#L10
19 | SyntaxHighlighter.registerLanguage("graphql", (hljs: any) => ({
20 | aliases: ["gql"],
21 | keywords: {
22 | keyword:
23 | "query mutation subscription|10 type interface union scalar fragment|10 enum on ...",
24 | literal: "true false null",
25 | },
26 | contains: [
27 | hljs.HASH_COMMENT_MODE,
28 | hljs.QUOTE_STRING_MODE,
29 | hljs.NUMBER_MODE,
30 | {
31 | className: "type",
32 | begin: "[^\\w][A-Z][a-z]",
33 | end: "\\W",
34 | excludeEnd: true,
35 | },
36 | {
37 | className: "literal",
38 | begin: "[^\\w][A-Z][A-Z]",
39 | end: "\\W",
40 | excludeEnd: true,
41 | },
42 | { className: "variable", begin: "\\$", end: "\\W", excludeEnd: true },
43 | {
44 | className: "keyword",
45 | begin: "[.]{2}",
46 | end: "\\.",
47 | },
48 | {
49 | className: "meta",
50 | begin: "@",
51 | end: "\\W",
52 | excludeEnd: true,
53 | },
54 | ],
55 | illegal: /([;<']|BEGIN)/,
56 | }));
57 |
58 | const defaultCopyButtonTooltipText = "Copy code to clipboard";
59 |
60 | export function CodeBlockComponent(
61 | { language, code, dark, fontSize }: any /* TODO: types */
62 | ) {
63 | const [copyButtonTooltipText, setCopyButtonTooltipText] = useState(
64 | defaultCopyButtonTooltipText
65 | );
66 |
67 | return (
68 |