@operato/input 8.0.0-alpha.41 → 8.0.0-alpha.46

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/input",
3
3
  "description": "Webcomponents for input following open-wc recommendations",
4
4
  "author": "heartyoh@hatiolab.com",
5
- "version": "8.0.0-alpha.41",
5
+ "version": "8.0.0-alpha.46",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -42,6 +42,7 @@
42
42
  "./ox-input-key-values.js": "./dist/src/ox-input-key-values.js",
43
43
  "./ox-select.js": "./dist/src/ox-select.js",
44
44
  "./ox-input-file.js": "./dist/src/ox-input-file.js",
45
+ "./ox-input-switch.js": "./dist/src/ox-input-switch.js",
45
46
  "./ox-input-image.js": "./dist/src/ox-input-image.js",
46
47
  "./ox-input-options.js": "./dist/src/ox-input-options.js",
47
48
  "./ox-input-select-buttons.js": "./dist/src/ox-input-select-buttons.js",
@@ -132,6 +133,9 @@
132
133
  "./ox-input-file.js": [
133
134
  "./dist/src/ox-input-file.d.ts"
134
135
  ],
136
+ "./ox-input-switch.js": [
137
+ "./dist/src/ox-input-switch.d.ts"
138
+ ],
135
139
  "./ox-input-image.js": [
136
140
  "./dist/src/ox-input-image.d.ts"
137
141
  ],
@@ -262,5 +266,5 @@
262
266
  "prettier --write"
263
267
  ]
264
268
  },
265
- "gitHead": "0c2adcc994cd105055c9355810fa9c7c8196ca41"
269
+ "gitHead": "7a14ca5ab93f0ff0efa56ac434bf458cae6c41d6"
266
270
  }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './ox-form-field.js'
6
6
  export * from './ox-buttons-radio.js'
7
7
  export * from './ox-checkbox.js'
8
8
  export * from './ox-select.js'
9
+ export * from './ox-input-switch.js'
9
10
  export * from './ox-input-angle.js'
10
11
  export * from './ox-input-3dish.js'
11
12
  export * from './ox-input-3axis.js'
