index.js 2.2 KB

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