Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Nov 19, 2024
1 parent 680fb18 commit 675b7fb
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 43 deletions.
8 changes: 4 additions & 4 deletions packages/govuk-frontend/src/govuk/common/configuration.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '../component.mjs'
import { ConfigError } from '../errors/index.mjs'
import { GOVUKFrontendComponent } from '../govuk-frontend-component.mjs'

import { isObject, formatErrorMessage } from './index.mjs'

Expand All @@ -13,9 +13,9 @@ export const configOverride = Symbol.for('configOverride')
* @virtual
* @template {ObjectNested} [ConfigurationType={}]
* @template {Element & { dataset: DOMStringMap }} [RootElementType=HTMLElement]
* @augments GOVUKFrontendComponent<RootElementType>
* @augments Component<RootElementType>
*/
export class GOVUKFrontendComponentConfigurable extends GOVUKFrontendComponent {
export class ConfigurableComponent extends Component {
/**
* configOverride
*
Expand Down Expand Up @@ -354,5 +354,5 @@ export function extractConfigByNamespace(schema, dataset, namespace) {

/**
* @template {ObjectNested} [ConfigurationType={}]
* @typedef {typeof GOVUKFrontendComponent & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
* @typedef {typeof Component & ChildClass<ConfigurationType>} ChildClassConstructor<ConfigurationType>
*/
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { ConfigError } from '../../errors/index.mjs'
import {
GOVUKFrontendComponentConfigurable,
configOverride
} from '../configuration.mjs'
import { ConfigurableComponent, configOverride } from '../configuration.mjs'

describe('GOVUKFrontendComponentConfigurable', () => {
beforeEach(() => {
Expand All @@ -18,23 +15,23 @@ describe('GOVUKFrontendComponentConfigurable', () => {

describe('throws error', () => {
it('if no schema defined', () => {
class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static defaults = {
randomAttribute: 0
}
}

expect(() => new ConfigurableComponent(document.body)).toThrow(
expect(() => new MockConfigurableComponent(document.body)).toThrow(
new ConfigError(
'config-component: Config passed as parameter into constructor but no schema defined'
)
)
})

it('if no defaults defined', () => {
class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static schema = {
Expand All @@ -44,7 +41,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
}
}

expect(() => new ConfigurableComponent(document.body)).toThrow(
expect(() => new MockConfigurableComponent(document.body)).toThrow(
new ConfigError(
'config-component: Config passed as parameter into constructor but no defaults defined'
)
Expand All @@ -58,7 +55,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
<div id="test-component"></div>
`

class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static schema = {
Expand All @@ -74,7 +71,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {

const testComponent = document.querySelector('#test-component')

const configComponent = new ConfigurableComponent(testComponent)
const configComponent = new MockConfigurableComponent(testComponent)

expect(configComponent._config).toMatchObject({ randomAttribute: 0 })
})
Expand All @@ -84,7 +81,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
<div id="test-component" data-random-attribute="42"></div>
`

class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static schema = {
Expand All @@ -100,7 +97,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {

const testComponent = document.querySelector('#test-component')

const configComponent = new ConfigurableComponent(testComponent)
const configComponent = new MockConfigurableComponent(testComponent)

expect(configComponent._config).toMatchObject({ randomAttribute: 42 })
})
Expand All @@ -110,7 +107,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
<div id="test-component"></div>
`

class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static schema = {
Expand All @@ -126,7 +123,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {

const testComponent = document.querySelector('#test-component')

const configComponent = new ConfigurableComponent(testComponent, {
const configComponent = new MockConfigurableComponent(testComponent, {
randomAttribute: 100
})

Expand All @@ -138,7 +135,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
<div id="test-component" data-random-attribute="12"></div>
`

class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
static moduleName = 'config-component'

static schema = {
Expand All @@ -154,7 +151,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {

const testComponent = document.querySelector('#test-component')

const configComponent = new ConfigurableComponent(testComponent, {
const configComponent = new MockConfigurableComponent(testComponent, {
randomAttribute: 100
})

Expand All @@ -170,7 +167,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
<div id="test-component" data-random-attribute="13"></div>
`

class ConfigurableComponent extends GOVUKFrontendComponentConfigurable {
class MockConfigurableComponent extends ConfigurableComponent {
[configOverride](config) {
return configOverrideFunction(config)
}
Expand All @@ -190,7 +187,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {

const testComponent = document.querySelector('#test-component')

const configComponent = new ConfigurableComponent(testComponent, {
const configComponent = new MockConfigurableComponent(testComponent, {
randomAttribute: '14'
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'
import { ElementError } from '../../errors/index.mjs'
import { I18n } from '../../i18n.mjs'

Expand All @@ -15,9 +15,9 @@ import { I18n } from '../../i18n.mjs'
* attribute, which also provides accessibility.
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<AccordionConfig>
* @augments ConfigurableComponent<AccordionConfig>
*/
export class Accordion extends GOVUKFrontendComponentConfigurable {
export class Accordion extends ConfigurableComponent {
/** @private */
i18n

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'

const DEBOUNCE_TIMEOUT_IN_SECONDS = 1

/**
* JavaScript enhancements for the Button component
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<ButtonConfig>
* @augments ConfigurableComponent<ButtonConfig>
*/
export class Button extends GOVUKFrontendComponentConfigurable {
export class Button extends ConfigurableComponent {
/**
* @private
* @type {number | null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { closestAttributeValue } from '../../common/closest-attribute-value.mjs'
import {
validateConfig,
GOVUKFrontendComponentConfigurable,
ConfigurableComponent,
configOverride
} from '../../common/configuration.mjs'
import { formatErrorMessage } from '../../common/index.mjs'
Expand All @@ -19,9 +19,9 @@ import { I18n } from '../../i18n.mjs'
* of the available characters/words has been entered.
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<CharacterCountConfig>
* @augments ConfigurableComponent<CharacterCountConfig>
*/
export class CharacterCount extends GOVUKFrontendComponentConfigurable {
export class CharacterCount extends ConfigurableComponent {
/** @private */
$textarea

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'
import { getFragmentFromUrl, setFocus } from '../../common/index.mjs'

/**
Expand All @@ -8,9 +8,9 @@ import { getFragmentFromUrl, setFocus } from '../../common/index.mjs'
* configuration.
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<ErrorSummaryConfig>
* @augments ConfigurableComponent<ErrorSummaryConfig>
*/
export class ErrorSummary extends GOVUKFrontendComponentConfigurable {
export class ErrorSummary extends ConfigurableComponent {
/**
* @param {Element | null} $root - HTML element to use for error summary
* @param {ErrorSummaryConfig} [config] - Error summary config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'
import { ElementError } from '../../errors/index.mjs'
import { I18n } from '../../i18n.mjs'

/**
* Exit this page component
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<ExitThisPageConfig>
* @augments ConfigurableComponent<ExitThisPageConfig>
*/
export class ExitThisPage extends GOVUKFrontendComponentConfigurable {
export class ExitThisPage extends ConfigurableComponent {
/** @private */
i18n

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'
import { setFocus } from '../../common/index.mjs'

/**
* Notification Banner component
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<NotificationBannerConfig>
* @augments ConfigurableComponent<NotificationBannerConfig>
*/
export class NotificationBanner extends GOVUKFrontendComponentConfigurable {
export class NotificationBanner extends ConfigurableComponent {
/**
* @param {Element | null} $root - 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,15 +1,15 @@
import { closestAttributeValue } from '../../common/closest-attribute-value.mjs'
import { GOVUKFrontendComponentConfigurable } from '../../common/configuration.mjs'
import { ConfigurableComponent } from '../../common/configuration.mjs'
import { ElementError } from '../../errors/index.mjs'
import { I18n } from '../../i18n.mjs'

/**
* Password input component
*
* @preserve
* @augments GOVUKFrontendComponentConfigurable<PasswordInputConfig>
* @augments ConfigurableComponent<PasswordInputConfig>
*/
export class PasswordInput extends GOVUKFrontendComponentConfigurable {
export class PasswordInput extends ConfigurableComponent {
/** @private */
i18n

Expand Down

0 comments on commit 675b7fb

Please sign in to comment.