A modular frontend toolkit designed to help with Brave project development, including accessibility enhancements, utility functions, and easy-to-use classes.
npm install @yardinternet/brave-frontend-kitAdds a specific class to the body when the user is navigating via keyboard (Tab key). It ensures that we can style keyboard users differently from mouse users.
import { FocusStyle } from '@yardinternet/brave-frontend-kit';
// Default: initialize the FocusStyle class
const focusStyle = new FocusStyle();
// Extended usage: all options
const customFocusStyle = new FocusStyle( {
bodyClass: 'custom-class',
} );Adds an icon to external links by checking if the hostname differs from the current site.
import { EnhanceExternalLinks } from '@yardinternet/brave-frontend-kit';
// Basic usage
new EnhanceExternalLinks( {
selector: '.main a',
icon: '<i class="js-enhance-external-link-icon fa-light fa-arrow-up-right-from-square"></i>',
} );
// Extended usage: all options
new EnhanceExternalLinks( {
selector: '.main a',
icon: '<i class="fa-regular fa-up-right-from-square mx-2"></i>',
excludedClasses: [ 'wp-block-button__link' ],
excludedUrlKeywords: [ 'openpdc' ],
insertIconBeforeText: true,
} );Enhances .pdf links with a visual icon and optional file size fetched via a HEAD request.
import { EnhancePDFLinks } from '@yardinternet/brave-frontend-kit';
// Basic usage
new EnhancePDFLinks( {a
selector: '.main a',
icon: '<i class="js-enhance-pdf-link-icon fa-light fa-file-pdf mx-2"></i>',
fileSizeClass: 'js-enhance-pdf-link-file-size text-xs',
} );
// Extended usage: all options
new EnhancePDFLinks( {
selector: '.main a',
icon: '<i class="fa-regular fa-file-pdf mx-2"></i>',
excludedClasses: [ 'wp-block-button__link' ],
excludedUrlKeywords: [ 'openpdc' ],
insertIconBeforeText: true,
showFileSize: false,
fileSizeClass: 'js-enhance-pdf-link-file-size text-xs',
insertIconBeforeText: true,
createFileSizeElement: ( bytes ) => {
const span = document.createElement( 'span' );
span.classList.add( 'text-xs' );
span.innerHTML = ` (pdf, ${ Math.round( bytes / 1024 ) } KB)`;
return span;
},
} );Initializes the Web Share API on a specific element and provides a function to handle the share action.
import { WebShareApi } from '@yardinternet/brave-frontend-kit';
// Basic usage
new WebShareApi();
// Extended usage: all options
new WebShareApi( {
selector: '.js-web-share-api',
} );Enhances FacetWP search pages. Adds scroll to top, aria labels, focus change on pager, hides label on filter and reset filters if no filters selected.
import { A11yFacetWP } from '@yardinternet/brave-frontend-kit';
// Basic usage
new A11yFacetWP();
// Extended usage: all options
new A11yFacetWP({
selectorPrefix: 'js',
scrollToTopOffset: 150,
});Enhances mobile menu. Adds expand, open & close buttons, aria labels, animations and focus trap.
import { A11yMobileMenu } from '@yardinternet/brave-frontend-kit';
// Basic usage
new A11yMobileMenu();
// Extended usage: all options
new A11yMobileMenu({
selectorPrefix: 'js',
onActivateFocusTrapAnimate: {
keyframes: [
{
transform: 'translateX(100%)',
opacity: '0',
visibility: 'hidden',
},
{
transform: 'translateX(0)',
opacity: '1',
visibility: 'visible',
},
],
options: {
duration: 500,
easing: 'cubic-bezier(0.22,1,0.36,1)',
fill: 'both',
}
},
[...]
});TBA
- Run
npm linkinside this project. - Run
npm link @yardinternet/brave-frontend-kitinside the project or theme. This will create a symbolic link to the project folder. - Run
npm run startinside this project AND the equivalent script inside the project or theme.
- Change the version of
package.jsonto the desired version and commit this change. - Go to releases of the package and click on "Draft a new release"
- Click "Choose a tag", type the corresponding version and press Enter. Add a title and description for the release.
- Click "Publish release"
The Github Workflow release-package.yml will run whenever a release is created in this repository. If the tests pass, then the package will be published to Github packages.


