@spectrum-web-components/number-field 0.3.6 → 0.3.9

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,372 @@
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';
16
+ 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,
28
+ },
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
+ },
161
+ },
162
+ };
163
+ 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 `
173
+ <sp-field-label for="default">Enter a number</sp-field-label>
174
+ <sp-number-field
175
+ id="default"
176
+ ...=${spreadProps(args)}
177
+ @input=${(event) => onInput(event.target.value)}
178
+ @change=${(event) => onChange(event.target.value)}
179
+ style="width: 150px"
180
+ ></sp-number-field>
181
+ `;
182
+ };
183
+ Default.args = {
184
+ value: 100,
185
+ };
186
+ export const quiet = (args = {}) => Default(args);
187
+ quiet.args = {
188
+ quiet: true,
189
+ value: 100,
190
+ };
191
+ export const indeterminate = (args = {}) => Default(args);
192
+ indeterminate.args = {
193
+ value: 100,
194
+ indeterminate: true,
195
+ };
196
+ export const decimals = (args) => {
197
+ return html `
198
+ <sp-field-label for="decimals">
199
+ Enter a number with visible decimals
200
+ </sp-field-label>
201
+ <sp-number-field
202
+ id="decimals"
203
+ style="width: 200px"
204
+ ...=${spreadProps(args)}
205
+ @change=${args.onChange}
206
+ .formatOptions=${{
207
+ signDisplay: 'exceptZero',
208
+ minimumFractionDigits: 1,
209
+ maximumFractionDigits: 2,
210
+ }}
211
+ ></sp-number-field>
212
+ `;
213
+ };
214
+ decimals.args = {
215
+ value: 19.274,
216
+ };
217
+ export const percents = (args = {}) => {
218
+ return html `
219
+ <sp-field-label for="percents">Enter a percentage</sp-field-label>
220
+ <sp-number-field
221
+ id="percents"
222
+ style="width: 200px"
223
+ ...=${spreadProps(args)}
224
+ @change=${args.onChange}
225
+ .formatOptions=${{
226
+ style: 'percent',
227
+ unitDisplay: 'narrow',
228
+ }}
229
+ ></sp-number-field>
230
+ `;
231
+ };
232
+ percents.args = {
233
+ value: 0.372,
234
+ };
235
+ export const currency = (args = {}) => {
236
+ return html `
237
+ <sp-field-label for="currency">Enter a value in Euros</sp-field-label>
238
+ <sp-number-field
239
+ style="width: 200px"
240
+ ...=${spreadProps(args)}
241
+ @change=${args.onChange}
242
+ .formatOptions=${{
243
+ style: 'currency',
244
+ currency: 'EUR',
245
+ currencyDisplay: 'code',
246
+ currencySign: 'accounting',
247
+ }}
248
+ ></sp-number-field>
249
+ `;
250
+ };
251
+ currency.args = {
252
+ value: 23.19,
253
+ };
254
+ export const units = (args) => {
255
+ return html `
256
+ <sp-field-label for="units">Enter a lengths in inches</sp-field-label>
257
+ <sp-number-field
258
+ id="units"
259
+ style="width: 200px"
260
+ ...=${spreadProps(args)}
261
+ @change=${args.onChange}
262
+ .formatOptions=${{
263
+ style: 'unit',
264
+ unit: 'inch',
265
+ unitDisplay: 'long',
266
+ }}
267
+ ></sp-number-field>
268
+ `;
269
+ };
270
+ units.args = {
271
+ value: 24,
272
+ };
273
+ export const pixels = (args) => {
274
+ return html `
275
+ <sp-field-label for="units">Enter a lengths in pixels</sp-field-label>
276
+ <sp-number-field
277
+ id="units"
278
+ style="width: 200px"
279
+ .formatOptions=${{
280
+ style: 'unit',
281
+ unit: 'px',
282
+ }}
283
+ ...=${spreadProps(args)}
284
+ @change=${args.onChange}
285
+ ></sp-number-field>
286
+ `;
287
+ };
288
+ pixels.args = {
289
+ value: 800,
290
+ };
291
+ export const minMax = (args) => html `
292
+ <sp-field-label for="min-max">
293
+ Enter a value between 0 and 255
294
+ </sp-field-label>
295
+ <sp-number-field
296
+ id="min-max"
297
+ style="width: 200px"
298
+ ...=${spreadProps(args)}
299
+ @change=${args.onChange}
300
+ ></sp-number-field>
301
+ `;
302
+ minMax.args = {
303
+ value: 4,
304
+ min: 0,
305
+ max: 255,
306
+ };
307
+ export const hideStepper = (args) => {
308
+ return html `
309
+ <sp-field-label for="hideStepper">
310
+ Enter a number without the stepper UI
311
+ </sp-field-label>
312
+ <sp-number-field
313
+ id="hideStepper"
314
+ ...=${spreadProps(args)}
315
+ @change=${args.onChange}
316
+ ></sp-number-field>
317
+ `;
318
+ };
319
+ hideStepper.args = {
320
+ hideStepper: true,
321
+ value: 67,
322
+ };
323
+ export const hideStepperQuiet = (args) => {
324
+ return html `
325
+ <sp-field-label for="hideStepper">
326
+ Enter a number without the stepper UI
327
+ </sp-field-label>
328
+ <sp-number-field
329
+ id="hideStepper"
330
+ ...=${spreadProps(args)}
331
+ @change=${args.onChange}
332
+ ></sp-number-field>
333
+ `;
334
+ };
335
+ hideStepperQuiet.args = {
336
+ hideStepper: true,
337
+ value: 67,
338
+ quiet: true,
339
+ };
340
+ export const disabled = (args) => {
341
+ return html `
342
+ <sp-field-label for="disabled">
343
+ This Number Field is disabled
344
+ </sp-field-label>
345
+ <sp-number-field
346
+ id="disabled"
347
+ ...=${spreadProps(args)}
348
+ @change=${args.onChange}
349
+ ></sp-number-field>
350
+ `;
351
+ };
352
+ disabled.args = {
353
+ disabled: true,
354
+ value: 892,
355
+ };
356
+ export const readOnly = (args) => {
357
+ return html `
358
+ <sp-field-label for="readonly">
359
+ You can only read the following value
360
+ </sp-field-label>
361
+ <sp-number-field
362
+ id="readonly"
363
+ ...=${spreadProps(args)}
364
+ @change=${args.onChange}
365
+ ></sp-number-field>
366
+ `;
367
+ };
368
+ readOnly.args = {
369
+ readonly: true,
370
+ value: '15',
371
+ };
372
+ //# sourceMappingURL=number-field.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-field.stories.js","sourceRoot":"","sources":["number-field.stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AAErE,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wDAAwD,CAAC;AAChE,OAAO,EAAE,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AACN,CAAC,CAAC;AACF,QAAQ,CAAC,IAAI,GAAG;IACZ,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,GAAG;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAe,EAAkB,EAAE;IACxD,OAAO,IAAI,CAAA;;;;;;kBAMG,WAAW,CAAC,IAAI,CAAC;sBACb,IAAI,CAAC,QAAQ;;KAE9B,CAAC;AACN,CAAC,CAAC;AACF,QAAQ,CAAC,IAAI,GAAG;IACZ,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;CACd,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\n\nimport '../sp-number-field.js';\nimport '@spectrum-web-components/field-label/sp-field-label.js';\nimport { spreadProps } from '../../../test/lit-helpers.js';\nimport { NumberField } from '../src/NumberField.js';\n\nexport default {\n title: 'Number Field',\n component: 'sp-number-field',\n args: {\n disabled: false,\n readonly: false,\n quiet: false,\n value: undefined,\n placeholder: '',\n min: undefined,\n max: undefined,\n step: undefined,\n },\n argTypes: {\n disabled: {\n name: 'disabled',\n type: { name: 'boolean', required: false },\n description:\n 'Disable this control. It will not receive focus or events.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n indeterminate: {\n name: 'indeterminate',\n type: { name: 'boolean', required: false },\n description:\n 'Whether the value of the Number Field can be determined for display.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n readonly: {\n name: 'readonly',\n type: { name: 'boolean', required: false },\n description:\n 'When this control is read only, you will not be able to input an updated value.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n quiet: {\n name: 'quiet',\n type: { name: 'boolean', required: false },\n description:\n 'An altered delivery with no background and only a bottom border.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n hideStepper: {\n name: 'hide stepper',\n type: { name: 'boolean', required: false },\n description: 'Whether to remove the stepper UI from the control.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n value: {\n name: 'value',\n type: { name: 'number', required: false },\n description: 'Value to apply to the control.',\n table: {\n type: { summary: 'string' },\n defaultValue: { summary: undefined },\n },\n control: {\n type: 'number',\n },\n },\n step: {\n name: 'step',\n type: { name: 'number', required: false },\n description:\n 'Amount to change the value by when using the stepper or arrow key interactions.',\n table: {\n type: { summary: 'string' },\n defaultValue: { summary: undefined },\n },\n control: {\n type: 'number',\n },\n },\n stepModifier: {\n name: 'step modifier',\n type: { name: 'number', required: false },\n description:\n 'Amount to scale the step increment/decrement when holding the shift key',\n table: {\n type: { summary: 'number' },\n defaultValue: { summary: 10 },\n },\n control: {\n type: 'number',\n },\n },\n placeholder: {\n name: 'placeholder',\n type: { name: 'string', required: false },\n description: 'Placeholder to apply to the control.',\n table: {\n type: { summary: 'string' },\n },\n control: {\n type: 'text',\n },\n },\n min: {\n name: 'min',\n type: { name: 'number', required: false },\n description: 'The minimum value the control can be set to.',\n table: {\n type: { summary: 'number' },\n defaultValue: { summary: undefined },\n },\n control: {\n type: 'number',\n },\n },\n max: {\n name: 'max',\n type: { name: 'numer', required: false },\n description: 'The maximum value the control can be set to.',\n table: {\n type: { summary: 'number' },\n defaultValue: { summary: undefined },\n },\n control: {\n type: 'number',\n },\n },\n },\n};\n\ninterface StoryArgs {\n disabled?: boolean;\n indeterminate?: boolean;\n invalid?: boolean;\n value?: number;\n placeholder?: string;\n max?: number;\n min?: number;\n hideStepper?: boolean;\n readonly?: boolean;\n step?: number;\n onChange?: (value: number) => void;\n onInput?: (value: number) => void;\n [prop: string]: unknown;\n}\n\nexport const Default = (args: StoryArgs = {}): TemplateResult => {\n const onChange =\n (args.onChange as (value: number) => void) ||\n (() => {\n return;\n });\n const onInput =\n (args.onInput as (value: number) => void) ||\n (() => {\n return;\n });\n return html`\n <sp-field-label for=\"default\">Enter a number</sp-field-label>\n <sp-number-field\n id=\"default\"\n ...=${spreadProps(args)}\n @input=${(event: Event) =>\n onInput((event.target as NumberField).value)}\n @change=${(event: Event) =>\n onChange((event.target as NumberField).value)}\n style=\"width: 150px\"\n ></sp-number-field>\n `;\n};\n\nDefault.args = {\n value: 100,\n};\n\nexport const quiet = (args: StoryArgs = {}): TemplateResult => Default(args);\n\nquiet.args = {\n quiet: true,\n value: 100,\n};\n\nexport const indeterminate = (args: StoryArgs = {}): TemplateResult =>\n Default(args);\n\nindeterminate.args = {\n value: 100,\n indeterminate: true,\n};\n\nexport const decimals = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"decimals\">\n Enter a number with visible decimals\n </sp-field-label>\n <sp-number-field\n id=\"decimals\"\n style=\"width: 200px\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n .formatOptions=${{\n signDisplay: 'exceptZero',\n minimumFractionDigits: 1,\n maximumFractionDigits: 2,\n } as unknown as Intl.NumberFormatOptions}\n ></sp-number-field>\n `;\n};\n\ndecimals.args = {\n value: 19.274,\n};\n\nexport const percents = (args: StoryArgs = {}): TemplateResult => {\n return html`\n <sp-field-label for=\"percents\">Enter a percentage</sp-field-label>\n <sp-number-field\n id=\"percents\"\n style=\"width: 200px\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n .formatOptions=${{\n style: 'percent',\n unitDisplay: 'narrow',\n } as unknown as Intl.NumberFormatOptions}\n ></sp-number-field>\n `;\n};\n\npercents.args = {\n value: 0.372,\n};\n\nexport const currency = (args: StoryArgs = {}): TemplateResult => {\n return html`\n <sp-field-label for=\"currency\">Enter a value in Euros</sp-field-label>\n <sp-number-field\n style=\"width: 200px\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n .formatOptions=${{\n style: 'currency',\n currency: 'EUR',\n currencyDisplay: 'code',\n currencySign: 'accounting',\n } as unknown as Intl.NumberFormatOptions}\n ></sp-number-field>\n `;\n};\n\ncurrency.args = {\n value: 23.19,\n};\n\nexport const units = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"units\">Enter a lengths in inches</sp-field-label>\n <sp-number-field\n id=\"units\"\n style=\"width: 200px\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n .formatOptions=${{\n style: 'unit',\n unit: 'inch',\n unitDisplay: 'long',\n } as unknown as Intl.NumberFormatOptions}\n ></sp-number-field>\n `;\n};\n\nunits.args = {\n value: 24,\n};\n\nexport const pixels = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"units\">Enter a lengths in pixels</sp-field-label>\n <sp-number-field\n id=\"units\"\n style=\"width: 200px\"\n .formatOptions=${{\n style: 'unit',\n unit: 'px',\n }}\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n `;\n};\n\npixels.args = {\n value: 800,\n};\n\nexport const minMax = (args: StoryArgs): TemplateResult => html`\n <sp-field-label for=\"min-max\">\n Enter a value between 0 and 255\n </sp-field-label>\n <sp-number-field\n id=\"min-max\"\n style=\"width: 200px\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n`;\n\nminMax.args = {\n value: 4,\n min: 0,\n max: 255,\n};\n\nexport const hideStepper = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"hideStepper\">\n Enter a number without the stepper UI\n </sp-field-label>\n <sp-number-field\n id=\"hideStepper\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n `;\n};\nhideStepper.args = {\n hideStepper: true,\n value: 67,\n};\n\nexport const hideStepperQuiet = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"hideStepper\">\n Enter a number without the stepper UI\n </sp-field-label>\n <sp-number-field\n id=\"hideStepper\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n `;\n};\nhideStepperQuiet.args = {\n hideStepper: true,\n value: 67,\n quiet: true,\n};\n\nexport const disabled = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"disabled\">\n This Number Field is disabled\n </sp-field-label>\n <sp-number-field\n id=\"disabled\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n `;\n};\ndisabled.args = {\n disabled: true,\n value: 892,\n};\n\nexport const readOnly = (args: StoryArgs): TemplateResult => {\n return html`\n <sp-field-label for=\"readonly\">\n You can only read the following value\n </sp-field-label>\n <sp-number-field\n id=\"readonly\"\n ...=${spreadProps(args)}\n @change=${args.onChange}\n ></sp-number-field>\n `;\n};\nreadOnly.args = {\n readonly: true,\n value: '15',\n};\n"]}
@@ -0,0 +1,18 @@
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 '@spectrum-web-components/number-field/sp-number-field.js';
13
+ import { html } from 'lit';
14
+ import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
15
+ measureFixtureCreation(html `
16
+ <sp-number-field></sp-number-field>
17
+ `);
18
+ //# sourceMappingURL=basic-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-test.js","sourceRoot":"","sources":["basic-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,0DAA0D,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;CAE1B,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/number-field/sp-number-field.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-number-field></sp-number-field>\n`);\n"]}
@@ -0,0 +1,66 @@
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 { elementUpdated, fixture, nextFrame } from '@open-wc/testing';
14
+ import { sendMouse } from '../../../test/plugins/browser.js';
15
+ export async function getElFrom(test) {
16
+ const wrapped = await fixture(html `
17
+ <div style="--spectrum-alias-ui-icon-chevron-size-75: 20px;">
18
+ ${test}
19
+ </div>
20
+ `);
21
+ const el = wrapped.querySelector('sp-number-field');
22
+ await elementUpdated(el);
23
+ return el;
24
+ }
25
+ export async function clickBySelector(el, selector, options = {}) {
26
+ const target = el.shadowRoot.querySelector(selector);
27
+ const targetRect = target.getBoundingClientRect();
28
+ await sendMouse({
29
+ steps: [
30
+ {
31
+ type: 'move',
32
+ position: [
33
+ targetRect.x + targetRect.width / 2,
34
+ targetRect.y + targetRect.height / 2,
35
+ ],
36
+ options,
37
+ },
38
+ {
39
+ type: 'down',
40
+ options,
41
+ },
42
+ ],
43
+ });
44
+ await nextFrame();
45
+ await sendMouse({
46
+ steps: [
47
+ {
48
+ type: 'up',
49
+ options,
50
+ },
51
+ ],
52
+ });
53
+ await elementUpdated(el);
54
+ }
55
+ export function createLanguageContext(lang) {
56
+ const langResolvers = [];
57
+ const createLangResolver = (event) => {
58
+ langResolvers.push(event.detail.callback);
59
+ resolveLanguage();
60
+ };
61
+ const resolveLanguage = () => {
62
+ langResolvers.forEach((resolver) => resolver(lang));
63
+ };
64
+ return createLangResolver;
65
+ }
66
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGtE,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAoB;IAChD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAiB,IAAI,CAAA;;cAExC,IAAI;;KAEb,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAgB,CAAC;IACnE,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;IACzB,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACjC,EAAe,EACf,QAAgB,EAChB,UAAoD,EAAE;IAEtD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAgB,CAAC;IACpE,MAAM,UAAU,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAClD,MAAM,SAAS,CAAC;QACZ,KAAK,EAAE;YACH;gBACI,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE;oBACN,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,GAAG,CAAC;oBACnC,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC;iBACvC;gBACD,OAAO;aACV;YACD;gBACI,IAAI,EAAE,MAAM;gBACZ,OAAO;aACV;SACJ;KACJ,CAAC,CAAC;IACH,MAAM,SAAS,EAAE,CAAC;IAClB,MAAM,SAAS,CAAC;QACZ,KAAK,EAAE;YACH;gBACI,IAAI,EAAE,IAAI;gBACV,OAAO;aACV;SACJ;KACJ,CAAC,CAAC;IACH,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACjC,IAAY;IAEZ,MAAM,aAAa,GAA8B,EAAE,CAAC;IACpD,MAAM,kBAAkB,GAAG,CAAC,KAA+B,EAAQ,EAAE;QACjE,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,eAAe,EAAE,CAAC;IACtB,CAAC,CAAC;IACF,MAAM,eAAe,GAAG,GAAS,EAAE;QAC/B,aAAa,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC;IACF,OAAO,kBAAkB,CAAC;AAC9B,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, fixture, nextFrame } from '@open-wc/testing';\nimport { ProvideLang } from '@spectrum-web-components/theme';\nimport { NumberField } from '../';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\nexport async function getElFrom(test: TemplateResult): Promise<NumberField> {\n const wrapped = await fixture<HTMLDivElement>(html`\n <div style=\"--spectrum-alias-ui-icon-chevron-size-75: 20px;\">\n ${test}\n </div>\n `);\n const el = wrapped.querySelector('sp-number-field') as NumberField;\n await elementUpdated(el);\n return el;\n}\n\nexport async function clickBySelector(\n el: NumberField,\n selector: string,\n options: { button?: 'left' | 'right' | 'middle' } = {}\n): Promise<void> {\n const target = el.shadowRoot.querySelector(selector) as HTMLElement;\n const targetRect = target.getBoundingClientRect();\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n targetRect.x + targetRect.width / 2,\n targetRect.y + targetRect.height / 2,\n ],\n options,\n },\n {\n type: 'down',\n options,\n },\n ],\n });\n await nextFrame();\n await sendMouse({\n steps: [\n {\n type: 'up',\n options,\n },\n ],\n });\n await elementUpdated(el);\n}\n\nexport function createLanguageContext(\n lang: string\n): (event: CustomEvent<ProvideLang>) => void {\n const langResolvers: ProvideLang['callback'][] = [];\n const createLangResolver = (event: CustomEvent<ProvideLang>): void => {\n langResolvers.push(event.detail.callback);\n resolveLanguage();\n };\n const resolveLanguage = (): void => {\n langResolvers.forEach((resolver) => resolver(lang));\n };\n return createLangResolver;\n}\n"]}