@transferwise/components 0.0.0-experimental-5f3c456 → 0.0.0-experimental-b2dc1ea

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 (62) hide show
  1. package/build/header/Header.js +89 -34
  2. package/build/header/Header.js.map +1 -1
  3. package/build/header/Header.mjs +85 -31
  4. package/build/header/Header.mjs.map +1 -1
  5. package/build/index.js +1 -1
  6. package/build/index.mjs +1 -1
  7. package/build/link/Link.js +5 -3
  8. package/build/link/Link.js.map +1 -1
  9. package/build/link/Link.mjs +5 -3
  10. package/build/link/Link.mjs.map +1 -1
  11. package/build/main.css +3 -0
  12. package/build/selectOption/SelectOption.js +1 -1
  13. package/build/selectOption/SelectOption.js.map +1 -1
  14. package/build/selectOption/SelectOption.mjs +1 -1
  15. package/build/styles/header/Header.css +3 -0
  16. package/build/styles/main.css +3 -0
  17. package/build/title/Title.js +6 -3
  18. package/build/title/Title.js.map +1 -1
  19. package/build/title/Title.mjs +6 -3
  20. package/build/title/Title.mjs.map +1 -1
  21. package/build/typeahead/Typeahead.js +1 -1
  22. package/build/typeahead/Typeahead.js.map +1 -1
  23. package/build/typeahead/Typeahead.mjs +1 -1
  24. package/build/typeahead/Typeahead.mjs.map +1 -1
  25. package/build/typeahead/typeaheadOption/TypeaheadOption.js +4 -6
  26. package/build/typeahead/typeaheadOption/TypeaheadOption.js.map +1 -1
  27. package/build/typeahead/typeaheadOption/TypeaheadOption.mjs +5 -7
  28. package/build/typeahead/typeaheadOption/TypeaheadOption.mjs.map +1 -1
  29. package/build/typeahead/util/highlight.js +3 -8
  30. package/build/typeahead/util/highlight.js.map +1 -1
  31. package/build/typeahead/util/highlight.mjs +4 -9
  32. package/build/typeahead/util/highlight.mjs.map +1 -1
  33. package/build/types/header/Header.d.ts +34 -10
  34. package/build/types/header/Header.d.ts.map +1 -1
  35. package/build/types/header/index.d.ts +1 -0
  36. package/build/types/header/index.d.ts.map +1 -1
  37. package/build/types/index.d.ts +1 -0
  38. package/build/types/index.d.ts.map +1 -1
  39. package/build/types/link/Link.d.ts +3 -1
  40. package/build/types/link/Link.d.ts.map +1 -1
  41. package/build/types/title/Title.d.ts +3 -4
  42. package/build/types/title/Title.d.ts.map +1 -1
  43. package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts.map +1 -1
  44. package/build/types/typeahead/util/highlight.d.ts +1 -5
  45. package/build/types/typeahead/util/highlight.d.ts.map +1 -1
  46. package/package.json +3 -3
  47. package/src/header/Header.css +3 -0
  48. package/src/header/Header.less +4 -0
  49. package/src/header/Header.spec.tsx +33 -0
  50. package/src/header/Header.story.tsx +54 -40
  51. package/src/header/Header.tsx +126 -60
  52. package/src/header/index.ts +1 -0
  53. package/src/index.ts +1 -0
  54. package/src/link/Link.tsx +29 -27
  55. package/src/main.css +3 -0
  56. package/src/title/Title.tsx +25 -11
  57. package/src/typeahead/Typeahead.rtl.spec.tsx +0 -26
  58. package/src/typeahead/Typeahead.tsx +2 -2
  59. package/src/typeahead/typeaheadOption/TypeaheadOption.spec.js +4 -5
  60. package/src/typeahead/typeaheadOption/TypeaheadOption.tsx +3 -7
  61. package/src/typeahead/util/highlight.spec.js +5 -5
  62. package/src/typeahead/util/highlight.tsx +3 -11
@@ -1,74 +1,129 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var clsx = require('clsx');
6
- var Button = require('../button/Button.js');
7
4
  var Link = require('../link/Link.js');
5
+ var Button = require('../button/Button.js');
8
6
  var Title = require('../title/Title.js');
7
+ var React = require('react');
9
8
  var jsxRuntime = require('react/jsx-runtime');
10
9
  var typography = require('../common/propsValues/typography.js');
11
10
 
12
- const HeaderAction = ({
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ var React__default = /*#__PURE__*/_interopDefault(React);
14
+
15
+ const HeaderAction = /*#__PURE__*/React__default.default.forwardRef(({
13
16
  action
14
- }) => {
15
- const props = {
16
- 'aria-label': action['aria-label']
17
- };
17
+ }, ref) => {
18
+ const {
19
+ 'aria-label': ariaLabel,
20
+ text,
21
+ onClick
22
+ } = action;
18
23
  if ('href' in action) {
24
+ const {
25
+ href,
26
+ target,
27
+ onClick: linkOnClick
28
+ } = action;
19
29
  return /*#__PURE__*/jsxRuntime.jsx(Link, {
20
- href: action.href,
21
- target: action.target,
22
- onClick: action.onClick,
23
- ...props,
24
- children: action.text
30
+ ref: ref,
31
+ href: href,
32
+ target: target,
33
+ "aria-label": ariaLabel,
34
+ onClick: linkOnClick,
35
+ children: text
25
36
  });
26
37
  }
27
38
  return /*#__PURE__*/jsxRuntime.jsx(Button, {
39
+ ref: ref,
28
40
  className: "np-header__button",
29
41
  priority: "tertiary",
30
42
  size: "sm",
31
- onClick: action.onClick,
32
- ...props,
33
- children: action.text
43
+ "aria-label": ariaLabel,
44
+ onClick: onClick,
45
+ children: text
34
46
  });
35
- };
47
+ });
36
48
  /**
49
+ * Header component
50
+ *
51
+ * The header component is used to render a section header with an optional action button or link.
52
+ * The header component can be rendered as a `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, or `legend` element.
37
53
  *
38
- * Neptune Web: https://transferwise.github.io/neptune-web/components/content/Header
54
+ * @component
55
+ * @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.
56
+ * @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.
57
+ * @param {string} title - Required prop to set the title of the section header.
58
+ * @param {'group' | 'section'} [variant='group'] - Optional prop to specify the variant of the section header.
59
+ * @param {string} [className] - Optional prop to specify classNames onto the Header.
60
+ * @param {string} [testId] - Optional prop to specify the ID used for testing.
39
61
  *
62
+ * @example
63
+ * // Example usage:
64
+ * import Header from './Header';
65
+ *
66
+ * function App() {
67
+ * return (
68
+ * <Header title="Header" />
69
+ * );
70
+ * }
40
71
  */
41
- const Header = ({
42
- action,
72
+ const Header = /*#__PURE__*/React__default.default.forwardRef(({
43
73
  as = 'h5',
74
+ action,
75
+ className,
76
+ testId,
44
77
  title,
45
- className
46
- }) => {
47
- if (!action) {
78
+ variant = 'group',
79
+ ...props
80
+ }, ref) => {
81
+ const internalRef = React.useRef(null);
82
+ const variantTypography = variant === 'section' ? typography.Typography.TITLE_SUBSECTION : typography.Typography.TITLE_GROUP;
83
+ const headerClasses = clsx.clsx('np-header', className, {
84
+ 'np-header--section': variant === 'section',
85
+ 'np-header__title': !action || as === 'legend'
86
+ });
87
+ const commonProps = {
88
+ className: headerClasses,
89
+ 'data-testid': testId
90
+ };
91
+ React.useEffect(() => {
92
+ if (as === 'legend' && internalRef.current) {
93
+ const {
94
+ parentElement
95
+ } = internalRef.current;
96
+ if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {
97
+ console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
98
+ }
99
+ }
100
+ }, [as]);
101
+ if (!action || as === 'legend') {
48
102
  return /*#__PURE__*/jsxRuntime.jsx(Title, {
103
+ ref: internalRef,
49
104
  as: as,
50
- type: typography.Typography.TITLE_GROUP,
51
- className: clsx.clsx('np-header', 'np-header__title', className),
105
+ type: variantTypography,
106
+ ...commonProps,
107
+ ...props,
52
108
  children: title
53
109
  });
54
110
  }
55
- if (as === 'legend') {
56
- // eslint-disable-next-line no-console
57
- console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
58
- }
111
+ const actionRef = /*#__PURE__*/React__default.default.createRef();
59
112
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
60
- className: clsx.clsx('np-header', className),
113
+ ...commonProps,
114
+ ...props,
115
+ ref: ref,
61
116
  children: [/*#__PURE__*/jsxRuntime.jsx(Title, {
62
117
  as: as,
63
- type: typography.Typography.TITLE_GROUP,
118
+ type: variantTypography,
64
119
  className: "np-header__title",
65
120
  children: title
66
121
  }), /*#__PURE__*/jsxRuntime.jsx(HeaderAction, {
122
+ ref: actionRef,
67
123
  action: action
68
124
  })]
69
125
  });
70
- };
126
+ });
71
127
 
