@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.
- package/CHANGELOG.md +21 -0
- package/cjs/components/anchor/style/deps.scss +9 -0
- package/cjs/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
- package/cjs/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
- package/cjs/components/button/style/themes/dnb-button-theme-ui.css +4 -0
- package/cjs/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
- package/cjs/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
- package/cjs/components/global-status/GlobalStatus.d.ts +3 -3
- package/cjs/components/heading/Heading.d.ts +89 -106
- package/cjs/components/heading/Heading.js +119 -184
- package/cjs/components/heading/HeadingContext.d.ts +12 -5
- package/cjs/components/heading/HeadingContext.js +2 -2
- package/cjs/components/heading/HeadingCounter.d.ts +38 -14
- package/cjs/components/heading/HeadingCounter.js +20 -17
- package/cjs/components/heading/HeadingHelpers.d.ts +45 -23
- package/cjs/components/heading/HeadingHelpers.js +29 -24
- package/cjs/components/heading/HeadingProvider.d.ts +9 -12
- package/cjs/components/heading/HeadingProvider.js +47 -90
- package/cjs/components/info-card/style/dnb-info-card.css +1 -1
- package/cjs/components/info-card/style/dnb-info-card.min.css +1 -1
- package/cjs/components/info-card/style/dnb-info-card.scss +1 -1
- package/cjs/shared/Eufemia.d.ts +1 -1
- package/cjs/shared/Eufemia.js +2 -2
- package/cjs/shared/index.d.ts +2 -1
- package/cjs/style/dnb-ui-components.css +1 -1
- package/cjs/style/dnb-ui-components.min.css +1 -1
- package/cjs/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
- package/cjs/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/cjs/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
- package/cjs/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
- package/cjs/style/themes/theme-ui/ui-theme-components.css +5 -1
- package/cjs/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/components/anchor/style/deps.scss +9 -0
- package/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
- package/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
- package/components/button/style/themes/dnb-button-theme-ui.css +4 -0
- package/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
- package/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
- package/components/global-status/GlobalStatus.d.ts +3 -3
- package/components/heading/Heading.d.ts +89 -106
- package/components/heading/Heading.js +115 -183
- package/components/heading/HeadingContext.d.ts +12 -5
- package/components/heading/HeadingContext.js +2 -2
- package/components/heading/HeadingCounter.d.ts +38 -14
- package/components/heading/HeadingCounter.js +20 -17
- package/components/heading/HeadingHelpers.d.ts +45 -23
- package/components/heading/HeadingHelpers.js +27 -13
- package/components/heading/HeadingProvider.d.ts +9 -12
- package/components/heading/HeadingProvider.js +46 -90
- package/components/info-card/style/dnb-info-card.css +1 -1
- package/components/info-card/style/dnb-info-card.min.css +1 -1
- package/components/info-card/style/dnb-info-card.scss +1 -1
- package/es/components/anchor/style/deps.scss +9 -0
- package/es/components/button/style/themes/dnb-button-theme-eiendom.css +4 -0
- package/es/components/button/style/themes/dnb-button-theme-eiendom.min.css +1 -1
- package/es/components/button/style/themes/dnb-button-theme-ui.css +4 -0
- package/es/components/button/style/themes/dnb-button-theme-ui.min.css +1 -1
- package/es/components/button/style/themes/dnb-button-theme-ui.scss +5 -0
- package/es/components/global-status/GlobalStatus.d.ts +3 -3
- package/es/components/heading/Heading.d.ts +89 -106
- package/es/components/heading/Heading.js +115 -183
- package/es/components/heading/HeadingContext.d.ts +12 -5
- package/es/components/heading/HeadingContext.js +2 -2
- package/es/components/heading/HeadingCounter.d.ts +38 -14
- package/es/components/heading/HeadingCounter.js +19 -18
- package/es/components/heading/HeadingHelpers.d.ts +45 -23
- package/es/components/heading/HeadingHelpers.js +27 -13
- package/es/components/heading/HeadingProvider.d.ts +9 -12
- package/es/components/heading/HeadingProvider.js +46 -90
- package/es/components/info-card/style/dnb-info-card.css +1 -1
- package/es/components/info-card/style/dnb-info-card.min.css +1 -1
- package/es/components/info-card/style/dnb-info-card.scss +1 -1
- package/es/shared/Eufemia.d.ts +1 -1
- package/es/shared/Eufemia.js +2 -2
- package/es/shared/index.d.ts +2 -1
- package/es/style/dnb-ui-components.css +1 -1
- package/es/style/dnb-ui-components.min.css +1 -1
- package/es/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
- package/es/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/es/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
- package/es/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
- package/es/style/themes/theme-ui/ui-theme-components.css +5 -1
- package/es/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +1 -1
- package/esm/dnb-ui-extensions.min.mjs +1 -1
- package/esm/dnb-ui-lib.min.mjs +1 -1
- package/package.json +1 -1
- package/shared/Eufemia.d.ts +1 -1
- package/shared/Eufemia.js +2 -2
- package/shared/index.d.ts +2 -1
- package/style/dnb-ui-components.css +1 -1
- package/style/dnb-ui-components.min.css +1 -1
- package/style/themes/theme-eiendom/eiendom-theme-components.css +9 -1
- package/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/style/themes/theme-sbanken/sbanken-theme-components.css +1 -1
- package/style/themes/theme-sbanken/sbanken-theme-components.min.css +1 -1
- package/style/themes/theme-ui/ui-theme-components.css +5 -1
- package/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +1 -1
- package/umd/dnb-ui-extensions.min.js +1 -1
- package/umd/dnb-ui-lib.min.js +1 -1
|
@@ -1,107 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
65
|
+
headingContext
|
|
64
66
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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$
|
|
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$
|
|
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
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
componentDidMount() {
|
|
85
|
+
state.prevLevel = parseFloat(String(props.level));
|
|
86
|
+
return state;
|
|
87
|
+
});
|
|
88
|
+
React.useEffect(() => {
|
|
95
89
|
windupHeadings();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
140
|
+
if (!attributes['aria-level']) {
|
|
141
|
+
attributes['aria-level'] = String(level);
|
|
158
142
|
}
|
|
143
|
+
}
|
|
159
144
|
|
|
160
|
-
|
|
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
|
-
|
|
168
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import React from
|
|
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,18 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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:
|
|
35
|
+
contextCounter: ContextCounter;
|
|
13
36
|
reports: any[];
|
|
14
|
-
group:
|
|
15
|
-
children:
|
|
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?:
|
|
47
|
+
setEntryLevel(level?: InternalHeadingLevel): void;
|
|
24
48
|
isInContext(): boolean;
|
|
25
|
-
setContextCounter(contextCounter:
|
|
26
|
-
skipMakeMeReady(): void;
|
|
49
|
+
setContextCounter(contextCounter: ContextCounter): void;
|
|
27
50
|
windup(): void;
|
|
28
51
|
teardown(): void;
|
|
29
|
-
makeMeReady(
|
|
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:
|
|
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
|
}
|