@@ -0,0 +1,117 @@
1
+ import { css, html } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+
4
+ import { OxFormField } from './ox-form-field'
5
+
6
+ @customElement('ox-input-switch')
7
+ export class OxInputSwitch extends OxFormField {
8
+ static styles = css`
9
+ :host {
10
+ --ox-simple-switch-fullwidth: 2em;
11
+ --ox-simple-switch-fullheight: 1em;
12
+ --ox-simple-switch-thumbnail-size: 1em;
13
+ }
14
+
15
+ label {
16
+ position: relative;
17
+ display: inline-block;
18
+ width: 100%;
19
+ height: 100%;
20
+ }
21
+
22
+ label input {
23
+ opacity: 0;
24
+ width: 0;
25
+ height: 0;
26
+ }
27
+
28
+ span {
29
+ position: absolute;
30
+ cursor: pointer;
31
+ width: var(--ox-simple-switch-fullwidth);
32
+ height: var(--ox-simple-switch-fullheight);
33
+ top: calc(0 - var(--ox-simple-switch-thumbnail-size));
34
+ left: 0;
35
+ background-color: var(--ox-simple-switch-off-color, #ccc);
36
+ -webkit-transition: 0.4s;
37
+ transition: 0.4s;
38
+ }
39
+
40
+ span:before {
41
+ position: absolute;
42
+ content: '';
43
+ height: calc(var(--ox-simple-switch-thumbnail-size) - 8px);
44
+ width: calc(var(--ox-simple-switch-thumbnail-size) - 8px);
45
+ left: 4px;
46
+ top: 4px;
47
+ background-color: var(--ox-simple-switch-thumbnail-color, white);
48
+ -webkit-transition: 0.4s;
49
+ transition: 0.4s;
50
+ }
51
+
52
+ input:checked + span {
53
+ background-color: var(--ox-simple-switch-on-color, #2196f3);
54
+ }
55
+
56
+ input + span:before {
57
+ -webkit-transform: translateY(
58
+ calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2)
59
+ );
60
+ -ms-transform: translateY(
61
+ calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2)
62
+ );
63
+ transform: translateY(calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2));
64
+ }
65
+
66
+ input:checked + span:before {
67
+ -webkit-transform: translateX(calc(var(--ox-simple-switch-fullwidth) - var(--ox-simple-switch-thumbnail-size)))
68
+ translateY(calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2));
69
+ -ms-transform: translateX(calc(var(--ox-simple-switch-fullwidth) - var(--ox-simple-switch-thumbnail-size)))
70
+ translateY(calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2));
71
+ transform: translateX(calc(var(--ox-simple-switch-fullwidth) - var(--ox-simple-switch-thumbnail-size)))
72
+ translateY(calc((var(--ox-simple-switch-fullheight) - var(--ox-simple-switch-thumbnail-size)) / 2));
73
+ }
74
+
75
+ /* Rounded sliders */
76
+ span[round] {
77
+ border-radius: calc(var(--ox-simple-switch-thumbnail-size) / 2);
78
+ }
79
+
80
+ span[round]:before {
81
+ border-radius: calc((var(--ox-simple-switch-thumbnail-size) - 8px) / 2);
82
+ }
83
+ `
84
+
85
+ @property({ type: Boolean }) round: boolean = false
86
+ @property({ type: Boolean }) value: boolean = false
87
+ @property({ type: Boolean }) disabled: boolean = false
88
+
89
+ render() {
90
+ return html`
91
+ <label>
92
+ <input type="checkbox" .checked=${this.value} ?disabled=${this.disabled} />
93
+ <span ?round=${this.round}></span>
94
+ </label>
95
+ `
96
+ }
97
+
98
+ firstUpdated() {
99
+ this.renderRoot.addEventListener('change', (e: Event) => {
100
+ e.preventDefault()
101
+ e.stopPropagation()
102
+
103
+ this.value = (e.target as HTMLInputElement)?.checked
104
+ this.dispatchEvent(
105
+ new CustomEvent('change', {
106
+ bubbles: true,
107
+ composed: true,
108
+ detail: this.value
109
+ })
110
+ )
111
+ })
112
+ }
113
+
114
+ protected appendFormData({ formData }: FormDataEvent): void {
115
+ this.name && formData.append(this.name, this.value ? 'true' : 'false')
116
+ }
117
+ }
@@ -0,0 +1,91 @@
1
+ import '@material/web/all.js'
2
+ import '../src/ox-input-switch.js'
3
+
4
+ import { TemplateResult, html } from 'lit'
5
+ import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
6
+
7
+ export default {
8
+ title: 'ox-input-switch',
9
+ component: 'ox-input-switch',
10
+ argTypes: {
11
+ label: { control: 'text' },
12
+ name: { control: 'text' },
13
+ round: { control: 'boolean' },
14
+ value: { control: 'boolean' },
15
+ disabled: { control: 'boolean' }
16
+ }
17
+ }
18
+
19
+ interface Story<T> {
20
+ (args: T): TemplateResult
21
+ args?: Partial<T>
22
+ argTypes?: Record<string, unknown>
23
+ }
24
+
25
+ interface ArgTypes {
26
+ label?: string
27
+ name?: string
28
+ round?: boolean
29
+ value?: boolean
30
+ disabled?: boolean
31
+ }
32
+
33
+ const Template: Story<ArgTypes> = ({
34
+ label = 'Checkbox',
35
+ name = 'hello',
36
+ round = false,
37
+ value = false,
38
+ disabled
39
+ }: ArgTypes) => html`
40
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
41
+
42
+ <link href="/themes/light.css" rel="stylesheet" />
43
+ <link href="/themes/dark.css" rel="stylesheet" />
44
+ <link href="/themes/spacing.css" rel="stylesheet" />
45
+
46
+ <link
47
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
48
+ rel="stylesheet"
49
+ />
50
+ <link
51
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
52
+ rel="stylesheet"
53
+ />
54
+ <link
55
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
56
+ rel="stylesheet"
57
+ />
58
+
59
+ <style>
60
+ ${MDTypeScaleStyles.cssText}
61
+ </style>
62
+
63
+ <style>
64
+ .container {
65
+ height: 500px;
66
+ text-align: center;
67
+ padding: 20px;
68
+ background-color: var(--md-sys-color-primary-container);
69
+ color: var(--md-sys-color-on-primary-container);
70
+ padding: 20px;
71
+ }
72
+
73
+ ox-input-switch {
74
+ --ox-simple-switch-fullwidth: 120px;
75
+ --ox-simple-switch-fullheight: 40px;
76
+ --ox-simple-switch-thumbnail-size: 60px;
77
+ }
78
+ </style>
79
+
80
+ <div class="container md-typescale-body-large-prominent">
81
+ <ox-input-switch name=${name} .value=${value} .round=${round} ?disabled=${disabled}> </ox-input-switch>
82
+ </div>
83
+ `
84
+
85
+ export const Regular = Template.bind({})
86
+ Regular.args = {
87
+ label: 'label',
88
+ name: 'label',
89
+ round: false,
90
+ value: false
91
+ }