kaplay-ui 0.18.3 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,9 +26,44 @@ npm install kaplay-ui
26
26
 
27
27
  ### Inputs
28
28
 
29
+ All inputs are imported from the <code>/inputs</code> folder.
30
+
31
+ ```javascript
32
+ import {} from "kaplay-ui/inputs";
33
+ ```
34
+
29
35
  #### Checkbox
30
36
 
31
- Makes a checkbow that takes the following parameters:
37
+ To make a checkbox, one must use the exported <code>makeCheckbox()</code> function.
38
+
39
+ ##### Example
40
+
41
+ An example usage of a checkbox.
42
+
43
+ ```javascript
44
+ import kaplay from "kaplay";
45
+ import "kaplay/global";
46
+
47
+ import { makeCheckbox } from "kaplay-ui/inputs";
48
+
49
+ kaplay();
50
+
51
+ const checkBox = makeCheckbox();
52
+
53
+ add(checkBox);
54
+ ```
55
+
56
+ ##### State
57
+
58
+ A cehckbox has the following state:
59
+
60
+ | state | Type | Default | State change by |
61
+ | --------- | --------- | ------- | ----------------- |
62
+ | `checked` | `boolean` | false | Click on checkbox |
63
+
64
+ ##### Parameters
65
+
66
+ A checkbox can take the following parameters:
32
67
 
33
68
  | Parameter | Type | Default | Required | Description |
34
69
  | --------- | -------- | ------- | -------- | ------------------- |
@@ -37,9 +72,72 @@ Makes a checkbow that takes the following parameters:
37
72
  | `width` | `number` | 25 | ❌ No | Checkbox width |
38
73
  | `height` | `number` | 25 | ❌ No | Checkbox height |
39
74
 
75
+ <br>
76
+
77
+ #### Switch
78
+
79
+ To make a text button, one must use the exported <code>makeSwitch()</code> function.
80
+
81
+ ##### Example
82
+
83
+ An example usage of a text button.
84
+
85
+ ```javascript
86
+ import kaplay from "kaplay";
87
+ import "kaplay/global";
88
+
89
+ import { makeSwitch } from "kaplay-ui/inputs";
90
+
91
+ kaplay();
92
+
93
+ const switchBtn = makeSwitch();
94
+
95
+ add(switchBtn);
96
+ ```
97
+
98
+ ##### State
99
+
100
+ A cehckbox has the following state:
101
+
102
+ | state | Type | Default | State change by |
103
+ | ---------- | --------- | ------- | --------------- |
104
+ | `switched` | `boolean` | false | Click on switch |
105
+
106
+ ##### Parameters
107
+
108
+ A switch can take the following parameters:
109
+
110
+ | Parameter | Type | Default | Required | Description |
111
+ | --------- | -------- | ------- | -------- | ----------------- |
112
+ | `x` | `number` | 0 | ❌ No | Switch x position |
113
+ | `y` | `number` | 0 | ❌ No | Switch x position |
114
+ | `width` | `number` | 50 | ❌ No | Switch width |
115
+ | `height` | `number` | 25 | ❌ No | Switch height |
116
+
40
117
  #### Text Button
41
118
 
42
- Makes a button with centered text that takes the following parameters:
119
+ To make a text button, one must use the exported <code>makeTextButton()</code> function.
120
+
121
+ ##### Example
122
+
123
+ An example usage of a text button.
124
+
125
+ ```javascript
126
+ import kaplay from "kaplay";
127
+ import "kaplay/global";
128
+
129
+ import { makeTextButton } from "kaplay-ui/inputs";
130
+
131
+ kaplay();
132
+
133
+ const txtBtn = makeTextButton("Start");
134
+
135
+ add(txtBtn);
136
+ ```
137
+
138
+ ##### Parameters
139
+
140
+ A text button can take the following parameters:
43
141
 
44
142
  | Parameter | Type | Default | Required | Description |
45
143
  | ------------ | -------- | ------- | -------- | ---------------------------------- |
