@cfpb/cfpb-design-system 4.2.3 → 4.3.0

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 (147) hide show
  1. package/CHANGELOG.md +178 -1
  2. package/dist/base/index.css +1 -1
  3. package/dist/base/index.css.map +2 -2
  4. package/dist/base/index.js.map +1 -1
  5. package/dist/components/cfpb-buttons/index.css +1 -1
  6. package/dist/components/cfpb-buttons/index.css.map +2 -2
  7. package/dist/components/cfpb-buttons/index.js.map +1 -1
  8. package/dist/components/cfpb-expandables/index.css.map +1 -1
  9. package/dist/components/cfpb-expandables/index.js +1 -1
  10. package/dist/components/cfpb-expandables/index.js.map +3 -3
  11. package/dist/components/cfpb-forms/index.css +1 -1
  12. package/dist/components/cfpb-forms/index.css.map +2 -2
  13. package/dist/components/cfpb-forms/index.js +1 -1
  14. package/dist/components/cfpb-forms/index.js.map +2 -2
  15. package/dist/components/cfpb-layout/index.css +1 -1
  16. package/dist/components/cfpb-layout/index.css.map +1 -1
  17. package/dist/components/cfpb-notifications/index.css.map +1 -1
  18. package/dist/components/cfpb-pagination/index.css.map +1 -1
  19. package/dist/components/cfpb-tables/index.css.map +1 -1
  20. package/dist/components/cfpb-typography/index.css +1 -1
  21. package/dist/components/cfpb-typography/index.css.map +2 -2
  22. package/dist/components/cfpb-typography/index.js.map +1 -1
  23. package/dist/elements/cfpb-button/index.js +4 -4
  24. package/dist/elements/cfpb-button/index.js.map +3 -3
  25. package/dist/elements/cfpb-checkbox-icon/index.js +29 -0
  26. package/dist/elements/{cfpb-checkbox → cfpb-checkbox-icon}/index.js.map +4 -4
  27. package/dist/elements/cfpb-expandable/index.css +2 -0
  28. package/dist/elements/cfpb-expandable/index.css.map +7 -0
  29. package/dist/elements/cfpb-expandable/index.js +33 -0
  30. package/dist/elements/cfpb-expandable/index.js.map +7 -0
  31. package/dist/elements/cfpb-file-upload/index.js +4 -4
  32. package/dist/elements/cfpb-file-upload/index.js.map +3 -3
  33. package/dist/elements/cfpb-form-alert/index.js +32 -0
  34. package/dist/elements/cfpb-form-alert/index.js.map +7 -0
  35. package/dist/elements/cfpb-form-choice/index.js +12 -3
  36. package/dist/elements/cfpb-form-choice/index.js.map +4 -4
  37. package/dist/elements/cfpb-form-search/index.js +41 -0
  38. package/dist/elements/cfpb-form-search/index.js.map +7 -0
  39. package/dist/elements/cfpb-form-search-input/index.js +41 -0
  40. package/dist/elements/cfpb-form-search-input/index.js.map +7 -0
  41. package/dist/elements/cfpb-icon-text/index.js +3 -3
  42. package/dist/elements/cfpb-icon-text/index.js.map +3 -3
  43. package/dist/elements/cfpb-label/index.js +3 -3
  44. package/dist/elements/cfpb-label/index.js.map +2 -2
  45. package/dist/elements/cfpb-list/index.js +39 -0
  46. package/dist/elements/cfpb-list/index.js.map +7 -0
  47. package/dist/elements/cfpb-list-item/index.js +39 -0
  48. package/dist/elements/cfpb-list-item/index.js.map +7 -0
  49. package/dist/elements/cfpb-multiselect/index.js +13 -4
  50. package/dist/elements/cfpb-multiselect/index.js.map +4 -4
  51. package/dist/elements/cfpb-pagination/index.js +3 -3
  52. package/dist/elements/cfpb-pagination/index.js.map +2 -2
  53. package/dist/elements/cfpb-select/index.css +2 -0
  54. package/dist/elements/cfpb-select/index.css.map +7 -0
  55. package/dist/elements/cfpb-select/index.js +42 -0
  56. package/dist/elements/cfpb-select/index.js.map +7 -0
  57. package/dist/elements/cfpb-select-list/index.js +39 -0
  58. package/dist/elements/cfpb-select-list/index.js.map +7 -0
  59. package/dist/elements/cfpb-tag-filter/index.js +3 -3
  60. package/dist/elements/cfpb-tag-filter/index.js.map +3 -3
  61. package/dist/elements/cfpb-tag-group/index.js +3 -3
  62. package/dist/elements/cfpb-tag-group/index.js.map +4 -4
  63. package/dist/elements/cfpb-tag-topic/index.js +4 -4
  64. package/dist/elements/cfpb-tag-topic/index.js.map +2 -2
  65. package/dist/elements/index.css +2 -0
  66. package/dist/elements/index.css.map +7 -0
  67. package/dist/elements/index.js +7 -6
  68. package/dist/elements/index.js.map +4 -4
  69. package/dist/index.css +1 -1
  70. package/dist/index.css.map +2 -2
  71. package/dist/index.js +7 -6
  72. package/dist/index.js.map +4 -4
  73. package/dist/utilities/index.css.map +1 -1
  74. package/dist/utilities/index.js +1 -1
  75. package/dist/utilities/index.js.map +3 -3
  76. package/package.json +1 -1
  77. package/src/base/base.scss +1 -1
  78. package/src/components/cfpb-buttons/button-link.scss +0 -1
  79. package/src/components/cfpb-expandables/expandable.js +3 -0
  80. package/src/components/cfpb-forms/multiselect.js +1 -1
  81. package/src/components/cfpb-typography/mixins.scss +3 -0
  82. package/src/elements/abstracts/custom-props.css +123 -0
  83. package/src/elements/abstracts/grid-mixins.scss +83 -0
  84. package/src/elements/abstracts/heading-mixins.scss +346 -0
  85. package/src/elements/abstracts/index.scss +7 -0
  86. package/src/elements/abstracts/media-queries.scss +35 -0
  87. package/src/elements/abstracts/sizing-vars.scss +65 -0
  88. package/src/elements/abstracts/vars-breakpoints.scss +16 -0
  89. package/src/elements/abstracts/vars.css +79 -0
  90. package/src/elements/base/base.scss +375 -0
  91. package/src/elements/base/font.scss +27 -0
  92. package/src/elements/base/index.scss +3 -0
  93. package/src/elements/base/normalize.scss +290 -0
  94. package/src/elements/cfpb-button/cfpb-button-group.scss +10 -0
  95. package/src/elements/cfpb-button/cfpb-button-link.scss +96 -0
  96. package/src/elements/cfpb-button/cfpb-button.component.scss +11 -4
  97. package/src/elements/cfpb-button/cfpb-button.scss +222 -0
  98. package/src/elements/cfpb-button/index.js +28 -29
  99. package/src/elements/cfpb-button/vars.css +30 -0
  100. package/src/elements/cfpb-checkbox-icon/cfpb-checkbox-icon.component.scss +88 -0
  101. package/src/elements/cfpb-checkbox-icon/index.js +104 -0
  102. package/src/elements/cfpb-expandable/cfpb-expandable.component.scss +218 -0
  103. package/src/elements/cfpb-expandable/index.js +127 -0
  104. package/src/elements/cfpb-file-upload/cfpb-file-upload.component.scss +2 -2
  105. package/src/elements/cfpb-file-upload/index.js +16 -18
  106. package/src/elements/cfpb-form-alert/cfpb-form-alert.component.scss +36 -0
  107. package/src/elements/cfpb-form-alert/index.js +55 -0
  108. package/src/elements/cfpb-form-choice/cfpb-form-choice.component.scss +42 -81
  109. package/src/elements/cfpb-form-choice/index.js +58 -18
  110. package/src/elements/cfpb-form-search/cfpb-form-search.component.scss +54 -0
  111. package/src/elements/cfpb-form-search/index.js +194 -0
  112. package/src/elements/cfpb-form-search-input/cfpb-form-search-input.component.scss +217 -0
  113. package/src/elements/cfpb-form-search-input/index.js +136 -0
  114. package/src/elements/cfpb-icon-text/cfpb-icon-text.component.scss +32 -39
  115. package/src/elements/cfpb-icon-text/index.js +32 -104
  116. package/src/elements/cfpb-label/cfpb-label.component.scss +2 -2
  117. package/src/elements/cfpb-label/index.js +6 -9
  118. package/src/elements/cfpb-list/cfpb-list.component.scss +23 -0
  119. package/src/elements/cfpb-list/index.js +357 -0
  120. package/src/elements/cfpb-list/index.spec.js +169 -0
  121. package/src/elements/cfpb-list-item/cfpb-list-item.component.scss +69 -0
  122. package/src/elements/cfpb-list-item/index.js +215 -0
  123. package/src/elements/cfpb-pagination/cfpb-pagination.component.scss +2 -7
  124. package/src/elements/cfpb-pagination/index.js +6 -8
  125. package/src/elements/cfpb-select/cfpb-select.component.scss +241 -0
  126. package/src/elements/cfpb-select/index.js +381 -0
  127. package/src/elements/cfpb-tag-filter/cfpb-tag-filter.component.scss +6 -3
  128. package/src/elements/cfpb-tag-filter/index.js +15 -7
  129. package/src/elements/cfpb-tag-group/cfpb-tag-group.component.scss +2 -2
  130. package/src/elements/cfpb-tag-group/index.js +53 -6
  131. package/src/elements/cfpb-tag-topic/index.js +5 -7
  132. package/src/elements/cfpb-utilities/parse-child-data.js +50 -0
  133. package/src/elements/cfpb-utilities/parse-child-data.spec.js +56 -0
  134. package/src/elements/cfpb-utilities/search-service.js +46 -0
  135. package/src/elements/cfpb-utilities/search-service.spec.js +138 -0
  136. package/src/elements/cfpb-utilities/transition/transition.scss +98 -0
  137. package/src/elements/index.js +7 -1
  138. package/src/index.scss +11 -0
  139. package/src/tokens/abstracts/custom-props.json +1642 -0
  140. package/src/tokens/abstracts/vars.json +1319 -0
  141. package/src/tokens/cfpb-button/vars.json +436 -0
  142. package/src/utilities/transition/max-height-transition.js +74 -0
  143. package/dist/elements/cfpb-checkbox/index.js +0 -29
  144. package/src/elements/cfpb-multiselect/cfpb-multiselect.component.scss +0 -225
  145. package/src/elements/cfpb-multiselect/index.js +0 -444
  146. package/src/elements/cfpb-multiselect/multiselect-model.js +0 -288
  147. package/src/elements/cfpb-multiselect/multiselect-model.spec.js +0 -236
