chunk.6QNJD6BH.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import {
  2. getLabelledBy,
  3. renderFormControl
  4. } from "./chunk.LLZCD55S.js";
  5. import {
  6. hasSlot
  7. } from "./chunk.FMCX45AD.js";
  8. import {
  9. l
  10. } from "./chunk.5MED2A3H.js";
  11. import {
  12. event,
  13. watch
  14. } from "./chunk.XX234VRK.js";
  15. import {
  16. e as e2
  17. } from "./chunk.YXKHB4AC.js";
  18. import {
  19. T,
  20. e,
  21. h,
  22. n,
  23. o,
  24. r,
  25. r2
  26. } from "./chunk.5PIDMFOE.js";
  27. import {
  28. __decorateClass
  29. } from "./chunk.IHGPZX35.js";
  30. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/input/input.scss
  31. var input_default = ":host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n.form-control .form-control__label {\n display: none;\n}\n.form-control .form-control__help-text {\n display: none;\n}\n\n.form-control--has-label .form-control__label {\n display: inline-block;\n color: var(--sl-input-label-color);\n margin-bottom: var(--sl-spacing-xxx-small);\n}\n.form-control--has-label.form-control--small .form-control__label {\n font-size: var(--sl-input-label-font-size-small);\n}\n.form-control--has-label.form-control--medium .form-control__label {\n font-size: var(--sl-input-label-font-size-medium);\n}\n.form-control--has-label.form-control--large .form-control_label {\n font-size: var(--sl-input-label-font-size-large);\n}\n\n.form-control--has-help-text .form-control__help-text {\n display: block;\n color: var(--sl-input-help-text-color);\n}\n.form-control--has-help-text .form-control__help-text ::slotted(*) {\n margin-top: var(--sl-spacing-xxx-small);\n}\n.form-control--has-help-text.form-control--small .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-small);\n}\n.form-control--has-help-text.form-control--medium .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-medium);\n}\n.form-control--has-help-text.form-control--large .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-large);\n}\n\n:host {\n --focus-ring: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n display: block;\n}\n\n.input {\n flex: 1 1 auto;\n display: inline-flex;\n align-items: stretch;\n justify-content: start;\n position: relative;\n width: 100%;\n font-family: var(--sl-input-font-family);\n font-weight: var(--sl-input-font-weight);\n letter-spacing: var(--sl-input-letter-spacing);\n background-color: var(--sl-input-background-color);\n border: solid var(--sl-input-border-width) var(--sl-input-border-color);\n vertical-align: middle;\n overflow: hidden;\n transition: var(--sl-transition-fast) color, var(--sl-transition-fast) border, var(--sl-transition-fast) box-shadow;\n cursor: text;\n}\n.input:hover:not(.input--disabled) {\n background-color: var(--sl-input-background-color-hover);\n border-color: var(--sl-input-border-color-hover);\n}\n.input:hover:not(.input--disabled) .input__control {\n color: var(--sl-input-color-hover);\n}\n.input.input--focused:not(.input--disabled) {\n background-color: var(--sl-input-background-color-focus);\n border-color: var(--sl-input-border-color-focus);\n box-shadow: var(--focus-ring);\n}\n.input.input--focused:not(.input--disabled) .input__control {\n color: var(--sl-input-color-focus);\n}\n.input.input--disabled {\n background-color: var(--sl-input-background-color-disabled);\n border-color: var(--sl-input-border-color-disabled);\n opacity: 0.5;\n cursor: not-allowed;\n}\n.input.input--disabled .input__control {\n color: var(--sl-input-color-disabled);\n}\n.input.input--disabled .input__control::placeholder {\n color: var(--sl-input-placeholder-color-disabled);\n}\n\n.input__control {\n flex: 1 1 auto;\n font-family: inherit;\n font-size: inherit;\n font-weight: inherit;\n min-width: 0;\n height: 100%;\n color: var(--sl-input-color);\n border: none;\n background: none;\n box-shadow: none;\n padding: 0;\n margin: 0;\n cursor: inherit;\n -webkit-appearance: none;\n}\n.input__control::-webkit-search-decoration, .input__control::-webkit-search-cancel-button, .input__control::-webkit-search-results-button, .input__control::-webkit-search-results-decoration {\n -webkit-appearance: none;\n}\n.input__control:-webkit-autofill, .input__control:-webkit-autofill:hover, .input__control:-webkit-autofill:focus, .input__control:-webkit-autofill:active {\n box-shadow: 0 0 0 var(--sl-input-height-large) var(--sl-input-background-color-hover) inset !important;\n -webkit-text-fill-color: var(--sl-color-primary-500);\n}\n.input__control::placeholder {\n color: var(--sl-input-placeholder-color);\n user-select: none;\n}\n.input__control:focus {\n outline: none;\n}\n\n.input__prefix,\n.input__suffix {\n display: inline-flex;\n flex: 0 0 auto;\n align-items: center;\n cursor: default;\n}\n.input__prefix ::slotted(sl-icon),\n.input__suffix ::slotted(sl-icon) {\n color: var(--sl-input-icon-color);\n}\n\n.input--small {\n border-radius: var(--sl-input-border-radius-small);\n font-size: var(--sl-input-font-size-small);\n height: var(--sl-input-height-small);\n}\n.input--small .input__control {\n height: calc(var(--sl-input-height-small) - var(--sl-input-border-width) * 2);\n margin: 0 var(--sl-input-spacing-small);\n}\n.input--small .input__clear,\n.input--small .input__password-toggle {\n margin-right: var(--sl-input-spacing-small);\n}\n.input--small .input__prefix ::slotted(*) {\n margin-left: var(--sl-input-spacing-small);\n}\n.input--small .input__suffix ::slotted(*) {\n margin-right: var(--sl-input-spacing-small);\n}\n\n.input--medium {\n border-radius: var(--sl-input-border-radius-medium);\n font-size: var(--sl-input-font-size-medium);\n height: var(--sl-input-height-medium);\n}\n.input--medium .input__control {\n height: calc(var(--sl-input-height-medium) - var(--sl-input-border-width) * 2);\n margin: 0 var(--sl-input-spacing-medium);\n}\n.input--medium .input__clear,\n.input--medium .input__password-toggle {\n margin-right: var(--sl-input-spacing-medium);\n}\n.input--medium .input__prefix ::slotted(*) {\n margin-left: var(--sl-input-spacing-medium);\n}\n.input--medium .input__suffix ::slotted(*) {\n margin-right: var(--sl-input-spacing-medium);\n}\n\n.input--large {\n border-radius: var(--sl-input-border-radius-large);\n font-size: var(--sl-input-font-size-large);\n height: var(--sl-input-height-large);\n}\n.input--large .input__control {\n height: calc(var(--sl-input-height-large) - var(--sl-input-border-width) * 2);\n margin: 0 var(--sl-input-spacing-large);\n}\n.input--large .input__clear,\n.input--large .input__password-toggle {\n margin-right: var(--sl-input-spacing-large);\n}\n.input--large .input__prefix ::slotted(*) {\n margin-left: var(--sl-input-spacing-large);\n}\n.input--large .input__suffix ::slotted(*) {\n margin-right: var(--sl-input-spacing-large);\n}\n\n.input--pill.input--small {\n border-radius: var(--sl-input-height-small);\n}\n.input--pill.input--medium {\n border-radius: var(--sl-input-height-medium);\n}\n.input--pill.input--large {\n border-radius: var(--sl-input-height-large);\n}\n\n.input__clear,\n.input__password-toggle {\n display: inline-flex;\n align-items: center;\n font-size: inherit;\n color: var(--sl-input-icon-color);\n border: none;\n background: none;\n padding: 0;\n transition: var(--sl-transition-fast) color;\n cursor: pointer;\n}\n.input__clear:hover,\n.input__password-toggle:hover {\n color: var(--sl-input-icon-color-hover);\n}\n.input__clear:focus,\n.input__password-toggle:focus {\n outline: none;\n}\n\n.input--empty .input__clear {\n visibility: hidden;\n}";
  32. // src/components/input/input.ts
  33. var id = 0;
  34. var SlInput = class extends h {
  35. constructor() {
  36. super(...arguments);
  37. this.inputId = `input-${++id}`;
  38. this.helpTextId = `input-help-text-${id}`;
  39. this.labelId = `input-label-${id}`;
  40. this.hasFocus = false;
  41. this.hasHelpTextSlot = false;
  42. this.hasLabelSlot = false;
  43. this.isPasswordVisible = false;
  44. this.type = "text";
  45. this.size = "medium";
  46. this.value = "";
  47. this.pill = false;
  48. this.helpText = "";
  49. this.clearable = false;
  50. this.togglePassword = false;
  51. this.disabled = false;
  52. this.readonly = false;
  53. this.required = false;
  54. this.invalid = false;
  55. }
  56. connectedCallback() {
  57. super.connectedCallback();
  58. this.handleSlotChange = this.handleSlotChange.bind(this);
  59. this.shadowRoot.addEventListener("slotchange", this.handleSlotChange);
  60. }
  61. disconnectedCallback() {
  62. super.disconnectedCallback();
  63. this.shadowRoot.removeEventListener("slotchange", this.handleSlotChange);
  64. }
  65. focus(options) {
  66. this.input.focus(options);
  67. }
  68. blur() {
  69. this.input.blur();
  70. }
  71. select() {
  72. return this.input.select();
  73. }
  74. setSelectionRange(selectionStart, selectionEnd, selectionDirection = "none") {
  75. return this.input.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
  76. }
  77. setRangeText(replacement, start, end, selectMode = "preserve") {
  78. this.input.setRangeText(replacement, start, end, selectMode);
  79. if (this.value !== this.input.value) {
  80. this.value = this.input.value;
  81. this.slInput.emit();
  82. this.slChange.emit();
  83. }
  84. }
  85. reportValidity() {
  86. return this.input.reportValidity();
  87. }
  88. setCustomValidity(message) {
  89. this.input.setCustomValidity(message);
  90. this.invalid = !this.input.checkValidity();
  91. }
  92. handleChange() {
  93. this.value = this.input.value;
  94. this.slChange.emit();
  95. }
  96. handleInput() {
  97. this.value = this.input.value;
  98. this.slInput.emit();
  99. }
  100. handleInvalid() {
  101. this.invalid = true;
  102. }
  103. handleBlur() {
  104. this.hasFocus = false;
  105. this.slBlur.emit();
  106. }
  107. handleFocus() {
  108. this.hasFocus = true;
  109. this.slFocus.emit();
  110. }
  111. handleClearClick(event2) {
  112. this.value = "";
  113. this.slClear.emit();
  114. this.slInput.emit();
  115. this.slChange.emit();
  116. this.input.focus();
  117. event2.stopPropagation();
  118. }
  119. handlePasswordToggle() {
  120. this.isPasswordVisible = !this.isPasswordVisible;
  121. }
  122. handleSlotChange() {
  123. this.hasHelpTextSlot = hasSlot(this, "help-text");
  124. this.hasLabelSlot = hasSlot(this, "label");
  125. }
  126. handleValueChange() {
  127. this.invalid = !this.input.checkValidity();
  128. }
  129. render() {
  130. return renderFormControl({
  131. inputId: this.inputId,
  132. label: this.label,
  133. labelId: this.labelId,
  134. hasLabelSlot: this.hasLabelSlot,
  135. helpTextId: this.helpTextId,
  136. helpText: this.helpText,
  137. hasHelpTextSlot: this.hasHelpTextSlot,
  138. size: this.size
  139. }, T`
  140. <div
  141. part="base"
  142. class=${e2({
  143. input: true,
  144. "input--small": this.size === "small",
  145. "input--medium": this.size === "medium",
  146. "input--large": this.size === "large",
  147. "input--pill": this.pill,
  148. "input--disabled": this.disabled,
  149. "input--focused": this.hasFocus,
  150. "input--empty": this.value.length === 0,
  151. "input--invalid": this.invalid
  152. })}
  153. >
  154. <span part="prefix" class="input__prefix">
  155. <slot name="prefix"></slot>
  156. </span>
  157. <input
  158. part="input"
  159. id=${this.inputId}
  160. class="input__control"
  161. type=${this.type === "password" && this.isPasswordVisible ? "text" : this.type}
  162. name=${l(this.name)}
  163. ?disabled=${this.disabled}
  164. ?readonly=${this.readonly}
  165. ?required=${this.required}
  166. placeholder=${l(this.placeholder)}
  167. minlength=${l(this.minlength)}
  168. maxlength=${l(this.maxlength)}
  169. min=${l(this.min)}
  170. max=${l(this.max)}
  171. step=${l(this.step)}
  172. .value=${this.value}
  173. autocapitalize=${l(this.autocapitalize)}
  174. autocomplete=${l(this.autocomplete)}
  175. autocorrect=${l(this.autocorrect)}
  176. ?autofocus=${this.autofocus}
  177. spellcheck=${l(this.spellcheck)}
  178. pattern=${l(this.pattern)}
  179. inputmode=${l(this.inputmode)}
  180. aria-labelledby=${l(getLabelledBy({
  181. label: this.label,
  182. labelId: this.labelId,
  183. hasLabelSlot: this.hasLabelSlot,
  184. helpText: this.helpText,
  185. helpTextId: this.helpTextId,
  186. hasHelpTextSlot: this.hasHelpTextSlot
  187. }))}
  188. aria-invalid=${this.invalid ? "true" : "false"}
  189. @change=${this.handleChange}
  190. @input=${this.handleInput}
  191. @invalid=${this.handleInvalid}
  192. @focus=${this.handleFocus}
  193. @blur=${this.handleBlur}
  194. />
  195. ${this.clearable && this.value.length > 0 ? T`
  196. <button
  197. part="clear-button"
  198. class="input__clear"
  199. type="button"
  200. @click=${this.handleClearClick}
  201. tabindex="-1"
  202. >
  203. <slot name="clear-icon">
  204. <sl-icon name="x-circle" library="system"></sl-icon>
  205. </slot>
  206. </button>
  207. ` : ""}
  208. ${this.togglePassword ? T`
  209. <button
  210. part="password-toggle-button"
  211. class="input__password-toggle"
  212. type="button"
  213. @click=${this.handlePasswordToggle}
  214. tabindex="-1"
  215. >
  216. ${this.isPasswordVisible ? T`
  217. <slot name="show-password-icon">
  218. <sl-icon name="eye-slash" library="system"></sl-icon>
  219. </slot>
  220. ` : T`
  221. <slot name="hide-password-icon">
  222. ${" "}
  223. <sl-icon name="eye" library="system"></sl-icon>
  224. </slot>
  225. `}
  226. </button>
  227. ` : ""}
  228. <span part="suffix" class="input__suffix">
  229. <slot name="suffix"></slot>
  230. </span>
  231. </div>
  232. `);
  233. }
  234. };
  235. SlInput.styles = r(input_default);
  236. __decorateClass([
  237. o(".input__control")
  238. ], SlInput.prototype, "input", 2);
  239. __decorateClass([
  240. r2()
  241. ], SlInput.prototype, "hasFocus", 2);
  242. __decorateClass([
  243. r2()
  244. ], SlInput.prototype, "hasHelpTextSlot", 2);
  245. __decorateClass([
  246. r2()
  247. ], SlInput.prototype, "hasLabelSlot", 2);
  248. __decorateClass([
  249. r2()
  250. ], SlInput.prototype, "isPasswordVisible", 2);
  251. __decorateClass([
  252. e({ reflect: true })
  253. ], SlInput.prototype, "type", 2);
  254. __decorateClass([
  255. e({ reflect: true })
  256. ], SlInput.prototype, "size", 2);
  257. __decorateClass([
  258. e()
  259. ], SlInput.prototype, "name", 2);
  260. __decorateClass([
  261. e()
  262. ], SlInput.prototype, "value", 2);
  263. __decorateClass([
  264. e({ type: Boolean, reflect: true })
  265. ], SlInput.prototype, "pill", 2);
  266. __decorateClass([
  267. e()
  268. ], SlInput.prototype, "label", 2);
  269. __decorateClass([
  270. e({ attribute: "help-text" })
  271. ], SlInput.prototype, "helpText", 2);
  272. __decorateClass([
  273. e({ type: Boolean })
  274. ], SlInput.prototype, "clearable", 2);
  275. __decorateClass([
  276. e({ attribute: "toggle-password", type: Boolean })
  277. ], SlInput.prototype, "togglePassword", 2);
  278. __decorateClass([
  279. e()
  280. ], SlInput.prototype, "placeholder", 2);
  281. __decorateClass([
  282. e({ type: Boolean, reflect: true })
  283. ], SlInput.prototype, "disabled", 2);
  284. __decorateClass([
  285. e({ type: Boolean, reflect: true })
  286. ], SlInput.prototype, "readonly", 2);
  287. __decorateClass([
  288. e({ type: Number })
  289. ], SlInput.prototype, "minlength", 2);
  290. __decorateClass([
  291. e({ type: Number })
  292. ], SlInput.prototype, "maxlength", 2);
  293. __decorateClass([
  294. e()
  295. ], SlInput.prototype, "min", 2);
  296. __decorateClass([
  297. e()
  298. ], SlInput.prototype, "max", 2);
  299. __decorateClass([
  300. e({ type: Number })
  301. ], SlInput.prototype, "step", 2);
  302. __decorateClass([
  303. e()
  304. ], SlInput.prototype, "pattern", 2);
  305. __decorateClass([
  306. e({ type: Boolean, reflect: true })
  307. ], SlInput.prototype, "required", 2);
  308. __decorateClass([
  309. e({ type: Boolean, reflect: true })
  310. ], SlInput.prototype, "invalid", 2);
  311. __decorateClass([
  312. e()
  313. ], SlInput.prototype, "autocapitalize", 2);
  314. __decorateClass([
  315. e()
  316. ], SlInput.prototype, "autocorrect", 2);
  317. __decorateClass([
  318. e()
  319. ], SlInput.prototype, "autocomplete", 2);
  320. __decorateClass([
  321. e({ type: Boolean })
  322. ], SlInput.prototype, "autofocus", 2);
  323. __decorateClass([
  324. e({ type: Boolean })
  325. ], SlInput.prototype, "spellcheck", 2);
  326. __decorateClass([
  327. e()
  328. ], SlInput.prototype, "inputmode", 2);
  329. __decorateClass([
  330. event("sl-change")
  331. ], SlInput.prototype, "slChange", 2);
  332. __decorateClass([
  333. event("sl-clear")
  334. ], SlInput.prototype, "slClear", 2);
  335. __decorateClass([
  336. event("sl-input")
  337. ], SlInput.prototype, "slInput", 2);
  338. __decorateClass([
  339. event("sl-focus")
  340. ], SlInput.prototype, "slFocus", 2);
  341. __decorateClass([
  342. event("sl-blur")
  343. ], SlInput.prototype, "slBlur", 2);
  344. __decorateClass([
  345. watch("helpText"),
  346. watch("label")
  347. ], SlInput.prototype, "handleSlotChange", 1);
  348. __decorateClass([
  349. watch("value")
  350. ], SlInput.prototype, "handleValueChange", 1);
  351. SlInput = __decorateClass([
  352. n("sl-input")
  353. ], SlInput);
  354. var input_default2 = SlInput;
  355. export {
  356. input_default2 as input_default
  357. };