Skip to content

Commit 2ff212e

Browse files
committed
Added: ToggleSwitch
1 parent 0e194ed commit 2ff212e

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * as button from './button/index.ts'
2+
export * as toggleSwitch from './toggle_switch/index.ts'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.ui.toggle-switch {
2+
display: flex;
3+
align-items: center;
4+
padding: 0 12px;
5+
width: 64px;
6+
height: 32px;
7+
appearance: none;
8+
border: 1px solid;
9+
border-radius: 6px;
10+
font-size: 14px;
11+
font-weight: 500;
12+
cursor: pointer;
13+
user-select: none;
14+
15+
&[class$="--active"] {
16+
background-color: #f6f8fa;
17+
box-shadow: 0px 1px 0px 0px #1f23280a;
18+
border-color: #d1d9e0;
19+
color: #25292e;
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {ToggleSwitch} from './toggle_switch.tsx'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { type JSXElement, createSignal } from '@solid-js'
2+
3+
import './index.css'
4+
5+
6+
export function ToggleSwitch() : JSXElement {
7+
8+
const [state, setState] = createSignal(false);
9+
10+
const toggle = () => {
11+
setState((v) => !v);
12+
console.log('State is now:', state());
13+
}
14+
15+
return (
16+
<button
17+
type='button'
18+
class={`ui toggle-switch`}
19+
classList={{
20+
'toggle-switch--active': state()
21+
}}
22+
data-checked={state()}
23+
onClick={toggle}
24+
>
25+
{state() ? 'ON' : 'OFF'}
26+
</button>
27+
)
28+
}

src/render/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { render } from '@solid-js/web';
22
import { HashRouter, Route } from '@solid-js/router'
3-
import { button } from '../components/index.ts';
3+
import { button, toggleSwitch } from '../components/index.ts';
44
import './index.css'
55

66

77
render(
88
() => <HashRouter>
99
<Route path='/button' component={() => <button.Button>Hello</button.Button>}/>
10+
<Route path='/toggle-switch' component={() => <toggleSwitch.ToggleSwitch />}/>
1011
</HashRouter>,
1112
globalThis.document.body
1213
);

0 commit comments

Comments
 (0)