Components
kick
{{-- src/views/components/user-card.kick --}}
@input user
@input compact = false
<div class="card">
<strong>{{ user.name }}</strong>
@if (!compact) {
<p>{{ user.email }}</p>
}
<slot>No details</slot>
<footer><slot name="footer" /></footer>
</div>
{{-- in a page --}}
@for (u of users; track u.id) {
<user-card [user]="u" compact class="mb-2">
Joined {{ u.joined | date:'mediumDate' }}
@slot('footer') {
<a href="/users/{{ u.id }}">Open</a>
}
</user-card>
}- A tag with a hyphen that matches
src/views/components/<path>.kickis a component. Folders join with-, socomponents/forms/text-field.kickis<forms-text-field>. The component's content replaces the tag. @input nameis required;@input name = valuehas a default.[name]="expr"passes an expression,name="text"a string, and a barenametrue.compact="false"passes the string"false", which is truthy, so write[compact]="false".- Kebab-case (
user-id="1") bindsuserId. - A missing required input fails the check.
- Every other attribute goes to the component's single root element. That covers
class,id,hx-*,x-*,type,[disabled]="…"and anything else. Classes and styles merge with the root's own; any other attribute replaces the root's attribute of the same name.- Each one is checked as if written on that element, so
<ui-link href="{{ url }}">gets the URL check of the<a>it lands on. - A name close to an input warns:
compcatasks whether you meantcompact. - When the root is itself a component (a wrapper such as
primary-buttonaround<ui-button>), the attributes pass on: one the inner component declares becomes its input, and the rest go to its root. - Some attributes decide how their element is checked, so the component must declare them as inputs:
type,name,value,checkedandvalidateon an<input>,<select>,<textarea>or<option>root (they control form refill), andhttp-equivandcontenton a<meta>root. - A component whose root isn't a single element (several roots, a block such as
@if, a<slot>) can't take extra attributes: the check names them. A<component>root takes onlyclass,id,style,role,aria-*anddata-*, which no check depends on; its element is only chosen at render time. typeon a<script>root is refused too: it decides how{{ }}inside the script is checked.
- Each one is checked as if written on that element, so
- A component sees only its inputs. Content passed between its tags uses the page's data.
- Components can include themselves (trees), up to 64 levels deep.
Slots that receive data
A component can hand values to the content its caller puts in a slot: a list that leaves each row's markup to the page, say.
kick
{{-- src/views/components/user-list.kick --}}
@input users
<ul>
@for (u of users; track u.id) {
<li><slot name="row" [user]="u">{{ user.name }}</slot></li>
}
</ul>kick
<user-list [users]="team">
@slot('row'; let user) {
<a href="/users/{{ user.id }}">{{ user.name }}</a>
}
</user-list>- A
<slot>takes onlyname="…", which picks the slot, and[value]="expr"bindings, which offer values ([name]="…"offers one calledname). Any other attribute is an error: a template that used to putclasson a<slot>, where it was ignored, should move it to a real element. [name]="expr"on a<slot>offers a value. The default slot offers values the same way (<slot [item]="x" />) and is filled with@slot(default; let item) { … }.let usertakes an offered value, andlet u = userrenames it. Taking a name the slot doesn't offer fails the check, listing what it offers. Content written between the tags without@slotreceives nothing.- The slot's fallback content can read the values it offers.
- Every
<slot>with one name must offer the same names. - A layout's slots can offer values to a page's
@slotthe same way.
Dynamic components
To pick a component from data, such as a dashboard widget's type, list the ones it may be:
kick
<component [is]="widget.type" of="chart-bar chart-line stat-card" [data]="widget" />ofnames the candidate tags, and the check covers every one of them: each must exist, and each one's required inputs must be given. An attribute that one candidate declares as an input goes to that candidate's root on the others.- At render time,
nullorundefinedrenders nothing. Any value outside the list fails the render, listing the candidates, so data can't reach a component you didn't list. - Slot content works as for any component. A fill only some candidates have renders for those, and a value only some offer is
undefinedfor the rest.