@@ -52,9 +150,40 @@ Makes a button with centered text that takes the following parameters:
52
150
  | `btnOutline` | `number` | 1 | ❌ No | Button outline |
53
151
  | `txtSize` | `number` | 15 | ❌ No | Text size |
54
152
 
153
+ <br>
154
+
55
155
  #### Toggle
56
156
 
57
- Makes a toggle that takes the following parameters:
157
+ To make a toggle, one must use the exported <code>makeToggle()</code> function.
158
+
159
+ ##### Example
160
+
161
+ An example usage of a toggle.
162
+
163
+ ```javascript
164
+ import kaplay from "kaplay";
165
+ import "kaplay/global";
166
+
167
+ import { makeToggle } from "kaplay-ui/inputs";
168
+
169
+ kaplay();
170
+
171
+ const toggle = makeToggle();
172
+
173
+ add(toggle);
174
+ ```
175
+
176
+ ##### State
177
+
178
+ A cehckbox has the following state:
179
+
180
+ | state | Type | Default | State change by |
181
+ | --------- | --------- | ------- | --------------- |
182
+ | `toggled` | `boolean` | false | Click on toggle |
183
+
184
+ ##### Parameters
185
+
186
+ A toggle can take the following parameters:
58
187
 
59
188
  | Parameter | Type | Default | Required | Description |
60
189
  | --------- | -------- | ------- | -------- | ----------------- |
@@ -63,10 +192,14 @@ Makes a toggle that takes the following parameters:
63
192
  | `width` | `number` | 50 | ❌ No | Toggle width |
64
193
  | `height` | `number` | 25 | ❌ No | Toggle height |
65
194
 
195
+ <br>
196
+
66
197
  ## License
67
198
 
68
199
  This project is licensed under the MIT License - see the LICENSE file for details.
69
200
 
201
+ <br>
202
+
70
203
  ## Contact
71
204
 
72
205
  Have questions or suggestions? Reach out via:
package/inputs/index.js CHANGED
@@ -131,3 +131,56 @@ export const makeCheckbox = (x = 0, y = 0, width = 25, height = 25) => {
131
131
 
132
132
  return checkbox;
133
133
  };
134
+
135
+ /**
136
+ * Makes checkbox
137
+ * @param {number} x - Switch x postion (default is 0)
138
+ * @param {number} y - Switch y postion (default is 0)
139
+ * @param {number} width - Switch width (default is 50)
140
+ * @param {number} height - Switch height (default is 25)
141
+ * @returns {GameObj}
142
+ */
143
+ export const makeSwitch = (x = 0, y = 0, width = 50, height = 25) => {
144
+ // Make switch base
145
+ const switchBase = make([
146
+ rect(width, height),
147
+ pos(x, y),
148
+ opacity(0),
149
+ area(),
150
+ {
151
+ switched: false,
152
+ },
153
+ ]);
154
+
155
+ // Make switch line
156
+ const switchLine = make([
157
+ rect(width, height / 2, { radius: height / 4 }),
158
+ color(169, 169, 169),
159
+ pos(0, height / 2 - height / 4),
160
+ area(),
161
+ ]);
162
+
163
+ // Make switch circle
164
+ const switchCircle = make([circle(height / 2), pos(height / 2, height / 2)]);
165
+
166
+ // On click
167
+ switchBase.onClick(() => {
168
+ if (switchBase.switched) {
169
+ switchLine.use(color(169, 169, 169));
170
+ switchCircle.use(color(255, 255, 255));
171
+ switchCircle.use(pos(height / 2, height / 2));
172
+ switchBase.switched = false;
173
+ } else {
174
+ switchLine.use(color(148, 188, 236));
175
+ switchCircle.use(color(24, 118, 210));
176
+ switchCircle.use(pos(width - switchCircle.radius, height / 2));
177
+ switchBase.switched = true;
178
+ }
179
+ });
180
+
181
+ // Add line and circle
182
+ switchBase.add(switchLine);
183
+ switchBase.add(switchCircle);
184
+
185
+ return switchBase;
186
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.18.3",
3
+ "version": "0.19.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {