@cfpb/cfpb-design-system 5.2.0 → 5.3.1

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 (67) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/dist/index.css +1 -1
  3. package/dist/index.js +1771 -1715
  4. package/package.json +1 -1
  5. package/src/elements/abstracts/custom-props.css +2 -1
  6. package/src/elements/abstracts/vars.css +1 -6
  7. package/src/elements/base/base.scss +3 -0
  8. package/src/elements/base/font.scss +1 -1
  9. package/src/elements/cfpb-button/cfpb-button.scss +1 -1
  10. package/src/elements/cfpb-button/index.js +3 -4
  11. package/src/elements/cfpb-checkbox-icon/index.js +3 -3
  12. package/src/elements/cfpb-expandable/index.js +10 -12
  13. package/src/elements/cfpb-expandable/{cfpb-expandable.component.scss → styles.component.scss} +1 -1
  14. package/src/elements/cfpb-file-upload/index.js +3 -6
  15. package/src/elements/cfpb-file-upload/styles.component.css +7 -0
  16. package/src/elements/cfpb-flag-usa/index.js +3 -3
  17. package/src/elements/cfpb-flag-usa/{cfpb-flag-usa.component.scss → styles.component.css} +2 -2
  18. package/src/elements/cfpb-form-alert/index.js +24 -15
  19. package/src/elements/cfpb-form-alert/styles.component.scss +14 -0
  20. package/src/elements/cfpb-form-choice/index.js +3 -4
  21. package/src/elements/cfpb-form-choice/{cfpb-form-choice.component.scss → styles.component.scss} +5 -6
  22. package/src/elements/cfpb-form-search/index.js +8 -8
  23. package/src/elements/cfpb-form-search/skeleton.css +8 -0
  24. package/src/elements/cfpb-form-search/{cfpb-form-search.component.scss → styles.component.scss} +3 -3
  25. package/src/elements/cfpb-form-search-input/index.js +7 -14
  26. package/src/elements/cfpb-form-search-input/{cfpb-form-search-input.component.scss → styles.component.scss} +6 -8
  27. package/src/elements/cfpb-icon/index.js +45 -0
  28. package/src/elements/cfpb-icon/styles.component.css +48 -0
  29. package/src/elements/cfpb-icon-text/index.js +3 -3
  30. package/src/elements/cfpb-icon-text/{cfpb-icon-text.component.scss → styles.component.scss} +2 -3
  31. package/src/elements/cfpb-label/index.js +3 -3
  32. package/src/elements/cfpb-label/{cfpb-label.component.scss → styles.component.scss} +5 -5
  33. package/src/elements/{cfpb-list → cfpb-listbox}/index.js +13 -10
  34. package/src/elements/{cfpb-list → cfpb-listbox}/index.spec.js +9 -9
  35. package/src/elements/{cfpb-list/cfpb-list.component.scss → cfpb-listbox/styles.component.scss} +1 -5
  36. package/src/elements/{cfpb-list-item → cfpb-listbox-item}/index.js +5 -7
  37. package/src/elements/{cfpb-list-item/cfpb-list-item.component.scss → cfpb-listbox-item/styles.component.scss} +2 -2
  38. package/src/elements/cfpb-pagination/index.js +10 -10
  39. package/src/elements/cfpb-pagination/{cfpb-pagination.component.scss → styles.component.scss} +6 -6
  40. package/src/elements/cfpb-select/index.js +11 -15
  41. package/src/elements/cfpb-select/multiple-select-event-proxy.js +2 -2
  42. package/src/elements/cfpb-select/single-select-event-proxy.js +1 -1
  43. package/src/elements/cfpb-select/{cfpb-select.component.scss → styles.component.scss} +5 -6
  44. package/src/elements/cfpb-tag-filter/index.js +3 -4
  45. package/src/elements/cfpb-tag-filter/{cfpb-tag-filter.component.scss → styles.component.scss} +6 -8
  46. package/src/elements/cfpb-tag-group/index.js +3 -3
  47. package/src/elements/cfpb-tag-group/{cfpb-tag-group.component.scss → styles.component.scss} +3 -4
  48. package/src/elements/cfpb-tag-topic/index.js +3 -4
  49. package/src/elements/cfpb-tag-topic/{cfpb-tag-topic.component.scss → styles.component.scss} +2 -2
  50. package/src/elements/cfpb-tagline/index.js +4 -5
  51. package/src/elements/cfpb-tagline/skeleton.css +7 -0
  52. package/src/elements/cfpb-tagline/{cfpb-tagline.component.scss → styles.component.scss} +3 -4
  53. package/src/elements/cfpb-utilities/fallback/wc-fallback.css +31 -0
  54. package/src/elements/cfpb-utilities/fallback/wc-fallback.js +65 -0
  55. package/src/elements/cfpb-utilities/shared-config.js +52 -0
  56. package/src/elements/cfpb-utilities/skeleton.css +33 -0
  57. package/src/elements/cfpb-utilities/transition/{transition.scss → transition.css} +11 -11
  58. package/src/elements/index.js +11 -2
  59. package/src/index.js +1 -5
  60. package/src/index.scss +1 -1
  61. package/src/tokens/abstracts/custom-props.json +13 -1
  62. package/src/utilities/functions.scss +20 -0
  63. package/src/elements/base/index.js +0 -2
  64. package/src/elements/cfpb-file-upload/cfpb-file-upload.component.scss +0 -10
  65. package/src/elements/cfpb-form-alert/cfpb-form-alert.component.scss +0 -36
  66. /package/src/elements/cfpb-button/{cfpb-button.component.scss → styles.component.scss} +0 -0
  67. /package/src/elements/cfpb-checkbox-icon/{cfpb-checkbox-icon.component.scss → styles.component.scss} +0 -0
