@iabbb/bds-react 0.38.6 → 0.39.0-alpha

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 (58) hide show
  1. package/Button/Button.d.ts +7 -0
  2. package/Button/index.cjs +115 -0
  3. package/Button/index.cjs.map +1 -0
  4. package/{src/Button/index.js → Button/index.d.ts} +2 -1
  5. package/Button/index.mjs +94 -0
  6. package/Button/index.mjs.map +1 -0
  7. package/Button/package.json +7 -0
  8. package/CallToAction/CallToAction.d.ts +6 -0
  9. package/CallToAction/index.cjs +83 -0
  10. package/CallToAction/index.cjs.map +1 -0
  11. package/{src/CallToAction/index.js → CallToAction/index.d.ts} +2 -1
  12. package/CallToAction/index.mjs +62 -0
  13. package/CallToAction/index.mjs.map +1 -0
  14. package/CallToAction/package.json +7 -0
  15. package/ErrorSummary/ErrorSummary.d.ts +14 -0
  16. package/ErrorSummary/index.cjs +194 -0
  17. package/ErrorSummary/index.cjs.map +1 -0
  18. package/{src/ErrorSummary/index.js → ErrorSummary/index.d.ts} +2 -2
  19. package/ErrorSummary/index.mjs +170 -0
  20. package/ErrorSummary/index.mjs.map +1 -0
  21. package/ErrorSummary/package.json +7 -0
  22. package/ErrorSummary/utils.d.ts +2 -0
  23. package/FieldTextInput/FieldTextInput.d.ts +10 -0
  24. package/FieldTextInput/index.cjs +109 -0
  25. package/FieldTextInput/index.cjs.map +1 -0
  26. package/{src/FieldTextInput/index.js → FieldTextInput/index.d.ts} +1 -1
  27. package/FieldTextInput/index.mjs +88 -0
  28. package/FieldTextInput/index.mjs.map +1 -0
  29. package/FieldTextInput/package.json +7 -0
  30. package/Pagination/Pagination.d.ts +8 -0
  31. package/Pagination/index.cjs +180 -0
  32. package/Pagination/index.cjs.map +1 -0
  33. package/{src/Pagination/index.js → Pagination/index.d.ts} +1 -1
  34. package/Pagination/index.mjs +159 -0
  35. package/Pagination/index.mjs.map +1 -0
  36. package/Pagination/package.json +7 -0
  37. package/README.md +17 -25
  38. package/Typography/Typography.d.ts +7 -0
  39. package/Typography/index.cjs +99 -0
  40. package/Typography/index.cjs.map +1 -0
  41. package/{src/Typography/index.js → Typography/index.d.ts} +1 -1
  42. package/Typography/index.mjs +78 -0
  43. package/Typography/index.mjs.map +1 -0
  44. package/Typography/package.json +7 -0
  45. package/index.cjs +447 -0
  46. package/index.cjs.map +1 -0
  47. package/index.d.ts +6 -0
  48. package/index.mjs +421 -0
  49. package/index.mjs.map +1 -0
  50. package/package.json +35 -21
  51. package/src/Button/Button.js +0 -54
  52. package/src/CallToAction/CallToAction.js +0 -16
  53. package/src/ErrorSummary/ErrorSummary.js +0 -102
  54. package/src/ErrorSummary/utils.js +0 -42
  55. package/src/FieldTextInput/FieldTextInput.js +0 -46
  56. package/src/Pagination/Pagination.js +0 -101
  57. package/src/Typography/Typography.js +0 -26
  58. package/src/index.js +0 -6
