@uh-design-system/component-library 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/cjs/component-library.cjs.js +2 -2
  2. package/dist/cjs/ds-accordion_3.cjs.entry.js +11 -11
  3. package/dist/cjs/ds-checkbox-group.cjs.entry.js +15 -16
  4. package/dist/cjs/ds-checkbox.cjs.entry.js +42 -35
  5. package/dist/cjs/ds-input-validity.cjs.entry.js +4 -6
  6. package/dist/cjs/ds-link-with-arrow.cjs.entry.js +5 -5
  7. package/dist/cjs/ds-link.cjs.entry.js +5 -5
  8. package/dist/cjs/ds-text-input.cjs.entry.js +52 -24
  9. package/dist/cjs/ds-visually-hidden.cjs.entry.js +2 -2
  10. package/dist/cjs/{index-b2bddcf4.js → index-bf84b124.js} +16 -0
  11. package/dist/cjs/index.cjs.js +8 -0
  12. package/dist/cjs/{linkUtils-e911e899.js → linkUtils-695da37c.js} +0 -10
  13. package/dist/cjs/loader.cjs.js +2 -2
  14. package/dist/cjs/store-9bd20f3c.js +207 -0
  15. package/dist/cjs/{utils-c9113835.js → utils-2ba5e075.js} +10 -0
  16. package/dist/collection/collection-manifest.json +1 -1
  17. package/dist/collection/components/00-foundations/icons/icons.stories.js +1 -0
  18. package/dist/collection/components/00-foundations/types.js +1 -0
  19. package/dist/collection/components/01-base-components/ds-accordion/ds-accordion.js +6 -6
  20. package/dist/collection/components/01-base-components/ds-button/ds-button.css +6 -0
  21. package/dist/collection/components/01-base-components/ds-button/ds-button.js +1 -1
  22. package/dist/collection/components/01-base-components/ds-checkbox/ds-checkbox.css +1 -1
  23. package/dist/collection/components/01-base-components/ds-checkbox/ds-checkbox.js +68 -56
  24. package/dist/collection/components/01-base-components/ds-checkbox/stories/ds-checkbox.stories.js +1 -0
  25. package/dist/collection/components/01-base-components/ds-checkbox-group/ds-checkbox-group.js +27 -67
  26. package/dist/collection/components/01-base-components/ds-icon/ds-icon.js +1 -1
  27. package/dist/collection/components/01-base-components/ds-input-validity/ds-input-validity.js +5 -8
  28. package/dist/collection/components/01-base-components/ds-input-validity/stories/ds-input-validity.stories.js +1 -0
  29. package/dist/collection/components/01-base-components/ds-link/ds-link.js +6 -6
  30. package/dist/collection/components/01-base-components/ds-link/stories/ds-link.stories.js +1 -1
  31. package/dist/collection/components/01-base-components/ds-link-with-arrow/ds-link-with-arrow.js +6 -6
  32. package/dist/collection/components/01-base-components/ds-link-with-arrow/stories/ds-link-with-arrow.stories.js +1 -1
  33. package/dist/collection/components/01-base-components/ds-text-input/ds-text-input.css +6 -0
  34. package/dist/collection/components/01-base-components/ds-text-input/ds-text-input.js +73 -27
  35. package/dist/collection/components/01-base-components/ds-text-input/stories/ds-text-input.examples.stories.js +82 -13
  36. package/dist/collection/components/01-base-components/ds-text-input/stories/ds-text-input.stories.js +6 -7
  37. package/dist/collection/components/01-base-components/ds-text-input/utils.js +1 -10
  38. package/dist/collection/components/01-base-components/ds-visually-hidden/ds-visually-hidden.js +1 -1
  39. package/dist/collection/index.js +1 -1
  40. package/dist/collection/store.js +13 -0
  41. package/dist/collection/utils/link/linkUtils.js +0 -9
  42. package/dist/collection/utils/utils.js +9 -0
  43. package/dist/component-library/component-library.esm.js +1 -1
  44. package/dist/component-library/ds-accordion_3.entry.js +1 -1
  45. package/dist/component-library/ds-checkbox-group.entry.js +1 -1
  46. package/dist/component-library/ds-checkbox.entry.js +1 -1
  47. package/dist/component-library/ds-input-validity.entry.js +1 -1
  48. package/dist/component-library/ds-link-with-arrow.entry.js +1 -1
  49. package/dist/component-library/ds-link.entry.js +1 -1
  50. package/dist/component-library/ds-text-input.entry.js +1 -1
  51. package/dist/component-library/ds-visually-hidden.entry.js +1 -1
  52. package/dist/component-library/{index-50783b0c.js → index-434995e1.js} +2 -2
  53. package/dist/component-library/index.esm.js +1 -0
  54. package/dist/component-library/{linkUtils-fe63ff72.js → linkUtils-3d1b28cf.js} +1 -1
  55. package/dist/component-library/store-b8d17c10.js +1 -0
  56. package/dist/component-library/utils-5daa5bc0.js +1 -0
  57. package/dist/components/ds-accordion.js +6 -6
  58. package/dist/components/ds-button2.js +2 -2
  59. package/dist/components/ds-checkbox-group.js +21 -23
  60. package/dist/components/ds-checkbox2.js +44 -37
  61. package/dist/components/ds-icon2.js +11 -2
  62. package/dist/components/ds-input-validity2.js +4 -6
  63. package/dist/components/ds-link-with-arrow.js +5 -5
  64. package/dist/components/ds-link.js +5 -5
  65. package/dist/components/ds-text-input.js +58 -29
  66. package/dist/components/ds-visually-hidden2.js +1 -1
  67. package/dist/components/index.js +1 -0
  68. package/dist/components/index2.js +15 -1
  69. package/dist/components/linkUtils.js +1 -10
  70. package/dist/components/store.js +204 -0
  71. package/dist/esm/component-library.js +3 -3
  72. package/dist/esm/ds-accordion_3.entry.js +11 -11
  73. package/dist/esm/ds-checkbox-group.entry.js +15 -16
  74. package/dist/esm/ds-checkbox.entry.js +42 -35
  75. package/dist/esm/ds-input-validity.entry.js +4 -6
  76. package/dist/esm/ds-link-with-arrow.entry.js +5 -5
  77. package/dist/esm/ds-link.entry.js +5 -5
  78. package/dist/esm/ds-text-input.entry.js +52 -24
  79. package/dist/esm/ds-visually-hidden.entry.js +2 -2
  80. package/dist/esm/{index-50783b0c.js → index-434995e1.js} +15 -1
  81. package/dist/esm/index.js +2 -1
  82. package/dist/esm/{linkUtils-fe63ff72.js → linkUtils-3d1b28cf.js} +1 -10
  83. package/dist/esm/loader.js +3 -3
  84. package/dist/esm/store-b8d17c10.js +204 -0
  85. package/dist/esm/{utils-b5843ae1.js → utils-5daa5bc0.js} +10 -1
  86. package/dist/types/components/00-foundations/types.d.ts +3 -0
  87. package/dist/types/components/01-base-components/ds-checkbox/ds-checkbox.d.ts +14 -14
  88. package/dist/types/components/01-base-components/ds-checkbox-group/ds-checkbox-group.d.ts +14 -16
  89. package/dist/types/components/01-base-components/ds-link/ds-link.d.ts +1 -1
  90. package/dist/types/components/01-base-components/ds-link-with-arrow/ds-link-with-arrow.d.ts +1 -1
  91. package/dist/types/components/01-base-components/ds-text-input/ds-text-input.d.ts +17 -8
  92. package/dist/types/components/01-base-components/ds-text-input/stories/ds-text-input.examples.stories.d.ts +1 -0
  93. package/dist/types/components/01-base-components/ds-text-input/utils.d.ts +1 -1
  94. package/dist/types/components.d.ts +42 -28
  95. package/dist/types/index.d.ts +1 -0
  96. package/dist/types/store.d.ts +10 -0
  97. package/dist/types/utils/link/linkUtils.d.ts +0 -1
  98. package/dist/types/utils/utils.d.ts +1 -0
  99. package/package.json +3 -2
  100. package/dist/component-library/utils-b5843ae1.js +0 -1
