@operato/input 1.0.0-beta.30 → 1.0.0-beta.33

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.
@@ -0,0 +1,143 @@
1
+ import '@material/mwc-button'
2
+
3
+ import { css, html } from 'lit'
4
+ import { customElement, property, query } from 'lit/decorators.js'
5
+
6
+ import { i18next } from '@operato/i18n'
7
+
8
+ import { OxFormField } from './ox-form-field'
9
+
10
+ @customElement('ox-input-duration')
11
+ export class OxInputDuration extends OxFormField {
12
+ static styles = css`
13
+ :host {
14
+ display: block;
15
+ width: 100%;
16
+ height: 100%;
17
+ }
18
+
19
+ :host * {
20
+ box-sizing: border-box;
21
+ }
22
+
23
+ :host *:focus {
24
+ outline: none;
25
+ }
26
+
27
+ form {
28
+ width: 100%;
29
+ height: 100%;
30
+ justify-content: center;
31
+ }
32
+
33
+ input {
34
+ margin-top: var(--margin-default);
35
+ padding: 5px;
36
+ border: 0;
37
+ border-bottom: var(--border-dark-color);
38
+ padding: var(--input-padding);
39
+ font: var(--input-font);
40
+ color: var(--primary-text-color);
41
+ }
42
+
43
+ input:focus {
44
+ outline: none;
45
+ border-bottom: 1px solid var(--primary-color);
46
+ }
47
+
48
+ input:invalid {
49
+ border-bottom: 1px solid var(--status-danger-color);
50
+ color: var(--status-danger-color);
51
+ }
52
+
53
+ label {
54
+ width: 100%;
55
+ font: normal 0.8em var(--theme-font);
56
+ color: var(--primary-color);
57
+ }
58
+ `
59
+
60
+ @property({ type: Number }) declare value?: number
61
+
62
+ render() {
63
+ var d = Number(this.value || 0)
64
+
65
+ const days = Math.floor(d / (3600 * 24))
66
+ d -= days * 24 * 3600
67
+ const hours = Math.floor(d / 3600)
68
+ d -= hours * 3600
69
+ const minutes = Math.floor(d / 60)
70
+ const seconds = d - minutes * 60
71
+
72
+ return html`
73
+ <form @change=${this.onChange.bind(this)}>
74
+ <input id="days" type="number" .value=${days} pattern="\\d*" />
75
+ <label for="days">${i18next.t('label.days')}</label>
76
+
77
+ <input id="hours" type="number" .value=${hours} pattern="[01]?\\d|2[0-3]" />
78
+ <label for="hour">${i18next.t('label.hours')}</label>
79
+
80
+ <input id="minutes" type="number" .value=${minutes} pattern="[0-5]?\\d" />
81
+ <label for="minute">${i18next.t('label.minutes')}</label>
82
+
83
+ <input id="seconds" type="number" .value=${seconds} pattern="[0-5]?\\d" />
84
+ <label for="second">${i18next.t('label.seconds')}</label>
85
+
86
+ <button
87
+ type="button"
88
+ @click=${(e: Event) => {
89
+ e.preventDefault()
90
+ e.stopPropagation()
91
+
92
+ this.value = 0
93
+
94
+ this.dispatchEvent(
95
+ new CustomEvent('change', {
96
+ bubbles: true,
97
+ composed: true,
98
+ detail: this.value
99
+ })
100
+ )
101
+ }}
102
+ >
103
+ Clear
104
+ </button>
105
+ </form>
106
+ `
107
+ }
108
+
109
+ firstUpdated() {
110
+ ;(this.renderRoot.querySelector('input') as HTMLInputElement).focus()
111
+ }
112
+
113
+ @query('#days') days!: HTMLInputElement
114
+ @query('#hours') hours!: HTMLInputElement
115
+ @query('#minutes') minutes!: HTMLInputElement
116
+ @query('#seconds') seconds!: HTMLInputElement
117
+
118
+ onChange(e: Event) {
119
+ e.stopPropagation()
120
+
121
+ var form = this.renderRoot.querySelector('form') as HTMLFormElement
122
+ var valid = form.checkValidity()
123
+ if (!valid) {
124
+ form.reportValidity()
125
+ return
126
+ }
127
+
128
+ const days = Number(this.days.value)
129
+ const hours = Number(this.hours.value)
130
+ const minutes = Number(this.minutes.value)
131
+ const seconds = Number(this.seconds.value)
132
+
133
+ this.value = (days || 0) * 24 * 60 * 60 + (hours || 0) * 60 * 60 + (minutes || 0) * 60 + (seconds || 0)
134
+
135
+ this.dispatchEvent(
136
+ new CustomEvent('change', {
137
+ bubbles: true,
138
+ composed: true,
139
+ detail: this.value
140
+ })
141
+ )
142
+ }
143
+ }
@@ -9,7 +9,9 @@ export default {
9
9
  name: { control: 'text' },
10
10
  value: { control: 'text' },
11
11
  scannable: { control: 'boolean' },
12
- withoutEnter: { control: 'boolean' }
12
+ withoutEnter: { control: 'boolean' },
13
+ englishOnly: { control: 'boolean' },
14
+ selectAfterChange: { control: 'boolean' }
13
15
  }
