File tree 5 files changed +75
-6
lines changed
5 files changed +75
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"svelte.plugin.svelte.compilerWarnings" : {
3
3
"a11y-click-events-have-key-events" : " ignore" ,
4
- "a11y-no-static-element-interactions" : " ignore"
4
+ "a11y-no-static-element-interactions" : " ignore" ,
5
+ "a11y-no-noninteractive-element-interactions" : " ignore"
5
6
}
6
7
}
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import type { SwitchProps } from ' ./switch'
3
+ import ' ./switch.scss'
4
+
5
+ export let label: SwitchProps [' label' ] = ' '
6
+ export let toggled: SwitchProps [' toggled' ] = false
7
+ export let offColor: SwitchProps [' offColor' ] = ' '
8
+ export let onColor: SwitchProps [' onColor' ] = ' '
9
+ export let reverse: SwitchProps [' reverse' ] = false
10
+ export let small: SwitchProps [' small' ] = false
11
+ export let square: SwitchProps [' square' ] = false
12
+ export let disabled: SwitchProps [' disabled' ] = false
13
+ export let className: SwitchProps [' className' ] = ' '
14
+ export let onClick: () => any = () => {}
15
+
16
+ const classes = [
17
+ ' w-switch' ,
18
+ reverse && ' reverse' ,
19
+ small && ' small' ,
20
+ square && ' square' ,
21
+ disabled && ' disabled' ,
22
+ className
23
+ ].filter (Boolean ).join (' ' )
24
+
25
+ const styles = [
26
+ offColor && ` --w-switch-off-color: ${offColor }; ` ,
27
+ onColor && ` --w-switch-on-color: ${onColor }; `
28
+ ].filter (Boolean ).join (' ' )
29
+ </script >
30
+
31
+ <label class ={classes } style ={styles || null } on:click ={onClick }>
32
+ <input type ="checkbox" checked ={toggled } disabled ={disabled } />
33
+ <span class =" toggle" ></span >
34
+ {#if label }
35
+ <span class ="label" >{label }</span >
36
+ {/if }
37
+ </label >
Original file line number Diff line number Diff line change @@ -2,14 +2,44 @@ import React from 'react'
2
2
import type { SwitchProps } from './switch'
3
3
import './switch.scss'
4
4
5
+ type ReactSwitchProps = {
6
+ onClick : ( ) => any
7
+ } & SwitchProps
8
+
5
9
const Switch = ( {
6
-
7
- } : SwitchProps ) => {
10
+ label,
11
+ toggled,
12
+ offColor,
13
+ onColor,
14
+ reverse,
15
+ small,
16
+ square,
17
+ disabled,
18
+ className,
19
+ onClick
20
+ } : ReactSwitchProps ) => {
21
+ const classes = [
22
+ 'w-switch' ,
23
+ reverse && 'reverse' ,
24
+ small && 'small' ,
25
+ square && 'square' ,
26
+ disabled && 'disabled' ,
27
+ className
28
+ ] . filter ( Boolean ) . join ( ' ' )
8
29
30
+ const styles = {
31
+ ...( offColor && { '--w-switch-off-color' : offColor } ) ,
32
+ ...( onColor && { '--w-switch-on-color' : onColor } )
33
+ } as React . CSSProperties
9
34
10
35
return (
11
- < div > switch</ div >
36
+ < label className = { classes } style = { styles || null } onClick = { onClick } >
37
+ < input type = "checkbox" checked = { toggled } disabled = { disabled } />
38
+ < span className = "toggle" > </ span >
39
+ { label && < span className = "label" > { label } </ span > }
40
+ </ label >
12
41
)
42
+
13
43
}
14
44
15
45
export default Switch
Original file line number Diff line number Diff line change @@ -30,11 +30,11 @@ const sections = [
30
30
</ComponentWrapper >
31
31
32
32
<ComponentWrapper type =" Svelte" >
33
- <SvelteSwitch color =" #ee5253" />
33
+ <SvelteSwitch offColor =" #ee5253" />
34
34
</ComponentWrapper >
35
35
36
36
<ComponentWrapper type =" React" >
37
- <ReactSwitch color =" #48dbfb" />
37
+ <ReactSwitch offColor =" #48dbfb" />
38
38
</ComponentWrapper >
39
39
</div >
40
40
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export default {
8
8
const ignoreWarnings = [
9
9
'a11y-click-events-have-key-events' ,
10
10
'a11y-no-static-element-interactions' ,
11
+ 'a11y-no-noninteractive-element-interactions' ,
11
12
'.accordion-title'
12
13
]
13
14
You can’t perform that action at this time.
0 commit comments