0.0.133 • Published 1 year ago
@rhtml/decorators v0.0.133
@rhtml/decorators
Installation
npm i @rhtml/decorators
Usage
import { Attribute, Options, Input } from '@rhtml/custom-attributes';
import { HostListener } from '@rhtml/decorators';
@Modifier({
selector: 'test'
})
export class TestDirective extends Attribute {
@Input()
myProperty: string;
@HostListener('mouseenter')
enter(event: Event) {
console.log('ENTER', this, event);
console.log(this.myProperty);
}
@HostListener('mouseleave')
leave(event: Event) {
console.log('LEAVE', this, event);
console.log(this.myProperty);
}
}
<div test myProperty="12312">
111
</div>
Usage inside @rxdi/lit-html
import { Component, html, LitElement } from '@rxdi/lit-html';
import { HostListener } from '@rhtml/decorators';
/**
* @customElement home-component
*/
@Component({
selector: 'home-component',
template(this) {
return html`
Home Component
`;
}
})
export class HomeComponent extends LitElement {
@HostListener('mouseenter') onEnter() {
console.log('Enter home');
}
@HostListener('mouseleave') onLeave() {
console.log('Leave home');
}
}
@HostBinding and @Input decorators
Specifiyng Input and HostBinding decorator gives you an reactive ability to assign styles directly to input properties
This way by editing padding
, color
or background
will reflect to the style associated with
By doing this we can skip OnInit
, OnDestroy
, OnUpdate
manual assign inside hooks
import { Attribute, Input, Modifier } from '@rhtml/custom-attributes';
import { HostBinding } from '@rhtml/decorators';
@Modifier({
selector: 'layout'
})
export class CustomLayout extends Attribute {
@Input({ observe: true })
@HostBinding('style.padding')
padding: string;
@Input({ observe: true })
@HostBinding('style.color')
color: string;
@Input({ observe: true })
@HostBinding('style.background')
background: string;
}
0.0.133
1 year ago
0.0.131
1 year ago
0.0.132
1 year ago
0.0.130
1 year ago
0.0.129
1 year ago
0.0.128
1 year ago
0.0.127
1 year ago
0.0.126
1 year ago
0.0.125
2 years ago
0.0.120
2 years ago
0.0.124
2 years ago
0.0.123
2 years ago
0.0.122
2 years ago
0.0.121
2 years ago
0.0.119
2 years ago
0.0.118
3 years ago
0.0.117
3 years ago
0.0.116
3 years ago
0.0.115
3 years ago
0.0.114
3 years ago
0.0.113
3 years ago
0.0.112
3 years ago
0.0.111
3 years ago
0.0.110
3 years ago
0.0.109
3 years ago
0.0.108
3 years ago
0.0.107
3 years ago
0.0.106
3 years ago
0.0.105
3 years ago
0.0.104
3 years ago
0.0.103
3 years ago
0.0.102
3 years ago
0.0.101
3 years ago