@dnb/eufemia 10.1.0 → 10.2.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/cjs/components/anchor/style/deps.scss +9 -0
  3. package/cjs/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
  4. package/cjs/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
  5. package/cjs/components/button/style/themes/dnb-button-theme-ui.css +4 -0
  6. package/cjs/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
  7. package/cjs/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
  8. package/cjs/components/global-status/GlobalStatus.d.ts +3 -3
  9. package/cjs/components/heading/Heading.d.ts +89 -106
  10. package/cjs/components/heading/Heading.js +119 -184
  11. package/cjs/components/heading/HeadingContext.d.ts +12 -5
  12. package/cjs/components/heading/HeadingContext.js +2 -2
  13. package/cjs/components/heading/HeadingCounter.d.ts +38 -14
  14. package/cjs/components/heading/HeadingCounter.js +20 -17
  15. package/cjs/components/heading/HeadingHelpers.d.ts +45 -23
  16. package/cjs/components/heading/HeadingHelpers.js +29 -24
  17. package/cjs/components/heading/HeadingProvider.d.ts +9 -12
  18. package/cjs/components/heading/HeadingProvider.js +47 -90
  19. package/cjs/components/info-card/style/dnb-info-card.css +1 -1
  20. package/cjs/components/info-card/style/dnb-info-card.min.css +1 -1
  21. package/cjs/components/info-card/style/dnb-info-card.scss +1 -1
  22. package/cjs/shared/Eufemia.d.ts +1 -1
  23. package/cjs/shared/Eufemia.js +2 -2
  24. package/cjs/shared/index.d.ts +2 -1
  25. package/cjs/style/dnb-ui-components.css +1 -1
  26. package/cjs/style/dnb-ui-components.min.css +1 -1
  27. package/cjs/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
  28. package/cjs/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
  29. package/cjs/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
  30. package/cjs/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
  31. package/cjs/style/themes/theme-ui/ui-theme-components.css +5 -1
  32. package/cjs/style/themes/theme-ui/ui-theme-components.min.css +1 -1
  33. package/components/anchor/style/deps.scss +9 -0
  34. package/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
  35. package/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
  36. package/components/button/style/themes/dnb-button-theme-ui.css +4 -0
  37. package/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
  38. package/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
  39. package/components/global-status/GlobalStatus.d.ts +3 -3
  40. package/components/heading/Heading.d.ts +89 -106
  41. package/components/heading/Heading.js +115 -183
  42. package/components/heading/HeadingContext.d.ts +12 -5
  43. package/components/heading/HeadingContext.js +2 -2
  44. package/components/heading/HeadingCounter.d.ts +38 -14
  45. package/components/heading/HeadingCounter.js +20 -17
  46. package/components/heading/HeadingHelpers.d.ts +45 -23
  47. package/components/heading/HeadingHelpers.js +27 -13
  48. package/components/heading/HeadingProvider.d.ts +9 -12
  49. package/components/heading/HeadingProvider.js +46 -90
  50. package/components/info-card/style/dnb-info-card.css +1 -1
  51. package/components/info-card/style/dnb-info-card.min.css +1 -1
  52. package/components/info-card/style/dnb-info-card.scss +1 -1
  53. package/es/components/anchor/style/deps.scss +9 -0
  54. package/es/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
  55. package/es/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
  56. package/es/components/button/style/themes/dnb-button-theme-ui.css +4 -0
  57. package/es/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
  58. package/es/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
  59. package/es/components/global-status/GlobalStatus.d.ts +3 -3
  60. package/es/components/heading/Heading.d.ts +89 -106
  61. package/es/components/heading/Heading.js +115 -183
  62. package/es/components/heading/HeadingContext.d.ts +12 -5
  63. package/es/components/heading/HeadingContext.js +2 -2
  64. package/es/components/heading/HeadingCounter.d.ts +38 -14
  65. package/es/components/heading/HeadingCounter.js +19 -18
  66. package/es/components/heading/HeadingHelpers.d.ts +45 -23
  67. package/es/components/heading/HeadingHelpers.js +27 -13
  68. package/es/components/heading/HeadingProvider.d.ts +9 -12
  69. package/es/components/heading/HeadingProvider.js +46 -90
  70. package/es/components/info-card/style/dnb-info-card.css +1 -1
  71. package/es/components/info-card/style/dnb-info-card.min.css +1 -1
  72. package/es/components/info-card/style/dnb-info-card.scss +1 -1
  73. package/es/shared/Eufemia.d.ts +1 -1
  74. package/es/shared/Eufemia.js +2 -2
  75. package/es/shared/index.d.ts +2 -1
  76. package/es/style/dnb-ui-components.css +1 -1
  77. package/es/style/dnb-ui-components.min.css +1 -1
  78. package/es/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
  79. package/es/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
  80. package/es/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
  81. package/es/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
  82. package/es/style/themes/theme-ui/ui-theme-components.css +5 -1
  83. package/es/style/themes/theme-ui/ui-theme-components.min.css +1 -1
  84. package/esm/dnb-ui-basis.min.mjs +1 -1
  85. package/esm/dnb-ui-components.min.mjs +1 -1
  86. package/esm/dnb-ui-elements.min.mjs +1 -1
  87. package/esm/dnb-ui-extensions.min.mjs +1 -1
  88. package/esm/dnb-ui-lib.min.mjs +1 -1
  89. package/package.json +1 -1
  90. package/shared/Eufemia.d.ts +1 -1
  91. package/shared/Eufemia.js +2 -2
  92. package/shared/index.d.ts +2 -1
  93. package/style/dnb-ui-components.css +1 -1
  94. package/style/dnb-ui-components.min.css +1 -1
  95. package/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
  96. package/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
  97. package/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
  98. package/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
  99. package/style/themes/theme-ui/ui-theme-components.css +5 -1
  100. package/style/themes/theme-ui/ui-theme-components.min.css +1 -1
  101. package/umd/dnb-ui-basis.min.js +1 -1
  102. package/umd/dnb-ui-components.min.js +1 -1
  103. package/umd/dnb-ui-elements.min.js +1 -1
  104. package/umd/dnb-ui-extensions.min.js +1 -1
  105. package/umd/dnb-ui-lib.min.js +1 -1
