@operato/input 1.5.19 → 1.5.23

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.
@@ -86,7 +86,7 @@ export class OxInputDuration extends OxFormField {
86
86
  }
87
87
  `
88
88
 
89
- @property({ type: Number }) declare value?: number
89
+ @property({ type: Number }) value?: number
90
90
 
91
91
  render() {
92
92
  var d = Number(this.value || 0)
@@ -100,16 +100,16 @@ export class OxInputDuration extends OxFormField {
100
100
 
101
101
  return html`
102
102
  <form @change=${this.onChange.bind(this)}>
103
- <input id="days" type="number" .value=${days} pattern="\\d*" />
103
+ <input id="days" type="number" .value=${String(days || 0)} pattern="\\d*" />
104
104
  <label for="days">${i18next.t('label.days')}</label>
105
105
 
106
- <input id="hours" type="number" .value=${hours} pattern="[01]?\\d|2[0-3]" />
106
+ <input id="hours" type="number" .value=${String(hours || 0)} pattern="[01]?\\d|2[0-3]" />
107
107
  <label for="hour">${i18next.t('label.hours')}</label>
108
108
 
109
- <input id="minutes" type="number" .value=${minutes} pattern="[0-5]?\\d" />
109
+ <input id="minutes" type="number" .value=${String(minutes || 0)} pattern="[0-5]?\\d" />
110
110
  <label for="minute">${i18next.t('label.minutes')}</label>
111
111
 
112
- <input id="seconds" type="number" .value=${seconds} pattern="[0-5]?\\d" />
112
+ <input id="seconds" type="number" .value=${String(seconds || 0)} pattern="[0-5]?\\d" />
113
113
  <label for="second">${i18next.t('label.seconds')}</label>
114
114
 
115
115
  <button
@@ -0,0 +1,222 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import '@material/mwc-button'
6
+
7
+ import { css, html } from 'lit'
8
+ import { customElement, property, query } from 'lit/decorators.js'
9
+ import { ifDefined } from 'lit/directives/if-defined.js'
10
+
11
+ import { i18next } from '@operato/i18n'
12
+
13
+ import { OxFormField } from './ox-form-field'
14
+
15
+ @customElement('ox-input-permission')
16
+ export class OxInputPermission extends OxFormField {
17
+ static styles = css`
18
+ :host {
19
+ text-align: center;
20
+ padding: 10px;
21
+ }
22
+
23
+ :host * {
24
+ box-sizing: border-box;
25
+ }
26
+
27
+ :host *:focus {
28
+ outline: none;
29
+ }
30
+
31
+ form {
32
+ display: flex;
33
+ flex-direction: column;
34
+
35
+ width: 100%;
36
+ height: 100%;
37
+ }
38
+
39
+ div[values] {
40
+ flex: 1;
41
+ display: grid;
42
+ grid-template-columns: 1fr 1fr;
43
+ grid-gap: 10px;
44
+ }
45
+
46
+ div[values] > [col1] {
47
+ text-align: right;
48
+ }
49
+
50
+ div[values] > [col2] {
51
+ text-align: left;
52
+ margin-right: auto;
53
+ }
54
+
55
+ input {
56
+ border: 0;
57
+ border-bottom: var(--border-dark-color);
58
+ padding: var(--input-padding);
59
+ padding-right: 0;
60
+ max-width: 70px;
61
+ font: var(--input-font);
62
+ color: var(--primary-text-color);
63
+ text-align: right;
64
+ }
65
+
66
+ input:focus {
67
+ outline: none;
68
+ border-bottom: 1px solid var(--primary-color);
69
+ }
70
+
71
+ input:invalid {
72
+ border-bottom: 1px solid var(--status-danger-color);
73
+ color: var(--status-danger-color);
74
+ }
75
+
76
+ label {
77
+ margin-right: var(--margin-default);
78
+ font: normal 0.8em var(--theme-font);
79
+ color: var(--primary-color);
80
+ }
81
+
82
+ div[buttons] {
83
+ display: flex;
84
+ flex-direction: row;
85
+ justify-content: center;
86
+ padding: 10px;
87
+ gap: 10px;
88
+ }
89
+
90
+ button {
91
+ border: var(--button-border);
92
+ border-radius: var(--border-radius);
93
+ background-color: var(--button-background-color);
94
+ padding: var(--padding-narrow) var(--padding-default);
95
+ min-height: 35px;
96
+ line-height: 0.8;
97
+ color: var(--button-color);
98
+ cursor: pointer;
99
+ }
100
+ button:focus,
101
+ button:hover,
102
+ button:active {
103
+ border: var(--button-activ-border);
104
+ background-color: var(--button-background-focus-color);
105
+ color: var(--theme-white-color);
106
+ }
107
+ `
108
+
109
+ @property({ type: Object }) value?: {
110
+ category: string
111
+ privilege: string
112
+ owner: boolean
113
+ super: boolean
114
+ } | null
115
+
116
+ @property({ type: Array }) privileges: { name: string; category: string; description: string }[] = []
117
+
118
+ @query('form') private form!: HTMLFormElement
119
+
120
+ render() {
121
+ const { category, privilege, owner, super: superUser } = this.value || {}
122
+ const privileges = this.privileges || []
123
+
124
+ return html`
125
+ <form @change=${this.onChange.bind(this)}>
126
+ <div values>
127
+ <label for="privilege" col1>${i18next.t('label.privilege')}</label>
128
+ <select id="privilege" name="privilege" value=${ifDefined(privilege)}>
129
+ <option value="">&nbsp;</option>
130
+ ${privileges.map(
131
+ p =>
132
+ html`<option
133
+ value=${`${p.category}-${p.name}`}
134
+ ?selected=${category == p.category && privilege == p.name}
135
+ >
136
+ ${p.description}
137
+ </option>`
138
+ )}
139
+ </select>
140
+
141
+ <label for="owner" col1>${i18next.t('label.domain-owner')}</label>
142
+ <input id="owner" type="checkbox" name="owner" ?checked=${owner} col2></input>
143
+
144
+ <label for="super" col1>${i18next.t('label.superuser')}</label>
145
+ <input id="super" type="checkbox" name="super" ?checked=${superUser} col2></input>
146
+ </div>
147
+
148
+ <div buttons>
149
+ <button
150
+ type="button"
151
+ @click=${(e: Event) => {
152
+ this.value = null
153
+
154
+ this.dispatchEvent(
155
+ new CustomEvent('change', {
156
+ bubbles: true,
157
+ composed: true,
158
+ detail: this.value
159
+ })
160
+ )
161
+ }}
162
+ >
163
+ reset
164
+ </button>
165
+
166
+ <button
167
+ type="button"
168
+ @click=${(e: Event) => {
169
+ e.preventDefault()
170
+ e.stopPropagation()
171
+
172
+ this.value = this.buildValue()
173
+
174
+ this.dispatchEvent(
175
+ new CustomEvent('change', {
176
+ bubbles: true,
177
+ composed: true,
178
+ detail: this.value
179
+ })
180
+ )
181
+ }}
182
+ >
183
+ OK
184
+ </button>
185
+ </div>
186
+ </form>
187
+ `
188
+ }
189
+
190
+ buildValue() {
191
+ const formData = new FormData(this.form)
192
+
193
+ const [category, privilege] = (formData.get('privilege') as string).split('-')
194
+ const owner = formData.get('owner') as string
195
+ const superUser = formData.get('super') as string
196
+
197
+ return {
198
+ category,
199
+ privilege,
200
+ owner: owner == 'on',
201
+ super: superUser == 'on'
202
+ }
203
+ }
204
+
205
+ firstUpdated() {
206
+ ;(this.renderRoot.querySelector('input') as HTMLInputElement).focus()
207
+ }
208
+
209
+ onChange(e: Event) {
210
+ e.stopPropagation()
211
+
212
+ this.value = this.buildValue()
213
+
214
+ this.dispatchEvent(
215
+ new CustomEvent('change', {
216
+ bubbles: true,
217
+ composed: true,
218
+ detail: this.value
219
+ })
220
+ )
221
+ }
222
+ }
@@ -65,8 +65,10 @@ export class OxInputTextarea extends OxFormField {
65
65
  this.textarea.style.height = this.textarea.scrollHeight + 'px'
66
66
  }
