-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
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
There are no files selected for viewing
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.
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]", | ||
|
@@ -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" | ||
|
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.