@@ -1,102 +0,0 @@
1
- import * as React from 'react';
2
-
3
- import { getAssociatedLegendOrLabel, getFragmentFromUrl } from './utils';
4
-
5
- export const FormErrorKey = '_form';
6
-
7
- const FINAL_FORM_ERROR = 'FINAL_FORM/form-error';
8
-
9
- export default function BdsErrorSummary({ className, errors, mapNameToId = (name) => name, ...props }) {
10
- const headingId = React.useId();
11
- const groupRef = React.useRef(null);
12
-
13
- React.useEffect(() => {
14
- if (!errors || Object.keys(errors).length === 0) return;
15
- if (!groupRef.current) return;
16
-
17
- groupRef.current.focus();
18
- }, [errors]);
19
-
20
- if (!errors || Object.keys(errors).length === 0) return null;
21
-
22
- const handleLinkClick = (e) => {
23
- const inputId = getFragmentFromUrl(e.currentTarget.href);
24
-
25
- if (!inputId) {
26
- return;
27
- }
28
-
29
- const input = document.getElementById(inputId);
30
-
31
- if (!input) {
32
- return;
33
- }
34
-
35
- const legendOrLabel = getAssociatedLegendOrLabel(input);
36
-
37
- if (!legendOrLabel) {
38
- return;
39
- }
40
-
41
- e.preventDefault();
42
-
43
- legendOrLabel.scrollIntoView();
44
- input.focus({ preventScroll: true });
45
- };
46
-
47
- return (
48
- <bds-error-summary
49
- className={['stack', className].filter((x) => x).join(' ')}
50
- role="group"
51
- aria-labelledby={headingId}
52
- ref={groupRef}
53
- tabIndex={-1}
54
- {...props}
55
- >
56
- <h2 className="bds-h5" id={headingId}>
57
- <svg
58
- xmlns="http://www.w3.org/2000/svg"
59
- viewBox="0 0 512 512"
60
- aria-hidden="true"
61
- height="1em"
62
- width="1em"
63
- fill="currentColor"
64
- >
65
- <path d="M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z" />
66
- </svg>
67
- Issue
68
- </h2>
69
- <ul>
70
- {Object.keys(errors).map((errorKey) => {
71
- const message = errors[errorKey];
72
- const isFormError = [FINAL_FORM_ERROR, FormErrorKey].includes(errorKey);
73
-
74
- if (isFormError) {
75
- return <li key={errorKey} dangerouslySetInnerHTML={{ __html: message }} />;
76
- }
77
-
78
- const isArrayField = Array.isArray(message);
79
-
80
- const messages = isArrayField ? message : [message];
81
-
82
- return (
83
- <React.Fragment key={errorKey}>
84
- {messages.map((fieldMessage, index) => {
85
- const inputId = `${mapNameToId(errorKey)}${isArrayField ? `[${index}]` : ''}`;
86
-
87
- return (
88
- <li key={inputId}>
89
- <a href={`#${inputId}`} onClick={handleLinkClick}>
90
- {fieldMessage}
91
- {messages.length > 1 ? ` (${index + 1} of ${messages.length})` : undefined}
92
- </a>
93
- </li>
94
- );
95
- })}
96
- </React.Fragment>
97
- );
98
- })}
99
- </ul>
100
- </bds-error-summary>
101
- );
102
- }
@@ -1,42 +0,0 @@
1
- export function getFragmentFromUrl(url) {
2
- return url.includes('#') ? url.split('#').pop() : undefined;
3
- }
4
-
5
- export function getAssociatedLegendOrLabel(input) {
6
- const fieldset = input.closest('fieldset');
7
-
8
- if (fieldset) {
9
- const legends = fieldset.getElementsByTagName('legend');
10
-
11
- if (legends.length) {
12
- const candidateLegend = legends[0];
13
-
14
- // If the input type is radio or checkbox, always use the legend if there
15
- // is one.
16
- if (input instanceof HTMLInputElement && (input.type === 'checkbox' || input.type === 'radio')) {
17
- return candidateLegend;
18
- }
19
-
20
- // For other input types, only scroll to the fieldset’s legend (instead of
21
- // the label associated with the input) if the input would end up in the
22
- // top half of the screen.
23
- //
24
- // This should avoid situations where the input either ends up off the
25
- // screen, or obscured by a software keyboard.
26
- const legendTop = candidateLegend.getBoundingClientRect().top;
27
- const inputRect = input.getBoundingClientRect();
28
-
29
- // If the browser doesn't support Element.getBoundingClientRect().height
30
- // or window.innerHeight (like IE8), bail and just link to the label.
31
- if (inputRect.height && window.innerHeight) {
32
- const inputBottom = inputRect.top + inputRect.height;
33
-
34
- if (inputBottom - legendTop < window.innerHeight / 2) {
35
- return candidateLegend;
36
- }
37
- }
38
- }
39
- }
40
-
41
- return document.querySelector(`label[for='${input.getAttribute('id')}']`) ?? input.closest('label');
42
- }
@@ -1,46 +0,0 @@
1
- import * as React from 'react';
2
-
3
- export default function FieldTextInput({ as, error, hint, id, isOptional = false, label, ...props }) {
4
- id = id ?? props.name;
5
-
6
- const errorId = React.useId();
7
- const hintId = React.useId();
8
-
9
- const InputComponent = as ?? 'input';
10
-
11
- return (
12
- <div className="bds-text-input stack">
13
- <label htmlFor={id}>
14
- {label}
15
- {isOptional && ' (optional)'}
16
- </label>
17
- {hint && (
18
- <span className="bds-hint" id={hintId}>
19
- {hint}
20
- </span>
21
- )}
22
- {error && (
23
- <span className="bds-error" id={errorId}>
24
- <svg
25
- xmlns="http://www.w3.org/2000/svg"
26
- viewBox="0 0 512 512"
27
- aria-hidden="true"
28
- height="1em"
29
- width="1em"
30
- fill="currentColor"
31
- >
32
- <path d="M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z" />
33
- </svg>
34
- {error}
35
- </span>
36
- )}
37
- <InputComponent
38
- aria-invalid={error ? true : undefined}
39
- aria-describedby={error && hint ? `${hintId} ${errorId}` : error ? errorId : hint ? hintId : undefined}
40
- aria-required={isOptional ? undefined : true}
41
- id={id}
42
- {...props}
43
- />
44
- </div>
45
- );
46
- }
@@ -1,101 +0,0 @@
1
- import * as React from 'react';
2
-
3
- function usePages(currentPage, totalPages) {
4
- const pages = [1, currentPage - 1, currentPage, currentPage + 1, totalPages].filter(
5
- (x) => x >= 1 && x <= totalPages,
6
- );
7
- return [...new Set(pages)];
8
- }
9
-
10
- export default function Pagination({ buildPageUrl, className, currentPage, onPageClick, totalPages, ...props }) {
11
- const pages = usePages(currentPage, totalPages);
12
-
13
- return (
14
- <nav aria-label="pagination" className={['bds-pagination', className].filter((x) => x).join(' ')} {...props}>
15
- {currentPage !== 1 && (
16
- <>
17
- <a href={buildPageUrl(1)} className="bds-first-page">
18
- <svg
19
- xmlns="http://www.w3.org/2000/svg"
20
- aria-hidden="true"
21
- focusable="false"
22
- height="1em"
23
- width="100%"
24
- viewBox="0 63.95 512 384.1"
25
- >
26
- <path d="M459.5 440.6c9.5 7.9 22.8 9.7 34.1 4.4s18.4-16.6 18.4-29V96c0-12.4-7.2-23.7-18.4-29s-24.5-3.6-34.1 4.4L288 214.3v83.4l171.5 142.9zM256 352V96c0-12.4-7.2-23.7-18.4-29s-24.5-3.6-34.1 4.4l-192 160C4.2 237.5 0 246.5 0 256s4.2 18.5 11.5 24.6l192 160c9.5 7.9 22.8 9.7 34.1 4.4s18.4-16.6 18.4-29v-64z" />
27
- </svg>
28
- First
29
- </a>
30
- <a aria-label="previous" href={buildPageUrl(currentPage - 1)} rel="prev">
31
- <svg
32
- xmlns="http://www.w3.org/2000/svg"
33
- aria-hidden="true"
34
- focusable="false"
35
- width="100%"
36
- height="1em"
37
- viewBox="0.02 95.9 192.08 320.17"
38
- >
39
- <path d="M9.4 278.6c-12.5-12.5-12.5-32.8 0-45.3l128-128c9.2-9.2 22.9-11.9 34.9-6.9s19.8 16.6 19.8 29.6v256c0 12.9-7.8 24.6-19.8 29.6s-25.7 2.2-34.9-6.9l-128-128z" />
40
- </svg>
41
- Prev.
42
- </a>
43
- </>
44
- )}
45
- <ul>
46
- {pages.map((page, index) => {
47
- const handlePageClick = () => {
48
- if (!onPageClick) return;
49
-
50
- onPageClick(page);
51
- };
52
-
53
- return (
54
- <React.Fragment key={page}>
55
- <li>
56
- <a
57
- aria-current={page === currentPage ? 'page' : undefined}
58
- href={buildPageUrl(page)}
59
- onClick={handlePageClick}
60
- >
61
- <span className="visually-hidden">Page</span> {page}
62
- </a>
63
- </li>
64
- {pages[index + 1] > page + 1 ? <li data-overflow="">...</li> : null}
65
- </React.Fragment>
66
- );
67
- })}
68
- </ul>
69
- {currentPage !== totalPages && (
70
- <>
71
- <a href={buildPageUrl(currentPage + 1)} rel="next">
72
- Next
73
- <svg
74
- xmlns="http://www.w3.org/2000/svg"
75
- aria-hidden="true"
76
- focusable="false"
77
- viewBox="63.9 95.9 192.1 320.17"
78
- width="100%"
79
- height="1em"
80
- >
81
- <path d="M246.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-128-128c-9.2-9.2-22.9-11.9-34.9-6.9S63.9 115 63.9 128v256c0 12.9 7.8 24.6 19.8 29.6s25.7 2.2 34.9-6.9l128-128z" />
82
- </svg>
83
- </a>
84
- <a href={buildPageUrl(totalPages)} className="bds-last-page">
85
- Last
86
- <svg
87
- xmlns="http://www.w3.org/2000/svg"
88
- aria-hidden="true"
89
- focusable="false"
90
- width="100%"
91
- height="1em"
92
- viewBox="0 63.95 512 384.1"
93
- >
94
- <path d="M52.5 440.6c-9.5 7.9-22.8 9.7-34.1 4.4S0 428.4 0 416V96c0-12.4 7.2-23.7 18.4-29s24.5-3.6 34.1 4.4L224 214.3v83.4L52.5 440.6zM256 352V96c0-12.4 7.2-23.7 18.4-29s24.5-3.6 34.1 4.4l192 160c7.3 6.1 11.5 15.1 11.5 24.6s-4.2 18.5-11.5 24.6l-192 160c-9.5 7.9-22.8 9.7-34.1 4.4S256 428.4 256 416v-64z" />
95
- </svg>
96
- </a>
97
- </>
98
- )}
99
- </nav>
100
- );
101
- }
@@ -1,26 +0,0 @@
1
- import * as React from 'react';
2
-
3
- const componentMap = {
4
- h1: 'h1',
5
- h2: 'h2',
6
- h3: 'h3',
7
- h4: 'h4',
8
- h5: 'h5',
9
- body: 'p',
10
- };
11
-
12
- const classMap = {
13
- h1: 'bds-h1',
14
- h2: 'bds-h2',
15
- h3: 'bds-h3',
16
- h4: 'bds-h4',
17
- h5: 'bds-h5',
18
- body: 'bds-body',
19
- };
20
-
21
- const Typography = React.forwardRef(({ className, component, variant = 'body', ...props }, ref) => {
22
- const Component = component ?? componentMap[variant];
23
- return <Component className={[classMap[variant], className].filter((x) => x).join(' ')} ref={ref} {...props} />;
24
- });
25
-
26
- export default Typography;
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- export { default as Button } from './Button/index';
2
- export { default as CallToAction } from './CallToAction/index';
3
- export { default as ErrorSummary } from './ErrorSummary/index';
4
- export { default as FieldTextInput } from './FieldTextInput/index';
5
- export { default as Pagination } from './Pagination/index';
6
- export { default as Typography } from './Typography/index';