chunk.LLZCD55S.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {
  2. l
  3. } from "./chunk.5MED2A3H.js";
  4. import {
  5. e
  6. } from "./chunk.YXKHB4AC.js";
  7. import {
  8. T
  9. } from "./chunk.5PIDMFOE.js";
  10. // src/internal/form-control.ts
  11. var renderFormControl = (props, input) => {
  12. const hasLabel = props.label ? true : !!props.hasLabelSlot;
  13. const hasHelpText = props.helpText ? true : !!props.hasHelpTextSlot;
  14. return T`
  15. <div
  16. part="form-control"
  17. class=${e({
  18. "form-control": true,
  19. "form-control--small": props.size === "small",
  20. "form-control--medium": props.size === "medium",
  21. "form-control--large": props.size === "large",
  22. "form-control--has-label": hasLabel,
  23. "form-control--has-help-text": hasHelpText
  24. })}
  25. >
  26. <label
  27. part="label"
  28. id=${l(props.labelId)}
  29. class="form-control__label"
  30. for=${props.inputId}
  31. aria-hidden=${hasLabel ? "false" : "true"}
  32. @click=${(event) => props.onLabelClick ? props.onLabelClick(event) : null}
  33. >
  34. <slot name="label">${props.label}</slot>
  35. </label>
  36. <div class="form-control__input">${T`${input}`}</div>
  37. <div
  38. part="help-text"
  39. id=${l(props.helpTextId)}
  40. class="form-control__help-text"
  41. aria-hidden=${hasHelpText ? "false" : "true"}
  42. >
  43. <slot name="help-text">${props.helpText}</slot>
  44. </div>
  45. </div>
  46. `;
  47. };
  48. function getLabelledBy(props) {
  49. const labelledBy = [
  50. props.label || props.hasLabelSlot ? props.labelId : "",
  51. props.helpText || props.hasHelpTextSlot ? props.helpTextId : ""
  52. ].filter((val) => val);
  53. return labelledBy.join(" ") || void 0;
  54. }
  55. export {
  56. renderFormControl,
  57. getLabelledBy
  58. };