@@ -1,9 +1,8 @@
1
- @use 'sass:math';
2
- @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
1
+ @use '../../utilities/functions' as *;
3
2
 
4
3
  :host {
5
4
  .a-tagline {
6
- font-size: math.div(12px, $base-font-size-px) + rem;
5
+ font-size: rem-from-px(12px);
7
6
 
8
7
  display: grid;
9
8
  grid-template-columns: 22px 1fr;
@@ -19,7 +18,7 @@
19
18
  }
20
19
 
21
20
  &--large {
22
- font-size: math.div(16px, $base-font-size-px) + rem;
21
+ font-size: rem-from-px(16px);
23
22
 
24
23
  & cfpb-flag-usa {
25
24
  margin-top: 4px;
@@ -0,0 +1,31 @@
1
+ /*
2
+ This fallback CSS assumes a web component that contains a <noscript> fallback,
3
+ as well as author-supplied content, and separately has a script to swap the
4
+ <noscript> with `<div class="fallback">` if JS is enabled, but the web component
5
+ definition is not defined.
6
+
7
+ Ex.
8
+
9
+ <cfpb-example-btn hasfallback>
10
+ <!-- author-supplied no-js fallback -->
11
+ <noscript><button>Click this basic button!</button>
12
+
13
+ <!-- author-supplied slotted content -->
14
+ Click this fancy button!
15
+ </cfpb-example-btn>
16
+ */
17
+
18
+ /* 1. If JS is disabled, hide everything except <noscript> */
19
+ [hasfallback] > :not(noscript) {
20
+ display: none;
21
+ }
22
+
23
+ /* 2. If JS is enabled, but web component definition is not defined, show fallback. */
24
+ [hasfallback] > .fallback {
25
+ display: block;
26
+ }
27
+
28
+ /* 3. If JS is enabled and web component definition is defined, operate as normal. */
29
+ [hasfallback]:defined > :not(noscript) {
30
+ display: block;
31
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * This utility IIFE function can be added to a page with web components
3
+ * to support the display of any fallback content in `<noscript>` tags
4
+ * that would otherwise not appear if JavaScript was enabled, but
5
+ * the Web Component APIs were not supported.
6
+ */
7
+ (function () {
8
+ /**
9
+ * Within a custom element (web component),
10
+ * convert any `<noscript>` tags into `<div class="fallback">`,
11
+ * so that the fallback content appears in environments where
12
+ * JavaScript is enabled, but web component APIs are not supported.
13
+ * @param {HTMLElement} el - A custom element.
14
+ */
15
+ function applyFallback(el) {
16
+ if (!el) return;
17
+
18
+ const tag = el.tagName.toLowerCase();
19
+ const isDefined = !!customElements.get(tag);
20
+ const noscript = el.querySelector('noscript');
21
+
22
+ // Only act if the element is NOT defined and there is a <noscript>
23
+ if (!isDefined && noscript) {
24
+ // Create a <div> with the fallback content.
25
+ const fallbackDiv = document.createElement('div');
26
+ fallbackDiv.className = 'fallback';
27
+ fallbackDiv.innerHTML = noscript.innerHTML;
28
+
29
+ // Insert fallback at the top.
30
+ el.insertBefore(fallbackDiv, el.firstChild);
31
+
32
+ // Hide the original <noscript> to avoid duplicates.
33
+ noscript.style.display = 'none';
34
+
35
+ /*
36
+ // Hide other non-fallback children (optional; wc-fallback.css handles this).
37
+ Array.from(el.children).forEach((child) => {
38
+ if (child !== fallbackDiv && child !== noscript) {
39
+ child.style.display = 'none';
40
+ }
41
+ });
42
+ */
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Query the document for custom elements that have the "fallback" attribute,
48
+ * e.g. <my-custom-btn fallback>
49
+ * @param {string} selector - The CSS selector to search for on the page.
50
+ */
51
+ function applyAllFallbacks(selector = '[fallback]') {
52
+ document.querySelectorAll(selector).forEach((el) => applyFallback(el));
53
+ }
54
+
55
+ // Check for browser support of the Web Component APIs.
56
+ const supportsWC =
57
+ 'customElements' in window &&
58
+ 'attachShadow' in Element.prototype &&
59
+ 'content' in document.createElement('template');
60
+
61
+ // Only run the fallback utility script globally if web components are NOT supported.
62
+ if (!supportsWC) {
63
+ document.addEventListener('DOMContentLoaded', applyAllFallbacks);
64
+ }
65
+ })();
@@ -0,0 +1,52 @@
1
+ const DEFAULT_CONFIG = {
2
+ iconPath: './icons/',
3
+ };
4
+
5
+ let config = { ...DEFAULT_CONFIG };
6
+ let initialized = false;
7
+
8
+ const ALLOWED_KEYS = Object.keys(DEFAULT_CONFIG);
9
+
10
+ /**
11
+ * Set the shared configuration for the project.
12
+ * @param {object} userConfig - User supplied settings that override DEFAULT_CONFIG settings.
13
+ */
14
+ export function setSharedConfig(userConfig) {
15
+ if (initialized) {
16
+ // eslint-disable-next-line no-console
17
+ console.warn('CFPB Design System config already initialized');
18
+ return;
19
+ }
20
+
21
+ for (const key of Object.keys(userConfig)) {
22
+ if (!ALLOWED_KEYS.includes(key)) {
23
+ // eslint-disable-next-line no-console
24
+ console.warn(`CFPB Design System invalid config key: ${key}`);
25
+ }
26
+ }
27
+
28
+ config = {
29
+ ...config,
30
+ ...userConfig,
31
+ };
32
+
33
+ initialized = true;
34
+ }
35
+
36
+ /**
37
+ * @returns {object} The shared config used in the project.
38
+ */
39
+ export function getSharedConfig() {
40
+ return config;
41
+ }
42
+
43
+ /**
44
+ * Check if a custom element is registered, and if not, define it on the globalThis (window).
45
+ * @param {string} tag - A custom element's tag as it appears in markup.
46
+ * @param {HTMLElement} constructor - A custom element constructor.
47
+ */
48
+ export function defineComponent(tag, constructor) {
49
+ if (!globalThis.customElements.get(tag)) {
50
+ globalThis.customElements.define(tag, constructor);
51
+ }
52
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ This file defines a "loading skeleton", which is a wireframe-esque box that loads
3
+ in before a web component has been initialized.
4
+
5
+ Each component that has a loading skeleton also has a file similar to this one,
6
+ which defines the dimensions of the box that should load.
7
+
8
+ Having a loading skeleton avoids a layout shift when the component is actually
9
+ initialized and rendered.
10
+ */
11
+ *:not(:defined) {
12
+ display: block;
13
+ width: 100%;
14
+
15
+ box-shadow: 0 0 3px rgb(90, 93, 97, 10%) inset;
16
+ border-radius: 4px;
17
+
18
+ animation: pulse-background 1.5s infinite;
19
+ }
20
+
21
+ @keyframes pulse-background {
22
+ 0% {
23
+ background-color: transparent;
24
+ }
25
+
26
+ 50% {
27
+ background-color: rgb(90, 93, 97, 5%);
28
+ }
29
+
30
+ 100% {
31
+ background-color: transparent;
32
+ }
33
+ }
@@ -9,9 +9,9 @@
9
9
  transition-duration: 0s !important;
10
10
  }
11
11
 
12
- //
13
- // Utility classes for moving an element using transform translate values.
14
- //
12
+ /**
13
+ * Utility classes for moving an element using transform translate values.
14
+ */
15
15
 
16
16
  .u-move-transition {
17
17
  transition: transform 0.25s ease-out;
@@ -25,7 +25,7 @@
25
25
  transform: translate3d(-100%, 0, 0);
26
26
  }
27
27
 
28
- // TODO: Look into adding a mixin for movement multiples.
28
+ /* TODO: Look into adding a mixin for movement multiples. */
29
29
  .u-move-left-2x {
30
30
  transform: translate3d(-200%, 0, 0);
31
31
  }
@@ -42,9 +42,9 @@
42
42
  transform: translate3d(0, -100%, 0);
43
43
  }
44
44
 
45
- //
46
- // Utility classes for setting an element's opacity.
47
- //
45
+ /**
46
+ * Utility classes for setting an element's opacity.
47
+ */
48
48
 
49
49
  .u-alpha-transition {
50
50
  transition: opacity 0.25s linear;
@@ -58,15 +58,15 @@
58
58
  opacity: 0;
59
59
  }
60
60
 
61
- //
62
- // Utility classes for setting an element's height.
63
- //
61
+ /**
62
+ * Utility classes for setting an element's height.
63
+ */
64
64
 
65
65
  .u-max-height-transition {
66
66
  overflow: hidden;
67
67
  contain: paint;
68
68
 
69
- // Duration is set here, but it is actually overridden in the JavaScript.
69
+ /* Duration is set here, but it is actually overridden in the JavaScript. */
70
70
  transition: max-height 0.2s ease-out;
71
71
  }
72
72
 
@@ -3,14 +3,23 @@
3
3
  ========================================================================== */
4
4
 
5
5
  // TODO: aggregate and export the component subdirectories automatically.
6
+
7
+ // Base styles.
8
+ export * from './abstracts';
9
+
10
+ // Shared config.
11
+ export * from './cfpb-utilities/shared-config';
12
+
13
+ // Component styles.
6
14
  export * from './cfpb-button';
7
15
  export * from './cfpb-form-alert';
8
16
  export * from './cfpb-expandable';
9
17
  export * from './cfpb-form-choice';
10
18
  export * from './cfpb-file-upload';
19
+ export * from './cfpb-icon';
11
20
  export * from './cfpb-label';
12
- export * from './cfpb-list';
13
- export * from './cfpb-list-item';
21
+ export * from './cfpb-listbox';
22
+ export * from './cfpb-listbox-item';
14
23
  export * from './cfpb-form-search';
15
24
  export * from './cfpb-form-search-input';
16
25
  export * from './cfpb-tagline';
package/src/index.js CHANGED
@@ -2,9 +2,7 @@
2
2
  Design System
3
3
  ========================================================================== */
4
4
 
5
- export * from './elements/abstracts';
6
-
7
- export * from './elements/base';
5
+ export * from './elements';
8
6
 
9
7
  export * from './components/cfpb-buttons';
10
8
  export * from './components/cfpb-expandables';
@@ -17,5 +15,3 @@ export * from './components/cfpb-tables';
17
15
  export * from './components/cfpb-typography';
18
16
 
19
17
  export * from './utilities';
20
-
21
- export * from './elements';
package/src/index.scss CHANGED
@@ -74,4 +74,4 @@
74
74
  @forward 'elements/cfpb-button/vars';
75
75
 
76
76
  // cfpb-icon-text
77
- @forward 'elements/cfpb-icon-text/cfpb-icon-text.component';
77
+ @forward 'elements/cfpb-icon-text/styles.component';
@@ -2321,7 +2321,7 @@
2321
2321
  },
2322
2322
  "font-stack": {
2323
2323
  "$type": "string",
2324
- "$value": "system-ui,sans-serif",
2324
+ "$value": "var(--font-stack-branded, system-ui, sans-serif)",
2325
2325
  "$extensions": {
2326
2326
  "com.figma.variableId": "VariableID:8191:7009",
2327
2327
  "com.figma.scopes": [
@@ -2331,6 +2331,18 @@
2331
2331
  "com.figma.isOverride": true
2332
2332
  }
2333
2333
  },
2334
+ "font-stack-branded": {
2335
+ "$type": "string",
2336
+ "$value": "initial",
2337
+ "$extensions": {
2338
+ "com.figma.variableId": "VariableID:9617:2",
2339
+ "com.figma.scopes": [
2340
+ "ALL_SCOPES"
2341
+ ],
2342
+ "com.figma.type": "string",
2343
+ "com.figma.isOverride": true
2344
+ }
2345
+ },
2334
2346
  "$extensions": {
2335
2347
  "com.figma.modeName": "default"
2336
2348
  }
@@ -0,0 +1,20 @@
1
+ @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
2
+
3
+ /*
4
+ The native CSS implementation of the below would look like:
5
+
6
+ @function --rem-from-px(--px <length>, --base <length>: 16px) returns <length> {
7
+ result: calc((var(--px) / var(--base)) * 1rem);
8
+ }
9
+
10
+ This can be swapped in when browser coverage is added to Firefox and Safari
11
+ See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@function
12
+ */
13
+
14
+ @function rem-from-px($px, $base: $base-font-size-px) {
15
+ @return calc(($px / $base) * 1rem);
16
+ }
17
+
18
+ @function unitless-from-px($px, $base: $base-font-size-px) {
19
+ @return calc($px / $base);
20
+ }
@@ -1,2 +0,0 @@
1
- export * as normalizeStyles from './normalize.scss';
2
- export * as baseStyles from './base.scss';
@@ -1,10 +0,0 @@
1
- @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
2
- @use '@cfpb/cfpb-design-system/src/elements/cfpb-button/vars' as *;
3
-
4
- :host {
5
- // This prevents the child button from having an empty gap after the button.
6
- display: flex;
7
- width: fit-content;
8
-
9
- flex-direction: column;
10
- }
@@ -1,36 +0,0 @@
1
- @use 'sass:math';
2
- @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
3
- @use '@cfpb/cfpb-design-system/src/components/cfpb-icons/icon' as *;
4
-
5
- :host {
6
- .a-form-alert {
7
- // Theme
8
- --form-alert-icon-color: var(--form-alert-icon-color-default);
9
-
10
- margin-top: math.div(15px, $base-font-size-px) + rem;
11
- display: flex;
12
- gap: math.div(5px, $base-font-size-px) + rem;
13
-
14
- .cf-icon-svg {
15
- color: var(--form-alert-icon-color);
16
- flex: none;
17
- margin-top: math.div(1px, $base-font-size-px) + rem;
18
- }
19
-
20
- &__text {
21
- display: block;
22
- }
23
-
24
- &--success .cf-icon-svg {
25
- --form-alert-icon-color: var(--form-alert-icon-color-success);
26
- }
27
-
28
- &--warning .cf-icon-svg {
29
- --form-alert-icon-color: var(--form-alert-icon-color-warning);
30
- }
31
-
32
- &--error .cf-icon-svg {
33
- --form-alert-icon-color: var(--form-alert-icon-color-error);
34
- }
35
- }
36
- }