4
4
[ ![ npm] ( https://img.shields.io/npm/dt/nativescript-checkbox.svg?label=npm%20downloads )] ( https://www.npmjs.com/package/nativescript-checkbox )
5
5
6
6
# NativeScript CheckBox :white_check_mark :
7
+
7
8
A NativeScript plugin for the native checkbox widget.
8
9
9
- #### Platform controls used:
10
- Android | iOS
11
- ---------- | -------
12
- [ Android CheckBox] ( https://developer.android.com/reference/android/widget/CheckBox.html ) | [ BEMCheckBox] ( http://cocoapods.org/pods/BEMCheckBox )
10
+ #### Platform controls used:
13
11
12
+ | Android | iOS |
13
+ | ---------------------------------------------------------------------------------------- | ---------------------------------------------------- |
14
+ | [ Android CheckBox] ( https://developer.android.com/reference/android/widget/CheckBox.html ) | [ BEMCheckBox] ( http://cocoapods.org/pods/BEMCheckBox ) |
14
15
15
16
## Sample Usage
16
17
17
- Android Sample | iOS Sample
18
- -------- | ---------
19
- ![ Sample1] ( ./screens/checkbox.gif ) | ![ Sample2] ( ./screens/iosCheckbox.gif )
18
+ | Android Sample | iOS Sample |
19
+ | ---------------------------------- | ------------------------------------- |
20
+ | ![ Sample1] ( ./screens/checkbox.gif ) | ![ Sample2] ( ./screens/iosCheckbox.gif ) |
20
21
21
22
## Installation
23
+
22
24
From your command prompt/terminal go to your app's root folder and execute:
23
25
24
26
#### NS 3.0+
27
+
25
28
` tns plugin add nativescript-checkbox `
26
29
27
30
#### NS < 3.0
31
+
28
32
` tns plugin add [email protected] `
29
33
30
34
## Usage
31
35
32
36
###
37
+
33
38
``` XML
34
- <Page
35
- xmlns =" http://schemas.nativescript.org/tns.xsd"
39
+ <Page
40
+ xmlns =" http://schemas.nativescript.org/tns.xsd"
36
41
xmlns : CheckBox =" nativescript-checkbox" loaded =" pageLoaded" >
37
42
<ActionBar title =" Native Checkbox" />
38
43
<StackLayout >
@@ -42,7 +47,8 @@ From your command prompt/terminal go to your app's root folder and execute:
42
47
</Page >
43
48
```
44
49
45
- ###
50
+ ###
51
+
46
52
``` TS
47
53
import { CheckBox } from ' nativescript-checkbox' ;
48
54
import { topmost } from ' ui/frame' ;
@@ -65,30 +71,32 @@ public getCheckProp() {
65
71
import { TNSCheckBoxModule } from ' nativescript-checkbox/angular' ;
66
72
67
73
@NgModule ({
68
- imports: [TNSCheckBoxModule ],
69
- // etc.
74
+ imports: [TNSCheckBoxModule ]
75
+ // etc.
70
76
})
71
77
export class YourModule {}
72
78
73
79
// component:
74
- export class SomeComponent {
75
- @ViewChild (" CB1" ) FirstCheckBox: ElementRef ;
76
- constructor () {}
77
- public toggleCheck() {
78
- this .FirstCheckBox .nativeElement .toggle ();
79
- }
80
-
81
- public getCheckProp() {
82
- console .log (' checked prop value = ' + this .FirstCheckBox .nativeElement .checked );
83
- }
80
+ export class SomeComponent {
81
+ @ViewChild (' CB1' ) FirstCheckBox: ElementRef ;
82
+ constructor () {}
83
+ public toggleCheck() {
84
+ this .FirstCheckBox .nativeElement .toggle ();
85
+ }
86
+
87
+ public getCheckProp() {
88
+ console .log (
89
+ ' checked prop value = ' + this .FirstCheckBox .nativeElement .checked
90
+ );
91
+ }
84
92
}
85
93
```
86
94
87
95
``` html
88
96
<StackLayout >
89
- <CheckBox #CB1 text =" CheckBox Label" checked =" false" ></CheckBox >
90
- < Button (tap) =" toggleCheck()" text =" Toggle it!" ></Button >
91
- < Button (tap) =" getCheckProp()" text =" Check Property" ></Button >
97
+ <CheckBox #CB1 text =" CheckBox Label" checked =" false" ></CheckBox >
98
+ < button (tap) =" toggleCheck()" text =" Toggle it!" ></button >
99
+ < button (tap) =" getCheckProp()" text =" Check Property" ></button >
92
100
</StackLayout >
93
101
```
94
102
@@ -97,12 +105,16 @@ export class SomeComponent {
97
105
In your ` main.js ` (The file where the root Vue instance is created) register the element
98
106
99
107
``` js
100
- Vue .registerElement (' CheckBox' , () => require (' nativescript-checkbox' ).CheckBox , {
101
- model: {
102
- prop: ' checked' ,
103
- event : ' checkedChange'
104
- }
105
- })
108
+ Vue .registerElement (
109
+ ' CheckBox' ,
110
+ () => require (' nativescript-checkbox' ).CheckBox ,
111
+ {
112
+ model: {
113
+ prop: ' checked' ,
114
+ event : ' checkedChange'
115
+ }
116
+ }
117
+ );
106
118
```
107
119
108
120
And in your template, use it
@@ -129,14 +141,16 @@ And in your template, use it
129
141
## Css Styling
130
142
131
143
- ** color** - set the text label color
132
- - ** font-size** - checkbox is sized to text from here : default 15
144
+ - ** font-size** - checkbox is sized to text from here : default 15
133
145
- ** border-width** - set the line width of the checkbox element: iOS only
134
146
135
147
## Styling [ Android]
148
+
136
149
- ** checkStyle** - set to the name of your drawable
137
150
- ** checkPadding** - set the padding of the checkbox
138
151
139
152
Add the following to ` app/App_Resources/Android/drawable/checkbox_grey.xml `
153
+
140
154
``` xml
141
155
<?xml version =" 1.0" encoding =" utf-8" ?>
142
156
@@ -149,22 +163,24 @@ Add the following to `app/App_Resources/Android/drawable/checkbox_grey.xml`
149
163
```
150
164
151
165
## Radiobuttons, anyone?
166
+
152
167
Want to use radiobutton behavior for your checkboxes (only one option possible within a group)?
153
168
Set ` boxType="circle" ` and check out the second tab in the [ Angular demo] ( demo-ng/ ) , here's a screenshot:
154
169
155
170
<img src =" ./screens/radiobuttons.png " width =" 225px " />
156
171
157
172
## Demo Setup
158
- * npm i
159
- * npm run preparedemo
160
- * npm run demo.ios
161
173
174
+ - npm i
175
+ - npm run preparedemo
176
+ - npm run demo.ios
162
177
163
178
#### Contributors
164
179
165
180
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
166
181
167
- | [ <img src =" https://avatars0.githubusercontent.com/u/6006148?v=3 " width =" 100px; " /><br /><sub >Brad Martin</sub >] ( https://bradmartin.net/ ) | [ <img src =" https://avatars2.githubusercontent.com/u/1542376?v=3 " width =" 100px; " /><br /><sub >Steve McNiven-Scott</sub >] ( https://github.com/sitefinitysteve ) | [ <img src =" https://avatars3.githubusercontent.com/u/6695919?v=3 " width =" 100px; " /><br /><sub >Osei Fortune</sub >] ( https://github.com/triniwiz ) | [ <img src =" https://avatars2.githubusercontent.com/u/457187?v=3 " width =" 100px; " /><br /><sub >Nathan Walker</sub >] ( https://github.com/NathanWalker ) |
168
- | ---| ---| ---| ---| ---|
182
+ | [ <img src =" https://avatars0.githubusercontent.com/u/6006148?v=3 " width =" 100px; " /><br /><sub >Brad Martin</sub >] ( https://bradmartin.net/ ) | [ <img src =" https://avatars2.githubusercontent.com/u/1542376?v=3 " width =" 100px; " /><br /><sub >Steve McNiven-Scott</sub >] ( https://github.com/sitefinitysteve ) | [ <img src =" https://avatars3.githubusercontent.com/u/6695919?v=3 " width =" 100px; " /><br /><sub >Osei Fortune</sub >] ( https://github.com/triniwiz ) | [ <img src =" https://avatars2.githubusercontent.com/u/457187?v=3 " width =" 100px; " /><br /><sub >Nathan Walker</sub >] ( https://github.com/NathanWalker ) |
183
+ | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
184
+
169
185
170
186
<!-- ALL-CONTRIBUTORS-LIST:END -->
0 commit comments