67
67
 
68
- onKeydown(e: Event) {
69
- e.stopPropagation()
68
+ onKeydown(e: KeyboardEvent) {
69
+ if (e.key === 'Enter') {
70
+ e.stopPropagation()
71
+ }
70
72
  }
71
73
 
72
74
  onChange(e: Event) {
@@ -0,0 +1,75 @@
1
+ import '../src/ox-input-permission.js'
2
+ import '../src/locale/locale-picker.js'
3
+
4
+ import { html, TemplateResult } from 'lit'
5
+
6
+ export default {
7
+ title: 'ox-input-permission',
8
+ component: 'ox-input-permission',
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
+ privileges: { name: string; category: string; description: string }[]
24
+ value?: {
25
+ privilege: string
26
+ category: string
27
+ owner: boolean
28
+ super: boolean
29
+ } | null
30
+ }
31
+
32
+ const Template: Story<ArgTypes> = ({ name = 'permission', value = null, privileges }: ArgTypes) => html`
33
+ <link href="/themes/app-theme.css" rel="stylesheet" />
34
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
35
+ <style>
36
+ body {
37
+ }
38
+ </style>
39
+
40
+ <locale-picker></locale-picker>
41
+ <br /><br />
42
+
43
+ <ox-input-permission
44
+ @change=${(e: Event) => {
45
+ console.log((e.target as HTMLInputElement).value)
46
+ }}
47
+ name=${name}
48
+ .value=${value}
49
+ .privileges=${privileges}
50
+ >
51
+ </ox-input-permission>
52
+ `
53
+
54
+ export const Regular = Template.bind({})
55
+ Regular.args = {
56
+ name: 'permission',
57
+ privileges: [
58
+ {
59
+ name: 'query',
60
+ category: 'aaa',
61
+ description: 'readable aaa'
62
+ },
63
+ {
64
+ name: 'mutation',
65
+ category: 'aaa',
66
+ description: 'writable aaa'
67
+ }
68
+ ],
69
+ value: {
70
+ privilege: 'mutation',
71
+ category: 'aaa',
72
+ owner: true,
73
+ super: true
74
+ }
75
+ }