@uncinc/uncinc-react-kitchen-sink 2.18.0 → 2.19.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.
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface AccessibleLinkDescriptionProps {
3
+ id: string;
4
+ }
5
+ declare const AccessibleLinkDescription: React.FC<AccessibleLinkDescriptionProps>;
6
+ export default AccessibleLinkDescription;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ var AccessibleLinkDescription = function AccessibleLinkDescription(_ref) {
4
+ var id = _ref.id;
5
+ var _useTranslation = useTranslation(),
6
+ t = _useTranslation.t;
7
+ return /*#__PURE__*/React.createElement("span", {
8
+ className: "visually-hidden",
9
+ id: id
10
+ }, t(['atoms.accessible_link_description', 'Opens in a new tab']));
11
+ };
12
+ export default AccessibleLinkDescription;
@@ -6,9 +6,11 @@ import React from 'react';
6
6
  import { Link } from 'react-router-dom';
7
7
  import PropTypes from 'prop-types';
8
8
  import classNames from 'classnames';
9
+ import { v4 as uuidv4 } from 'uuid';
9
10
  import gtm from '../../helpers/gtm';
10
11
  import { isExternalLink, isHashLink } from '../../helpers/link';
11
12
  import withMapping from '../../Context/withMapping';
13
+ import AccessibleLinkDescription from '../AccessibleLinkDescription';
12
14
  import './style.scss';
13
15
  export var Button = function Button(_ref) {
14
16
  var href = _ref.href,
@@ -24,6 +26,7 @@ export var Button = function Button(_ref) {
24
26
  target = _ref.target,
25
27
  forwardRef = _ref.forwardRef,
26
28
  props = _objectWithoutProperties(_ref, _excluded);
29
+ var accessibleLinkDescriptionId = "accessible-link-description-".concat(uuidv4());
27
30
  var classes = classNames('Button', className, {
28
31
  'Button--primary': primary,
29
32
  'Button--inverted': inverted,
@@ -46,8 +49,7 @@ export var Button = function Button(_ref) {
46
49
  // eslint-disable-next-line react/button-has-type
47
50
  React.createElement("button", _extends({
48
51
  type: htmlType,
49
- className: classes,
50
- href: href
52
+ className: classes
51
53
  }, props, {
52
54
  ref: forwardRef,
53
55
  onClick: onClick
@@ -55,35 +57,44 @@ export var Button = function Button(_ref) {
55
57
  );
56
58
  }
57
59
  if (isExternalLink(href)) {
58
- return /*#__PURE__*/React.createElement("a", _extends({
60
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", _extends({
59
61
  className: classes,
60
62
  href: href,
61
63
  target: "_blank",
62
64
  rel: "noreferrer noopener"
63
65
  }, props, {
64
66
  ref: forwardRef,
65
- onClick: onClick
66
- }), children);
67
+ onClick: onClick,
68
+ "aria-describedby": accessibleLinkDescriptionId
69
+ }), children), /*#__PURE__*/React.createElement(AccessibleLinkDescription, {
70
+ id: accessibleLinkDescriptionId
71
+ }));
67
72
  }
68
73
  if (isHashLink(href)) {
69
- return /*#__PURE__*/React.createElement("a", _extends({
74
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", _extends({
70
75
  className: classes,
71
76
  href: href,
72
77
  target: target,
73
78
  rel: "noreferrer noopener"
74
79
  }, props, {
75
80
  ref: forwardRef,
76
- onClick: onClick
77
- }), children);
81
+ onClick: onClick,
82
+ "aria-describedby": target === '_blank' ? accessibleLinkDescriptionId : undefined
83
+ }), children), target === '_blank' && /*#__PURE__*/React.createElement(AccessibleLinkDescription, {
84
+ id: accessibleLinkDescriptionId
85
+ }));
78
86
  }
79
- return /*#__PURE__*/React.createElement(Link, _extends({
87
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Link, _extends({
80
88
  to: href,
81
89
  className: classes,
82
90
  target: target
83
91
  }, props, {
84
92
  ref: forwardRef,
85
- onClick: onClick
86
- }), children);
93
+ onClick: onClick,
94
+ "aria-describedby": target === '_blank' ? accessibleLinkDescriptionId : undefined
95
+ }), children), target === '_blank' && /*#__PURE__*/React.createElement(AccessibleLinkDescription, {
96
+ id: accessibleLinkDescriptionId
97
+ }));
87
98
  };
88
99
  Button.defaultProps = {
89
100
  primary: true,
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { default as Accordion } from "./components/Accordion";
3
3
  export { default as AccordionItem } from "./components/Accordion/AccordionItem";
4
4
  export { default as AccordionItemVariant } from "./components/Accordion/AccordionItemVariant";
5
5
  export { default as Button } from "./components/Button";
6
+ export { default as AccessibleLinkDescription } from "./components/AccessibleLinkDescription";
6
7
  export { default as Hamburger } from "./components/Hamburger";
7
8
  export { default as Image } from "./components/Image";
8
9
  export { default as Icon } from "./components/Icon";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { default as Accordion } from './components/Accordion';
4
4
  export { default as AccordionItem } from './components/Accordion/AccordionItem';
5
5
  export { default as AccordionItemVariant } from './components/Accordion/AccordionItemVariant';
6
6
  export { default as Button } from './components/Button';
7
+ export { default as AccessibleLinkDescription } from './components/AccessibleLinkDescription';
7
8
  export { default as Hamburger } from './components/Hamburger';
8
9
  export { default as Image } from './components/Image';
9
10
  export { default as Icon } from './components/Icon';
@@ -16,4 +16,11 @@ jest.mock('react-i18next', function () {
16
16
  };
17
17
  }
18
18
  };
19
+ });
20
+ jest.mock('uuid', function () {
21
+ return {
22
+ v4: function v4() {
23
+ return '123e4567-e89b-12d3-a456-426614174000';
24
+ }
25
+ };
19
26
  });
@@ -6,6 +6,18 @@
6
6
  display: none !important;
7
7
  }
8
8
 
9
+ .visually-hidden {
10
+ position: absolute;
11
+ overflow: hidden;
12
+ width: 1px;
13
+ height: 1px;
14
+ margin: -1px;
15
+ padding: 0;
16
+ white-space: nowrap;
17
+ clip: rect(0, 0, 0, 0);
18
+ border: 0;
19
+ }
20
+
9
21
  html {
10
22
  font-size: 62.5%;
11
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",