@operato/input 1.0.0-beta.29 → 1.0.0-beta.31
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/CHANGELOG.md +19 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-input-barcode.d.ts +4 -2
- package/dist/src/ox-input-barcode.js +49 -19
- package/dist/src/ox-input-barcode.js.map +1 -1
- package/dist/src/ox-input-duration.d.ts +13 -0
- package/dist/src/ox-input-duration.js +138 -0
- package/dist/src/ox-input-duration.js.map +1 -0
- package/dist/stories/ox-input-barcode.stories.d.ts +5 -0
- package/dist/stories/ox-input-barcode.stories.js +22 -4
- package/dist/stories/ox-input-barcode.stories.js.map +1 -1
- package/dist/stories/ox-input-duration.stories.d.ts +26 -0
- package/dist/stories/ox-input-duration.stories.js +37 -0
- package/dist/stories/ox-input-duration.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/index.ts +3 -2
- package/src/ox-input-barcode.ts +56 -20
- package/src/ox-input-duration.ts +143 -0
- package/stories/ox-input-barcode.stories.ts +29 -4
- package/stories/ox-input-duration.stories.ts +51 -0
@@ -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,8 @@ 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' }
|
13
14
|
}
|
14
15
|
}
|
15
16
|
|
@@ -24,15 +25,39 @@ interface ArgTypes {
|
|
24
25
|
value?: string
|
25
26
|
scannable?: boolean
|
26
27
|
withoutEnter?: boolean
|
28
|
+
englishOnly?: boolean
|
27
29
|
}
|
28
30
|
|
29
|
-
const Template: Story<ArgTypes> = ({
|
30
|
-
|
31
|
+
const Template: Story<ArgTypes> = ({
|
32
|
+
name = 'barcode',
|
33
|
+
scannable = true,
|
34
|
+
withoutEnter = true,
|
35
|
+
englishOnly = false
|
36
|
+
}: ArgTypes) => html`
|
37
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
38
|
+
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
39
|
+
<ox-input-barcode
|
40
|
+
name=${name}
|
41
|
+
?without-enter=${withoutEnter}
|
42
|
+
?scannable=${scannable}
|
43
|
+
?english-only=${englishOnly}
|
44
|
+
@change=${(e: CustomEvent) => console.log(e.detail)}
|
45
|
+
>
|
46
|
+
</ox-input-barcode>
|
31
47
|
`
|
32
48
|
|
33
49
|
export const Regular = Template.bind({})
|
34
50
|
Regular.args = {
|
35
51
|
name: 'barcode',
|
36
52
|
scannable: true,
|
37
|
-
withoutEnter: true
|
53
|
+
withoutEnter: true,
|
54
|
+
englishOnly: false
|
55
|
+
}
|
56
|
+
|
57
|
+
export const EnglishOnly = Template.bind({})
|
58
|
+
EnglishOnly.args = {
|
59
|
+
name: 'barcode',
|
60
|
+
scannable: true,
|
61
|
+
withoutEnter: true,
|
62
|
+
englishOnly: true
|
38
63
|
}
|
@@ -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
|
+
}
|