72
- exports.Header = Header;
73
- exports.default = Header;
128
+ module.exports = Header;
74
129
  //# sourceMappingURL=Header.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Header.js","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { ActionButtonProps } from '../actionButton/ActionButton';\nimport Button from '../button';\nimport { AriaLabelProperty, CommonProps, Heading, LinkProps, Typography } from '../common';\nimport Link from '../link';\nimport Title from '../title';\n\ntype ActionProps = AriaLabelProperty & {\n text: string;\n};\n\ntype ButtonActionProps = ActionProps & ActionButtonProps;\n\ntype LinkActionProps = ActionProps & LinkProps;\n\nexport type HeaderProps = CommonProps & {\n /**\n * When the `href` property is provided to the `action`, we will render a `Link` instead of a `ActionButton`.\n */\n action?: ButtonActionProps | LinkActionProps;\n /**\n * Override the heading element rendered for the title, useful to specify the semantics of your header.\n *\n * @default \"h5\"\n */\n as?: Heading | 'legend';\n title: string;\n};\n\nconst HeaderAction = ({ action }: { action: ButtonActionProps | LinkActionProps }) => {\n const props = {\n 'aria-label': action['aria-label'],\n };\n\n if ('href' in action) {\n return (\n <Link href={action.href} target={action.target} onClick={action.onClick} {...props}>\n {action.text}\n </Link>\n );\n }\n\n return (\n <Button\n className=\"np-header__button\"\n priority=\"tertiary\"\n size=\"sm\"\n onClick={action.onClick}\n {...props}\n >\n {action.text}\n </Button>\n );\n};\n\n/**\n *\n * Neptune Web: https://transferwise.github.io/neptune-web/components/content/Header\n *\n */\nexport const Header = ({ action, as = 'h5', title, className }: HeaderProps) => {\n if (!action) {\n return (\n <Title\n as={as}\n type={Typography.TITLE_GROUP}\n className={clsx('np-header', 'np-header__title', className)}\n >\n {title}\n </Title>\n );\n }\n\n if (as === 'legend') {\n // eslint-disable-next-line no-console\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 return (\n <div className={clsx('np-header', className)}>\n <Title as={as} type={Typography.TITLE_GROUP} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction action={action} />\n </div>\n );\n};\n\nexport default Header;\n"],"names":["HeaderAction","action","props","_jsx","Link","href","target","onClick","children","text","Button","className","priority","size","Header","as","title","Title","type","Typography","TITLE_GROUP","clsx","console","warn","_jsxs"],"mappings":";;;;;;;;;;;AA8BA,MAAMA,YAAY,GAAGA,CAAC;AAAEC,EAAAA,MAAAA;AAAM,CAAmD,KAAI;AACnF,EAAA,MAAMC,KAAK,GAAG;IACZ,YAAY,EAAED,MAAM,CAAC,YAAY,CAAA;GAClC,CAAA;EAED,IAAI,MAAM,IAAIA,MAAM,EAAE;IACpB,oBACEE,cAAA,CAACC,IAAI,EAAA;MAACC,IAAI,EAAEJ,MAAM,CAACI,IAAK;MAACC,MAAM,EAAEL,MAAM,CAACK,MAAO;MAACC,OAAO,EAAEN,MAAM,CAACM,OAAQ;AAAA,MAAA,GAAKL,KAAK;MAAAM,QAAA,EAC/EP,MAAM,CAACQ,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;EAEA,oBACEN,cAAA,CAACO,MAAM,EAAA;AACLC,IAAAA,SAAS,EAAC,mBAAmB;AAC7BC,IAAAA,QAAQ,EAAC,UAAU;AACnBC,IAAAA,IAAI,EAAC,IAAI;IACTN,OAAO,EAAEN,MAAM,CAACM,OAAQ;AAAA,IAAA,GACpBL,KAAK;IAAAM,QAAA,EAERP,MAAM,CAACQ,IAAAA;AAAI,GACN,CAAC,CAAA;AAEb,CAAC,CAAA;AAED;;;;AAIG;AACI,MAAMK,MAAM,GAAGA,CAAC;EAAEb,MAAM;AAAEc,EAAAA,EAAE,GAAG,IAAI;EAAEC,KAAK;AAAEL,EAAAA,SAAAA;AAAS,CAAe,KAAI;EAC7E,IAAI,CAACV,MAAM,EAAE;IACX,oBACEE,cAAA,CAACc,KAAK,EAAA;AACJF,MAAAA,EAAE,EAAEA,EAAG;MACPG,IAAI,EAAEC,qBAAU,CAACC,WAAY;MAC7BT,SAAS,EAAEU,SAAI,CAAC,WAAW,EAAE,kBAAkB,EAAEV,SAAS,CAAE;AAAAH,MAAAA,QAAA,EAE3DQ,KAAAA;AAAK,KACD,CAAC,CAAA;AAEZ,GAAA;EAEA,IAAID,EAAE,KAAK,QAAQ,EAAE;AACnB;AACAO,IAAAA,OAAO,CAACC,IAAI,CACV,oGAAoG,CACrG,CAAA;AACH,GAAA;AAEA,EAAA,oBACEC,eAAA,CAAA,KAAA,EAAA;AAAKb,IAAAA,SAAS,EAAEU,SAAI,CAAC,WAAW,EAAEV,SAAS,CAAE;IAAAH,QAAA,EAAA,cAC3CL,cAAA,CAACc,KAAK,EAAA;AAACF,MAAAA,EAAE,EAAEA,EAAG;MAACG,IAAI,EAAEC,qBAAU,CAACC,WAAY;AAACT,MAAAA,SAAS,EAAC,kBAAkB;AAAAH,MAAAA,QAAA,EACtEQ,KAAAA;AAAK,KACD,CACP,eAAAb,cAAA,CAACH,YAAY,EAAA;AAACC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAC/B,CAAA,CAAA;AAAA,GAAK,CAAC,CAAA;AAEV;;;;;"}
1
+ {"version":3,"file":"Header.js","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { ActionButtonProps } from '../actionButton/ActionButton';\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};\n\ntype ButtonActionProps = ActionProps & ActionButtonProps;\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';\n\n /** Optional prop to specify classNames onto the Header */\n className?: string;\n\n /** Optional prop to specify the ID used for testing */\n testId?: string;\n\n /** Required prop to set the title of the Header. */\n title: string;\n\n /** Optional prop to specify the variant of the Header */\n variant?: 'section' | 'group';\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\n/**\n * Header component\n *\n * The header component is used to render a section header with an optional action button or link.\n * The header component can be rendered as a `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, or `legend` element.\n *\n * @component\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'} [variant='group'] - Optional prop to specify the variant of the section header.\n * @param {string} [className] - Optional prop to specify classNames onto the Header.\n * @param {string} [testId] - Optional prop to specify the ID used for testing.\n *\n * @example\n * // Example usage:\n * import Header from './Header';\n *\n * function App() {\n * return (\n * <Header title=\"Header\" />\n * );\n * }\n */\nconst Header: FunctionComponent<HeaderProps> = React.forwardRef(\n (\n { as = 'h5', action, className, testId, title, variant = 'group', ...props },\n ref: React.Ref<HTMLDivElement | HTMLHeadingElement | HTMLLegendElement>,\n ) => {\n const internalRef = useRef<HTMLLegendElement>(null);\n const variantTypography =\n variant === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;\n const headerClasses = clsx('np-header', className, {\n 'np-header--section': variant === '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={variantTypography} {...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={variantTypography} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction ref={actionRef} action={action} />\n </div>\n );\n },\n);\n\nexport default Header;\n"],"names":["HeaderAction","React","forwardRef","action","ref","ariaLabel","text","onClick","href","target","linkOnClick","_jsx","Link","children","Button","className","priority","size","Header","as","testId","title","variant","props","internalRef","useRef","variantTypography","Typography","TITLE_SUBSECTION","TITLE_GROUP","headerClasses","clsx","commonProps","useEffect","current","parentElement","tagName","toLowerCase","console","warn","Title","type","actionRef","createRef","_jsxs"],"mappings":";;;;;;;;;;;;;;AA8CA,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,GAAG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,MAAAA,QAAA,EACjEQ,KAAAA;AAAK,KACD,CACP,eAAAV,cAAA,CAACX,YAAY,EAAA;AAACI,MAAAA,GAAG,EAAEsC,SAAU;AAACvC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAC/C,CAAA,CAAA;AAAA,GAAK,CAAC,CAAA;AAEV,CAAC;;;;"}
@@ -1,69 +1,123 @@
1
1
  import { clsx } from 'clsx';
