@danske/sapphire-react-lab 0.105.2 → 0.106.1
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/build/cjs/index.js +1527 -2226
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/src/Accordion.js +41 -73
- package/build/esm/Accordion/src/Accordion.js.map +1 -1
- package/build/esm/Accordion/src/AccordionContext.js +3 -1
- package/build/esm/Accordion/src/AccordionContext.js.map +1 -1
- package/build/esm/Accordion/src/AccordionHeading.js +22 -54
- package/build/esm/Accordion/src/AccordionHeading.js.map +1 -1
- package/build/esm/Accordion/src/AccordionItem.js +15 -42
- package/build/esm/Accordion/src/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/src/AccordionPanel.js +27 -44
- package/build/esm/Accordion/src/AccordionPanel.js.map +1 -1
- package/build/esm/Accordion/src/utils.js.map +1 -1
- package/build/esm/Alert/src/Alert.js +26 -64
- package/build/esm/Alert/src/Alert.js.map +1 -1
- package/build/esm/Amount/src/Amount.js +40 -62
- package/build/esm/Amount/src/Amount.js.map +1 -1
- package/build/esm/Amount/src/useGroupAmount.js +4 -1
- package/build/esm/Amount/src/useGroupAmount.js.map +1 -1
- package/build/esm/Autocomplete/i18n/da-DK.json.js +6 -0
- package/build/esm/Autocomplete/i18n/da-DK.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/de-DE.json.js +6 -0
- package/build/esm/Autocomplete/i18n/de-DE.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/en-US.json.js +6 -0
- package/build/esm/Autocomplete/i18n/en-US.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/fi-FI.json.js +6 -0
- package/build/esm/Autocomplete/i18n/fi-FI.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/index.js +9 -9
- package/build/esm/Autocomplete/i18n/index.js.map +1 -1
- package/build/esm/Autocomplete/i18n/nb-NO.json.js +6 -0
- package/build/esm/Autocomplete/i18n/nb-NO.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/pl-PL.json.js +6 -0
- package/build/esm/Autocomplete/i18n/pl-PL.json.js.map +1 -0
- package/build/esm/Autocomplete/i18n/sv-SE.json.js +6 -0
- package/build/esm/Autocomplete/i18n/sv-SE.json.js.map +1 -0
- package/build/esm/Autocomplete/src/Autocomplete.js +49 -74
- package/build/esm/Autocomplete/src/Autocomplete.js.map +1 -1
- package/build/esm/Breadcrumbs/src/BreadcrumbItem.js +44 -51
- package/build/esm/Breadcrumbs/src/BreadcrumbItem.js.map +1 -1
- package/build/esm/Breadcrumbs/src/BreadcrumbItemLink.js +17 -45
- package/build/esm/Breadcrumbs/src/BreadcrumbItemLink.js.map +1 -1
- package/build/esm/Breadcrumbs/src/BreadcrumbItemStatic.js +24 -45
- package/build/esm/Breadcrumbs/src/BreadcrumbItemStatic.js.map +1 -1
- package/build/esm/Breadcrumbs/src/BreadcrumbOverflowMenu.js +18 -11
- package/build/esm/Breadcrumbs/src/BreadcrumbOverflowMenu.js.map +1 -1
- package/build/esm/Breadcrumbs/src/Breadcrumbs.js +42 -61
- package/build/esm/Breadcrumbs/src/Breadcrumbs.js.map +1 -1
- package/build/esm/Breadcrumbs/src/BreadcrumbsSeparator.js +8 -6
- package/build/esm/Breadcrumbs/src/BreadcrumbsSeparator.js.map +1 -1
- package/build/esm/Breadcrumbs/src/useBreadcrumbThreshold.js +5 -5
- package/build/esm/Breadcrumbs/src/useBreadcrumbThreshold.js.map +1 -1
- package/build/esm/FileDropzone/i18n/{da-DK.js → da-DK.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/da-DK.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/{de-DE.js → de-DE.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/de-DE.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/{en-US.js → en-US.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/en-US.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/{fi-FI.js → fi-FI.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/fi-FI.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/index.js +9 -9
- package/build/esm/FileDropzone/i18n/index.js.map +1 -1
- package/build/esm/FileDropzone/i18n/{nb-NO.js → nb-NO.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/nb-NO.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/{pl-PL.js → pl-PL.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/pl-PL.json.js.map +1 -0
- package/build/esm/FileDropzone/i18n/{sv-SE.js → sv-SE.json.js} +3 -3
- package/build/esm/FileDropzone/i18n/sv-SE.json.js.map +1 -0
- package/build/esm/FileDropzone/src/FileDropzone.js +59 -84
- package/build/esm/FileDropzone/src/FileDropzone.js.map +1 -1
- package/build/esm/FileDropzone/src/FileTrigger.js +26 -59
- package/build/esm/FileDropzone/src/FileTrigger.js.map +1 -1
- package/build/esm/FileDropzone/src/utils.js.map +1 -1
- package/build/esm/Filtering/src/FilterDropdown.js +88 -110
- package/build/esm/Filtering/src/FilterDropdown.js.map +1 -1
- package/build/esm/Filtering/src/SearchableSelectFilter.js +38 -58
- package/build/esm/Filtering/src/SearchableSelectFilter.js.map +1 -1
- package/build/esm/Flag/src/Flag.js +5 -37
- package/build/esm/Flag/src/Flag.js.map +1 -1
- package/build/esm/LabeledValue/src/LabeledValue.js +19 -53
- package/build/esm/LabeledValue/src/LabeledValue.js.map +1 -1
- package/build/esm/NumberField/i18n/da-DK.json.js +9 -0
- package/build/esm/NumberField/i18n/da-DK.json.js.map +1 -0
- package/build/esm/NumberField/i18n/de-DE.json.js +9 -0
- package/build/esm/NumberField/i18n/de-DE.json.js.map +1 -0
- package/build/esm/NumberField/i18n/en-US.json.js +9 -0
- package/build/esm/NumberField/i18n/en-US.json.js.map +1 -0
- package/build/esm/NumberField/i18n/fi-FI.json.js +9 -0
- package/build/esm/NumberField/i18n/fi-FI.json.js.map +1 -0
- package/build/esm/NumberField/i18n/index.js +9 -9
- package/build/esm/NumberField/i18n/index.js.map +1 -1
- package/build/esm/NumberField/i18n/nb-NO.json.js +9 -0
- package/build/esm/NumberField/i18n/nb-NO.json.js.map +1 -0
- package/build/esm/NumberField/i18n/pl-PL.json.js +9 -0
- package/build/esm/NumberField/i18n/pl-PL.json.js.map +1 -0
- package/build/esm/NumberField/i18n/sv-SE.json.js +9 -0
- package/build/esm/NumberField/i18n/sv-SE.json.js.map +1 -0
- package/build/esm/NumberField/src/NumberField.js +125 -108
- package/build/esm/NumberField/src/NumberField.js.map +1 -1
- package/build/esm/NumberField/src/StepperButton.js +28 -50
- package/build/esm/NumberField/src/StepperButton.js.map +1 -1
- package/build/esm/NumberField/src/cursorHelpers.js +13 -8
- package/build/esm/NumberField/src/cursorHelpers.js.map +1 -1
- package/build/esm/NumberField/src/formatHelpers.js +15 -18
- package/build/esm/NumberField/src/formatHelpers.js.map +1 -1
- package/build/esm/NumberField/src/keyboardHelpers.js +13 -8
- package/build/esm/NumberField/src/keyboardHelpers.js.map +1 -1
- package/build/esm/NumberField/src/useAutofillStyle.js.map +1 -1
- package/build/esm/NumberField/src/useNumberFieldFormatting.js +79 -45
- package/build/esm/NumberField/src/useNumberFieldFormatting.js.map +1 -1
- package/build/esm/NumberField/src/useSapphireNumberField.js +13 -39
- package/build/esm/NumberField/src/useSapphireNumberField.js.map +1 -1
- package/build/esm/ProgressIndicator/src/ProgressIndicator.js +21 -33
- package/build/esm/ProgressIndicator/src/ProgressIndicator.js.map +1 -1
- package/build/esm/Sidebar/index.js.map +1 -1
- package/build/esm/Sidebar/src/Body.js +18 -43
- package/build/esm/Sidebar/src/Body.js.map +1 -1
- package/build/esm/Sidebar/src/ExpandableItem.js +86 -95
- package/build/esm/Sidebar/src/ExpandableItem.js.map +1 -1
- package/build/esm/Sidebar/src/Header.js +13 -43
- package/build/esm/Sidebar/src/Header.js.map +1 -1
- package/build/esm/Sidebar/src/Item.js +16 -43
- package/build/esm/Sidebar/src/Item.js.map +1 -1
- package/build/esm/Sidebar/src/List.js +13 -42
- package/build/esm/Sidebar/src/List.js.map +1 -1
- package/build/esm/Sidebar/src/Panel.js +56 -69
- package/build/esm/Sidebar/src/Panel.js.map +1 -1
- package/build/esm/Sidebar/src/ResponsiveSidebarContext.js +16 -8
- package/build/esm/Sidebar/src/ResponsiveSidebarContext.js.map +1 -1
- package/build/esm/Sidebar/src/SecondarySidebarContext.js +14 -11
- package/build/esm/Sidebar/src/SecondarySidebarContext.js.map +1 -1
- package/build/esm/Sidebar/src/Section.js +36 -49
- package/build/esm/Sidebar/src/Section.js.map +1 -1
- package/build/esm/Sidebar/src/Sidebar.js +62 -91
- package/build/esm/Sidebar/src/Sidebar.js.map +1 -1
- package/build/esm/Sidebar/src/useSidebar.js.map +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Slider/src/Slider.js +46 -71
- package/build/esm/Slider/src/Slider.js.map +1 -1
- package/build/esm/TagGroup/src/Tag.js +66 -82
- package/build/esm/TagGroup/src/Tag.js.map +1 -1
- package/build/esm/TagGroup/src/TagGroup.js +44 -65
- package/build/esm/TagGroup/src/TagGroup.js.map +1 -1
- package/build/esm/TagGroup/src/TagItem.js.map +1 -1
- package/build/esm/TimeField/i18n/da-DK.json.js +7 -0
- package/build/esm/TimeField/i18n/da-DK.json.js.map +1 -0
- package/build/esm/TimeField/i18n/de-DE.json.js +7 -0
- package/build/esm/TimeField/i18n/de-DE.json.js.map +1 -0
- package/build/esm/TimeField/i18n/en-US.json.js +7 -0
- package/build/esm/TimeField/i18n/en-US.json.js.map +1 -0
- package/build/esm/TimeField/i18n/fi-FI.json.js +7 -0
- package/build/esm/TimeField/i18n/fi-FI.json.js.map +1 -0
- package/build/esm/TimeField/i18n/index.js +7 -7
- package/build/esm/TimeField/i18n/index.js.map +1 -1
- package/build/esm/TimeField/i18n/nb-NO.json.js +7 -0
- package/build/esm/TimeField/i18n/nb-NO.json.js.map +1 -0
- package/build/esm/TimeField/i18n/pl-PL.json.js +7 -0
- package/build/esm/TimeField/i18n/pl-PL.json.js.map +1 -0
- package/build/esm/TimeField/i18n/{sv-SE.js → sv-SE.json.js} +1 -1
- package/build/esm/TimeField/i18n/sv-SE.json.js.map +1 -0
- package/build/esm/TimeField/src/TimeField.js +62 -80
- package/build/esm/TimeField/src/TimeField.js.map +1 -1
- package/build/esm/TimeField/src/TimeFieldSegment.js +24 -36
- package/build/esm/TimeField/src/TimeFieldSegment.js.map +1 -1
- package/build/index.d.ts +13 -12
- package/package.json +5 -5
- package/build/esm/Autocomplete/i18n/da-DK.js +0 -6
- package/build/esm/Autocomplete/i18n/da-DK.js.map +0 -1
- package/build/esm/Autocomplete/i18n/de-DE.js +0 -6
- package/build/esm/Autocomplete/i18n/de-DE.js.map +0 -1
- package/build/esm/Autocomplete/i18n/en-US.js +0 -6
- package/build/esm/Autocomplete/i18n/en-US.js.map +0 -1
- package/build/esm/Autocomplete/i18n/fi-FI.js +0 -6
- package/build/esm/Autocomplete/i18n/fi-FI.js.map +0 -1
- package/build/esm/Autocomplete/i18n/nb-NO.js +0 -6
- package/build/esm/Autocomplete/i18n/nb-NO.js.map +0 -1
- package/build/esm/Autocomplete/i18n/pl-PL.js +0 -6
- package/build/esm/Autocomplete/i18n/pl-PL.js.map +0 -1
- package/build/esm/Autocomplete/i18n/sv-SE.js +0 -6
- package/build/esm/Autocomplete/i18n/sv-SE.js.map +0 -1
- package/build/esm/FileDropzone/i18n/da-DK.js.map +0 -1
- package/build/esm/FileDropzone/i18n/de-DE.js.map +0 -1
- package/build/esm/FileDropzone/i18n/en-US.js.map +0 -1
- package/build/esm/FileDropzone/i18n/fi-FI.js.map +0 -1
- package/build/esm/FileDropzone/i18n/nb-NO.js.map +0 -1
- package/build/esm/FileDropzone/i18n/pl-PL.js.map +0 -1
- package/build/esm/FileDropzone/i18n/sv-SE.js.map +0 -1
- package/build/esm/NumberField/i18n/da-DK.js +0 -9
- package/build/esm/NumberField/i18n/da-DK.js.map +0 -1
- package/build/esm/NumberField/i18n/de-DE.js +0 -9
- package/build/esm/NumberField/i18n/de-DE.js.map +0 -1
- package/build/esm/NumberField/i18n/en-US.js +0 -9
- package/build/esm/NumberField/i18n/en-US.js.map +0 -1
- package/build/esm/NumberField/i18n/fi-FI.js +0 -9
- package/build/esm/NumberField/i18n/fi-FI.js.map +0 -1
- package/build/esm/NumberField/i18n/nb-NO.js +0 -9
- package/build/esm/NumberField/i18n/nb-NO.js.map +0 -1
- package/build/esm/NumberField/i18n/pl-PL.js +0 -9
- package/build/esm/NumberField/i18n/pl-PL.js.map +0 -1
- package/build/esm/NumberField/i18n/sv-SE.js +0 -9
- package/build/esm/NumberField/i18n/sv-SE.js.map +0 -1
- package/build/esm/TimeField/i18n/da-DK.js +0 -7
- package/build/esm/TimeField/i18n/da-DK.js.map +0 -1
- package/build/esm/TimeField/i18n/de-DE.js +0 -7
- package/build/esm/TimeField/i18n/de-DE.js.map +0 -1
- package/build/esm/TimeField/i18n/en-US.js +0 -7
- package/build/esm/TimeField/i18n/en-US.js.map +0 -1
- package/build/esm/TimeField/i18n/fi-FI.js +0 -7
- package/build/esm/TimeField/i18n/fi-FI.js.map +0 -1
- package/build/esm/TimeField/i18n/nb-NO.js +0 -7
- package/build/esm/TimeField/i18n/nb-NO.js.map +0 -1
- package/build/esm/TimeField/i18n/pl-PL.js +0 -7
- package/build/esm/TimeField/i18n/pl-PL.js.map +0 -1
- package/build/esm/TimeField/i18n/sv-SE.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fi-FI.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import da from './da-DK.js';
|
|
2
|
-
import en from './en-US.js';
|
|
3
|
-
import de from './de-DE.js';
|
|
4
|
-
import fi from './fi-FI.js';
|
|
5
|
-
import no from './nb-NO.js';
|
|
6
|
-
import pl from './pl-PL.js';
|
|
7
|
-
import se from './sv-SE.js';
|
|
1
|
+
import da from './da-DK.json.js';
|
|
2
|
+
import en from './en-US.json.js';
|
|
3
|
+
import de from './de-DE.json.js';
|
|
4
|
+
import fi from './fi-FI.json.js';
|
|
5
|
+
import no from './nb-NO.json.js';
|
|
6
|
+
import pl from './pl-PL.json.js';
|
|
7
|
+
import se from './sv-SE.json.js';
|
|
8
8
|
|
|
9
|
-
var intlMessages = {
|
|
9
|
+
var intlMessages$1 = {
|
|
10
10
|
"da-DK": da,
|
|
11
11
|
"en-US": en,
|
|
12
12
|
"de-DE": de,
|
|
@@ -16,5 +16,5 @@ var intlMessages = {
|
|
|
16
16
|
"sv-SE": se
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export { intlMessages as default };
|
|
19
|
+
export { intlMessages$1 as default };
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/NumberField/i18n/index.ts"],"sourcesContent":["import da from './da-DK.json';\nimport en from './en-US.json';\nimport de from './de-DE.json';\nimport fi from './fi-FI.json';\nimport no from './nb-NO.json';\nimport pl from './pl-PL.json';\nimport se from './sv-SE.json';\n\nexport default {\n 'da-DK': da,\n 'en-US': en,\n 'de-DE': de,\n 'fi-FI': fi,\n 'nb-NO': no,\n 'pl-PL': pl,\n 'sv-SE': se,\n};\n"],"names":[],"mappings":";;;;;;;;AAQA,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/NumberField/i18n/index.ts"],"sourcesContent":["import da from './da-DK.json';\nimport en from './en-US.json';\nimport de from './de-DE.json';\nimport fi from './fi-FI.json';\nimport no from './nb-NO.json';\nimport pl from './pl-PL.json';\nimport se from './sv-SE.json';\n\nexport default {\n 'da-DK': da,\n 'en-US': en,\n 'de-DE': de,\n 'fi-FI': fi,\n 'nb-NO': no,\n 'pl-PL': pl,\n 'sv-SE': se,\n};\n"],"names":[],"mappings":";;;;;;;;AAQA,qBAAe;AAAA,EACb,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS,EAAA;AAAA,EACT,OAAA,EAAS;AACX,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nb-NO.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pl-PL.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sv-SE.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -12,40 +12,8 @@ import { useAutofillStyle } from './useAutofillStyle.js';
|
|
|
12
12
|
import { useNumberFieldFormatting } from './useNumberFieldFormatting.js';
|
|
13
13
|
import { useSapphireNumberField } from './useSapphireNumberField.js';
|
|
14
14
|
|
|
15
|
-
var __defProp = Object.defineProperty;
|
|
16
|
-
var __defProps = Object.defineProperties;
|
|
17
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
18
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
19
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
20
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
21
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
22
|
-
var __spreadValues = (a, b) => {
|
|
23
|
-
for (var prop in b || (b = {}))
|
|
24
|
-
if (__hasOwnProp.call(b, prop))
|
|
25
|
-
__defNormalProp(a, prop, b[prop]);
|
|
26
|
-
if (__getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
28
|
-
if (__propIsEnum.call(b, prop))
|
|
29
|
-
__defNormalProp(a, prop, b[prop]);
|
|
30
|
-
}
|
|
31
|
-
return a;
|
|
32
|
-
};
|
|
33
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
34
|
-
var __objRest = (source, exclude) => {
|
|
35
|
-
var target = {};
|
|
36
|
-
for (var prop in source)
|
|
37
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
38
|
-
target[prop] = source[prop];
|
|
39
|
-
if (source != null && __getOwnPropSymbols)
|
|
40
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
41
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
42
|
-
target[prop] = source[prop];
|
|
43
|
-
}
|
|
44
|
-
return target;
|
|
45
|
-
};
|
|
46
15
|
const NumberField = forwardRef(function NumberField2(props, ref) {
|
|
47
|
-
|
|
48
|
-
const _a = props, {
|
|
16
|
+
const {
|
|
49
17
|
label,
|
|
50
18
|
isDisabled,
|
|
51
19
|
error,
|
|
@@ -60,24 +28,9 @@ const NumberField = forwardRef(function NumberField2(props, ref) {
|
|
|
60
28
|
showButtons = false,
|
|
61
29
|
incrementAriaLabel,
|
|
62
30
|
decrementAriaLabel,
|
|
63
|
-
autoFormat = false
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"isDisabled",
|
|
67
|
-
"error",
|
|
68
|
-
"note",
|
|
69
|
-
"isRequired",
|
|
70
|
-
"contextualHelp",
|
|
71
|
-
"affix",
|
|
72
|
-
"size",
|
|
73
|
-
"labelPlacement",
|
|
74
|
-
"necessityIndicator",
|
|
75
|
-
"alignInputRight",
|
|
76
|
-
"showButtons",
|
|
77
|
-
"incrementAriaLabel",
|
|
78
|
-
"decrementAriaLabel",
|
|
79
|
-
"autoFormat"
|
|
80
|
-
]);
|
|
31
|
+
autoFormat = false,
|
|
32
|
+
...otherProps
|
|
33
|
+
} = props;
|
|
81
34
|
const { prefix, postfix } = useMemo(() => {
|
|
82
35
|
if (affix === "auto") {
|
|
83
36
|
return { prefix: void 0, postfix: void 0 };
|
|
@@ -94,14 +47,21 @@ const NumberField = forwardRef(function NumberField2(props, ref) {
|
|
|
94
47
|
decrementButtonProps,
|
|
95
48
|
descriptionProps,
|
|
96
49
|
errorMessageProps
|
|
97
|
-
} = useSapphireNumberField(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
50
|
+
} = useSapphireNumberField(
|
|
51
|
+
{
|
|
52
|
+
...props,
|
|
53
|
+
incrementAriaLabel: incrementAriaLabel ?? formatMessage("increment"),
|
|
54
|
+
decrementAriaLabel: decrementAriaLabel ?? formatMessage("decrement")
|
|
55
|
+
},
|
|
56
|
+
inputRef
|
|
57
|
+
);
|
|
101
58
|
const { focusProps, isFocusVisible } = useFocusRing();
|
|
102
59
|
const { autofillStyles, updateStyle } = useAutofillStyle(inputRef);
|
|
103
60
|
const { locale } = useLocale();
|
|
104
|
-
const formatter = useMemo(
|
|
61
|
+
const formatter = useMemo(
|
|
62
|
+
() => new Intl.NumberFormat(locale, props.formatOptions),
|
|
63
|
+
[locale, props.formatOptions]
|
|
64
|
+
);
|
|
105
65
|
const formattingResult = useNumberFieldFormatting({
|
|
106
66
|
inputRef,
|
|
107
67
|
formatter,
|
|
@@ -119,63 +79,120 @@ const NumberField = forwardRef(function NumberField2(props, ref) {
|
|
|
119
79
|
handleKeyDown: inputProps.onKeyDown
|
|
120
80
|
};
|
|
121
81
|
const containerRef = useRef(null);
|
|
122
|
-
useImperativeHandle(ref, () =>
|
|
82
|
+
useImperativeHandle(ref, () => ({
|
|
83
|
+
...createFocusableRef(containerRef, inputRef),
|
|
84
|
+
/**
|
|
85
|
+
* (This function is deprecated. Use `inputRef` prop)
|
|
86
|
+
* @deprecated
|
|
87
|
+
*/
|
|
123
88
|
getInputElement() {
|
|
124
89
|
return inputRef.current;
|
|
125
90
|
}
|
|
126
91
|
}));
|
|
127
|
-
return /* @__PURE__ */ React.createElement(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
92
|
+
return /* @__PURE__ */ React.createElement(
|
|
93
|
+
Field,
|
|
94
|
+
{
|
|
95
|
+
...removeUniqueDOMProps(otherProps),
|
|
96
|
+
ref: containerRef,
|
|
97
|
+
size,
|
|
98
|
+
labelPlacement
|
|
99
|
+
},
|
|
100
|
+
/* @__PURE__ */ React.createElement(
|
|
101
|
+
Field.Context,
|
|
102
|
+
{
|
|
103
|
+
descriptionProps: error ? errorMessageProps : descriptionProps
|
|
104
|
+
},
|
|
105
|
+
label && /* @__PURE__ */ React.createElement(Field.Label, null, /* @__PURE__ */ React.createElement(
|
|
106
|
+
Label,
|
|
107
|
+
{
|
|
108
|
+
...labelProps,
|
|
109
|
+
size,
|
|
110
|
+
necessityIndicator: isRequired && necessityIndicator ? "required" : !isRequired && necessityIndicator ? "optional" : void 0,
|
|
111
|
+
contextualHelp
|
|
112
|
+
},
|
|
113
|
+
label
|
|
114
|
+
)),
|
|
115
|
+
/* @__PURE__ */ React.createElement(Field.Control, null, /* @__PURE__ */ React.createElement(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
className: clsx(textFieldStyles["sapphire-text-field"], {
|
|
119
|
+
[textFieldStyles["is-focus"]]: isFocusVisible,
|
|
120
|
+
[textFieldStyles["sapphire-text-field--error"]]: error === true || typeof error === "string",
|
|
121
|
+
[textFieldStyles["sapphire-text-field--md"]]: size === "md"
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
extractedPrefix && /* @__PURE__ */ React.createElement(
|
|
125
|
+
"span",
|
|
126
|
+
{
|
|
127
|
+
className: clsx(
|
|
128
|
+
textFieldStyles["sapphire-text-field__prefix"],
|
|
129
|
+
{
|
|
130
|
+
[textFieldStyles["sapphire-text-field__prefix--icon"]]: typeof extractedPrefix !== "string"
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
extractedPrefix
|
|
135
|
+
),
|
|
136
|
+
/* @__PURE__ */ React.createElement(
|
|
137
|
+
"input",
|
|
138
|
+
{
|
|
139
|
+
...mergeProps(
|
|
140
|
+
inputProps,
|
|
141
|
+
focusProps,
|
|
142
|
+
{
|
|
143
|
+
onChange: updateStyle,
|
|
144
|
+
onBlur: updateStyle
|
|
145
|
+
},
|
|
146
|
+
autoFormat ? {
|
|
147
|
+
onInput: handleInput,
|
|
148
|
+
onKeyDown: handleKeyDown
|
|
149
|
+
} : {}
|
|
150
|
+
),
|
|
151
|
+
value: formattingResult?.displayValue ?? inputProps.value,
|
|
152
|
+
ref: inputRef,
|
|
153
|
+
className: clsx(textFieldStyles["sapphire-text-field__input"], {
|
|
154
|
+
[textFieldStyles["sapphire-text-field__input--align-right"]]: !!alignInputRight
|
|
155
|
+
}),
|
|
156
|
+
style: autofillStyles
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
extractedPostfix && /* @__PURE__ */ React.createElement(
|
|
160
|
+
"span",
|
|
161
|
+
{
|
|
162
|
+
className: clsx(
|
|
163
|
+
textFieldStyles["sapphire-text-field__postfix"],
|
|
164
|
+
{
|
|
165
|
+
[textFieldStyles["sapphire-text-field__postfix--icon"]]: typeof extractedPostfix !== "string"
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
},
|
|
169
|
+
extractedPostfix
|
|
170
|
+
),
|
|
171
|
+
showButtons && /* @__PURE__ */ React.createElement("div", { className: textFieldStyles["sapphire-text-field__stepper"] }, /* @__PURE__ */ React.createElement(
|
|
172
|
+
StepperButton,
|
|
173
|
+
{
|
|
174
|
+
variant: "decrement",
|
|
175
|
+
size,
|
|
176
|
+
...decrementButtonProps
|
|
177
|
+
}
|
|
178
|
+
), /* @__PURE__ */ React.createElement(Separator, { orientation: "vertical" }), /* @__PURE__ */ React.createElement(
|
|
179
|
+
StepperButton,
|
|
180
|
+
{
|
|
181
|
+
variant: "increment",
|
|
182
|
+
size,
|
|
183
|
+
...incrementButtonProps
|
|
184
|
+
}
|
|
185
|
+
))
|
|
186
|
+
)),
|
|
187
|
+
(error && typeof error !== "boolean" || note) && /* @__PURE__ */ React.createElement(Field.Footer, null, error && typeof error !== "boolean" ? /* @__PURE__ */ React.createElement(Field.Note, { variant: "error" }, error) : note ? note : /* @__PURE__ */ React.createElement(React.Fragment, null))
|
|
188
|
+
)
|
|
189
|
+
);
|
|
177
190
|
});
|
|
178
|
-
const removeUniqueDOMProps = (props) => Object.fromEntries(
|
|
191
|
+
const removeUniqueDOMProps = (props) => Object.fromEntries(
|
|
192
|
+
Object.entries(props).filter(
|
|
193
|
+
([name]) => name !== "id" && !name.startsWith("data-")
|
|
194
|
+
)
|
|
195
|
+
);
|
|
179
196
|
|
|
180
197
|
export { NumberField };
|
|
181
198
|
//# sourceMappingURL=NumberField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberField.js","sources":["../../../../src/NumberField/src/NumberField.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ForwardedRef,\n ReactNode,\n RefObject,\n useImperativeHandle,\n useRef,\n useMemo,\n} from 'react';\nimport clsx from 'clsx';\nimport { useFocusRing } from '@react-aria/focus';\nimport { useLocale, useMessageFormatter } from '@react-aria/i18n';\nimport { mergeProps, useObjectRef } from '@react-aria/utils';\nimport { createFocusableRef } from '@react-spectrum/utils';\nimport { FocusableRefValue, PressEvents } from '@react-types/shared';\nimport textFieldStyles from '@danske/sapphire-css/components/textField/textField.module.css';\nimport {\n Field,\n Label,\n SapphireStyleProps,\n useThemeCheck,\n GlobalDomAttributes,\n Separator,\n} from '@danske/sapphire-react';\n\nimport intlMessages from '../i18n';\nimport { StepperButton } from './StepperButton';\nimport { useAutofillStyle } from './useAutofillStyle';\nimport { useNumberFieldFormatting } from './useNumberFieldFormatting';\nimport {\n SapphireNumberFieldProps,\n useSapphireNumberField,\n} from './useSapphireNumberField';\n\nexport type NumberFieldRef = FocusableRefValue<\n HTMLInputElement,\n HTMLDivElement\n> & {\n getInputElement(): HTMLInputElement | null;\n};\n\nexport interface NumberFieldProps\n extends SapphireNumberFieldProps,\n PressEvents,\n SapphireStyleProps,\n GlobalDomAttributes {\n /**\n * A string or element to show before / after the input value.\n *\n * By default (`'auto'`), the component will automatically extract currency/unit symbols\n * from the locale formatter and display them as prefix/postfix.\n * If you provide a custom prefix or postfix, those will be used instead and\n * the extracted symbols will be ignored.\n *\n * @default 'auto' - automatically extracts currency/unit symbols from locale formatter\n */\n affix?: 'auto' | { prefix?: ReactNode; postfix?: ReactNode };\n inputRef?: RefObject<HTMLInputElement | null>;\n /**\n * A note to show below the input.\n * If the input has an error message, this note will be replaced by that.\n */\n note?: ReactNode;\n /**\n * A HelpButton to render next to the label.\n */\n contextualHelp?: ReactNode;\n /**\n * To visually indicate if this field is required or optional.\n * @default false\n */\n necessityIndicator?: boolean;\n /**\n * @default 'lg'\n */\n size?: 'lg' | 'md';\n /**\n * Aligns the text inside the input fields without affecting the positioning of the label of the field.\n */\n alignInputRight?: boolean;\n /**\n * Places the label either above (default) or on the side of the control.\n * @default 'above'\n */\n labelPlacement?: 'side' | 'above';\n /**\n * To show the buttons for incrementing and decrementing the value.\n * @default false\n */\n showButtons?: boolean;\n /**\n * Enables automatic formatting of the input value as the user types, based on the provided formatter and affix.\n *\n * @default false\n */\n autoFormat?: boolean;\n}\n\nexport const NumberField = forwardRef(function NumberField(\n props: NumberFieldProps,\n ref: ForwardedRef<NumberFieldRef>\n) {\n const {\n label,\n isDisabled,\n error,\n note,\n isRequired,\n contextualHelp,\n affix = 'auto',\n size = 'lg',\n labelPlacement = 'above',\n necessityIndicator = false,\n alignInputRight,\n showButtons = false,\n incrementAriaLabel,\n decrementAriaLabel,\n autoFormat = false,\n ...otherProps\n } = props;\n\n // Extract prefix and postfix from affix prop\n const { prefix, postfix } = useMemo(() => {\n if (affix === 'auto') {\n return { prefix: undefined, postfix: undefined };\n }\n return { prefix: affix.prefix, postfix: affix.postfix };\n }, [affix]);\n useThemeCheck();\n const inputRef = useObjectRef<HTMLInputElement>(props.inputRef);\n const formatMessage = useMessageFormatter(intlMessages);\n\n const {\n inputProps,\n labelProps,\n incrementButtonProps,\n decrementButtonProps,\n descriptionProps,\n errorMessageProps,\n } = useSapphireNumberField(\n {\n ...props,\n incrementAriaLabel: incrementAriaLabel ?? formatMessage('increment'),\n decrementAriaLabel: decrementAriaLabel ?? formatMessage('decrement'),\n },\n inputRef\n );\n const { focusProps, isFocusVisible } = useFocusRing();\n const { autofillStyles, updateStyle } = useAutofillStyle<'input'>(inputRef);\n const { locale } = useLocale();\n\n const formatter = useMemo(\n () => new Intl.NumberFormat(locale, props.formatOptions),\n [locale, props.formatOptions]\n );\n\n const formattingResult = useNumberFieldFormatting({\n inputRef,\n formatter,\n inputValue: inputProps.value as string,\n prefix,\n postfix,\n onOriginalKeyDown: inputProps.onKeyDown,\n onChange: props.onChange,\n autoFormat,\n });\n\n const { extractedPrefix, extractedPostfix, handleInput, handleKeyDown } =\n autoFormat\n ? formattingResult\n : {\n extractedPrefix: formattingResult.extractedPrefix,\n extractedPostfix: formattingResult.extractedPostfix,\n handleInput: undefined,\n handleKeyDown: inputProps.onKeyDown,\n };\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n ...createFocusableRef(containerRef, inputRef),\n /**\n * (This function is deprecated. Use `inputRef` prop)\n * @deprecated\n */\n getInputElement() {\n return inputRef.current;\n },\n }));\n\n return (\n <Field\n // otherProps contains some of the same props as inputProps. That is\n // intended, but some DOM props, like \"id\", should not be repeated\n {...removeUniqueDOMProps(otherProps)}\n ref={containerRef}\n size={size}\n labelPlacement={labelPlacement}\n >\n <Field.Context\n descriptionProps={error ? errorMessageProps : descriptionProps}\n >\n {label && (\n <Field.Label>\n <Label\n {...labelProps}\n size={size}\n necessityIndicator={\n isRequired && necessityIndicator\n ? 'required'\n : !isRequired && necessityIndicator\n ? 'optional'\n : undefined\n }\n contextualHelp={contextualHelp}\n >\n {label}\n </Label>\n </Field.Label>\n )}\n <Field.Control>\n <div\n className={clsx(textFieldStyles['sapphire-text-field'], {\n [textFieldStyles['is-focus']]: isFocusVisible,\n [textFieldStyles['sapphire-text-field--error']]:\n error === true || typeof error === 'string',\n [textFieldStyles['sapphire-text-field--md']]: size === 'md',\n })}\n >\n {extractedPrefix && (\n <span\n className={clsx(\n textFieldStyles['sapphire-text-field__prefix'],\n {\n [textFieldStyles['sapphire-text-field__prefix--icon']]:\n typeof extractedPrefix !== 'string',\n }\n )}\n >\n {extractedPrefix}\n </span>\n )}\n <input\n {...mergeProps(\n inputProps,\n focusProps,\n {\n onChange: updateStyle,\n onBlur: updateStyle,\n },\n autoFormat\n ? {\n onInput: handleInput,\n onKeyDown: handleKeyDown,\n }\n : {}\n )}\n value={formattingResult?.displayValue ?? inputProps.value}\n ref={inputRef}\n className={clsx(textFieldStyles['sapphire-text-field__input'], {\n [textFieldStyles['sapphire-text-field__input--align-right']]:\n !!alignInputRight,\n })}\n style={autofillStyles}\n />\n {extractedPostfix && (\n <span\n className={clsx(\n textFieldStyles['sapphire-text-field__postfix'],\n {\n [textFieldStyles['sapphire-text-field__postfix--icon']]:\n typeof extractedPostfix !== 'string',\n }\n )}\n >\n {extractedPostfix}\n </span>\n )}\n {showButtons && (\n <div className={textFieldStyles['sapphire-text-field__stepper']}>\n <StepperButton\n variant=\"decrement\"\n size={size}\n {...decrementButtonProps}\n />\n <Separator orientation=\"vertical\" />\n <StepperButton\n variant=\"increment\"\n size={size}\n {...incrementButtonProps}\n />\n </div>\n )}\n </div>\n </Field.Control>\n {((error && typeof error !== 'boolean') || note) && (\n <Field.Footer>\n {error && typeof error !== 'boolean' ? (\n <Field.Note variant=\"error\">{error}</Field.Note>\n ) : note ? (\n note\n ) : (\n <></>\n )}\n </Field.Footer>\n )}\n </Field.Context>\n </Field>\n );\n});\n\n// Once moved to the core package, this function should be removed and instead consume the one from TextFieldBase.\nconst removeUniqueDOMProps = (props: Record<any, any>): Record<any, any> =>\n Object.fromEntries(\n Object.entries(props).filter(\n ([name]) => name !== 'id' && !name.startsWith('data-')\n )\n );\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGO,MAAM,WAAc,GAAA,UAAA,CAAW,SACpC,YAAA,CAAA,KAAA,EACA,GACA,EAAA;AArGF,EAAA,IAAA,EAAA,CAAA;AAsGE,EAAA,MAiBI,EAhBF,GAAA,KAAA,EAAA;AAAA,IAAA,KAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,cAAA;AAAA,IACA,KAAQ,GAAA,MAAA;AAAA,IACR,IAAO,GAAA,IAAA;AAAA,IACP,cAAiB,GAAA,OAAA;AAAA,IACjB,kBAAqB,GAAA,KAAA;AAAA,IACrB,eAAA;AAAA,IACA,WAAc,GAAA,KAAA;AAAA,IACd,kBAAA;AAAA,IACA,kBAAA;AAAA,IACA,UAAa,GAAA,K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AAO,KAAU,KAAA,SAAA,IAAc,yBACxC,KAAA,CAAA,aAAA,CAAA,KAAA,CAAM,MAAP,EAAA,IAAA,EACG,SAAS,OAAO,KAAA,KAAU,SACzB,mBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,IAAP,EAAA;AAAA,IAAY,OAAQ,EAAA,OAAA;AAAA,GAAS,EAAA,KAAA,CAAA,GAC3B,OACF,IAEA,mBAAA,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,EAAA;AAUd,MAAM,uBAAuB,CAAC,KAAA,KAC5B,MAAO,CAAA,WAAA,CACL,OAAO,OAAQ,CAAA,KAAA,CAAA,CAAO,MACpB,CAAA,CAAC,CAAC,IAAU,CAAA,KAAA,IAAA,KAAS,IAAQ,IAAA,CAAC,KAAK,UAAW,CAAA,OAAA,CAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"NumberField.js","sources":["../../../../src/NumberField/src/NumberField.tsx"],"sourcesContent":["import React, {\n forwardRef,\n ForwardedRef,\n ReactNode,\n RefObject,\n useImperativeHandle,\n useRef,\n useMemo,\n} from 'react';\nimport clsx from 'clsx';\nimport { useFocusRing } from '@react-aria/focus';\nimport { useLocale, useMessageFormatter } from '@react-aria/i18n';\nimport { mergeProps, useObjectRef } from '@react-aria/utils';\nimport { createFocusableRef } from '@react-spectrum/utils';\nimport { FocusableRefValue, PressEvents } from '@react-types/shared';\nimport textFieldStyles from '@danske/sapphire-css/components/textField/textField.module.css';\nimport {\n Field,\n Label,\n SapphireStyleProps,\n useThemeCheck,\n GlobalDomAttributes,\n Separator,\n} from '@danske/sapphire-react';\n\nimport intlMessages from '../i18n';\nimport { StepperButton } from './StepperButton';\nimport { useAutofillStyle } from './useAutofillStyle';\nimport { useNumberFieldFormatting } from './useNumberFieldFormatting';\nimport {\n SapphireNumberFieldProps,\n useSapphireNumberField,\n} from './useSapphireNumberField';\n\nexport type NumberFieldRef = FocusableRefValue<\n HTMLInputElement,\n HTMLDivElement\n> & {\n getInputElement(): HTMLInputElement | null;\n};\n\nexport interface NumberFieldProps\n extends SapphireNumberFieldProps,\n PressEvents,\n SapphireStyleProps,\n GlobalDomAttributes {\n /**\n * A string or element to show before / after the input value.\n *\n * By default (`'auto'`), the component will automatically extract currency/unit symbols\n * from the locale formatter and display them as prefix/postfix.\n * If you provide a custom prefix or postfix, those will be used instead and\n * the extracted symbols will be ignored.\n *\n * @default 'auto' - automatically extracts currency/unit symbols from locale formatter\n */\n affix?: 'auto' | { prefix?: ReactNode; postfix?: ReactNode };\n inputRef?: RefObject<HTMLInputElement | null>;\n /**\n * A note to show below the input.\n * If the input has an error message, this note will be replaced by that.\n */\n note?: ReactNode;\n /**\n * A HelpButton to render next to the label.\n */\n contextualHelp?: ReactNode;\n /**\n * To visually indicate if this field is required or optional.\n * @default false\n */\n necessityIndicator?: boolean;\n /**\n * @default 'lg'\n */\n size?: 'lg' | 'md';\n /**\n * Aligns the text inside the input fields without affecting the positioning of the label of the field.\n */\n alignInputRight?: boolean;\n /**\n * Places the label either above (default) or on the side of the control.\n * @default 'above'\n */\n labelPlacement?: 'side' | 'above';\n /**\n * To show the buttons for incrementing and decrementing the value.\n * @default false\n */\n showButtons?: boolean;\n /**\n * Enables automatic formatting of the input value as the user types, based on the provided formatter and affix.\n *\n * @default false\n */\n autoFormat?: boolean;\n}\n\nexport const NumberField = forwardRef(function NumberField(\n props: NumberFieldProps,\n ref: ForwardedRef<NumberFieldRef>\n) {\n const {\n label,\n isDisabled,\n error,\n note,\n isRequired,\n contextualHelp,\n affix = 'auto',\n size = 'lg',\n labelPlacement = 'above',\n necessityIndicator = false,\n alignInputRight,\n showButtons = false,\n incrementAriaLabel,\n decrementAriaLabel,\n autoFormat = false,\n ...otherProps\n } = props;\n\n // Extract prefix and postfix from affix prop\n const { prefix, postfix } = useMemo(() => {\n if (affix === 'auto') {\n return { prefix: undefined, postfix: undefined };\n }\n return { prefix: affix.prefix, postfix: affix.postfix };\n }, [affix]);\n useThemeCheck();\n const inputRef = useObjectRef<HTMLInputElement>(props.inputRef);\n const formatMessage = useMessageFormatter(intlMessages);\n\n const {\n inputProps,\n labelProps,\n incrementButtonProps,\n decrementButtonProps,\n descriptionProps,\n errorMessageProps,\n } = useSapphireNumberField(\n {\n ...props,\n incrementAriaLabel: incrementAriaLabel ?? formatMessage('increment'),\n decrementAriaLabel: decrementAriaLabel ?? formatMessage('decrement'),\n },\n inputRef\n );\n const { focusProps, isFocusVisible } = useFocusRing();\n const { autofillStyles, updateStyle } = useAutofillStyle<'input'>(inputRef);\n const { locale } = useLocale();\n\n const formatter = useMemo(\n () => new Intl.NumberFormat(locale, props.formatOptions),\n [locale, props.formatOptions]\n );\n\n const formattingResult = useNumberFieldFormatting({\n inputRef,\n formatter,\n inputValue: inputProps.value as string,\n prefix,\n postfix,\n onOriginalKeyDown: inputProps.onKeyDown,\n onChange: props.onChange,\n autoFormat,\n });\n\n const { extractedPrefix, extractedPostfix, handleInput, handleKeyDown } =\n autoFormat\n ? formattingResult\n : {\n extractedPrefix: formattingResult.extractedPrefix,\n extractedPostfix: formattingResult.extractedPostfix,\n handleInput: undefined,\n handleKeyDown: inputProps.onKeyDown,\n };\n\n const containerRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n ...createFocusableRef(containerRef, inputRef),\n /**\n * (This function is deprecated. Use `inputRef` prop)\n * @deprecated\n */\n getInputElement() {\n return inputRef.current;\n },\n }));\n\n return (\n <Field\n // otherProps contains some of the same props as inputProps. That is\n // intended, but some DOM props, like \"id\", should not be repeated\n {...removeUniqueDOMProps(otherProps)}\n ref={containerRef}\n size={size}\n labelPlacement={labelPlacement}\n >\n <Field.Context\n descriptionProps={error ? errorMessageProps : descriptionProps}\n >\n {label && (\n <Field.Label>\n <Label\n {...labelProps}\n size={size}\n necessityIndicator={\n isRequired && necessityIndicator\n ? 'required'\n : !isRequired && necessityIndicator\n ? 'optional'\n : undefined\n }\n contextualHelp={contextualHelp}\n >\n {label}\n </Label>\n </Field.Label>\n )}\n <Field.Control>\n <div\n className={clsx(textFieldStyles['sapphire-text-field'], {\n [textFieldStyles['is-focus']]: isFocusVisible,\n [textFieldStyles['sapphire-text-field--error']]:\n error === true || typeof error === 'string',\n [textFieldStyles['sapphire-text-field--md']]: size === 'md',\n })}\n >\n {extractedPrefix && (\n <span\n className={clsx(\n textFieldStyles['sapphire-text-field__prefix'],\n {\n [textFieldStyles['sapphire-text-field__prefix--icon']]:\n typeof extractedPrefix !== 'string',\n }\n )}\n >\n {extractedPrefix}\n </span>\n )}\n <input\n {...mergeProps(\n inputProps,\n focusProps,\n {\n onChange: updateStyle,\n onBlur: updateStyle,\n },\n autoFormat\n ? {\n onInput: handleInput,\n onKeyDown: handleKeyDown,\n }\n : {}\n )}\n value={formattingResult?.displayValue ?? inputProps.value}\n ref={inputRef}\n className={clsx(textFieldStyles['sapphire-text-field__input'], {\n [textFieldStyles['sapphire-text-field__input--align-right']]:\n !!alignInputRight,\n })}\n style={autofillStyles}\n />\n {extractedPostfix && (\n <span\n className={clsx(\n textFieldStyles['sapphire-text-field__postfix'],\n {\n [textFieldStyles['sapphire-text-field__postfix--icon']]:\n typeof extractedPostfix !== 'string',\n }\n )}\n >\n {extractedPostfix}\n </span>\n )}\n {showButtons && (\n <div className={textFieldStyles['sapphire-text-field__stepper']}>\n <StepperButton\n variant=\"decrement\"\n size={size}\n {...decrementButtonProps}\n />\n <Separator orientation=\"vertical\" />\n <StepperButton\n variant=\"increment\"\n size={size}\n {...incrementButtonProps}\n />\n </div>\n )}\n </div>\n </Field.Control>\n {((error && typeof error !== 'boolean') || note) && (\n <Field.Footer>\n {error && typeof error !== 'boolean' ? (\n <Field.Note variant=\"error\">{error}</Field.Note>\n ) : note ? (\n note\n ) : (\n <></>\n )}\n </Field.Footer>\n )}\n </Field.Context>\n </Field>\n );\n});\n\n// Once moved to the core package, this function should be removed and instead consume the one from TextFieldBase.\nconst removeUniqueDOMProps = (props: Record<any, any>): Record<any, any> =>\n Object.fromEntries(\n Object.entries(props).filter(\n ([name]) => name !== 'id' && !name.startsWith('data-')\n )\n );\n"],"names":["NumberField"],"mappings":";;;;;;;;;;;;;;AAkGO,MAAM,WAAA,GAAc,UAAA,CAAW,SAASA,YAAAA,CAC7C,OACA,GAAA,EACA;AACA,EAAA,MAAM;AAAA,IACJ,KAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAA;AAAA,IACA,cAAA;AAAA,IACA,KAAA,GAAQ,MAAA;AAAA,IACR,IAAA,GAAO,IAAA;AAAA,IACP,cAAA,GAAiB,OAAA;AAAA,IACjB,kBAAA,GAAqB,KAAA;AAAA,IACrB,eAAA;AAAA,IACA,WAAA,GAAc,KAAA;AAAA,IACd,kBAAA;AAAA,IACA,kBAAA;AAAA,IACA,UAAA,GAAa,KAAA;AAAA,IACb,GAAG;AAAA,GACL,GAAI,KAAA;AAGJ,EAAA,MAAM,EAAE,MAAA,EAAQ,OAAA,EAAQ,GAAI,QAAQ,MAAM;AACxC,IAAA,IAAI,UAAU,MAAA,EAAQ;AACpB,MAAA,OAAO,EAAE,MAAA,EAAQ,MAAA,EAAW,OAAA,EAAS,MAAA,EAAU;AAAA,IACjD;AACA,IAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,EACxD,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AACV,EAAA,aAAA,EAAc;AACd,EAAA,MAAM,QAAA,GAAW,YAAA,CAA+B,KAAA,CAAM,QAAQ,CAAA;AAC9D,EAAA,MAAM,aAAA,GAAgB,oBAAoB,YAAY,CAAA;AAEtD,EAAA,MAAM;AAAA,IACJ,UAAA;AAAA,IACA,UAAA;AAAA,IACA,oBAAA;AAAA,IACA,oBAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACF,GAAI,s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;AAAA,YACR,IAAA;AAAA,YACC,GAAG;AAAA;AAAA,SACN,kBACA,KAAA,CAAA,aAAA,CAAC,SAAA,EAAA,EAAU,WAAA,EAAY,YAAW,CAAA,kBAClC,KAAA,CAAA,aAAA;AAAA,UAAC,aAAA;AAAA,UAAA;AAAA,YACC,OAAA,EAAQ,WAAA;AAAA,YACR,IAAA;AAAA,YACC,GAAG;AAAA;AAAA,SAER;AAAA,OAGN,CAAA;AAAA,MAAA,CACG,KAAA,IAAS,OAAO,KAAA,KAAU,SAAA,IAAc,IAAA,yCACxC,KAAA,CAAM,MAAA,EAAN,IAAA,EACE,KAAA,IAAS,OAAO,KAAA,KAAU,4BACzB,KAAA,CAAA,aAAA,CAAC,KAAA,CAAM,IAAA,EAAN,EAAW,OAAA,EAAQ,OAAA,EAAA,EAAS,KAAM,CAAA,GACjC,IAAA,GACF,IAAA,mBAEA,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAE,CAEN;AAAA;AAEJ,GACF;AAEJ,CAAC;AAGD,MAAM,oBAAA,GAAuB,CAAC,KAAA,KAC5B,MAAA,CAAO,WAAA;AAAA,EACL,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,MAAA;AAAA,IACpB,CAAC,CAAC,IAAI,CAAA,KAAM,SAAS,IAAA,IAAQ,CAAC,IAAA,CAAK,UAAA,CAAW,OAAO;AAAA;AAEzD,CAAA;;;;"}
|
|
@@ -7,60 +7,38 @@ import { useButton, Icon } from '@danske/sapphire-react';
|
|
|
7
7
|
import { Add, Subtract } from '@danske/sapphire-icons/react';
|
|
8
8
|
import { useFocusRing } from '@react-aria/focus';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
16
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
-
var __spreadValues = (a, b) => {
|
|
18
|
-
for (var prop in b || (b = {}))
|
|
19
|
-
if (__hasOwnProp.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
if (__getOwnPropSymbols)
|
|
22
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
23
|
-
if (__propIsEnum.call(b, prop))
|
|
24
|
-
__defNormalProp(a, prop, b[prop]);
|
|
25
|
-
}
|
|
26
|
-
return a;
|
|
27
|
-
};
|
|
28
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
|
-
var __objRest = (source, exclude) => {
|
|
30
|
-
var target = {};
|
|
31
|
-
for (var prop in source)
|
|
32
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
if (source != null && __getOwnPropSymbols)
|
|
35
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
36
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
37
|
-
target[prop] = source[prop];
|
|
38
|
-
}
|
|
39
|
-
return target;
|
|
40
|
-
};
|
|
41
|
-
const StepperButton = (_a) => {
|
|
42
|
-
var _b = _a, {
|
|
43
|
-
variant,
|
|
44
|
-
size
|
|
45
|
-
} = _b, props = __objRest(_b, [
|
|
46
|
-
"variant",
|
|
47
|
-
"size"
|
|
48
|
-
]);
|
|
10
|
+
const StepperButton = ({
|
|
11
|
+
variant,
|
|
12
|
+
size,
|
|
13
|
+
...props
|
|
14
|
+
}) => {
|
|
49
15
|
const ref = useRef(null);
|
|
50
16
|
const { buttonProps, isPressed } = useButton(props, ref);
|
|
51
17
|
const { hoverProps, isHovered } = useHover({ isDisabled: props.isDisabled });
|
|
52
18
|
const { focusProps, isFocusVisible } = useFocusRing();
|
|
53
|
-
return /* @__PURE__ */ React.createElement(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
19
|
+
return /* @__PURE__ */ React.createElement(
|
|
20
|
+
"button",
|
|
21
|
+
{
|
|
22
|
+
...mergeProps(
|
|
23
|
+
buttonProps,
|
|
24
|
+
hoverProps,
|
|
25
|
+
focusProps,
|
|
26
|
+
filterDOMProps(props, { global: true })
|
|
27
|
+
),
|
|
28
|
+
tabIndex: 0,
|
|
29
|
+
ref,
|
|
30
|
+
className: clsx(
|
|
31
|
+
textFieldStyles["sapphire-text-field__stepper-button"],
|
|
32
|
+
textFieldStyles["js-hover"],
|
|
33
|
+
{
|
|
34
|
+
[textFieldStyles["is-active"]]: isPressed,
|
|
35
|
+
[textFieldStyles["is-hover"]]: isHovered,
|
|
36
|
+
[textFieldStyles["is-focus"]]: isFocusVisible
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
/* @__PURE__ */ React.createElement(Icon, { size: size === "lg" ? "md" : "sm" }, variant === "increment" ? /* @__PURE__ */ React.createElement(Add, null) : /* @__PURE__ */ React.createElement(Subtract, null))
|
|
41
|
+
);
|
|
64
42
|
};
|
|
65
43
|
|
|
66
44
|
export { StepperButton };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepperButton.js","sources":["../../../../src/NumberField/src/StepperButton.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { AriaButtonProps } from '@react-aria/button';\nimport { useHover } from '@react-aria/interactions';\nimport { filterDOMProps, mergeProps } from '@react-aria/utils';\nimport clsx from 'clsx';\nimport styles from '@danske/sapphire-css/components/textField/textField.module.css';\nimport { Icon, useButton } from '@danske/sapphire-react';\nimport { Add, Subtract } from '@danske/sapphire-icons/react';\nimport { useFocusRing } from '@react-aria/focus';\n\n/**\n * @internal\n */\nexport const StepperButton = ({\n variant,\n size,\n ...props\n}: AriaButtonProps & {\n variant: 'increment' | 'decrement';\n size: 'lg' | 'md';\n}): React.JSX.Element => {\n const ref = useRef(null);\n const { buttonProps, isPressed } = useButton(props, ref);\n const { hoverProps, isHovered } = useHover({ isDisabled: props.isDisabled });\n const { focusProps, isFocusVisible } = useFocusRing();\n\n return (\n <button\n {...mergeProps(\n buttonProps,\n hoverProps,\n focusProps,\n filterDOMProps(props, { global: true })\n )}\n tabIndex={0} // tabIndex comes as \"-1\" from the react-aria hook\n ref={ref}\n className={clsx(\n styles['sapphire-text-field__stepper-button'],\n styles['js-hover'],\n {\n [styles['is-active']]: isPressed,\n [styles['is-hover']]: isHovered,\n [styles['is-focus']]: isFocusVisible,\n }\n )}\n >\n <Icon size={size === 'lg' ? 'md' : 'sm'}>\n {variant === 'increment' ? <Add /> : <Subtract />}\n </Icon>\n </button>\n );\n};\n"],"names":["styles"],"mappings":"
|
|
1
|
+
{"version":3,"file":"StepperButton.js","sources":["../../../../src/NumberField/src/StepperButton.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { AriaButtonProps } from '@react-aria/button';\nimport { useHover } from '@react-aria/interactions';\nimport { filterDOMProps, mergeProps } from '@react-aria/utils';\nimport clsx from 'clsx';\nimport styles from '@danske/sapphire-css/components/textField/textField.module.css';\nimport { Icon, useButton } from '@danske/sapphire-react';\nimport { Add, Subtract } from '@danske/sapphire-icons/react';\nimport { useFocusRing } from '@react-aria/focus';\n\n/**\n * @internal\n */\nexport const StepperButton = ({\n variant,\n size,\n ...props\n}: AriaButtonProps & {\n variant: 'increment' | 'decrement';\n size: 'lg' | 'md';\n}): React.JSX.Element => {\n const ref = useRef(null);\n const { buttonProps, isPressed } = useButton(props, ref);\n const { hoverProps, isHovered } = useHover({ isDisabled: props.isDisabled });\n const { focusProps, isFocusVisible } = useFocusRing();\n\n return (\n <button\n {...mergeProps(\n buttonProps,\n hoverProps,\n focusProps,\n filterDOMProps(props, { global: true })\n )}\n tabIndex={0} // tabIndex comes as \"-1\" from the react-aria hook\n ref={ref}\n className={clsx(\n styles['sapphire-text-field__stepper-button'],\n styles['js-hover'],\n {\n [styles['is-active']]: isPressed,\n [styles['is-hover']]: isHovered,\n [styles['is-focus']]: isFocusVisible,\n }\n )}\n >\n <Icon size={size === 'lg' ? 'md' : 'sm'}>\n {variant === 'increment' ? <Add /> : <Subtract />}\n </Icon>\n </button>\n );\n};\n"],"names":["styles"],"mappings":";;;;;;;;;AAaO,MAAM,gBAAgB,CAAC;AAAA,EAC5B,OAAA;AAAA,EACA,IAAA;AAAA,EACA,GAAG;AACL,CAAA,KAGyB;AACvB,EAAA,MAAM,GAAA,GAAM,OAAO,IAAI,CAAA;AACvB,EAAA,MAAM,EAAE,WAAA,EAAa,SAAA,EAAU,GAAI,SAAA,CAAU,OAAO,GAAG,CAAA;AACvD,EAAA,MAAM,EAAE,YAAY,SAAA,EAAU,GAAI,SAAS,EAAE,UAAA,EAAY,KAAA,CAAM,UAAA,EAAY,CAAA;AAC3E,EAAA,MAAM,EAAE,UAAA,EAAY,cAAA,EAAe,GAAI,YAAA,EAAa;AAEpD,EAAA,uBACE,KAAA,CAAA,aAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACE,GAAG,UAAA;AAAA,QACF,WAAA;AAAA,QACA,UAAA;AAAA,QACA,UAAA;AAAA,QACA,cAAA,CAAe,KAAA,EAAO,EAAE,MAAA,EAAQ,MAAM;AAAA,OACxC;AAAA,MACA,QAAA,EAAU,CAAA;AAAA,MACV,GAAA;AAAA,MACA,SAAA,EAAW,IAAA;AAAA,QACTA,gBAAO,qCAAqC,CAAA;AAAA,QAC5CA,gBAAO,UAAU,CAAA;AAAA,QACjB;AAAA,UACE,CAACA,eAAA,CAAO,WAAW,CAAC,GAAG,SAAA;AAAA,UACvB,CAACA,eAAA,CAAO,UAAU,CAAC,GAAG,SAAA;AAAA,UACtB,CAACA,eAAA,CAAO,UAAU,CAAC,GAAG;AAAA;AACxB;AACF,KAAA;AAAA,oBAEA,KAAA,CAAA,aAAA,CAAC,IAAA,EAAA,EAAK,IAAA,EAAM,IAAA,KAAS,OAAO,IAAA,GAAO,IAAA,EAAA,EAChC,OAAA,KAAY,WAAA,mBAAc,KAAA,CAAA,aAAA,CAAC,GAAA,EAAA,IAAI,CAAA,mBAAK,KAAA,CAAA,aAAA,CAAC,cAAS,CACjD;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -2,8 +2,7 @@ const isDeleteOperation = (inputType) => {
|
|
|
2
2
|
return inputType === "deleteContentBackward" || inputType === "deleteContentForward";
|
|
3
3
|
};
|
|
4
4
|
const calculateCursorPosition = (oldValue, newValue, oldCursor, inputType, decimalSeparator, numericValue) => {
|
|
5
|
-
if (!newValue)
|
|
6
|
-
return 0;
|
|
5
|
+
if (!newValue) return 0;
|
|
7
6
|
const oldDecimalPos = oldValue.indexOf(decimalSeparator);
|
|
8
7
|
const newDecimalPos = newValue.indexOf(decimalSeparator);
|
|
9
8
|
if (numericValue === 0 && isDeleteOperation(inputType)) {
|
|
@@ -12,8 +11,7 @@ const calculateCursorPosition = (oldValue, newValue, oldCursor, inputType, decim
|
|
|
12
11
|
const countDigits = (str, start, end) => {
|
|
13
12
|
let count = 0;
|
|
14
13
|
for (let i = start; i < end; i++) {
|
|
15
|
-
if (/[0-9]/.test(str[i]))
|
|
16
|
-
count++;
|
|
14
|
+
if (/[0-9]/.test(str[i])) count++;
|
|
17
15
|
}
|
|
18
16
|
return count;
|
|
19
17
|
};
|
|
@@ -21,7 +19,11 @@ const calculateCursorPosition = (oldValue, newValue, oldCursor, inputType, decim
|
|
|
21
19
|
return newDecimalPos;
|
|
22
20
|
}
|
|
23
21
|
if (oldDecimalPos >= 0 && oldCursor > oldDecimalPos && newDecimalPos >= 0) {
|
|
24
|
-
const digitsBeforeCursor = countDigits(
|
|
22
|
+
const digitsBeforeCursor = countDigits(
|
|
23
|
+
oldValue,
|
|
24
|
+
oldDecimalPos + 1,
|
|
25
|
+
oldCursor
|
|
26
|
+
);
|
|
25
27
|
let digitCount2 = 0;
|
|
26
28
|
for (let i = newDecimalPos + 1; i < newValue.length; i++) {
|
|
27
29
|
if (/[0-9]/.test(newValue[i]) && ++digitCount2 === digitsBeforeCursor) {
|
|
@@ -32,12 +34,15 @@ const calculateCursorPosition = (oldValue, newValue, oldCursor, inputType, decim
|
|
|
32
34
|
}
|
|
33
35
|
const oldEnd = oldDecimalPos >= 0 ? oldDecimalPos : oldValue.length;
|
|
34
36
|
const newEnd = newDecimalPos >= 0 ? newDecimalPos : newValue.length;
|
|
35
|
-
const intDigitsBeforeCursor = countDigits(
|
|
37
|
+
const intDigitsBeforeCursor = countDigits(
|
|
38
|
+
oldValue,
|
|
39
|
+
0,
|
|
40
|
+
Math.min(oldCursor, oldEnd)
|
|
41
|
+
);
|
|
36
42
|
if (intDigitsBeforeCursor === 0) {
|
|
37
43
|
if (isDeleteOperation(inputType)) {
|
|
38
44
|
for (let i = 0; i < newValue.length; i++) {
|
|
39
|
-
if (/[0-9]/.test(newValue[i]))
|
|
40
|
-
return i + 1;
|
|
45
|
+
if (/[0-9]/.test(newValue[i])) return i + 1;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
return 0;
|