kaplay-ui 0.15.3 → 0.16.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
@@ -24,7 +24,7 @@ npm install kaplay-ui
24
24
 
25
25
  ## Usage
26
26
 
27
- ### Buttons
27
+ ### Inputs
28
28
 
29
29
  #### Text Button
30
30
 
@@ -41,6 +41,15 @@ Makes a button with centered text that takes the following parameters:
41
41
  | `btnOutline` | `number` | 1 | ❌ No | Button outline |
42
42
  | `txtSize` | `number` | 15 | ❌ No | Text size |
43
43
 
44
+ #### Toggle
45
+
46
+ Makes a toggle that takes the following parameters:
47
+
48
+ | Parameter | Type | Default | Required | Description |
49
+ | --------- | -------- | ------- | -------- | ----------------- |
50
+ | `x` | `number` | 0 | ❌ No | Toggle x position |
51
+ | `y` | `number` | 0 | ❌ No | Toggle y position |
52
+
44
53
  ## License
45
54
 
46
55
  This project is licensed under the MIT License - see the LICENSE file for details.
@@ -45,3 +45,42 @@ export const makeTextButton = (
45
45
 
46
46
  return btn;
47
47
  };
48
+
49
+ /**
50
+ * Makes toggle
51
+ * @param {number} x - The x postion to set (default is 0).
52
+ * @param {number} y - The x postion to set (default is 0)
53
+ * @returns {GameObj}
54
+ */
55
+ export const makeToggle = (x = 0, y = 0) => {
56
+ // Toggle base
57
+ const toggle = make([
58
+ rect(50, 25, { radius: 25 }),
59
+ pos(x, y),
60
+ color(169, 169, 169),
61
+ area(),
62
+ {
63
+ toggled: false,
64
+ },
65
+ ]);
66
+
67
+ // Toggle button
68
+ const toggleBtn = make([circle(10), color(WHITE), pos(12.5, 12.5)]);
69
+
70
+ // Add button to toggleBase
71
+ toggle.add(toggleBtn);
72
+
73
+ toggle.onClick(() => {
74
+ if (toggle.toggled) {
75
+ toggle.use(color(169, 169, 169));
76
+ toggleBtn.use(pos(12.5, 12.5));
77
+ toggle.toggled = false;
78
+ } else {
79
+ toggle.use(color(59, 130, 246));
80
+ toggleBtn.use(pos(37.5, 12.5));
81
+ toggle.toggled = true;
82
+ }
83
+ });
84
+
85
+ return toggle;
86
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {