@dnb/eufemia 10.51.1 → 10.51.2

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/cjs/components/badge/Badge.js +44 -37
  3. package/cjs/components/badge/Badge.js.map +1 -1
  4. package/cjs/extensions/forms/Field/Selection/Selection.js +1 -1
  5. package/cjs/extensions/forms/Field/Selection/Selection.js.map +1 -1
  6. package/cjs/extensions/forms/Form/Visibility/Visibility.d.ts +2 -2
  7. package/cjs/extensions/forms/Form/Visibility/Visibility.js.map +1 -1
  8. package/cjs/extensions/forms/hooks/useFieldProps.js +23 -20
  9. package/cjs/extensions/forms/hooks/useFieldProps.js.map +1 -1
  10. package/cjs/extensions/forms/types.d.ts +2 -2
  11. package/cjs/extensions/forms/types.js.map +1 -1
  12. package/cjs/extensions/forms/utils/ajv.js +1 -1
  13. package/cjs/extensions/forms/utils/ajv.js.map +1 -1
  14. package/cjs/extensions/forms/utils/json-pointer/json-pointer.js +1 -1
  15. package/cjs/extensions/forms/utils/json-pointer/json-pointer.js.map +1 -1
  16. package/cjs/shared/Eufemia.d.ts +1 -1
  17. package/cjs/shared/Eufemia.js +2 -2
  18. package/cjs/shared/Eufemia.js.map +1 -1
  19. package/cjs/shared/locales/en-GB.js +1 -1
  20. package/cjs/shared/locales/en-GB.js.map +1 -1
  21. package/cjs/style/core/scopes.scss +1 -1
  22. package/cjs/style/dnb-ui-basis.css +1 -1
  23. package/cjs/style/dnb-ui-basis.min.css +1 -1
  24. package/cjs/style/dnb-ui-body.css +1 -1
  25. package/cjs/style/dnb-ui-body.min.css +1 -1
  26. package/cjs/style/dnb-ui-core.css +1 -1
  27. package/cjs/style/dnb-ui-core.min.css +1 -1
  28. package/components/badge/Badge.js +44 -37
  29. package/components/badge/Badge.js.map +1 -1
  30. package/es/components/badge/Badge.js +43 -36
  31. package/es/components/badge/Badge.js.map +1 -1
  32. package/es/extensions/forms/Field/Selection/Selection.js +1 -1
  33. package/es/extensions/forms/Field/Selection/Selection.js.map +1 -1
  34. package/es/extensions/forms/Form/Visibility/Visibility.d.ts +2 -2
  35. package/es/extensions/forms/Form/Visibility/Visibility.js.map +1 -1
  36. package/es/extensions/forms/hooks/useFieldProps.js +22 -19
  37. package/es/extensions/forms/hooks/useFieldProps.js.map +1 -1
  38. package/es/extensions/forms/types.d.ts +2 -2
  39. package/es/extensions/forms/types.js.map +1 -1
  40. package/es/extensions/forms/utils/ajv.js +1 -1
  41. package/es/extensions/forms/utils/ajv.js.map +1 -1
  42. package/es/extensions/forms/utils/json-pointer/json-pointer.js +1 -1
  43. package/es/extensions/forms/utils/json-pointer/json-pointer.js.map +1 -1
  44. package/es/shared/Eufemia.d.ts +1 -1
  45. package/es/shared/Eufemia.js +2 -2
  46. package/es/shared/Eufemia.js.map +1 -1
  47. package/es/shared/locales/en-GB.js +1 -1
  48. package/es/shared/locales/en-GB.js.map +1 -1
  49. package/es/style/core/scopes.scss +1 -1
  50. package/es/style/dnb-ui-basis.css +1 -1
  51. package/es/style/dnb-ui-basis.min.css +1 -1
  52. package/es/style/dnb-ui-body.css +1 -1
  53. package/es/style/dnb-ui-body.min.css +1 -1
  54. package/es/style/dnb-ui-core.css +1 -1
  55. package/es/style/dnb-ui-core.min.css +1 -1
  56. package/esm/dnb-ui-basis.min.mjs +1 -1
  57. package/esm/dnb-ui-components.min.mjs +1 -1
  58. package/esm/dnb-ui-elements.min.mjs +1 -1
  59. package/esm/dnb-ui-extensions.min.mjs +2 -2
  60. package/esm/dnb-ui-lib.min.mjs +1 -1
  61. package/extensions/forms/Field/Selection/Selection.js +1 -1
  62. package/extensions/forms/Field/Selection/Selection.js.map +1 -1
  63. package/extensions/forms/Form/Visibility/Visibility.d.ts +2 -2
  64. package/extensions/forms/Form/Visibility/Visibility.js.map +1 -1
  65. package/extensions/forms/hooks/useFieldProps.js +22 -19
  66. package/extensions/forms/hooks/useFieldProps.js.map +1 -1
  67. package/extensions/forms/types.d.ts +2 -2
  68. package/extensions/forms/types.js.map +1 -1
  69. package/extensions/forms/utils/ajv.js +1 -1
  70. package/extensions/forms/utils/ajv.js.map +1 -1
  71. package/extensions/forms/utils/json-pointer/json-pointer.js +1 -1
  72. package/extensions/forms/utils/json-pointer/json-pointer.js.map +1 -1
  73. package/package.json +1 -1
  74. package/shared/Eufemia.d.ts +1 -1
  75. package/shared/Eufemia.js +2 -2
  76. package/shared/Eufemia.js.map +1 -1
  77. package/shared/locales/en-GB.js +1 -1
  78. package/shared/locales/en-GB.js.map +1 -1
  79. package/style/core/scopes.scss +1 -1
  80. package/style/dnb-ui-basis.css +1 -1
  81. package/style/dnb-ui-basis.min.css +1 -1
  82. package/style/dnb-ui-body.css +1 -1
  83. package/style/dnb-ui-body.min.css +1 -1
  84. package/style/dnb-ui-core.css +1 -1
  85. package/style/dnb-ui-core.min.css +1 -1
  86. package/umd/dnb-ui-basis.min.js +1 -1
  87. package/umd/dnb-ui-components.min.js +1 -1
  88. package/umd/dnb-ui-elements.min.js +1 -1
  89. package/umd/dnb-ui-extensions.min.js +3 -3
  90. package/umd/dnb-ui-lib.min.js +1 -1
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- const _excluded = ["label", "className", "children", "skeleton", "horizontal", "vertical", "content", "variant"];
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["label", "className", "children", "skeleton", "horizontal", "vertical", "content", "variant", "context"];
6
6
  import React from 'react';
7
7
  import classnames from 'classnames';
8
8
  import { createSpacingClasses } from '../space/SpacingHelper';
@@ -20,11 +20,31 @@ export const defaultProps = {
20
20
  variant: 'information'
21
21
  };
22
22
  function Badge(localProps) {
23
- var _span;
24
23
  const context = React.useContext(Context);
25
24
  const allProps = extendPropsWithContext(localProps, defaultProps, context === null || context === void 0 ? void 0 : context.Badge, {
26
25
  skeleton: context === null || context === void 0 ? void 0 : context.skeleton
27
26
  });
27
+ const {
28
+ children
29
+ } = allProps;
30
+ if (children) {
31
+ return React.createElement(BadgeRoot, null, children, React.createElement(BadgeElem, _extends({
32
+ context: context
33
+ }, allProps)));
34
+ }
35
+ return React.createElement(BadgeElem, _extends({
36
+ context: context
37
+ }, allProps));
38
+ }
39
+ function BadgeRoot(_ref) {
40
+ let {
41
+ children
42
+ } = _ref;
43
+ return React.createElement("span", {
44
+ className: "dnb-badge__root"
45
+ }, children);
46
+ }
47
+ function BadgeElem(props) {
28
48
  const {
29
49
  label,
30
50
  className,
@@ -33,42 +53,29 @@ function Badge(localProps) {
33
53
  horizontal,
34
54
  vertical,
35
55
  content: contentProp,
36
- variant
37
- } = allProps,
38
- props = _objectWithoutProperties(allProps, _excluded);
39
- validateDOMAttributes(allProps, props);
40
- if (children) {
41
- return React.createElement(BadgeRoot, null, children, React.createElement(BadgeElem, null));
42
- }
43
- return React.createElement(BadgeElem, null);
44
- function BadgeRoot(_ref) {
45
- let {
46
- children
47
- } = _ref;
48
- return React.createElement("span", {
49
- className: "dnb-badge__root"
50
- }, children);
56
+ variant,
57
+ context
58
+ } = props,
59
+ restProps = _objectWithoutProperties(props, _excluded);
60
+ validateDOMAttributes(props, restProps);
61
+ const skeletonClasses = createSkeletonClass('shape', skeleton, context);
62
+ const spacingClasses = createSpacingClasses(props);
63
+ const contentIsNum = typeof contentProp === 'number';
64
+ const variantIsNotification = variant === 'notification';
65
+ const content = variantIsNotification && contentIsNum && contentProp > 9 ? '9+' : contentProp;
66
+ if (variantIsNotification && !contentIsNum) {
67
+ warn(`Type of content should be a number: A notification badge is best suited to display content of type number.`);
51
68
  }
52
- function BadgeElem() {
53
- const skeletonClasses = createSkeletonClass('shape', skeleton, context);
54
- const spacingClasses = createSpacingClasses(allProps);
55
- const contentIsNum = typeof contentProp === 'number';
56
- const variantIsNotification = variant === 'notification';
57
- const content = variantIsNotification && contentIsNum && contentProp > 9 ? '9+' : contentProp;
58
- if (variantIsNotification && !contentIsNum) {
59
- warn(`Type of content should be a number: A notification badge is best suited to display content of type number.`);
60
- }
61
- if (!label && contentIsNum) {
62
- warn(`Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`);
63
- }
64
- const isInline = !children && content;
65
- return React.createElement("span", _extends({
66
- role: "status",
67
- className: classnames(`dnb-badge dnb-badge--variant-${variant}`, skeletonClasses, spacingClasses, className, horizontal && `dnb-badge--horizontal-${horizontal}`, vertical && `dnb-badge--vertical-${vertical}`, isInline && 'dnb-badge--inline')
68
- }, props), label && (_span || (_span = React.createElement("span", {
69
- className: "dnb-sr-only"
70
- }, label, " "))), content);
69
+ if (!label && contentIsNum) {
70
+ warn(`Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`);
71
71
  }
72
+ const isInline = !children && content;
73
+ return React.createElement("span", _extends({
74
+ role: "status",
75
+ className: classnames(`dnb-badge dnb-badge--variant-${variant}`, skeletonClasses, spacingClasses, className, horizontal && `dnb-badge--horizontal-${horizontal}`, vertical && `dnb-badge--vertical-${vertical}`, isInline && 'dnb-badge--inline')
76
+ }, restProps), label && React.createElement("span", {
77
+ className: "dnb-sr-only"
78
+ }, label, " "), content);
72
79
  }
73
80
  Badge._supportsSpacingProps = true;
74
81
  export default Badge;
@@ -1 +1 @@
1
- {"version":3,"file":"Badge.js","names":["React","classnames","createSpacingClasses","createSkeletonClass","Context","warn","extendPropsWithContext","validateDOMAttributes","defaultProps","label","className","skeleton","children","content","vertical","horizontal","variant","Badge","localProps","_span","context","useContext","allProps","contentProp","props","_objectWithoutProperties","_excluded","createElement","BadgeRoot","BadgeElem","_ref","skeletonClasses","spacingClasses","contentIsNum","variantIsNotification","isInline","_extends","role","_supportsSpacingProps"],"sources":["../../../../src/components/badge/Badge.tsx"],"sourcesContent":["import React from 'react'\nimport classnames from 'classnames'\n\n// Components\nimport { createSpacingClasses } from '../space/SpacingHelper'\nimport { createSkeletonClass } from '../skeleton/SkeletonHelper'\n\n// Shared\nimport Context from '../../shared/Context'\nimport type { SpacingProps } from '../../shared/types'\nimport type { SkeletonShow } from '../skeleton/Skeleton'\nimport {\n warn,\n extendPropsWithContext,\n validateDOMAttributes,\n} from '../../shared/component-helper'\n\nexport type BadgeProps = {\n /**\n * Aria label to describe the badge\n * Default: null\n */\n label?: React.ReactNode\n\n /**\n * Custom className on the component root\n * Default: null\n */\n className?: string\n\n /**\n * Skeleton should be applied when loading content\n * Default: null\n */\n skeleton?: SkeletonShow\n\n /**\n * The content to display the badge on top of.\n * Default: null\n */\n children?: React.ReactNode\n\n /**\n * The content of the component.\n * Default: null\n */\n content?: string | number | React.ReactNode\n\n /**\n * The vertical positioning of the component.\n * Default: null\n */\n vertical?: 'bottom' | 'top'\n\n /**\n * The horizontal positioning of the component.\n * Default: null\n */\n horizontal?: 'left' | 'right'\n\n /**\n * The variant of the component.\n * Default: information.\n */\n variant?: 'information' | 'notification'\n}\n\ntype BadgeAndSpacingProps = BadgeProps & SpacingProps\n\nexport const defaultProps = {\n label: null,\n className: null,\n skeleton: false,\n children: null,\n content: null,\n vertical: null,\n horizontal: null,\n variant: 'information',\n}\n\nfunction Badge(localProps: BadgeAndSpacingProps) {\n // Every component should have a context\n const context = React.useContext(Context)\n\n // Extract additional props from global context\n const allProps = extendPropsWithContext(\n localProps,\n defaultProps,\n context?.Badge,\n { skeleton: context?.skeleton }\n )\n\n const {\n label,\n className,\n children, // eslint-disable-line\n skeleton,\n horizontal,\n vertical,\n content: contentProp,\n variant,\n ...props\n } = allProps\n\n validateDOMAttributes(allProps, props)\n\n if (children) {\n return (\n <BadgeRoot>\n {children}\n <BadgeElem />\n </BadgeRoot>\n )\n }\n\n return <BadgeElem />\n\n function BadgeRoot({ children }: { children: React.ReactNode }) {\n return <span className=\"dnb-badge__root\">{children}</span>\n }\n\n function BadgeElem() {\n const skeletonClasses = createSkeletonClass('shape', skeleton, context)\n const spacingClasses = createSpacingClasses(allProps)\n const contentIsNum = typeof contentProp === 'number'\n const variantIsNotification = variant === 'notification'\n\n const content =\n variantIsNotification && contentIsNum && contentProp > 9\n ? '9+'\n : contentProp\n\n if (variantIsNotification && !contentIsNum) {\n warn(\n `Type of content should be a number: A notification badge is best suited to display content of type number.`\n )\n }\n if (!label && contentIsNum) {\n warn(\n `Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`\n )\n }\n\n const isInline = !children && content\n\n return (\n <span\n role=\"status\"\n className={classnames(\n 'dnb-badge',\n `dnb-badge--variant-${variant}`,\n horizontal && `dnb-badge--horizontal-${horizontal}`,\n vertical && `dnb-badge--vertical-${vertical}`,\n isInline && 'dnb-badge--inline',\n skeletonClasses,\n spacingClasses,\n className\n )}\n {...props}\n >\n {label && <span className=\"dnb-sr-only\">{label} </span>}\n {content}\n </span>\n )\n }\n}\n\nBadge._supportsSpacingProps = true\n\nexport default Badge\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AAGnC,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAA4B;AAGhE,OAAOC,OAAO,MAAM,sBAAsB;AAG1C,SACEC,IAAI,EACJC,sBAAsB,EACtBC,qBAAqB,QAChB,+BAA+B;AAsDtC,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,IAAI;EACXC,SAAS,EAAE,IAAI;EACfC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,IAAI;EACdC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE,IAAI;EACdC,UAAU,EAAE,IAAI;EAChBC,OAAO,EAAE;AACX,CAAC;AAED,SAASC,KAAKA,CAACC,UAAgC,EAAE;EAAA,IAAAC,KAAA;EAE/C,MAAMC,OAAO,GAAGpB,KAAK,CAACqB,UAAU,CAACjB,OAAO,CAAC;EAGzC,MAAMkB,QAAQ,GAAGhB,sBAAsB,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GACH,CAAC;IACH;IACA,IAAI,CAACI,KAAK,IAAIwB,YAAY,EAAE;MAC1B5B,IAAI,CACD,8JACH,CAAC;IACH;IAEA,MAAM8B,QAAQ,GAAG,CAACvB,QAAQ,IAAIC,OAAO;IAErC,OACEb,KAAA,CAAA2B,aAAA,SAAAS,QAAA;MACEC,IAAI,EAAC,QAAQ;MACb3B,SAAS,EAAET,UAAU,iCAEGe,OAAQ,IAI9Be,eAAe,EACfC,cAAc,EACdtB,SAAS,EALTK,UAAU,IAAK,yBAAwBA,UAAW,EAAC,EACnDD,QAAQ,IAAK,uBAAsBA,QAAS,EAAC,EAC7CqB,QAAQ,IAAI,mBAId;IAAE,GACEX,KAAK,GAERf,KAAK,KAAAU,KAAA,KAAAA,KAAA,GAAInB,KAAA,CAAA2B,aAAA;MAAMjB,SAAS,EAAC;IAAa,GAAED,KAAK,EAAC,GAAO,CAAC,IACtDI,OACG,CAAC;EAEX;AACF;AAEAI,KAAK,CAACqB,qBAAqB,GAAG,IAAI;AAElC,eAAerB,KAAK"}
1
+ {"version":3,"file":"Badge.js","names":["React","classnames","createSpacingClasses","createSkeletonClass","Context","warn","extendPropsWithContext","validateDOMAttributes","defaultProps","label","className","skeleton","children","content","vertical","horizontal","variant","Badge","localProps","context","useContext","allProps","createElement","BadgeRoot","BadgeElem","_extends","_ref","props","contentProp","restProps","_objectWithoutProperties","_excluded","skeletonClasses","spacingClasses","contentIsNum","variantIsNotification","isInline","role","_supportsSpacingProps"],"sources":["../../../../src/components/badge/Badge.tsx"],"sourcesContent":["import React from 'react'\nimport classnames from 'classnames'\n\n// Components\nimport { createSpacingClasses } from '../space/SpacingHelper'\nimport { createSkeletonClass } from '../skeleton/SkeletonHelper'\n\n// Shared\nimport Context, { ContextProps } from '../../shared/Context'\nimport type { SpacingProps } from '../../shared/types'\nimport type { SkeletonShow } from '../skeleton/Skeleton'\nimport {\n warn,\n extendPropsWithContext,\n validateDOMAttributes,\n} from '../../shared/component-helper'\n\nexport type BadgeProps = {\n /**\n * Aria label to describe the badge\n * Default: null\n */\n label?: React.ReactNode\n\n /**\n * Custom className on the component root\n * Default: null\n */\n className?: string\n\n /**\n * Skeleton should be applied when loading content\n * Default: null\n */\n skeleton?: SkeletonShow\n\n /**\n * The content to display the badge on top of.\n * Default: null\n */\n children?: React.ReactNode\n\n /**\n * The content of the component.\n * Default: null\n */\n content?: string | number | React.ReactNode\n\n /**\n * The vertical positioning of the component.\n * Default: null\n */\n vertical?: 'bottom' | 'top'\n\n /**\n * The horizontal positioning of the component.\n * Default: null\n */\n horizontal?: 'left' | 'right'\n\n /**\n * The variant of the component.\n * Default: information.\n */\n variant?: 'information' | 'notification'\n}\n\ntype BadgeAndSpacingProps = BadgeProps & SpacingProps\n\nexport const defaultProps = {\n label: null,\n className: null,\n skeleton: false,\n children: null,\n content: null,\n vertical: null,\n horizontal: null,\n variant: 'information',\n}\n\nfunction Badge(localProps: BadgeAndSpacingProps) {\n // Every component should have a context\n const context = React.useContext(Context)\n\n // Extract additional props from global context\n const allProps = extendPropsWithContext(\n localProps,\n defaultProps,\n context?.Badge,\n { skeleton: context?.skeleton }\n )\n const { children } = allProps\n\n if (children) {\n return (\n <BadgeRoot>\n {children}\n <BadgeElem context={context} {...allProps} />\n </BadgeRoot>\n )\n }\n\n return <BadgeElem context={context} {...allProps} />\n}\n\nfunction BadgeRoot({ children }: { children: React.ReactNode }) {\n return <span className=\"dnb-badge__root\">{children}</span>\n}\n\nfunction BadgeElem(\n props: BadgeAndSpacingProps & { context: ContextProps }\n) {\n const {\n label,\n className,\n children,\n skeleton,\n horizontal,\n vertical,\n content: contentProp,\n variant,\n context,\n ...restProps\n } = props\n\n // to remove spacing props, etc.\n validateDOMAttributes(props, restProps)\n\n const skeletonClasses = createSkeletonClass('shape', skeleton, context)\n const spacingClasses = createSpacingClasses(props)\n const contentIsNum = typeof contentProp === 'number'\n const variantIsNotification = variant === 'notification'\n\n const content =\n variantIsNotification && contentIsNum && contentProp > 9\n ? '9+'\n : contentProp\n\n if (variantIsNotification && !contentIsNum) {\n warn(\n `Type of content should be a number: A notification badge is best suited to display content of type number.`\n )\n }\n if (!label && contentIsNum) {\n warn(\n `Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`\n )\n }\n\n const isInline = !children && content\n\n return (\n <span\n role=\"status\"\n className={classnames(\n 'dnb-badge',\n `dnb-badge--variant-${variant}`,\n horizontal && `dnb-badge--horizontal-${horizontal}`,\n vertical && `dnb-badge--vertical-${vertical}`,\n isInline && 'dnb-badge--inline',\n skeletonClasses,\n spacingClasses,\n className\n )}\n {...restProps}\n >\n {label && <span className=\"dnb-sr-only\">{label} </span>}\n {content}\n </span>\n )\n}\n\nBadge._supportsSpacingProps = true\n\nexport default Badge\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AAGnC,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAA4B;AAGhE,OAAOC,OAAO,MAAwB,sBAAsB;AAG5D,SACEC,IAAI,EACJC,sBAAsB,EACtBC,qBAAqB,QAChB,+BAA+B;AAsDtC,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,IAAI;EACXC,SAAS,EAAE,IAAI;EACfC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,IAAI;EACdC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE,IAAI;EACdC,UAAU,EAAE,IAAI;EAChBC,OAAO,EAAE;AACX,CAAC;AAED,SAASC,KAAKA,CAACC,UAAgC,EAAE;EAE/C,MAAMC,OAAO,GAAGnB,KAAK,CAACoB,UAAU,CAAChB,OAAO,CAAC;EAGzC,MAAMiB,QAAQ,GAAGf,sBAAsB,CACrCY,UAAU,EACVV,YAAY,EACZW,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEF,KAAK,EACd;IAAEN,QAAQ,EAAEQ,OAAO,aAAPA,OAAO,uB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BAAqB,IAAI,CAACD,YAAY,EAAE;IAC1C7B,IAAI,CACD,4GACH,CAAC;EACH;EACA,IAAI,CAACI,KAAK,IAAIyB,YAAY,EAAE;IAC1B7B,IAAI,CACD,8JACH,CAAC;EACH;EAEA,MAAM+B,QAAQ,GAAG,CAACxB,QAAQ,IAAIC,OAAO;EAErC,OACEb,KAAA,CAAAsB,aAAA,SAAAG,QAAA;IACEY,IAAI,EAAC,QAAQ;IACb3B,SAAS,EAAET,UAAU,iCAEGe,OAAQ,IAI9BgB,eAAe,EACfC,cAAc,EACdvB,SAAS,EALTK,UAAU,IAAK,yBAAwBA,UAAW,EAAC,EACnDD,QAAQ,IAAK,uBAAsBA,QAAS,EAAC,EAC7CsB,QAAQ,IAAI,mBAId;EAAE,GACEP,SAAS,GAEZpB,KAAK,IAAIT,KAAA,CAAAsB,aAAA;IAAMZ,SAAS,EAAC;EAAa,GAAED,KAAK,EAAC,GAAO,CAAC,EACtDI,OACG,CAAC;AAEX;AAEAI,KAAK,CAACqB,qBAAqB,GAAG,IAAI;AAElC,eAAerB,KAAK"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- const _excluded = ["label", "className", "children", "skeleton", "horizontal", "vertical", "content", "variant"];
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["label", "className", "children", "skeleton", "horizontal", "vertical", "content", "variant", "context"];
6
6
  import React from 'react';
7
7
  import classnames from 'classnames';
8
8
  import { createSpacingClasses } from '../space/SpacingHelper';
@@ -20,11 +20,30 @@ export const defaultProps = {
20
20
  variant: 'information'
21
21
  };
22
22
  function Badge(localProps) {
23
- var _span;
24
23
  const context = React.useContext(Context);
25
24
  const allProps = extendPropsWithContext(localProps, defaultProps, context === null || context === void 0 ? void 0 : context.Badge, {
26
25
  skeleton: context === null || context === void 0 ? void 0 : context.skeleton
27
26
  });
27
+ const {
28
+ children
29
+ } = allProps;
30
+ if (children) {
31
+ return React.createElement(BadgeRoot, null, children, React.createElement(BadgeElem, _extends({
32
+ context: context
33
+ }, allProps)));
34
+ }
35
+ return React.createElement(BadgeElem, _extends({
36
+ context: context
37
+ }, allProps));
38
+ }
39
+ function BadgeRoot({
40
+ children
41
+ }) {
42
+ return React.createElement("span", {
43
+ className: "dnb-badge__root"
44
+ }, children);
45
+ }
46
+ function BadgeElem(props) {
28
47
  const {
29
48
  label,
30
49
  className,
@@ -33,41 +52,29 @@ function Badge(localProps) {
33
52
  horizontal,
34
53
  vertical,
35
54
  content: contentProp,
36
- variant
37
- } = allProps,
38
- props = _objectWithoutProperties(allProps, _excluded);
39
- validateDOMAttributes(allProps, props);
40
- if (children) {
41
- return React.createElement(BadgeRoot, null, children, React.createElement(BadgeElem, null));
42
- }
43
- return React.createElement(BadgeElem, null);
44
- function BadgeRoot({
45
- children
46
- }) {
47
- return React.createElement("span", {
48
- className: "dnb-badge__root"
49
- }, children);
55
+ variant,
56
+ context
57
+ } = props,
58
+ restProps = _objectWithoutProperties(props, _excluded);
59
+ validateDOMAttributes(props, restProps);
60
+ const skeletonClasses = createSkeletonClass('shape', skeleton, context);
61
+ const spacingClasses = createSpacingClasses(props);
62
+ const contentIsNum = typeof contentProp === 'number';
63
+ const variantIsNotification = variant === 'notification';
64
+ const content = variantIsNotification && contentIsNum && contentProp > 9 ? '9+' : contentProp;
65
+ if (variantIsNotification && !contentIsNum) {
66
+ warn(`Type of content should be a number: A notification badge is best suited to display content of type number.`);
50
67
  }
51
- function BadgeElem() {
52
- const skeletonClasses = createSkeletonClass('shape', skeleton, context);
53
- const spacingClasses = createSpacingClasses(allProps);
54
- const contentIsNum = typeof contentProp === 'number';
55
- const variantIsNotification = variant === 'notification';
56
- const content = variantIsNotification && contentIsNum && contentProp > 9 ? '9+' : contentProp;
57
- if (variantIsNotification && !contentIsNum) {
58
- warn(`Type of content should be a number: A notification badge is best suited to display content of type number.`);
59
- }
60
- if (!label && contentIsNum) {
61
- warn(`Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`);
62
- }
63
- const isInline = !children && content;
64
- return React.createElement("span", _extends({
65
- role: "status",
66
- className: classnames(`dnb-badge dnb-badge--variant-${variant}`, skeletonClasses, spacingClasses, className, horizontal && `dnb-badge--horizontal-${horizontal}`, vertical && `dnb-badge--vertical-${vertical}`, isInline && 'dnb-badge--inline')
67
- }, props), label && (_span || (_span = React.createElement("span", {
68
- className: "dnb-sr-only"
69
- }, label, " "))), content);
68
+ if (!label && contentIsNum) {
69
+ warn(`Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`);
70
70
  }
71
+ const isInline = !children && content;
72
+ return React.createElement("span", _extends({
73
+ role: "status",
74
+ className: classnames(`dnb-badge dnb-badge--variant-${variant}`, skeletonClasses, spacingClasses, className, horizontal && `dnb-badge--horizontal-${horizontal}`, vertical && `dnb-badge--vertical-${vertical}`, isInline && 'dnb-badge--inline')
75
+ }, restProps), label && React.createElement("span", {
76
+ className: "dnb-sr-only"
77
+ }, label, " "), content);
71
78
  }
72
79
  Badge._supportsSpacingProps = true;
73
80
  export default Badge;
@@ -1 +1 @@
1
- {"version":3,"file":"Badge.js","names":["React","classnames","createSpacingClasses","createSkeletonClass","Context","warn","extendPropsWithContext","validateDOMAttributes","defaultProps","label","className","skeleton","children","content","vertical","horizontal","variant","Badge","localProps","_span","context","useContext","allProps","contentProp","props","_objectWithoutProperties","_excluded","createElement","BadgeRoot","BadgeElem","skeletonClasses","spacingClasses","contentIsNum","variantIsNotification","isInline","_extends","role","_supportsSpacingProps"],"sources":["../../../../src/components/badge/Badge.tsx"],"sourcesContent":["import React from 'react'\nimport classnames from 'classnames'\n\n// Components\nimport { createSpacingClasses } from '../space/SpacingHelper'\nimport { createSkeletonClass } from '../skeleton/SkeletonHelper'\n\n// Shared\nimport Context from '../../shared/Context'\nimport type { SpacingProps } from '../../shared/types'\nimport type { SkeletonShow } from '../skeleton/Skeleton'\nimport {\n warn,\n extendPropsWithContext,\n validateDOMAttributes,\n} from '../../shared/component-helper'\n\nexport type BadgeProps = {\n /**\n * Aria label to describe the badge\n * Default: null\n */\n label?: React.ReactNode\n\n /**\n * Custom className on the component root\n * Default: null\n */\n className?: string\n\n /**\n * Skeleton should be applied when loading content\n * Default: null\n */\n skeleton?: SkeletonShow\n\n /**\n * The content to display the badge on top of.\n * Default: null\n */\n children?: React.ReactNode\n\n /**\n * The content of the component.\n * Default: null\n */\n content?: string | number | React.ReactNode\n\n /**\n * The vertical positioning of the component.\n * Default: null\n */\n vertical?: 'bottom' | 'top'\n\n /**\n * The horizontal positioning of the component.\n * Default: null\n */\n horizontal?: 'left' | 'right'\n\n /**\n * The variant of the component.\n * Default: information.\n */\n variant?: 'information' | 'notification'\n}\n\ntype BadgeAndSpacingProps = BadgeProps & SpacingProps\n\nexport const defaultProps = {\n label: null,\n className: null,\n skeleton: false,\n children: null,\n content: null,\n vertical: null,\n horizontal: null,\n variant: 'information',\n}\n\nfunction Badge(localProps: BadgeAndSpacingProps) {\n // Every component should have a context\n const context = React.useContext(Context)\n\n // Extract additional props from global context\n const allProps = extendPropsWithContext(\n localProps,\n defaultProps,\n context?.Badge,\n { skeleton: context?.skeleton }\n )\n\n const {\n label,\n className,\n children, // eslint-disable-line\n skeleton,\n horizontal,\n vertical,\n content: contentProp,\n variant,\n ...props\n } = allProps\n\n validateDOMAttributes(allProps, props)\n\n if (children) {\n return (\n <BadgeRoot>\n {children}\n <BadgeElem />\n </BadgeRoot>\n )\n }\n\n return <BadgeElem />\n\n function BadgeRoot({ children }: { children: React.ReactNode }) {\n return <span className=\"dnb-badge__root\">{children}</span>\n }\n\n function BadgeElem() {\n const skeletonClasses = createSkeletonClass('shape', skeleton, context)\n const spacingClasses = createSpacingClasses(allProps)\n const contentIsNum = typeof contentProp === 'number'\n const variantIsNotification = variant === 'notification'\n\n const content =\n variantIsNotification && contentIsNum && contentProp > 9\n ? '9+'\n : contentProp\n\n if (variantIsNotification && !contentIsNum) {\n warn(\n `Type of content should be a number: A notification badge is best suited to display content of type number.`\n )\n }\n if (!label && contentIsNum) {\n warn(\n `Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`\n )\n }\n\n const isInline = !children && content\n\n return (\n <span\n role=\"status\"\n className={classnames(\n 'dnb-badge',\n `dnb-badge--variant-${variant}`,\n horizontal && `dnb-badge--horizontal-${horizontal}`,\n vertical && `dnb-badge--vertical-${vertical}`,\n isInline && 'dnb-badge--inline',\n skeletonClasses,\n spacingClasses,\n className\n )}\n {...props}\n >\n {label && <span className=\"dnb-sr-only\">{label} </span>}\n {content}\n </span>\n )\n }\n}\n\nBadge._supportsSpacingProps = true\n\nexport default Badge\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AAGnC,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAA4B;AAGhE,OAAOC,OAAO,MAAM,sBAAsB;AAG1C,SACEC,IAAI,EACJC,sBAAsB,EACtBC,qBAAqB,QAChB,+BAA+B;AAsDtC,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,IAAI;EACXC,SAAS,EAAE,IAAI;EACfC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,IAAI;EACdC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE,IAAI;EACdC,UAAU,EAAE,IAAI;EAChBC,OAAO,EAAE;AACX,CAAC;AAED,SAASC,KAAKA,CAACC,UAAgC,EAAE;EAAA,IAAAC,KAAA;EAE/C,MAAMC,OAAO,GAAGpB,KAAK,CAACqB,UAAU,CAACjB,OAAO,CAAC;EAGzC,MAAMkB,QAAQ,GAAGhB,sBAAsB,CACrCY,UAAU,EACVV,YAAY,EACZY,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEH,KAAK,EACd;IAAEN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,CAACtB,QAAQ,IAAIC,OAAO;IAErC,OACEb,KAAA,CAAA2B,aAAA,SAAAQ,QAAA;MACEC,IAAI,EAAC,QAAQ;MACb1B,SAAS,EAAET,UAAU,iCAEGe,OAAQ,IAI9Bc,eAAe,EACfC,cAAc,EACdrB,SAAS,EALTK,UAAU,IAAK,yBAAwBA,UAAW,EAAC,EACnDD,QAAQ,IAAK,uBAAsBA,QAAS,EAAC,EAC7CoB,QAAQ,IAAI,mBAId;IAAE,GACEV,KAAK,GAERf,KAAK,KAAAU,KAAA,KAAAA,KAAA,GAAInB,KAAA,CAAA2B,aAAA;MAAMjB,SAAS,EAAC;IAAa,GAAED,KAAK,EAAC,GAAO,CAAC,IACtDI,OACG,CAAC;EAEX;AACF;AAEAI,KAAK,CAACoB,qBAAqB,GAAG,IAAI;AAElC,eAAepB,KAAK"}
1
+ {"version":3,"file":"Badge.js","names":["React","classnames","createSpacingClasses","createSkeletonClass","Context","warn","extendPropsWithContext","validateDOMAttributes","defaultProps","label","className","skeleton","children","content","vertical","horizontal","variant","Badge","localProps","context","useContext","allProps","createElement","BadgeRoot","BadgeElem","_extends","props","contentProp","restProps","_objectWithoutProperties","_excluded","skeletonClasses","spacingClasses","contentIsNum","variantIsNotification","isInline","role","_supportsSpacingProps"],"sources":["../../../../src/components/badge/Badge.tsx"],"sourcesContent":["import React from 'react'\nimport classnames from 'classnames'\n\n// Components\nimport { createSpacingClasses } from '../space/SpacingHelper'\nimport { createSkeletonClass } from '../skeleton/SkeletonHelper'\n\n// Shared\nimport Context, { ContextProps } from '../../shared/Context'\nimport type { SpacingProps } from '../../shared/types'\nimport type { SkeletonShow } from '../skeleton/Skeleton'\nimport {\n warn,\n extendPropsWithContext,\n validateDOMAttributes,\n} from '../../shared/component-helper'\n\nexport type BadgeProps = {\n /**\n * Aria label to describe the badge\n * Default: null\n */\n label?: React.ReactNode\n\n /**\n * Custom className on the component root\n * Default: null\n */\n className?: string\n\n /**\n * Skeleton should be applied when loading content\n * Default: null\n */\n skeleton?: SkeletonShow\n\n /**\n * The content to display the badge on top of.\n * Default: null\n */\n children?: React.ReactNode\n\n /**\n * The content of the component.\n * Default: null\n */\n content?: string | number | React.ReactNode\n\n /**\n * The vertical positioning of the component.\n * Default: null\n */\n vertical?: 'bottom' | 'top'\n\n /**\n * The horizontal positioning of the component.\n * Default: null\n */\n horizontal?: 'left' | 'right'\n\n /**\n * The variant of the component.\n * Default: information.\n */\n variant?: 'information' | 'notification'\n}\n\ntype BadgeAndSpacingProps = BadgeProps & SpacingProps\n\nexport const defaultProps = {\n label: null,\n className: null,\n skeleton: false,\n children: null,\n content: null,\n vertical: null,\n horizontal: null,\n variant: 'information',\n}\n\nfunction Badge(localProps: BadgeAndSpacingProps) {\n // Every component should have a context\n const context = React.useContext(Context)\n\n // Extract additional props from global context\n const allProps = extendPropsWithContext(\n localProps,\n defaultProps,\n context?.Badge,\n { skeleton: context?.skeleton }\n )\n const { children } = allProps\n\n if (children) {\n return (\n <BadgeRoot>\n {children}\n <BadgeElem context={context} {...allProps} />\n </BadgeRoot>\n )\n }\n\n return <BadgeElem context={context} {...allProps} />\n}\n\nfunction BadgeRoot({ children }: { children: React.ReactNode }) {\n return <span className=\"dnb-badge__root\">{children}</span>\n}\n\nfunction BadgeElem(\n props: BadgeAndSpacingProps & { context: ContextProps }\n) {\n const {\n label,\n className,\n children,\n skeleton,\n horizontal,\n vertical,\n content: contentProp,\n variant,\n context,\n ...restProps\n } = props\n\n // to remove spacing props, etc.\n validateDOMAttributes(props, restProps)\n\n const skeletonClasses = createSkeletonClass('shape', skeleton, context)\n const spacingClasses = createSpacingClasses(props)\n const contentIsNum = typeof contentProp === 'number'\n const variantIsNotification = variant === 'notification'\n\n const content =\n variantIsNotification && contentIsNum && contentProp > 9\n ? '9+'\n : contentProp\n\n if (variantIsNotification && !contentIsNum) {\n warn(\n `Type of content should be a number: A notification badge is best suited to display content of type number.`\n )\n }\n if (!label && contentIsNum) {\n warn(\n `Label required: A Badge with a number as content requires a label describing the content of the badge. This is to ensure correct semantic and accessibility.`\n )\n }\n\n const isInline = !children && content\n\n return (\n <span\n role=\"status\"\n className={classnames(\n 'dnb-badge',\n `dnb-badge--variant-${variant}`,\n horizontal && `dnb-badge--horizontal-${horizontal}`,\n vertical && `dnb-badge--vertical-${vertical}`,\n isInline && 'dnb-badge--inline',\n skeletonClasses,\n spacingClasses,\n className\n )}\n {...restProps}\n >\n {label && <span className=\"dnb-sr-only\">{label} </span>}\n {content}\n </span>\n )\n}\n\nBadge._supportsSpacingProps = true\n\nexport default Badge\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AAGnC,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAA4B;AAGhE,OAAOC,OAAO,MAAwB,sBAAsB;AAG5D,SACEC,IAAI,EACJC,sBAAsB,EACtBC,qBAAqB,QAChB,+BAA+B;AAsDtC,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,IAAI;EACXC,SAAS,EAAE,IAAI;EACfC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,IAAI;EACdC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE,IAAI;EACdC,UAAU,EAAE,IAAI;EAChBC,OAAO,EAAE;AACX,CAAC;AAED,SAASC,KAAKA,CAACC,UAAgC,EAAE;EAE/C,MAAMC,OAAO,GAAGnB,KAAK,CAACoB,UAAU,CAAChB,OAAO,CAAC;EAGzC,MAAMiB,QAAQ,GAAGf,sBAAsB,CACrCY,UAAU,EACVV,YAAY,EACZW,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEF,KAAK,EACd;IAAEN,QAAQ,EAAEQ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAER;EAAS,CAChC,CAAC;EACD,MAAM;IAAEC;EAAS,CAAC,GAAGS,QAAQ;EAE7B,IAAIT,QAAQ,EAAE;IACZ,OACEZ,KAA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,QAAQ,GAAG,CAACvB,QAAQ,IAAIC,OAAO;EAErC,OACEb,KAAA,CAAAsB,aAAA,SAAAG,QAAA;IACEW,IAAI,EAAC,QAAQ;IACb1B,SAAS,EAAET,UAAU,iCAEGe,OAAQ,IAI9Be,eAAe,EACfC,cAAc,EACdtB,SAAS,EALTK,UAAU,IAAK,yBAAwBA,UAAW,EAAC,EACnDD,QAAQ,IAAK,uBAAsBA,QAAS,EAAC,EAC7CqB,QAAQ,IAAI,mBAId;EAAE,GACEP,SAAS,GAEZnB,KAAK,IAAIT,KAAA,CAAAsB,aAAA;IAAMZ,SAAS,EAAC;EAAa,GAAED,KAAK,EAAC,GAAO,CAAC,EACtDI,OACG,CAAC;AAEX;AAEAI,KAAK,CAACoB,qBAAqB,GAAG,IAAI;AAElC,eAAepB,KAAK"}
@@ -173,7 +173,7 @@ function renderRadioItems({
173
173
  const Component = variant === 'radio' ? Radio : ToggleButton;
174
174
  return React.createElement(Component, _extends({
175
175
  id: optionsCount === 1 ? id : undefined,
176
- key: `option-${i}-${value}`,
176
+ key: `option-${i}-${id}`,
177
177
  label: variant === 'radio' ? label : undefined,
178
178
  text: variant === 'button' ? label : undefined,
179
179
  value: String(value !== null && value !== void 0 ? value : ''),
@@ -1 +1 @@
1
- {"version":3,"file":"Selection.js","names":["React","useMemo","useCallback","classnames","makeUniqueId","ToggleButton","Dropdown","Radio","HelpButton","Autocomplete","OptionField","useFieldProps","pickSpacingProps","FieldBlock","FormError","convertCamelCaseProps","useDataValue","Selection","props","clearValue","id","className","variant","label","labelDescription","layout","optionsLayout","placeholder","value","info","warning","error","hasError","disabled","help","emptyValue","width","htmlAttributes","setHasFocus","handleChange","data","dataPath","children","autocompleteProps","dropdownProps","getValueByPath","dataList","handleDropdownChange","selectedKey","onChangeHandler","undefined","handleShow","handleHide","cn","fieldBlockProps","_objectSpread","forId","Component","items","renderRadioItems","createElement","_extends","asFieldset","Children","count","Group","layout_direction","on_change","String","status","getStatus","renderDropdownItems","concat","makeOptions","filter","Boolean","sharedProps","list_class","portal_class","title","suffix","content","on_show","on_hide","stretch","_error$message","message","Error","toString","optionsCount","length","createOption","i","rest","_objectWithoutProperties","_excluded","size","key","text","map","mapOptions","child","isValidElement","type","nestedChildren","cloneElement","_child","_child$props","_child$props$children","_ref","_props$children","_props$value","_em","_em2","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Field/Selection/Selection.tsx"],"sourcesContent":["import React, { useMemo, useCallback } from 'react'\nimport classnames from 'classnames'\nimport { makeUniqueId } from '../../../../shared/component-helper'\nimport {\n ToggleButton,\n Dropdown,\n Radio,\n HelpButton,\n Autocomplete,\n} from '../../../../components'\nimport OptionField, { Props as OptionFieldProps } from '../Option'\nimport { useFieldProps } from '../../hooks'\nimport { ReturnAdditional } from '../../hooks/useFieldProps'\nimport { pickSpacingProps } from '../../../../components/flex/utils'\nimport FieldBlock from '../../FieldBlock'\nimport {\n FormError,\n FieldProps,\n FieldHelpProps,\n FieldBlockWidth,\n Path,\n} from '../../types'\nimport type { FormStatusText } from '../../../../components/FormStatus'\nimport type { AutocompleteAllProps } from '../../../../components/Autocomplete'\nimport type { DropdownAllProps } from '../../../../components/Dropdown'\nimport { HelpButtonProps } from '../../../../components/HelpButton'\nimport { DrawerListProps } from '../../../../fragments/DrawerList'\nimport {\n convertCamelCaseProps,\n ToCamelCase,\n} from '../../../../shared/helpers/withCamelCaseProps'\nimport useDataValue from '../../hooks/useDataValue'\n\ntype IOption = {\n title: string | React.ReactNode\n value: number | string\n status: FormStatusText\n}\nexport type Data = Array<{\n value: string\n title: React.ReactNode\n text?: React.ReactNode\n}>\n\nexport type Props = FieldHelpProps &\n FieldProps<IOption['value']> & {\n /**\n * Defines the variant of the component.\n * Default: dropdown\n */\n variant?: 'dropdown' | 'autocomplete' | 'radio' | 'button'\n\n /**\n * The width of the component.\n * Default: large\n */\n width?: FieldBlockWidth\n\n /**\n * Defines the layout of the options for radio and button variants.\n */\n optionsLayout?: 'horizontal' | 'vertical'\n\n /**\n * The path to the context data (Form.Handler).\n * The context data object needs to have a `value` and a `title` property.\n */\n dataPath?: Path\n\n /**\n * Data to be used for the component. The object needs to have a `value` and a `title` property.\n * The generated options will be placed above given JSX based children.\n */\n data?: Data\n\n /**\n * Autocomplete specific props\n */\n autocompleteProps?: ToCamelCase<AutocompleteAllProps>\n\n /**\n * Dropdown specific props\n */\n dropdownProps?: ToCamelCase<DropdownAllProps>\n\n /**\n * The content of the component.\n */\n children?: React.ReactNode\n }\n\nfunction Selection(props: Props) {\n const clearValue = useMemo(() => `clear-option-${makeUniqueId()}`, [])\n\n const {\n id,\n className,\n variant = 'dropdown',\n label,\n labelDescription,\n layout = 'vertical',\n optionsLayout = 'vertical',\n placeholder,\n value,\n info,\n warning,\n error,\n hasError,\n disabled,\n help,\n emptyValue,\n width = 'large',\n htmlAttributes,\n setHasFocus,\n handleChange,\n data,\n dataPath,\n children,\n\n // - Autocomplete and Dropdown specific props\n autocompleteProps,\n dropdownProps,\n } = useFieldProps(props)\n\n const { getValueByPath } = useDataValue()\n let dataList = data\n if (dataPath) {\n dataList = getValueByPath(dataPath)\n }\n\n const handleDropdownChange = useCallback(\n ({ data }) => {\n const selectedKey = data?.selectedKey\n handleChange?.(\n !selectedKey || selectedKey === clearValue\n ? emptyValue\n : selectedKey\n )\n },\n [handleChange, emptyValue, clearValue]\n )\n\n const onChangeHandler = useCallback(\n ({ value }) => {\n handleChange?.(value === undefined ? emptyValue : value)\n },\n [handleChange, emptyValue]\n )\n\n // Specific handleShow and handleHide because Dropdown preserve the initially received callbacks, so changes\n // due to `useCallback` usage will have no effect, leading to useFieldPropss handleFocus and handleBlur sending out old\n // copies of value as arguments.\n const handleShow = useCallback(\n ({ data }) => {\n setHasFocus(true, data?.selectedKey)\n },\n [setHasFocus]\n )\n\n const handleHide = useCallback(\n ({ data }) => {\n setHasFocus(false, data?.selectedKey)\n },\n [setHasFocus]\n )\n\n const cn = classnames(\n 'dnb-forms-field-selection',\n `dnb-forms-field-selection__variant--${variant}`,\n `dnb-forms-field-selection__options-layout--${optionsLayout}`,\n className\n )\n\n const fieldBlockProps = {\n forId: id,\n className: cn,\n ...pickSpacingProps(props),\n info,\n warning,\n error,\n layout,\n label,\n labelDescription,\n }\n\n switch (variant) {\n case 'radio':\n case 'button': {\n const Component = (\n variant === 'radio' ? Radio : ToggleButton\n ) as typeof Radio & typeof ToggleButton\n\n const items = renderRadioItems({\n id,\n value,\n variant,\n info,\n warning,\n htmlAttributes,\n children,\n dataList,\n hasError,\n })\n\n return (\n <FieldBlock\n {...fieldBlockProps}\n asFieldset={React.Children.count(items) > 1}\n >\n <Component.Group\n className={cn}\n layout_direction={\n optionsLayout === 'horizontal' ? 'row' : 'column'\n }\n disabled={disabled}\n on_change={onChangeHandler}\n value={String(value ?? '')}\n >\n {items}\n </Component.Group>\n </FieldBlock>\n )\n }\n\n case 'autocomplete':\n case 'dropdown': {\n const status = getStatus(error, info, warning)\n const data = renderDropdownItems(dataList)\n .concat(makeOptions(children))\n .filter(Boolean)\n\n const sharedProps: AutocompleteAllProps & DropdownAllProps = {\n id,\n list_class: 'dnb-forms-field-selection__list',\n portal_class: 'dnb-forms-field-selection__portal',\n title: placeholder,\n value: String(value ?? ''),\n status: (hasError || status) && 'error',\n disabled,\n ...htmlAttributes,\n data,\n suffix: help ? (\n <HelpButton title={help.title}>{help.content}</HelpButton>\n ) : undefined,\n on_change: handleDropdownChange,\n on_show: handleShow,\n on_hide: handleHide,\n stretch: true,\n }\n\n return (\n <FieldBlock {...fieldBlockProps} width={width}>\n {variant === 'autocomplete' ? (\n <Autocomplete\n {...sharedProps}\n {...(autocompleteProps\n ? (convertCamelCaseProps(\n autocompleteProps\n ) as AutocompleteAllProps)\n : null)}\n />\n ) : (\n <Dropdown\n {...sharedProps}\n {...(dropdownProps\n ? (convertCamelCaseProps(\n dropdownProps\n ) as DropdownAllProps)\n : null)}\n />\n )}\n </FieldBlock>\n )\n }\n }\n}\n\nexport function getStatus(\n error: Error | FormError | undefined,\n info: React.ReactNode,\n warning: React.ReactNode\n) {\n return (\n error?.message ??\n ((warning instanceof Error && warning.message) ||\n (warning instanceof FormError && warning.message) ||\n warning?.toString() ||\n (info instanceof Error && info.message) ||\n (info instanceof FormError && info.message) ||\n info?.toString())\n )\n}\n\ntype OptionProps = React.ComponentProps<\n React.FC<{\n error?: Error | FormError | undefined\n title: React.ReactNode\n help?: HelpButtonProps\n children?: React.ReactNode\n }>\n>\n\nfunction renderRadioItems({\n id,\n value,\n variant,\n info,\n warning,\n htmlAttributes,\n children,\n dataList,\n hasError,\n}: {\n id: string\n value: Props['value']\n variant: Props['variant']\n info: Props['info']\n warning: Props['warning']\n htmlAttributes: Props['htmlAttributes']\n children: Props['children']\n dataList: Data\n hasError: ReturnAdditional<Props['value']>['hasError']\n}) {\n const optionsCount =\n React.Children.count(children) + (dataList?.length || 0)\n\n const createOption = (props: OptionProps, i: number) => {\n const { error, title, help, children, ...rest } = props\n\n const label = title ?? children\n const status = getStatus(error, info, warning)\n const suffix = help ? (\n <HelpButton size=\"small\" title={help.title}>\n {help.content}\n </HelpButton>\n ) : undefined\n\n const Component = (\n variant === 'radio' ? Radio : ToggleButton\n ) as typeof Radio & typeof ToggleButton\n\n return (\n <Component\n id={optionsCount === 1 ? id : undefined}\n key={`option-${i}-${value}`}\n label={variant === 'radio' ? label : undefined}\n text={variant === 'button' ? label : undefined}\n value={String(value ?? '')}\n status={(hasError || status) && 'error'}\n suffix={suffix}\n {...htmlAttributes}\n {...rest}\n />\n )\n }\n\n return [\n ...(dataList || []).map((props, i) => {\n return createOption(props as OptionProps, i)\n }),\n ...(mapOptions(children, { createOption }) || []),\n ].filter(Boolean)\n}\n\nexport function mapOptions(children: React.ReactNode, { createOption }) {\n return React.Children.map(\n children,\n (child: React.ReactElement<OptionProps>, i) => {\n if (React.isValidElement(child)) {\n if (child.type === OptionField) {\n return createOption(child.props, i)\n }\n\n if (child.props.children) {\n const nestedChildren = mapOptions(child.props.children, {\n createOption,\n })\n return React.cloneElement(child, child.props, nestedChildren)\n }\n }\n\n return child\n }\n )\n}\n\nexport function makeOptions<T = DrawerListProps['data']>(\n children: React.ReactNode\n): T {\n return React.Children.map(children, (child) => {\n if (child?.['props']?.children?.type === OptionField) {\n child = child['props'].children\n }\n\n if (React.isValidElement(child) && child.type === OptionField) {\n const props = child.props as OptionFieldProps\n const title = props.children ?? props.title ?? <em>Untitled</em>\n const content = props.text ? [title, props.text] : title\n const selectedKey = String(props.value ?? '')\n\n return { selectedKey, content }\n }\n\n // For other children, just show them as content\n if (child) {\n return {\n content: child,\n }\n }\n }) as T\n}\n\nfunction renderDropdownItems(data: Data) {\n return (\n data?.map(({ value, title, text }) => ({\n selectedKey: value,\n content: (text ? [title, text] : title) || <em>Untitled</em>,\n })) || []\n )\n}\n\nSelection._supportsSpacingProps = true\nexport default Selection\n"],"mappings":";;;;;;;AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,WAAW,QAAQ,OAAO;AACnD,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SACEC,YAAY,EACZC,QAAQ,EACRC,KAAK,EACLC,UAAU,EACVC,YAAY,QACP,wBAAwB;AAC/B,OAAOC,WAAW,MAAqC,WAAW;AAClE,SAASC,aAAa,QAAQ,aAAa;AAE3C,SAASC,gBAAgB,QAAQ,mCAAmC;AACpE,OAAOC,UAAU,MAAM,kBAAkB;AACzC,SACEC,SAAS,QAKJ,aAAa;AAMpB,SACEC,qBAAqB,QAEhB,+CAA+C;AACtD,OAAOC,YAAY,MAAM,0BAA0B;AA4DnD,SAASC,SAASA,CAACC,KAAY,EAAE;EAC/B,MAAMC,UAAU,GAAGlB,OAAO,CAAC,MAAO,gBAAeG,YAAY,CAAC,CAAE,EAAC,EAAE,EAAE,CAAC;EAEtE,MAAM;IACJgB,EAAE;IACFC,SAAS;IACTC,OAAO,GAAG,UAAU;IACpBC,KAAK;IACLC,gBAAgB;IAChBC,MAAM,GAAG,UAAU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,SAAS"}
1
+ {"version":3,"file":"Selection.js","names":["React","useMemo","useCallback","classnames","makeUniqueId","ToggleButton","Dropdown","Radio","HelpButton","Autocomplete","OptionField","useFieldProps","pickSpacingProps","FieldBlock","FormError","convertCamelCaseProps","useDataValue","Selection","props","clearValue","id","className","variant","label","labelDescription","layout","optionsLayout","placeholder","value","info","warning","error","hasError","disabled","help","emptyValue","width","htmlAttributes","setHasFocus","handleChange","data","dataPath","children","autocompleteProps","dropdownProps","getValueByPath","dataList","handleDropdownChange","selectedKey","onChangeHandler","undefined","handleShow","handleHide","cn","fieldBlockProps","_objectSpread","forId","Component","items","renderRadioItems","createElement","_extends","asFieldset","Children","count","Group","layout_direction","on_change","String","status","getStatus","renderDropdownItems","concat","makeOptions","filter","Boolean","sharedProps","list_class","portal_class","title","suffix","content","on_show","on_hide","stretch","_error$message","message","Error","toString","optionsCount","length","createOption","i","rest","_objectWithoutProperties","_excluded","size","key","text","map","mapOptions","child","isValidElement","type","nestedChildren","cloneElement","_child","_child$props","_child$props$children","_ref","_props$children","_props$value","_em","_em2","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Field/Selection/Selection.tsx"],"sourcesContent":["import React, { useMemo, useCallback } from 'react'\nimport classnames from 'classnames'\nimport { makeUniqueId } from '../../../../shared/component-helper'\nimport {\n ToggleButton,\n Dropdown,\n Radio,\n HelpButton,\n Autocomplete,\n} from '../../../../components'\nimport OptionField, { Props as OptionFieldProps } from '../Option'\nimport { useFieldProps } from '../../hooks'\nimport { ReturnAdditional } from '../../hooks/useFieldProps'\nimport { pickSpacingProps } from '../../../../components/flex/utils'\nimport FieldBlock from '../../FieldBlock'\nimport {\n FormError,\n FieldProps,\n FieldHelpProps,\n FieldBlockWidth,\n Path,\n} from '../../types'\nimport type { FormStatusText } from '../../../../components/FormStatus'\nimport type { AutocompleteAllProps } from '../../../../components/Autocomplete'\nimport type { DropdownAllProps } from '../../../../components/Dropdown'\nimport { HelpButtonProps } from '../../../../components/HelpButton'\nimport { DrawerListProps } from '../../../../fragments/DrawerList'\nimport {\n convertCamelCaseProps,\n ToCamelCase,\n} from '../../../../shared/helpers/withCamelCaseProps'\nimport useDataValue from '../../hooks/useDataValue'\n\ntype IOption = {\n title: string | React.ReactNode\n value: number | string\n status: FormStatusText\n}\nexport type Data = Array<{\n value: string\n title: React.ReactNode\n text?: React.ReactNode\n}>\n\nexport type Props = FieldHelpProps &\n FieldProps<IOption['value']> & {\n /**\n * Defines the variant of the component.\n * Default: dropdown\n */\n variant?: 'dropdown' | 'autocomplete' | 'radio' | 'button'\n\n /**\n * The width of the component.\n * Default: large\n */\n width?: FieldBlockWidth\n\n /**\n * Defines the layout of the options for radio and button variants.\n */\n optionsLayout?: 'horizontal' | 'vertical'\n\n /**\n * The path to the context data (Form.Handler).\n * The context data object needs to have a `value` and a `title` property.\n */\n dataPath?: Path\n\n /**\n * Data to be used for the component. The object needs to have a `value` and a `title` property.\n * The generated options will be placed above given JSX based children.\n */\n data?: Data\n\n /**\n * Autocomplete specific props\n */\n autocompleteProps?: ToCamelCase<AutocompleteAllProps>\n\n /**\n * Dropdown specific props\n */\n dropdownProps?: ToCamelCase<DropdownAllProps>\n\n /**\n * The content of the component.\n */\n children?: React.ReactNode\n }\n\nfunction Selection(props: Props) {\n const clearValue = useMemo(() => `clear-option-${makeUniqueId()}`, [])\n\n const {\n id,\n className,\n variant = 'dropdown',\n label,\n labelDescription,\n layout = 'vertical',\n optionsLayout = 'vertical',\n placeholder,\n value,\n info,\n warning,\n error,\n hasError,\n disabled,\n help,\n emptyValue,\n width = 'large',\n htmlAttributes,\n setHasFocus,\n handleChange,\n data,\n dataPath,\n children,\n\n // - Autocomplete and Dropdown specific props\n autocompleteProps,\n dropdownProps,\n } = useFieldProps(props)\n\n const { getValueByPath } = useDataValue()\n let dataList = data\n if (dataPath) {\n dataList = getValueByPath(dataPath)\n }\n\n const handleDropdownChange = useCallback(\n ({ data }) => {\n const selectedKey = data?.selectedKey\n handleChange?.(\n !selectedKey || selectedKey === clearValue\n ? emptyValue\n : selectedKey\n )\n },\n [handleChange, emptyValue, clearValue]\n )\n\n const onChangeHandler = useCallback(\n ({ value }) => {\n handleChange?.(value === undefined ? emptyValue : value)\n },\n [handleChange, emptyValue]\n )\n\n // Specific handleShow and handleHide because Dropdown preserve the initially received callbacks, so changes\n // due to `useCallback` usage will have no effect, leading to useFieldPropss handleFocus and handleBlur sending out old\n // copies of value as arguments.\n const handleShow = useCallback(\n ({ data }) => {\n setHasFocus(true, data?.selectedKey)\n },\n [setHasFocus]\n )\n\n const handleHide = useCallback(\n ({ data }) => {\n setHasFocus(false, data?.selectedKey)\n },\n [setHasFocus]\n )\n\n const cn = classnames(\n 'dnb-forms-field-selection',\n `dnb-forms-field-selection__variant--${variant}`,\n `dnb-forms-field-selection__options-layout--${optionsLayout}`,\n className\n )\n\n const fieldBlockProps = {\n forId: id,\n className: cn,\n ...pickSpacingProps(props),\n info,\n warning,\n error,\n layout,\n label,\n labelDescription,\n }\n\n switch (variant) {\n case 'radio':\n case 'button': {\n const Component = (\n variant === 'radio' ? Radio : ToggleButton\n ) as typeof Radio & typeof ToggleButton\n\n const items = renderRadioItems({\n id,\n value,\n variant,\n info,\n warning,\n htmlAttributes,\n children,\n dataList,\n hasError,\n })\n\n return (\n <FieldBlock\n {...fieldBlockProps}\n asFieldset={React.Children.count(items) > 1}\n >\n <Component.Group\n className={cn}\n layout_direction={\n optionsLayout === 'horizontal' ? 'row' : 'column'\n }\n disabled={disabled}\n on_change={onChangeHandler}\n value={String(value ?? '')}\n >\n {items}\n </Component.Group>\n </FieldBlock>\n )\n }\n\n case 'autocomplete':\n case 'dropdown': {\n const status = getStatus(error, info, warning)\n const data = renderDropdownItems(dataList)\n .concat(makeOptions(children))\n .filter(Boolean)\n\n const sharedProps: AutocompleteAllProps & DropdownAllProps = {\n id,\n list_class: 'dnb-forms-field-selection__list',\n portal_class: 'dnb-forms-field-selection__portal',\n title: placeholder,\n value: String(value ?? ''),\n status: (hasError || status) && 'error',\n disabled,\n ...htmlAttributes,\n data,\n suffix: help ? (\n <HelpButton title={help.title}>{help.content}</HelpButton>\n ) : undefined,\n on_change: handleDropdownChange,\n on_show: handleShow,\n on_hide: handleHide,\n stretch: true,\n }\n\n return (\n <FieldBlock {...fieldBlockProps} width={width}>\n {variant === 'autocomplete' ? (\n <Autocomplete\n {...sharedProps}\n {...(autocompleteProps\n ? (convertCamelCaseProps(\n autocompleteProps\n ) as AutocompleteAllProps)\n : null)}\n />\n ) : (\n <Dropdown\n {...sharedProps}\n {...(dropdownProps\n ? (convertCamelCaseProps(\n dropdownProps\n ) as DropdownAllProps)\n : null)}\n />\n )}\n </FieldBlock>\n )\n }\n }\n}\n\nexport function getStatus(\n error: Error | FormError | undefined,\n info: React.ReactNode,\n warning: React.ReactNode\n) {\n return (\n error?.message ??\n ((warning instanceof Error && warning.message) ||\n (warning instanceof FormError && warning.message) ||\n warning?.toString() ||\n (info instanceof Error && info.message) ||\n (info instanceof FormError && info.message) ||\n info?.toString())\n )\n}\n\ntype OptionProps = React.ComponentProps<\n React.FC<{\n error?: Error | FormError | undefined\n title: React.ReactNode\n help?: HelpButtonProps\n children?: React.ReactNode\n }>\n>\n\nfunction renderRadioItems({\n id,\n value,\n variant,\n info,\n warning,\n htmlAttributes,\n children,\n dataList,\n hasError,\n}: {\n id: string\n value: Props['value']\n variant: Props['variant']\n info: Props['info']\n warning: Props['warning']\n htmlAttributes: Props['htmlAttributes']\n children: Props['children']\n dataList: Data\n hasError: ReturnAdditional<Props['value']>['hasError']\n}) {\n const optionsCount =\n React.Children.count(children) + (dataList?.length || 0)\n\n const createOption = (props: OptionProps, i: number) => {\n const { error, title, help, children, ...rest } = props\n\n const label = title ?? children\n const status = getStatus(error, info, warning)\n const suffix = help ? (\n <HelpButton size=\"small\" title={help.title}>\n {help.content}\n </HelpButton>\n ) : undefined\n\n const Component = (\n variant === 'radio' ? Radio : ToggleButton\n ) as typeof Radio & typeof ToggleButton\n\n return (\n <Component\n id={optionsCount === 1 ? id : undefined}\n key={`option-${i}-${id}`}\n label={variant === 'radio' ? label : undefined}\n text={variant === 'button' ? label : undefined}\n value={String(value ?? '')}\n status={(hasError || status) && 'error'}\n suffix={suffix}\n {...htmlAttributes}\n {...rest}\n />\n )\n }\n\n return [\n ...(dataList || []).map((props, i) => {\n return createOption(props as OptionProps, i)\n }),\n ...(mapOptions(children, { createOption }) || []),\n ].filter(Boolean)\n}\n\nexport function mapOptions(children: React.ReactNode, { createOption }) {\n return React.Children.map(\n children,\n (child: React.ReactElement<OptionProps>, i) => {\n if (React.isValidElement(child)) {\n if (child.type === OptionField) {\n return createOption(child.props, i)\n }\n\n if (child.props.children) {\n const nestedChildren = mapOptions(child.props.children, {\n createOption,\n })\n return React.cloneElement(child, child.props, nestedChildren)\n }\n }\n\n return child\n }\n )\n}\n\nexport function makeOptions<T = DrawerListProps['data']>(\n children: React.ReactNode\n): T {\n return React.Children.map(children, (child) => {\n if (child?.['props']?.children?.type === OptionField) {\n child = child['props'].children\n }\n\n if (React.isValidElement(child) && child.type === OptionField) {\n const props = child.props as OptionFieldProps\n const title = props.children ?? props.title ?? <em>Untitled</em>\n const content = props.text ? [title, props.text] : title\n const selectedKey = String(props.value ?? '')\n\n return { selectedKey, content }\n }\n\n // For other children, just show them as content\n if (child) {\n return {\n content: child,\n }\n }\n }) as T\n}\n\nfunction renderDropdownItems(data: Data) {\n return (\n data?.map(({ value, title, text }) => ({\n selectedKey: value,\n content: (text ? [title, text] : title) || <em>Untitled</em>,\n })) || []\n )\n}\n\nSelection._supportsSpacingProps = true\nexport default Selection\n"],"mappings":";;;;;;;AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,WAAW,QAAQ,OAAO;AACnD,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SACEC,YAAY,EACZC,QAAQ,EACRC,KAAK,EACLC,UAAU,EACVC,YAAY,QACP,wBAAwB;AAC/B,OAAOC,WAAW,MAAqC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,SAAS9B,mBAAmBA,CAAC/B,IAAU,EAAE;EACvC,OACE,CAAAA,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE2D,GAAG,CAAC,CAAC;IAAEvE,KAAK;IAAEmD,KAAK;IAAEmB;EAAK,CAAC,MAAM;IACrClD,WAAW,EAAEpB,KAAK;IAClBqD,OAAO,EAAE,CAACiB,IAAI,GAAG,CAACnB,KAAK,EAAEmB,IAAI,CAAC,GAAGnB,KAAK,KAAAkC,IAAA,KAAAA,IAAA,GAAKjH,KAAA,CAAA4D,aAAA,aAAI,UAAY,CAAC;EAC9D,CAAC,CAAC,CAAC,KAAI,EAAE;AAEb;AAEA3C,SAAS,CAACiG,qBAAqB,GAAG,IAAI;AACtC,eAAejG,SAAS"}
@@ -11,7 +11,7 @@ export type VisibleWhen = {
11
11
  hasValue: unknown;
12
12
  }
13
13
  /**
14
- * @deprecated Will be remove din v11!
14
+ * @deprecated Will be removed in v11!
15
15
  */
16
16
  | {
17
17
  path: Path;
@@ -19,7 +19,7 @@ export type VisibleWhen = {
19
19
  withValue: (value: unknown) => boolean;
20
20
  }
21
21
  /**
22
- * @deprecated Will be remove din v11!
22
+ * @deprecated Will be removed in v11!
23
23
  */
24
24
  | {
25
25
  itemPath: Path;
@@ -1 +1 @@
1
- {"version":3,"file":"Visibility.js","names":["React","warn","useMountEffect","HeightAnimation","FieldProvider","useVisibility","VisibilityContext","Visibility","_ref","visible","pathDefined","pathUndefined","pathTruthy","pathFalsy","pathTrue","pathFalse","pathValue","whenValue","visibleWhen","visibleWhenNot","inferData","filterData","animate","keepInDOM","compensateForGap","fieldPropsWhenHidden","children","rest","_objectWithoutProperties","_excluded","check","open","content","createElement","Provider","value","isVisible","props","_extends","Boolean","className","hidden","Fragment","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Form/Visibility/Visibility.tsx"],"sourcesContent":["import React, { AriaAttributes } from 'react'\n\nimport { warn } from '../../../../shared/helpers'\nimport useMountEffect from '../../../../shared/helpers/useMountEffect'\nimport HeightAnimation, {\n HeightAnimationProps,\n} from '../../../../components/HeightAnimation'\nimport FieldProvider from '../../Field/Provider'\nimport useVisibility from './useVisibility'\n\nimport type { Path, UseFieldProps } from '../../types'\nimport type { DataAttributes } from '../../hooks/useFieldProps'\nimport { FilterData } from '../../DataContext'\nimport VisibilityContext from './VisibilityContext'\n\nexport type VisibleWhen =\n | {\n path: Path\n hasValue: unknown\n }\n | {\n itemPath: Path\n hasValue: unknown\n }\n /**\n * @deprecated Will be remove din v11!\n */\n | {\n path: Path\n /** @deprecated Use `hasValue` instead */\n withValue: (value: unknown) => boolean\n }\n /**\n * @deprecated Will be remove din v11!\n */\n | {\n itemPath: Path\n /** @deprecated Use `hasValue` instead */\n withValue: (value: unknown) => boolean\n }\n\nexport type Props = {\n visible?: boolean\n /** Given data context path must be defined to show children */\n pathDefined?: Path\n /** Given data context path must be undefined to show children */\n pathUndefined?: Path\n /** Given data context path must be truthy to show children */\n pathTruthy?: Path\n /** Given data context path must be falsy to show children */\n pathFalsy?: Path\n /** Given data context path must be true to show children */\n pathTrue?: Path\n /** Given data context path must be false to show children */\n pathFalse?: Path\n /** Provide a `path` or `itemPath` and a `hasValue` method that returns a boolean or the excepted value in order to show children. The first parameter is the value of the path. */\n visibleWhen?: VisibleWhen\n /** Same as `visibleWhen`, but with inverted logic. */\n visibleWhenNot?: VisibleWhen\n /** Infer visibility calling given derivative function with the whole data set. Should return true/false for visibility. */\n inferData?: (data: unknown) => boolean\n /** Filter data based on provided criteria. The first parameter is the path, the second is the value, and the third is the props, and the fourth is the internal. Return false to filter out the data. */\n filterData?: FilterData\n /** Animate the visibility change */\n animate?: boolean\n /** Keep the content in the DOM, even if it's not visible */\n keepInDOM?: boolean\n /** To compensate for CSS gap between the rows, so animation does not jump during the animation. Provide a CSS unit or `auto`. Defaults to `null`. */\n compensateForGap?: HeightAnimationProps['compensateForGap']\n /** When visibility is hidden, and `keepInDOM` is true, pass these props to the children */\n fieldPropsWhenHidden?: UseFieldProps & DataAttributes & AriaAttributes\n element?: HeightAnimationProps['element']\n children: React.ReactNode\n\n /** @deprecated Use `visibleWhen` instead */\n pathValue?: string\n /** @deprecated Use `visibleWhen` instead */\n whenValue?: unknown\n}\n\nfunction Visibility({\n visible,\n pathDefined,\n pathUndefined,\n pathTruthy,\n pathFalsy,\n pathTrue,\n pathFalse,\n pathValue,\n whenValue,\n visibleWhen,\n visibleWhenNot,\n inferData,\n filterData,\n animate,\n keepInDOM,\n compensateForGap,\n fieldPropsWhenHidden,\n children,\n ...rest\n}: Props) {\n useMountEffect(() => {\n if (fieldPropsWhenHidden && !keepInDOM) {\n warn('Using \"fieldPropsWhenHidden\" requires \"keepInDOM\" to be true.')\n }\n })\n\n const { check } = useVisibility({\n visible,\n pathDefined,\n pathUndefined,\n pathTruthy,\n pathFalsy,\n pathTrue,\n pathFalse,\n pathValue,\n whenValue,\n visibleWhen,\n visibleWhenNot,\n inferData,\n filterData,\n })\n const open = check()\n const content = (\n <VisibilityContext.Provider\n value={{\n isVisible: open,\n }}\n >\n {children}\n </VisibilityContext.Provider>\n )\n\n if (animate) {\n const props = !open ? fieldPropsWhenHidden : null\n\n return (\n <HeightAnimation\n open={open}\n keepInDOM={Boolean(keepInDOM)}\n className=\"dnb-forms-visibility\"\n compensateForGap={compensateForGap}\n {...rest}\n >\n <FieldProvider {...props}>{content}</FieldProvider>\n </HeightAnimation>\n )\n }\n\n if (keepInDOM) {\n const props = !open ? fieldPropsWhenHidden : null\n return (\n <span className=\"dnb-forms-visibility\" hidden={!open}>\n <FieldProvider {...props}>{content}</FieldProvider>\n </span>\n )\n }\n\n return <>{open ? content : null}</>\n}\n\nVisibility._supportsSpacingProps = 'children'\nexport default Visibility\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAA0B,OAAO;AAE7C,SAASC,IAAI,QAAQ,4BAA4B;AACjD,OAAOC,cAAc,MAAM,2CAA2C;AACtE,OAAOC,eAAe,MAEf,wCAAwC;AAC/C,OAAOC,aAAa,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,sBAAsB;MAChChB,gBAAgB,EAAEA;IAAiB,GAC/BG,IAAI,GAER3B,KAAA,CAAAiC,aAAA,CAAC7B,aAAa,EAAKiC,KAAK,EAAGL,OAAuB,CACnC,CAAC;EAEtB;EAEA,IAAIT,SAAS,EAAE;IACb,MAAMc,KAAK,GAAG,CAACN,IAAI,GAAGN,oBAAoB,GAAG,IAAI;IACjD,OACEzB,KAAA,CAAAiC,aAAA;MAAMO,SAAS,EAAC,sBAAsB;MAACC,MAAM,EAAE,CAACV;IAAK,GACnD/B,KAAA,CAAAiC,aAAA,CAAC7B,aAAa,EAAKiC,KAAK,EAAGL,OAAuB,CAC9C,CAAC;EAEX;EAEA,OAAOhC,KAAA,CAAAiC,aAAA,CAAAjC,KAAA,CAAA0C,QAAA,QAAGX,IAAI,GAAGC,OAAO,GAAG,IAAO,CAAC;AACrC;AAEAzB,UAAU,CAACoC,qBAAqB,GAAG,UAAU;AAC7C,eAAepC,UAAU"}
1
+ {"version":3,"file":"Visibility.js","names":["React","warn","useMountEffect","HeightAnimation","FieldProvider","useVisibility","VisibilityContext","Visibility","_ref","visible","pathDefined","pathUndefined","pathTruthy","pathFalsy","pathTrue","pathFalse","pathValue","whenValue","visibleWhen","visibleWhenNot","inferData","filterData","animate","keepInDOM","compensateForGap","fieldPropsWhenHidden","children","rest","_objectWithoutProperties","_excluded","check","open","content","createElement","Provider","value","isVisible","props","_extends","Boolean","className","hidden","Fragment","_supportsSpacingProps"],"sources":["../../../../../../src/extensions/forms/Form/Visibility/Visibility.tsx"],"sourcesContent":["import React, { AriaAttributes } from 'react'\n\nimport { warn } from '../../../../shared/helpers'\nimport useMountEffect from '../../../../shared/helpers/useMountEffect'\nimport HeightAnimation, {\n HeightAnimationProps,\n} from '../../../../components/HeightAnimation'\nimport FieldProvider from '../../Field/Provider'\nimport useVisibility from './useVisibility'\n\nimport type { Path, UseFieldProps } from '../../types'\nimport type { DataAttributes } from '../../hooks/useFieldProps'\nimport { FilterData } from '../../DataContext'\nimport VisibilityContext from './VisibilityContext'\n\nexport type VisibleWhen =\n | {\n path: Path\n hasValue: unknown\n }\n | {\n itemPath: Path\n hasValue: unknown\n }\n /**\n * @deprecated Will be removed in v11!\n */\n | {\n path: Path\n /** @deprecated Use `hasValue` instead */\n withValue: (value: unknown) => boolean\n }\n /**\n * @deprecated Will be removed in v11!\n */\n | {\n itemPath: Path\n /** @deprecated Use `hasValue` instead */\n withValue: (value: unknown) => boolean\n }\n\nexport type Props = {\n visible?: boolean\n /** Given data context path must be defined to show children */\n pathDefined?: Path\n /** Given data context path must be undefined to show children */\n pathUndefined?: Path\n /** Given data context path must be truthy to show children */\n pathTruthy?: Path\n /** Given data context path must be falsy to show children */\n pathFalsy?: Path\n /** Given data context path must be true to show children */\n pathTrue?: Path\n /** Given data context path must be false to show children */\n pathFalse?: Path\n /** Provide a `path` or `itemPath` and a `hasValue` method that returns a boolean or the excepted value in order to show children. The first parameter is the value of the path. */\n visibleWhen?: VisibleWhen\n /** Same as `visibleWhen`, but with inverted logic. */\n visibleWhenNot?: VisibleWhen\n /** Infer visibility calling given derivative function with the whole data set. Should return true/false for visibility. */\n inferData?: (data: unknown) => boolean\n /** Filter data based on provided criteria. The first parameter is the path, the second is the value, and the third is the props, and the fourth is the internal. Return false to filter out the data. */\n filterData?: FilterData\n /** Animate the visibility change */\n animate?: boolean\n /** Keep the content in the DOM, even if it's not visible */\n keepInDOM?: boolean\n /** To compensate for CSS gap between the rows, so animation does not jump during the animation. Provide a CSS unit or `auto`. Defaults to `null`. */\n compensateForGap?: HeightAnimationProps['compensateForGap']\n /** When visibility is hidden, and `keepInDOM` is true, pass these props to the children */\n fieldPropsWhenHidden?: UseFieldProps & DataAttributes & AriaAttributes\n element?: HeightAnimationProps['element']\n children: React.ReactNode\n\n /** @deprecated Use `visibleWhen` instead */\n pathValue?: string\n /** @deprecated Use `visibleWhen` instead */\n whenValue?: unknown\n}\n\nfunction Visibility({\n visible,\n pathDefined,\n pathUndefined,\n pathTruthy,\n pathFalsy,\n pathTrue,\n pathFalse,\n pathValue,\n whenValue,\n visibleWhen,\n visibleWhenNot,\n inferData,\n filterData,\n animate,\n keepInDOM,\n compensateForGap,\n fieldPropsWhenHidden,\n children,\n ...rest\n}: Props) {\n useMountEffect(() => {\n if (fieldPropsWhenHidden && !keepInDOM) {\n warn('Using \"fieldPropsWhenHidden\" requires \"keepInDOM\" to be true.')\n }\n })\n\n const { check } = useVisibility({\n visible,\n pathDefined,\n pathUndefined,\n pathTruthy,\n pathFalsy,\n pathTrue,\n pathFalse,\n pathValue,\n whenValue,\n visibleWhen,\n visibleWhenNot,\n inferData,\n filterData,\n })\n const open = check()\n const content = (\n <VisibilityContext.Provider\n value={{\n isVisible: open,\n }}\n >\n {children}\n </VisibilityContext.Provider>\n )\n\n if (animate) {\n const props = !open ? fieldPropsWhenHidden : null\n\n return (\n <HeightAnimation\n open={open}\n keepInDOM={Boolean(keepInDOM)}\n className=\"dnb-forms-visibility\"\n compensateForGap={compensateForGap}\n {...rest}\n >\n <FieldProvider {...props}>{content}</FieldProvider>\n </HeightAnimation>\n )\n }\n\n if (keepInDOM) {\n const props = !open ? fieldPropsWhenHidden : null\n return (\n <span className=\"dnb-forms-visibility\" hidden={!open}>\n <FieldProvider {...props}>{content}</FieldProvider>\n </span>\n )\n }\n\n return <>{open ? content : null}</>\n}\n\nVisibility._supportsSpacingProps = 'children'\nexport default Visibility\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAA0B,OAAO;AAE7C,SAASC,IAAI,QAAQ,4BAA4B;AACjD,OAAOC,cAAc,MAAM,2CAA2C;AACtE,OAAOC,eAAe,MAEf,wCAAwC;AAC/C,OAAOC,aAAa,MAAM,sBAAsB;AAChD,OAAOC,aAAa,MAAM,iBAAiB;AAK3C,OAAOC,iBAAiB,MAAM,qBAAqB;AAmEnD,SAASC,UAAUA,CAAAC,IAAA,EAoBT;EAAA,IApBU;MAClBC,OAAO;MACPC,WAAW;MACXC,aAAa;MACbC,UAAU;MACVC,S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ACN,IAAI,GAAGN,oBAAoB,GAAG,IAAI;IACjD,OACEzB,KAAA,CAAAiC,aAAA;MAAMO,SAAS,EAAC,sBAAsB;MAACC,MAAM,EAAE,CAACV;IAAK,GACnD/B,KAAA,CAAAiC,aAAA,CAAC7B,aAAa,EAAKiC,KAAK,EAAGL,OAAuB,CAC9C,CAAC;EAEX;EAEA,OAAOhC,KAAA,CAAAiC,aAAA,CAAAjC,KAAA,CAAA0C,QAAA,QAAGX,IAAI,GAAGC,OAAO,GAAG,IAAO,CAAC;AACrC;AAEAzB,UAAU,CAACoC,qBAAqB,GAAG,UAAU;AAC7C,eAAepC,UAAU"}
@@ -32,7 +32,7 @@ export default function useFieldProps(localeProps, {
32
32
  executeOnChangeRegardlessOfError = false,
33
33
  updateContextDataInSync = false
34
34
  } = {}) {
35
- var _dataContext$props, _useExternalValue, _dataContext$ajvInsta, _localErrorRef$curren, _ref, _dataContext$props3, _props$path, _props$autoComplete;
35
+ var _dataContext$props, _transformers$current, _dataContext$ajvInsta, _localErrorRef$curren, _ref, _dataContext$props3, _props$path, _props$autoComplete;
36
36
  const {
37
37
  extend
38
38
  } = useContext(FieldProviderContext);
@@ -156,13 +156,13 @@ export default function useFieldProps(localeProps, {
156
156
  useLayoutEffect(() => {
157
157
  defaultValueRef.current = defaultValue;
158
158
  }, []);
159
- const externalValue = (_useExternalValue = useExternalValue({
159
+ const externalValue = (_transformers$current = transformers.current.transformIn(useExternalValue({
160
160
  path,
161
161
  itemPath,
162
162
  value: valueProp,
163
163
  transformers,
164
164
  emptyValue
165
- })) !== null && _useExternalValue !== void 0 ? _useExternalValue : defaultValueRef.current;
165
+ }))) !== null && _transformers$current !== void 0 ? _transformers$current : defaultValueRef.current;
166
166
  const valueRef = useRef(externalValue);
167
167
  const changedRef = useRef();
168
168
  const hasFocusRef = useRef();
@@ -665,10 +665,11 @@ export default function useFieldProps(localeProps, {
665
665
  }) => {
666
666
  const value = transformers.current.toEvent(overrideValue !== null && overrideValue !== void 0 ? overrideValue : valueRef.current, eventName);
667
667
  const args = transformers.current.provideAdditionalArgs(value, additionalArgs);
668
+ const transformedValue = transformers.current.transformOut(value, args);
668
669
  if (typeof args !== 'undefined') {
669
- return [value, args];
670
+ return [transformedValue, args];
670
671
  }
671
- return [value];
672
+ return [transformedValue];
672
673
  }, []);
673
674
  const setHasFocus = useCallback(async (hasFocus, overrideValue, additionalArgs) => {
674
675
  const args = getEventArgs({
@@ -797,19 +798,25 @@ export default function useFieldProps(localeProps, {
797
798
  forceUpdate();
798
799
  }, [asyncBehaviorIsEnabled, executeOnChangeRegardlessOfError, hasPath, yieldAsyncProcess, onChangeContext, defineAsyncProcess, hasError, setEventResult, handlePathChangeDataContext, identifier]);
799
800
  const updateValue = useCallback(async newValue => {
800
- if (newValue === valueRef.current) {
801
+ const currentValue = valueRef.current;
802
+ if (newValue === currentValue) {
801
803
  return;
802
804
  }
803
- valueRef.current = newValue;
805
+ const transformedValue = transformers.current.transformValue(newValue, currentValue);
806
+ const contextValue = transformers.current.transformOut(transformedValue, transformers.current.provideAdditionalArgs(transformedValue, additionalArgs));
807
+ valueRef.current = transformedValue;
804
808
  if (hasPath) {
805
- handlePathChangeUnvalidatedDataContext(identifier, newValue);
809
+ handlePathChangeUnvalidatedDataContext(identifier, contextValue);
810
+ }
811
+ if (itemPath) {
812
+ handleChangeIterateContext === null || handleChangeIterateContext === void 0 ? void 0 : handleChangeIterateContext(makeIteratePath(itemPath, ''), contextValue);
806
813
  }
807
814
  addToPool('validator', validateValue, isAsync(onChangeValidatorRef.current));
808
815
  addToPool('onChangeContext', callOnChangeContext, isAsync(onChangeContext));
809
816
  await runPool(() => {
810
817
  handleError();
811
818
  });
812
- }, [hasPath, addToPool, validateValue, callOnChangeContext, onChangeContext, runPool, handlePathChangeUnvalidatedDataContext, identifier, handleError]);
819
+ }, [additionalArgs, hasPath, itemPath, addToPool, validateValue, callOnChangeContext, onChangeContext, runPool, handlePathChangeUnvalidatedDataContext, identifier, handleChangeIterateContext, makeIteratePath, handleError]);
813
820
  const setChanged = state => {
814
821
  changedRef.current = state;
815
822
  };
@@ -819,16 +826,12 @@ export default function useFieldProps(localeProps, {
819
826
  if (fromInput === currentValue) {
820
827
  return;
821
828
  }
822
- const transformedValue = transformers.current.transformOut(transformers.current.transformValue(fromInput, currentValue), transformers.current.provideAdditionalArgs(fromInput, additionalArgs));
823
829
  changedRef.current = true;
824
- if (itemPath) {
825
- handleChangeIterateContext === null || handleChangeIterateContext === void 0 ? void 0 : handleChangeIterateContext(makeIteratePath(itemPath, ''), transformedValue);
826
- }
827
830
  if (asyncBehaviorIsEnabled) {
828
831
  hideError();
829
- await updateValue(transformedValue);
832
+ await updateValue(fromInput);
830
833
  } else {
831
- updateValue(transformedValue);
834
+ updateValue(fromInput);
832
835
  }
833
836
  if (isAsync(onChange)) {
834
837
  addToPool('onChangeLocal', async () => {
@@ -867,7 +870,7 @@ export default function useFieldProps(localeProps, {
867
870
  setEventResult(onChange === null || onChange === void 0 ? void 0 : onChange.apply(this, args));
868
871
  }
869
872
  await runPool();
870
- }, [itemPath, asyncBehaviorIsEnabled, onChange, runPool, handleChangeIterateContext, makeIteratePath, hideError, updateValue, addToPool, getEventArgs, yieldAsyncProcess, defineAsyncProcess, hasError, setEventResult]);
873
+ }, [asyncBehaviorIsEnabled, onChange, runPool, hideError, updateValue, addToPool, getEventArgs, yieldAsyncProcess, defineAsyncProcess, hasError, setEventResult]);
871
874
  const handleFocus = useCallback(() => setHasFocus(true), [setHasFocus]);
872
875
  const handleBlur = useCallback(() => setHasFocus(false), [setHasFocus]);
873
876
  setFieldPropsDataContext === null || setFieldPropsDataContext === void 0 ? void 0 : setFieldPropsDataContext(identifier, props);
@@ -973,12 +976,12 @@ export default function useFieldProps(localeProps, {
973
976
  let valueToStore = valueProp;
974
977
  const data = wizardContext !== null && wizardContext !== void 0 && wizardContext.prerenderFieldProps ? dataContext.data : (_dataContext$internal = dataContext.internalDataRef) === null || _dataContext$internal === void 0 ? void 0 : _dataContext$internal.current;
975
978
  const hasValue = pointer.has(data, identifier) || identifier === '/';
976
- const existingValue = identifier === '/' ? data : hasValue ? pointer.get(data, identifier) : undefined;
979
+ const existingValue = transformers.current.transformIn(identifier === '/' ? data : hasValue ? pointer.get(data, identifier) : undefined);
977
980
  if (dataContext.id && !hasValue && typeof existingValue === 'undefined' && typeof valueToStore === 'undefined') {
978
981
  const sharedState = createSharedState(dataContext.id);
979
982
  const hasValue = pointer.has(sharedState.data, identifier);
980
983
  if (hasValue) {
981
- const sharedValue = pointer.get(sharedState.data, identifier);
984
+ const sharedValue = transformers.current.transformIn(pointer.get(sharedState.data, identifier));
982
985
  if (sharedValue) {
983
986
  valueToStore = sharedValue;
984
987
  }
@@ -1162,7 +1165,7 @@ export default function useFieldProps(localeProps, {
1162
1165
  name: props.name || ((_props$path = props.path) === null || _props$path === void 0 ? void 0 : _props$path.replace('/', '')) || id,
1163
1166
  autoComplete: (_props$autoComplete = props.autoComplete) !== null && _props$autoComplete !== void 0 ? _props$autoComplete : dataContext.autoComplete === true ? 'on' : undefined,
1164
1167
  id,
1165
- value: transformers.current.transformIn(transformers.current.toInput(valueRef.current)),
1168
+ value: transformers.current.toInput(valueRef.current),
1166
1169
  hasError: hasVisibleError,
1167
1170
  isChanged: Boolean(changedRef.current),
1168
1171
  props,