@@ -8,9 +8,12 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs'
8
8
import { closestAttributeValue } from '../../common/closest-attribute-value.mjs'
9
9
10
10
/**
11
+ * @constant
11
12
* @type {CharacterCountTranslations }
13
+ * @see Default value for {@link CharacterCountConfig.i18n}
14
+ * @default
12
15
*/
13
- var TRANSLATIONS_DEFAULT = {
16
+ var CHARACTER_COUNT_TRANSLATIONS = {
14
17
// Characters
15
18
charactersUnderLimit : {
16
19
one : 'You have %{count} character remaining' ,
@@ -48,13 +51,7 @@ var TRANSLATIONS_DEFAULT = {
48
51
*
49
52
* @class
50
53
* @param {HTMLElement } $module - The element this component controls
51
- * @param {object } config - Character count config
52
- * @param {number } config.maxlength - The maximum number of characters. If maxwords is provided, the maxlength option will be ignored.
53
- * @param {number } config.maxwords - The maximum number of words. If maxwords is provided, the maxlength option will be ignored.
54
- * @param {number } [config.threshold=0] - The percentage value of the limit at
55
- * which point the count message is displayed. If this attribute is set, the
56
- * count message will be hidden by default.
57
- * @param {CharacterCountTranslations } [config.i18n = DEFAULT_TRANSLATIONS]
54
+ * @param {CharacterCountConfig } [config] - Character count config
58
55
*/
59
56
function CharacterCount ( $module , config ) {
60
57
if ( ! $module ) {
@@ -63,7 +60,7 @@ function CharacterCount ($module, config) {
63
60
64
61
var defaultConfig = {
65
62
threshold : 0 ,
66
- i18n : TRANSLATIONS_DEFAULT
63
+ i18n : CHARACTER_COUNT_TRANSLATIONS
67
64
}
68
65
69
66
// Read config set using dataset ('data-' values)
@@ -376,12 +373,44 @@ CharacterCount.prototype.isOverThreshold = function () {
376
373
export default CharacterCount
377
374
378
375
/**
376
+ * Character count config
377
+ *
378
+ * @typedef {CharacterCountConfigWithMaxLength | CharacterCountConfigWithMaxWords } CharacterCountConfig
379
+ */
380
+
381
+ /**
382
+ * Character count config (with maximum number of characters)
383
+ *
384
+ * @typedef {object } CharacterCountConfigWithMaxLength
385
+ * @property {number } [maxlength] - The maximum number of characters.
386
+ * If maxwords is provided, the maxlength option will be ignored.
387
+ * @property {number } [threshold = 0] - The percentage value of the limit at
388
+ * which point the count message is displayed. If this attribute is set, the
389
+ * count message will be hidden by default.
390
+ * @property {CharacterCountTranslations } [i18n = CHARACTER_COUNT_TRANSLATIONS] - See constant {@link CHARACTER_COUNT_TRANSLATIONS}
391
+ */
392
+
393
+ /**
394
+ * Character count config (with maximum number of words)
395
+ *
396
+ * @typedef {object } CharacterCountConfigWithMaxWords
397
+ * @property {number } [maxwords] - The maximum number of words. If maxwords is
398
+ * provided, the maxlength option will be ignored.
399
+ * @property {number } [threshold = 0] - The percentage value of the limit at
400
+ * which point the count message is displayed. If this attribute is set, the
401
+ * count message will be hidden by default.
402
+ * @property {CharacterCountTranslations } [i18n = CHARACTER_COUNT_TRANSLATIONS] - See constant {@link CHARACTER_COUNT_TRANSLATIONS}
403
+ */
404
+
405
+ /**
406
+ * Character count translations
407
+ *
379
408
* @typedef {object } CharacterCountTranslations
380
409
*
381
410
* Messages shown to users as they type. It provides feedback on how many words
382
411
* or characters they have remaining or if they are over the limit. This also
383
412
* includes a message used as an accessible description for the textarea.
384
- * @property {PluralisedTranslation } [charactersUnderLimit] - Message displayed
413
+ * @property {TranslationPluralForms } [charactersUnderLimit] - Message displayed
385
414
* when the number of characters is under the configured maximum, `maxlength`.
386
415
* This message is displayed visually and through assistive technologies. The
387
416
* component will replace the `%{count}` placeholder with the number of
@@ -390,13 +419,13 @@ export default CharacterCount
390
419
* @property {string } [charactersAtLimit] - Message displayed when the number of
391
420
* characters reaches the configured maximum, `maxlength`. This message is
392
421
* displayed visually and through assistive technologies.
393
- * @property {PluralisedTranslation } [charactersOverLimit] - Message displayed
422
+ * @property {TranslationPluralForms } [charactersOverLimit] - Message displayed
394
423
* when the number of characters is over the configured maximum, `maxlength`.
395
424
* This message is displayed visually and through assistive technologies. The
396
425
* component will replace the `%{count}` placeholder with the number of
397
426
* remaining characters. This is a [pluralised list of
398
427
* messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
399
- * @property {PluralisedTranslation } [wordsUnderLimit] - Message displayed when
428
+ * @property {TranslationPluralForms } [wordsUnderLimit] - Message displayed when
400
429
* the number of words is under the configured maximum, `maxlength`. This
401
430
* message is displayed visually and through assistive technologies. The
402
431
* component will replace the `%{count}` placeholder with the number of
@@ -405,13 +434,13 @@ export default CharacterCount
405
434
* @property {string } [wordsAtLimit] - Message displayed when the number of
406
435
* words reaches the configured maximum, `maxlength`. This message is
407
436
* displayed visually and through assistive technologies.
408
- * @property {PluralisedTranslation } [wordsOverLimit] - Message displayed when
437
+ * @property {TranslationPluralForms } [wordsOverLimit] - Message displayed when
409
438
* the number of words is over the configured maximum, `maxlength`. This
410
439
* message is displayed visually and through assistive technologies. The
411
440
* component will replace the `%{count}` placeholder with the number of
412
441
* remaining words. This is a [pluralised list of
413
442
* messages](https://frontend.design-system.service.gov.uk/localise-govuk-frontend).
414
- * @property {PluralisedTranslation } [textareaDescription] - Message made
443
+ * @property {TranslationPluralForms } [textareaDescription] - Message made
415
444
* available to assistive technologies, if none is already present in the
416
445
* HTML, to describe that the component accepts only a limited amount of
417
446
* content. It is visible on the page when JavaScript is unavailable. The
@@ -420,5 +449,5 @@ export default CharacterCount
420
449
*/
421
450
422
451
/**
423
- * @typedef {import('../../i18n.mjs').PluralisedTranslation } PluralisedTranslation
452
+ * @typedef {import('../../i18n.mjs').TranslationPluralForms } TranslationPluralForms
424
453
*/
0 commit comments