@spectrum-web-components/number-field 0.3.13 → 0.4.1-devmode.7

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.
@@ -1,200 +1,188 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { html } from '@spectrum-web-components/base';
13
- import '../sp-number-field.js';
14
- import '@spectrum-web-components/field-label/sp-field-label.js';
15
- import { spreadProps } from '../../../test/lit-helpers.js';
1
+ import { html } from "@spectrum-web-components/base";
2
+ import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
3
+ import "@spectrum-web-components/number-field/sp-number-field.js";
4
+ import "@spectrum-web-components/field-label/sp-field-label.js";
5
+ import { spreadProps } from "../../../test/lit-helpers.js";
16
6
  export default {
17
- title: 'Number Field',
18
- component: 'sp-number-field',
19
- args: {
20
- disabled: false,
21
- readonly: false,
22
- quiet: false,
23
- value: undefined,
24
- placeholder: '',
25
- min: undefined,
26
- max: undefined,
27
- step: undefined,
7
+ title: "Number Field",
8
+ component: "sp-number-field",
9
+ args: {
10
+ disabled: false,
11
+ readonly: false,
12
+ quiet: false,
13
+ value: void 0,
14
+ placeholder: "",
15
+ min: void 0,
16
+ max: void 0,
17
+ step: void 0
18
+ },
19
+ argTypes: {
20
+ disabled: {
21
+ name: "disabled",
22
+ type: { name: "boolean", required: false },
23
+ description: "Disable this control. It will not receive focus or events.",
24
+ table: {
25
+ type: { summary: "boolean" },
26
+ defaultValue: { summary: false }
27
+ },
28
+ control: {
29
+ type: "boolean"
30
+ }
31
+ },
32
+ indeterminate: {
33
+ name: "indeterminate",
34
+ type: { name: "boolean", required: false },
35
+ description: "Whether the value of the Number Field can be determined for display.",
36
+ table: {
37
+ type: { summary: "boolean" },
38
+ defaultValue: { summary: false }
39
+ },
40
+ control: {
41
+ type: "boolean"
42
+ }
43
+ },
44
+ readonly: {
45
+ name: "readonly",
46
+ type: { name: "boolean", required: false },
47
+ description: "When this control is read only, you will not be able to input an updated value.",
48
+ table: {
49
+ type: { summary: "boolean" },
50
+ defaultValue: { summary: false }
51
+ },
52
+ control: {
53
+ type: "boolean"
54
+ }
55
+ },
56
+ quiet: {
57
+ name: "quiet",
58
+ type: { name: "boolean", required: false },
59
+ description: "An altered delivery with no background and only a bottom border.",
60
+ table: {
61
+ type: { summary: "boolean" },
62
+ defaultValue: { summary: false }
63
+ },
64
+ control: {
65
+ type: "boolean"
66
+ }
67
+ },
68
+ hideStepper: {
69
+ name: "hide stepper",
70
+ type: { name: "boolean", required: false },
71
+ description: "Whether to remove the stepper UI from the control.",
72
+ table: {
73
+ type: { summary: "boolean" },
74
+ defaultValue: { summary: false }
75
+ },
76
+ control: {
77
+ type: "boolean"
78
+ }
79
+ },
80
+ value: {
81
+ name: "value",
82
+ type: { name: "number", required: false },
83
+ description: "Value to apply to the control.",
84
+ table: {
85
+ type: { summary: "string" },
86
+ defaultValue: { summary: void 0 }
87
+ },
88
+ control: {
89
+ type: "number"
90
+ }
91
+ },
92
+ step: {
93
+ name: "step",
94
+ type: { name: "number", required: false },
95
+ description: "Amount to change the value by when using the stepper or arrow key interactions.",
96
+ table: {
97
+ type: { summary: "string" },
98
+ defaultValue: { summary: void 0 }
99
+ },
100
+ control: {
101
+ type: "number"
102
+ }
103
+ },
104
+ stepModifier: {
105
+ name: "step modifier",
106
+ type: { name: "number", required: false },
107
+ description: "Amount to scale the step increment/decrement when holding the shift key",
108
+ table: {
109
+ type: { summary: "number" },
110
+ defaultValue: { summary: 10 }
111
+ },
112
+ control: {
113
+ type: "number"
114
+ }
115
+ },
116
+ placeholder: {
117
+ name: "placeholder",
118
+ type: { name: "string", required: false },
119
+ description: "Placeholder to apply to the control.",
120
+ table: {
121
+ type: { summary: "string" }
122
+ },
123
+ control: {
124
+ type: "text"
125
+ }
28
126
  },
29
- argTypes: {
30
- disabled: {
31
- name: 'disabled',
32
- type: { name: 'boolean', required: false },
33
- description: 'Disable this control. It will not receive focus or events.',
34
- table: {
35
- type: { summary: 'boolean' },
36
- defaultValue: { summary: false },
37
- },
38
- control: {
39
- type: 'boolean',
40
- },
41
- },
42
- indeterminate: {
43
- name: 'indeterminate',
44
- type: { name: 'boolean', required: false },
45
- description: 'Whether the value of the Number Field can be determined for display.',
46
- table: {
47
- type: { summary: 'boolean' },
48
- defaultValue: { summary: false },
49
- },
50
- control: {
51
- type: 'boolean',
52
- },
53
- },
54
- readonly: {
55
- name: 'readonly',
56
- type: { name: 'boolean', required: false },
57
- description: 'When this control is read only, you will not be able to input an updated value.',
58
- table: {
59
- type: { summary: 'boolean' },
60
- defaultValue: { summary: false },
61
- },
62
- control: {
63
- type: 'boolean',
64
- },
65
- },
66
- quiet: {
67
- name: 'quiet',
68
- type: { name: 'boolean', required: false },
69
- description: 'An altered delivery with no background and only a bottom border.',
70
- table: {
71
- type: { summary: 'boolean' },
72
- defaultValue: { summary: false },
73
- },
74
- control: {
75
- type: 'boolean',
76
- },
77
- },
78
- hideStepper: {
79
- name: 'hide stepper',
80
- type: { name: 'boolean', required: false },
81
- description: 'Whether to remove the stepper UI from the control.',
82
- table: {
83
- type: { summary: 'boolean' },
84
- defaultValue: { summary: false },
85
- },
86
- control: {
87
- type: 'boolean',
88
- },
89
- },
90
- value: {
91
- name: 'value',
92
- type: { name: 'number', required: false },
93
- description: 'Value to apply to the control.',
94
- table: {
95
- type: { summary: 'string' },
96
- defaultValue: { summary: undefined },
97
- },
98
- control: {
99
- type: 'number',
100
- },
101
- },
102
- step: {
103
- name: 'step',
104
- type: { name: 'number', required: false },
105
- description: 'Amount to change the value by when using the stepper or arrow key interactions.',
106
- table: {
107
- type: { summary: 'string' },
108
- defaultValue: { summary: undefined },
109
- },
110
- control: {
111
- type: 'number',
112
- },
113
- },
114
- stepModifier: {
115
- name: 'step modifier',
116
- type: { name: 'number', required: false },
117
- description: 'Amount to scale the step increment/decrement when holding the shift key',
118
- table: {
119
- type: { summary: 'number' },
120
- defaultValue: { summary: 10 },
121
- },
122
- control: {
123
- type: 'number',
124
- },
125
- },
126
- placeholder: {
127
- name: 'placeholder',
128
- type: { name: 'string', required: false },
129
- description: 'Placeholder to apply to the control.',
130
- table: {
131
- type: { summary: 'string' },
132
- },
133
- control: {
134
- type: 'text',
135
- },
136
- },
137
- min: {
138
- name: 'min',
139
- type: { name: 'number', required: false },
140
- description: 'The minimum value the control can be set to.',
141
- table: {
142
- type: { summary: 'number' },
143
- defaultValue: { summary: undefined },
144
- },
145
- control: {
146
- type: 'number',
147
- },
148
- },
149
- max: {
150
- name: 'max',
151
- type: { name: 'numer', required: false },
152
- description: 'The maximum value the control can be set to.',
153
- table: {
154
- type: { summary: 'number' },
155
- defaultValue: { summary: undefined },
156
- },
157
- control: {
158
- type: 'number',
159
- },
160
- },
127
+ min: {
128
+ name: "min",
129
+ type: { name: "number", required: false },
130
+ description: "The minimum value the control can be set to.",
131
+ table: {
132
+ type: { summary: "number" },
133
+ defaultValue: { summary: void 0 }
134
+ },
135
+ control: {
136
+ type: "number"
137
+ }
161
138
  },
139
+ max: {
140
+ name: "max",
141
+ type: { name: "numer", required: false },
142
+ description: "The maximum value the control can be set to.",
143
+ table: {
144
+ type: { summary: "number" },
145
+ defaultValue: { summary: void 0 }
146
+ },
147
+ control: {
148
+ type: "number"
149
+ }
150
+ }
151
+ }
162
152
  };
163
153
  export const Default = (args = {}) => {
164
- const onChange = args.onChange ||
165
- (() => {
166
- return;
167
- });
168
- const onInput = args.onInput ||
169
- (() => {
170
- return;
171
- });
172
- return html `
154
+ const onChange = args.onChange || (() => {
155
+ return;
156
+ });
157
+ const onInput = args.onInput || (() => {
158
+ return;
159
+ });
160
+ return html`
173
161
  <sp-field-label for="default">Enter a number</sp-field-label>
174
162
  <sp-number-field
175
163
  id="default"
176
164
  ...=${spreadProps(args)}
177
165
  @input=${(event) => onInput(event.target.value)}
178
166
  @change=${(event) => onChange(event.target.value)}
179
- style="width: 150px"
167
+ style=${ifDefined(args.quiet ? void 0 : "width: 150px")}
180
168
  ></sp-number-field>
181
169
  `;
182
170
  };
183
171
  Default.args = {
184
- value: 100,
172
+ value: 100
185
173
  };
186
174
  export const quiet = (args = {}) => Default(args);
187
175
  quiet.args = {
188
- quiet: true,
189
- value: 100,
176
+ quiet: true,
177
+ value: 100
190
178
  };
191
179
  export const indeterminate = (args = {}) => Default(args);
192
180
  indeterminate.args = {
193
- value: 100,
194
- indeterminate: true,
181
+ value: 100,
182
+ indeterminate: true
195
183
  };
196
184
  export const decimals = (args) => {
197
- return html `
185
+ return html`
198
186
  <sp-field-label for="decimals">
199
187
  Enter a number with visible decimals
200
188
  </sp-field-label>
@@ -204,18 +192,18 @@ export const decimals = (args) => {
204
192
  ...=${spreadProps(args)}
205
193
  @change=${args.onChange}
206
194
  .formatOptions=${{
207
- signDisplay: 'exceptZero',
208
- minimumFractionDigits: 1,
209
- maximumFractionDigits: 2,
210
- }}
195
+ signDisplay: "exceptZero",
196
+ minimumFractionDigits: 1,
197
+ maximumFractionDigits: 2
198
+ }}
211
199
  ></sp-number-field>
212
200
  `;
213
201
  };
214
202
  decimals.args = {
215
- value: 19.274,
203
+ value: 19.274
216
204
  };
217
205
  export const percents = (args = {}) => {
218
- return html `
206
+ return html`
219
207
  <sp-field-label for="percents">Enter a percentage</sp-field-label>
220
208
  <sp-number-field
221
209
  id="percents"
@@ -223,36 +211,36 @@ export const percents = (args = {}) => {
223
211
  ...=${spreadProps(args)}
224
212
  @change=${args.onChange}
225
213
  .formatOptions=${{
226
- style: 'percent',
227
- unitDisplay: 'narrow',
228
- }}
214
+ style: "percent",
215
+ unitDisplay: "narrow"
216
+ }}
229
217
  ></sp-number-field>
230
218
  `;
231
219
  };
232
220
  percents.args = {
233
- value: 0.372,
221
+ value: 0.372
234
222
  };
235
223
  export const currency = (args = {}) => {
236
- return html `
224
+ return html`
237
225
  <sp-field-label for="currency">Enter a value in Euros</sp-field-label>
238
226
  <sp-number-field
239
227
  style="width: 200px"
240
228
  ...=${spreadProps(args)}
241
229
  @change=${args.onChange}
242
230
  .formatOptions=${{
243
- style: 'currency',
244
- currency: 'EUR',
245
- currencyDisplay: 'code',
246
- currencySign: 'accounting',
247
- }}
231
+ style: "currency",
232
+ currency: "EUR",
233
+ currencyDisplay: "code",
234
+ currencySign: "accounting"
235
+ }}
248
236
  ></sp-number-field>
249
237
  `;
250
238
  };
251
239
  currency.args = {
252
- value: 23.19,
240
+ value: 23.19
253
241
  };
254
242
  export const units = (args) => {
255
- return html `
243
+ return html`
256
244
  <sp-field-label for="units">Enter a lengths in inches</sp-field-label>
257
245
  <sp-number-field
258
246
  id="units"
@@ -260,35 +248,35 @@ export const units = (args) => {
260
248
  ...=${spreadProps(args)}
261
249
  @change=${args.onChange}
262
250
  .formatOptions=${{
263
- style: 'unit',
264
- unit: 'inch',
265
- unitDisplay: 'long',
266
- }}
251
+ style: "unit",
252
+ unit: "inch",
253
+ unitDisplay: "long"
254
+ }}
267
255
  ></sp-number-field>
268
256
  `;
269
257
  };
270
258
  units.args = {
271
- value: 24,
259
+ value: 24
272
260
  };
273
261
  export const pixels = (args) => {
274
- return html `
262
+ return html`
275
263
  <sp-field-label for="units">Enter a lengths in pixels</sp-field-label>
276
264
  <sp-number-field
277
265
  id="units"
278
266
  style="width: 200px"
279
267
  .formatOptions=${{
280
- style: 'unit',
281
- unit: 'px',
282
- }}
268
+ style: "unit",
269
+ unit: "px"
270
+ }}
283
271
  ...=${spreadProps(args)}
284
272
  @change=${args.onChange}
285
273
  ></sp-number-field>
286
274
  `;
287
275
  };
