File tree 3 files changed +47
-26
lines changed
src/Components/Inputs/Switch 3 files changed +47
-26
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @programmer_network/yail" ,
3
- "version" : " 1.0.192 " ,
3
+ "version" : " 1.0.193 " ,
4
4
"description" : " Programmer Network's official UI library for React" ,
5
5
"author" : " Aleksandar Grbic - (https://programmer.network)" ,
6
6
"publishConfig" : {
Original file line number Diff line number Diff line change @@ -6,16 +6,26 @@ export default {
6
6
title : "Input / Switch"
7
7
} ;
8
8
9
- export const Default = ( ) => {
10
- const [ isChecked , setIsChecked ] = useState ( false ) ;
9
+ export const IsChecked = ( ) => {
10
+ return (
11
+ < Switch
12
+ name = 'isEnabled'
13
+ label = 'Lorem ipsum'
14
+ isChecked = { true }
15
+ onChange = { ( { isEnabled } ) => console . log ( isEnabled ) }
16
+ />
17
+ ) ;
18
+ } ;
11
19
12
- console . log ( "🚀 ─── Default ─── isChecked:" , isChecked ) ;
20
+ export const IsNotChecked = ( ) => {
21
+ const [ isChecked , setIsChecked ] = useState ( false ) ;
13
22
14
23
return (
15
24
< Switch
25
+ name = 'isEnabled'
26
+ label = 'Lorem ipsum'
16
27
isChecked = { isChecked }
17
28
onChange = { ( { isEnabled } ) => setIsChecked ( isEnabled ) }
18
- name = 'isEnabled'
19
29
/>
20
30
) ;
21
31
} ;
Original file line number Diff line number Diff line change @@ -7,33 +7,44 @@ const Switch: React.FC<ISwitchProps> = ({
7
7
name,
8
8
isChecked,
9
9
onChange,
10
- label = "Toggle me" ,
10
+ label,
11
11
className
12
12
} ) => {
13
13
const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
14
14
onChange ( { [ name ] : event . target . checked } ) ;
15
15
} ;
16
-
17
16
return (
18
- < label
19
- className = { classNames (
20
- "yl-inline-flex yl-cursor-pointer yl-items-center" ,
21
- className
22
- ) }
23
- >
24
- < input
25
- type = 'checkbox'
26
- checked = { isChecked }
27
- onChange = { handleChange }
28
- className = 'peer sr-only yl-hidden'
29
- />
30
- < div className = "peer yl-relative yl-h-6 yl-w-12 yl-rounded-full yl-bg-primary-text-color after:yl-absolute after:yl-start-[2px] after:yl-top-[2px] after:yl-h-5 after:yl-w-5 after:yl-rounded-full after:yl-bg-primary-background-color after:yl-transition-all after:yl-content-[''] peer-checked:yl-bg-primary peer-checked:after:yl-translate-x-full rtl:peer-checked:after:-yl-translate-x-full" />
31
- { label && (
32
- < span className = 'yl-ms-3 yl-text-sm yl-font-medium yl-text-primary-text-color' >
33
- { label }
34
- </ span >
35
- ) }
36
- </ label >
17
+ < >
18
+ < label className = 'yl-flex yl-cursor-pointer yl-select-none yl-items-center' >
19
+ < div className = { classNames ( "yl-relative" , className ) } >
20
+ < input
21
+ type = 'checkbox'
22
+ checked = { isChecked }
23
+ onChange = { handleChange }
24
+ className = 'yl-sr-only'
25
+ />
26
+ < div
27
+ className = { classNames ( "yl-block yl-h-8 yl-w-14 yl-rounded-full" , {
28
+ "yl-bg-primary" : isChecked ,
29
+ "yl-bg-primary-text-color" : ! isChecked
30
+ } ) }
31
+ > </ div >
32
+ < div
33
+ className = { classNames (
34
+ "yl-dot yl-absolute yl-left-1 yl-top-1 yl-h-6 yl-w-6 yl-rounded-full yl-transition yl-bg-primary-background-color" ,
35
+ {
36
+ "yl-translate-x-6" : isChecked
37
+ }
38
+ ) }
39
+ > </ div >
40
+ </ div >
41
+ { label && (
42
+ < span className = 'yl-ms-3 yl-text-sm yl-font-medium yl-text-primary-text-color' >
43
+ { label }
44
+ </ span >
45
+ ) }
46
+ </ label >
47
+ </ >
37
48
) ;
38
49
} ;
39
50
You can’t perform that action at this time.
0 commit comments