@lemonadejs/switch 1.0.0 → 1.0.1
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 +73 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +2 -2
- package/dist/react.d.ts +15 -0
- package/dist/react.js +34 -0
- package/dist/style.css +2 -0
- package/dist/vue.d.ts +15 -0
- package/dist/vue.js +45 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# LemonadeJS Switch
|
|
2
|
+
|
|
3
|
+
[Official website and documentation is here](https://lemonadejs.net/components/switch)
|
|
4
|
+
|
|
5
|
+
Compatible with Vanilla JavaScript, LemonadeJS, React, Vue or Angular.
|
|
6
|
+
|
|
7
|
+
The LemonadeJS JavaScript Switch is a responsive and reactive component that enables users to make a binary choice through a visually appealing interface.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Lightweight: The JavaScript Switch is only about 2 KBytes;
|
|
12
|
+
- Integration: It can be used as a standalone library or integrated with any modern framework;
|
|
13
|
+
|
|
14
|
+
## Getting Started
|
|
15
|
+
|
|
16
|
+
You can install using NPM or using directly from a CDN.
|
|
17
|
+
|
|
18
|
+
### npm Installation
|
|
19
|
+
|
|
20
|
+
To install it in your project using npm, run the following command:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ npm install @lemonadejs/switch
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### CDN
|
|
27
|
+
|
|
28
|
+
To use tabs via a CDN, include the following script tags in your HTML file:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
|
|
32
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/index.min.js"></script>
|
|
33
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/style.min.css" />
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Usage
|
|
37
|
+
|
|
38
|
+
Quick example with Lemonade
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import lemonade from 'lemonadejs'
|
|
42
|
+
import Switch from '@lemonadejs/switch';
|
|
43
|
+
import '@lemonadejs/switch/dist/style.css';
|
|
44
|
+
|
|
45
|
+
export default function App() {
|
|
46
|
+
const self = this;
|
|
47
|
+
|
|
48
|
+
return `<div>
|
|
49
|
+
<Switch text="On/Off" />
|
|
50
|
+
</div>`
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
[You can find more examples here in the official documentation.](https://lemonadejs.net/components/switch)
|
|
55
|
+
|
|
56
|
+
#### Settings
|
|
57
|
+
|
|
58
|
+
| Attribute | Description |
|
|
59
|
+
|-----------|-------------|
|
|
60
|
+
| text?: string | The displayed text. |
|
|
61
|
+
| value?: any | The current value of the component. |
|
|
62
|
+
| name?: string | The attribute `name` assigned to the switch element. |
|
|
63
|
+
| disabled?: boolean | Disables the functionality of the switch. |
|
|
64
|
+
| onopen? | function | When a new tabs is opened. |
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
The [LemonadeJS](https://lemonadejs.net) Switch is released under the MIT.
|
|
69
|
+
|
|
70
|
+
## Other Tools
|
|
71
|
+
|
|
72
|
+
- [jSuites](https://jsuites.net/v4/)
|
|
73
|
+
- [Jspreadsheet Data Grid](https://jspreadsheet.com)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Type definitions for the JavaScript Switch
|
|
3
|
+
* https://lemonadejs.net
|
|
4
|
+
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
declare function Switch(el: HTMLElement, options?: Switch.Options): Switch.Instance;
|
|
8
|
+
|
|
9
|
+
declare namespace Switch {
|
|
10
|
+
interface Options {
|
|
11
|
+
/** The 'Text' serves as the label displayed on the switch side, indicating the information associated with the switch */
|
|
12
|
+
text?: string;
|
|
13
|
+
/** Value will hold the current switch internal state value */
|
|
14
|
+
value?: boolean;
|
|
15
|
+
/** Identification name */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Determines whether the switch can be toggled or not */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Instance {
|
|
22
|
+
/** Value will hold the current switch internal state value */
|
|
23
|
+
value?: boolean;
|
|
24
|
+
/** Determines whether the switch can be toggled or not */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default Switch;
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
11
11
|
let self = this;
|
|
12
12
|
|
|
13
13
|
return `<label class="lm-switch">
|
|
14
|
-
|
|
14
|
+
<input type="checkbox" name="{{self.name}}" disabled="{{self.disabled}}" :bind="self.value"> <span>{{self.text}}</span>
|
|
15
15
|
</label>`
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
19
19
|
|
|
20
20
|
return function (root, options) {
|
|
21
21
|
if (typeof (root) === 'object') {
|
|
22
|
-
lemonade.render(
|
|
22
|
+
lemonade.render(Switch, root, options)
|
|
23
23
|
return options;
|
|
24
24
|
} else {
|
|
25
25
|
return Switch.call(this, root);
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Type definitions for the LemonadeJS plugins
|
|
3
|
+
* https://lemonadejs.net
|
|
4
|
+
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
*/
|
|
6
|
+
import Component from './index';
|
|
7
|
+
|
|
8
|
+
interface Switch {
|
|
9
|
+
(): any
|
|
10
|
+
[key: string]: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function Switch<Switch>(props: Component.Options): any;
|
|
14
|
+
|
|
15
|
+
export default Switch;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
|
+
import Component from './index';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default React.forwardRef((props, mainReference) => {
|
|
6
|
+
// Dom element
|
|
7
|
+
const Ref = useRef(null);
|
|
8
|
+
|
|
9
|
+
// Get the properties for the spreadsheet
|
|
10
|
+
let options = { ...props };
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!Ref.current.innerHTML) {
|
|
14
|
+
mainReference.current = Component(Ref.current, options);
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
for (let key in props) {
|
|
20
|
+
if (props.hasOwnProperty(key) && mainReference.current.hasOwnProperty(key)) {
|
|
21
|
+
if (props[key] !== mainReference.current[key]) {
|
|
22
|
+
mainReference.current[key] = props[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, [props])
|
|
27
|
+
|
|
28
|
+
let prop = {
|
|
29
|
+
ref: Ref,
|
|
30
|
+
style: { height: '100%', width: '100%' }
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return React.createElement("div", prop);
|
|
34
|
+
})
|
package/dist/style.css
CHANGED
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Type definitions for the LemonadeJS plugins
|
|
3
|
+
* https://lemonadejs.net
|
|
4
|
+
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
*/
|
|
6
|
+
import Component from './index';
|
|
7
|
+
|
|
8
|
+
interface Switch {
|
|
9
|
+
(): any
|
|
10
|
+
[key: string]: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function Switch<Switch>(props: Component.Options): any;
|
|
14
|
+
|
|
15
|
+
export default Switch;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { h } from 'vue';
|
|
2
|
+
import component from "./index";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
mounted() {
|
|
8
|
+
let options = {
|
|
9
|
+
...this.$attrs
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
this.el = this.$refs.container;
|
|
13
|
+
|
|
14
|
+
this.current = component(this.$refs.container, options);
|
|
15
|
+
},
|
|
16
|
+
setup() {
|
|
17
|
+
let containerProps = {
|
|
18
|
+
ref: 'container',
|
|
19
|
+
style: {
|
|
20
|
+
width: '100%',
|
|
21
|
+
height: '100%',
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return () => h('div', containerProps);
|
|
25
|
+
},
|
|
26
|
+
watch: {
|
|
27
|
+
$attrs: {
|
|
28
|
+
deep: true,
|
|
29
|
+
handler() {
|
|
30
|
+
this.updateState();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
methods: {
|
|
35
|
+
updateState() {
|
|
36
|
+
for (let key in this.$attrs) {
|
|
37
|
+
if (this.$attrs.hasOwnProperty(key) && this.current.hasOwnProperty(key)) {
|
|
38
|
+
if (this.$attrs[key] !== this.current[key]) {
|
|
39
|
+
this.current[key] = this.$attrs[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
CHANGED