chunk.ZSB7SSW4.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/radio/radio.scss
  24. var radio_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.radio {\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.radio__icon {\n display: inline-flex;\n width: var(--sl-toggle-size);\n height: var(--sl-toggle-size);\n}\n.radio__icon svg {\n width: 100%;\n height: 100%;\n}\n\n.radio__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: 50%;\n background-color: var(--sl-input-background-color);\n color: transparent;\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.radio__control input[type=radio] {\n position: absolute;\n opacity: 0;\n padding: 0;\n margin: 0;\n pointer-events: none;\n}\n\n.radio:not(.radio--checked):not(.radio--disabled) .radio__control:hover {\n border-color: var(--sl-input-border-color-hover);\n background-color: var(--sl-input-background-color-hover);\n}\n\n.radio.radio--focused:not(.radio--checked):not(.radio--disabled) .radio__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.radio--checked .radio__control {\n color: var(--sl-color-white);\n border-color: var(--sl-color-primary-500);\n background-color: var(--sl-color-primary-500);\n}\n\n.radio.radio--checked:not(.radio--disabled) .radio__control:hover {\n border-color: var(--sl-color-primary-400);\n background-color: var(--sl-color-primary-400);\n}\n\n.radio.radio--checked:not(.radio--disabled).radio--focused .radio__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.radio--disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.radio:not(.radio--checked) svg circle {\n opacity: 0;\n}\n\n.radio__label {\n line-height: var(--sl-toggle-size);\n margin-left: 0.5em;\n user-select: none;\n}";
  25. // src/components/radio/radio.ts
  26. var id = 0;
  27. var SlRadio = class extends h {
  28. constructor() {
  29. super(...arguments);
  30. this.inputId = `radio-${++id}`;
  31. this.labelId = `radio-label-${id}`;
  32. this.hasFocus = false;
  33. this.disabled = false;
  34. this.checked = false;
  35. this.invalid = false;
  36. }
  37. click() {
  38. this.input.click();
  39. }
  40. focus(options) {
  41. this.input.focus(options);
  42. }
  43. blur() {
  44. this.input.blur();
  45. }
  46. reportValidity() {
  47. return this.input.reportValidity();
  48. }
  49. setCustomValidity(message) {
  50. this.input.setCustomValidity(message);
  51. this.invalid = !this.input.checkValidity();
  52. }
  53. getAllRadios() {
  54. const radioGroup = this.closest("sl-radio-group");
  55. if (!radioGroup) {
  56. return [];
  57. }
  58. return [...radioGroup.querySelectorAll("sl-radio")].filter((radio) => radio.name === this.name);
  59. }
  60. getSiblingRadios() {
  61. return this.getAllRadios().filter((radio) => radio !== this);
  62. }
  63. handleCheckedChange() {
  64. if (this.checked) {
  65. this.getSiblingRadios().map((radio) => radio.checked = false);
  66. }
  67. this.input.checked = this.checked;
  68. this.slChange.emit();
  69. }
  70. handleClick() {
  71. this.checked = true;
  72. }
  73. handleBlur() {
  74. this.hasFocus = false;
  75. this.slBlur.emit();
  76. }
  77. handleFocus() {
  78. this.hasFocus = true;
  79. this.slFocus.emit();
  80. }
  81. handleKeyDown(event2) {
  82. if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event2.key)) {
  83. const radios = this.getAllRadios().filter((radio) => !radio.disabled);
  84. const incr = ["ArrowUp", "ArrowLeft"].includes(event2.key) ? -1 : 1;
  85. let index = radios.indexOf(this) + incr;
  86. if (index < 0)
  87. index = radios.length - 1;
  88. if (index > radios.length - 1)
  89. index = 0;
  90. this.getAllRadios().map((radio) => radio.checked = false);
  91. radios[index].focus();
  92. radios[index].checked = true;
  93. event2.preventDefault();
  94. }
  95. }
  96. handleMouseDown(event2) {
  97. event2.preventDefault();
  98. this.input.focus();
  99. }
  100. render() {
  101. return T`
  102. <label
  103. part="base"
  104. class=${e2({
  105. radio: true,
  106. "radio--checked": this.checked,
  107. "radio--disabled": this.disabled,
  108. "radio--focused": this.hasFocus
  109. })}
  110. for=${this.inputId}
  111. @keydown=${this.handleKeyDown}
  112. @mousedown=${this.handleMouseDown}
  113. >
  114. <span part="control" class="radio__control">
  115. <span part="checked-icon" class="radio__icon">
  116. <svg viewBox="0 0 16 16">
  117. <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
  118. <g fill="currentColor">
  119. <circle cx="8" cy="8" r="3.42857143"></circle>
  120. </g>
  121. </g>
  122. </svg>
  123. </span>
  124. <input
  125. id=${this.inputId}
  126. type="radio"
  127. name=${l(this.name)}
  128. value=${l(this.value)}
  129. ?checked=${this.checked}
  130. ?disabled=${this.disabled}
  131. aria-checked=${this.checked ? "true" : "false"}
  132. aria-disabled=${this.disabled ? "true" : "false"}
  133. aria-labelledby=${this.labelId}
  134. @click=${this.handleClick}
  135. @blur=${this.handleBlur}
  136. @focus=${this.handleFocus}
  137. />
  138. </span>
  139. <span part="label" id=${this.labelId} class="radio__label">
  140. <slot></slot>
  141. </span>
  142. </label>
  143. `;
  144. }
  145. };
  146. SlRadio.styles = r(radio_default);
  147. __decorateClass([
  148. o('input[type="radio"]')
  149. ], SlRadio.prototype, "input", 2);
  150. __decorateClass([
  151. r2()
  152. ], SlRadio.prototype, "hasFocus", 2);
  153. __decorateClass([
  154. e()
  155. ], SlRadio.prototype, "name", 2);
  156. __decorateClass([
  157. e()
  158. ], SlRadio.prototype, "value", 2);
  159. __decorateClass([
  160. e({ type: Boolean, reflect: true })
  161. ], SlRadio.prototype, "disabled", 2);
  162. __decorateClass([
  163. e({ type: Boolean, reflect: true })
  164. ], SlRadio.prototype, "checked", 2);
  165. __decorateClass([
  166. e({ type: Boolean, reflect: true })
  167. ], SlRadio.prototype, "invalid", 2);
  168. __decorateClass([
  169. event("sl-blur")
  170. ], SlRadio.prototype, "slBlur", 2);
  171. __decorateClass([
  172. event("sl-change")
  173. ], SlRadio.prototype, "slChange", 2);
  174. __decorateClass([
  175. event("sl-focus")
  176. ], SlRadio.prototype, "slFocus", 2);
  177. __decorateClass([
  178. watch("checked")
  179. ], SlRadio.prototype, "handleCheckedChange", 1);
  180. SlRadio = __decorateClass([
  181. n("sl-radio")
  182. ], SlRadio);
  183. var radio_default2 = SlRadio;
  184. export {
  185. radio_default2 as radio_default
  186. };