Basic
import { html, atom, renderApp } from 'mates';
import { TextSelect, Text } from 'mates-ui';
const App = () => {
const font = atom(""); const theme = atom(""); const lang = atom("");
return () => html`
<x-col gap="var(--md-space-4)">
<x-row gap="var(--md-space-5)" align="center" wrap>
${TextSelect({ options: [{ id: "sm", label: "Small" }, { id: "md", label: "Medium" }, { id: "lg", label: "Large" }, { id: "xl", label: "Extra Large" }], value: font(), onChange: (id) => font.set(id), placeholder: "Font size…", popup: { position: "bottom-start" } })}
${TextSelect({ options: [{ id: "light", label: "Light" }, { id: "dark", label: "Dark" }, { id: "system", label: "System" }], value: theme(), onChange: (id) => theme.set(id), placeholder: "Theme…", popup: { position: "bottom-start" } })}
${TextSelect({ options: [{ id: "en", label: "English" }, { id: "fr", label: "Français" }, { id: "de", label: "Deutsch" }, { id: "ja", label: "日本語" }], value: lang(), onChange: (id) => lang.set(id), placeholder: "Language…", popup: { position: "bottom-start" } })}
</x-row>
${Text("Font: " + (font() || "—") + " · Theme: " + (theme() || "—") + " · Lang: " + (lang() || "—"), { type: "body-sm", color: "muted" })}
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Sizes
import { html, atom, renderApp } from 'mates';
import { TextSelect, Text } from 'mates-ui';
const OPTS = [{ id: "sm", label: "Small" }, { id: "md", label: "Medium" }, { id: "lg", label: "Large" }];
const App = () => {
const sm = atom(""); const md = atom(""); const lg = atom("");
return () => html`
<x-col gap="var(--md-space-3)">
<x-row gap="var(--md-space-4)" align="center">
${Text("sm", { type: "label-sm", color: "muted" })}
${TextSelect({ size: "sm", options: OPTS, value: sm(), onChange: (id) => sm.set(id), placeholder: "Pick size…", popup: { position: "bottom-start" } })}
</x-row>
<x-row gap="var(--md-space-4)" align="center">
${Text("md", { type: "label-sm", color: "muted" })}
${TextSelect({ size: "md", options: OPTS, value: md(), onChange: (id) => md.set(id), placeholder: "Pick size…", popup: { position: "bottom-start" } })}
</x-row>
<x-row gap="var(--md-space-4)" align="center">
${Text("lg", { type: "label-sm", color: "muted" })}
${TextSelect({ size: "lg", options: OPTS, value: lg(), onChange: (id) => lg.set(id), placeholder: "Pick size…", popup: { position: "bottom-start" } })}
</x-row>
</x-col>
`;
};
renderApp(App, document.getElementById('app'));
Inline in text
import { html, atom, renderApp } from 'mates';
import { TextSelect } from 'mates-ui';
const App = () => {
const perPage = atom("10");
const sortBy = atom("name");
const order = atom("asc");
return () => html`
<p style="font-size:var(--md-text-base);color:var(--md-color-text);line-height:2;">
Show
${TextSelect({ options: [{ id: "10", label: "10" }, { id: "25", label: "25" }, { id: "50", label: "50" }, { id: "100", label: "100" }], value: perPage(), onChange: (id) => perPage.set(id), popup: { position: "bottom-start" } })}
items per page, sorted by
${TextSelect({ options: [{ id: "name", label: "name" }, { id: "date", label: "date" }, { id: "size", label: "size" }], value: sortBy(), onChange: (id) => sortBy.set(id), popup: { position: "bottom-start" } })},
in
${TextSelect({ options: [{ id: "asc", label: "ascending" }, { id: "desc", label: "descending" }], value: order(), onChange: (id) => order.set(id), popup: { position: "bottom-start" } })}
order.
</p>
`;
};
renderApp(App, document.getElementById('app'));
Disabled
import { html, renderApp } from 'mates';
import { TextSelect } from 'mates-ui';
const OPTS = [{ id: "sm", label: "Small" }, { id: "md", label: "Medium" }, { id: "lg", label: "Large" }];
const App = () => () => html`
<x-row gap="var(--md-space-5)" align="center">
${TextSelect({ options: OPTS, value: "md", disabled: true, popup: { position: "bottom-start" } })}
${TextSelect({ options: OPTS, placeholder: "Pick size…", disabled: true, popup: { position: "bottom-start" } })}
</x-row>
`;
renderApp(App, document.getElementById('app'));