chunk.RICSQUXH.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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/textarea/textarea.scss
  31. var textarea_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 display: block;\n}\n\n.textarea {\n display: flex;\n align-items: center;\n position: relative;\n width: 100%;\n font-family: var(--sl-input-font-family);\n font-weight: var(--sl-input-font-weight);\n line-height: var(--sl-line-height-normal);\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 transition: var(--sl-transition-fast) color, var(--sl-transition-fast) border, var(--sl-transition-fast) box-shadow;\n cursor: text;\n}\n.textarea:hover:not(.textarea--disabled) {\n background-color: var(--sl-input-background-color-hover);\n border-color: var(--sl-input-border-color-hover);\n}\n.textarea:hover:not(.textarea--disabled) .textarea__control {\n color: var(--sl-input-color-hover);\n}\n.textarea.textarea--focused:not(.textarea--disabled) {\n background-color: var(--sl-input-background-color-focus);\n border-color: var(--sl-input-border-color-focus);\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n color: var(--sl-input-color-focus);\n}\n.textarea.textarea--focused:not(.textarea--disabled) .textarea__control {\n color: var(--sl-input-color-focus);\n}\n.textarea.textarea--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.textarea.textarea--disabled .textarea__control {\n color: var(--sl-input-color-disabled);\n}\n.textarea.textarea--disabled .textarea__control::placeholder {\n color: var(--sl-input-placeholder-color-disabled);\n}\n\n.textarea__control {\n flex: 1 1 auto;\n font-family: inherit;\n font-size: inherit;\n font-weight: inherit;\n line-height: 1.4;\n color: var(--sl-input-color);\n border: none;\n background: none;\n box-shadow: none;\n cursor: inherit;\n -webkit-appearance: none;\n}\n.textarea__control::-webkit-search-decoration, .textarea__control::-webkit-search-cancel-button, .textarea__control::-webkit-search-results-button, .textarea__control::-webkit-search-results-decoration {\n -webkit-appearance: none;\n}\n.textarea__control::placeholder {\n color: var(--sl-input-placeholder-color);\n user-select: none;\n}\n.textarea__control:focus {\n outline: none;\n}\n\n.textarea--small {\n border-radius: var(--sl-input-border-radius-small);\n font-size: var(--sl-input-font-size-small);\n}\n.textarea--small .textarea__control {\n padding: 0.5em var(--sl-input-spacing-small);\n}\n\n.textarea--medium {\n border-radius: var(--sl-input-border-radius-medium);\n font-size: var(--sl-input-font-size-medium);\n}\n.textarea--medium .textarea__control {\n padding: 0.5em var(--sl-input-spacing-medium);\n}\n\n.textarea--large {\n border-radius: var(--sl-input-border-radius-large);\n font-size: var(--sl-input-font-size-large);\n}\n.textarea--large .textarea__control {\n padding: 0.5em var(--sl-input-spacing-large);\n}\n\n.textarea--resize-none .textarea__control {\n resize: none;\n}\n\n.textarea--resize-vertical .textarea__control {\n resize: vertical;\n}\n\n.textarea--resize-auto .textarea__control {\n height: auto;\n resize: none;\n}";
  32. // src/components/textarea/textarea.ts
  33. var id = 0;
  34. var SlTextarea = class extends h {
  35. constructor() {
  36. super(...arguments);
  37. this.inputId = `textarea-${++id}`;
  38. this.helpTextId = `textarea-help-text-${id}`;
  39. this.labelId = `textarea-label-${id}`;
  40. this.hasFocus = false;
  41. this.hasHelpTextSlot = false;
  42. this.hasLabelSlot = false;
  43. this.size = "medium";
  44. this.value = "";
  45. this.helpText = "";
  46. this.rows = 4;
  47. this.resize = "vertical";
  48. this.disabled = false;
  49. this.readonly = false;
  50. this.required = false;
  51. this.invalid = false;
  52. }
  53. connectedCallback() {
  54. super.connectedCallback();
  55. this.handleSlotChange = this.handleSlotChange.bind(this);
  56. this.resizeObserver = new ResizeObserver(() => this.setTextareaHeight());
  57. this.shadowRoot.addEventListener("slotchange", this.handleSlotChange);
  58. this.handleSlotChange();
  59. this.updateComplete.then(() => {
  60. this.setTextareaHeight();
  61. this.resizeObserver.observe(this.input);
  62. });
  63. }
  64. disconnectedCallback() {
  65. super.disconnectedCallback();
  66. this.resizeObserver.unobserve(this.input);
  67. this.shadowRoot.removeEventListener("slotchange", this.handleSlotChange);
  68. }
  69. focus(options) {
  70. this.input.focus(options);
  71. }
  72. blur() {
  73. this.input.blur();
  74. }
  75. select() {
  76. return this.input.select();
  77. }
  78. scrollPosition(position) {
  79. if (position) {
  80. if (typeof position.top === "number")
  81. this.input.scrollTop = position.top;
  82. if (typeof position.left === "number")
  83. this.input.scrollLeft = position.left;
  84. return;
  85. }
  86. return {
  87. top: this.input.scrollTop,
  88. left: this.input.scrollTop
  89. };
  90. }
  91. setSelectionRange(selectionStart, selectionEnd, selectionDirection = "none") {
  92. return this.input.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
  93. }
  94. setRangeText(replacement, start, end, selectMode = "preserve") {
  95. this.input.setRangeText(replacement, start, end, selectMode);
  96. if (this.value !== this.input.value) {
  97. this.value = this.input.value;
  98. this.slInput.emit();
  99. }
  100. if (this.value !== this.input.value) {
  101. this.value = this.input.value;
  102. this.setTextareaHeight();
  103. this.slInput.emit();
  104. this.slChange.emit();
  105. }
  106. }
  107. reportValidity() {
  108. return this.input.reportValidity();
  109. }
  110. setCustomValidity(message) {
  111. this.input.setCustomValidity(message);
  112. this.invalid = !this.input.checkValidity();
  113. }
  114. handleChange() {
  115. this.value = this.input.value;
  116. this.slChange.emit();
  117. }
  118. handleInput() {
  119. this.value = this.input.value;
  120. this.setTextareaHeight();
  121. this.slInput.emit();
  122. }
  123. handleBlur() {
  124. this.hasFocus = false;
  125. this.slBlur.emit();
  126. }
  127. handleFocus() {
  128. this.hasFocus = true;
  129. this.slFocus.emit();
  130. }
  131. handleRowsChange() {
  132. this.setTextareaHeight();
  133. }
  134. handleSlotChange() {
  135. this.hasHelpTextSlot = hasSlot(this, "help-text");
  136. this.hasLabelSlot = hasSlot(this, "label");
  137. }
  138. handleValueChange() {
  139. this.invalid = !this.input.checkValidity();
  140. }
  141. setTextareaHeight() {
  142. if (this.resize === "auto") {
  143. this.input.style.height = "auto";
  144. this.input.style.height = this.input.scrollHeight + "px";
  145. } else {
  146. this.input.style.height = void 0;
  147. }
  148. }
  149. render() {
  150. return renderFormControl({
  151. inputId: this.inputId,
  152. label: this.label,
  153. labelId: this.labelId,
  154. hasLabelSlot: this.hasLabelSlot,
  155. helpTextId: this.helpTextId,
  156. helpText: this.helpText,
  157. hasHelpTextSlot: this.hasHelpTextSlot,
  158. size: this.size
  159. }, T`
  160. <div
  161. part="base"
  162. class=${e2({
  163. textarea: true,
  164. "textarea--small": this.size === "small",
  165. "textarea--medium": this.size === "medium",
  166. "textarea--large": this.size === "large",
  167. "textarea--disabled": this.disabled,
  168. "textarea--focused": this.hasFocus,
  169. "textarea--empty": this.value.length === 0,
  170. "textarea--invalid": this.invalid,
  171. "textarea--resize-none": this.resize === "none",
  172. "textarea--resize-vertical": this.resize === "vertical",
  173. "textarea--resize-auto": this.resize === "auto"
  174. })}
  175. >
  176. <textarea
  177. part="textarea"
  178. id=${this.inputId}
  179. class="textarea__control"
  180. name=${l(this.name)}
  181. .value=${this.value}
  182. ?disabled=${this.disabled}
  183. ?readonly=${this.readonly}
  184. ?required=${this.required}
  185. placeholder=${l(this.placeholder)}
  186. rows=${l(this.rows)}
  187. minlength=${l(this.minlength)}
  188. maxlength=${l(this.maxlength)}
  189. autocapitalize=${l(this.autocapitalize)}
  190. autocorrect=${l(this.autocorrect)}
  191. ?autofocus=${this.autofocus}
  192. spellcheck=${l(this.spellcheck)}
  193. inputmode=${l(this.inputmode)}
  194. aria-labelledby=${l(getLabelledBy({
  195. label: this.label,
  196. labelId: this.labelId,
  197. hasLabelSlot: this.hasLabelSlot,
  198. helpText: this.helpText,
  199. helpTextId: this.helpTextId,
  200. hasHelpTextSlot: this.hasHelpTextSlot
  201. }))}
  202. @change=${this.handleChange.bind(this)}
  203. @input=${this.handleInput.bind(this)}
  204. @focus=${this.handleFocus.bind(this)}
  205. @blur=${this.handleBlur.bind(this)}
  206. ></textarea>
  207. </div>
  208. `);
  209. }
  210. };
  211. SlTextarea.styles = r(textarea_default);
  212. __decorateClass([
  213. o(".textarea__control")
  214. ], SlTextarea.prototype, "input", 2);
  215. __decorateClass([
  216. r2()
  217. ], SlTextarea.prototype, "hasFocus", 2);
  218. __decorateClass([
  219. r2()
  220. ], SlTextarea.prototype, "hasHelpTextSlot", 2);
  221. __decorateClass([
  222. r2()
  223. ], SlTextarea.prototype, "hasLabelSlot", 2);
  224. __decorateClass([
  225. e({ reflect: true })
  226. ], SlTextarea.prototype, "size", 2);
  227. __decorateClass([
  228. e()
  229. ], SlTextarea.prototype, "name", 2);
  230. __decorateClass([
  231. e()
  232. ], SlTextarea.prototype, "value", 2);
  233. __decorateClass([
  234. e()
  235. ], SlTextarea.prototype, "label", 2);
  236. __decorateClass([
  237. e({ attribute: "help-text" })
  238. ], SlTextarea.prototype, "helpText", 2);
  239. __decorateClass([
  240. e()
  241. ], SlTextarea.prototype, "placeholder", 2);
  242. __decorateClass([
  243. e({ type: Number })
  244. ], SlTextarea.prototype, "rows", 2);
  245. __decorateClass([
  246. e()
  247. ], SlTextarea.prototype, "resize", 2);
  248. __decorateClass([
  249. e({ type: Boolean, reflect: true })
  250. ], SlTextarea.prototype, "disabled", 2);
  251. __decorateClass([
  252. e({ type: Boolean, reflect: true })
  253. ], SlTextarea.prototype, "readonly", 2);
  254. __decorateClass([
  255. e({ type: Number })
  256. ], SlTextarea.prototype, "minlength", 2);
  257. __decorateClass([
  258. e({ type: Number })
  259. ], SlTextarea.prototype, "maxlength", 2);
  260. __decorateClass([
  261. e()
  262. ], SlTextarea.prototype, "pattern", 2);
  263. __decorateClass([
  264. e({ type: Boolean, reflect: true })
  265. ], SlTextarea.prototype, "required", 2);
  266. __decorateClass([
  267. e({ type: Boolean, reflect: true })
  268. ], SlTextarea.prototype, "invalid", 2);
  269. __decorateClass([
  270. e()
  271. ], SlTextarea.prototype, "autocapitalize", 2);
  272. __decorateClass([
  273. e()
  274. ], SlTextarea.prototype, "autocorrect", 2);
  275. __decorateClass([
  276. e()
  277. ], SlTextarea.prototype, "autocomplete", 2);
  278. __decorateClass([
  279. e({ type: Boolean })
  280. ], SlTextarea.prototype, "autofocus", 2);
  281. __decorateClass([
  282. e({ type: Boolean })
  283. ], SlTextarea.prototype, "spellcheck", 2);
  284. __decorateClass([
  285. e()
  286. ], SlTextarea.prototype, "inputmode", 2);
  287. __decorateClass([
  288. event("sl-change")
  289. ], SlTextarea.prototype, "slChange", 2);
  290. __decorateClass([
  291. event("sl-input")
  292. ], SlTextarea.prototype, "slInput", 2);
  293. __decorateClass([
  294. event("sl-focus")
  295. ], SlTextarea.prototype, "slFocus", 2);
  296. __decorateClass([
  297. event("sl-blur")
  298. ], SlTextarea.prototype, "slBlur", 2);
  299. __decorateClass([
  300. watch("rows")
  301. ], SlTextarea.prototype, "handleRowsChange", 1);
  302. __decorateClass([
  303. watch("helpText"),
  304. watch("label")
  305. ], SlTextarea.prototype, "handleSlotChange", 1);
  306. __decorateClass([
  307. watch("value")
  308. ], SlTextarea.prototype, "handleValueChange", 1);
  309. SlTextarea = __decorateClass([
  310. n("sl-textarea")
  311. ], SlTextarea);
  312. var textarea_default2 = SlTextarea;
  313. export {
  314. textarea_default2 as textarea_default
  315. };