2
- import Button from '../button/Button.mjs';
3
2
  import Link from '../link/Link.mjs';
3
+ import Button from '../button/Button.mjs';
4
4
  import Title from '../title/Title.mjs';
5
+ import React__default, { useRef, useEffect } from 'react';
5
6
  import { jsx, jsxs } from 'react/jsx-runtime';
6
7
  import { Typography } from '../common/propsValues/typography.mjs';
7
8
 
8
- const HeaderAction = ({
9
+ const HeaderAction = /*#__PURE__*/React__default.forwardRef(({
9
10
  action
10
- }) => {
11
- const props = {
12
- 'aria-label': action['aria-label']
13
- };
11
+ }, ref) => {
12
+ const {
13
+ 'aria-label': ariaLabel,
14
+ text,
15
+ onClick
16
+ } = action;
14
17
  if ('href' in action) {
18
+ const {
19
+ href,
20
+ target,
21
+ onClick: linkOnClick
22
+ } = action;
15
23
  return /*#__PURE__*/jsx(Link, {
16
- href: action.href,
17
- target: action.target,
18
- onClick: action.onClick,
19
- ...props,
20
- children: action.text
24
+ ref: ref,
25
+ href: href,
26
+ target: target,
27
+ "aria-label": ariaLabel,
28
+ onClick: linkOnClick,
29
+ children: text
21
30
  });
22
31
  }
23
32
  return /*#__PURE__*/jsx(Button, {
33
+ ref: ref,
24
34
  className: "np-header__button",
25
35
  priority: "tertiary",
26
36
  size: "sm",
27
- onClick: action.onClick,
28
- ...props,
29
- children: action.text
37
+ "aria-label": ariaLabel,
38
+ onClick: onClick,
39
+ children: text
30
40
  });
31
- };
41
+ });
32
42
  /**
43
+ * Header component
44
+ *
45
+ * The header component is used to render a section header with an optional action button or link.
46
+ * The header component can be rendered as a `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, or `legend` element.
47
+ *
48
+ * @component
49
+ * @param {ButtonActionProps | LinkActionProps} [action] - Optional prop to specify the action button or link.
50
+ * @param {Heading | 'legend'} [as='h5'] - Optional prop to override the heading element rendered for the title.
51
+ * @param {string} title - Required prop to set the title of the section header.
52
+ * @param {'group' | 'section'} [variant='group'] - Optional prop to specify the variant of the section header.
53
+ * @param {string} [className] - Optional prop to specify classNames onto the Header.
54
+ * @param {string} [testId] - Optional prop to specify the ID used for testing.
33
55
  *
34
- * Neptune Web: https://transferwise.github.io/neptune-web/components/content/Header
56
+ * @example
57
+ * // Example usage:
58
+ * import Header from './Header';
35
59
  *
60
+ * function App() {
61
+ * return (
62
+ * <Header title="Header" />
63
+ * );
64
+ * }
36
65
  */
