|
77 | 77 | /** Set to `true` to use inline version */ |
78 | 78 | export let inline = false; |
79 | 79 |
|
| 80 | + /** |
| 81 | + * Set HTML attributes on the `label` element |
| 82 | + * @type {import('svelte/elements').HTMLLabelAttributes} |
| 83 | + */ |
| 84 | + export let labelAttributes = {}; |
| 85 | +
|
| 86 | + /** |
| 87 | + * Set HTML attributes on the `input` element |
| 88 | + * @type {import('svelte/elements').HTMLInputAttributes} |
| 89 | + */ |
| 90 | + export let inputAttributes = {}; |
| 91 | +
|
80 | 92 | import { getContext } from "svelte"; |
81 | 93 | import WarningFilled from "../icons/WarningFilled.svelte"; |
82 | 94 | import WarningAltFilled from "../icons/WarningAltFilled.svelte"; |
|
101 | 113 | class:bx--text-input-wrapper--light="{light}" |
102 | 114 | class:bx--text-input-wrapper--inline="{inline}" |
103 | 115 | on:click |
104 | | - on:mouseover |
105 | | - on:mouseenter |
106 | | - on:mouseleave |
| 116 | + on:pointerover |
| 117 | + on:pointerenter |
| 118 | + on:pointerleave |
107 | 119 | > |
108 | 120 | {#if inline} |
109 | 121 | <label |
|
114 | 126 | class:bx--label--inline="{inline}" |
115 | 127 | class:bx--label--inline--sm="{inline && size === 'sm'}" |
116 | 128 | class:bx--label--inline--lg="{inline && (size === 'lg' || size === 'xl')}" |
| 129 | + {...labelAttributes} |
117 | 130 | > |
118 | 131 | <slot name="labelText"> |
119 | 132 | {labelText} |
120 | 133 | </slot> |
121 | 134 | </label> |
122 | | - {#if !isFluid && helperText} |
| 135 | + {#if !isFluid && (helperText || $$slots.helperText)} |
123 | 136 | <div |
124 | 137 | id="{helperId}" |
125 | 138 | class:bx--form__helper-text="{true}" |
126 | 139 | class:bx--form__helper-text--disabled="{disabled}" |
127 | 140 | class:bx--form__helper-text--inline="{inline}" |
128 | 141 | > |
129 | | - {helperText} |
| 142 | + <slot name="helperText"> |
| 143 | + {helperText} |
| 144 | + </slot> |
130 | 145 | </div> |
131 | 146 | {/if} |
132 | 147 | {/if} |
|
187 | 202 | class:bx--text-input--warning="{warn}" |
188 | 203 | class:bx--text-input--sm="{size === 'sm'}" |
189 | 204 | class:bx--text-input--lg="{size === 'lg' || size === 'xl'}" |
190 | | - {...$$restProps} |
| 205 | + {...inputAttributes} |
191 | 206 | on:change |
192 | 207 | on:input |
193 | | - on:input="{({ target }) => { |
194 | | - value = target.value; |
195 | | - }}" |
196 | 208 | on:keydown |
197 | 209 | on:keyup |
198 | 210 | on:focus |
199 | 211 | on:blur |
200 | 212 | on:paste |
201 | 213 | /> |
202 | | - {#if isFluid && invalid} |
| 214 | + {#if isFluid && (invalid || $$slots.invalidText)} |
203 | 215 | <hr class="bx--text-input__divider" /> |
204 | 216 | <div class="bx--form-requirement" id="{errorId}"> |
205 | | - {invalidText} |
| 217 | + ' |
| 218 | + <slot name="invalidText"> |
| 219 | + {invalidText} |
| 220 | + </slot> |
206 | 221 | </div> |
207 | 222 | {/if} |
208 | 223 | {#if !(isFluid && invalid)} |
|
230 | 245 | <span class:bx--assistive-text="{true}"> |
231 | 246 | {#if type === "text"} |
232 | 247 | {hidePasswordLabel} |
233 | | - {:else}{showPasswordLabel}{/if} |
| 248 | + {:else} |
| 249 | + {showPasswordLabel} |
| 250 | + {/if} |
234 | 251 | </span> |
235 | 252 | {/if} |
236 | 253 | {#if type === "text"} |
|
241 | 258 | </button> |
242 | 259 | {/if} |
243 | 260 | </div> |
244 | | - {#if !isFluid && invalid} |
| 261 | + {#if !isFluid && (invalid || $$slots.invalidText)} |
245 | 262 | <div class:bx--form-requirement="{true}" id="{errorId}"> |
246 | | - {invalidText} |
| 263 | + <slot name="invalidText"> |
| 264 | + {invalidText} |
| 265 | + </slot> |
247 | 266 | </div> |
248 | 267 | {/if} |
249 | | - {#if !invalid && !warn && !isFluid && !inline && helperText} |
| 268 | + {#if !invalid && !warn && !isFluid && !inline && (helperText || $$slots.helperText)} |
250 | 269 | <div |
251 | 270 | class:bx--form__helper-text="{true}" |
252 | 271 | class:bx--form__helper-text--disabled="{disabled}" |
253 | 272 | class:bx--form__helper-text--inline="{inline}" |
254 | 273 | > |
255 | | - {helperText} |
| 274 | + <slot name="helperText"> |
| 275 | + {helperText} |
| 276 | + </slot> |
256 | 277 | </div> |
257 | 278 | {/if} |
258 | 279 | {#if !isFluid && !invalid && warn} |
|
0 commit comments