Skip to content

Commit

Permalink
Use named exports for component classes
Browse files Browse the repository at this point in the history
We prefer named exports over default exports to avoid compatibility issues with transpiler "synthetic default" as discussed in: #2829

See our [coding standards for JavaScript](/docs/contributing/coding-standards/js.md)
  • Loading branch information
colinrotherham committed Jun 12, 2023
1 parent d9d6f32 commit b94e812
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 25 deletions.
22 changes: 11 additions & 11 deletions packages/govuk-frontend/src/govuk/all.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { version } from './common/govuk-frontend-version.mjs'
import Accordion from './components/accordion/accordion.mjs'
import Button from './components/button/button.mjs'
import CharacterCount from './components/character-count/character-count.mjs'
import Checkboxes from './components/checkboxes/checkboxes.mjs'
import Details from './components/details/details.mjs'
import ErrorSummary from './components/error-summary/error-summary.mjs'
import Header from './components/header/header.mjs'
import NotificationBanner from './components/notification-banner/notification-banner.mjs'
import Radios from './components/radios/radios.mjs'
import SkipLink from './components/skip-link/skip-link.mjs'
import Tabs from './components/tabs/tabs.mjs'
import { Accordion } from './components/accordion/accordion.mjs'
import { Button } from './components/button/button.mjs'
import { CharacterCount } from './components/character-count/character-count.mjs'
import { Checkboxes } from './components/checkboxes/checkboxes.mjs'
import { Details } from './components/details/details.mjs'
import { ErrorSummary } from './components/error-summary/error-summary.mjs'
import { Header } from './components/header/header.mjs'
import { NotificationBanner } from './components/notification-banner/notification-banner.mjs'
import { Radios } from './components/radios/radios.mjs'
import { SkipLink } from './components/skip-link/skip-link.mjs'
import { Tabs } from './components/tabs/tabs.mjs'

/**
* Initialise all components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ACCORDION_TRANSLATIONS = {
* The state of each section is saved to the DOM via the `aria-expanded`
* attribute, which also provides accessibility.
*/
export default class Accordion {
export class Accordion {
/**
* @param {Element} $module - HTML element to use for accordion
* @param {AccordionConfig} [config] - Accordion config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEBOUNCE_TIMEOUT_IN_SECONDS = 1
/**
* JavaScript enhancements for the Button component
*/
export default class Button {
export class Button {
/**
*
* @param {Element} $module - HTML element to use for button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CHARACTER_COUNT_TRANSLATIONS = {
* You can configure the message to only appear after a certain percentage
* of the available characters/words has been entered.
*/
export default class CharacterCount {
export class CharacterCount {
/**
* @param {Element} $module - HTML element to use for character count
* @param {CharacterCountConfig} [config] - Character count config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CharacterCount from './character-count.mjs'
import { CharacterCount } from './character-count.mjs'

describe('CharacterCount', () => {
let $container
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Checkboxes component
*/
export default class Checkboxes {
export class Checkboxes {
/**
* @param {Element} $module - HTML element to use for checkboxes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const KEY_SPACE = 32
/**
* Details component
*/
export default class Details {
export class Details {
/**
*
* @param {Element} $module - HTML element to use for details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs'
*
* Takes focus on initialisation for accessible announcement, unless disabled in configuration.
*/
export default class ErrorSummary {
export class ErrorSummary {
/**
*
* @param {Element} $module - HTML element to use for error summary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Header component
*/
export default class Header {
export class Header {
/**
* @param {Element} $module - HTML element to use for header
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs'
/**
* Notification Banner component
*/
export default class NotificationBanner {
export class NotificationBanner {
/**
* @param {Element} $module - HTML element to use for notification banner
* @param {NotificationBannerConfig} [config] - Notification banner config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Radios component
*/
export default class Radios {
export class Radios {
/**
* @param {Element} $module - HTML element to use for radios
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Skip link component
*/
export default class SkipLink {
export class SkipLink {
/**
*
* @param {Element} $module - HTML element to use for skip link
Expand Down
2 changes: 1 addition & 1 deletion packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Tabs component
*/
export default class Tabs {
export class Tabs {
/**
* @param {Element} $module - HTML element to use for tabs
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend/tasks/build/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ describe('packages/govuk-frontend/dist/', () => {
const moduleText = await readFile(join(paths.package, 'dist/govuk/components', modulePath), 'utf8')
const moduleTextESM = await readFile(join(paths.package, 'dist/govuk-esm/components', modulePathESM), 'utf8')

expect(moduleText).toContain(`typeof define === 'function' && define.amd ? define('${moduleName}', factory)`)
expect(moduleTextESM).toContain(`export { ${componentNameToClassName(componentName)} as default }`)
expect(moduleText).toContain(`typeof define === 'function' && define.amd ? define('${moduleName}', ['exports'], factory)`)
expect(moduleTextESM).toContain(`export { ${componentNameToClassName(componentName)} }`)
})

// Check all component files
Expand Down

0 comments on commit b94e812

Please sign in to comment.