Skip to content

Commit

Permalink
Add exports config to DS package
Browse files Browse the repository at this point in the history
The `exports` field allows multiple entrypoints to be defined instead of
just a single `main` entrypoint. This allows the bundled code to be selectively
imported by developers. For our purposes, we can package the majority of our DS
code into a single file but keep the tooltip code separate. Tooltips are used
on very few pages and they rely on a third party library that we don't want users
to unnecessarily download on every page of cf.gov.

See https://nodejs.org/api/packages.html#package-entry-points
  • Loading branch information
contolini committed Oct 24, 2024
1 parent 5f9f801 commit 97188f9
Show file tree
Hide file tree
Showing 147 changed files with 479 additions and 443 deletions.
2 changes: 1 addition & 1 deletion docs/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
AlphaTransition,
MaxHeightTransition,
MoveTransition,
Tooltip,
} from '@cfpb/cfpb-design-system';
import { Tooltip } from '@cfpb/cfpb-design-system/tooltips';
import Tabs from './tabs.js';
import redirectBanner from './redirect-banner.js';
import sidebar from './sidebar.js';
Expand Down
51 changes: 47 additions & 4 deletions docs/pages/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,62 @@ description: A tooltip provides short, descriptive information when a user
variation_groups:
- variations:
- variation_is_deprecated: false
variation_code_snippet: >+
variation_code_snippet: >-
The APR for the World Bank Platinum Credit Card is 9.7% <span
data-tooltip="relevant-tooltip">{% include icons/help-round.svg
%}</span>
<template id="relevant-tooltip">
<div class="tippy-heading">This data is accurate as of June 2023</div>
<div class="tippy-body">APRs change over time and are specific to the applicant. Check rates before applying.</div>
<div class="tippy-body">
APRs change over time and are specific to the applicant. Check rates before applying.
</div>
</template>
<!--
Tooltips require a <template> element with an 'id' that matches the 'data-tooltip'
attribute of the tooltip's trigger element. The template can be anywhere on the page.
Additionally, the tooltip component must be imported independently of the rest of
the Design System using the namespace '@cfpb/cfpb-design-system/tooltips'.
For example, your project's JavaScript file might look like:
import {
Expandable,
ExpandableGroup,
Summary,
Multiselect,
} from '@cfpb/cfpb-design-system';
import { Tooltip } from '@cfpb/cfpb-design-system/tooltips';
Summary.init();
Expandable.init();
ExpandableGroup.init();
Multiselect.init();
Tooltip.init();
...rest of your code
-->
variation_description: ''
variation_code_snippet_rendered: ''
variation_group_name: Standard tooltip
variation_group_description: ""
variation_group_description: ''
guidelines: Be judicious in using tooltips and explore other design options that
keep content visible before choosing to use a tooltip. Only consider using a
tooltip for short, non-critical information in a space-constrained user
Expand All @@ -43,5 +86,5 @@ accessibility: As USWDS states, tooltips are progressive enhancements for the
doesn’t initialize. When testing tooltips for accessibility, ensure they are
compliant with [USWDS tooltip accessibility
tests](https://designsystem.digital.gov/components/tooltip/accessibility-tests/).
related_items: ""
related_items: ''
---
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@babel-core-7.25.2.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@babel-parser-7.25.6.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@babel-types-7.25.6.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@octokit-types-13.6.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@types-lodash-4.17.9.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/@types-node-22.7.4.tgz
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@types-react-18.3.10.tgz
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/@types-sizzle-2.3.8.tgz
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/acorn-8.12.1.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/acorn-8.13.0.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/axe-core-4.10.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/axe-core-4.10.2.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/bare-stream-2.3.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/bare-stream-2.3.2.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/browserslist-4.24.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/cookie-0.6.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/cookie-0.7.1.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/express-4.21.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/express-4.21.1.tgz
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/form-data-4.0.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/form-data-4.0.1.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/jsesc-2.5.2.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/jsesc-3.0.2.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/mdn-data-2.11.1.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/parse5-7.1.2.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/parse5-7.2.0.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/picocolors-1.1.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/picocolors-1.1.1.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/readdirp-4.0.1.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/readdirp-4.0.2.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/sass-1.79.3.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/sass-1.80.3.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/stylelint-scss-6.7.0.tgz
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/text-decoder-1.2.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/text-decoder-1.2.1.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/tippy.js-6.3.7.tgz
Binary file not shown.
Binary file removed npm-packages-offline-cache/tldts-icann-6.1.48.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed npm-packages-offline-cache/tslib-2.7.0.tgz
Binary file not shown.
Binary file added npm-packages-offline-cache/tslib-2.8.0.tgz
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cfpb-design-system/dist/index.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/cfpb-design-system/dist/index.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cfpb-design-system/dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/cfpb-design-system/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cfpb-design-system/dist/utilities/index.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/cfpb-design-system/dist/utilities/index.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cfpb-design-system/dist/utilities/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/cfpb-design-system/dist/utilities/index.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions packages/cfpb-design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "@cfpb/cfpb-design-system",
"version": "3.2.5",
"description": "CFPB's UI framework",
"main": "src/index.js",
"exports": {
".": "./src/index.js",
"./tooltips": "./src/components/cfpb-tooltips/index.js"
},
"author": {
"name": "Consumer Financial Protection Bureau",
"email": "[email protected]",
Expand All @@ -24,7 +27,7 @@
"gitHead": "d9b9862ef0a34a0ca6f4835347ac7f202ed50e3e",
"type": "module",
"dependencies": {
"tippy.js": "6.3.7"
"tippy.js": "6.3.7"
},
"devDependencies": {
"auto-changelog": "2.5.0"
Expand Down
79 changes: 76 additions & 3 deletions packages/cfpb-design-system/src/components/cfpb-tooltips/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
/* ==========================================================================
Design System
Tooltips
Tooltip Organism
========================================================================== */

export { Tooltip } from './tooltip.js';
import tippy from 'tippy.js';
import { instantiateAll } from '@cfpb/cfpb-design-system';

import * as TooltipStyles from './tooltip.scss';

const BASE_ATTRIBUTE = 'data-tooltip';

/**
* Tooltip
* @class
* @classdesc Initializes a new Tooltip.
* @param {HTMLElement} element - The DOM element that should
* activate the tooltip.
* @returns {Tooltip} An instance.
*/
function Tooltip(element) {
const tooltipContent = element.getAttribute(BASE_ATTRIBUTE);

/**
* Set up and create the tooltip.
* @returns {Tooltip} An instance.
*/
function init() {
tippy(element, {
theme: 'cfpb',
maxWidth: 450,
content: function (reference) {
const template = reference.parentElement.querySelector(
`#${tooltipContent}`,
);
const container = document.createElement('div');
const node = document.importNode(template.content, true);
container.appendChild(node);
return container;
},
// See https://atomiks.github.io/tippyjs/v6/plugins/
plugins: [
{
name: 'hideOnEsc',
defaultValue: true,
fn({ hide }) {
/**
* Hide when the escape key is pressed.
* @param {KeyboardEvent} event - Key down event.
*/
function onKeyDown(event) {
if (event.key === 'Escape') {
hide();
}
}
return {
onShow() {
document.addEventListener('keydown', onKeyDown);
},
onHide() {
document.removeEventListener('keydown', onKeyDown);
},
};
},
},
],
});
}

// Attach public events.
this.init = init;

return this;
}

Tooltip.BASE_ATTRIBUTE = BASE_ATTRIBUTE;
Tooltip.init = (scope) =>
instantiateAll(`[${Tooltip.BASE_ATTRIBUTE}]`, Tooltip, scope);

export { Tooltip, TooltipStyles };

This file was deleted.

1 change: 0 additions & 1 deletion packages/cfpb-design-system/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export * from './components/cfpb-layout';
export * from './components/cfpb-notifications';
export * from './components/cfpb-pagination';
export * from './components/cfpb-tables';
export * from './components/cfpb-tooltips';
export * from './components/cfpb-typography';

export * from './utilities';
Loading

0 comments on commit 97188f9

Please sign in to comment.