37
- const Header = ({
38
- action,
66
+ const Header = /*#__PURE__*/React__default.forwardRef(({
39
67
  as = 'h5',
68
+ action,
69
+ className,
70
+ testId,
40
71
  title,
41
- className
42
- }) => {
43
- if (!action) {
72
+ variant = 'group',
73
+ ...props
74
+ }, ref) => {
75
+ const internalRef = useRef(null);
76
+ const variantTypography = variant === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;
77
+ const headerClasses = clsx('np-header', className, {
78
+ 'np-header--section': variant === 'section',
79
+ 'np-header__title': !action || as === 'legend'
80
+ });
81
+ const commonProps = {
82
+ className: headerClasses,
83
+ 'data-testid': testId
84
+ };
85
+ useEffect(() => {
86
+ if (as === 'legend' && internalRef.current) {
87
+ const {
88
+ parentElement
89
+ } = internalRef.current;
90
+ if (!parentElement || parentElement.tagName.toLowerCase() !== 'fieldset') {
91
+ console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
92
+ }
93
+ }
94
+ }, [as]);
95
+ if (!action || as === 'legend') {
44
96
  return /*#__PURE__*/jsx(Title, {
97
+ ref: internalRef,
45
98
  as: as,
46
- type: Typography.TITLE_GROUP,
47
- className: clsx('np-header', 'np-header__title', className),
99
+ type: variantTypography,
100
+ ...commonProps,
101
+ ...props,
48
102
  children: title
49
103
  });
50
104
  }
51
- if (as === 'legend') {
52
- // eslint-disable-next-line no-console
53
- console.warn('Legends should be the first child in a fieldset, and this is not possible when including an action');
54
- }
105
+ const actionRef = /*#__PURE__*/React__default.createRef();
55
106
  return /*#__PURE__*/jsxs("div", {
56
- className: clsx('np-header', className),
107
+ ...commonProps,
108
+ ...props,
109
+ ref: ref,
57
110
  children: [/*#__PURE__*/jsx(Title, {
58
111
  as: as,
59
- type: Typography.TITLE_GROUP,
112
+ type: variantTypography,
60
113
  className: "np-header__title",
61
114
  children: title
62
115
  }), /*#__PURE__*/jsx(HeaderAction, {
116
+ ref: actionRef,
63
117
  action: action
64
118
  })]
65
119
  });
66
- };
120
+ });
67
121
 
68
- export { Header, Header as default };
122
+ export { Header as default };
69
123
  //# sourceMappingURL=Header.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Header.mjs","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { ActionButtonProps } from '../actionButton/ActionButton';\nimport Button from '../button';\nimport { AriaLabelProperty, CommonProps, Heading, LinkProps, Typography } from '../common';\nimport Link from '../link';\nimport Title from '../title';\n\ntype ActionProps = AriaLabelProperty & {\n text: string;\n};\n\ntype ButtonActionProps = ActionProps & ActionButtonProps;\n\ntype LinkActionProps = ActionProps & LinkProps;\n\nexport type HeaderProps = CommonProps & {\n /**\n * When the `href` property is provided to the `action`, we will render a `Link` instead of a `ActionButton`.\n */\n action?: ButtonActionProps | LinkActionProps;\n /**\n * Override the heading element rendered for the title, useful to specify the semantics of your header.\n *\n * @default \"h5\"\n */\n as?: Heading | 'legend';\n title: string;\n};\n\nconst HeaderAction = ({ action }: { action: ButtonActionProps | LinkActionProps }) => {\n const props = {\n 'aria-label': action['aria-label'],\n };\n\n if ('href' in action) {\n return (\n <Link href={action.href} target={action.target} onClick={action.onClick} {...props}>\n {action.text}\n </Link>\n );\n }\n\n return (\n <Button\n className=\"np-header__button\"\n priority=\"tertiary\"\n size=\"sm\"\n onClick={action.onClick}\n {...props}\n >\n {action.text}\n </Button>\n );\n};\n\n/**\n *\n * Neptune Web: https://transferwise.github.io/neptune-web/components/content/Header\n *\n */\nexport const Header = ({ action, as = 'h5', title, className }: HeaderProps) => {\n if (!action) {\n return (\n <Title\n as={as}\n type={Typography.TITLE_GROUP}\n className={clsx('np-header', 'np-header__title', className)}\n >\n {title}\n </Title>\n );\n }\n\n if (as === 'legend') {\n // eslint-disable-next-line no-console\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 return (\n <div className={clsx('np-header', className)}>\n <Title as={as} type={Typography.TITLE_GROUP} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction action={action} />\n </div>\n );\n};\n\nexport default Header;\n"],"names":["HeaderAction","action","props","_jsx","Link","href","target","onClick","children","text","Button","className","priority","size","Header","as","title","Title","type","Typography","TITLE_GROUP","clsx","console","warn","_jsxs"],"mappings":";;;;;;;AA8BA,MAAMA,YAAY,GAAGA,CAAC;AAAEC,EAAAA,MAAAA;AAAM,CAAmD,KAAI;AACnF,EAAA,MAAMC,KAAK,GAAG;IACZ,YAAY,EAAED,MAAM,CAAC,YAAY,CAAA;GAClC,CAAA;EAED,IAAI,MAAM,IAAIA,MAAM,EAAE;IACpB,oBACEE,GAAA,CAACC,IAAI,EAAA;MAACC,IAAI,EAAEJ,MAAM,CAACI,IAAK;MAACC,MAAM,EAAEL,MAAM,CAACK,MAAO;MAACC,OAAO,EAAEN,MAAM,CAACM,OAAQ;AAAA,MAAA,GAAKL,KAAK;MAAAM,QAAA,EAC/EP,MAAM,CAACQ,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;EAEA,oBACEN,GAAA,CAACO,MAAM,EAAA;AACLC,IAAAA,SAAS,EAAC,mBAAmB;AAC7BC,IAAAA,QAAQ,EAAC,UAAU;AACnBC,IAAAA,IAAI,EAAC,IAAI;IACTN,OAAO,EAAEN,MAAM,CAACM,OAAQ;AAAA,IAAA,GACpBL,KAAK;IAAAM,QAAA,EAERP,MAAM,CAACQ,IAAAA;AAAI,GACN,CAAC,CAAA;AAEb,CAAC,CAAA;AAED;;;;AAIG;AACI,MAAMK,MAAM,GAAGA,CAAC;EAAEb,MAAM;AAAEc,EAAAA,EAAE,GAAG,IAAI;EAAEC,KAAK;AAAEL,EAAAA,SAAAA;AAAS,CAAe,KAAI;EAC7E,IAAI,CAACV,MAAM,EAAE;IACX,oBACEE,GAAA,CAACc,KAAK,EAAA;AACJF,MAAAA,EAAE,EAAEA,EAAG;MACPG,IAAI,EAAEC,UAAU,CAACC,WAAY;MAC7BT,SAAS,EAAEU,IAAI,CAAC,WAAW,EAAE,kBAAkB,EAAEV,SAAS,CAAE;AAAAH,MAAAA,QAAA,EAE3DQ,KAAAA;AAAK,KACD,CAAC,CAAA;AAEZ,GAAA;EAEA,IAAID,EAAE,KAAK,QAAQ,EAAE;AACnB;AACAO,IAAAA,OAAO,CAACC,IAAI,CACV,oGAAoG,CACrG,CAAA;AACH,GAAA;AAEA,EAAA,oBACEC,IAAA,CAAA,KAAA,EAAA;AAAKb,IAAAA,SAAS,EAAEU,IAAI,CAAC,WAAW,EAAEV,SAAS,CAAE;IAAAH,QAAA,EAAA,cAC3CL,GAAA,CAACc,KAAK,EAAA;AAACF,MAAAA,EAAE,EAAEA,EAAG;MAACG,IAAI,EAAEC,UAAU,CAACC,WAAY;AAACT,MAAAA,SAAS,EAAC,kBAAkB;AAAAH,MAAAA,QAAA,EACtEQ,KAAAA;AAAK,KACD,CACP,eAAAb,GAAA,CAACH,YAAY,EAAA;AAACC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAC/B,CAAA,CAAA;AAAA,GAAK,CAAC,CAAA;AAEV;;;;"}
1
+ {"version":3,"file":"Header.mjs","sources":["../../src/header/Header.tsx"],"sourcesContent":["import { clsx } from 'clsx';\n\nimport { ActionButtonProps } from '../actionButton/ActionButton';\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};\n\ntype ButtonActionProps = ActionProps & ActionButtonProps;\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';\n\n /** Optional prop to specify classNames onto the Header */\n className?: string;\n\n /** Optional prop to specify the ID used for testing */\n testId?: string;\n\n /** Required prop to set the title of the Header. */\n title: string;\n\n /** Optional prop to specify the variant of the Header */\n variant?: 'section' | 'group';\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\n/**\n * Header component\n *\n * The header component is used to render a section header with an optional action button or link.\n * The header component can be rendered as a `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, or `legend` element.\n *\n * @component\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'} [variant='group'] - Optional prop to specify the variant of the section header.\n * @param {string} [className] - Optional prop to specify classNames onto the Header.\n * @param {string} [testId] - Optional prop to specify the ID used for testing.\n *\n * @example\n * // Example usage:\n * import Header from './Header';\n *\n * function App() {\n * return (\n * <Header title=\"Header\" />\n * );\n * }\n */\nconst Header: FunctionComponent<HeaderProps> = React.forwardRef(\n (\n { as = 'h5', action, className, testId, title, variant = 'group', ...props },\n ref: React.Ref<HTMLDivElement | HTMLHeadingElement | HTMLLegendElement>,\n ) => {\n const internalRef = useRef<HTMLLegendElement>(null);\n const variantTypography =\n variant === 'section' ? Typography.TITLE_SUBSECTION : Typography.TITLE_GROUP;\n const headerClasses = clsx('np-header', className, {\n 'np-header--section': variant === '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={variantTypography} {...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={variantTypography} className=\"np-header__title\">\n {title}\n </Title>\n <HeaderAction ref={actionRef} action={action} />\n </div>\n );\n },\n);\n\nexport default Header;\n"],"names":["HeaderAction","React","forwardRef","action","ref","ariaLabel","text","onClick","href","target","linkOnClick","_jsx","Link","children","Button","className","priority","size","Header","as","testId","title","variant","props","internalRef","useRef","variantTypography","Typography","TITLE_SUBSECTION","TITLE_GROUP","headerClasses","clsx","commonProps","useEffect","current","parentElement","tagName","toLowerCase","console","warn","Title","type","actionRef","createRef","_jsxs"],"mappings":";;;;;;;;AA8CA,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;AAED;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACH,MAAMY,MAAM,gBAAmCjB,cAAK,CAACC,UAAU,CAC7D,CACE;AAAEiB,EAAAA,EAAE,GAAG,IAAI;EAAEhB,MAAM;EAAEY,SAAS;EAAEK,MAAM;EAAEC,KAAK;AA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,MAAAA,QAAA,EACjFQ,KAAAA;AAAK,KACD,CAAC,CAAA;AAEZ,GAAA;AAEA,EAAA,MAAMqB,SAAS,gBAAGzC,cAAK,CAAC0C,SAAS,EAAyC,CAAA;AAE1E,EAAA,oBACEC,IAAA,CAAA,KAAA,EAAA;AAAA,IAAA,GAASZ,WAAW;AAAA,IAAA,GAAMT,KAAK;AAAEnB,IAAAA,GAAG,EAAEA,GAAiC;IAAAS,QAAA,EAAA,cACrEF,GAAA,CAAC6B,KAAK,EAAA;AAACrB,MAAAA,EAAE,EAAEA,EAAG;AAACsB,MAAAA,IAAI,EAAEf,iBAAkB;AAACX,MAAAA,SAAS,EAAC,kBAAkB;AAAAF,MAAAA,QAAA,EACjEQ,KAAAA;AAAK,KACD,CACP,eAAAV,GAAA,CAACX,YAAY,EAAA;AAACI,MAAAA,GAAG,EAAEsC,SAAU;AAACvC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAC/C,CAAA,CAAA;AAAA,GAAK,CAAC,CAAA;AAEV,CAAC;;;;"}
package/build/index.js CHANGED
@@ -176,7 +176,7 @@ exports.DropFade = DropFade;
176
176
  exports.Emphasis = Emphasis;
177
177
  exports.Field = Field.Field;
178
178
  exports.FlowNavigation = FlowNavigation;
179
- exports.Header = Header.Header;
179
+ exports.Header = Header;
180
180
  exports.Image = Image.default;
181
181
  Object.defineProperty(exports, "InfoPresentation", {
182
182
  enumerable: true,
package/build/index.mjs CHANGED
@@ -33,7 +33,7 @@ export { default as DropFade } from './dropFade/DropFade.mjs';
33
33
  export { default as Emphasis } from './emphasis/Emphasis.mjs';
34
34
  export { Field } from './field/Field.mjs';
35
35
  export { default as FlowNavigation } from './flowNavigation/FlowNavigation.mjs';
36
- export { Header } from './header/Header.mjs';
36
+ export { default as Header } from './header/Header.mjs';
37
37
  export { default as Image } from './image/Image.mjs';
38
38
  export { InfoPresentation } from './info/infoPresentations.mjs';
39
39
  export { default as Info } from './info/Info.mjs';
@@ -2,11 +2,12 @@
2
2
 
3
3
  var icons = require('@transferwise/icons');
4
4
  var clsx = require('clsx');
5
+ var React = require('react');
5
6
  var reactIntl = require('react-intl');
6
7
  var Link_messages = require('./Link.messages.js');
7
8
  var jsxRuntime = require('react/jsx-runtime');
8
9
 
9
- const Link = ({
10
+ const Link = /*#__PURE__*/React.forwardRef(({
10
11
  className,
11
12
  children,
12
13
  href,
@@ -15,12 +16,13 @@ const Link = ({
15
16
  'aria-label': ariaLabel,
16
17
  onClick,
17
18
  ...props
18
- }) => {
19
+ }, ref) => {
19
20
  const isBlank = target === '_blank';
20
21
  const {
21
22
  formatMessage
22
23
  } = reactIntl.useIntl();
23
24
  return /*#__PURE__*/jsxRuntime.jsxs("a", {
25
+ ref: ref,
24
26
  href: href,
25
27
  target: target,
26
28
  className: clsx.clsx('np-link', type ? `np-text-${type}` : undefined, 'd-inline-flex', className),
@@ -32,7 +34,7 @@ const Link = ({
32
34
  title: formatMessage(Link_messages.opensInNewTab)
33
35
  })]
34
36
  });
35
- };
37
+ });
36
38
 
37
39
  module.exports = Link;
38
40
  //# sourceMappingURL=Link.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.js","sources":["../../src/link/Link.tsx"],"sourcesContent":["import { NavigateAway as NavigateAwayIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport { AnchorHTMLAttributes } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { LinkLarge, LinkDefault } from '../common';\n\nimport messages from './Link.messages';\n\nexport type Props = AnchorHTMLAttributes<HTMLAnchorElement> & { type?: LinkLarge | LinkDefault };\n\n/**\n * Standard Link component with navigate away icon\n *\n * Documentation: https://transferwise.github.io/neptune-web/components/content/Link\n */\nconst Link = ({\n className,\n children,\n href,\n target,\n type,\n 'aria-label': ariaLabel,\n onClick,\n ...props\n}: Props) => {\n const isBlank = target === '_blank';\n\n const { formatMessage } = useIntl();\n\n return (\n <a\n href={href}\n target={target}\n className={clsx('np-link', type ? `np-text-${type}` : undefined, 'd-inline-flex', className)}\n aria-label={ariaLabel}\n rel={isBlank ? 'noreferrer' : undefined}\n onClick={onClick}\n {...props}\n >\n {children} {isBlank && <NavigateAwayIcon title={formatMessage(messages.opensInNewTab)} />}\n </a>\n );\n};\n\nexport default Link;\n"],"names":["Link","className","children","href","target","type","ariaLabel","onClick","props","isBlank","formatMessage","useIntl","_jsxs","clsx","undefined","rel","_jsx","NavigateAwayIcon","title","messages","opensInNewTab"],"mappings":";;;;;;;;AAgBMA,MAAAA,IAAI,GAAGA,CAAC;EACZC,SAAS;EACTC,QAAQ;EACRC,IAAI;EACJC,MAAM;EACNC,IAAI;AACJ,EAAA,YAAY,EAAEC,SAAS;EACvBC,OAAO;EACP,GAAGC,KAAAA;AACG,CAAA,KAAI;AACV,EAAA,MAAMC,OAAO,GAAGL,MAAM,KAAK,QAAQ,CAAA;EAEnC,MAAM;AAAEM,IAAAA,aAAAA;GAAe,GAAGC,iBAAO,EAAE,CAAA;AAEnC,EAAA,oBACEC,eAAA,CAAA,GAAA,EAAA;AACET,IAAAA,IAAI,EAAEA,IAAK;AACXC,IAAAA,MAAM,EAAEA,MAAO;AACfH,IAAAA,SAAS,EAAEY,SAAI,CAAC,SAAS,EAAER,IAAI,GAAG,CAAA,QAAA,EAAWA,IAAI,CAAA,CAAE,GAAGS,SAAS,EAAE,eAAe,EAAEb,SAAS,CAAE;AAC7F,IAAA,YAAA,EAAYK,SAAU;AACtBS,IAAAA,GAAG,EAAEN,OAAO,GAAG,YAAY,GAAGK,SAAU;AACxCP,IAAAA,OAAO,EAAEA,OAAQ;AAAA,IAAA,GACbC,KAAK;IAAAN,QAAA,EAAA,CAERA,QAAQ,EAAE,GAAA,EAACO,OAAO,iBAAIO,cAAA,CAACC,kBAAgB,EAAA;AAACC,MAAAA,KAAK,EAAER,aAAa,CAACS,aAAQ,CAACC,aAAa,CAAA;AAAE,MAAG,CAAA;AAAA,GACxF,CAAC,CAAA;AAER;;;;"}
1
+ {"version":3,"file":"Link.js","sources":["../../src/link/Link.tsx"],"sourcesContent":["import { NavigateAway as NavigateAwayIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport { AnchorHTMLAttributes, forwardRef } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { LinkLarge, LinkDefault } from '../common';\n\nimport messages from './Link.messages';\n\nexport type Props = AnchorHTMLAttributes<HTMLAnchorElement> & { type?: LinkLarge | LinkDefault };\n\n/**\n * Standard Link component with navigate away icon\n *\n * Documentation: https://transferwise.github.io/neptune-web/components/content/Link\n */\nconst Link = forwardRef<HTMLAnchorElement, Props>(\n (\n { className, children, href, target, type, 'aria-label': ariaLabel, onClick, ...props }: Props,\n ref,\n ) => {\n const isBlank = target === '_blank';\n\n const { formatMessage } = useIntl();\n\n return (\n <a\n ref={ref}\n href={href}\n target={target}\n className={clsx(\n 'np-link',\n type ? `np-text-${type}` : undefined,\n 'd-inline-flex',\n className,\n )}\n aria-label={ariaLabel}\n rel={isBlank ? 'noreferrer' : undefined}\n onClick={onClick}\n {...props}\n >\n {children} {isBlank && <NavigateAwayIcon title={formatMessage(messages.opensInNewTab)} />}\n </a>\n );\n },\n);\n\nexport default Link;\n"],"names":["Link","forwardRef","className","children","href","target","type","ariaLabel","onClick","props","ref","isBlank","formatMessage","useIntl","_jsxs","clsx","undefined","rel","_jsx","NavigateAwayIcon","title","messages","opensInNewTab"],"mappings":";;;;;;;;;AAgBA,MAAMA,IAAI,gBAAGC,gBAAU,CACrB,CACE;EAAEC,SAAS;EAAEC,QAAQ;EAAEC,IAAI;EAAEC,MAAM;EAAEC,IAAI;AAAE,EAAA,YAAY,EAAEC,SAAS;EAAEC,OAAO;EAAE,GAAGC,KAAAA;AAAc,CAAA,EAC9FC,GAAG,KACD;AACF,EAAA,MAAMC,OAAO,GAAGN,MAAM,KAAK,QAAQ,CAAA;EAEnC,MAAM;AAAEO,IAAAA,aAAAA;GAAe,GAAGC,iBAAO,EAAE,CAAA;AAEnC,EAAA,oBACEC,eAAA,CAAA,GAAA,EAAA;AACEJ,IAAAA,GAAG,EAAEA,GAAI;AACTN,IAAAA,IAAI,EAAEA,IAAK;AACXC,IAAAA,MAAM,EAAEA,MAAO;AACfH,IAAAA,SAAS,EAAEa,SAAI,CACb,SAAS,EACTT,IAAI,GAAG,CAAA,QAAA,EAAWA,IAAI,CAAA,CAAE,GAAGU,SAAS,EACpC,eAAe,EACfd,SAAS,CACT;AACF,IAAA,YAAA,EAAYK,SAAU;AACtBU,IAAAA,GAAG,EAAEN,OAAO,GAAG,YAAY,GAAGK,SAAU;AACxCR,IAAAA,OAAO,EAAEA,OAAQ;AAAA,IAAA,GACbC,KAAK;IAAAN,QAAA,EAAA,CAERA,QAAQ,EAAE,GAAA,EAACQ,OAAO,iBAAIO,cAAA,CAACC,kBAAgB,EAAA;AAACC,MAAAA,KAAK,EAAER,aAAa,CAACS,aAAQ,CAACC,aAAa,CAAA;AAAE,MAAG,CAAA;AAAA,GACxF,CAAC,CAAA;AAER,CAAC;;;;"}
@@ -1,10 +1,11 @@
1
1
  import { NavigateAway } from '@transferwise/icons';
2
2
  import { clsx } from 'clsx';
3
+ import { forwardRef } from 'react';
3
4
  import { useIntl } from 'react-intl';
4
5
  import messages from './Link.messages.mjs';
5
6
  import { jsxs, jsx } from 'react/jsx-runtime';
6
7
 
7
- const Link = ({
8
+ const Link = /*#__PURE__*/forwardRef(({
8
9
  className,
9
10
  children,
10
11
  href,
@@ -13,12 +14,13 @@ const Link = ({
13
14
  'aria-label': ariaLabel,
14
15
  onClick,
15
16
  ...props
16
- }) => {
17
+ }, ref) => {
17
18
  const isBlank = target === '_blank';
18
19
  const {
19
20
  formatMessage
20
21
  } = useIntl();
21
22
  return /*#__PURE__*/jsxs("a", {
23
+ ref: ref,
22
24
  href: href,
23
25
  target: target,
24
26
  className: clsx('np-link', type ? `np-text-${type}` : undefined, 'd-inline-flex', className),
@@ -30,7 +32,7 @@ const Link = ({
30
32
  title: formatMessage(messages.opensInNewTab)
31
33
  })]
32
34
  });
33
- };
35
+ });
34
36
 
35
37
  export { Link as default };
36
38
  //# sourceMappingURL=Link.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.mjs","sources":["../../src/link/Link.tsx"],"sourcesContent":["import { NavigateAway as NavigateAwayIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport { AnchorHTMLAttributes } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { LinkLarge, LinkDefault } from '../common';\n\nimport messages from './Link.messages';\n\nexport type Props = AnchorHTMLAttributes<HTMLAnchorElement> & { type?: LinkLarge | LinkDefault };\n\n/**\n * Standard Link component with navigate away icon\n *\n * Documentation: https://transferwise.github.io/neptune-web/components/content/Link\n */\nconst Link = ({\n className,\n children,\n href,\n target,\n type,\n 'aria-label': ariaLabel,\n onClick,\n ...props\n}: Props) => {\n const isBlank = target === '_blank';\n\n const { formatMessage } = useIntl();\n\n return (\n <a\n href={href}\n target={target}\n className={clsx('np-link', type ? `np-text-${type}` : undefined, 'd-inline-flex', className)}\n aria-label={ariaLabel}\n rel={isBlank ? 'noreferrer' : undefined}\n onClick={onClick}\n {...props}\n >\n {children} {isBlank && <NavigateAwayIcon title={formatMessage(messages.opensInNewTab)} />}\n </a>\n );\n};\n\nexport default Link;\n"],"names":["Link","className","children","href","target","type","ariaLabel","onClick","props","isBlank","formatMessage","useIntl","_jsxs","clsx","undefined","rel","_jsx","NavigateAwayIcon","title","messages","opensInNewTab"],"mappings":";;;;;;AAgBMA,MAAAA,IAAI,GAAGA,CAAC;EACZC,SAAS;EACTC,QAAQ;EACRC,IAAI;EACJC,MAAM;EACNC,IAAI;AACJ,EAAA,YAAY,EAAEC,SAAS;EACvBC,OAAO;EACP,GAAGC,KAAAA;AACG,CAAA,KAAI;AACV,EAAA,MAAMC,OAAO,GAAGL,MAAM,KAAK,QAAQ,CAAA;EAEnC,MAAM;AAAEM,IAAAA,aAAAA;GAAe,GAAGC,OAAO,EAAE,CAAA;AAEnC,EAAA,oBACEC,IAAA,CAAA,GAAA,EAAA;AACET,IAAAA,IAAI,EAAEA,IAAK;AACXC,IAAAA,MAAM,EAAEA,MAAO;AACfH,IAAAA,SAAS,EAAEY,IAAI,CAAC,SAAS,EAAER,IAAI,GAAG,CAAA,QAAA,EAAWA,IAAI,CAAA,CAAE,GAAGS,SAAS,EAAE,eAAe,EAAEb,SAAS,CAAE;AAC7F,IAAA,YAAA,EAAYK,SAAU;AACtBS,IAAAA,GAAG,EAAEN,OAAO,GAAG,YAAY,GAAGK,SAAU;AACxCP,IAAAA,OAAO,EAAEA,OAAQ;AAAA,IAAA,GACbC,KAAK;IAAAN,QAAA,EAAA,CAERA,QAAQ,EAAE,GAAA,EAACO,OAAO,iBAAIO,GAAA,CAACC,YAAgB,EAAA;AAACC,MAAAA,KAAK,EAAER,aAAa,CAACS,QAAQ,CAACC,aAAa,CAAA;AAAE,MAAG,CAAA;AAAA,GACxF,CAAC,CAAA;AAER;;;;"}
1
+ {"version":3,"file":"Link.mjs","sources":["../../src/link/Link.tsx"],"sourcesContent":["import { NavigateAway as NavigateAwayIcon } from '@transferwise/icons';\nimport { clsx } from 'clsx';\nimport { AnchorHTMLAttributes, forwardRef } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { LinkLarge, LinkDefault } from '../common';\n\nimport messages from './Link.messages';\n\nexport type Props = AnchorHTMLAttributes<HTMLAnchorElement> & { type?: LinkLarge | LinkDefault };\n\n/**\n * Standard Link component with navigate away icon\n *\n * Documentation: https://transferwise.github.io/neptune-web/components/content/Link\n */\nconst Link = forwardRef<HTMLAnchorElement, Props>(\n (\n { className, children, href, target, type, 'aria-label': ariaLabel, onClick, ...props }: Props,\n ref,\n ) => {\n const isBlank = target === '_blank';\n\n const { formatMessage } = useIntl();\n\n return (\n <a\n ref={ref}\n href={href}\n target={target}\n className={clsx(\n 'np-link',\n type ? `np-text-${type}` : undefined,\n 'd-inline-flex',\n className,\n )}\n aria-label={ariaLabel}\n rel={isBlank ? 'noreferrer' : undefined}\n onClick={onClick}\n {...props}\n >\n {children} {isBlank && <NavigateAwayIcon title={formatMessage(messages.opensInNewTab)} />}\n </a>\n );\n },\n);\n\nexport default Link;\n"],"names":["Link","forwardRef","className","children","href","target","type","ariaLabel","onClick","props","ref","isBlank","formatMessage","useIntl","_jsxs","clsx","undefined","rel","_jsx","NavigateAwayIcon","title","messages","opensInNewTab"],"mappings":";;;;;;;AAgBA,MAAMA,IAAI,gBAAGC,UAAU,CACrB,CACE;EAAEC,SAAS;EAAEC,QAAQ;EAAEC,IAAI;EAAEC,MAAM;EAAEC,IAAI;AAAE,EAAA,YAAY,EAAEC,SAAS;EAAEC,OAAO;EAAE,GAAGC,KAAAA;AAAc,CAAA,EAC9FC,GAAG,KACD;AACF,EAAA,MAAMC,OAAO,GAAGN,MAAM,KAAK,QAAQ,CAAA;EAEnC,MAAM;AAAEO,IAAAA,aAAAA;GAAe,GAAGC,OAAO,EAAE,CAAA;AAEnC,EAAA,oBACEC,IAAA,CAAA,GAAA,EAAA;AACEJ,IAAAA,GAAG,EAAEA,GAAI;AACTN,IAAAA,IAAI,EAAEA,IAAK;AACXC,IAAAA,MAAM,EAAEA,MAAO;AACfH,IAAAA,SAAS,EAAEa,IAAI,CACb,SAAS,EACTT,IAAI,GAAG,CAAA,QAAA,EAAWA,IAAI,CAAA,CAAE,GAAGU,SAAS,EACpC,eAAe,EACfd,SAAS,CACT;AACF,IAAA,YAAA,EAAYK,SAAU;AACtBU,IAAAA,GAAG,EAAEN,OAAO,GAAG,YAAY,GAAGK,SAAU;AACxCR,IAAAA,OAAO,EAAEA,OAAQ;AAAA,IAAA,GACbC,KAAK;IAAAN,QAAA,EAAA,CAERA,QAAQ,EAAE,GAAA,EAACQ,OAAO,iBAAIO,GAAA,CAACC,YAAgB,EAAA;AAACC,MAAAA,KAAK,EAAER,aAAa,CAACS,QAAQ,CAACC,aAAa,CAAA;AAAE,MAAG,CAAA;AAAA,GACxF,CAAC,CAAA;AAER,CAAC;;;;"}
package/build/main.css CHANGED
@@ -2242,6 +2242,9 @@ html:not([dir="rtl"]) .np-flow-navigation--sm .np-flow-navigation__stepper {
2242
2242
  -moz-column-gap: var(--size-24);
2243
2243
  column-gap: var(--size-24);
2244
2244
  }
2245
+ .np-header--section {
2246
+ border-bottom: none;
2247
+ }
2245
2248
  .np-header__title {
2246
2249
  color: #5d7079;
2247
2250
  color: var(--color-content-secondary);
@@ -52,7 +52,7 @@ function SelectOption({
52
52
  className: clsx.clsx({
53
53
  'p-x-2 p-y-1': isLargeScreen
54
54
  }),
55
- children: [optionsSection.title && /*#__PURE__*/jsxRuntime.jsx(Header.Header, {
55
+ children: [optionsSection.title && /*#__PURE__*/jsxRuntime.jsx(Header, {
56
56
  title: optionsSection.title
57
57
  }), /*#__PURE__*/jsxRuntime.jsx(NavigationOptionsList, {
58
58
  children: optionsSection.options.map((option, index) => {
@@ -1 +1 @@
1
- {"version":3,"file":"SelectOption.js","sources":["../../src/selectOption/SelectOption.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { ActionButtonProps } from '../actionButton';\nimport { clsx } from 'clsx';\nimport Option from '../common/Option';\nimport type { OptionProps } from '../common/Option/Option';\nimport { Breakpoint, Position } from '../common';\nimport Section from '../section';\nimport Header from '../header';\nimport { HeaderProps } from '../header/Header';\nimport NavigationOption from '../navigationOption';\nimport NavigationOptionsList from '../navigationOptionsList';\nimport { useInputAttributes } from '../inputs/contexts';\nimport messages from './SelectOption.messages';\nimport { useIntl } from 'react-intl';\nimport ResponsivePanel from '../common/responsivePanel';\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport { ChevronDown, Plus } from '@transferwise/icons';\n\nexport type SelectOptiopsSection<T = unknown> = {\n title?: HeaderProps['title'];\n options: SelectOptionValue<T>[];\n};\n\nexport type SelectOptionValue<T = unknown> = Pick<\n OptionProps,\n 'media' | 'title' | 'content' | 'disabled'\n> & {\n value?: T;\n};\n\nexport type SelectOptionPlaceholder = Pick<OptionProps, 'media' | 'title' | 'content'> & {\n actionLabel?: ActionButtonProps['children'];\n};\n\nexport type SelectOptionProps<T = unknown> = {\n onChange: (selected: SelectOptionValue<T>) => void;\n selected?: SelectOptionValue<T>;\n options: SelectOptiopsSection<T>[];\n placeholder: SelectOptionPlaceholder;\n} & Omit<\n OptionProps,\n 'as' | 'title' | 'media' | 'content' | 'onClick' | 'onChange' | 'showMediaAtAllSizes' | 'decision'\n>;\n\nexport default function SelectOption<T>({\n selected = undefined,\n options,\n onChange,\n placeholder,\n disabled,\n ...props\n}: SelectOptionProps<T>) {\n const intl = useIntl();\n const rootRef = useRef(null);\n const [showOptions, setShowOptions] = useState(false);\n\n const hasSelected = selected !== undefined;\n const isLargeScreen = useScreenSize(Breakpoint.SMALL);\n\n const inputAttributes = useInputAttributes();\n const ariaLabelledBy = props['aria-labelledby'] ?? inputAttributes?.['aria-labelledby'];\n\n function handleOnClick(showOptionsStatus: boolean) {\n return () => {\n setShowOptions(showOptionsStatus);\n };\n }\n\n function handleOnChange(data: SelectOptionValue<T>) {\n return () => {\n setShowOptions(false);\n onChange(data);\n };\n }\n\n function getOptions(isLargeScreen = false) {\n return (\n <div className={clsx({ 'np-select-option-list': isLargeScreen })}>\n {options.map((optionsSection, index) => (\n <Section key={index} className={clsx({ 'p-x-2 p-y-1': isLargeScreen })}>\n {optionsSection.title && <Header title={optionsSection.title} />}\n <NavigationOptionsList>\n {optionsSection.options.map((option, index) => {\n return (\n <NavigationOption\n key={index}\n isContainerAligned={!isLargeScreen}\n showMediaCircle\n showMediaAtAllSizes\n onClick={handleOnChange(option)}\n {...option}\n />\n );\n })}\n </NavigationOptionsList>\n </Section>\n ))}\n </div>\n );\n }\n\n return (\n <>\n <Option\n ref={rootRef}\n as=\"div\"\n showMediaAtAllSizes\n disabled={disabled}\n decision={false}\n media={hasSelected ? selected.media : (placeholder.media ?? <Plus size={24} />)}\n title={(hasSelected ? selected : placeholder).title}\n content={(hasSelected ? selected : placeholder).content}\n className={clsx(\n 'np-select-option',\n 'clickable',\n hasSelected ? 'np-select-option-selected' : 'np-select-option-placeholder',\n props.className,\n )}\n button={\n <button\n {...inputAttributes}\n type=\"button\"\n disabled={disabled}\n aria-labelledby={ariaLabelledBy}\n aria-haspopup=\"dialog\"\n aria-expanded={showOptions}\n className={hasSelected ? 'btn-unstyled' : 'np-action-btn'}\n aria-label={hasSelected ? undefined : props['aria-label']}\n onClick={handleOnClick(true)}\n >\n {hasSelected ? (\n <ChevronDown title={intl.formatMessage(messages.selectedActionLabel)} />\n ) : (\n placeholder.actionLabel || intl.formatMessage(messages.actionLabel)\n )}\n </button>\n }\n />\n <ResponsivePanel\n anchorWidth\n altAxis\n anchorRef={rootRef}\n open={showOptions}\n position={Position.BOTTOM}\n onClose={handleOnClick(false)}\n >\n {getOptions(isLargeScreen)}\n </ResponsivePanel>\n </>\n );\n}\n"],"names":["SelectOption","selected","undefined","options","onChange","placeholder","disabled","props","intl","useIntl","rootRef","useRef","showOptions","setShowOptions","useState","hasSelected","isLargeScreen","useScreenSize","Breakpoint","SMALL","inputAttributes","useInputAttributes","ariaLabelledBy","handleOnClick","showOptionsStatus","handleOnChange","data","getOptions","_jsx","className","clsx","children","map","optionsSection","index","_jsxs","Section","title","Header","NavigationOptionsList","option","NavigationOption","isContainerAligned","showMediaCircle","showMediaAtAllSizes","onClick","_Fragment","Option","ref","as","decision","media","Plus","size","content","button","type","ChevronDown","formatMessage","messages","selectedActionLabel","actionLabel","ResponsivePanel","anchorWidth","altAxis","anchorRef","open","position","Position","BOTTOM","onClose"],"mappings":";;;;;;;;;;;;;;;;;;;AA4CwB,SAAAA,YAAYA,CAAI;AACtCC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,OAAO;EACPC,QAAQ;EACRC,WAAW;EACXC,QAAQ;EACR,GAAGC,KAAAA;AACkB,CAAA,EAAA;AACrB,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE,CAAA;AACtB,EAAA,MAAMC,OAAO,GAAGC,YAAM,CAAC,IAAI,CAAC,CAAA;EAC5B,MAAM,CAACC,WAAW,EAAEC,cA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AAS;AACnB,QAAA,iBAAA,EAAiBgB,cAAe;AAChC,QAAA,eAAA,EAAc,QAAQ;AACtB,QAAA,eAAA,EAAeV,WAAY;AAC3BiB,QAAAA,SAAS,EAAEd,WAAW,GAAG,cAAc,GAAG,eAAgB;AAC1D,QAAA,YAAA,EAAYA,WAAW,GAAGb,SAAS,GAAGK,KAAK,CAAC,YAAY,CAAE;AAC1DsC,QAAAA,OAAO,EAAEtB,aAAa,CAAC,IAAI,CAAE;AAAAQ,QAAAA,QAAA,EAE5BhB,WAAW,gBACVa,cAAA,CAAC6B,iBAAW,EAAA;AAACpB,UAAAA,KAAK,EAAE7B,IAAI,CAACkD,aAAa,CAACC,qBAAQ,CAACC,mBAAmB,CAAA;AAAE,SAAA,CAAG,GAExEvD,WAAW,CAACwD,WAAW,IAAIrD,IAAI,CAACkD,aAAa,CAACC,qBAAQ,CAACE,WAAW,CAAA;OAE9D,CAAA;AACT,KAEH,CAAA,eAAAjC,cAAA,CAACkC,eAAe,EAAA;MACdC,WAAW,EAAA,IAAA;MACXC,OAAO,EAAA,IAAA;AACPC,MAAAA,SAAS,EAAEvD,OAAQ;AACnBwD,MAAAA,IAAI,EAAEtD,WAAY;MAClBuD,QAAQ,EAAEC,iBAAQ,CAACC,MAAO;AAC1BC,MAAAA,OAAO,EAAE/C,aAAa,CAAC,KAAK,CAAE;MAAAQ,QAAA,EAE7BJ,UAAU,CAACX,aAAa,CAAA;AAAC,KACX,CACnB,CAAA;AAAA,GAAA,CAAG,CAAA;AAEP;;;;"}
1
+ {"version":3,"file":"SelectOption.js","sources":["../../src/selectOption/SelectOption.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { ActionButtonProps } from '../actionButton';\nimport { clsx } from 'clsx';\nimport Option from '../common/Option';\nimport type { OptionProps } from '../common/Option/Option';\nimport { Breakpoint, Position } from '../common';\nimport Section from '../section';\nimport Header from '../header';\nimport { HeaderProps } from '../header/Header';\nimport NavigationOption from '../navigationOption';\nimport NavigationOptionsList from '../navigationOptionsList';\nimport { useInputAttributes } from '../inputs/contexts';\nimport messages from './SelectOption.messages';\nimport { useIntl } from 'react-intl';\nimport ResponsivePanel from '../common/responsivePanel';\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport { ChevronDown, Plus } from '@transferwise/icons';\n\nexport type SelectOptiopsSection<T = unknown> = {\n title?: HeaderProps['title'];\n options: SelectOptionValue<T>[];\n};\n\nexport type SelectOptionValue<T = unknown> = Pick<\n OptionProps,\n 'media' | 'title' | 'content' | 'disabled'\n> & {\n value?: T;\n};\n\nexport type SelectOptionPlaceholder = Pick<OptionProps, 'media' | 'title' | 'content'> & {\n actionLabel?: ActionButtonProps['children'];\n};\n\nexport type SelectOptionProps<T = unknown> = {\n onChange: (selected: SelectOptionValue<T>) => void;\n selected?: SelectOptionValue<T>;\n options: SelectOptiopsSection<T>[];\n placeholder: SelectOptionPlaceholder;\n} & Omit<\n OptionProps,\n 'as' | 'title' | 'media' | 'content' | 'onClick' | 'onChange' | 'showMediaAtAllSizes' | 'decision'\n>;\n\nexport default function SelectOption<T>({\n selected = undefined,\n options,\n onChange,\n placeholder,\n disabled,\n ...props\n}: SelectOptionProps<T>) {\n const intl = useIntl();\n const rootRef = useRef(null);\n const [showOptions, setShowOptions] = useState(false);\n\n const hasSelected = selected !== undefined;\n const isLargeScreen = useScreenSize(Breakpoint.SMALL);\n\n const inputAttributes = useInputAttributes();\n const ariaLabelledBy = props['aria-labelledby'] ?? inputAttributes?.['aria-labelledby'];\n\n function handleOnClick(showOptionsStatus: boolean) {\n return () => {\n setShowOptions(showOptionsStatus);\n };\n }\n\n function handleOnChange(data: SelectOptionValue<T>) {\n return () => {\n setShowOptions(false);\n onChange(data);\n };\n }\n\n function getOptions(isLargeScreen = false) {\n return (\n <div className={clsx({ 'np-select-option-list': isLargeScreen })}>\n {options.map((optionsSection, index) => (\n <Section key={index} className={clsx({ 'p-x-2 p-y-1': isLargeScreen })}>\n {optionsSection.title && <Header title={optionsSection.title} />}\n <NavigationOptionsList>\n {optionsSection.options.map((option, index) => {\n return (\n <NavigationOption\n key={index}\n isContainerAligned={!isLargeScreen}\n showMediaCircle\n showMediaAtAllSizes\n onClick={handleOnChange(option)}\n {...option}\n />\n );\n })}\n </NavigationOptionsList>\n </Section>\n ))}\n </div>\n );\n }\n\n return (\n <>\n <Option\n ref={rootRef}\n as=\"div\"\n showMediaAtAllSizes\n disabled={disabled}\n decision={false}\n media={hasSelected ? selected.media : (placeholder.media ?? <Plus size={24} />)}\n title={(hasSelected ? selected : placeholder).title}\n content={(hasSelected ? selected : placeholder).content}\n className={clsx(\n 'np-select-option',\n 'clickable',\n hasSelected ? 'np-select-option-selected' : 'np-select-option-placeholder',\n props.className,\n )}\n button={\n <button\n {...inputAttributes}\n type=\"button\"\n disabled={disabled}\n aria-labelledby={ariaLabelledBy}\n aria-haspopup=\"dialog\"\n aria-expanded={showOptions}\n className={hasSelected ? 'btn-unstyled' : 'np-action-btn'}\n aria-label={hasSelected ? undefined : props['aria-label']}\n onClick={handleOnClick(true)}\n >\n {hasSelected ? (\n <ChevronDown title={intl.formatMessage(messages.selectedActionLabel)} />\n ) : (\n placeholder.actionLabel || intl.formatMessage(messages.actionLabel)\n )}\n </button>\n }\n />\n <ResponsivePanel\n anchorWidth\n altAxis\n anchorRef={rootRef}\n open={showOptions}\n position={Position.BOTTOM}\n onClose={handleOnClick(false)}\n >\n {getOptions(isLargeScreen)}\n </ResponsivePanel>\n </>\n );\n}\n"],"names":["SelectOption","selected","undefined","options","onChange","placeholder","disabled","props","intl","useIntl","rootRef","useRef","showOptions","setShowOptions","useState","hasSelected","isLargeScreen","useScreenSize","Breakpoint","SMALL","inputAttributes","useInputAttributes","ariaLabelledBy","handleOnClick","showOptionsStatus","handleOnChange","data","getOptions","_jsx","className","clsx","children","map","optionsSection","index","_jsxs","Section","title","Header","NavigationOptionsList","option","NavigationOption","isContainerAligned","showMediaCircle","showMediaAtAllSizes","onClick","_Fragment","Option","ref","as","decision","media","Plus","size","content","button","type","ChevronDown","formatMessage","messages","selectedActionLabel","actionLabel","ResponsivePanel","anchorWidth","altAxis","anchorRef","open","position","Position","BOTTOM","onClose"],"mappings":";;;;;;;;;;;;;;;;;;;AA4CwB,SAAAA,YAAYA,CAAI;AACtCC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,OAAO;EACPC,QAAQ;EACRC,WAAW;EACXC,QAAQ;EACR,GAAGC,KAAAA;AACkB,CAAA,EAAA;AACrB,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE,CAAA;AACtB,EAAA,MAAMC,OAAO,GAAGC,YAAM,CAAC,IAAI,CAAC,CAAA;EAC5B,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC,CAAA;AAErD,EAAA,MAAMC,WAAW,GAAGd,QAAQ,KAAKC,SAAS,CAAA;AAC1C,EAAA,MAAMc,aAAa,GAAGC,2BAAa,CAACC,qBAAU,CAACC,KAAK,CAAC,CAAA;AAErD,EAAA,MAAMC,eAAe,GAAGC,2BAAkB,EAAE,CAAA;EAC5C,MAAMC,cAAc,GAAGf,KAAK,CAAC,iBAAiB,CAAC,IAAIa,eAAe,GAAG,iBAAiB,CAAC,CAAA;EAEvF,SAASG,aAAaA,CAACC,iBAA0B,EAAA;AAC/C,IAAA,OAAO,MAAK;MACVX,cAAc,CAACW,iBAAiB,CAAC,CAAA;KAClC,CAAA;AACH,GAAA;EAEA,SAASC,cAAcA,CAACC,IAA0B,EAAA;AAChD,IAAA,OAAO,MAAK;MACVb,cAAc,CAAC,KAAK,CAAC,CAAA;MACrBT,QAAQ,CAACsB,IAAI,CAAC,CAAA;KACf,CAAA;AACH,GAAA;AAEA,EAAA,SAASC,UAAUA,CAACX,aAAa,GAAG,KAAK,EAAA;AACvC,IAAA,oBACEY,cAAA,CAAA,KAAA,EAAA;MAAKC,SAAS,EAAEC,SAAI,CAAC;AAAE,QAAA,uBAAuB,EAAEd,aAAAA;AAAe,OAAA,CA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AAO,EAAE/C,aAAa,CAAC,KAAK,CAAE;MAAAQ,QAAA,EAE7BJ,UAAU,CAACX,aAAa,CAAA;AAAC,KACX,CACnB,CAAA;AAAA,GAAA,CAAG,CAAA;AAEP;;;;"}
@@ -2,7 +2,7 @@ import { useRef, useState } from 'react';
2
2
  import { clsx } from 'clsx';
3
3
  import Option from '../common/Option/Option.mjs';
4
4
  import Section from '../section/Section.mjs';
5
- import { Header } from '../header/Header.mjs';
5
+ import Header from '../header/Header.mjs';
6
6
  import NavigationOption from '../navigationOption/NavigationOption.mjs';
7
7
  import NavigationOptionList from '../navigationOptionsList/NavigationOptionsList.mjs';
8
8
  import { useInputAttributes } from '../inputs/contexts.mjs';