Basic
import { html, atom, renderApp } from 'mates';
import { AutoComplete } from 'mates-ui';
const COUNTRIES = [
{ id: "us", label: "United States", subLabel: "North America" },
{ id: "uk", label: "United Kingdom", subLabel: "Europe" },
{ id: "de", label: "Germany", subLabel: "Europe" },
{ id: "fr", label: "France", subLabel: "Europe" },
{ id: "jp", label: "Japan", subLabel: "Asia" },
{ id: "au", label: "Australia", subLabel: "Oceania" },
];
const App = () => {
const selected = atom(null);
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:22rem;">
${AutoComplete({
options: COUNTRIES,
value: selected(),
label: "Country",
placeholder: "Search countries…",
onChange: (id) => selected.set(id),
})}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Variants & Sizes
import { html, atom, renderApp } from 'mates';
import { AutoComplete } from 'mates-ui';
const OPTIONS = [
{ id: "us", label: "United States", subLabel: "North America" },
{ id: "uk", label: "United Kingdom", subLabel: "Europe" },
{ id: "de", label: "Germany", subLabel: "Europe" },
{ id: "fr", label: "France", subLabel: "Europe" },
{ id: "jp", label: "Japan", subLabel: "Asia" },
];
const App = () => {
const v1 = atom(null); const v2 = atom(null); const v3 = atom(null);
const v4 = atom(null); const v5 = atom(null); const v6 = atom(null);
return () => html`
<x-row gap="var(--md-space-6)" style="max-width:48rem;align-items:flex-start;">
<x-col gap="var(--md-space-3)" style="flex:1;">
${AutoComplete({ options: OPTIONS, value: v1(), label: "Outlined sm", variant: "outlined", size: "sm", onChange: (id) => v1.set(id) })}
${AutoComplete({ options: OPTIONS, value: v2(), label: "Outlined md", variant: "outlined", size: "md", onChange: (id) => v2.set(id) })}
${AutoComplete({ options: OPTIONS, value: v3(), label: "Outlined lg", variant: "outlined", size: "lg", onChange: (id) => v3.set(id) })}
</x-col>
<x-col gap="var(--md-space-3)" style="flex:1;">
${AutoComplete({ options: OPTIONS, value: v4(), label: "Filled sm", variant: "filled", size: "sm", onChange: (id) => v4.set(id) })}
${AutoComplete({ options: OPTIONS, value: v5(), label: "Filled md", variant: "filled", size: "md", onChange: (id) => v5.set(id) })}
${AutoComplete({ options: OPTIONS, value: v6(), label: "Filled lg", variant: "filled", size: "lg", onChange: (id) => v6.set(id) })}
</x-col>
</x-row>
`;
};
renderApp(App, document.getElementById('app'));
States — Helper, Error, Disabled, Loading
import { html, atom, renderApp } from 'mates';
import { AutoComplete } from 'mates-ui';
const OPTIONS = [
{ id: "us", label: "United States", subLabel: "North America" },
{ id: "uk", label: "United Kingdom", subLabel: "Europe" },
{ id: "de", label: "Germany", subLabel: "Europe" },
];
const App = () => {
const v1 = atom(null); const v2 = atom(null);
return () => html`
<x-col gap="var(--md-space-5)" style="max-width:28rem;">
${AutoComplete({ options: OPTIONS, value: v1(), label: "With helper text", placeholder: "Search…", helper: "Start typing to filter.", onChange: (id) => v1.set(id) })}
${AutoComplete({ options: OPTIONS, value: v2(), label: "With error", placeholder: "Search…", error: "Please select a valid country.", onChange: (id) => v2.set(id) })}
${AutoComplete({ options: OPTIONS, value: "de", label: "Disabled", placeholder: "Search…", disabled: true, onChange: () => {} })}
${AutoComplete({ options: [], value: null, label: "Loading", placeholder: "Loading options…", loading: true, skeletonCount: 3, onChange: () => {} })}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Multiple selection
import { html, atom, renderApp } from 'mates';
import { AutoComplete } from 'mates-ui';
const OPTIONS = [
{ id: "us", label: "United States", subLabel: "North America" },
{ id: "uk", label: "United Kingdom", subLabel: "Europe" },
{ id: "de", label: "Germany", subLabel: "Europe" },
{ id: "fr", label: "France", subLabel: "Europe" },
{ id: "jp", label: "Japan", subLabel: "Asia" },
];
const App = () => {
const selected = atom([]);
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:28rem;">
${AutoComplete({
options: OPTIONS,
multiple: true,
values: selected(),
label: "Countries",
placeholder: "Search and pick countries…",
onChangeMultiple: (ids) => selected.set(ids),
})}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Options with Icons
import { html, atom, renderApp } from 'mates';
import { AutoComplete } from 'mates-ui';
import { AdminPanelSettingsIcon, EditIcon, VisibilityIcon, StarIcon } from 'mates-icons';
const ROLES = [
{ id: "admin", label: "Admin", subLabel: "Full access", icon: AdminPanelSettingsIcon() },
{ id: "editor", label: "Editor", subLabel: "Can edit content", icon: EditIcon() },
{ id: "viewer", label: "Viewer", subLabel: "Read only", icon: VisibilityIcon() },
{ id: "owner", label: "Owner", subLabel: "Ownership rights", icon: StarIcon() },
];
const App = () => {
const role = atom(null);
return () => html`
<x-col gap="var(--md-space-4)" style="max-width:22rem;">
${AutoComplete({
options: ROLES,
value: role(),
label: "Assign role",
placeholder: "Search roles…",
onChange: (id) => role.set(id),
})}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));