@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
73 lines (72 loc) • 2.94 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StrokeActionButton = void 0;
const lit_1 = require("lit");
const decorators_js_1 = require("lit/decorators.js");
const context_1 = require("@lit/context");
const context_2 = require("../context");
const color_picker_1 = require("./color-picker");
let StrokeActionButton = class StrokeActionButton extends lit_1.LitElement {
handleStrokeChanged(e) {
const { type, value } = e.detail;
this.api.updateNode(this.node, {
stroke: type === 'solid'
? value.startsWith('#')
? value
: `#${value}`
: value,
});
this.api.record();
}
render() {
if (!this.node) {
return (0, lit_1.html) ``;
}
const { stroke } = this.node;
return (0, lit_1.html) `<sp-action-button quiet size="m" id="stroke">
<ic-spectrum-stroke-icon
value=${stroke}
slot="icon"
></ic-spectrum-stroke-icon>
<sp-tooltip self-managed placement="bottom"> Stroke </sp-tooltip>
</sp-action-button>
<sp-overlay trigger="stroke@click" placement="bottom" type="auto">
<sp-popover dialog>
<ic-spectrum-color-picker
value=${stroke}
.types=${[color_picker_1.ColorType.None, color_picker_1.ColorType.Solid]}
@color-change=${this.handleStrokeChanged}
></ic-spectrum-color-picker>
</sp-popover>
</sp-overlay>`;
}
};
exports.StrokeActionButton = StrokeActionButton;
StrokeActionButton.styles = (0, lit_1.css) `
ic-spectrum-stroke-icon {
width: 30px;
height: 30px;
}
sp-popover {
padding: 0;
}
`;
__decorate([
(0, context_1.consume)({ context: context_2.appStateContext, subscribe: true })
], StrokeActionButton.prototype, "appState", void 0);
__decorate([
(0, context_1.consume)({ context: context_2.apiContext, subscribe: true })
], StrokeActionButton.prototype, "api", void 0);
__decorate([
(0, decorators_js_1.property)()
], StrokeActionButton.prototype, "node", void 0);
exports.StrokeActionButton = StrokeActionButton = __decorate([
(0, decorators_js_1.customElement)('ic-spectrum-stroke-action-button')
], StrokeActionButton);
//# sourceMappingURL=stroke-action-button.js.map