chunk.UFFYEIKB.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import {
  2. l
  3. } from "./chunk.5MED2A3H.js";
  4. import {
  5. event,
  6. watch
  7. } from "./chunk.XX234VRK.js";
  8. import {
  9. e as e2
  10. } from "./chunk.YXKHB4AC.js";
  11. import {
  12. T,
  13. e,
  14. h,
  15. n,
  16. o,
  17. r,
  18. r2
  19. } from "./chunk.5PIDMFOE.js";
  20. import {
  21. __decorateClass
  22. } from "./chunk.IHGPZX35.js";
  23. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/checkbox/checkbox.scss
  24. var checkbox_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:host {\n display: inline-block;\n}\n\n.checkbox {\n display: inline-flex;\n align-items: center;\n font-family: var(--sl-input-font-family);\n font-size: var(--sl-input-font-size-medium);\n font-weight: var(--sl-input-font-weight);\n color: var(--sl-input-color);\n vertical-align: middle;\n cursor: pointer;\n}\n\n.checkbox__control {\n flex: 0 0 auto;\n position: relative;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: var(--sl-toggle-size);\n height: var(--sl-toggle-size);\n border: solid var(--sl-input-border-width) var(--sl-input-border-color);\n border-radius: 2px;\n background-color: var(--sl-input-background-color);\n color: var(--sl-color-white);\n transition: var(--sl-transition-fast) border-color, var(--sl-transition-fast) background-color, var(--sl-transition-fast) color, var(--sl-transition-fast) box-shadow;\n}\n.checkbox__control input[type=checkbox] {\n position: absolute;\n opacity: 0;\n padding: 0;\n margin: 0;\n pointer-events: none;\n}\n.checkbox__control .checkbox__icon {\n display: inline-flex;\n width: var(--sl-toggle-size);\n height: var(--sl-toggle-size);\n}\n.checkbox__control .checkbox__icon svg {\n width: 100%;\n height: 100%;\n}\n\n.checkbox:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__control:hover {\n border-color: var(--sl-input-border-color-hover);\n background-color: var(--sl-input-background-color-hover);\n}\n\n.checkbox.checkbox--focused:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__control {\n border-color: var(--sl-input-border-color-focus);\n background-color: var(--sl-input-background-color-focus);\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.checkbox--checked .checkbox__control,\n.checkbox--indeterminate .checkbox__control {\n border-color: var(--sl-color-primary-500);\n background-color: var(--sl-color-primary-500);\n}\n\n.checkbox.checkbox--checked:not(.checkbox--disabled) .checkbox__control:hover,\n.checkbox.checkbox--indeterminate:not(.checkbox--disabled) .checkbox__control:hover {\n border-color: var(--sl-color-primary-400);\n background-color: var(--sl-color-primary-400);\n}\n\n.checkbox.checkbox--checked:not(.checkbox--disabled).checkbox--focused .checkbox__control,\n.checkbox.checkbox--indeterminate:not(.checkbox--disabled).checkbox--focused .checkbox__control {\n border-color: var(--sl-color-primary-400);\n background-color: var(--sl-color-primary-400);\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.checkbox--disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.checkbox__label {\n line-height: var(--sl-toggle-size);\n margin-left: 0.5em;\n user-select: none;\n}";
  25. // src/components/checkbox/checkbox.ts
  26. var id = 0;
  27. var SlCheckbox = class extends h {
  28. constructor() {
  29. super(...arguments);
  30. this.inputId = `checkbox-${++id}`;
  31. this.labelId = `checkbox-label-${id}`;
  32. this.hasFocus = false;
  33. this.disabled = false;
  34. this.required = false;
  35. this.checked = false;
  36. this.indeterminate = false;
  37. this.invalid = false;
  38. }
  39. firstUpdated() {
  40. this.input.indeterminate = this.indeterminate;
  41. }
  42. click() {
  43. this.input.click();
  44. }
  45. focus(options) {
  46. this.input.focus(options);
  47. }
  48. blur() {
  49. this.input.blur();
  50. }
  51. reportValidity() {
  52. return this.input.reportValidity();
  53. }
  54. setCustomValidity(message) {
  55. this.input.setCustomValidity(message);
  56. this.invalid = !this.input.checkValidity();
  57. }
  58. handleClick() {
  59. this.checked = !this.checked;
  60. this.indeterminate = false;
  61. }
  62. handleBlur() {
  63. this.hasFocus = false;
  64. this.slBlur.emit();
  65. }
  66. handleFocus() {
  67. this.hasFocus = true;
  68. this.slFocus.emit();
  69. }
  70. handleLabelMouseDown(event2) {
  71. event2.preventDefault();
  72. this.input.focus();
  73. }
  74. handleStateChange() {
  75. this.input.checked = this.checked;
  76. this.input.indeterminate = this.indeterminate;
  77. this.slChange.emit();
  78. }
  79. render() {
  80. return T`
  81. <label
  82. part="base"
  83. class=${e2({
  84. checkbox: true,
  85. "checkbox--checked": this.checked,
  86. "checkbox--disabled": this.disabled,
  87. "checkbox--focused": this.hasFocus,
  88. "checkbox--indeterminate": this.indeterminate
  89. })}
  90. for=${this.inputId}
  91. @mousedown=${this.handleLabelMouseDown}
  92. >
  93. <span part="control" class="checkbox__control">
  94. ${this.checked ? T`
  95. <span part="checked-icon" class="checkbox__icon">
  96. <svg viewBox="0 0 16 16">
  97. <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round">
  98. <g stroke="currentColor" stroke-width="2">
  99. <g transform="translate(3.428571, 3.428571)">
  100. <path d="M0,5.71428571 L3.42857143,9.14285714"></path>
  101. <path d="M9.14285714,0 L3.42857143,9.14285714"></path>
  102. </g>
  103. </g>
  104. </g>
  105. </svg>
  106. </span>
  107. ` : ""}
  108. ${!this.checked && this.indeterminate ? T`
  109. <span part="indeterminate-icon" class="checkbox__icon">
  110. <svg viewBox="0 0 16 16">
  111. <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round">
  112. <g stroke="currentColor" stroke-width="2">
  113. <g transform="translate(2.285714, 6.857143)">
  114. <path d="M10.2857143,1.14285714 L1.14285714,1.14285714"></path>
  115. </g>
  116. </g>
  117. </g>
  118. </svg>
  119. </span>
  120. ` : ""}
  121. <input
  122. id=${this.inputId}
  123. type="checkbox"
  124. name=${l(this.name)}
  125. value=${l(this.value)}
  126. ?checked=${this.checked}
  127. ?disabled=${this.disabled}
  128. ?required=${this.required}
  129. role="checkbox"
  130. aria-checked=${this.checked ? "true" : "false"}
  131. aria-labelledby=${this.labelId}
  132. @click=${this.handleClick}
  133. @blur=${this.handleBlur}
  134. @focus=${this.handleFocus}
  135. />
  136. </span>
  137. <span part="label" id=${this.labelId} class="checkbox__label">
  138. <slot></slot>
  139. </span>
  140. </label>
  141. `;
  142. }
  143. };
  144. SlCheckbox.styles = r(checkbox_default);
  145. __decorateClass([
  146. o('input[type="checkbox"]')
  147. ], SlCheckbox.prototype, "input", 2);
  148. __decorateClass([
  149. r2()
  150. ], SlCheckbox.prototype, "hasFocus", 2);
  151. __decorateClass([
  152. e()
  153. ], SlCheckbox.prototype, "name", 2);
  154. __decorateClass([
  155. e()
  156. ], SlCheckbox.prototype, "value", 2);
  157. __decorateClass([
  158. e({ type: Boolean, reflect: true })
  159. ], SlCheckbox.prototype, "disabled", 2);
  160. __decorateClass([
  161. e({ type: Boolean, reflect: true })
  162. ], SlCheckbox.prototype, "required", 2);
  163. __decorateClass([
  164. e({ type: Boolean, reflect: true })
  165. ], SlCheckbox.prototype, "checked", 2);
  166. __decorateClass([
  167. e({ type: Boolean, reflect: true })
  168. ], SlCheckbox.prototype, "indeterminate", 2);
  169. __decorateClass([
  170. e({ type: Boolean, reflect: true })
  171. ], SlCheckbox.prototype, "invalid", 2);
  172. __decorateClass([
  173. event("sl-blur")
  174. ], SlCheckbox.prototype, "slBlur", 2);
  175. __decorateClass([
  176. event("sl-change")
  177. ], SlCheckbox.prototype, "slChange", 2);
  178. __decorateClass([
  179. event("sl-focus")
  180. ], SlCheckbox.prototype, "slFocus", 2);
  181. __decorateClass([
  182. watch("checked"),
  183. watch("indeterminate")
  184. ], SlCheckbox.prototype, "handleStateChange", 1);
  185. SlCheckbox = __decorateClass([
  186. n("sl-checkbox")
  187. ], SlCheckbox);
  188. var checkbox_default2 = SlCheckbox;
  189. export {
  190. checkbox_default2 as checkbox_default
  191. };