|
| 1 | +import React, { useState } from "react"; |
| 2 | +import { CodeBlock } from "../button/code-block"; |
| 3 | +import { Switch, FormControlLabel, SistentThemeProvider } from "@sistent/sistent"; |
| 4 | +import { SistentLayout } from "../../sistent-layout"; |
| 5 | +import TabButton from "../../../../../reusecore/Button"; |
| 6 | +import { navigate } from "gatsby"; |
| 7 | +import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; |
| 8 | +import { useLocation } from "@reach/router"; |
| 9 | + |
| 10 | +const codes = [ |
| 11 | + ` <SistentThemeProvider> |
| 12 | + <Switch/> |
| 13 | + </SistentThemeProvider>`, |
| 14 | + ` <SistentThemeProvider> |
| 15 | + <Switch checked={false} disabled /> |
| 16 | + </SistentThemeProvider>`, |
| 17 | + ` <SistentThemeProvider> |
| 18 | + <FormControlLabel |
| 19 | + control={ |
| 20 | + <Switch |
| 21 | + checked={checked} |
| 22 | + onChange={handleChange} |
| 23 | + name="demoSwitch" |
| 24 | + color="primary" |
| 25 | + /> |
| 26 | + } |
| 27 | + label="Enable Notifications" |
| 28 | + /> |
| 29 | + </SistentThemeProvider>`, |
| 30 | + ` <SistentThemeProvider> |
| 31 | + <Switch |
| 32 | + size="small" |
| 33 | + checked={checked} |
| 34 | + onChange={handleChange} |
| 35 | + inputProps={{ 'aria-label': 'toggle something' }} |
| 36 | + /> |
| 37 | + </SistentThemeProvider>`, |
| 38 | +]; |
| 39 | + |
| 40 | +const SwitchCode = () => { |
| 41 | + const [checked, setChecked] = useState(true); |
| 42 | + const handleChange = (event) => setChecked(event.target.checked); |
| 43 | + const location = useLocation(); |
| 44 | + const { isDark } = useStyledDarkMode(); |
| 45 | + return ( |
| 46 | + <SistentLayout title="Switch"> |
| 47 | + <div className="content"> |
| 48 | + <a id="Switch"> |
| 49 | + <h2>Switch</h2> |
| 50 | + </a> |
| 51 | + <p> |
| 52 | + The Switch component allows users to toggle a setting between two states—on or off. |
| 53 | + </p> |
| 54 | + <div className="filterBtns"> |
| 55 | + <TabButton |
| 56 | + className={location.pathname === "/projects/sistent/components/switch" ? "active" : ""} |
| 57 | + onClick={() => navigate("/projects/sistent/components/switch")} |
| 58 | + title="Overview" |
| 59 | + /> |
| 60 | + <TabButton |
| 61 | + className={location.pathname === "/projects/sistent/components/switch/guidance" ? "active" : ""} |
| 62 | + onClick={() => navigate("/projects/sistent/components/switch/guidance")} |
| 63 | + title="Guidance" |
| 64 | + /> |
| 65 | + <TabButton |
| 66 | + className={location.pathname === "/projects/sistent/components/switch/code" ? "active" : ""} |
| 67 | + onClick={() => navigate("/projects/sistent/components/switch/code")} |
| 68 | + title="Code" |
| 69 | + /> |
| 70 | + </div> |
| 71 | + <div className="main-content"> |
| 72 | + <a id="Basic Switch"> |
| 73 | + <h2>Basic Switch</h2> |
| 74 | + </a> |
| 75 | + <p> |
| 76 | + This is the default switch style used to represent changes between two states. |
| 77 | + </p> |
| 78 | + <div className="showcase"> |
| 79 | + <div className="items"> |
| 80 | + <SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 81 | + <Switch checked={checked} /> |
| 82 | + </SistentThemeProvider> |
| 83 | + </div> |
| 84 | + <CodeBlock name="basic-switch" code={codes[0]} /> |
| 85 | + </div> |
| 86 | + |
| 87 | + <a id="Disabled Switch"> |
| 88 | + <h2>Disabled Switch</h2> |
| 89 | + </a> |
| 90 | + <p> |
| 91 | + Disabled switches show the state but are not interactive. |
| 92 | + </p> |
| 93 | + <div className="showcase"> |
| 94 | + <div className="items"> |
| 95 | + <SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 96 | + <Switch checked={false} disabled /> |
| 97 | + </SistentThemeProvider> |
| 98 | + </div> |
| 99 | + <CodeBlock name="disabled-switch" code={codes[1]} /> |
| 100 | + </div> |
| 101 | + |
| 102 | + <a id="Labeled Switch"> |
| 103 | + <h2>Labeled Switch</h2> |
| 104 | + </a> |
| 105 | + <p> |
| 106 | + Labels describe the action being toggled and improve accessibility. |
| 107 | + </p> |
| 108 | + <div className="showcase"> |
| 109 | + <div className="items"> |
| 110 | + <SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 111 | + <FormControlLabel |
| 112 | + control={ |
| 113 | + <Switch |
| 114 | + checked={checked} |
| 115 | + onChange={handleChange} |
| 116 | + name="demoSwitch" |
| 117 | + color="primary" |
| 118 | + /> |
| 119 | + } |
| 120 | + label="Enable Notifications" |
| 121 | + /> |
| 122 | + </SistentThemeProvider> |
| 123 | + </div> |
| 124 | + <CodeBlock name="labeled-switch" code={codes[2]} /> |
| 125 | + </div> |
| 126 | + |
| 127 | + <a id="Small Switch"> |
| 128 | + <h2>Small Switch</h2> |
| 129 | + </a> |
| 130 | + <p> |
| 131 | + Use the <code>size="small"</code> prop for a more compact version. |
| 132 | + </p> |
| 133 | + <div className="showcase"> |
| 134 | + <div className="items"> |
| 135 | + <SistentThemeProvider initialMode={isDark ? "dark" : "light"}> |
| 136 | + <Switch |
| 137 | + size="small" |
| 138 | + checked={checked} |
| 139 | + onChange={handleChange} |
| 140 | + inputProps={{ "aria-label": "toggle something" }} |
| 141 | + /> |
| 142 | + </SistentThemeProvider> |
| 143 | + </div> |
| 144 | + <CodeBlock name="small-switch" code={codes[3]} /> |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + </SistentLayout> |
| 149 | + ); |
| 150 | +}; |
| 151 | + |
| 152 | +export default SwitchCode; |
0 commit comments