@transferwise/components 0.0.0-experimental-b7e52e5 → 0.0.0-experimental-2442a28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/header/Header.js +78 -38
- package/build/header/Header.js.map +1 -1
- package/build/header/Header.mjs +75 -38
- package/build/header/Header.mjs.map +1 -1
- package/build/index.js +1 -1
- package/build/index.mjs +1 -1
- package/build/inputs/SelectInput.js +1 -1
- package/build/inputs/SelectInput.js.map +1 -1
- package/build/inputs/SelectInput.mjs +1 -1
- package/build/main.css +4 -0
- package/build/selectOption/SelectOption.js +1 -1
- package/build/selectOption/SelectOption.js.map +1 -1
- package/build/selectOption/SelectOption.mjs +1 -1
- package/build/styles/header/Header.css +4 -0
- package/build/styles/main.css +4 -0
- package/build/title/Title.js +6 -4
- package/build/title/Title.js.map +1 -1
- package/build/title/Title.mjs +6 -4
- package/build/title/Title.mjs.map +1 -1
- package/build/types/header/Header.d.ts +22 -14
- package/build/types/header/Header.d.ts.map +1 -1
- package/build/types/header/index.d.ts +1 -0
- package/build/types/header/index.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/title/Title.d.ts +3 -4
- package/build/types/title/Title.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/header/Header.accessibility.docs.mdx +85 -0
- package/src/header/Header.css +4 -0
- package/src/header/Header.less +5 -0
- package/src/header/Header.spec.tsx +68 -50
- package/src/header/Header.story.tsx +174 -40
- package/src/header/Header.tsx +116 -72
- package/src/header/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/listItem/ListItem.tests.story.tsx +22 -17
- package/src/main.css +4 -0
- package/src/summary/Summary.tests.story.tsx +29 -29
- package/src/title/Title.tsx +25 -11
- package/src/upload/Upload.spec.tsx +3 -1
- package/src/upload/steps/processingStep/processingStep.spec.tsx +1 -1
- package/src/upload/steps/uploadImageStep/uploadImageStep.spec.tsx +4 -4
package/build/header/Header.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var clsx = require('clsx');
|
|
6
|
-
var Button_resolver = require('../button/Button.resolver.js');
|
|
7
6
|
require('../common/theme.js');
|
|
8
7
|
require('../common/direction.js');
|
|
9
8
|
require('../common/propsValues/control.js');
|
|
@@ -24,78 +23,119 @@ require('../common/propsValues/scroll.js');
|
|
|
24
23
|
require('../common/propsValues/markdownNodeType.js');
|
|
25
24
|
require('../common/fileType.js');
|
|
26
25
|
require('@transferwise/icons');
|
|
27
|
-
require('react');
|
|
26
|
+
var React = require('react');
|
|
28
27
|
require('react-intl');
|
|
29
28
|
require('../common/closeButton/CloseButton.messages.js');
|
|
30
29
|
var jsxRuntime = require('react/jsx-runtime');
|
|
31
30
|
var Link = require('../link/Link.js');
|
|
31
|
+
var Button_resolver = require('../button/Button.resolver.js');
|
|
32
32
|
var Title = require('../title/Title.js');
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
35
|
+
|
|
36
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
37
|
+
|
|
38
|
+
const HeaderAction = /*#__PURE__*/React__default.default.forwardRef(({
|
|
35
39
|
action
|
|
36
|
-
}) => {
|
|
37
|
-
const
|
|
38
|
-
'aria-label':
|
|
39
|
-
|
|
40
|
+
}, ref) => {
|
|
41
|
+
const {
|
|
42
|
+
'aria-label': ariaLabel,
|
|
43
|
+
text,
|
|
44
|
+
onClick
|
|
45
|
+
} = action;
|
|
40
46
|
if ('href' in action) {
|
|
47
|
+
const {
|
|
48
|
+
href,
|
|
49
|
+
target,
|
|
50
|
+
onClick: linkOnClick
|
|
51
|
+
} = action;
|
|
41
52
|
return /*#__PURE__*/jsxRuntime.jsx(Link.default, {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
ref: ref,
|
|
54
|
+
href: href,
|
|
55
|
+
target: target,
|
|
56
|
+
"aria-label": ariaLabel,
|
|
57
|
+
onClick: linkOnClick,
|
|
58
|
+
children: text
|
|
47
59
|
});
|
|
48
60
|
}
|
|
49
61
|
return /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
|
|
62
|
+
ref: ref,
|
|
50
63
|
className: "np-header__button",
|
|
51
64
|
priority: "tertiary",
|
|
52
65
|
size: "sm",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
children:
|
|
66
|
+
"aria-label": ariaLabel,
|
|
67
|
+
onClick: onClick,
|
|
68
|
+
children: text
|
|
56
69
|
});
|
|
57
|
-
};
|
|
70
|
+
});
|
|
71
|
+
HeaderAction.displayName = 'HeaderAction';
|
|
58
72
|
/**
|
|
73
|
+
* @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.
|
|
74
|
+
* @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.
|
|
75
|
+
* @param {string} title - Required prop to set the title of the section header.
|
|
76
|
+
* @param {'group' | 'section'} [level='group'] - Optional prop to specify the level of the section header.
|
|
77
|
+
* @param {string} [className]
|
|
78
|
+
* @param {string} [testId]
|
|
59
79
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
80
|
+
* @see {@link Header } for further information.
|
|
81
|
+
* @see {@link https://storybook.wise.design/?path=/docs/typography-header--docs|Storybook Wise Design}
|
|
62
82
|
*/
|
|
63
|
-
const Header = ({
|
|
64
|
-
id,
|
|
65
|
-
action,
|
|
83
|
+
const Header = /*#__PURE__*/React__default.default.forwardRef(({
|
|
66
84
|
as = 'h5',
|
|
67
|
-
|
|
85
|
+
action,
|
|
68
86
|
className,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
testId,
|
|
88
|
+
title,
|
|
89
|
+
level = 'group',
|
|
90
|
+
...props
|
|
91
|
+
}, ref) => {
|
|
92
|
+
const internalRef = React.useRef(null);
|
|
93
|
+
const levelTypography = level === 'section' ? typography.Typography.TITLE_SUBSECTION : typography.Typography.TITLE_GROUP;
|
|
94
|
+
const headerClasses = clsx.clsx('np-header', className, {
|
|
95
|
+
'np-header--section': level === 'section',
|
|
96
|
+
'np-header__title': !action || as === 'legend'
|
|
97
|
+
});
|
|
98
|
+
const commonProps = {
|
|
99
|
+
className: headerClasses,
|
|
100
|
+
'data-testid': testId
|
|
101
|
+
};
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
if (as === 'legend' && internalRef.current) {
|
|
104
|
+
const {
|
|
105
|
+
parentElement
|
|
106
|
+
} = internalRef.current;
|
|
107
|
+
if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {
|
|
108
|
+
console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, [as]);
|
|
112
|
+
if (!action || as === 'legend') {
|
|
72
113
|
return /*#__PURE__*/jsxRuntime.jsx(Title.default, {
|
|
114
|
+
ref: internalRef,
|
|
73
115
|
as: as,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
className: clsx.clsx('np-header', 'np-header__title', className),
|
|
116
|
+
type: levelTypography,
|
|
117
|
+
...commonProps,
|
|
118
|
+
...props,
|
|
78
119
|
children: title
|
|
79
120
|
});
|
|
80
121
|
}
|
|
81
|
-
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
|
|
84
|
-
}
|
|
122
|
+
const actionRef = /*#__PURE__*/React__default.default.createRef();
|
|
85
123
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
86
|
-
|
|
124
|
+
...commonProps,
|
|
125
|
+
...props,
|
|
126
|
+
ref: ref,
|
|
87
127
|
children: [/*#__PURE__*/jsxRuntime.jsx(Title.default, {
|
|
88
128
|
as: as,
|
|
89
|
-
type:
|
|
90
|
-
id: id,
|
|
129
|
+
type: levelTypography,
|
|
91
130
|
className: "np-header__title",
|
|
92
131
|
children: title
|
|
93
132
|
}), /*#__PURE__*/jsxRuntime.jsx(HeaderAction, {
|
|
133
|
+
ref: actionRef,
|
|
94
134
|
action: action
|
|
95
135
|
})]
|
|
96
136
|
});
|
|
97
|
-
};
|
|
137
|
+
});
|
|
138
|
+
Header.displayName = 'Header';
|
|
98
139
|
|
|
99
|
-
exports.Header = Header;
|
|
100
140
|
exports.default = Header;
|
|
101
141
|
//# sourceMappingURL=Header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.js","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport {
|
|
1
|
+
{"version":3,"file":"Header.js","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { AriaLabelProperty, CommonProps, Heading, LinkProps, Typography } from '../common';\nimport Link from '../link';\nimport Button from '../button';\nimport Title from '../title';\nimport React, { useEffect, useRef, FunctionComponent } from 'react';\n\ntype ActionProps = AriaLabelProperty & {\n text: string;\n onClick?: () => void;\n};\n\ntype ButtonActionProps = ActionProps;\ntype LinkActionProps = ActionProps & LinkProps;\n\nexport interface HeaderProps extends CommonProps {\n /**\n * Optional prop to define the action for the header. If the `href` property\n * is provided, a `Link` will be rendered instead of an `ActionButton`.\n */\n action?: ButtonActionProps | LinkActionProps;\n\n /** Option prop to specify DOM render element of the title */\n as?: Heading | 'legend' | 'header';\n\n /** Required prop to set the title of the Header. */\n title: string;\n\n /** Optional prop to specify the level of the Header */\n level?: 'section' | 'group';\n\n className?: string;\n testId?: string;\n}\n\n/**\n * Renders a header action which can be either a button or a link.\n *\n * @param {Object} props - The properties object.\n * @param {ButtonActionProps | LinkActionProps} props.action - The action object which can be either a button or a link.\n * @returns {JSX.Element} The rendered header action component.\n */\nconst HeaderAction = React.forwardRef(\n (\n { action }: { action: ButtonActionProps | LinkActionProps },\n ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>,\n ) => {\n const { 'aria-label': ariaLabel, text, onClick } = action;\n\n if ('href' in action) {\n const { href, target, onClick: linkOnClick } = action;\n return (\n <Link\n ref={ref as React.Ref<HTMLAnchorElement>}\n href={href}\n target={target}\n aria-label={ariaLabel}\n onClick={linkOnClick}\n >\n {text}\n </Link>\n );\n }\n\n return (\n <Button\n ref={ref as React.Ref<HTMLButtonElement>}\n className=\"np-header__button\"\n priority=\"tertiary\"\n size=\"sm\"\n aria-label={ariaLabel}\n onClick={onClick}\n >\n {text}\n </Button>\n );\n },\n);\n\nHeaderAction.displayName = 'HeaderAction';\n\n/**\n * @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.\n * @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.\n * @param {string} title - Required prop to set the title of the section header.\n * @param {'group' | 'section'} [level='group'] - Optional prop to specify the level of the section header.\n * @param {string} [className]\n * @param {string} [testId]\n *\n * @see {@link Header } for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/typography-header--docs|Storybook Wise Design}\n */\nconst Header: FunctionComponent<HeaderProps> = React.forwardRef(\n (\n { as = 'h5', action, className, testId, title, level = 'group', ...props },\n ref: React.Ref<HTMLDivElement | HTMLHeadingElement | HTMLLegendElement>,\n ) => {\n const internalRef = useRef<HTMLLegendElement>(null);\n const levelTypography =\n level === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;\n const headerClasses = clsx('np-header', className, {\n 'np-header--section': level === 'section',\n 'np-header__title': !action || as === 'legend',\n });\n\n const commonProps = {\n className: headerClasses,\n 'data-testid': testId,\n };\n\n useEffect(() => {\n if (as === 'legend' && internalRef.current) {\n const { parentElement } = internalRef.current;\n if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {\n console.warn(\n 'Legends should be the first child in a fieldset, and this is not possible when including an action',\n );\n }\n }\n }, [as]);\n\n if (!action || as === 'legend') {\n return (\n <Title ref={internalRef} as={as} type={levelTypography} {...commonProps} {...props}>\n {title}\n </Title>\n );\n }\n\n const actionRef = React.createRef<HTMLButtonElement | HTMLAnchorElement>();\n\n return (\n <div {...commonProps} {...props} ref={ref as React.Ref<HTMLDivElement>}>\n <Title as={as} type={levelTypography} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction ref={actionRef} action={action} />\n </div>\n );\n },\n);\n\nHeader.displayName = 'Header';\n\nexport default Header;\n"],"names":["HeaderAction","React","forwardRef","action","ref","ariaLabel","text","onClick","href","target","linkOnClick","_jsx","Link","children","Button","className","priority","size","displayName","Header","as","testId","title","level","props","internalRef","useRef","levelTypography","Typography","TITLE_SUBSECTION","TITLE_GROUP","headerClasses","clsx","commonProps","useEffect","current","parentElement","tagName","toLowerCase","console","warn","Title","type","actionRef","createRef","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAMA,YAAY,gBAAGC,sBAAK,CAACC,UAAU,CACnC,CACE;AAAEC,EAAAA,MAAAA;AAAM,CAAmD,EAC3DC,GAAqD,KACnD;EACF,MAAM;AAAE,IAAA,YAAY,EAAEC,SAAS;IAAEC,IAAI;AAAEC,IAAAA,OAAAA;AAAO,GAAE,GAAGJ,MAAM,CAAA;EAEzD,IAAI,MAAM,IAAIA,MAAM,EAAE;IACpB,MAAM;MAAEK,IAAI;MAAEC,MAAM;AAAEF,MAAAA,OAAO,EAAEG,WAAAA;AAAW,KAAE,GAAGP,MAAM,CAAA;IACrD,oBACEQ,cAAA,CAACC,YAAI,EAAA;AACHR,MAAAA,GAAG,EAAEA,GAAoC;AACzCI,MAAAA,IAAI,EAAEA,IAAK;AACXC,MAAAA,MAAM,EAAEA,MAAO;AACf,MAAA,YAAA,EAAYJ,SAAU;AACtBE,MAAAA,OAAO,EAAEG,WAAY;AAAAG,MAAAA,QAAA,EAEpBP,IAAAA;AAAI,KACD,CAAC,CAAA;AAEX,GAAA;EAEA,oBACEK,cAAA,CAACG,uBAAM,EAAA;AACLV,IAAAA,GAAG,EAAEA,GAAo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clsx';
|
|
2
|
-
import Button from '../button/Button.resolver.mjs';
|
|
3
2
|
import '../common/theme.mjs';
|
|
4
3
|
import '../common/direction.mjs';
|
|
5
4
|
import '../common/propsValues/control.mjs';
|
|
@@ -20,77 +19,115 @@ import '../common/propsValues/scroll.mjs';
|
|
|
20
19
|
import '../common/propsValues/markdownNodeType.mjs';
|
|
21
20
|
import '../common/fileType.mjs';
|
|
22
21
|
import '@transferwise/icons';
|
|
23
|
-
import 'react';
|
|
22
|
+
import React__default, { useRef, useEffect } from 'react';
|
|
24
23
|
import 'react-intl';
|
|
25
24
|
import '../common/closeButton/CloseButton.messages.mjs';
|
|
26
25
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
27
26
|
import Link from '../link/Link.mjs';
|
|
27
|
+
import Button from '../button/Button.resolver.mjs';
|
|
28
28
|
import Title from '../title/Title.mjs';
|
|
29
29
|
|
|
30
|
-
const HeaderAction = ({
|
|
30
|
+
const HeaderAction = /*#__PURE__*/React__default.forwardRef(({
|
|
31
31
|
action
|
|
32
|
-
}) => {
|
|
33
|
-
const
|
|
34
|
-
'aria-label':
|
|
35
|
-
|
|
32
|
+
}, ref) => {
|
|
33
|
+
const {
|
|
34
|
+
'aria-label': ariaLabel,
|
|
35
|
+
text,
|
|
36
|
+
onClick
|
|
37
|
+
} = action;
|
|
36
38
|
if ('href' in action) {
|
|
39
|
+
const {
|
|
40
|
+
href,
|
|
41
|
+
target,
|
|
42
|
+
onClick: linkOnClick
|
|
43
|
+
} = action;
|
|
37
44
|
return /*#__PURE__*/jsx(Link, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
ref: ref,
|
|
46
|
+
href: href,
|
|
47
|
+
target: target,
|
|
48
|
+
"aria-label": ariaLabel,
|
|
49
|
+
onClick: linkOnClick,
|
|
50
|
+
children: text
|
|
43
51
|
});
|
|
44
52
|
}
|
|
45
53
|
return /*#__PURE__*/jsx(Button, {
|
|
54
|
+
ref: ref,
|
|
46
55
|
className: "np-header__button",
|
|
47
56
|
priority: "tertiary",
|
|
48
57
|
size: "sm",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
children:
|
|
58
|
+
"aria-label": ariaLabel,
|
|
59
|
+
onClick: onClick,
|
|
60
|
+
children: text
|
|
52
61
|
});
|
|
53
|
-
};
|
|
62
|
+
});
|
|
63
|
+
HeaderAction.displayName = 'HeaderAction';
|
|
54
64
|
/**
|
|
65
|
+
* @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.
|
|
66
|
+
* @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.
|
|
67
|
+
* @param {string} title - Required prop to set the title of the section header.
|
|
68
|
+
* @param {'group' | 'section'} [level='group'] - Optional prop to specify the level of the section header.
|
|
69
|
+
* @param {string} [className]
|
|
70
|
+
* @param {string} [testId]
|
|
55
71
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
72
|
+
* @see {@link Header } for further information.
|
|
73
|
+
* @see {@link https://storybook.wise.design/?path=/docs/typography-header--docs|Storybook Wise Design}
|
|
58
74
|
*/
|
|
59
|
-
const Header = ({
|
|
60
|
-
id,
|
|
61
|
-
action,
|
|
75
|
+
const Header = /*#__PURE__*/React__default.forwardRef(({
|
|
62
76
|
as = 'h5',
|
|
63
|
-
|
|
77
|
+
action,
|
|
64
78
|
className,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
testId,
|
|
80
|
+
title,
|
|
81
|
+
level = 'group',
|
|
82
|
+
...props
|
|
83
|
+
}, ref) => {
|
|
84
|
+
const internalRef = useRef(null);
|
|
85
|
+
const levelTypography = level === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;
|
|
86
|
+
const headerClasses = clsx('np-header', className, {
|
|
87
|
+
'np-header--section': level === 'section',
|
|
88
|
+
'np-header__title': !action || as === 'legend'
|
|
89
|
+
});
|
|
90
|
+
const commonProps = {
|
|
91
|
+
className: headerClasses,
|
|
92
|
+
'data-testid': testId
|
|
93
|
+
};
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (as === 'legend' && internalRef.current) {
|
|
96
|
+
const {
|
|
97
|
+
parentElement
|
|
98
|
+
} = internalRef.current;
|
|
99
|
+
if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {
|
|
100
|
+
console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, [as]);
|
|
104
|
+
if (!action || as === 'legend') {
|
|
68
105
|
return /*#__PURE__*/jsx(Title, {
|
|
106
|
+
ref: internalRef,
|
|
69
107
|
as: as,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
className: clsx('np-header', 'np-header__title', className),
|
|
108
|
+
type: levelTypography,
|
|
109
|
+
...commonProps,
|
|
110
|
+
...props,
|
|
74
111
|
children: title
|
|
75
112
|
});
|
|
76
113
|
}
|
|
77
|
-
|
|
78
|
-
// eslint-disable-next-line no-console
|
|
79
|
-
console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
|
|
80
|
-
}
|
|
114
|
+
const actionRef = /*#__PURE__*/React__default.createRef();
|
|
81
115
|
return /*#__PURE__*/jsxs("div", {
|
|
82
|
-
|
|
116
|
+
...commonProps,
|
|
117
|
+
...props,
|
|
118
|
+
ref: ref,
|
|
83
119
|
children: [/*#__PURE__*/jsx(Title, {
|
|
84
120
|
as: as,
|
|
85
|
-
type:
|
|
86
|
-
id: id,
|
|
121
|
+
type: levelTypography,
|
|
87
122
|
className: "np-header__title",
|
|
88
123
|
children: title
|
|
89
124
|
}), /*#__PURE__*/jsx(HeaderAction, {
|
|
125
|
+
ref: actionRef,
|
|
90
126
|
action: action
|
|
91
127
|
})]
|
|
92
128
|
});
|
|
93
|
-
};
|
|
129
|
+
});
|
|
130
|
+
Header.displayName = 'Header';
|
|
94
131
|
|
|
95
|
-
export { Header
|
|
132
|
+
export { Header as default };
|
|
96
133
|
//# sourceMappingURL=Header.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.mjs","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport {
|
|
1
|
+
{"version":3,"file":"Header.mjs","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { AriaLabelProperty, CommonProps, Heading, LinkProps, Typography } from '../common';\nimport Link from '../link';\nimport Button from '../button';\nimport Title from '../title';\nimport React, { useEffect, useRef, FunctionComponent } from 'react';\n\ntype ActionProps = AriaLabelProperty & {\n text: string;\n onClick?: () => void;\n};\n\ntype ButtonActionProps = ActionProps;\ntype LinkActionProps = ActionProps & LinkProps;\n\nexport interface HeaderProps extends CommonProps {\n /**\n * Optional prop to define the action for the header. If the `href` property\n * is provided, a `Link` will be rendered instead of an `ActionButton`.\n */\n action?: ButtonActionProps | LinkActionProps;\n\n /** Option prop to specify DOM render element of the title */\n as?: Heading | 'legend' | 'header';\n\n /** Required prop to set the title of the Header. */\n title: string;\n\n /** Optional prop to specify the level of the Header */\n level?: 'section' | 'group';\n\n className?: string;\n testId?: string;\n}\n\n/**\n * Renders a header action which can be either a button or a link.\n *\n * @param {Object} props - The properties object.\n * @param {ButtonActionProps | LinkActionProps} props.action - The action object which can be either a button or a link.\n * @returns {JSX.Element} The rendered header action component.\n */\nconst HeaderAction = React.forwardRef(\n (\n { action }: { action: ButtonActionProps | LinkActionProps },\n ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>,\n ) => {\n const { 'aria-label': ariaLabel, text, onClick } = action;\n\n if ('href' in action) {\n const { href, target, onClick: linkOnClick } = action;\n return (\n <Link\n ref={ref as React.Ref<HTMLAnchorElement>}\n href={href}\n target={target}\n aria-label={ariaLabel}\n onClick={linkOnClick}\n >\n {text}\n </Link>\n );\n }\n\n return (\n <Button\n ref={ref as React.Ref<HTMLButtonElement>}\n className=\"np-header__button\"\n priority=\"tertiary\"\n size=\"sm\"\n aria-label={ariaLabel}\n onClick={onClick}\n >\n {text}\n </Button>\n );\n },\n);\n\nHeaderAction.displayName = 'HeaderAction';\n\n/**\n * @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.\n * @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.\n * @param {string} title - Required prop to set the title of the section header.\n * @param {'group' | 'section'} [level='group'] - Optional prop to specify the level of the section header.\n * @param {string} [className]\n * @param {string} [testId]\n *\n * @see {@link Header } for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/typography-header--docs|Storybook Wise Design}\n */\nconst Header: FunctionComponent<HeaderProps> = React.forwardRef(\n (\n { as = 'h5', action, className, testId, title, level = 'group', ...props },\n ref: React.Ref<HTMLDivElement | HTMLHeadingElement | HTMLLegendElement>,\n ) => {\n const internalRef = useRef<HTMLLegendElement>(null);\n const levelTypography =\n level === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;\n const headerClasses = clsx('np-header', className, {\n 'np-header--section': level === 'section',\n 'np-header__title': !action || as === 'legend',\n });\n\n const commonProps = {\n className: headerClasses,\n 'data-testid': testId,\n };\n\n useEffect(() => {\n if (as === 'legend' && internalRef.current) {\n const { parentElement } = internalRef.current;\n if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {\n console.warn(\n 'Legends should be the first child in a fieldset, and this is not possible when including an action',\n );\n }\n }\n }, [as]);\n\n if (!action || as === 'legend') {\n return (\n <Title ref={internalRef} as={as} type={levelTypography} {...commonProps} {...props}>\n {title}\n </Title>\n );\n }\n\n const actionRef = React.createRef<HTMLButtonElement | HTMLAnchorElement>();\n\n return (\n <div {...commonProps} {...props} ref={ref as React.Ref<HTMLDivElement>}>\n <Title as={as} type={levelTypography} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction ref={actionRef} action={action} />\n </div>\n );\n },\n);\n\nHeader.displayName = 'Header';\n\nexport default Header;\n"],"names":["HeaderAction","React","forwardRef","action","ref","ariaLabel","text","onClick","href","target","linkOnClick","_jsx","Link","children","Button","className","priority","size","displayName","Header","as","testId","title","level","props","internalRef","useRef","levelTypography","Typography","TITLE_SUBSECTION","TITLE_GROUP","headerClasses","clsx","commonProps","useEffect","current","parentElement","tagName","toLowerCase","console","warn","Title","type","actionRef","createRef","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAMA,YAAY,gBAAGC,cAAK,CAACC,UAAU,CACnC,CACE;AAAEC,EAAAA,MAAAA;AAAM,CAAmD,EAC3DC,GAAqD,KACnD;EACF,MAAM;AAAE,IAAA,YAAY,EAAEC,SAAS;IAAEC,IAAI;AAAEC,IAAAA,OAAAA;AAAO,GAAE,GAAGJ,MAAM,CAAA;EAEzD,IAAI,MAAM,IAAIA,MAAM,EAAE;IACpB,MAAM;MAAEK,IAAI;MAAEC,MAAM;AAAEF,MAAAA,OAAO,EAAEG,WAAAA;AAAW,KAAE,GAAGP,MAAM,CAAA;IACrD,oBACEQ,GAAA,CAACC,IAAI,EAAA;AACHR,MAAAA,GAAG,EAAEA,GAAoC;AACzCI,MAAAA,IAAI,EAAEA,IAAK;AACXC,MAAAA,MAAM,EAAEA,MAAO;AACf,MAAA,YAAA,EAAYJ,SAAU;AACtBE,MAAAA,OAAO,EAAEG,WAAY;AAAAG,MAAAA,QAAA,EAEpBP,IAAAA;AAAI,KACD,CAAC,CAAA;AAEX,GAAA;EAEA,oBACEK,GAAA,CAACG,MAAM,EAAA;AACLV,IAAAA,GAAG,EAAEA,GAAoC;AACzCW,IAAAA,SAAS,EAAC,mBAAmB;AAC7BC,IAAAA,QAAQ,EAAC,UAAU;AACnBC,IAAAA,IAAI,EAAC,IAAI;AACT,IAAA,YAAA,EAAYZ,SAAU;AACtBE,IAAAA,OAAO,EAAEA,OAAQ;AAAAM,IAAAA,QAAA,EAEhBP,IAAAA;AAAI,GACC,CAAC,CAAA;AAEb,CAAC,CACF,CAAA;AAEDN,YAAY,CAACkB,WAAW,GAAG,cA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CAAC8B,KAAK,EAAA;AAACrC,MAAAA,GAAG,EAAEqB,WAAY;AAACL,MAAAA,EAAE,EAAEA,EAAG;AAACsB,MAAAA,IAAI,EAAEf,eAAgB;AAAA,MAAA,GAAKM,WAAW;AAAA,MAAA,GAAMT,KAAK;AAAAX,MAAAA,QAAA,EAC/ES,KAAAA;AAAK,KACD,CAAC,CAAA;AAEZ,GAAA;AAEA,EAAA,MAAMqB,SAAS,gBAAG1C,cAAK,CAAC2C,SAAS,EAAyC,CAAA;AAE1E,EAAA,oBACEC,IAAA,CAAA,KAAA,EAAA;AAAA,IAAA,GAASZ,WAAW;AAAA,IAAA,GAAMT,KAAK;AAAEpB,IAAAA,GAAG,EAAEA,GAAiC;IAAAS,QAAA,EAAA,cACrEF,GAAA,CAAC8B,KAAK,EAAA;AAACrB,MAAAA,EAAE,EAAEA,EAAG;AAACsB,MAAAA,IAAI,EAAEf,eAAgB;AAACZ,MAAAA,SAAS,EAAC,kBAAkB;AAAAF,MAAAA,QAAA,EAC/DS,KAAAA;AAAK,KACD,CACP,eAAAX,GAAA,CAACX,YAAY,EAAA;AAACI,MAAAA,GAAG,EAAEuC,SAAU;AAACxC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAC/C,CAAA,CAAA;AAAA,GAAK,CAAC,CAAA;AAEV,CAAC,EACF;AAEDgB,MAAM,CAACD,WAAW,GAAG,QAAQ;;;;"}
|
package/build/index.js
CHANGED
|
@@ -201,7 +201,7 @@ exports.DropFade = DropFade.default;
|
|
|
201
201
|
exports.Emphasis = Emphasis.default;
|
|
202
202
|
exports.Field = Field.Field;
|
|
203
203
|
exports.FlowNavigation = FlowNavigation.default;
|
|
204
|
-
exports.Header = Header.
|
|
204
|
+
exports.Header = Header.default;
|
|
205
205
|
Object.defineProperty(exports, "InfoPresentation", {
|
|
206
206
|
enumerable: true,
|
|
207
207
|
get: function () { return infoPresentations.InfoPresentation; }
|
package/build/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ export { default as DropFade } from './dropFade/DropFade.mjs';
|
|
|
46
46
|
export { default as Emphasis } from './emphasis/Emphasis.mjs';
|
|
47
47
|
export { Field } from './field/Field.mjs';
|
|
48
48
|
export { default as FlowNavigation } from './flowNavigation/FlowNavigation.mjs';
|
|
49
|
-
export { Header } from './header/Header.mjs';
|
|
49
|
+
export { default as Header } from './header/Header.mjs';
|
|
50
50
|
export { InfoPresentation } from './info/infoPresentations.mjs';
|
|
51
51
|
export { default as Info } from './info/Info.mjs';
|
|
52
52
|
export { default as InlineAlert } from './inlineAlert/InlineAlert.mjs';
|
|
@@ -603,7 +603,7 @@ function SelectInputGroupItemView({
|
|
|
603
603
|
needle
|
|
604
604
|
}) {
|
|
605
605
|
const headerId = React.useId();
|
|
606
|
-
const header = /*#__PURE__*/jsxRuntime.jsx(Header.
|
|
606
|
+
const header = /*#__PURE__*/jsxRuntime.jsx(Header.default, {
|
|
607
607
|
as: "header",
|
|
608
608
|
role: "none",
|
|
609
609
|
id: headerId,
|