const Component = use('util.Component');
export default def(class Button extends Component {
static ID = 'ui.component.Button';
static PROPERTIES = {
label: { value: 'Test Label' },
on_click: { value: null },
enabled: { value: true },
style: { value: 'primary' }
}
static RENDER_MODE = Component.NO_SHADOW;
static CSS = /*css*/`
button {
margin: 0;
color: hsl(220, 25%, 31%);
}
.link-button {
background: none;
border: none;
color: #3b4863;
text-decoration: none;
cursor: pointer;
text-align: center;
display: block;
width: 100%;
}
.link-button:hover {
text-decoration: underline;
}
`;
create_template ({ template }) {
if ( this.get('style') === 'link' ) {
$(template).html(/*html*/`
`);
return;
}
// TODO: Replace hack for 'small' with a better way to configure button classes.
$(template).html(/*html*/`
`);
}
on_ready ({ listen }) {
if ( this.get('on_click') ) {
const $button = $(this.dom_).find('button');
$button.on('click', async () => {
$button.html(``);
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);
});
}
});