Checker.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. checkerProps: () => checkerProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_icon = require("../icon");
  28. const checkerProps = {
  29. name: import_utils.unknownProp,
  30. shape: (0, import_utils.makeStringProp)("round"),
  31. disabled: Boolean,
  32. iconSize: import_utils.numericProp,
  33. modelValue: import_utils.unknownProp,
  34. checkedColor: String,
  35. labelPosition: String,
  36. labelDisabled: Boolean
  37. };
  38. var stdin_default = (0, import_vue2.defineComponent)({
  39. props: (0, import_utils.extend)({}, checkerProps, {
  40. bem: (0, import_utils.makeRequiredProp)(Function),
  41. role: String,
  42. parent: Object,
  43. checked: Boolean,
  44. bindGroup: import_utils.truthProp
  45. }),
  46. emits: ["click", "toggle"],
  47. setup(props, {
  48. emit,
  49. slots
  50. }) {
  51. const iconRef = (0, import_vue2.ref)();
  52. const getParentProp = (name) => {
  53. if (props.parent && props.bindGroup) {
  54. return props.parent.props[name];
  55. }
  56. };
  57. const disabled = (0, import_vue2.computed)(() => getParentProp("disabled") || props.disabled);
  58. const direction = (0, import_vue2.computed)(() => getParentProp("direction"));
  59. const iconStyle = (0, import_vue2.computed)(() => {
  60. const checkedColor = props.checkedColor || getParentProp("checkedColor");
  61. if (checkedColor && props.checked && !disabled.value) {
  62. return {
  63. borderColor: checkedColor,
  64. backgroundColor: checkedColor
  65. };
  66. }
  67. });
  68. const onClick = (event) => {
  69. const {
  70. target
  71. } = event;
  72. const icon = iconRef.value;
  73. const iconClicked = icon === target || (icon == null ? void 0 : icon.contains(target));
  74. if (!disabled.value && (iconClicked || !props.labelDisabled)) {
  75. emit("toggle");
  76. }
  77. emit("click", event);
  78. };
  79. const renderIcon = () => {
  80. const {
  81. bem,
  82. shape,
  83. checked
  84. } = props;
  85. const iconSize = props.iconSize || getParentProp("iconSize");
  86. return (0, import_vue.createVNode)("div", {
  87. "ref": iconRef,
  88. "class": bem("icon", [shape, {
  89. disabled: disabled.value,
  90. checked
  91. }]),
  92. "style": {
  93. fontSize: (0, import_utils.addUnit)(iconSize)
  94. }
  95. }, [slots.icon ? slots.icon({
  96. checked,
  97. disabled: disabled.value
  98. }) : (0, import_vue.createVNode)(import_icon.Icon, {
  99. "name": "success",
  100. "style": iconStyle.value
  101. }, null)]);
  102. };
  103. const renderLabel = () => {
  104. if (slots.default) {
  105. return (0, import_vue.createVNode)("span", {
  106. "class": props.bem("label", [props.labelPosition, {
  107. disabled: disabled.value
  108. }])
  109. }, [slots.default()]);
  110. }
  111. };
  112. return () => {
  113. const nodes = props.labelPosition === "left" ? [renderLabel(), renderIcon()] : [renderIcon(), renderLabel()];
  114. return (0, import_vue.createVNode)("div", {
  115. "role": props.role,
  116. "class": props.bem([{
  117. disabled: disabled.value,
  118. "label-disabled": props.labelDisabled
  119. }, direction.value]),
  120. "tabindex": disabled.value ? void 0 : 0,
  121. "aria-checked": props.checked,
  122. "onClick": onClick
  123. }, [nodes]);
  124. };
  125. }
  126. });