Files
puter/src/UI/Components/Button.js
T

51 lines
2.1 KiB
JavaScript

import { Component } from "../../util/Component.js";
export default class Button extends Component {
static PROPERTIES = {
label: { value: 'Test Label' },
on_click: { value: null },
enabled: { value: true },
}
static RENDER_MODE = Component.NO_SHADOW;
static CSS = /*css*/`
button {
margin: 0;
color: hsl(220, 25%, 31%);
}
`;
create_template ({ template }) {
$(template).html(/*html*/`
<button type="submit" class="button button-block button-primary code-confirm-btn" style="margin-top:10px;" disabled>${
html_encode(this.get('label'))
}</button>
`);
}
on_ready ({ listen }) {
if ( this.get('on_click') ) {
const $button = $(this.dom_).find('button');
$button.on('click', async () => {
$button.html(`<svg style="width:20px; margin-top: 5px;" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><title>circle anim</title><g fill="#fff" class="nc-icon-wrapper"><g class="nc-loop-circle-24-icon-f"><path d="M12 24a12 12 0 1 1 12-12 12.013 12.013 0 0 1-12 12zm0-22a10 10 0 1 0 10 10A10.011 10.011 0 0 0 12 2z" fill="#eee" opacity=".4"></path><path d="M24 12h-2A10.011 10.011 0 0 0 12 2V0a12.013 12.013 0 0 1 12 12z" data-color="color-2"></path></g><style>.nc-loop-circle-24-icon-f{--animation-duration:0.5s;transform-origin:12px 12px;animation:nc-loop-circle-anim var(--animation-duration) infinite linear}@keyframes nc-loop-circle-anim{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style></g></svg>`);
const on_click = this.get('on_click');
await on_click();
$button.html(this.get('label'));
});
}
listen('enabled', enabled => {
$(this.dom_).find('button').prop('disabled', ! enabled);
});
}
}
// TODO: This is necessary because files can be loaded from
// both `/src/UI` and `/UI` in the URL; we need to fix that
if ( ! window.__component_button ) {
window.__component_button = true;
customElements.define('c-button', Button);
}