@@ -0,0 +1,194 @@
1
+ import { html, LitElement, css, unsafeCSS } from 'lit';
2
+ import styles from './cfpb-form-search.component.scss';
3
+ import { ref, createRef } from 'lit/directives/ref.js';
4
+ import { CfpbFormSearchInput } from '../cfpb-form-search-input';
5
+ import { SearchService } from '../cfpb-utilities/search-service.js';
6
+ import { CfpbList } from '../cfpb-list';
7
+ import { CfpbFormAlert } from '../cfpb-form-alert';
8
+
9
+ /**
10
+ * @element cfpb-form-search
11
+ */
12
+ export class CfpbFormSearch extends LitElement {
13
+ static styles = css`
14
+ ${unsafeCSS(styles)}
15
+ `;
16
+
17
+ static formAssociated = true;
18
+
19
+ /**
20
+ * @property {boolean} disabled - Whether the choice is disabled or not.
21
+ * @property {string} validation - Validation style: error, warning, success.
22
+ * @property {string} label - The aria-label for the input.
23
+ * @property {string} name - The name within a form.
24
+ * @property {string} value - The value within the input.
25
+ * @property {string} placeholder - The placeholder value.
26
+ * @property {string} maxlength - The maximum characters allowed in the input.
27
+ * @property {string} ariaLabelInput - aria-label for input.
28
+ * @property {string} ariaLabelButton - aria-label for button.
29
+ * @returns {object} The map of properties.
30
+ */
31
+ static get properties() {
32
+ return {
33
+ disabled: { type: Boolean },
34
+ validation: { type: String },
35
+ label: { type: String },
36
+ name: { type: String },
37
+ title: { type: Boolean, attribute: true },
38
+ value: { type: String },
39
+ maxlength: { type: Number },
40
+ placeholder: { type: String },
41
+ ariaLabelInput: { type: String, attribute: 'aria-label-input' },
42
+ ariaLabelButton: { type: String, attribute: 'aria-label-button' },
43
+ searchList: { type: Array },
44
+ };
45
+ }
46
+
47
+ #list = createRef();
48
+ #popup = createRef();
49
+
50
+ #internals;
51
+ #search;
52
+
53
+ constructor() {
54
+ super();
55
+
56
+ this.value = '';
57
+ this.#internals = this.attachInternals();
58
+ this.searchList = [];
59
+ }
60
+
61
+ #onSlotChange(evt) {
62
+ const slot = evt.target;
63
+
64
+ const list = slot
65
+ .assignedNodes({ flatten: true })
66
+ .filter(
67
+ (node) =>
68
+ node.nodeType === Node.ELEMENT_NODE &&
69
+ (node.tagName === 'UL' || node.tagName === 'OL'),
70
+ );
71
+
72
+ if (!list || !list[0]) {
73
+ return;
74
+ }
75
+
76
+ // Extract list items (with their text or link info)
77
+ const items = [...list[0].querySelectorAll('li')].map((li) => {
78
+ const link = li.querySelector('a');
79
+ if (link) {
80
+ return {
81
+ value: link.textContent.trim(),
82
+ href: link.getAttribute('href'),
83
+ };
84
+ }
85
+ return { value: li.textContent.trim() };
86
+ });
87
+
88
+ this.searchList = items;
89
+
90
+ this.#search = new SearchService(
91
+ items.map((item) => {
92
+ return item.value;
93
+ }),
94
+ );
95
+ }
96
+
97
+ #onClear() {
98
+ this.#popup.value.classList.remove('show');
99
+ this.#list.value.showAllItems();
100
+ }
101
+
102
+ #onInput(evt) {
103
+ if (evt.target.value.length > 1) {
104
+ this.#popup.value.classList.add('show');
105
+ if (this.#search) {
106
+ this.#list.value.filterItems(this.#search.search(evt.target.value));
107
+ }
108
+ } else {
109
+ this.#popup.value.classList.remove('show');
110
+ }
111
+
112
+ this.value = evt.target.value;
113
+ }
114
+
115
+ #onBlur() {
116
+ this.#popup.value.classList.remove('show');
117
+ }
118
+
119
+ get isSearchDisabled() {
120
+ return this.disabled || this.isOverMaxLength;
121
+ }
122
+
123
+ get isOverMaxLength() {
124
+ const isOverMax = this.value.length > this.maxlength;
125
+ if (isOverMax) this.validation = 'error';
126
+ else this.validation = '';
127
+ return isOverMax;
128
+ }
129
+
130
+ #onClickSearch(evt) {
131
+ evt.preventDefault();
132
+ if (this.disabled) return;
133
+
134
+ console.log(this.value);
135
+
136
+ if (this.value !== '') {
137
+ this.#internals.setFormValue(this.value);
138
+ this.#internals.form?.requestSubmit();
139
+ }
140
+ }
141
+
142
+ render() {
143
+ return html` <!--Light DOM content-->
144
+ <slot @slotchange=${this.#onSlotChange}></slot>
145
+
146
+ <!--Shadow DOM content-->
147
+ <div class="o-form-search">
148
+ <div class="container">
149
+ <cfpb-form-search-input
150
+ ?name=${this.name}
151
+ ?value=${this.value}
152
+ ?placeholder=${this.placeholder}
153
+ title=${this.title}
154
+ ?maxlength=${this.maxlength}
155
+ aria-label=${this.ariaLabelInput}
156
+ ?validation=${this.validation}
157
+ @clear=${this.#onClear}
158
+ @input=${this.#onInput}
159
+ @blur=${this.#onBlur}
160
+ ></cfpb-form-search-input>
161
+
162
+ <div class="popup" ${ref(this.#popup)}>
163
+ <cfpb-list .childData=${this.searchList} ${ref(this.#list)}>
164
+ </cfpb-list>
165
+ </div>
166
+ </div>
167
+
168
+ <button
169
+ class="a-btn"
170
+ type="submit"
171
+ aria-label="Search for term(s)"
172
+ ?disabled=${this.isSearchDisabled}
173
+ @click=${this.#onClickSearch}
174
+ >
175
+ Search
176
+ </button>
177
+ </div>
178
+
179
+ ${this.isOverMaxLength
180
+ ? html`<cfpb-form-alert validation="error">
181
+ Searches are limited to ${this.maxlength} characters.
182
+ </cfpb-form-alert>`
183
+ : null}`;
184
+ }
185
+
186
+ static init() {
187
+ CfpbFormSearchInput.init();
188
+ CfpbList.init();
189
+ CfpbFormAlert.init();
190
+
191
+ window.customElements.get('cfpb-form-search') ||
192
+ window.customElements.define('cfpb-form-search', CfpbFormSearch);
193
+ }
194
+ }
@@ -0,0 +1,217 @@
1
+ @use 'sass:math';
2
+ @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
3
+ @use '@cfpb/cfpb-design-system/src/components/cfpb-forms/text-input' as *;
4
+ @use '@cfpb/cfpb-design-system/src/components/cfpb-icons/icon' as *;
5
+
6
+ :host {
7
+ // Theme
8
+ --input-border-default: var(--gray-60); // $input-border
9
+ --input-border-disabled: var(--gray-60);
10
+ --input-border-success: var(--green);
11
+ --input-border-warning: var(--gold);
12
+ --input-border-error: var(--red);
13
+
14
+ // Private vars
15
+ --input-border: var(--input-border-default);
16
+
17
+ .o-search-input {
18
+ position: relative;
19
+ display: flex;
20
+ width: initial;
21
+ flex: 0 1 100%;
22
+
23
+ // Add a min-width for the default width of the text input + clear button,
24
+ // so that when the clear button appears it doesn't bump the input width.
25
+ min-width: 300px;
26
+
27
+ background: var(--white);
28
+
29
+ // Create a faux input border that includes the input and clear button.
30
+ border: 1px solid var(--input-border);
31
+ outline: 0 solid var(--input-border);
32
+
33
+ label {
34
+ position: absolute;
35
+ left: 10px;
36
+ align-self: center;
37
+ cursor: pointer;
38
+ line-height: math.div(
39
+ 14.4px,
40
+ $base-font-size-px
41
+ ); // 9px vertically centers icon.
42
+ }
43
+
44
+ // This line-height settings is taken from base.scss.
45
+ input {
46
+ line-height: math.div(19px, $base-font-size-px);
47
+ }
48
+
49
+ input[type='search'] {
50
+ font-size: 1rem;
51
+ width: 100%;
52
+ white-space: nowrap;
53
+ padding-left: 30px;
54
+ cursor: text;
55
+
56
+ // Remove default rounding in Safari.
57
+ appearance: none;
58
+
59
+ // Remove input border and re-create it around the input and clear X.
60
+ border: none;
61
+ box-shadow: none;
62
+ outline: none;
63
+ }
64
+
65
+ // Style the clear x button, and hide it by default.
66
+ button[type='reset'] {
67
+ display: none;
68
+ align-self: center;
69
+
70
+ color: var(--gray-40);
71
+ font-size: 20px;
72
+ border: 1px solid transparent;
73
+ background-color: transparent;
74
+ outline: 0;
75
+
76
+ // Set the touch target minimum for iOS.
77
+ width: 44px;
78
+ text-align: right;
79
+
80
+ > svg {
81
+ // Set width of SVG width to create a box for the focus rectangle.
82
+ width: 25px;
83
+
84
+ // Prevent targeting of button's internal SVG icon.
85
+ pointer-events: none;
86
+ }
87
+ }
88
+
89
+ button[type='reset']:hover {
90
+ color: var(--black);
91
+ cursor: pointer;
92
+ }
93
+
94
+ // Style the clear x focus rectangle.
95
+ button[type='reset']:focus {
96
+ color: var(--black);
97
+
98
+ // Put the focus rectangle on the icon
99
+ // because the button touch target is larger and would be lop-sided if
100
+ // we put the rectangle on the button.
101
+ > svg {
102
+ outline: 1px dotted var(--pacific);
103
+ }
104
+ }
105
+
106
+ // However, hide it if we haven't entered any text yet.
107
+ input[type='search']:placeholder-shown ~ button[type='reset'] {
108
+ display: none;
109
+ }
110
+
111
+ // Remove the default x mark in Chrome.
112
+ input[type='search']::-webkit-search-decoration,
113
+ input[type='search']::-webkit-search-cancel-button,
114
+ input[type='search']::-webkit-search-results-button,
115
+ input[type='search']::-webkit-search-results-decoration {
116
+ display: none;
117
+ }
118
+
119
+ &:hover,
120
+ &:focus-within {
121
+ border: 1px solid var(--pacific);
122
+ box-shadow: 0 0 0 1px var(--pacific);
123
+ outline-color: var(--pacific);
124
+ input[type='search'] {
125
+ outline: none;
126
+
127
+ // Remove the right-hand padding, because the clear button is showing.
128
+ padding-right: 0;
129
+ }
130
+ }
131
+
132
+ &:focus-within {
133
+ outline: 1px dotted var(--pacific);
134
+ outline-offset: 2px;
135
+ }
136
+
137
+ // Validation state coloring.
138
+ &--error,
139
+ &--warning,
140
+ &--success {
141
+ outline-width: 1px;
142
+ }
143
+
144
+ &--error {
145
+ --input-border: var(--input-border-error);
146
+ }
147
+
148
+ &--warning {
149
+ --input-border: var(--input-border-warning);
150
+ }
151
+
152
+ &--success {
153
+ --input-border: var(--input-border-success);
154
+ }
155
+
156
+ // Show the clear x button if we're focused within the search input area.
157
+ &:focus-within button[type='reset'],
158
+ &:hover button[type='reset'] {
159
+ display: flex;
160
+ justify-content: flex-end;
161
+ }
162
+ }
163
+
164
+ // If the value is on a search input by the backend, then the reset button
165
+ // will only reset the input back to initial value at page load. We add a
166
+ // small amount of JS to fully clear the input for this circumstance.
167
+ // However, this doesn't work when JS is disabled,
168
+ // so in that case we hide the reset button.
169
+ .no-js .o-search-input button[type='reset'] {
170
+ display: none !important;
171
+ }
172
+ }
173
+
174
+ :host([borderless]) {
175
+ .o-search-input {
176
+ border-color: transparent;
177
+
178
+ &:hover,
179
+ &:focus-within {
180
+ border-color: transparent;
181
+ box-shadow: 0 0 0 1px transparent;
182
+ outline-color: transparent;
183
+ }
184
+ }
185
+ }
186
+
187
+ :host([disabled]) {
188
+ --input-border: var(--input-border-disabled);
189
+
190
+ .o-search-input {
191
+ label,
192
+ input[type='search'] {
193
+ color: var(--input-border);
194
+ }
195
+
196
+ &:hover {
197
+ border: 1px solid var(--input-border);
198
+ box-shadow: none;
199
+
200
+ label,
201
+ input[type='search'] {
202
+ cursor: not-allowed;
203
+ }
204
+
205
+ button[type='reset'] {
206
+ display: none;
207
+ }
208
+ }
209
+
210
+ // Validation state coloring.
211
+ &--error:hover,
212
+ &--warning:hover,
213
+ &--success:hover {
214
+ outline-color: var(--input-border);
215
+ }
216
+ }
217
+ }
@@ -0,0 +1,136 @@
1
+ import { html, LitElement, css, unsafeCSS } from 'lit';
2
+ import { ref, createRef } from 'lit/directives/ref.js';
3
+ import styles from './cfpb-form-search-input.component.scss';
4
+ import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
5
+
6
+ import searchIcon from '../../components/cfpb-icons/icons/search.svg';
7
+ import clearIcon from '../../components/cfpb-icons/icons/error.svg';
8
+
9
+ /**
10
+ * @element cfpb-form-search-input
11
+ */
12
+ export class CfpbFormSearchInput extends LitElement {
13
+ static styles = css`
14
+ ${unsafeCSS(styles)}
15
+ `;
16
+
17
+ /**
18
+ * @property {boolean} disabled - Whether the input is disabled or not.
19
+ * @property {string} validation - Validation style: error, warning, success.
20
+ * @property {string} label - The aria-label for the input.
21
+ * @property {string} name - The name within a form.
22
+ * @property {string} value - The value within the input.
23
+ * @property {number} maxlength - The maximum characters allowed in the input.
24
+ * @property {string} placeholder - The placeholder value.
25
+ * @property {string} ariaLabelInput - aria-label for input.
26
+ * @property {string} ariaLabelButton - aria-label for button.
27
+ * @property {boolean} borderless - Whether the input has a border or not.
28
+ * @returns {object} The map of properties.
29
+ */
30
+ static properties = {
31
+ disabled: { type: Boolean, reflect: true },
32
+ validation: { type: String, reflect: true },
33
+ label: { type: String },
34
+ name: { type: String },
35
+ title: { type: String, attribute: true },
36
+ value: { type: String },
37
+ maxlength: { type: Number, reflect: true },
38
+ placeholder: { type: String },
39
+ ariaLabelInput: { type: String, attribute: 'aria-label-input' },
40
+ ariaLabelButton: { type: String, attribute: 'aria-label-button' },
41
+ borderless: { type: Boolean, reflect: true },
42
+ };
43
+
44
+ #searchInput;
45
+
46
+ constructor() {
47
+ super();
48
+
49
+ this.label = 'Search';
50
+ this.name = '';
51
+ this.title = 'Search';
52
+ this.value = '';
53
+ this.maxlength = 75;
54
+ this.placeholder = '';
55
+ this.ariaLabelInput = 'Search input';
56
+ this.ariaLabelButton = 'Clear search';
57
+ this.disabled = false;
58
+ this.#searchInput = createRef();
59
+
60
+ // Borderless is only used for CSS.
61
+ this.borderless = false;
62
+ }
63
+
64
+ #onInput(evt) {
65
+ this.value = evt.target.value;
66
+ }
67
+
68
+ #onBlur() {
69
+ this.dispatchEvent(
70
+ new Event('blur', {
71
+ bubbles: true,
72
+ composed: true,
73
+ }),
74
+ );
75
+ }
76
+
77
+ #onClickClear(evt) {
78
+ evt.preventDefault();
79
+ if (this.disabled) return;
80
+ this.value = '';
81
+ this.#searchInput.value?.focus();
82
+ this.dispatchEvent(
83
+ new CustomEvent('clear', { detail: '', bubbles: true, composed: true }),
84
+ );
85
+ }
86
+
87
+ render() {
88
+ return html`
89
+ <div
90
+ class="o-search-input ${this.validation
91
+ ? `o-search-input--${this.validation}`
92
+ : ''}"
93
+ >
94
+ <label
95
+ for="search-text"
96
+ class="o-search-input__input-label"
97
+ aria-label=${this.label}
98
+ >
99
+ ${unsafeSVG(searchIcon)}
100
+ </label>
101
+ <input
102
+ id="search-text"
103
+ type="search"
104
+ name=${this.name}
105
+ .value=${this.value}
106
+ ?disabled=${this.disabled}
107
+ class="a-text-input a-text-input__full"
108
+ placeholder=${this.placeholder}
109
+ title=${this.title}
110
+ autocomplete="off"
111
+ maxlength=${this.maxlength}
112
+ aria-label=${this.ariaLabelInput}
113
+ ${ref(this.#searchInput)}
114
+ @input=${this.#onInput}
115
+ @blur=${this.#onBlur}
116
+ />
117
+ <button
118
+ type="reset"
119
+ aria-label=${this.ariaLabelButton}
120
+ title=${this.ariaLabelButton}
121
+ @click=${this.#onClickClear}
122
+ >
123
+ ${unsafeSVG(clearIcon)}
124
+ </button>
125
+ </div>
126
+ `;
127
+ }
128
+
129
+ static init() {
130
+ window.customElements.get('cfpb-form-search-input') ||
131
+ window.customElements.define(
132
+ 'cfpb-form-search-input',
133
+ CfpbFormSearchInput,
134
+ );
135
+ }
136
+ }
@@ -1,60 +1,53 @@
1
1
  @use 'sass:math';
