@danske/sapphire-react-lab 0.79.1 → 0.81.0
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 +1278 -855
- package/build/cjs/index.js.map +1 -1
- package/build/esm/AlertDialog/src/AlertDialog.js +73 -0
- package/build/esm/AlertDialog/src/AlertDialog.js.map +1 -0
- package/build/esm/Avatar/src/Avatar.js +14 -1
- package/build/esm/Avatar/src/Avatar.js.map +1 -1
- package/build/esm/FeedbackMessage/src/FeedbackMessage.js +43 -11
- package/build/esm/FeedbackMessage/src/FeedbackMessage.js.map +1 -1
- package/build/esm/NumberField/i18n/da-DK.js +9 -0
- package/build/esm/NumberField/i18n/da-DK.js.map +1 -0
- package/build/esm/NumberField/i18n/de-DE.js +9 -0
- package/build/esm/NumberField/i18n/de-DE.js.map +1 -0
- package/build/esm/NumberField/i18n/en-US.js +9 -0
- package/build/esm/NumberField/i18n/en-US.js.map +1 -0
- package/build/esm/NumberField/i18n/fi-FI.js +9 -0
- package/build/esm/NumberField/i18n/fi-FI.js.map +1 -0
- package/build/esm/NumberField/i18n/index.js +20 -0
- package/build/esm/NumberField/i18n/index.js.map +1 -0
- package/build/esm/NumberField/i18n/nb-NO.js +9 -0
- package/build/esm/NumberField/i18n/nb-NO.js.map +1 -0
- package/build/esm/NumberField/i18n/pl-PL.js +9 -0
- package/build/esm/NumberField/i18n/pl-PL.js.map +1 -0
- package/build/esm/NumberField/i18n/sv-SE.js +9 -0
- package/build/esm/NumberField/i18n/sv-SE.js.map +1 -0
- package/build/esm/NumberField/src/NumberField.js +149 -0
- package/build/esm/NumberField/src/NumberField.js.map +1 -0
- package/build/esm/NumberField/src/StepperButton.js +63 -0
- package/build/esm/NumberField/src/StepperButton.js.map +1 -0
- package/build/esm/NumberField/src/useAutofillStyle.js +21 -0
- package/build/esm/NumberField/src/useAutofillStyle.js.map +1 -0
- package/build/esm/NumberField/src/useSapphireNumberField.js +49 -0
- package/build/esm/NumberField/src/useSapphireNumberField.js.map +1 -0
- package/build/esm/index.js +2 -0
- package/build/esm/index.js.map +1 -1
- package/build/index.d.ts +108 -8
- package/package.json +5 -3
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useThemeCheck, Dialog } from '@danske/sapphire-react';
|
|
3
|
+
import { FeedbackMessage } from '../../FeedbackMessage/src/FeedbackMessage.js';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
const AlertDialog = React.forwardRef(function AlertDialog2(props, ref) {
|
|
34
|
+
useThemeCheck();
|
|
35
|
+
const _a = props, {
|
|
36
|
+
variant = "neutral",
|
|
37
|
+
icon,
|
|
38
|
+
body,
|
|
39
|
+
actionsOrientation = "horizontal",
|
|
40
|
+
actions,
|
|
41
|
+
heading
|
|
42
|
+
} = _a, rest = __objRest(_a, [
|
|
43
|
+
"variant",
|
|
44
|
+
"icon",
|
|
45
|
+
"body",
|
|
46
|
+
"actionsOrientation",
|
|
47
|
+
"actions",
|
|
48
|
+
"heading"
|
|
49
|
+
]);
|
|
50
|
+
return /* @__PURE__ */ React.createElement(Dialog, __spreadValues({
|
|
51
|
+
ref,
|
|
52
|
+
role: "alertdialog",
|
|
53
|
+
type: "active",
|
|
54
|
+
size: "extra-small",
|
|
55
|
+
header: /* @__PURE__ */ React.createElement(React.Fragment, null),
|
|
56
|
+
content: /* @__PURE__ */ React.createElement(Dialog.Content, null, /* @__PURE__ */ React.createElement(FeedbackMessage, {
|
|
57
|
+
heading: /* @__PURE__ */ React.createElement(Dialog.Header, {
|
|
58
|
+
level: 6,
|
|
59
|
+
heading
|
|
60
|
+
}),
|
|
61
|
+
variant,
|
|
62
|
+
icon,
|
|
63
|
+
body
|
|
64
|
+
})),
|
|
65
|
+
footer: /* @__PURE__ */ React.createElement(Dialog.Footer, {
|
|
66
|
+
stretch: "autoVertical",
|
|
67
|
+
orientation: actionsOrientation
|
|
68
|
+
}, actions)
|
|
69
|
+
}, rest));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export { AlertDialog };
|
|
73
|
+
//# sourceMappingURL=AlertDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlertDialog.js","sources":["../../../../src/AlertDialog/src/AlertDialog.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n Dialog,\n DialogProps,\n SapphireStyleProps,\n useThemeCheck,\n} from '@danske/sapphire-react';\nimport {\n FeedbackMessage,\n SapphireFeedbackMessageProps,\n} from '../../FeedbackMessage';\nimport { AriaModalOverlayProps } from '@react-aria/overlays';\nimport { DOMRef } from '@react-types/shared';\n\nexport type SapphireAlertDialogProps = AriaModalOverlayProps &\n SapphireStyleProps &\n Pick<DialogProps, 'isOpen' | 'onClose'> &\n Omit<SapphireFeedbackMessageProps, 'heading' | 'actions'> & {\n /**\n *\n * @default \"horizontal\"\n */\n actionsOrientation?: 'vertical' | 'horizontal';\n /**\n * The elements that will be rendered in the footer of the dialog.\n */\n actions: ReactNode;\n /**\n * The title of the dialog.\n */\n heading: string;\n };\n\nexport const AlertDialog = React.forwardRef(function AlertDialog(\n props: SapphireAlertDialogProps,\n ref: DOMRef<HTMLDivElement>\n) {\n useThemeCheck();\n\n const {\n variant = 'neutral',\n icon,\n body,\n actionsOrientation = 'horizontal',\n actions,\n heading,\n ...rest\n } = props;\n\n return (\n <Dialog\n ref={ref}\n role=\"alertdialog\"\n type=\"active\"\n size=\"extra-small\"\n header={<></>}\n content={\n <Dialog.Content>\n <FeedbackMessage\n heading={<Dialog.Header level={6} heading={heading} />}\n variant={variant}\n icon={icon}\n body={body}\n />\n </Dialog.Content>\n }\n footer={\n <Dialog.Footer stretch=\"autoVertical\" orientation={actionsOrientation}>\n {actions}\n </Dialog.Footer>\n }\n {...rest}\n />\n );\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,MAAM,WAAc,GAAA,KAAA,CAAM,UAAW,CAAA,SAAA,YAAA,CAC1C,OACA,GACA,EAAA;AACA,EAAA,aAAA,EAAA,CAAA;AAEA,EAAA,MAQI,EAPF,GAAA,KAAA,EAAA;AAAA,IAAU,OAAA,GAAA,SAAA;AAAA,IACV,IAAA;AAAA,IACA,IAAA;AAAA,IACA,kBAAqB,GAAA,YAAA;AAAA,IACrB,OAAA;AAAA,IACA,OAAA;AAAA,GAEE,GAAA,EAAA,EADC,iBACD,EADC,EAAA;AAAA,IANH,SAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,oBAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,GAAA,CAAA,CAAA;AAIF,EAAA,2CACG,MAAD,EAAA,cAAA,CAAA;AAAA,IACE,GAAA;AAAA,IACA,IAAK,EAAA,aAAA;AAAA,IACL,IAAK,EAAA,QAAA;AAAA,IACL,IAAK,EAAA,aAAA;AAAA,IACL,MAAQ,kBAAA,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,CAAA;AAAA,IACR,yBACG,KAAA,CAAA,aAAA,CAAA,MAAA,CAAO,OAAR,EAAA,IAAA,sCACG,eAAD,EAAA;AAAA,MACE,OAAA,kBAAU,KAAA,CAAA,aAAA,CAAA,MAAA,CAAO,MAAR,EAAA;AAAA,QAAe,KAAO,EAAA,CAAA;AAAA,QAAG,OAAA;AAAA,OAAA,CAAA;AAAA,MAClC,OAAA;AAAA,MACA,IAAA;AAAA,MACA,IAAA;AAAA,KAAA,CAAA,CAAA;AAAA,IAIN,MAAA,kBACG,KAAA,CAAA,aAAA,CAAA,MAAA,CAAO,MAAR,EAAA;AAAA,MAAe,OAAQ,EAAA,cAAA;AAAA,MAAe,WAAa,EAAA,kBAAA;AAAA,KAChD,EAAA,OAAA,CAAA;AAAA,GAGD,EAAA,IAAA,CAAA,CAAA,CAAA;AAAA,CAAA;;;;"}
|
|
@@ -34,6 +34,18 @@ var __objRest = (source, exclude) => {
|
|
|
34
34
|
}
|
|
35
35
|
return target;
|
|
36
36
|
};
|
|
37
|
+
const getIconSize = (size) => {
|
|
38
|
+
switch (size) {
|
|
39
|
+
case "medium":
|
|
40
|
+
return "m";
|
|
41
|
+
case "large":
|
|
42
|
+
return "l";
|
|
43
|
+
case "extraLarge":
|
|
44
|
+
return "xl";
|
|
45
|
+
default:
|
|
46
|
+
return "s";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
37
49
|
const Avatar = (_a) => {
|
|
38
50
|
var _b = _a, {
|
|
39
51
|
monogram,
|
|
@@ -50,12 +62,13 @@ const Avatar = (_a) => {
|
|
|
50
62
|
const { styleProps } = useSapphireStyleProps(props);
|
|
51
63
|
return /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, styleProps), {
|
|
52
64
|
className: clsx(styleProps.className, styles["sapphire-avatar"], {
|
|
65
|
+
[styles["sapphire-avatar--extra-large"]]: size === "extraLarge",
|
|
53
66
|
[styles["sapphire-avatar--large"]]: size === "large",
|
|
54
67
|
[styles["sapphire-avatar--small"]]: size === "small",
|
|
55
68
|
[styles["sapphire-avatar--extra-small"]]: size === "extraSmall"
|
|
56
69
|
}, color !== "passive" && styles[`sapphire-avatar--${color}`])
|
|
57
70
|
}), icon ? /* @__PURE__ */ React.createElement(Icon, {
|
|
58
|
-
size: size
|
|
71
|
+
size: getIconSize(size)
|
|
59
72
|
}, icon) : monogram);
|
|
60
73
|
};
|
|
61
74
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sources":["../../../../src/Avatar/src/Avatar.tsx"],"sourcesContent":["import {\n Icon,\n SapphireStyleProps,\n useSapphireStyleProps,\n useThemeCheck,\n} from '@danske/sapphire-react';\nimport React, { ReactNode } from 'react';\nimport styles from '@danske/sapphire-css/components/avatar/avatar.module.css';\nimport clsx from 'clsx';\n\nexport type SapphireAvatarProps = SapphireStyleProps & {\n /**\n * @default 'medium'\n */\n size?: 'large' | 'medium' | 'small' | 'extraSmall';\n\n /**\n * The background color of the avatar.\n * Can either be semantic or one of the named decorative colors.\n *\n * @default 'informative'\n */\n\n color?:\n | 'positive'\n | 'negative'\n | 'warning'\n | 'informative'\n | 'passive'\n | 'aqua'\n | 'copper'\n | 'electro'\n | 'indigo'\n | 'lime'\n | 'pink'\n | 'violet'\n | 'gold'\n | 'beige'\n | 'orchid'\n | 'gray'\n | 'cobalt'\n | 'forestGreen'\n | 'teal'\n | 'orange';\n} & (\n | {\n monogram: ReactNode;\n icon?: never;\n }\n | {\n monogram?: never;\n icon: ReactNode;\n }\n );\n\nexport const Avatar = ({\n monogram,\n icon,\n color = 'informative',\n size = 'medium',\n ...props\n}: SapphireAvatarProps): React.ReactElement => {\n useThemeCheck();\n const { styleProps } = useSapphireStyleProps(props);\n\n return (\n <div\n {...styleProps}\n className={clsx(\n styleProps.className,\n styles['sapphire-avatar'],\n {\n [styles['sapphire-avatar--large']]: size === 'large',\n [styles['sapphire-avatar--small']]: size === 'small',\n [styles['sapphire-avatar--extra-small']]: size === 'extraSmall',\n },\n color !== 'passive' && styles[`sapphire-avatar--${color}`]\n )}\n >\n {icon ?
|
|
1
|
+
{"version":3,"file":"Avatar.js","sources":["../../../../src/Avatar/src/Avatar.tsx"],"sourcesContent":["import {\n Icon,\n SapphireStyleProps,\n useSapphireStyleProps,\n useThemeCheck,\n} from '@danske/sapphire-react';\nimport React, { ReactNode } from 'react';\nimport styles from '@danske/sapphire-css/components/avatar/avatar.module.css';\nimport clsx from 'clsx';\n\nconst getIconSize = (\n size?: 'extraLarge' | 'large' | 'medium' | 'small' | 'extraSmall'\n) => {\n switch (size) {\n case 'medium':\n return 'm';\n case 'large':\n return 'l';\n case 'extraLarge':\n return 'xl';\n default:\n return 's';\n }\n};\n\nexport type SapphireAvatarProps = SapphireStyleProps & {\n /**\n * @default 'medium'\n */\n size?: 'extraLarge' | 'large' | 'medium' | 'small' | 'extraSmall';\n\n /**\n * The background color of the avatar.\n * Can either be semantic or one of the named decorative colors.\n *\n * @default 'informative'\n */\n\n color?:\n | 'positive'\n | 'negative'\n | 'warning'\n | 'informative'\n | 'passive'\n | 'aqua'\n | 'copper'\n | 'electro'\n | 'indigo'\n | 'lime'\n | 'pink'\n | 'violet'\n | 'gold'\n | 'beige'\n | 'orchid'\n | 'gray'\n | 'cobalt'\n | 'forestGreen'\n | 'teal'\n | 'orange';\n} & (\n | {\n monogram: ReactNode;\n icon?: never;\n }\n | {\n monogram?: never;\n icon: ReactNode;\n }\n );\n\nexport const Avatar = ({\n monogram,\n icon,\n color = 'informative',\n size = 'medium',\n ...props\n}: SapphireAvatarProps): React.ReactElement => {\n useThemeCheck();\n const { styleProps } = useSapphireStyleProps(props);\n\n return (\n <div\n {...styleProps}\n className={clsx(\n styleProps.className,\n styles['sapphire-avatar'],\n {\n [styles['sapphire-avatar--extra-large']]: size === 'extraLarge',\n [styles['sapphire-avatar--large']]: size === 'large',\n [styles['sapphire-avatar--small']]: size === 'small',\n [styles['sapphire-avatar--extra-small']]: size === 'extraSmall',\n },\n color !== 'passive' && styles[`sapphire-avatar--${color}`]\n )}\n >\n {icon ? <Icon size={getIconSize(size)}>{icon}</Icon> : monogram}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,WAAA,GAAc,CAClB,IACG,KAAA;AACH,EAAQ,QAAA,IAAA;AAAA,IACD,KAAA,QAAA;AACH,MAAO,OAAA,GAAA,CAAA;AAAA,IACJ,KAAA,OAAA;AACH,MAAO,OAAA,GAAA,CAAA;AAAA,IACJ,KAAA,YAAA;AACH,MAAO,OAAA,IAAA,CAAA;AAAA,IAAA;AAEP,MAAO,OAAA,GAAA,CAAA;AAAA,GAAA;AAAA,CAAA,CAAA;AAiDA,MAAA,MAAA,GAAS,CAAC,EAMwB,KAAA;AANxB,EACrB,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAA,QAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAQ,GAAA,aAAA;AAAA,IACR,IAAO,GAAA,QAAA;AAAA,GAJc,GAAA,EAAA,EAKlB,kBALkB,EAKlB,EAAA;AAAA,IAJH,UAAA;AAAA,IACA,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAA;AAAA,GAAA,CAAA,CAAA;AAGA,EAAA,aAAA,EAAA,CAAA;AACA,EAAM,MAAA,EAAE,eAAe,qBAAsB,CAAA,KAAA,CAAA,CAAA;AAE7C,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,KAAD,EAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EACM,UADN,CAAA,EAAA;AAAA,IAEE,SAAW,EAAA,IAAA,CACT,UAAW,CAAA,SAAA,EACX,OAAO,iBACP,CAAA,EAAA;AAAA,MACG,CAAA,MAAA,CAAO,kCAAkC,IAAS,KAAA,YAAA;AAAA,MAClD,CAAA,MAAA,CAAO,4BAA4B,IAAS,KAAA,OAAA;AAAA,MAC5C,CAAA,MAAA,CAAO,4BAA4B,IAAS,KAAA,OAAA;AAAA,MAC5C,CAAA,MAAA,CAAO,kCAAkC,IAAS,KAAA,YAAA;AAAA,KAErD,EAAA,KAAA,KAAU,SAAa,IAAA,MAAA,CAAO,CAAoB,iBAAA,EAAA,KAAA,CAAA,CAAA,CAAA,CAAA;AAAA,GAGnD,CAAA,EAAA,IAAA,uCAAQ,IAAD,EAAA;AAAA,IAAM,MAAM,WAAY,CAAA,IAAA,CAAA;AAAA,GAAA,EAAQ,IAAe,CAAA,GAAA,QAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
4
|
-
import { useThemeCheck, useSapphireStyleProps,
|
|
3
|
+
import { Bell, AlertTriangle, AlertCircle, CheckMarkCircle } from '@danske/sapphire-icons/react';
|
|
4
|
+
import { useThemeCheck, useSapphireStyleProps, Heading } from '@danske/sapphire-react';
|
|
5
5
|
import styles from '@danske/sapphire-css/components/feedbackMessage/feedbackMessage.module.css';
|
|
6
|
+
import { Avatar } from '../../Avatar/src/Avatar.js';
|
|
6
7
|
|
|
7
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -19,17 +20,48 @@ var __objRest = (source, exclude) => {
|
|
|
19
20
|
}
|
|
20
21
|
return target;
|
|
21
22
|
};
|
|
23
|
+
const getColor = (variant) => {
|
|
24
|
+
switch (variant) {
|
|
25
|
+
case "success":
|
|
26
|
+
return "positive";
|
|
27
|
+
case "error":
|
|
28
|
+
return "negative";
|
|
29
|
+
case "neutral":
|
|
30
|
+
return "passive";
|
|
31
|
+
default:
|
|
32
|
+
return variant;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getIcon = (variant, icon) => {
|
|
36
|
+
if (icon) {
|
|
37
|
+
return icon;
|
|
38
|
+
}
|
|
39
|
+
switch (variant) {
|
|
40
|
+
case "success":
|
|
41
|
+
return /* @__PURE__ */ React.createElement(CheckMarkCircle, null);
|
|
42
|
+
case "error":
|
|
43
|
+
return /* @__PURE__ */ React.createElement(AlertCircle, null);
|
|
44
|
+
case "warning":
|
|
45
|
+
return /* @__PURE__ */ React.createElement(AlertTriangle, null);
|
|
46
|
+
case "informative":
|
|
47
|
+
return /* @__PURE__ */ React.createElement(Bell, null);
|
|
48
|
+
default:
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
22
52
|
const FeedbackMessage = (_a) => {
|
|
23
53
|
var _b = _a, {
|
|
24
54
|
heading,
|
|
25
55
|
body,
|
|
26
56
|
actions,
|
|
27
|
-
|
|
57
|
+
variant = "neutral",
|
|
58
|
+
icon
|
|
28
59
|
} = _b, otherProps = __objRest(_b, [
|
|
29
60
|
"heading",
|
|
30
61
|
"body",
|
|
31
62
|
"actions",
|
|
32
|
-
"
|
|
63
|
+
"variant",
|
|
64
|
+
"icon"
|
|
33
65
|
]);
|
|
34
66
|
useThemeCheck();
|
|
35
67
|
const {
|
|
@@ -38,15 +70,15 @@ const FeedbackMessage = (_a) => {
|
|
|
38
70
|
return /* @__PURE__ */ React.createElement("div", {
|
|
39
71
|
className: clsx(styles["sapphire-feedback-message"], className),
|
|
40
72
|
style
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
73
|
+
}, variant !== "neutral" && /* @__PURE__ */ React.createElement(Avatar, {
|
|
74
|
+
color: getColor(variant),
|
|
75
|
+
size: "extraLarge",
|
|
76
|
+
icon: getIcon(variant, icon)
|
|
77
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
46
78
|
className: styles["sapphire-feedback-message__content"]
|
|
47
|
-
}, /* @__PURE__ */ React.createElement(Heading, {
|
|
79
|
+
}, typeof heading === "string" ? /* @__PURE__ */ React.createElement(Heading, {
|
|
48
80
|
level: 3
|
|
49
|
-
}, heading), /* @__PURE__ */ React.createElement("section", {
|
|
81
|
+
}, heading) : heading, /* @__PURE__ */ React.createElement("section", {
|
|
50
82
|
className: styles["sapphire-feedback-message__body"]
|
|
51
83
|
}, body)), actions);
|
|
52
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedbackMessage.js","sources":["../../../../src/FeedbackMessage/src/FeedbackMessage.tsx"],"sourcesContent":["import React from 'react';\nimport clsx from 'clsx';\nimport {
|
|
1
|
+
{"version":3,"file":"FeedbackMessage.js","sources":["../../../../src/FeedbackMessage/src/FeedbackMessage.tsx"],"sourcesContent":["import React from 'react';\nimport clsx from 'clsx';\nimport {\n AlertCircle,\n AlertTriangle,\n Bell,\n CheckMarkCircle,\n} from '@danske/sapphire-icons/react';\nimport {\n Heading,\n SapphireStyleProps,\n useSapphireStyleProps,\n useThemeCheck,\n} from '@danske/sapphire-react';\nimport styles from '@danske/sapphire-css/components/feedbackMessage/feedbackMessage.module.css';\nimport { Avatar } from '../../Avatar';\n\nexport type FeedbackMessageVariant =\n | 'success'\n | 'error'\n | 'warning'\n | 'informative'\n | 'neutral';\n\nexport interface SapphireFeedbackMessageProps extends SapphireStyleProps {\n /**\n * Heading content, rendered in a sapphire Heading component.\n */\n heading: React.ReactNode | string;\n /**\n * The type of message.\n * The 'error' and 'success' are meant to attract more attention.\n *\n * @default 'neutral'\n */\n variant?: FeedbackMessageVariant;\n /**\n * Optional icon to override the default icon for the message type.\n */\n icon?: React.ReactNode;\n /**\n * Optional description, rendered as a section below heading.\n */\n body?: React.ReactNode;\n /**\n * Optional actions, rendered at the bottom. Use {@link ButtonGroup}\n * for the content.\n */\n actions?: React.ReactNode;\n}\n\nconst getColor = (variant: FeedbackMessageVariant) => {\n switch (variant) {\n case 'success':\n return 'positive';\n case 'error':\n return 'negative';\n case 'neutral':\n return 'passive';\n default:\n return variant;\n }\n};\n\nconst getIcon = (variant: FeedbackMessageVariant, icon?: React.ReactNode) => {\n if (icon) {\n return icon;\n }\n\n switch (variant) {\n case 'success':\n return <CheckMarkCircle />;\n case 'error':\n return <AlertCircle />;\n case 'warning':\n return <AlertTriangle />;\n case 'informative':\n return <Bell />;\n default:\n return null;\n }\n};\n\n/**\n * Implements layout and style of a feedback message.\n */\nexport const FeedbackMessage = ({\n heading,\n body,\n actions,\n variant = 'neutral',\n icon,\n ...otherProps\n}: SapphireFeedbackMessageProps): JSX.Element => {\n useThemeCheck();\n const {\n styleProps: { style, className },\n } = useSapphireStyleProps(otherProps);\n\n return (\n <div\n className={clsx(styles['sapphire-feedback-message'], className)}\n style={style}\n >\n {variant !== 'neutral' && (\n <Avatar\n color={getColor(variant)}\n size=\"extraLarge\"\n icon={getIcon(variant, icon)}\n />\n )}\n <div className={styles['sapphire-feedback-message__content']}>\n {typeof heading === 'string' ? (\n <Heading level={3}>{heading}</Heading>\n ) : (\n heading\n )}\n <section className={styles['sapphire-feedback-message__body']}>\n {body}\n </section>\n </div>\n {actions}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,QAAA,GAAW,CAAC,OAAoC,KAAA;AACpD,EAAQ,QAAA,OAAA;AAAA,IACD,KAAA,SAAA;AACH,MAAO,OAAA,UAAA,CAAA;AAAA,IACJ,KAAA,OAAA;AACH,MAAO,OAAA,UAAA,CAAA;AAAA,IACJ,KAAA,SAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IAAA;AAEP,MAAO,OAAA,OAAA,CAAA;AAAA,GAAA;AAAA,CAAA,CAAA;AAIb,MAAM,OAAA,GAAU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OAAA,CAAA;AAAA,IAChB,IAAK,EAAA,YAAA;AAAA,IACL,IAAA,EAAM,QAAQ,OAAS,EAAA,IAAA,CAAA;AAAA,GAAA,CAAA,sCAG1B,KAAD,EAAA;AAAA,IAAK,WAAW,MAAO,CAAA,oCAAA,CAAA;AAAA,GAAA,EACpB,OAAO,OAAA,KAAY,QAClB,mBAAA,KAAA,CAAA,aAAA,CAAC,OAAD,EAAA;AAAA,IAAS,KAAO,EAAA,CAAA;AAAA,GAAI,EAAA,OAAA,CAAA,GAEpB,OAEF,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAD,EAAA;AAAA,IAAS,WAAW,MAAO,CAAA,iCAAA,CAAA;AAAA,GAAA,EACxB,IAGJ,CAAA,CAAA,EAAA,OAAA,CAAA,CAAA;AAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"da-DK.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de-DE.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fi-FI.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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';
|
|
8
|
+
|
|
9
|
+
var intlMessages = {
|
|
10
|
+
"da-DK": da,
|
|
11
|
+
"en-US": en,
|
|
12
|
+
"de-DE": de,
|
|
13
|
+
"fi-FI": fi,
|
|
14
|
+
"nb-NO": no,
|
|
15
|
+
"pl-PL": pl,
|
|
16
|
+
"sv-SE": se
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { intlMessages as default };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,mBAAe;AAAA,EACb,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,EACT,OAAS,EAAA,EAAA;AAAA,CAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nb-NO.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pl-PL.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sv-SE.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useObjectRef, mergeProps } from '@react-aria/utils';
|
|
2
|
+
import { createFocusableRef } from '@react-spectrum/utils';
|
|
3
|
+
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
|
|
4
|
+
import { useSapphireNumberField } from './useSapphireNumberField.js';
|
|
5
|
+
import textFieldStyles from '@danske/sapphire-css/components/textField/textField.module.css';
|
|
6
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
7
|
+
import clsx from 'clsx';
|
|
8
|
+
import { useThemeCheck, useSapphireStyleProps, Field, Label } from '@danske/sapphire-react';
|
|
9
|
+
import { useAutofillStyle } from './useAutofillStyle.js';
|
|
10
|
+
import { useMessageFormatter } from '@react-aria/i18n';
|
|
11
|
+
import intlMessages from '../i18n/index.js';
|
|
12
|
+
import { StepperButton } from './StepperButton.js';
|
|
13
|
+
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __defProps = Object.defineProperties;
|
|
16
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
17
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
20
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
21
|
+
var __spreadValues = (a, b) => {
|
|
22
|
+
for (var prop in b || (b = {}))
|
|
23
|
+
if (__hasOwnProp.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
if (__getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
27
|
+
if (__propIsEnum.call(b, prop))
|
|
28
|
+
__defNormalProp(a, prop, b[prop]);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
};
|
|
32
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
33
|
+
var __objRest = (source, exclude) => {
|
|
34
|
+
var target = {};
|
|
35
|
+
for (var prop in source)
|
|
36
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
37
|
+
target[prop] = source[prop];
|
|
38
|
+
if (source != null && __getOwnPropSymbols)
|
|
39
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
40
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
41
|
+
target[prop] = source[prop];
|
|
42
|
+
}
|
|
43
|
+
return target;
|
|
44
|
+
};
|
|
45
|
+
const NumberField = forwardRef(function NumberField2(props, ref) {
|
|
46
|
+
const _a = props, {
|
|
47
|
+
label,
|
|
48
|
+
isDisabled,
|
|
49
|
+
error,
|
|
50
|
+
note,
|
|
51
|
+
isRequired,
|
|
52
|
+
contextualHelp,
|
|
53
|
+
prefix,
|
|
54
|
+
postfix,
|
|
55
|
+
size = "large",
|
|
56
|
+
labelPlacement = "above",
|
|
57
|
+
necessityIndicator = false,
|
|
58
|
+
alignInputRight,
|
|
59
|
+
showButtons = false,
|
|
60
|
+
incrementAriaLabel,
|
|
61
|
+
decrementAriaLabel
|
|
62
|
+
} = _a, otherProps = __objRest(_a, [
|
|
63
|
+
"label",
|
|
64
|
+
"isDisabled",
|
|
65
|
+
"error",
|
|
66
|
+
"note",
|
|
67
|
+
"isRequired",
|
|
68
|
+
"contextualHelp",
|
|
69
|
+
"prefix",
|
|
70
|
+
"postfix",
|
|
71
|
+
"size",
|
|
72
|
+
"labelPlacement",
|
|
73
|
+
"necessityIndicator",
|
|
74
|
+
"alignInputRight",
|
|
75
|
+
"showButtons",
|
|
76
|
+
"incrementAriaLabel",
|
|
77
|
+
"decrementAriaLabel"
|
|
78
|
+
]);
|
|
79
|
+
useThemeCheck();
|
|
80
|
+
const inputRef = useObjectRef(props.inputRef);
|
|
81
|
+
const formatMessage = useMessageFormatter(intlMessages);
|
|
82
|
+
const {
|
|
83
|
+
inputProps,
|
|
84
|
+
labelProps,
|
|
85
|
+
incrementButtonProps,
|
|
86
|
+
decrementButtonProps,
|
|
87
|
+
descriptionProps,
|
|
88
|
+
errorMessageProps
|
|
89
|
+
} = useSapphireNumberField(__spreadProps(__spreadValues({}, props), {
|
|
90
|
+
incrementAriaLabel: incrementAriaLabel != null ? incrementAriaLabel : formatMessage("increment"),
|
|
91
|
+
decrementAriaLabel: decrementAriaLabel != null ? decrementAriaLabel : formatMessage("decrement")
|
|
92
|
+
}), inputRef);
|
|
93
|
+
const { focusProps, isFocusVisible } = useFocusRing(props);
|
|
94
|
+
const { styleProps } = useSapphireStyleProps(props);
|
|
95
|
+
const { autofillStyles, updateStyle } = useAutofillStyle(inputRef);
|
|
96
|
+
const domRef = useRef(null);
|
|
97
|
+
useImperativeHandle(ref, () => __spreadProps(__spreadValues({}, createFocusableRef(domRef, inputRef)), {
|
|
98
|
+
getInputElement() {
|
|
99
|
+
return inputRef.current;
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
return /* @__PURE__ */ React.createElement(Field, __spreadProps(__spreadValues({}, removeUniqueDOMProps(otherProps)), {
|
|
103
|
+
ref: domRef,
|
|
104
|
+
isDisabled,
|
|
105
|
+
error: !!error,
|
|
106
|
+
size,
|
|
107
|
+
labelPlacement
|
|
108
|
+
}), label && /* @__PURE__ */ React.createElement(Field.Label, null, /* @__PURE__ */ React.createElement(Label, __spreadProps(__spreadValues({}, labelProps), {
|
|
109
|
+
size,
|
|
110
|
+
necessityIndicator: isRequired && necessityIndicator ? "required" : !isRequired && necessityIndicator ? "optional" : void 0,
|
|
111
|
+
contextualHelp
|
|
112
|
+
}), label)), /* @__PURE__ */ React.createElement(Field.Control, null, /* @__PURE__ */ React.createElement("div", {
|
|
113
|
+
className: clsx(textFieldStyles["sapphire-text-field"], {
|
|
114
|
+
[textFieldStyles["is-focus"]]: isFocusVisible,
|
|
115
|
+
[textFieldStyles["sapphire-text-field--error"]]: error === true || typeof error === "string",
|
|
116
|
+
[textFieldStyles["sapphire-text-field--medium"]]: size === "medium"
|
|
117
|
+
}),
|
|
118
|
+
style: __spreadValues({}, styleProps.style.width ? { width: styleProps.style.width } : {})
|
|
119
|
+
}, prefix && /* @__PURE__ */ React.createElement("span", {
|
|
120
|
+
className: clsx(textFieldStyles["sapphire-text-field__prefix"], {
|
|
121
|
+
[textFieldStyles["sapphire-text-field__prefix--icon"]]: typeof prefix !== "string"
|
|
122
|
+
})
|
|
123
|
+
}, prefix), /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({}, mergeProps(inputProps, focusProps, {
|
|
124
|
+
onChange: updateStyle,
|
|
125
|
+
onBlur: updateStyle
|
|
126
|
+
})), {
|
|
127
|
+
ref: inputRef,
|
|
128
|
+
className: clsx(textFieldStyles["sapphire-text-field__input"], {
|
|
129
|
+
[textFieldStyles["sapphire-text-field__input--align-right"]]: !!alignInputRight
|
|
130
|
+
}),
|
|
131
|
+
style: autofillStyles
|
|
132
|
+
})), postfix && /* @__PURE__ */ React.createElement("span", {
|
|
133
|
+
className: clsx(textFieldStyles["sapphire-text-field__postfix"], {
|
|
134
|
+
[textFieldStyles["sapphire-text-field__postfix--icon"]]: typeof postfix !== "string"
|
|
135
|
+
})
|
|
136
|
+
}, postfix), showButtons && /* @__PURE__ */ React.createElement("div", {
|
|
137
|
+
className: clsx(textFieldStyles["sapphire-text-field__stepper"])
|
|
138
|
+
}, /* @__PURE__ */ React.createElement(StepperButton, __spreadValues({
|
|
139
|
+
variant: "increment",
|
|
140
|
+
size
|
|
141
|
+
}, incrementButtonProps)), /* @__PURE__ */ React.createElement(StepperButton, __spreadValues({
|
|
142
|
+
variant: "decrement",
|
|
143
|
+
size
|
|
144
|
+
}, decrementButtonProps))))), (error || note) && /* @__PURE__ */ React.createElement(Field.Footer, null, error ? /* @__PURE__ */ React.createElement(Field.Note, __spreadValues({}, errorMessageProps), error) : note ? /* @__PURE__ */ React.createElement(Field.Note, __spreadValues({}, descriptionProps), note) : /* @__PURE__ */ React.createElement(React.Fragment, null)));
|
|
145
|
+
});
|
|
146
|
+
const removeUniqueDOMProps = (props) => Object.fromEntries(Object.entries(props).filter(([name]) => name !== "id" && !name.startsWith("data-")));
|
|
147
|
+
|
|
148
|
+
export { NumberField };
|
|
149
|
+
//# sourceMappingURL=NumberField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NumberField.js","sources":["../../../../src/NumberField/src/NumberField.tsx"],"sourcesContent":["import { mergeProps, useObjectRef } from '@react-aria/utils';\nimport { createFocusableRef } from '@react-spectrum/utils';\nimport { FocusableRefValue, PressEvents } from '@react-types/shared';\nimport React from 'react';\nimport {\n ForwardedRef,\n forwardRef,\n ReactNode,\n RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\nimport {\n SapphireNumberFieldProps,\n useSapphireNumberField,\n} from './useSapphireNumberField';\nimport textFieldStyles from '@danske/sapphire-css/components/textField/textField.module.css';\nimport { useFocusRing } from '@react-aria/focus';\nimport clsx from 'clsx';\nimport {\n Field,\n Label,\n SapphireStyleProps,\n useSapphireStyleProps,\n useThemeCheck,\n} from '@danske/sapphire-react';\nimport { useAutofillStyle } from './useAutofillStyle';\nimport { useMessageFormatter } from '@react-aria/i18n';\nimport intlMessages from '../i18n';\nimport { StepperButton } from './StepperButton';\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 prefix?: ReactNode;\n 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 ContextualHelp 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 'large'\n */\n size?: 'large' | 'medium';\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\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 prefix,\n postfix,\n size = 'large',\n labelPlacement = 'above',\n necessityIndicator = false,\n alignInputRight,\n showButtons = false,\n incrementAriaLabel,\n decrementAriaLabel,\n ...otherProps\n } = props;\n useThemeCheck();\n const inputRef = useObjectRef<HTMLInputElement>(props.inputRef);\n const formatMessage = useMessageFormatter(intlMessages);\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(props);\n const { styleProps } = useSapphireStyleProps(props);\n const { autofillStyles, updateStyle } = useAutofillStyle<'input'>(inputRef);\n\n const domRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n ...createFocusableRef(domRef, 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={domRef}\n isDisabled={isDisabled}\n error={!!error}\n size={size}\n labelPlacement={labelPlacement}\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--medium']]: size === 'medium',\n })}\n style={{\n ...(styleProps.style.width\n ? { width: styleProps.style.width }\n : {}),\n }}\n >\n {prefix && (\n <span\n className={clsx(textFieldStyles['sapphire-text-field__prefix'], {\n [textFieldStyles['sapphire-text-field__prefix--icon']]:\n typeof prefix !== 'string',\n })}\n >\n {prefix}\n </span>\n )}\n <input\n {...mergeProps(inputProps, focusProps, {\n onChange: updateStyle,\n onBlur: updateStyle,\n })}\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 {postfix && (\n <span\n className={clsx(textFieldStyles['sapphire-text-field__postfix'], {\n [textFieldStyles['sapphire-text-field__postfix--icon']]:\n typeof postfix !== 'string',\n })}\n >\n {postfix}\n </span>\n )}\n {showButtons && (\n <div\n className={clsx(textFieldStyles['sapphire-text-field__stepper'])}\n >\n <StepperButton\n variant=\"increment\"\n size={size}\n {...incrementButtonProps}\n />\n <StepperButton\n variant=\"decrement\"\n size={size}\n {...decrementButtonProps}\n />\n </div>\n )}\n </div>\n </Field.Control>\n {(error || note) && (\n <Field.Footer>\n {error ? (\n <Field.Note {...errorMessageProps}>{error}</Field.Note>\n ) : note ? (\n <Field.Note {...descriptionProps}>{note}</Field.Note>\n ) : (\n <></>\n )}\n </Field.Footer>\n )}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EO,MAAM,WAAc,GAAA,UAAA,CAAW,SACpC,YAAA,CAAA,KAAA,EACA,GACA,EAA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A,IACE,SAAA,EAAW,KAAK,eAAgB,CAAA,8BAAA,CAAA,CAAA;AAAA,GAAA,sCAE/B,aAAD,EAAA,cAAA,CAAA;AAAA,IACE,OAAQ,EAAA,WAAA;AAAA,IACR,IAAA;AAAA,GACI,EAAA,oBAAA,CAAA,CAAA,sCAEL,aAAD,EAAA,cAAA,CAAA;AAAA,IACE,OAAQ,EAAA,WAAA;AAAA,IACR,IAAA;AAAA,GACI,EAAA,oBAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAMZ,UAAS,IACT,qBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,MAAP,EAAA,IAAA,EACG,wBACE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAM,MAAP,cAAgB,CAAA,EAAA,EAAA,iBAAA,CAAA,EAAoB,SAClC,IACF,mBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,IAAP,EAAA,cAAA,CAAA,EAAA,EAAgB,mBAAmB,IAEnC,CAAA,mBAAA,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,CAAA,CAAA,CAAA,CAAA;AAAA,CAAA,EAAA;AASZ,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;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { useHover } from '@react-aria/interactions';
|
|
3
|
+
import { mergeProps, filterDOMProps } from '@react-aria/utils';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import textFieldStyles from '@danske/sapphire-css/components/textField/textField.module.css';
|
|
6
|
+
import { useButton, Icon } from '@danske/sapphire-react';
|
|
7
|
+
import { CaretUp, CaretDown } from '@danske/sapphire-icons/react';
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defProps = Object.defineProperties;
|
|
11
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
12
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
28
|
+
var __objRest = (source, exclude) => {
|
|
29
|
+
var target = {};
|
|
30
|
+
for (var prop in source)
|
|
31
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
if (source != null && __getOwnPropSymbols)
|
|
34
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
35
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
36
|
+
target[prop] = source[prop];
|
|
37
|
+
}
|
|
38
|
+
return target;
|
|
39
|
+
};
|
|
40
|
+
const StepperButton = (_a) => {
|
|
41
|
+
var _b = _a, {
|
|
42
|
+
variant,
|
|
43
|
+
size
|
|
44
|
+
} = _b, props = __objRest(_b, [
|
|
45
|
+
"variant",
|
|
46
|
+
"size"
|
|
47
|
+
]);
|
|
48
|
+
const ref = useRef(null);
|
|
49
|
+
const { buttonProps, isPressed } = useButton(props, ref);
|
|
50
|
+
const { hoverProps, isHovered } = useHover({ isDisabled: props.isDisabled });
|
|
51
|
+
return /* @__PURE__ */ React.createElement("button", __spreadProps(__spreadValues({}, mergeProps(buttonProps, hoverProps, filterDOMProps(props))), {
|
|
52
|
+
ref,
|
|
53
|
+
className: clsx(textFieldStyles["sapphire-text-field__stepper-button"], textFieldStyles["js-hover"], {
|
|
54
|
+
[textFieldStyles["is-active"]]: isPressed,
|
|
55
|
+
[textFieldStyles["is-hover"]]: isHovered
|
|
56
|
+
})
|
|
57
|
+
}), /* @__PURE__ */ React.createElement(Icon, {
|
|
58
|
+
size: size === "large" ? "m" : "s"
|
|
59
|
+
}, variant === "increment" ? /* @__PURE__ */ React.createElement(CaretUp, null) : /* @__PURE__ */ React.createElement(CaretDown, null)));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { StepperButton };
|
|
63
|
+
//# sourceMappingURL=StepperButton.js.map
|
|
@@ -0,0 +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 { CaretUp, CaretDown } from '@danske/sapphire-icons/react';\n\n/**\n * @internal\n */\nexport const StepperButton = ({\n variant,\n size,\n ...props\n}: AriaButtonProps & {\n variant: 'increment' | 'decrement';\n size: 'large' | 'medium';\n}) => {\n const ref = useRef(null);\n const { buttonProps, isPressed } = useButton(props, ref);\n const { hoverProps, isHovered } = useHover({ isDisabled: props.isDisabled });\n\n return (\n <button\n {...mergeProps(buttonProps, hoverProps, filterDOMProps(props))}\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 }\n )}\n >\n <Icon size={size === 'large' ? 'm' : 's'}>\n {variant === 'increment' ? <CaretUp /> : <CaretDown />}\n </Icon>\n </button>\n );\n};\n"],"names":["styles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYa,MAAA,aAAA,GAAgB,CAAC,EAOxB,KAAA;AAPwB,EAC5B,IAAA,EAAA,GAAA,EAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA,IAAA;AAAA,GAF4B,GAAA,EAAA,EAGzB,kBAHyB,EAGzB,EAAA;AAAA,IAFH,SAAA;AAAA,IACA,MAAA;AAAA,GAAA,CAAA,CAAA;AAMA,EAAA,MAAM,MAAM,MAAO,CAAA,IAAA,CAAA,CAAA;AACnB,EAAA,MAAM,EAAE,WAAA,EAAa,SAAc,EAAA,GAAA,SAAA,CAAU,KAAO,EAAA,GAAA,CAAA,CAAA;AACpD,EAAA,MAAM,EAAE,UAAY,EAAA,SAAA,EAAA,GAAc,QAAS,CAAA,EAAE,YAAY,KAAM,CAAA,UAAA,EAAA,CAAA,CAAA;AAE/D,EAAA,2CACG,QAAD,EAAA,aAAA,CAAA,cAAA,CAAA,EAAA,EACM,WAAW,WAAa,EAAA,UAAA,EAAY,eAAe,KADzD,CAAA,CAAA,CAAA,EAAA;AAAA,IAEE,GAAA;AAAA,IACA,SAAW,EAAA,IAAA,CACTA,eAAO,CAAA,qCAAA,CAAA,EACPA,gBAAO,UACP,CAAA,EAAA;AAAA,MAAA,CACGA,gBAAO,WAAe,CAAA,GAAA,SAAA;AAAA,MAAA,CACtBA,gBAAO,UAAc,CAAA,GAAA,SAAA;AAAA,KAAA,CAAA;AAAA,GAAA,CAAA,sCAIzB,IAAD,EAAA;AAAA,IAAM,IAAA,EAAM,IAAS,KAAA,OAAA,GAAU,GAAM,GAAA,GA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