Atom binding
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const query = atom("");
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:28rem;width:100%;">
${SearchField({ atom: query, debounceMs: 300, placeholder: "Search users…", label: "Search" })}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
value / setValue binding
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const query = atom("");
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:28rem;width:100%;">
${SearchField({ value: query(), setValue: (v) => query.set(v), debounceMs: 500, label: "Search", placeholder: "Search products…" })}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Debounce delay comparison
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const instant = atom("");
const fast = atom("");
const slow = atom("");
return () => html`
<x-row gap="var(--md-space-5)" wrap style="align-items:flex-start;">
<x-col gap="var(--md-space-2)" style="min-width:14rem;">
${SearchField({ atom: instant, debounceMs: 0, placeholder: "Instant…", label: "0 ms" })}
</x-col>
<x-col gap="var(--md-space-2)" style="min-width:14rem;">
${SearchField({ atom: fast, debounceMs: 300, placeholder: "300 ms…", label: "300 ms (default)" })}
</x-col>
<x-col gap="var(--md-space-2)" style="min-width:14rem;">
${SearchField({ atom: slow, debounceMs: 1000, placeholder: "1 000 ms…", label: "1 000 ms" })}
</x-col>
</x-row>
`;
};
renderApp(App, document.getElementById('app'));
Loading state
import { html, atom, renderApp } from 'mates';
import { SearchField, FilledButton } from 'mates-ui';
const App = () => {
const fixed = atom("results loading");
const toggleQ = atom("toggle me");
const loading = atom(false);
return () => html`
<x-col gap="var(--md-space-5)" style="max-width:28rem;width:100%;">
${SearchField({ atom: fixed, loading: true, label: "Always loading", placeholder: "Search…" })}
<x-col gap="var(--md-space-3)">
${SearchField({ atom: toggleQ, loading: loading(), label: "Toggle loading" })}
${FilledButton(loading() ? "Stop loading" : "Start loading", {
onClick: () => loading.set((v) => !v),
})}
</x-col>
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Sizes
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const sm = atom(""); const md = atom(""); const lg = atom("");
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:28rem;width:100%;">
${SearchField({ atom: sm, size: "sm", placeholder: "Small…", label: "sm" })}
${SearchField({ atom: md, size: "md", placeholder: "Medium…", label: "md" })}
${SearchField({ atom: lg, size: "lg", placeholder: "Large…", label: "lg" })}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Variants
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const o = atom(""); const f = atom("");
return () => html`
<x-row gap="var(--md-space-6)" wrap style="align-items:flex-start;">
<x-col gap="var(--md-space-2)" style="min-width:16rem;">
${SearchField({ atom: o, variant: "outlined", label: "Outlined (default)", placeholder: "Search…" })}
</x-col>
<x-col gap="var(--md-space-2)" style="min-width:16rem;">
${SearchField({ atom: f, variant: "filled", label: "Filled", placeholder: "Search…" })}
</x-col>
</x-row>
`;
};
renderApp(App, document.getElementById('app'));
Disabled + Error
import { html, atom, renderApp } from 'mates';
import { SearchField } from 'mates-ui';
const App = () => {
const disabled = atom("pre-filled query");
const error = atom("???");
const helper = atom("");
return () => html`
<x-row gap="var(--md-space-5)" wrap style="align-items:flex-start;">
<x-col gap="var(--md-space-2)" style="min-width:16rem;">
${SearchField({ atom: disabled, disabled: true, label: "Disabled", placeholder: "Search…" })}
</x-col>
<x-col gap="var(--md-space-2)" style="min-width:16rem;">
${SearchField({ atom: error, errorText: "Query contains invalid characters.", label: "Error", placeholder: "Search…" })}
</x-col>
<x-col gap="var(--md-space-2)" style="min-width:16rem;">
${SearchField({ atom: helper, helperText: "Results update after 300 ms.", label: "Helper", placeholder: "Search…" })}
</x-col>
</x-row>
`;
};
renderApp(App, document.getElementById('app'));