@operato/input 1.5.22 → 1.5.24

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,180 @@
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
+ width: 100%;
33
+ height: 100%;
34
+ }
35
+
36
+ div[values] {
37
+ display: grid;
38
+ grid-template-columns: 1fr 1fr;
39
+ grid-gap: 10px;
40
+ }
41
+
42
+ div[values] > [col1] {
43
+ text-align: right;
44
+ align-self: center;
45
+ }
46
+
47
+ div[values] > [col2] {
48
+ text-align: left;
49
+ align-self: center;
50
+ margin-right: auto;
51
+ }
52
+
53
+ input {
54
+ border: 0;
55
+ border-bottom: var(--border-dark-color);
56
+ padding: var(--input-padding);
57
+ padding-right: 0;
58
+ max-width: 70px;
59
+ font: var(--input-font);
60
+ color: var(--primary-text-color);
61
+ text-align: right;
62
+ }
63
+
64
+ input:focus {
65
+ outline: none;
66
+ border-bottom: 1px solid var(--primary-color);
67
+ }
68
+
69
+ input:invalid {
70
+ border-bottom: 1px solid var(--status-danger-color);
71
+ color: var(--status-danger-color);
72
+ }
73
+
74
+ label {
75
+ margin-right: var(--margin-default);
76
+ font: normal 0.8em var(--theme-font);
77
+ color: var(--primary-color);
78
+ }
79
+
80
+ div[buttons] {
81
+ display: flex;
82
+ flex-direction: row;
83
+ justify-content: left;
84
+ padding: 10px;
85
+ }
86
+
87
+ button {
88
+ border: var(--button-border);
89
+ border-radius: var(--border-radius);
90
+ background-color: var(--button-background-color);
91
+ padding: var(--padding-narrow) var(--padding-default);
92
+ min-height: 35px;
93
+ line-height: 0.8;
94
+ color: var(--button-color);
95
+ cursor: pointer;
96
+ }
97
+ button:focus,
98
+ button:hover,
99
+ button:active {
100
+ border: var(--button-activ-border);
101
+ background-color: var(--button-background-focus-color);
102
+ color: var(--theme-white-color);
103
+ }
104
+ `
105
+
106
+ @property({ type: Object }) value?: {
107
+ category: string
108
+ privilege: string
109
+ owner: boolean
110
+ super: boolean
111
+ } | null
112
+
113
+ @property({ type: Array }) privileges: { name: string; category: string; description: string }[] = []
114
+
115
+ @query('form') private form!: HTMLFormElement
116
+
117
+ render() {
118
+ const { category, privilege, owner, super: superUser } = this.value || {}
119
+ const privileges = this.privileges || []
120
+
121
+ return html`
122
+ <form @change=${this.onChange.bind(this)}>
123
+ <div values>
124
+ <label for="privilege" col1>${i18next.t('label.privilege')}</label>
125
+ <select id="privilege" name="privilege" value=${ifDefined(privilege)}>
126
+ <option value="">&nbsp;</option>
127
+ ${privileges.map(
128
+ p =>
129
+ html`<option
130
+ value=${`${p.category}-${p.name}`}
131
+ ?selected=${category == p.category && privilege == p.name}
132
+ >
133
+ ${p.description}
134
+ </option>`
135
+ )}
136
+ </select>
137
+
138
+ <label for="owner" col1>${i18next.t('label.domain-owner')}</label>
139
+ <input id="owner" type="checkbox" name="owner" ?checked=${owner} col2></input>
140
+
141
+ <label for="super" col1>${i18next.t('label.superuser')}</label>
142
+ <input id="super" type="checkbox" name="super" ?checked=${superUser} col2></input>
143
+ </div>
144
+ </form>
145
+ `
146
+ }
147
+
148
+ buildValue() {
149
+ const formData = new FormData(this.form)
150
+
151
+ const [category = '', privilege = ''] = (formData.get('privilege') as string).split('-')
152
+ const owner = formData.get('owner') as string
153
+ const superUser = formData.get('super') as string
154
+
155
+ return {
156
+ category,
157
+ privilege,
158
+ owner: owner == 'on',
159
+ super: superUser == 'on'
160
+ }
161
+ }
162
+
163
+ firstUpdated() {
164
+ ;(this.renderRoot.querySelector('input') as HTMLInputElement).focus()
165
+ }
166
+
167
+ onChange(e: Event) {
168
+ e.stopPropagation()
169
+
170
+ this.value = this.buildValue()
171
+
172
+ this.dispatchEvent(
173
+ new CustomEvent('change', {
174
+ bubbles: true,
175
+ composed: true,
176
+ detail: this.value
177
+ })
178
+ )
179
+ }
180
+ }
@@ -0,0 +1,80 @@
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
+
39
+ ox-input-permission {
40
+ width: 100%;
41
+ min-height: 500px;
42
+ }
43
+ </style>
44
+
45
+ <locale-picker></locale-picker>
46
+ <br /><br />
47
+
48
+ <ox-input-permission
49
+ @change=${(e: Event) => {
50
+ console.log((e.target as HTMLInputElement).value)
51
+ }}
52
+ name=${name}
53
+ .value=${value}
54
+ .privileges=${privileges}
55
+ >
56
+ </ox-input-permission>
57
+ `
58
+
59
+ export const Regular = Template.bind({})
60
+ Regular.args = {
61
+ name: 'permission',
62
+ privileges: [
63
+ {
64
+ name: 'query',
65
+ category: 'aaa',
66
+ description: 'readable aaa'
67
+ },
68
+ {
69
+ name: 'mutation',
70
+ category: 'aaa',
71
+ description: 'writable aaa'
72
+ }
73
+ ],
74
+ value: {
75
+ privilege: 'mutation',
76
+ category: 'aaa',
77
+ owner: true,
78
+ super: true
79
+ }
80
+ }