14
16
  }
15
17
 
@@ -24,17 +26,51 @@ interface ArgTypes {
24
26
  value?: string
25
27
  scannable?: boolean
26
28
  withoutEnter?: boolean
29
+ englishOnly?: boolean
30
+ selectAfterChange?: boolean
27
31
  }
28
32
 
29
- const Template: Story<ArgTypes> = ({ name = 'barcode', scannable = true, withoutEnter = true }: ArgTypes) => html`
33
+ const Template: Story<ArgTypes> = ({
34
+ name = 'barcode',
35
+ scannable = true,
36
+ withoutEnter = true,
37
+ englishOnly = false,
38
+ selectAfterChange = false
39
+ }: ArgTypes) => html`
30
40
  <link href="/themes/app-theme.css" rel="stylesheet" />
31
41
  <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
32
- <ox-input-barcode name=${name} ?without-enter=${withoutEnter} ?scannable=${scannable}> </ox-input-barcode>
42
+ <ox-input-barcode
43
+ name=${name}
44
+ ?without-enter=${withoutEnter}
45
+ ?scannable=${scannable}
46
+ ?english-only=${englishOnly}
47
+ ?select-after-change=${selectAfterChange}
48
+ @change=${(e: CustomEvent) => console.log((e.target as HTMLInputElement).value)}
49
+ >
50
+ </ox-input-barcode>
33
51
  `
34
52
 
35
53
  export const Regular = Template.bind({})
36
54
  Regular.args = {
37
55
  name: 'barcode',
38
56
  scannable: true,
39
- withoutEnter: true
57
+ withoutEnter: true,
58
+ englishOnly: false
59
+ }
60
+
61
+ export const EnglishOnly = Template.bind({})
62
+ EnglishOnly.args = {
63
+ name: 'barcode',
64
+ scannable: true,
65
+ withoutEnter: true,
66
+ englishOnly: true
67
+ }
68
+
69
+ export const selectAfterChange = Template.bind({})
70
+ selectAfterChange.args = {
71
+ name: 'barcode',
72
+ scannable: true,
73
+ withoutEnter: true,
74
+ englishOnly: true,
75
+ selectAfterChange: true
40
76
  }
@@ -0,0 +1,51 @@
1
+ import '../src/ox-input-duration.js'
2
+ import '../src/locale/locale-picker.js'
3
+
4
+ import { html, TemplateResult } from 'lit'
5
+
6
+ export default {
7
+ title: 'ox-input-duration',
8
+ component: 'ox-input-duration',
9
+ argTypes: {
10
+ value: { control: 'number' },
11
+ name: { control: 'text' }
12
+ }
13
+ }
14
+
15
+ interface Story<T> {
16
+ (args: T): TemplateResult
17
+ args?: Partial<T>
18
+ argTypes?: Record<string, unknown>
19
+ }
20
+
21
+ interface ArgTypes {
22
+ name?: string
23
+ value?: number
24
+ }
25
+
26
+ const Template: Story<ArgTypes> = ({ name = 'duration', value = 3601 }: ArgTypes) => html`
27
+ <link href="/themes/app-theme.css" rel="stylesheet" />
28
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
29
+ <style>
30
+ body {
31
+ }
32
+ </style>
33
+
34
+ <locale-picker></locale-picker>
35
+ <br /><br />
36
+
37
+ <ox-input-duration
38
+ @change=${(e: Event) => {
39
+ console.log((e.target as HTMLInputElement).value)
40
+ }}
41
+ name=${name}
42
+ .value=${value}
43
+ >
44
+ </ox-input-duration>
45
+ `
46
+
47
+ export const Regular = Template.bind({})
48
+ Regular.args = {
49
+ name: 'duration',
50
+ value: 3601
51
+ }