288
276
  pixels.args = {
289
- value: 800,
277
+ value: 800
290
278
  };
291
- export const minMax = (args) => html `
279
+ export const minMax = (args) => html`
292
280
  <sp-field-label for="min-max">
293
281
  Enter a value between 0 and 255
294
282
  </sp-field-label>
@@ -300,12 +288,12 @@ export const minMax = (args) => html `
300
288
  ></sp-number-field>
301
289
  `;
302
290
  minMax.args = {
303
- value: 4,
304
- min: 0,
305
- max: 255,
291
+ value: 4,
292
+ min: 0,
293
+ max: 255
306
294
  };
307
295
  export const hideStepper = (args) => {
308
- return html `
296
+ return html`
309
297
  <sp-field-label for="hideStepper">
310
298
  Enter a number without the stepper UI
311
299
  </sp-field-label>
@@ -317,11 +305,11 @@ export const hideStepper = (args) => {
317
305
  `;
318
306
  };
319
307
  hideStepper.args = {
320
- hideStepper: true,
321
- value: 67,
308
+ hideStepper: true,
309
+ value: 67
322
310
  };
323
311
  export const hideStepperQuiet = (args) => {
324
- return html `
312
+ return html`
325
313
  <sp-field-label for="hideStepper">
326
314
  Enter a number without the stepper UI
327
315
  </sp-field-label>
@@ -333,12 +321,12 @@ export const hideStepperQuiet = (args) => {
333
321
  `;
334
322
  };
335
323
  hideStepperQuiet.args = {
336
- hideStepper: true,
337
- value: 67,
338
- quiet: true,
324
+ hideStepper: true,
325
+ value: 67,
326
+ quiet: true
339
327
  };
340
328
  export const disabled = (args) => {
341
- return html `
329
+ return html`
342
330
  <sp-field-label for="disabled">
343
331
  This Number Field is disabled
344
332
  </sp-field-label>
@@ -350,11 +338,11 @@ export const disabled = (args) => {
350
338
  `;
351
339
  };
352
340
  disabled.args = {
353
- disabled: true,
354
- value: 892,
341
+ disabled: true,
342
+ value: 892
355
343
  };
356
344
  export const readOnly = (args) => {
357
- return html `
345
+ return html`
358
346
  <sp-field-label for="readonly">
359
347
  You can only read the following value
360
348
  </sp-field-label>
@@ -366,19 +354,17 @@ export const readOnly = (args) => {
366
354
  `;
367
355
  };
368
356
  readOnly.args = {
369
- readonly: true,
370
- value: '15',
357
+ readonly: true,
358
+ value: "15"
371
359
  };
372
360
  export const ScrollingContainer = (args = {}) => {
373
- const onChange = args.onChange ||
374
- (() => {
375
- return;
376
- });
377
- const onInput = args.onInput ||
378
- (() => {
379
- return;
380
- });
381
- return html `
361
+ const onChange = args.onChange || (() => {
362
+ return;
363
+ });
364
+ const onInput = args.onInput || (() => {
365
+ return;
366
+ });
367
+ return html`
382
368
  <style>
383
369
  .scroller {
384
370
  height: 140px;
@@ -411,4 +397,4 @@ export const ScrollingContainer = (args = {}) => {
411
397
  </div>
412
398
  `;
413
399
  };
414
- //# sourceMappingURL=number-field.stories.js.map
400
+ //# sourceMappingURL=number-field.stories.js.map