2
- @use '@cfpb/cfpb-design-system/src/abstracts' as *;
2
+ @use '@cfpb/cfpb-design-system/src/elements/abstracts' as *;
3
3
 
4
4
  @mixin u-btn-divider() {
5
5
  content: '';
6
6
  border-left: 1px solid var(--icon-text-divider);
7
- order: 2;
8
7
  place-self: normal;
9
8
  }
10
9
 
11
10
  :host {
12
11
  // Theme variables.
13
- --icon-text-divider: var(--pacific-60);
12
+ --icon-text-divider-default: var(--pacific-60);
13
+ --icon-text-divider-disabled: var(--gray-60);
14
14
 
15
- div {
15
+ // Private variables.
16
+ --icon-text-divider: var(--icon-text-divider-default);
17
+
18
+ .wrapper {
16
19
  // This prevents the child button from having an empty gap after the button.
17
20
  display: flex;
18
21
  width: fit-content;
19
22
  align-items: center;
20
23
 
21
- // Hide SVG by default.
22
- & ::slotted(svg) {
23
- display: none;
24
- }
25
-
26
- &.u-has-icon {
27
- gap: math.div(10px, $btn-font-size) + rem;
28
- & slot::before {
29
- @include u-btn-divider;
30
- }
31
-
32
- // Show SVG.
33
- & ::slotted(svg) {
34
- display: initial;
35
- }
36
- }
37
-
38
- &.u-has-icon--left {
39
- & ::slotted(svg) {
40
- order: 1;
41
- }
42
- & ::slotted(span) {
43
- order: 3;
44
- }
45
- }
46
-
47
- &.u-has-icon--right {
48
- & ::slotted(svg) {
49
- order: 3;
50
- }
51
- & ::slotted(span) {
52
- order: 1;
53
- }
54
- }
24
+ gap: math.div(10px, $btn-font-size) + rem;
25
+ }
26
+
27
+ .left-divider::before,
28
+ .right-divider::after {
29
+ @include u-btn-divider;
30
+ }
31
+
32
+ // Shine the slot contents through to the wrapper's flexbox items.
33
+ slot {
34
+ display: contents;
55
35
  }
56
36
  }
57
37
 
38
+ .left-divider ::slotted(svg:first-of-type) {
39
+ order: -1;
40
+ }
41
+
42
+ .right-divider ::slotted(svg:last-of-type) {
43
+ order: 1;
44
+ }
45
+
58
46
  :host([disabled]) {
59
- --icon-text-divider: var(--gray-60);
47
+ --icon-text-divider: var(--icon-text-divider-disabled);
48
+ }
49
+
50
+ // Hide SVG if user calls hideIcon()
51
+ :host([icon-hidden]) ::slotted(svg) {
52
+ display: none !important;
60
53
  }