@@ -1,7 +1,8 @@
1
1
  import { Fragment, h } from "@stencil/core";
2
2
  import classNames from "classnames";
3
- import { idGenerator } from "../../../utils/utils";
4
3
  import { getOptionalText, getRequiredText } from "../../../utils/controls/controlUtils";
4
+ import { isValidation } from "../../../store";
5
+ import { idGenerator, getAriaLabel } from "../../../utils/utils";
5
6
  const INPUT_TYPE_ICONS_MAP = {
6
7
  search: 'search',
7
8
  };
@@ -10,23 +11,21 @@ const INPUT_TYPE_ACTION_BUTTON_ICON_MAP = {
10
11
  password: ({ passwordInputVisible }) => (passwordInputVisible ? 'visibility_off_fill' : 'visibility_fill'),
11
12
  };
12
13
  const inputIdGenerator = idGenerator('ds-input');
13
- const assistiveTextIdGenerator = idGenerator('ds-assistive-text');
14
- const visuallyHiddenAssistiveTextIdGenerator = idGenerator('visually-hidden-assistive-text');
15
- const successTextIdGenerator = idGenerator('success-text');
16
- const errorTextIdGenerator = idGenerator('error-text');
17
14
  export class DsTextInput {
18
15
  suffixButtonElement;
19
16
  inputElement;
20
- assistiveTextId = assistiveTextIdGenerator.next().value;
21
- visuallyHiddenAssistiveTextId = visuallyHiddenAssistiveTextIdGenerator.next().value;
22
- successTextId = successTextIdGenerator.next().value;
23
- errorTextId = errorTextIdGenerator.next().value;
17
+ assistiveTextId;
18
+ visuallyHiddenAssistiveTextId;
19
+ errorTextId;
20
+ successTextId;
24
21
  hasPrefixSlot = false;
25
22
  hasSuffixSlot = false;
26
23
  el;
24
+ internals;
25
+ clear;
27
26
  label;
28
27
  placeholder;
29
- dsId = inputIdGenerator.next().value;
28
+ identifier = inputIdGenerator.next().value;
30
29
  name;
31
30
  disabled;
32
31
  optional;
@@ -55,6 +54,14 @@ export class DsTextInput {
55
54
  clearButtonVisible = false;
56
55
  passwordInputVisible = false;
57
56
  inputActive = false;
57
+ validationMessage;
58
+ setIds = () => {
59
+ this.assistiveTextId = `${this.identifier}-assistive-text`;
60
+ this.visuallyHiddenAssistiveTextId = `${this.identifier}-visually-hidden-assistive-text`;
61
+ this.errorTextId = `${this.identifier}-error-text`;
62
+ this.successTextId = `${this.identifier}-success-text`;
63
+ };
64
+ getValidationMessage = () => this.errorText || this.internals?.validationMessage || this.inputElement?.validationMessage;
58
65
  async togglePasswordVisibility() {
59
66
  return (this.passwordInputVisible = !this.passwordInputVisible);
60
67
  }
@@ -62,6 +69,7 @@ export class DsTextInput {
62
69
  this.inputElement.value = '';
63
70
  this.inputElement.focus();
64
71
  this.clearButtonVisible = false;
72
+ this.clear.emit({ id: this.identifier });
65
73
  }
66
74
  getLabelText = () => {
67
75
  if (this.required) {
@@ -73,9 +81,27 @@ export class DsTextInput {
73
81
  return this.label;
74
82
  };
75
83
  componentWillLoad() {
84
+ this.setIds();
76
85
  this.hasPrefixSlot = !!this.el.querySelector('[slot="prefix"]');
77
86
  this.hasSuffixSlot = !!this.el.querySelector('[slot="suffix"]');
87
+ if (isValidation('server') || this.errorText) {
88
+ this.validationMessage = this.getValidationMessage();
89
+ }
78
90
  }
91
+ handleInput = (e) => {
92
+ const target = e.target;
93
+ this.clearButtonVisible = !!target.value;
94
+ this.internals?.setFormValue(target.value);
95
+ if (isValidation('client') && this.validationMessage) {
96
+ this.validationMessage = this.getValidationMessage();
97
+ }
98
+ };
99
+ handleBlur = () => {
100
+ this.hasFocus = false;
101
+ if (isValidation('client')) {
102
+ this.validationMessage = this.getValidationMessage();
103
+ }
104
+ };
79
105
  onActionButtonClicked = (e) => {
80
106
  e.stopPropagation();
81
107
  switch (this.type) {
@@ -87,13 +113,6 @@ export class DsTextInput {
87
113
  return;
88
114
  }
89
115
  };
90
- renderValidityMessage(type) {
91
- const textId = type === 'success' ? this.successTextId : this.errorTextId;
92
- const text = type === 'success' ? this.successText : this.errorText;
93
- const icon = type === 'success' ? 'check_circle_fill' : 'warning_fill';
94
- const className = type + '-text';
95
- return (h("slot", { name: className }, text && (h("div", { class: `${className}--container` }, h("ds-icon", { name: icon }), h("small", { id: textId, class: className }, text)))));
96
- }
97
116
  renderPrefixContent() {
98
117
  if (this.hasPrefixSlot) {
99
118
  return h("slot", { name: "prefix" });
@@ -128,21 +147,22 @@ export class DsTextInput {
128
147
  }
129
148
  render() {
130
149
  const inputType = this.type === 'password' && this.passwordInputVisible ? 'text' : this.type;
131
- return (h(Fragment, { key: '4d3ad7cc3f0d7c6aba4bcb8e5b05d0794b614f32' }, h("div", { key: '1cad6e50d1a9c0f4214824d1ff46a8418a095790', class: "ds-input--label-container" }, h("slot", { key: '67d096bb1eecd6ac492a5dcd14bd6f9bda21eb2c', name: "label" }, h("label", { key: 'cfffb9b06f2122dd80e4ad94831ca69b71e5a0de', htmlFor: this.dsId }, this.getLabelText())), h("slot", { key: '2256dfda0cf19eae50307b9badc2a2a97d9e190b', name: "help-text" }, h("small", { key: 'b9496a9afec60a4a64a0ff66505a7572362387ac', id: this.assistiveTextId }, this.assistiveText), h("ds-visually-hidden", { key: '23026b2453728e607802aabb7760f07229edeb7c', id: this.visuallyHiddenAssistiveTextId }, this.hiddenAssistiveText))), h("div", { key: '161a4d4eed706c5fd6ba2af90029e68b1c6b95c9', onMouseDown: () => (this.inputActive = true), onMouseUp: () => (this.inputActive = false), onClick: e => this.handleInputContainerClick(e), class: classNames('ds-input--container', {
150
+ return (h(Fragment, { key: 'efb783f742bb82b01fd6807a628eb693666a819b' }, h("div", { key: 'dde260b136af4b68de1fa15928529f5e57f54c3a', class: "ds-input--label-container" }, h("slot", { key: 'e7ba428a8b8202c9b3e4d9a9c6d4257b0b48d83a', name: "label" }, h("label", { key: '1f28c5fd53249068de50c6d0ea0aa88ccf65a1ec', htmlFor: this.identifier }, this.getLabelText())), h("slot", { key: 'e3c1ea925cfc7f9599ee651da0aeaab98fa806bb', name: "help-text" }, h("small", { key: '671ab99029e2775d964feb012beb8a20912be5e3', id: this.assistiveTextId }, this.assistiveText), h("ds-visually-hidden", { key: '8eb744be9b95ddceb1dd5bed0274d29a26e7ec1d', id: this.visuallyHiddenAssistiveTextId }, this.hiddenAssistiveText))), h("div", { key: 'b7fa7067a52d176b810eb88777423adf50dfd8b9', onMouseDown: () => (this.inputActive = true), onMouseUp: () => (this.inputActive = false), onClick: e => this.handleInputContainerClick(e), class: classNames('ds-input--container', {
132
151
  disabled: this.disabled,
133
152
  readonly: this.readonly,
134
153
  valid: !!this.successText,
135
154
  invalid: !!this.errorText,
136
155
  focus: this.hasFocus,
137
156
  active: !!this.inputActive,
138
- }) }, this.renderPrefixContent(), h("input", { key: 'a04e9ed4de86a65290206ca62efde1c27d76aa80', ref: e => (this.inputElement = e), id: this.dsId, name: this.name, "aria-label": this.ariaLabel, "aria-labelledby": this.ariaLabelledBy, "aria-describedby": this.ariaDescribedby ||
157
+ }) }, this.renderPrefixContent(), h("input", { key: 'f619722a0c088fbd99d851b4cc49a220538da0ae', ref: e => (this.inputElement = e), id: this.identifier, name: this.name, "aria-label": getAriaLabel(this.label, this.ariaLabel), "aria-labelledby": this.ariaLabelledBy, "aria-describedby": this.ariaDescribedby ||
139
158
  classNames(this.assistiveTextId, this.visuallyHiddenAssistiveTextId, {
140
- [this.successTextId]: this.successText,
141
- [this.errorTextId]: this.errorText,
142
- }), disabled: this.disabled, required: this.required, readonly: this.readonly, value: this.value, type: inputType, min: this.min, max: this.max, maxlength: this.maxlength, pattern: this.pattern, placeholder: this.placeholder, autocomplete: this.autocomplete, onInput: e => (this.clearButtonVisible = !!e.target.value), onFocus: () => (this.hasFocus = true), onBlur: () => (this.hasFocus = false) }), this.renderSuffixContent()), this.renderValidityMessage('error'), this.renderValidityMessage('success')));
159
+ [this.errorTextId]: Boolean(this.validationMessage),
160
+ [this.successTextId]: Boolean(this.successText),
161
+ }), "aria-invalid": Boolean(this.validationMessage) ? 'true' : 'false', disabled: this.disabled, required: this.required, readonly: this.readonly, value: this.value, type: inputType, min: this.min, max: this.max, maxlength: this.maxlength, pattern: this.pattern, placeholder: this.placeholder, autocomplete: this.autocomplete, onInput: this.handleInput, onFocus: () => (this.hasFocus = true), onBlur: this.handleBlur }), this.renderSuffixContent()), h("slot", { key: 'b70c638ad0de13e0bfa1c2f0ec366e748ab8e4e2', name: "input-validity" }, h("ds-input-validity", { key: '7c1da6ba8d42add8de43f4926c24c8a64bbe32e2', id: this.errorTextId, text: this.validationMessage, type: "error", role: "alert" }), h("ds-input-validity", { key: '46258021c17e3461ea4a0c2ae720fb44305550c5', id: this.successTextId, text: this.successText, type: "success", role: "status" }))));
143
162
  }
144
163
  static get is() { return "ds-text-input"; }
145
164
  static get encapsulation() { return "scoped"; }
165
+ static get formAssociated() { return true; }
146
166
  static get originalStyleUrls() {
147
167
  return {
148
168
  "$": ["ds-text-input.scss"]
@@ -193,7 +213,7 @@ export class DsTextInput {
193
213
  "attribute": "placeholder",
194
214
  "reflect": false
195
215
  },
196
- "dsId": {
216
+ "identifier": {
197
217
  "type": "string",
198
218
  "mutable": false,
199
219
  "complexType": {
@@ -598,13 +618,13 @@ export class DsTextInput {
598
618
  "type": "string",
599
619
  "mutable": false,
600
620
  "complexType": {
601
- "original": "TextInputType",
621
+ "original": "DsTextInputType",
602
622
  "resolved": "\"email\" | \"loading\" | \"number\" | \"password\" | \"search\" | \"tel\" | \"text\" | \"url\"",
603
623
  "references": {
604
- "TextInputType": {
624
+ "DsTextInputType": {
605
625
  "location": "import",
606
626
  "path": "./utils",
607
- "id": "src/components/01-base-components/ds-text-input/utils.ts::TextInputType"
627
+ "id": "src/components/01-base-components/ds-text-input/utils.ts::DsTextInputType"
608
628
  }
609
629
  }
610
630
  },
@@ -684,9 +704,34 @@ export class DsTextInput {
684
704
  "hasFocus": {},
685
705
  "clearButtonVisible": {},
686
706
  "passwordInputVisible": {},
687
- "inputActive": {}
707
+ "inputActive": {},
708
+ "validationMessage": {}
688
709
  };
689
710
  }
711
+ static get events() {
712
+ return [{
713
+ "method": "clear",
714
+ "name": "clear",
715
+ "bubbles": true,
716
+ "cancelable": true,
717
+ "composed": true,
718
+ "docs": {
719
+ "tags": [],
720
+ "text": ""
721
+ },
722
+ "complexType": {
723
+ "original": "DsTextInputClearEvent",
724
+ "resolved": "DsEvent",
725
+ "references": {
726
+ "DsTextInputClearEvent": {
727
+ "location": "local",
728
+ "path": "/Users/teemuparssinen/hy/uh-design-system/component-library/packages/component-library/src/components/01-base-components/ds-text-input/ds-text-input.tsx",
729
+ "id": "src/components/01-base-components/ds-text-input/ds-text-input.tsx::DsTextInputClearEvent"
730
+ }
731
+ }
732
+ }
733
+ }];
734
+ }
690
735
  static get methods() {
691
736
  return {
692
737
  "togglePasswordVisibility": {
@@ -726,4 +771,5 @@ export class DsTextInput {
726
771
  };
727
772
  }
728
773
  static get elementRef() { return "el"; }
774
+ static get attachInternalsMemberName() { return "internals"; }
729
775
  }
@@ -1,4 +1,6 @@
1
1
  import { html } from "lit";
2
+ import { getDsElem } from "../../../../utils/tests/testUtils";
3
+ import { litTemplateResultToString } from "../../../../utils/utils";
2
4
  const meta = {
3
5
  title: 'Base Components/TextInput/Examples',
4
6
  component: 'ds-text-input',
@@ -27,12 +29,31 @@ export const UsingSlots = {
27
29
  <p slot='help-text'>Lorem ipsum</p>
28
30
  <ds-icon name='archive' slot='prefix'></ds-icon>
29
31
  <small slot='suffix'>Suffix</small>
30
- <div slot='error-text'>Error text slot</div>
31
- <div slot='success-text'>Success text slot</div>
32
+ <div slot='input-validity'>Validity slot</div>
32
33
  </ds-text-input>
33
34
  `,
34
35
  };
36
+ const formValidationDOM = html `
37
+ <form class="ds-sb-form-validation">
38
+ <ds-text-input type="number" label="Minimum value" id="min" name="min" min="5" required></ds-text-input>
39
+ <ds-text-input type="number" label="Maximum value" id="max" name="max" min="100" required></ds-text-input>
40
+ <ds-text-input type="email" label="Email" id="email" name="email" required></ds-text-input>
41
+ <ds-text-input type="tel" label="Telephone" id="tel" name="tel" required></ds-text-input>
42
+ <ds-text-input type="password" label="Password" id="password" name="password" required action-button-aria-label="password toggle"></ds-text-input>
43
+ <ds-text-input type="url" label="Url" id="url" name="url" required></ds-text-input>
44
+ <div class="button-group ds-sb-form-validation__buttons">
45
+ <ds-button type="submit" value="Submit"></ds-button>
46
+ </div>
47
+ </form>
48
+ `;
35
49
  export const FormValidation = {
50
+ parameters: {
51
+ docs: {
52
+ source: {
53
+ code: litTemplateResultToString(formValidationDOM),
54
+ },
55
+ },
56
+ },
36
57
  render: () => html `
37
58
  <style>
38
59
  .ds-sb-form-validation {
@@ -44,16 +65,64 @@ export const FormValidation = {
44
65
  align-self: flex-end;
45
66
  }
46
67
  </style>
47
- <form class="ds-sb-form-validation">
48
- <ds-text-input type="number" label="Minimum value" id="min" name="min" min="5" required></ds-text-input>
49
- <ds-text-input type="number" label="Maximum value" id="max" name="max" min="100" required></ds-text-input>
50
- <ds-text-input type="email" label="Email" id="email" name="email" required></ds-text-input>
51
- <ds-text-input type="tel" label="Telephone" id="tel" name="tel" required></ds-text-input>
52
- <ds-text-input type="password" label="Password" id="password" name="password" required action-button-aria-label="password toggle"></ds-text-input>
53
- <ds-text-input type="url" label="Url" id="url" name="url" required></ds-text-input>
54
- <div class="button-group ds-sb-form-validation__buttons">
55
- <ds-button type="submit" value="Submit"></ds-button>
56
- </div>
57
- </form>
68
+ ${formValidationDOM}
69
+ `,
70
+ };
71
+ const clientSideValidationDOM = html `
72
+ <div class="ds-sb-client-side-validation">
73
+ <div id="example-error-container">
74
+ <ds-text-input id="example-error" label="Error message" assistive-text='Type "error" and move to next input to display a validation message.'></ds-text-input>
75
+ </div>
76
+ <div id="example-success-container">
77
+ <ds-text-input id="example-success" label="Success message" assistive-text='Type "success" and move to next input to display a validation message.'></ds-text-input>
78
+ </div>
79
+ </div>
80
+ `;
81
+ export const ClientSideValidation = {
82
+ parameters: {
83
+ docs: {
84
+ source: {
85
+ code: litTemplateResultToString(clientSideValidationDOM),
86
+ },
87
+ story: {
88
+ autoplay: true,
89
+ },
90
+ },
91
+ },
92
+ render: () => html `
93
+ <style>
94
+ .ds-sb-client-side-validation {
95
+ display: flex;
96
+ flex-direction: column;
97
+ gap: 1rem;
98
+ }
99
+ </style>
100
+ ${clientSideValidationDOM}
58
101
  `,
102
+ play: async ({ canvasElement }) => {
103
+ const errorContainerElem = canvasElement.querySelector('#example-error-container');
104
+ const successContainerElem = canvasElement.querySelector('#example-success-container');
105
+ const errorElem = await getDsElem(canvasElement, 'ds-text-input#example-error');
106
+ const successElem = await getDsElem(canvasElement, 'ds-text-input#example-success');
107
+ errorContainerElem.addEventListener('input', (e) => {
108
+ const target = e.target;
109
+ switch (target.value) {
110
+ case 'error':
111
+ return errorElem.errorText = 'Error message';
112
+ default:
113
+ errorElem.errorText = "";
114
+ return;
115
+ }
116
+ });
117
+ successContainerElem.addEventListener('input', (e) => {
118
+ const target = e.target;
119
+ switch (target.value) {
120
+ case 'success':
121
+ return successElem.successText = 'Success message';
122
+ default:
123
+ successElem.successText = "";
124
+ return;
125
+ }
126
+ });
127
+ },
59
128
  };
@@ -1,5 +1,5 @@
1
- import { textInputTypes } from "../utils";
2
1
  import { icons } from "../../../00-foundations/icons/iconList";
2
+ import { textInputTypes } from "../utils";
3
3
  const meta = {
4
4
  title: 'Base Components/TextInput',
5
5
  component: 'ds-text-input',
@@ -17,7 +17,7 @@ export const Playground = {
17
17
  argTypes: {
18
18
  label: { control: 'text' },
19
19
  placeholder: { control: 'text' },
20
- dsId: { control: 'text' },
20
+ identifier: { control: 'text' },
21
21
  name: { control: 'text' },
22
22
  disabled: { control: 'boolean' },
23
23
  required: { control: 'boolean' },
@@ -40,15 +40,15 @@ export const Playground = {
40
40
  control: 'select',
41
41
  options: textInputTypes,
42
42
  },
43
- ariaLabel: { control: 'text' },
44
- ariaLabelledBy: { control: 'text' },
45
- ariaDescribedby: { control: 'text' },
43
+ ariaLabel: { name: 'aria-label', control: 'text' },
44
+ ariaLabelledBy: { name: 'aria-labelledby', control: 'text' },
45
+ ariaDescribedby: { name: 'aria-describedby', control: 'text' },
46
46
  autocomplete: { control: 'text' },
47
47
  },
48
48
  args: {
49
49
  label: 'Label',
50
50
  placeholder: '',
51
- dsId: 'input',
51
+ identifier: 'input',
52
52
  name: '',
53
53
  disabled: false,
54
54
  required: false,
@@ -57,7 +57,6 @@ export const Playground = {
57
57
  min: -1,
58
58
  max: -1,
59
59
  maxlength: -1,
60
- pattern: '',
61
60
  assistiveText: '',
62
61
  prefixText: '',
63
62
  suffixText: '',
@@ -1,10 +1 @@
1
- export const textInputTypes = [
2
- 'text',
3
- 'password',
4
- 'search',
5
- 'loading',
6
- 'tel',
7
- 'email',
8
- 'url',
9
- 'number',
10
- ];
1
+ export const textInputTypes = ['text', 'password', 'search', 'loading', 'tel', 'email', 'url', 'number'];
@@ -1,7 +1,7 @@
1
1
  import { h } from "@stencil/core";
2
2
  export class DsVisuallyHidden {
3
3
  render() {
4
- return (h("slot", { key: '4307602964aa15c8d3f4fb0f4b89188cf0a8b55e' }));
4
+ return (h("slot", { key: '083eaed9210a85360479b367769c8904a6089f64' }));
5
5
  }
6
6
  static get is() { return "ds-visually-hidden"; }
7
7
  static get encapsulation() { return "shadow"; }
@@ -1 +1 @@
1
- export {};
1
+ export { configure } from './store';
@@ -0,0 +1,13 @@
1
+ import { createStore } from "@stencil/store";
2
+ ;
3
+ const initialState = {
4
+ validation: 'client',
5
+ };
6
+ const { state, set } = createStore({
7
+ ...initialState,
8
+ });
9
+ export const isValidation = (validation) => state.validation === validation;
10
+ export const configure = ({ validation }) => {
11
+ set('validation', validation || initialState.validation);
12
+ };
13
+ export default state;
@@ -9,12 +9,3 @@ export const visuallyHiddenAssistiveText = (lang) => {
9
9
  return 'Opens in a new tab';
10
10
  }
11
11
  };
12
- export const getAriaLabel = (text, ariaLabel) => {
13
- if (!ariaLabel) {
14
- return undefined;
15
- }
16
- if (ariaLabel.startsWith(text)) {
17
- return ariaLabel;
18
- }
19
- return [text, ariaLabel].join(' ');
20
- };
@@ -56,3 +56,12 @@ export function* idGenerator(id) {
56
56
  yield `${id}-${currentId++}`;
57
57
  }
58
58
  }
59
+ export const getAriaLabel = (text, ariaLabel) => {
60
+ if (!ariaLabel) {
61
+ return undefined;
62
+ }
63
+ if (ariaLabel.startsWith(text)) {
64
+ return ariaLabel;
65
+ }
66
+ return [text, ariaLabel].join(' ');
67
+ };
@@ -1 +1 @@
1
- import{p as e,b as i}from"./index-50783b0c.js";export{s as setNonce}from"./index-50783b0c.js";import{g as t}from"./app-globals-0f993ce5.js";(()=>{const i=import.meta.url,t={};return""!==i&&(t.resourcesUrl=new URL(".",i).href),e(t)})().then((async e=>(await t(),i([["ds-accordion_3",[[1,"ds-accordion",{variant:[1],borderAligned:[4,"border-aligned"],openByDefault:[4,"open-by-default"],accordionId:[1,"accordion-id"],headingLevel:[2,"heading-level"],useCloseButton:[4,"use-close-button"],closeButtonLabel:[1,"close-button-label"],hideTopBorder:[4,"hide-top-border"],isExpanded:[32]},null,{isExpanded:["watchHandler"]}],[6,"ds-button",{value:[1],variant:[1],colour:[1],size:[1],fontWeight:[1,"font-weight"],icon:[1],iconPosition:[1,"icon-position"],type:[1],disabled:[4],fullWidth:[4,"full-width"],ariaDisabled:[1,"aria-disabled"]}],[1,"ds-icon",{name:[1],colour:[1],size:[1],dsTitle:[1,"title"],role:[1],hidden:[4],message:[32]}]]],["ds-checkbox-group",[[1,"ds-checkbox-group",{legend:[1],assistiveText:[1,"assistive-text"],direction:[1],errorText:[1,"error-text"],text:[1],checked:[1028],checkedChildElementCount:[1026,"checked-child-element-count"],disabled:[4],parentCheckedCount:[2,"parent-checked-count"],childElementsCount:[32],isIndeterminate:[32],indeterminateChildCheckboxCount:[32],setChecked:[64]},[[0,"dsCheckboxGroupIndeterminateChildChange","handleIndeterminateChildChange"],[0,"dsCheckboxChange","handleCheckboxChange"],[0,"dsCheckboxGroupChange","handleCheckboxGroupChange"]],{disabled:["handleCheckboxDisabledChange"],checked:["handleCheckedChange"],isIndeterminate:["handleIndeterminateChange"],checkedChildElementCount:["handleCheckedChildElementCountChange"]}]]],["ds-visually-hidden",[[1,"ds-visually-hidden"]]],["ds-text-input",[[6,"ds-text-input",{label:[1],placeholder:[1],dsId:[1,"id"],name:[1],disabled:[4],optional:[4],required:[4],readonly:[4],value:[1],min:[2],max:[2],maxlength:[2],pattern:[1],autocomplete:[1],optionalText:[1,"optional-text"],errorText:[1,"error-text"],successText:[1,"success-text"],assistiveText:[1,"assistive-text"],actionButtonAriaLabel:[1,"action-button-aria-label"],hiddenAssistiveText:[1,"hidden-assistive-text"],prefixText:[1,"prefix-text"],suffixText:[1,"suffix-text"],icon:[1],type:[1],ariaLabel:[1,"aria-label"],ariaLabelledBy:[1,"aria-labelledby"],ariaDescribedby:[1,"aria-describedby"],hasFocus:[32],clearButtonVisible:[32],passwordInputVisible:[32],inputActive:[32],togglePasswordVisibility:[64],clearInput:[64]}]]],["ds-link",[[1,"ds-link",{text:[1],size:[1],variant:[1],weight:[1],icon:[1025],iconPosition:[1025,"icon-position"],iconTitle:[1,"icon-title"],iconHidden:[4,"icon-hidden"],href:[1],target:[1],download:[4],language:[1,"lang"],linkAriaLabel:[1,"aria-label"]}]]],["ds-link-with-arrow",[[1,"ds-link-with-arrow",{text:[1],iconPosition:[1,"icon-position"],href:[1],target:[1],language:[1,"lang"],linkAriaLabel:[1,"aria-label"]}]]],["ds-input-validity",[[0,"ds-input-validity",{text:[1],type:[1],validityRole:[1,"role"],identifier:[32]}]]],["ds-checkbox",[[65,"ds-checkbox",{checkboxId:[1025,"id"],checked:[1028],legend:[1],assistiveText:[1,"assistive-text"],text:[1],indeterminate:[4],disabled:[4],errorText:[1,"error-text"],errorsDisabled:[4,"data-errors-disabled"],required:[4],optional:[4],optionalText:[1,"optional-text"],ariaLabel:[32],value:[32],validationMessage:[32]}]]]],e))));
1
+ import{p as e,b as i}from"./index-434995e1.js";export{s as setNonce}from"./index-434995e1.js";import{g as t}from"./app-globals-0f993ce5.js";(()=>{const i=import.meta.url,t={};return""!==i&&(t.resourcesUrl=new URL(".",i).href),e(t)})().then((async e=>(await t(),i([["ds-accordion_3",[[1,"ds-accordion",{variant:[1],borderAligned:[4,"border-aligned"],openByDefault:[4,"open-by-default"],accordionId:[1,"accordion-id"],headingLevel:[2,"heading-level"],useCloseButton:[4,"use-close-button"],closeButtonLabel:[1,"close-button-label"],hideTopBorder:[4,"hide-top-border"],isExpanded:[32]},null,{isExpanded:["watchHandler"]}],[6,"ds-button",{value:[1],variant:[1],colour:[1],size:[1],fontWeight:[1,"font-weight"],icon:[1],iconPosition:[1,"icon-position"],type:[1],disabled:[4],fullWidth:[4,"full-width"],ariaDisabled:[1,"aria-disabled"]}],[1,"ds-icon",{name:[1],colour:[1],size:[1],dsTitle:[1,"title"],role:[1],hidden:[4],message:[32]}]]],["ds-input-validity",[[0,"ds-input-validity",{text:[1],type:[1],validityRole:[1,"role"],identifier:[32]}]]],["ds-text-input",[[70,"ds-text-input",{label:[1],placeholder:[1],identifier:[1,"id"],name:[1],disabled:[4],optional:[4],required:[4],readonly:[4],value:[1],min:[2],max:[2],maxlength:[2],pattern:[1],autocomplete:[1],optionalText:[1,"optional-text"],errorText:[1,"error-text"],successText:[1,"success-text"],assistiveText:[1,"assistive-text"],actionButtonAriaLabel:[1,"action-button-aria-label"],hiddenAssistiveText:[1,"hidden-assistive-text"],prefixText:[1,"prefix-text"],suffixText:[1,"suffix-text"],icon:[1],type:[1],ariaLabel:[1,"aria-label"],ariaLabelledBy:[1,"aria-labelledby"],ariaDescribedby:[1,"aria-describedby"],hasFocus:[32],clearButtonVisible:[32],passwordInputVisible:[32],inputActive:[32],validationMessage:[32],togglePasswordVisibility:[64],clearInput:[64]}]]],["ds-checkbox",[[65,"ds-checkbox",{identifier:[1,"id"],checked:[1028],legend:[1],assistiveText:[1,"assistive-text"],text:[1],indeterminate:[4],disabled:[4],errorText:[1,"error-text"],errorsDisabled:[4,"data-errors-disabled"],required:[4],optional:[4],optionalText:[1,"optional-text"],ariaLabel:[1,"aria-label"],value:[32],validationMessage:[32]}]]],["ds-checkbox-group",[[1,"ds-checkbox-group",{legend:[1],assistiveText:[1,"assistive-text"],direction:[1],errorText:[1,"error-text"],text:[1],checked:[4],disabled:[4],childElementsCount:[32],checkedChildElementCount:[32],isIndeterminate:[32],indeterminateChildCheckboxCount:[32],setChecked:[64]},[[0,"dsCheckboxGroupIndeterminateChildChange","listenIndeterminateChildChange"],[0,"dsCheckboxInput","listenCheckboxChange"],[0,"dsCheckboxGroupChange","listenCheckboxGroupChange"]],{disabled:["watchCheckboxDisabledChange"],checked:["watchCheckedChange"],isIndeterminate:["watchIndeterminateChange"],checkedChildElementCount:["watchCheckedChildElementCountChange"]}]]],["ds-visually-hidden",[[1,"ds-visually-hidden"]]],["ds-link",[[1,"ds-link",{text:[1],size:[1],variant:[1],weight:[1],icon:[1025],iconPosition:[1025,"icon-position"],iconTitle:[1,"icon-title"],iconHidden:[4,"icon-hidden"],href:[1],target:[1],download:[4],language:[1,"lang"],ariaLabel:[1,"aria-label"]}]]],["ds-link-with-arrow",[[1,"ds-link-with-arrow",{text:[1],iconPosition:[1,"icon-position"],href:[1],target:[1],language:[1,"lang"],ariaLabel:[1,"aria-label"]}]]]],e))));