@lemonadejs/switch 1.0.0 → 1.0.2

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 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)
@@ -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
@@ -10,8 +10,8 @@ if (!lemonade && typeof (require) === 'function') {
10
10
  const Switch = function () {
11
11
  let self = this;
12
12
 
13
- return `<label class="lm-switch">
14
- <input type="checkbox" name="{{self.name}}" disabled="{{self.disabled}}" :checked="self.checked" :value="self.value"> <span>{{self.text}}</span>
13
+ return `<label class="lm-switch" position="{{self.position}}">
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(Tabs, root, options, template)
22
+ lemonade.render(Switch, root, options)
23
23
  return options;
24
24
  } else {
25
25
  return Switch.call(this, root);
@@ -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
@@ -1,22 +1,23 @@
1
1
  .lm-switch {
2
2
  position: relative;
3
- display: inline-block;
3
+ display: inline-flex;
4
4
  z-index: 0;
5
+ align-items: center;
5
6
  }
6
7
 
7
8
  .lm-switch > input {
8
9
  appearance: none;
9
10
  -moz-appearance: none;
10
11
  -webkit-appearance: none;
11
- z-index: -1;
12
12
  position: absolute;
13
- right: 6px;
14
- top: -8px;
15
- display: block;
13
+ left: 0;
16
14
  margin: 0;
15
+ display: block;
17
16
  border-radius: 50%;
18
17
  width: 40px;
19
18
  height: 40px;
19
+ max-width: 40px;
20
+ max-height: 40px;
20
21
  outline: none;
21
22
  opacity: 0;
22
23
  transform: scale(1);
@@ -25,11 +26,12 @@
25
26
  }
26
27
 
27
28
  .lm-switch > span {
28
- display: inline-block;
29
+ display: inline-flex;
29
30
  width: 100%;
30
31
  line-height: 24px;
31
32
  cursor: pointer;
32
- margin: 0 5px 0 0;
33
+ margin: 0 0 0 45px;
34
+ align-items: center;
33
35
  }
34
36
 
35
37
  .lm-switch > span:empty {
@@ -38,22 +40,19 @@
38
40
 
39
41
  .lm-switch > span::before {
40
42
  content: "";
41
- float: right;
42
- display: inline-block;
43
- margin: 5px 0 5px 0;
43
+ position: absolute;
44
+ left: 0;
44
45
  border-radius: 7px;
45
46
  width: 36px;
46
47
  height: 14px;
47
48
  background-color: rgba(var(--lm-switch-front-color, 0,0,0), 0.38);
48
- vertical-align: top;
49
49
  transition: background-color 0.2s, opacity 0.2s;
50
50
  }
51
51
 
52
52
  .lm-switch > span::after {
53
53
  content: "";
54
54
  position: absolute;
55
- top: 2px;
56
- right: 16px;
55
+ left: 0;
57
56
  border-radius: 50%;
58
57
  width: 20px;
59
58
  height: 20px;
@@ -63,7 +62,7 @@
63
62
  }
64
63
 
65
64
  .lm-switch > input:checked {
66
- right: -10px;
65
+ left: 6px;
67
66
  background-color: rgb(var(--pure-material-primary-rgb, 33,150,243));
68
67
  }
69
68
 
@@ -120,3 +119,22 @@
120
119
  .lm-switch > input:checked:disabled + span::before {
121
120
  background-color: rgba(var(--pure-material-primary-rgb,33,150,243), 0.6);
122
121
  }
122
+
123
+ .lm-switch[position="right"] > span {
124
+ margin: 0 45px 0 0;
125
+ }
126
+
127
+ .lm-switch[position="right"] > input {
128
+ left: initial;
129
+ right: -11px;
130
+ }
131
+
132
+ .lm-switch[position="right"] > span::before {
133
+ left: initial;
134
+ right: 0;
135
+ }
136
+
137
+ .lm-switch[position="right"] > span::after {
138
+ left: initial;
139
+ right: 16px;
140
+ }
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
@@ -16,5 +16,5 @@
16
16
  "lemonadejs": "^4.0.7"
17
17
  },
18
18
  "main": "dist/index.js",
19
- "version": "1.0.0"
19
+ "version": "1.0.2"
20
20
  }