index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Checkbox = void 0;
  4. var tslib_1 = require("tslib");
  5. var core_1 = require("../../core");
  6. var util_1 = require("../../util");
  7. var constant_1 = require("./constant");
  8. function getLablePosition(shape, spacing) {
  9. var bounds = shape.getLocalBounds();
  10. return {
  11. x: bounds.halfExtents[0] ? bounds.max[0] + (spacing || 0) : shape.style.x,
  12. y: bounds.halfExtents[1] ? (bounds.min[1] + bounds.max[1]) / 2 : shape.style.y,
  13. };
  14. }
  15. var Checkbox = /** @class */ (function (_super) {
  16. tslib_1.__extends(Checkbox, _super);
  17. function Checkbox(options) {
  18. return _super.call(this, options, tslib_1.__assign({ x: 0, y: 0, labelText: '', spacing: 4, checked: false }, constant_1.LABEL_TEXT_STYLE)) || this;
  19. }
  20. Checkbox.prototype.render = function (attributes, container) {
  21. var checked = attributes.checked, spacing = attributes.spacing;
  22. this.checked = !!checked;
  23. var group = (0, util_1.maybeAppend)(container, '.checkbox-content', 'g').attr('className', 'checkbox-content').node();
  24. var boxStyle = (0, util_1.subStyleProps)(attributes, 'box');
  25. var checkedStyle = (0, util_1.subStyleProps)(attributes, 'checked');
  26. var labelStyle = (0, util_1.subStyleProps)(attributes, 'label');
  27. var checkboxStyle = tslib_1.__assign(tslib_1.__assign({}, (this.checked ? constant_1.CHECKBOX_RECT_STYLE.selected : constant_1.CHECKBOX_RECT_STYLE.default)), boxStyle);
  28. var checkboxBoxCheckedStyle = tslib_1.__assign(tslib_1.__assign({}, constant_1.CHECKED_SHAPE_STYLE), checkedStyle);
  29. this.checkboxBoxShape = (0, util_1.maybeAppend)(group, '.checkbox-box', 'rect')
  30. .styles(tslib_1.__assign({ className: 'checkbox-box', zIndex: (group.style.zIndex || 0) - 1 }, checkboxStyle))
  31. .node();
  32. (0, util_1.maybeAppend)(this.checkboxBoxShape, '.checkbox-checked', 'path').styles(tslib_1.__assign({ className: 'checkbox-box-checked', stroke: '#fff' }, checkboxBoxCheckedStyle));
  33. var _a = getLablePosition(this.checkboxBoxShape, Number(spacing)), x = _a.x, y = _a.y;
  34. (0, util_1.maybeAppend)(group, '.checkbox-label', 'text').styles(tslib_1.__assign({ className: 'checkbox-label', x: x, y: y }, labelStyle));
  35. };
  36. /**
  37. * 组件 checkbox
  38. */
  39. Checkbox.tag = 'checkbox';
  40. return Checkbox;
  41. }(core_1.GUI));
  42. exports.Checkbox = Checkbox;
  43. //# sourceMappingURL=index.js.map