@@ -1,107 +1,90 @@
1
- import * as React from 'react';
2
- import type { SkeletonShow } from '../Skeleton';
3
- import type { SpacingProps } from '../space/types';
4
- type HeadingText = React.ReactNode | ((...args: any[]) => any);
5
- type HeadingSize =
6
- | 'auto'
7
- | 'xx-large'
8
- | 'x-large'
9
- | 'large'
10
- | 'medium'
11
- | 'basis'
12
- | 'small'
13
- | 'x-small';
14
- type HeadingLevel = number | string;
15
- type HeadingDebug = boolean | ((...args: any[]) => any);
16
- type HeadingDebugCounter = boolean | ((...args: any[]) => any);
17
- type HeadingReset = number | boolean;
18
- type HeadingChildren = React.ReactNode | ((...args: any[]) => any);
19
- export interface HeadingProps
20
- extends Omit<React.HTMLProps<HTMLElement>, 'ref'>,
21
- SpacingProps {
22
- id?: string;
23
- group?: string;
24
-
25
- /**
26
- * <em>(required)</em> a heading, can be text or React.Node.
27
- */
28
- text?: HeadingText;
29
-
30
- /**
31
- * Define the typography <a href="/uilib/typography/font-size">font-size</a> by a size <em>type</em>, e.g. `x-large`. Defaults to the predefined heading sizes.
32
- */
33
- size?: HeadingSize;
34
- level?: HeadingLevel;
35
-
36
- /**
37
- * If set to `true`, the heading level will be incremented by 1.
38
- */
39
- increase?: boolean;
40
-
41
- /**
42
- * If set to `true`, the heading level will be decremented by 1.
43
- */
44
- decrease?: boolean;
45
- up?: boolean;
46
- down?: boolean;
47
-
48
- /**
49
- * If set to `true`, the heading will not be corrected and warnings will not be shown. Warnings do not show up in "production builds" else either.
50
- */
51
- skip_correction?: boolean;
52
-
53
- /**
54
- * If set to `true`, the content will have a prefix, showing the heading level.
55
- */
56
- debug?: HeadingDebug;
57
-
58
- /**
59
- * If set to `true`, the content will have both a prefix and a JSON log attached to both headings and level contexts.
60
- */
61
- debug_counter?: HeadingDebugCounter;
62
- counter?: any;
63
-
64
- /**
65
- * If set to `true`, the heading last used level will be inherited. Also from inside a level context.
66
- */
67
- inherit?: boolean;
68
-
69
- /**
70
- * If set to `true`, the heading level will be reset to 2. You can give it a custom level if you need to, e.g. `reset(1)`.
71
- */
72
- reset?: HeadingReset;
73
-
74
- /**
75
- * If set to `true`, an overlaying skeleton with animation will be shown.
76
- */
77
- skeleton?: SkeletonShow;
78
-
79
- /**
80
- * Define what HTML element should be used. If you use, e.g. a `span`, then `role="heading"` and `aria-level` gets set. Defaults to semantic heading element.
81
- */
82
- element?: string;
83
- class?: string;
84
- className?: string;
85
-
86
- /**
87
- * <em>(required)</em> a heading, can be text or React.Node.
88
- */
89
- children?: HeadingChildren;
1
+ /**
2
+ * Web Heading Component
3
+ *
4
+ */
5
+ import React from 'react';
6
+ import '../../shared/helpers';
7
+ import HeadingProvider from './HeadingProvider';
8
+ import { resetLevels, resetAllLevels, setNextLevel } from './HeadingHelpers';
9
+ import { HeadingCounter, HeadingDebugCounter } from './HeadingCounter';
10
+ import { SpacingProps } from '../space/types';
11
+ import { SkeletonShow } from '../Skeleton';
12
+ import { DynamicElement } from '../../shared/types';
13
+ export declare const levelResolution: {
14
+ 1: string;
15
+ 2: string;
16
+ 3: string;
17
+ 4: string;
18
+ 5: string;
19
+ 6: string;
20
+ };
21
+ export declare type HeadingSize = 'auto' | 'xx-large' | 'x-large' | 'large' | 'medium' | 'basis' | 'small' | 'x-small';
22
+ export declare type HeadingLevel = '1' | '2' | '3' | '4' | '5' | '6' | 1 | 2 | 3 | 4 | 5 | 6;
23
+ export declare type InternalHeadingLevel = number;
24
+ export declare type HeadingProps = {
25
+ id?: string;
26
+ group?: string;
27
+ /**
28
+ * <em>(required)</em> a heading, can be text or React.Node.
29
+ */
30
+ text?: React.ReactNode;
31
+ /**
32
+ * Define the typography <a href="/uilib/typography/font-size">font-size</a> by a size <em>type</em>, e.g. `x-large`. Defaults to the predefined heading sizes.
33
+ */
34
+ size?: HeadingSize;
35
+ level?: HeadingLevel;
36
+ /**
37
+ * If set to `true`, the heading level will be incremented by 1.
38
+ */
39
+ increase?: boolean;
40
+ /**
41
+ * If set to `true`, the heading level will be decremented by 1.
42
+ */
43
+ decrease?: boolean;
44
+ up?: boolean;
45
+ down?: boolean;
46
+ /**
47
+ * If set to `true`, the heading will not be corrected and warnings will not be shown. Warnings do not show up in "production builds" else either.
48
+ */
49
+ skip_correction?: boolean;
50
+ /**
51
+ * If set to `true`, the content will have a prefix, showing the heading level.
52
+ */
53
+ debug?: boolean | (() => void);
54
+ /**
55
+ * If set to `true`, the content will have both a prefix and a JSON log attached to both headings and level contexts.
56
+ */
57
+ debug_counter?: HeadingDebugCounter;
58
+ counter?: HeadingCounter;
59
+ /**
60
+ * If set to `true`, the heading last used level will be inherited. Also from inside a level context.
61
+ */
62
+ inherit?: boolean;
63
+ /**
64
+ * If set to `true`, the heading level will be reset to 2. You can give it a custom level if you need to, e.g. `reset(1)`.
65
+ */
66
+ reset?: number | boolean;
67
+ /**
68
+ * If set to `true`, an overlaying skeleton with animation will be shown.
69
+ */
70
+ skeleton?: SkeletonShow;
71
+ /**
72
+ * Define what HTML element should be used. If you use, e.g. a `span`, then `role="heading"` and `aria-level` gets set. Defaults to semantic heading element.
73
+ */
74
+ element?: DynamicElement;
75
+ };
76
+ export declare type HeadingAllProps = HeadingProps & Omit<React.HTMLProps<HTMLElement>, 'size'> & SpacingProps;
77
+ declare function Heading(props: HeadingAllProps): JSX.Element;
78
+ declare namespace Heading {
79
+ var Level: typeof HeadingProvider;
80
+ var Increase: (props: HeadingStaticProps) => JSX.Element;
81
+ var Decrease: (props: HeadingStaticProps) => JSX.Element;
82
+ var Up: (props: HeadingStaticProps) => JSX.Element;
83
+ var Down: (props: HeadingStaticProps) => JSX.Element;
84
+ var Reset: (props: HeadingStaticProps) => JSX.Element;
85
+ var resetLevels: typeof import("./HeadingHelpers").resetLevels;
86
+ var setNextLevel: typeof import("./HeadingHelpers").setNextLevel;
90
87
  }
91
- export default class Heading extends React.Component<HeadingProps, any> {
92
- static defaultProps: object;
93
- static Level: (props: HeadingProps) => JSX.Element;
94
- static Increase: (props: HeadingProps) => JSX.Element;
95
- static Decrease: (props: HeadingProps) => JSX.Element;
96
- static resetLevels: resetLevels;
97
- static setNextLevel: setNextLevel;
98
- render(): JSX.Element;
99
- }
100
- export const setNextLevel = (
101
- level: HeadingLevel,
102
- { overwriteContext: boolean } = {}
103
- ) => null;
104
- export const resetLevels = (
105
- level: HeadingLevel,
106
- { overwriteContext: boolean } = {}
107
- ) => null;
88
+ export default Heading;
89
+ declare type HeadingStaticProps = Omit<HeadingAllProps, 'ref' | 'size'>;
90
+ export { resetAllLevels, resetLevels, setNextLevel };
@@ -1,23 +1,22 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- const _excluded = ["text", "relevel", "group", "debug", "debug_counter", "reset", "skip_correction", "increase", "decrease", "up", "down", "inherit", "level", "size", "skeleton", "element", "class", "className", "children"];
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ const _excluded = ["text", "group", "debug", "debug_counter", "reset", "skip_correction", "increase", "decrease", "up", "down", "inherit", "level", "size", "skeleton", "element", "className", "children"];
5
5
 
6
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7
7
 
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
9
 
10
10
  import React from 'react';
11
- import PropTypes from 'prop-types';
12
11
  import classnames from 'classnames';
13
12
  import { isTrue, validateDOMAttributes } from '../../shared/component-helper';
14
13
  import '../../shared/helpers';
15
- import { spacingPropTypes, createSpacingClasses } from '../space/SpacingHelper';
14
+ import { createSpacingClasses } from '../space/SpacingHelper';
16
15
  import HeadingContext from './HeadingContext';
17
16
  import Context from '../../shared/Context';
18
17
  import HeadingProvider from './HeadingProvider';
19
18
  import { createSkeletonClass } from '../skeleton/SkeletonHelper';
20
- import { correctHeadingLevel, resetLevels, resetAllLevels, setNextLevel, globalSyncCounter, globalHeadingCounter, windupHeadings, teardownHeadings, debugCounter } from './HeadingHelpers';
19
+ import { correctInternalHeadingLevel, resetLevels, resetAllLevels, setNextLevel, globalSyncCounter, globalHeadingCounter, windupHeadings, teardownHeadings, debugCounter } from './HeadingHelpers';
21
20
  import { initCounter } from './HeadingCounter';
22
21
  export const levelResolution = {
23
22
  1: 'xx-large',
@@ -27,205 +26,138 @@ export const levelResolution = {
27
26
  5: 'small',
28
27
  6: 'x-small'
29
28
  };
30
- export default class Heading extends React.PureComponent {
31
- static getDerivedStateFromProps(props, state) {
32
- if (state._listenForPropChanges) {
33
- const level = parseFloat(props.level);
34
-
35
- if (state.prevLevel !== props.level && level > 0 && level !== state.level || props.relevel) {
36
- var _state$context$headin, _state$context$headin2;
37
-
38
- state.counter.skipMakeMeReady();
39
- const {
40
- level: newLevel
41
- } = correctHeadingLevel({
42
- counter: state.counter,
43
- level,
44
- bypassChecks: isTrue(props.skip_correction) || isTrue((_state$context$headin = state.context.heading) === null || _state$context$headin === void 0 ? void 0 : _state$context$headin.skip_correction),
45
- source: props.text || props.children,
46
- debug: props.debug || ((_state$context$headin2 = state.context.heading) === null || _state$context$headin2 === void 0 ? void 0 : _state$context$headin2.debug)
47
- });
48
- state.level = state.prevLevel = newLevel;
49
- }
50
- }
51
-
52
- state._listenForPropChanges = true;
53
- return state;
54
- }
55
-
56
- constructor(props, context) {
57
- var _context$heading, _state$context$headin3, _state$context$headin4;
29
+ export default function Heading(props) {
30
+ var _headingContext$headi2, _headingContext$headi3;
31
+
32
+ const context = React.useContext(Context);
33
+ const headingContext = React.useContext(HeadingContext);
34
+
35
+ const _ref = React.useRef();
36
+
37
+ const {
38
+ text,
39
+ group: _group,
40
+ debug: _debug,
41
+ debug_counter: _debug_counter,
42
+ reset: _reset,
43
+ skip_correction: _skip_correction,
44
+ increase: _increase,
45
+ decrease: _decrease,
46
+ up: _up,
47
+ down: _down,
48
+ inherit: _inherit,
49
+ level: _level,
50
+ size: _size = 'auto',
51
+ skeleton: _skeleton,
52
+ element: _element,
53
+ className,
54
+ children
55
+ } = props,
56
+ rest = _objectWithoutProperties(props, _excluded);
57
+
58
+ const [state, setState] = React.useState(() => {
59
+ var _headingContext$headi, _state$headingContext, _state$headingContext2, _state$headingContext3, _state$headingContext4;
58
60
 
59
- super(props);
60
- this._ref = React.createRef();
61
61
  const state = {
62
+ level: null,
63
+ counter: null,
62
64
  context,
63
- _listenForPropChanges: true
65
+ headingContext
64
66
  };
65
-
66
- if ((_context$heading = context.heading) !== null && _context$heading !== void 0 && _context$heading.counter) {
67
- state.counter = initCounter(props);
68
- state.counter.setContextCounter(context.heading.counter);
69
- state.counter.isHeading = true;
70
- } else {
71
- state.counter = initCounter(props);
72
- state.counter.setContextCounter(globalHeadingCounter.current);
73
- state.counter.isHeading = true;
74
- }
75
-
76
- state.counter = correctHeadingLevel({
77
- ref: props,
67
+ state.counter = initCounter(props);
68
+ const counter = (_headingContext$headi = headingContext.heading) !== null && _headingContext$headi !== void 0 && _headingContext$headi.counter ? headingContext.heading.counter : globalHeadingCounter.current;
69
+ state.counter.setContextCounter(counter);
70
+ state.counter.isHeading = true;
71
+ state.counter = correctInternalHeadingLevel({
78
72
  counter: state.counter,
79
- level: parseFloat(props.level),
73
+ ref: props,
74
+ level: parseFloat(String(props.level)),
80
75
  inherit: isTrue(props.inherit),
81
76
  reset: props.reset,
82
77
  increase: isTrue(props.increase) || isTrue(props.up),
83
78
  decrease: isTrue(props.decrease) || isTrue(props.down),
84
- bypassChecks: isTrue(props.skip_correction) || isTrue((_state$context$headin3 = state.context.heading) === null || _state$context$headin3 === void 0 ? void 0 : _state$context$headin3.skip_correction),
79
+ bypassChecks: isTrue(props.skip_correction) || isTrue((_state$headingContext = state.headingContext) === null || _state$headingContext === void 0 ? void 0 : (_state$headingContext2 = _state$headingContext.heading) === null || _state$headingContext2 === void 0 ? void 0 : _state$headingContext2.skip_correction),
85
80
  source: props.text || props.children,
86
- debug: props.debug || ((_state$context$headin4 = state.context.heading) === null || _state$context$headin4 === void 0 ? void 0 : _state$context$headin4.debug)
81
+ debug: props.debug || ((_state$headingContext3 = state.headingContext) === null || _state$headingContext3 === void 0 ? void 0 : (_state$headingContext4 = _state$headingContext3.heading) === null || _state$headingContext4 === void 0 ? void 0 : _state$headingContext4.debug)
87
82
  });
88
83
  globalSyncCounter.current = state.counter;
89
84
  state.level = state.counter.level;
90
- state.prevLevel = props.level;
91
- this.state = state;
92
- }
93
-
94
- componentDidMount() {
85
+ state.prevLevel = parseFloat(String(props.level));
86
+ return state;
87
+ });
88
+ React.useEffect(() => {
95
89
  windupHeadings();
96
- this.state.counter.windup();
97
- }
98
-
99
- componentWillUnmount() {
100
- teardownHeadings();
101
- this.state.counter.teardown();
102
- }
103
-
104
- render() {
105
- var _this$context$heading, _this$context$heading2;
106
-
107
- const _this$props = this.props,
108
- {
109
- text,
110
- relevel: _relevel,
111
- group: _group,
112
- debug: _debug,
113
- debug_counter: _debug_counter,
114
- reset: _reset,
115
- skip_correction: _skip_correction,
116
- increase: _increase,
117
- decrease: _decrease,
118
- up: _up,
119
- down: _down,
120
- inherit: _inherit,
121
- level: _level,
122
- size: _size,
123
- skeleton: _skeleton,
124
- element: _element,
125
- class: _className,
126
- className,
127
- children
128
- } = _this$props,
129
- rest = _objectWithoutProperties(_this$props, _excluded);
130
-
131
- let {
132
- size,
133
- element,
134
- skeleton
135
- } = this.props;
136
- const {
137
- level
138
- } = this.state;
139
- const debug = _debug || ((_this$context$heading = this.context.heading) === null || _this$context$heading === void 0 ? void 0 : _this$context$heading.debug);
140
- const debug_counter = _debug_counter || ((_this$context$heading2 = this.context.heading) === null || _this$context$heading2 === void 0 ? void 0 : _this$context$heading2.debug_counter);
141
-
142
- const attributes = _objectSpread({}, rest);
143
-
144
- if (element === 'auto' || element === null) {
145
- element = `h${level || '6'}`;
146
-
147
- if (_size === 'auto' || _size === null) {
148
- size = levelResolution[level || '6'];
149
- }
150
- } else {
151
- if (!attributes.role) {
152
- attributes.role = 'heading';
153
- }
90
+ state.counter.windup();
91
+ return () => {
92
+ teardownHeadings();
93
+ state.counter.teardown();
94
+ };
95
+ }, []);
96
+ React.useEffect(() => {
97
+ const level = parseFloat(String(props.level));
98
+
99
+ if (state.prevLevel !== props.level && level > 0 && level !== state.level) {
100
+ var _state$headingContext5, _state$headingContext6, _state$headingContext7, _state$headingContext8;
101
+
102
+ const {
103
+ level: newLevel
104
+ } = correctInternalHeadingLevel({
105
+ counter: state.counter,
106
+ isRerender: true,
107
+ level,
108
+ bypassChecks: isTrue(props.skip_correction) || isTrue((_state$headingContext5 = state.headingContext) === null || _state$headingContext5 === void 0 ? void 0 : (_state$headingContext6 = _state$headingContext5.heading) === null || _state$headingContext6 === void 0 ? void 0 : _state$headingContext6.skip_correction),
109
+ source: props.text || props.children,
110
+ debug: props.debug || ((_state$headingContext7 = state.headingContext) === null || _state$headingContext7 === void 0 ? void 0 : (_state$headingContext8 = _state$headingContext7.heading) === null || _state$headingContext8 === void 0 ? void 0 : _state$headingContext8.debug)
111
+ });
112
+ state.level = state.prevLevel = newLevel;
113
+ setState(_objectSpread({}, state));
114
+ }
115
+ }, [props.level]);
116
+ let {
117
+ size,
118
+ element = 'auto',
119
+ skeleton
120
+ } = props;
121
+ const {
122
+ level
123
+ } = state;
124
+ const debug = _debug || (headingContext === null || headingContext === void 0 ? void 0 : (_headingContext$headi2 = headingContext.heading) === null || _headingContext$headi2 === void 0 ? void 0 : _headingContext$headi2.debug);
125
+ const debug_counter = _debug_counter || (headingContext === null || headingContext === void 0 ? void 0 : (_headingContext$headi3 = headingContext.heading) === null || _headingContext$headi3 === void 0 ? void 0 : _headingContext$headi3.debug_counter);
126
+
127
+ const attributes = _objectSpread({}, rest);
128
+
129
+ if (element === 'auto' || element === null) {
130
+ element = `h${level || 'x-small'}`;
131
+
132
+ if (_size === 'auto' || _size === null) {
133
+ size = levelResolution[level || 'x-small'];
134
+ }
135
+ } else {
136
+ if (!attributes.role) {
137
+ attributes.role = 'heading';
138
+ }
154
139
 
155
- if (!attributes['aria-level']) {
156
- attributes['aria-level'] = String(level);
157
- }
140
+ if (!attributes['aria-level']) {
141
+ attributes['aria-level'] = String(level);
158
142
  }
143
+ }
159
144
 
160
- validateDOMAttributes(this.props, attributes);
161
- const Element = element;
162
- return React.createElement(Context.Consumer, null, context => {
163
- if (typeof (context === null || context === void 0 ? void 0 : context.skeleton) !== 'undefined') {
164
- skeleton = context.skeleton;
165
- }
145
+ validateDOMAttributes(props, attributes);
166
146
 
167
- attributes.className = classnames(`dnb-heading dnb-h--${size}`, createSkeletonClass('font', skeleton, this.context), className, _className, createSpacingClasses(this.props));
168
- attributes.children = React.createElement(React.Fragment, null, debug && React.createElement("span", {
169
- className: "dnb-heading__debug"
170
- }, `[h${level || '6'}] `, debug_counter && React.createElement(React.Fragment, null, ' ', React.createElement("span", {
171
- className: "dnb-code"
172
- }, debugCounter(this.state.counter)))), text || children);
173
- return React.createElement(Element, _extends({
174
- ref: this._ref
175
- }, attributes));
176
- });
147
+ if (typeof (context === null || context === void 0 ? void 0 : context.skeleton) !== 'undefined') {
148
+ skeleton = context.skeleton;
177
149
  }
178
150
 
151
+ const Element = element;
152
+ return React.createElement(Element, _extends({}, attributes, {
153
+ ref: _ref,
154
+ className: classnames(`dnb-heading dnb-h--${size}`, createSkeletonClass('font', skeleton, headingContext), className, createSpacingClasses(props))
155
+ }), debug && React.createElement("span", {
156
+ className: "dnb-heading__debug"
157
+ }, `[h${level || '6'}] `, debug_counter && React.createElement(React.Fragment, null, ' ', React.createElement("span", {
158
+ className: "dnb-code"
159
+ }, debugCounter(state.counter)))), text || children);
179
160
  }
180
-
181
- _defineProperty(Heading, "contextType", HeadingContext);
182
-
183
- _defineProperty(Heading, "defaultProps", {
184
- id: null,
185
- group: null,
186
- text: null,
187
- size: 'auto',
188
- level: null,
189
- increase: null,
190
- decrease: null,
191
- up: null,
192
- down: null,
193
- skip_correction: null,
194
- debug: null,
195
- debug_counter: null,
196
- counter: null,
197
- reset: null,
198
- inherit: null,
199
- skeleton: null,
200
- element: 'auto',
201
- class: null,
202
- className: null,
203
- children: null
204
- });
205
-
206
- process.env.NODE_ENV !== "production" ? Heading.propTypes = _objectSpread(_objectSpread({
207
- id: PropTypes.string,
208
- group: PropTypes.string,
209
- text: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
210
- size: PropTypes.oneOf(['auto', 'xx-large', 'x-large', 'large', 'medium', 'basis', 'small', 'x-small']),
211
- level: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
212
- increase: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
213
- decrease: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
214
- up: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
215
- down: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
216
- skip_correction: PropTypes.bool,
217
- debug: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
218
- debug_counter: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
219
- counter: PropTypes.any,
220
- inherit: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
221
- reset: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool]),
222
- skeleton: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
223
- element: PropTypes.string
224
- }, spacingPropTypes), {}, {
225
- class: PropTypes.string,
226
- className: PropTypes.string,
227
- children: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
228
- }) : void 0;
229
161
  Heading.Level = HeadingProvider;
230
162
 
231
163
  Heading.Increase = props => React.createElement(HeadingProvider, _extends({
@@ -1,5 +1,12 @@
1
- export default Context;
2
- declare const Context: React.Context<{
3
- heading: any;
4
- }>;
5
- import React from "react";
1
+ /**
2
+ * Web Heading Context
3
+ *
4
+ */
5
+ import React from 'react';
6
+ import { SkeletonContextProps } from '../skeleton/SkeletonHelper';
7
+ import { HeadingProps } from './Heading';
8
+ export declare type HeadingContextProps = {
9
+ heading?: HeadingProps;
10
+ } & SkeletonContextProps;
11
+ declare const HeadingContext: React.Context<HeadingContextProps>;
12
+ export default HeadingContext;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- const Context = React.createContext({
2
+ const HeadingContext = React.createContext({
3
3
  heading: null
4
4
  });
5
- export default Context;
5
+ export default HeadingContext;
@@ -1,18 +1,42 @@
1
- export function initCounter(props?: any): any;
2
- export class Counter {
3
- constructor(props?: any);
4
- level: number;
5
- entry: number;
1
+ /**
2
+ * Web Heading Counter Instance
3
+ *
4
+ */
5
+ import { HeadingAllProps, InternalHeadingLevel } from './Heading';
6
+ export declare type HeadingCounter = Counter;
7
+ export declare type HeadingDebugCounter = boolean | (() => void);
8
+ export declare type ContextCounter = {
9
+ level: InternalHeadingLevel;
10
+ entry: InternalHeadingLevel;
11
+ countHeadings: number;
12
+ _initCount: number;
13
+ _isReady: boolean;
14
+ isGlobal?: boolean;
15
+ };
16
+ export declare const initCounter: (props?: CounterProps) => Counter;
17
+ export declare type CounterGroup = HeadingAllProps['group'];
18
+ export declare type CounterChildren = HeadingAllProps['children'];
19
+ export declare type CounterProps = {
20
+ isGlobal?: boolean;
21
+ group?: CounterGroup;
22
+ children?: CounterChildren;
23
+ counter?: CounterProps;
24
+ };
25
+ export declare class Counter {
26
+ level: InternalHeadingLevel;
27
+ entry: InternalHeadingLevel;
28
+ lastResetLevel: InternalHeadingLevel;
6
29
  _isReady: boolean;
7
30
  countHeadings: number;
8
31
  _initCount: number;
9
32
  isGlobal: boolean;
10
33
  isHeading: boolean;
11
34
  bypassChecks: boolean;
12
- contextCounter: any;
35
+ contextCounter: ContextCounter;
13
36
  reports: any[];
14
- group: any;
15
- children: any;
37
+ group: CounterGroup;
38
+ children: CounterChildren;
39
+ constructor(props?: CounterProps);
16
40
  report(...str: any[]): void;
17
41
  useLastReport(): any;
18
42
  enableBypassChecks(): void;
@@ -20,23 +44,23 @@ export class Counter {
20
44
  getLevel(): number;
21
45
  hasEntryLevel(): boolean;
22
46
  hasCorrection(): boolean;
23
- setEntryLevel(level?: any): void;
47
+ setEntryLevel(level?: InternalHeadingLevel): void;
24
48
  isInContext(): boolean;
25
- setContextCounter(contextCounter: any): void;
26
- skipMakeMeReady(): void;
49
+ setContextCounter(contextCounter: ContextCounter): void;
27
50
  windup(): void;
28
51
  teardown(): void;
29
- makeMeReady(): void;
52
+ makeMeReady({ level }?: {
53
+ level?: InternalHeadingLevel;
54
+ }): void;
30
55
  factorCheck({ action, level, current, report }: {
31
56
  action: any;
32
57
  level: any;
33
58
  current: any;
34
59
  report: any;
35
60
  }): any;
36
- setLevel(level: any, action?: string): void;
61
+ setLevel(level: InternalHeadingLevel, action?: string): void;
37
62
  increment(): void;
38
63
  decrement(): void;
39
64
  force(level?: number): void;
40
65
  reset(toLevel?: any): void;
41
- lastResetLevel: any;
42
66
  }