forked from philmtd/css-fx-layout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.js
More file actions
71 lines (67 loc) · 2.1 KB
/
examples.js
File metadata and controls
71 lines (67 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from "react";
import CodeBlock from '@theme/CodeBlock';
import example1 from "./example1";
import example2 from "./example2";
import example3 from "./example3";
import example4 from "./example4";
import example5 from "./example5";
import example6 from "./example6";
import example7 from "./example7";
import example8 from "./example8";
import example9 from "./example9";
import example10 from "./example10";
import BrowserOnly from "@docusaurus/BrowserOnly";
const examples = [
example1,
example2,
example3,
example4,
example5,
example6,
example7,
example8,
example9,
example10
]
export function Examples() {
return (
<BrowserOnly>{
() => {
let selectorFromLocalStorage = localStorage.getItem("css-fx-layout-preferred-selector") || "attributes";
const [currentSelector, updateSelector] = React.useState(selectorFromLocalStorage);
React.useEffect(() => {
localStorage.setItem("css-fx-layout-preferred-selector", currentSelector);
}, [currentSelector]);
return (
<div className="examples">
<div className="type-buttons" data-layout="row" data-layout-gap="4px">
<button className={"button button--" + (currentSelector === "attributes" ? "primary" : "secondary") } onClick={() => updateSelector("attributes")}>Attributes</button>
<button className={"button button--" + (currentSelector === "classes" ? "primary" : "secondary") } onClick={() => updateSelector("classes")}>Classes</button>
</div>
<div>
{ examples.map(ex => {
return (
<div key={ex.title} className="example-container">
<h2>{ ex.title }</h2>
<p>{ ex.description }</p>
<CodeBlock language="html">
{ currentSelector === "attributes" ? ex.attributes : ex.classes }
</CodeBlock>
<div className="example">
<GetCode code={ currentSelector === "attributes" ? ex.attributes : ex.classes }/>
</div>
</div>
);
})}
</div>
</div>
)
}
}</BrowserOnly>
)
}
function GetCode(opts) {
return (
<div dangerouslySetInnerHTML={{__html: opts["code"]}}></div>
)
}