diff --git a/frontend/administration.js b/frontend/administration.js index f009dfe7..80024df1 100644 --- a/frontend/administration.js +++ b/frontend/administration.js @@ -7,7 +7,7 @@ import { noAutofill } from "./no-autofill.js"; authoritative. */ import React, { useEffect, useState } from "react"; import { createRoot } from "react-dom/client"; -import { Badge, Box, Button, Paper } from "../tools/webui/mantine.js"; +import { Badge, Box, Button, NativeSelect, Paper, TextInput } from "../tools/webui/mantine.js"; const h = React.createElement; // Access, snapshot freshness and mutation activity are independent dimensions. @@ -297,7 +297,7 @@ function ComponentCard({ record, revision }) { h("fieldset", { className: "fieldset administration-policy", disabled: (ui.getSnapshot().activity === "busy") || (ui.getSnapshot().freshness === "stale") }, h("legend", { className: "fieldset-legend" }, "Release policy"), h("label", { className: "fieldset field" }, h("span", { className: "fieldset-legend" }, "Release channel"), - h(Box, { component: "select", className: "select select-sm", "aria-label": `${record.component} release channel`, value: channel, + h(NativeSelect, { size: "sm", "aria-label": `${record.component} release channel`, value: channel, onChange: event => { const value = event.target.value; setChannel(value); return mutate(record, "Save release channel", () => { @@ -306,7 +306,7 @@ function ComponentCard({ record, revision }) { }); } }, ...["latest", "stable", "nightly"].map(value => h("option", { key: value, value }, value === "latest" ? "Latest published build" : value === "stable" ? "Stable releases" : "Nightly releases")))), h("label", { className: "fieldset field" }, h("span", { className: "fieldset-legend" }, "Automatic installation"), - h(Box, { component: "select", className: "select select-sm", "aria-label": `${record.component} automatic installation cadence`, value: cadence, + h(NativeSelect, { size: "sm", "aria-label": `${record.component} automatic installation cadence`, value: cadence, onChange: event => { const value = event.target.value; setCadence(value); return mutate(record, "Save automatic installation", () => { @@ -328,7 +328,7 @@ function AlertChannelCard({ revision }) { h("p", { className: "muted" }, "The bot posts here once when boot repair can't restore the recorded bot or API release."), !saved && h("p", { id: "alert-channel-unset", className: "muted" }, "No alert channel is set. Mismatches are logged and shown on the component cards."), h("label", { className: "fieldset field" }, h("span", { className: "fieldset-legend" }, "Alert channel ID"), - h(Box, noAutofill({ component: "input", id: "alert-channel-id", className: "input input-sm", inputMode: "numeric", value, disabled: blocked, + h(TextInput, noAutofill({ id: "alert-channel-id", size: "sm", inputMode: "numeric", value, disabled: blocked, onChange: event => setValue(event.target.value) }))), h("div", { className: "card-actions" }, h(Button, { id: "save-alert-channel", type: "button", size: "sm", variant: "default", disabled: blocked || value.trim() === saved, diff --git a/frontend/app.js b/frontend/app.js index 81fd1d36..5e7f0a84 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -27,7 +27,7 @@ import { noAutofill } from "./no-autofill.js"; import React, { useState, useEffect, useLayoutEffect, useRef, useSyncExternalStore, createContext, useContext, useId } from "react"; import { flushSync } from "react-dom"; import { createRoot } from "react-dom/client"; -import { ActionIcon, Badge, Box, Button, FocusTrap, Modal, NativeSelect, Paper, Table, Tooltip, UnstyledButton, notifications } from "../tools/webui/mantine.js"; +import { ActionIcon, Badge, Box, Button, Checkbox, FocusTrap, Modal, NativeSelect, Paper, Switch, Table, TextInput, Textarea, Tooltip, UnstyledButton, notifications } from "../tools/webui/mantine.js"; const h = React.createElement; // Activity and edits are independent: an in-flight save may retain other drafts. @@ -117,14 +117,22 @@ function useDraftControl({ draftKey, defaultValue, onChange, ...props }, multili }, }; } -function Input(props) { - return h(Box, { component: "input", id: useContext(FieldId), ...noAutofill(useDraftControl(props)) }); +function FieldInput(props) { + return h(TextInput, { id: useContext(FieldId), ...noAutofill(useDraftControl(props)) }); } -function Textarea(props) { - return h(Box, { component: "textarea", id: useContext(FieldId), ...noAutofill(useDraftControl(props, true)) }); +function FieldTextarea(props) { + return h(Textarea, { id: useContext(FieldId), ...noAutofill(useDraftControl(props, true)) }); } -function Select(props) { - return h(Box, { component: "select", id: useContext(FieldId), ...useDraftControl(props) }); +function FieldSelect(props) { + return h(NativeSelect, { id: useContext(FieldId), ...useDraftControl(props) }); +} +function FieldSwitch(props) { + const working = useContext(BusyContext); + return h(Switch, noAutofill({ ...props, disabled: working || props.disabled })); +} +function FieldCheckbox(props) { + const working = useContext(BusyContext); + return h(Checkbox, noAutofill({ ...props, disabled: working || props.disabled })); } function OwnerTools() { const profile = useRef(null); @@ -173,8 +181,8 @@ function OwnerTools() { "View as…", ), canManageServer() && h( - Select, - { ref: profile, className: "select", "aria-label": "Preview profile" }, + FieldSelect, + { ref: profile, "aria-label": "Preview profile" }, h("option", { value: "administrator" }, "Administrator"), h("option", { value: "moderator" }, "Moderator (read-only)"), h("option", { value: "settings" }, "Settings"), @@ -335,7 +343,7 @@ function ServerPicker({ guilds, selectedId, onSelect }) { ref: triggerRef, id: "guild-select", type: "button", - className: "select select-sm w-full server-picker-trigger", + className: "w-full server-picker-trigger", disabled, "aria-haspopup": "listbox", "aria-expanded": open ? "true" : "false", @@ -703,12 +711,11 @@ function AccessGrantForm({ endpoint, grantedMessage, existingMessage, onGrant }) return h( "div", { className: "row form-actions", "data-no-draft": true }, h("label", null, "Discord user ID", - h(Box, { component: "input", - className: "input", + h(TextInput, noAutofill({ inputMode: "numeric", value: userId, onChange: (event) => setUserId(event.target.value), - }), + })), ), h(ActionButton, { variant: "filled", @@ -842,8 +849,8 @@ function SystemLogDestinationEditor({ row, refresh }) { }; return h("div", { className: "row form-actions" }, h("label", null, "Discord channel ID", - h(Box, { component: "input", className: "input", inputMode: "numeric", - value: channelId, onChange: (event) => setChannelId(event.target.value) }), + h(TextInput, noAutofill({ inputMode: "numeric", + value: channelId, onChange: (event) => setChannelId(event.target.value) })), ), h(ActionButton, { variant: "filled", disabled: !/^[1-9][0-9]{0,18}$/.test(channel) || (row.approved && row.channel_id === channel), @@ -871,7 +878,7 @@ function TabSystemLogChannels() { result.data && h(Paper, { className: "card bg-base-100 card-border", "data-no-draft": true }, h("div", { className: "card-body" }, enrolled.length ? h("label", null, "Server", - h(Select, { className: "select", value: selected?.guild_id || "", + h(FieldSelect, { value: selected?.guild_id || "", onChange: (event) => setGuildId(event.target.value) }, h("option", { value: "" }, "Choose a server"), enrolled.map((row) => h("option", { key: row.guild_id, value: row.guild_id }, serverLabel(row))), @@ -1135,8 +1142,8 @@ function ServerAdminRow({ admin, refresh, limit, setLimitDraft }) { } }, }, - h(Input, { - className: "input input-sm", type: "number", min: 0, max: 4294967295, step: 1, required: true, + h(FieldInput, { + size: "sm", type: "number", min: 0, max: 4294967295, step: 1, required: true, "aria-label": `Enrollment limit for ${admin.user_id}`, value: limit, onChange: (event) => { const value = event.target.value; @@ -1721,17 +1728,17 @@ function PlatformServerTable({ rows, totals, rangeLabel }) { h( "div", { className: "pa-controls" }, - h(Box, noAutofill({ component: "input", + h(TextInput, noAutofill({ + size: "sm", type: "search", - className: "input input-sm", placeholder: "Filter by name or ID", "aria-label": "Filter servers", value: query, onChange: (event) => setQuery(event.target.value), })), h( - Box, - { component: "select", className: "select select-sm", "aria-label": "Server status", value: filter, onChange: (event) => setFilter(event.target.value) }, + NativeSelect, + { size: "sm", "aria-label": "Server status", value: filter, onChange: (event) => setFilter(event.target.value) }, ...PLATFORM_SERVER_FILTERS.map(([value, label]) => h("option", { key: value, value }, label)), ), h("span", { className: "pa-count muted", role: "status" }, `${shown.length} of ${rows.length} servers`), @@ -5906,9 +5913,10 @@ function tabRules() { rules.length > 0 && h( "div", { className: "sf-wb-toolbar" }, - h(Input, { + h(FieldInput, { type: "search", - className: "input input-sm sf-wb-search", + size: "sm", + className: "sf-wb-search", placeholder: "Filter rules by name or description…", "aria-label": "Filter automod rules", "data-search": true, @@ -6283,30 +6291,20 @@ function RuleEditorHeader({ title, enabled, dryRun, dryRunDisabled, enabledDisab h( "div", { className: "rule-toggles" }, - h( - "label", - { className: "toggle-label" }, - h(Input, { - type: "checkbox", - className: "toggle toggle-sm", - ...(requireChannels ? { checked: enabled, disabled: !hasChannels } : { defaultChecked: enabled, disabled: disabled || enabledDisabled }), - onChange: (e) => onEnabled(e.target.checked), - }), - "Enabled", - ), - h( - "label", - { className: "toggle-label" }, - h(Input, { - ref: dryRunRef, - type: "checkbox", - className: "toggle toggle-sm", - defaultChecked: dryRun, - disabled: disabled || dryRunDisabled, - onChange: (e) => onDryRun(e.target.checked), - }), - "Dry-run (log only)", - ), + h(FieldSwitch, { + className: "toggle-label", + label: "Enabled", + ...(requireChannels ? { checked: enabled, disabled: !hasChannels } : { defaultChecked: enabled, disabled: disabled || enabledDisabled }), + onChange: (e) => onEnabled(e.target.checked), + }), + h(FieldSwitch, { + ref: dryRunRef, + className: "toggle-label", + label: "Dry-run (log only)", + defaultChecked: dryRun, + disabled: disabled || dryRunDisabled, + onChange: (e) => onDryRun(e.target.checked), + }), ), ); } @@ -6324,9 +6322,9 @@ function TriggerSentence({ fields, values, onValue }) { Field, { className: "trigger-field" }, h(Label, { className: "sr-only" }, f.label), - h(Input, { + h(FieldInput, { type: "number", - className: "input input-num", + className: "input-num", min: f.min ?? (f.key === "window_secs" ? 1 : 0), max: f.max ?? (f.key === "window_secs" ? 600 : Number.MAX_SAFE_INTEGER), step: 1, @@ -6525,10 +6523,10 @@ function IdPicker({ kind, label, hint, ids, names, rememberUser, onChange, pendi return () => pending.delete(flush); }, [pending]); const textBox = (labelled) => - h(Input, { + h(FieldInput, { type: "text", value: text, - className: "input input-sm", + size: "sm", "aria-label": labelled ? undefined : idLabel || `Add a ${noun} by ID`, placeholder: kind === "user" && names.status !== "unavailable" @@ -6582,9 +6580,9 @@ function IdPicker({ kind, label, hint, ids, names, rememberUser, onChange, pendi h(Label, { className: "fieldset-legend" }, label), useSelect ? h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: "", disabled: channelKinds !== null && options.length === 0, onChange: (e) => { @@ -6659,20 +6657,15 @@ function RuleExceptions({ rule, names, rememberUser, onChange, pending }) { return h( EditorSection, { title: "Exceptions", hint: ruleNamesHint(names) || "The rule never acts on these." }, - h( - "label", - { className: "toggle-label" }, - h(Input, { - type: "checkbox", - className: "toggle toggle-sm", - defaultChecked: rule.skip_moderators, - onChange: (e) => { - rule.skip_moderators = e.target.checked; - onChange(); - }, - }), - "Skip moderators", - ), + h(FieldSwitch, { + className: "toggle-label", + label: "Skip moderators", + defaultChecked: rule.skip_moderators, + onChange: (e) => { + rule.skip_moderators = e.target.checked; + onChange(); + }, + }), h( "div", { className: "editor-columns" }, @@ -6780,13 +6773,13 @@ function CustomRuleEditor({ record: r, creating }) { h( "div", { className: "editor-columns" }, - field("Name", h(Input, { type: "text", defaultValue: rule.name, className: "input input-sm", onInput: (e) => (rule.name = e.target.value) })), + field("Name", h(FieldInput, { type: "text", defaultValue: rule.name, size: "sm", onInput: (e) => (rule.name = e.target.value) })), !preset ? field( "Type", h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: kind, onChange: (e) => { const next = e.target.value; @@ -6821,9 +6814,10 @@ function CustomRuleEditor({ record: r, creating }) { kind === "pattern" ? field( "Pattern", - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm mono", + size: "sm", + className: "mono", defaultValue: rule.params.pattern || "", onInput: (e) => { rule.params.pattern = e.target.value; @@ -6836,9 +6830,9 @@ function CustomRuleEditor({ record: r, creating }) { kind === "word" ? field( "Words", - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", defaultValue: (rule.params.words || []).join(","), onInput: (e) => { rule.params.words = e.target.value.split(",").map((w) => w.trim()).filter(Boolean); @@ -6859,24 +6853,20 @@ function CustomRuleEditor({ record: r, creating }) { ["attachments", "Attachments and images"], ["gifs", "GIF picker links"], ["stickers", "Stickers"], - ].map(([key, label]) => h( - "label", - { key, className: "checkbox-label" }, - h(Input, { - type: "checkbox", - className: "checkbox", - checked: rule.params[key] === true, - onChange: (e) => { rule.params[key] = e.target.checked; refresh(); }, - }), + ].map(([key, label]) => h(FieldCheckbox, { + key, + className: "checkbox-label", label, - )), + checked: rule.params[key] === true, + onChange: (e) => { rule.params[key] = e.target.checked; refresh(); }, + })), ), h("p", { className: "field-help" }, "Links includes GIF picker links. To block just GIF picker links, turn Links off."), field( "Allowed domains", - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", defaultValue: (rule.params.allowed_domains || []).join(", "), onInput: (e) => { rule.params.allowed_domains = e.target.value.split(",").map((domain) => domain.trim()).filter(Boolean); @@ -6943,9 +6933,9 @@ function CustomRuleEditor({ record: r, creating }) { null, field( "Reply text", - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", maxLength: 2000, defaultValue: reply.template, onInput: (e) => setReply("template", e.target.value), @@ -6954,9 +6944,9 @@ function CustomRuleEditor({ record: r, creating }) { ), field( "Delete reply after (seconds)", - h(Input, { + h(FieldInput, { type: "number", - className: "input input-sm", + size: "sm", min: 0, max: 300, defaultValue: reply.delete_after_seconds ?? 10, @@ -6999,8 +6989,8 @@ function CustomRuleEditor({ record: r, creating }) { h( "div", { className: "row checkbox-group" }, - !actions.some((action) => action.action === "log") ? h("label", { className: "checkbox-label" }, h(Input, { type: "checkbox", className: "checkbox", defaultChecked: rule.log_automod, onChange: (e) => (rule.log_automod = e.target.checked) }), "Post to automod log") : null, - h("label", { className: "checkbox-label" }, h(Input, { type: "checkbox", className: "checkbox", defaultChecked: rule.open_case, onChange: (e) => (rule.open_case = e.target.checked) }), "Open a case"), + !actions.some((action) => action.action === "log") ? h(FieldCheckbox, { className: "checkbox-label", label: "Post to automod log", defaultChecked: rule.log_automod, onChange: (e) => (rule.log_automod = e.target.checked) }) : null, + h(FieldCheckbox, { className: "checkbox-label", label: "Open a case", defaultChecked: rule.open_case, onChange: (e) => (rule.open_case = e.target.checked) }), ), kind === "honeypot_role" ? h("p", { className: "field-help" }, "For a hidden case, turn on Open a case and turn off Post to automod log.") : null, ), @@ -7126,8 +7116,8 @@ function OnboardingTrapEditor({ record }) { rule.enabled && hasRole ? h(OnboardingTrapWarnings, { names, roleId: roleIds[0] }) : null, h(Field, {}, h(Label, {}, "Join window (minutes)"), - h(Input, { - type: "number", className: "input", min: 0, max: 1440, step: 1, required: true, + h(FieldInput, { + type: "number", min: 0, max: 1440, step: 1, required: true, disabled: liveRemoval, value: windowMinutes, onChange: (event) => setWindowMinutes(event.target.value), }), @@ -7148,15 +7138,15 @@ function OnboardingTrapEditor({ record }) { }) : h("p", { className: "field-help" }, "You need Manage Server to change or activate role removal."), h(Field, {}, h(Label, {}, "Kick reason"), - h(Input, { className: "input", value: rule.actions[0].reason, onChange: (event) => { + h(FieldInput, { value: rule.actions[0].reason, onChange: (event) => { rule.actions[0].reason = event.target.value; refresh(); } }), ), h(Field, {}, h(Label, {}, "Recent-message cleanup (minutes)"), - h(Input, { - type: "number", className: "input", min: 0, max: 60, step: 1, required: true, + h(FieldInput, { + type: "number", min: 0, max: 60, step: 1, required: true, value: cleanupMinutes, onChange: (event) => setCleanupMinutes(event.target.value), }), ), @@ -7311,11 +7301,11 @@ function RuleEditor({ record: r }) { r.rule_id === "invite" ? field( "Allowed invite codes (comma-separated)", - h(Input, { + h(FieldInput, { type: "text", defaultValue: values.allowlist_codes, placeholder: "code-one, code-two", - className: "input input-sm", + size: "sm", onInput: (e) => setValue("allowlist_codes", e.target.value), }), h("p", { className: "field-help" }, "Invites with these codes are allowed."), @@ -7596,9 +7586,8 @@ function ListTable({ title, rows, headings, renderRow, searchText, searchLabel, ? h( "div", { className: "list-toolbar", "data-no-draft": true }, - h(Input, { + h(FieldInput, { type: "search", - className: "input", "data-search": true, "aria-label": searchLabel, placeholder: searchLabel, @@ -7607,10 +7596,9 @@ function ListTable({ title, rows, headings, renderRow, searchText, searchLabel, }), ...filters.map((filter) => h( - Select, + FieldSelect, { key: filter.key, - className: "select", "aria-label": filter.label, value: picked[filter.key] || "", onChange: (event) => setPicked({ ...picked, [filter.key]: event.target.value }), @@ -7712,8 +7700,8 @@ function tabBadwords() { field( "Entry type", h( - Select, - { draftKey: "badwords:mode", defaultValue: "words", className: "select" }, + FieldSelect, + { draftKey: "badwords:mode", defaultValue: "words" }, h("option", { value: "words" }, "Words or phrases"), h("option", { value: "regex" }, "Advanced regex"), ), @@ -7723,14 +7711,13 @@ function tabBadwords() { h( "div", { className: "list-entry" }, - h(Textarea, { + h(FieldTextarea, { ref: patternRef, draftKey: "badwords:pattern", rows: 3, maxLength: mode === "regex" ? 512 : 4096, "aria-label": mode === "regex" ? "Advanced regex pattern" : "Words or phrases", placeholder: mode === "regex" ? "Advanced regex, e.g. (scam|pump and dump)" : "Words or phrases, separated by commas or newlines", - className: "textarea", }), h( "p", @@ -7746,7 +7733,7 @@ function tabBadwords() { null, field( "Note (optional)", - h(Input, { ref: noteRef, draftKey: "badwords:note", type: "text", "data-note": true, className: "input" }), + h(FieldInput, { ref: noteRef, draftKey: "badwords:note", type: "text", "data-note": true }), ), h( ActionButton, @@ -7848,13 +7835,12 @@ function tabBadwords() { h( ListFormSubmit, null, - h(Input, { + h(FieldInput, { ref: sampleRef, draftKey: "badwords:sample", type: "text", "aria-label": "Sample text", placeholder: "sample text to test, e.g. 5c@m 🅿🆁🅾🅼🅾", - className: "input", }), h( ActionButton, @@ -7927,10 +7913,7 @@ function CommandEnabledCell({ record, canManage }) { : scope === "global" && !isBotOwner() ? "Only the bot owner can change a global command." : undefined; return h(Table.Td, {}, - h(Input, { - type: "checkbox", - role: "switch", - className: "toggle toggle-sm", + h(FieldSwitch, { "aria-label": `Enable /${record.name}`, "data-no-draft": true, title: restriction, @@ -8130,9 +8113,10 @@ function tabCommands() { visibleCommands.length > 0 && h( "div", { className: "sf-wb-toolbar" }, - h(Input, { + h(FieldInput, { type: "search", - className: "input input-sm sf-wb-search", + size: "sm", + className: "sf-wb-search", placeholder: "Filter commands by name, alias, or description…", "aria-label": "Filter commands", "data-search": true, @@ -8141,9 +8125,9 @@ function tabCommands() { onChange: (event) => setQuery(event.target.value), }), categories.length > 1 && h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", "aria-label": "Filter commands by category", "data-no-draft": true, value: activeCategory, @@ -8449,8 +8433,8 @@ function DeleteDaysSelect({ label, value, onChange }) { { className: "trigger-field" }, h(Label, { className: "sr-only" }, label), h( - Select, - { className: "select select-sm", defaultValue: String(value || 0), onChange: (e) => onChange(Number(e.target.value)) }, + FieldSelect, + { size: "sm", defaultValue: String(value || 0), onChange: (e) => onChange(Number(e.target.value)) }, // A saved count outside Discord's 0-7 (from the old JSON box) stays visible as it is. [...new Set([0, 1, 2, 3, 4, 5, 6, 7, Number(value) || 0])].map((days) => h("option", { key: days, value: String(days) }, deleteDaysLabel(days))), ), @@ -8462,9 +8446,9 @@ function NumberField({ label, value, unit, min, max, onChange, hidden }) { Field, { className: "trigger-field" }, h(Label, { className: hidden ? "sr-only" : "escalation-label" }, label), - h(Input, { + h(FieldInput, { type: "number", - className: "input input-num", + className: "input-num", min, max, step: 1, @@ -8499,13 +8483,13 @@ function CommandBehaviorField({ spec, params, onChange }) { const text = (value) => (value === "" ? "Not set" : spec.options.includes(value) ? value : `${value} (${spec.unlisted})`); return field( spec.label, - h(Select, { className: "select select-sm", defaultValue: current, onChange: (e) => set(e.target.value) }, options.map((value) => h("option", { key: value, value }, text(value)))), + h(FieldSelect, { size: "sm", defaultValue: current, onChange: (e) => set(e.target.value) }, options.map((value) => h("option", { key: value, value }, text(value)))), help, ); } return field( spec.label, - h(Input, { type: "text", className: "input input-sm", defaultValue: params[spec.key] ?? "", onInput: (e) => set(e.target.value) }), + h(FieldInput, { type: "text", size: "sm", defaultValue: params[spec.key] ?? "", onInput: (e) => set(e.target.value) }), help, ); } @@ -8568,9 +8552,9 @@ function CommandEditor({ record: c }) { const spec = COMMAND_BEHAVIORS[kind]; const steps = isPlan ? data.behavior.params.steps : []; const text = (key, props = {}) => - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", defaultValue: data[key] ?? "", onInput: (e) => { data[key] = e.target.value; @@ -8637,20 +8621,15 @@ function CommandEditor({ record: c }) { h( "div", { className: "rule-toggles" }, - h( - "label", - { className: "toggle-label" }, - h(Input, { - type: "checkbox", - className: "toggle toggle-sm", - defaultChecked: data.enabled, - onChange: (e) => { - data.enabled = e.target.checked; - refresh(); - }, - }), - "Enabled", - ), + h(FieldSwitch, { + className: "toggle-label", + label: "Enabled", + defaultChecked: data.enabled, + onChange: (e) => { + data.enabled = e.target.checked; + refresh(); + }, + }), ), ), h(RuleSummary, { text: commandSummaryText(globalTarget ? { ...data, grant_roles: [] } : data, names) }), @@ -8668,9 +8647,9 @@ function CommandEditor({ record: c }) { ), field( "Aliases", - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", defaultValue: aliasText.value, placeholder: "e.g. b, yeet", onInput: (e) => (aliasText.value = e.target.value), @@ -8687,8 +8666,8 @@ function CommandEditor({ record: c }) { doesSection, field( "Chat reply", - h(Textarea, { - className: "textarea textarea-sm", + h(FieldTextarea, { + size: "sm", rows: 2, defaultValue: data.response || "", placeholder: isPlan ? "Optional reply after the steps" : "Leave empty for generated text or “done”.", @@ -8719,9 +8698,9 @@ function CommandEditor({ record: c }) { field( "Permission", h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: data.permission, onChange: (e) => { data.permission = e.target.value; @@ -8767,9 +8746,9 @@ function CommandEditor({ record: c }) { field( "Log event", h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: data.log_event || "", onChange: (e) => { data.log_event = e.target.value; @@ -9280,10 +9259,10 @@ function TemplatePreview({ record: t }) { function TemplateCard({ record: t }) { const textRef = useRef(null); - const text = h(Textarea, { + const text = h(FieldTextarea, { ref: textRef, draftKey: `template:${t.event}:text`, - className: "mono template-input textarea", + className: "mono template-input", rows: 8, spellCheck: false, defaultValue: t.effective, @@ -9463,30 +9442,27 @@ function LogChannelCard({ lc }) { const guildId = state.guildId; const enrollmentId = state.config.enrollment_id; const inputRef = useRef(null); - const input = h(Input, { + const input = h(FieldInput, { ref: inputRef, draftKey: `log:${lc.event}:channel`, type: "text", defaultValue: lc.effective && String(lc.effective) !== "0" ? String(lc.effective) : "", placeholder: "Channel ID, #mention or link", - className: "input", }); const ignoredUsersRef = useRef(null); - const ignoredUsers = h(Textarea, { + const ignoredUsers = h(FieldTextarea, { ref: ignoredUsersRef, draftKey: `log:${lc.event}:users`, placeholder: "One Discord user or bot ID per line", rows: 2, - className: "textarea", defaultValue: (lc.ignore?.users || []).join("\n"), }); const ignoredChannelsRef = useRef(null); - const ignoredChannels = h(Textarea, { + const ignoredChannels = h(FieldTextarea, { ref: ignoredChannelsRef, draftKey: `log:${lc.event}:channels`, placeholder: "One source channel ID per line", rows: 2, - className: "textarea", defaultValue: (lc.ignore?.channels || []).join("\n"), }); const scopeSelRef = useRef(null); @@ -11287,12 +11263,11 @@ function CaseView({ guildId, caseId, onRemoved, onFilter }) { ? h( "div", { className: "case-note-form" }, - h(Textarea, { + h(FieldTextarea, { ref: noteRef, rows: "2", "aria-label": "Note", placeholder: "Add a note for other moderators. Discord isn't changed.", - className: "textarea", }), h(ActionButton, { variant: "filled", size: "sm", type: "button", onClick: addNote }, "Add note"), ) @@ -11660,30 +11635,27 @@ function tabSettings() { const cfg = state.config; const ov = cfg.settings_override || {}; const prefixRef = useRef(null); - const prefix = h(Input, { + const prefix = h(FieldInput, { ref: prefixRef, draftKey: "settings:prefix", type: "text", defaultValue: cfg.settings.prefix, - className: "input", }); const botNameRef = useRef(null); - const botName = h(Input, { + const botName = h(FieldInput, { ref: botNameRef, draftKey: "settings:bot_name", type: "text", defaultValue: cfg.settings.bot_name, - className: "input", }); const srcSelRef = useRef(null); const srcSel = h( - Select, + FieldSelect, { ref: srcSelRef, draftKey: "copy:source", defaultValue: "", - className: "select", onChange: (event) => handleEvent( async () => { @@ -11705,19 +11677,18 @@ function tabSettings() { ); const sectionSelRef = useRef(null); const sectionSel = h( - Select, - { ref: sectionSelRef, className: "select", draftKey: "copy:section", defaultValue: "all" }, + FieldSelect, + { ref: sectionSelRef, draftKey: "copy:section", defaultValue: "all" }, ["all", "rules", "badwords", "commands", "templates", "settings"].map((s) => h("option", { key: s, value: s }, s === "all" ? "everything" : s), ), ); const globalPrefixRef = useRef(null); - const globalPrefix = h(Input, { + const globalPrefix = h(FieldInput, { ref: globalPrefixRef, draftKey: "global:prefix", type: "text", defaultValue: cfg.global_settings.prefix, - className: "input", }); /** Clear one override field via API null (inherit parent). */ @@ -11865,13 +11836,12 @@ function tabSettings() { const [roleBaseline, setRoleBaseline] = useState(null); const [accessRoleSettings, setAccessRoleSettings] = useState(null); const roleInputRef = useRef(null); - const roleInput = h(Input, { + const roleInput = h(FieldInput, { ref: roleInputRef, draftKey: "settings:roles", defaultValue: roleBaseline ?? "", type: "text", placeholder: "role id, <@&id> mention, comma-separated", - className: "input", }); const roleRevisions = useRef({ access: "", caseRemoval: "" }); const caseRoleWriteGeneration = useRef(0); @@ -12159,9 +12129,8 @@ function AccessRolesCard({ settings, revisions }) { { key: row.key, className: "row form-row access-role-row" }, field( "Role ID", - h(Input, { + h(FieldInput, { type: "text", - className: "input", value: row.role_id, placeholder: "Discord role (ID or <@&id> mention)", onChange: (event) => update(row.key, { role_id: event.target.value }), @@ -12170,9 +12139,8 @@ function AccessRolesCard({ settings, revisions }) { field( "Access", h( - Select, + FieldSelect, { - className: "select", value: row.level, onChange: (event) => update(row.key, { level: event.target.value }), }, @@ -12246,8 +12214,8 @@ function scopeSelect( onChange, ) { return h( - Select, - { ref, className: "select", draftKey, defaultValue: "guild", onChange }, + FieldSelect, + { ref, draftKey, defaultValue: "guild", onChange }, h("option", { value: "guild" }, guildLabel), allowGlobal && isBotOwner() && h("option", { value: "global" }, globalLabel), ); @@ -12264,9 +12232,9 @@ function BanOptions({ action, onChange }) { { className: "ban-behavior" }, h(Label, { className: "sr-only" }, "Ban behavior"), h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: selected, onChange: (event) => { const mode = event.target.value; @@ -12303,8 +12271,8 @@ function RuleAction({ action, index, remove, onChange, strike = true, clearBan = Field, { className: "trigger-field" }, h(Label, { className: "escalation-label" }, "Strike", h("span", { className: "sr-only" }, " count")), - h(Input, { - className: "input input-num", + h(FieldInput, { + className: "input-num", type: "number", min: 1, defaultValue: action.at, @@ -12320,9 +12288,9 @@ function RuleAction({ action, index, remove, onChange, strike = true, clearBan = { className: "trigger-field" }, h(Label, { className: "sr-only" }, "Action"), h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: kind, onChange: (event) => { const next = event.target.value; @@ -12345,8 +12313,8 @@ function RuleAction({ action, index, remove, onChange, strike = true, clearBan = Field, { className: "trigger-field" }, h(Label, { className: "sr-only" }, "Timeout (minutes)"), - h(Input, { - className: "input input-num", + h(FieldInput, { + className: "input-num", type: "number", min: clearBan ? 1 : 0, defaultValue: action.duration_minutes ?? 0, @@ -12367,8 +12335,8 @@ function RuleAction({ action, index, remove, onChange, strike = true, clearBan = Field, { className: "escalation-reason" }, h(Label, { className: "escalation-label" }, "Reason", h("span", { className: "sr-only" }, " template")), - h(Input, { - className: "input input-sm", + h(FieldInput, { + size: "sm", type: "text", defaultValue: action.reason || "", placeholder: "Shown in logs (optional)", @@ -12411,7 +12379,7 @@ function CommandStep({ step, index, names, pending, onChange, remove }) { Field, { className: "trigger-field" }, sr("log event"), - h(Select, { className: "select select-sm", defaultValue: step.event || "", onChange: (e) => set("event")(e.target.value) }, logEventOptions(step.event || "", false)), + h(FieldSelect, { size: "sm", defaultValue: step.event || "", onChange: (e) => set("event")(e.target.value) }, logEventOptions(step.event || "", false)), ); else if (type === "timeout") inline = h(NumberField, { label: `Step ${n} minutes`, hidden: true, value: step.minutes, unit: "min", min: 1, max: STEP_TIMEOUT_MAX, onChange: set("minutes") }); @@ -12427,9 +12395,10 @@ function CommandStep({ step, index, names, pending, onChange, remove }) { { className: "trigger-field" }, sr("emoji"), h( - Select, + FieldSelect, { - className: "select select-sm emoji-select", + size: "sm", + className: "emoji-select", defaultValue: customEmoji ? "" : step.emoji, onChange: (e) => { const custom = e.target.value === ""; @@ -12446,7 +12415,7 @@ function CommandStep({ step, index, names, pending, onChange, remove }) { Field, { className: "trigger-field" }, sr("other emoji"), - h(Input, { type: "text", className: "input input-sm input-num", defaultValue: step.emoji || "", placeholder: "Emoji", onInput: (e) => set("emoji")(e.target.value.trim()) }), + h(FieldInput, { type: "text", size: "sm", className: "input-num", defaultValue: step.emoji || "", placeholder: "Emoji", onInput: (e) => set("emoji")(e.target.value.trim()) }), ) : null, ); @@ -12456,9 +12425,9 @@ function CommandStep({ step, index, names, pending, onChange, remove }) { Field, { className: "escalation-reason" }, h(Label, { className: "escalation-label" }, "Message", h("span", { className: "sr-only" }, ` for step ${n}`)), - h(Input, { + h(FieldInput, { type: "text", - className: "input input-sm", + size: "sm", defaultValue: step.template || "", placeholder: type === "dm" ? "e.g. You were warned: {reason}" : type === "log" ? "e.g. {actor} ran {command}" : "e.g. Hi {user}!", onInput: (e) => set("template")(e.target.value), @@ -12489,9 +12458,9 @@ function CommandStep({ step, index, names, pending, onChange, remove }) { { className: "trigger-field" }, h(Label, { className: "escalation-label" }, `${n}.`, h("span", { className: "sr-only" }, ` Step ${n} action`)), h( - Select, + FieldSelect, { - className: "select select-sm", + size: "sm", defaultValue: type, onChange: (event) => { const next = planStepFor(event.target.value, step); @@ -13250,7 +13219,7 @@ function tabKnownSpam() { h("div", { className: "card-body" }, h("h3", { className: "card-title" }, "Add spam"), h("div", { className: "list-form-row" }, - field("Entry type", h(Select, { className: "select", "data-no-draft": true, value: kind, onChange: (event) => setKind(event.target.value) }, + field("Entry type", h(FieldSelect, { "data-no-draft": true, value: kind, onChange: (event) => setKind(event.target.value) }, h("option", { value: "sample" }, "Full message sample"), h("option", { value: "url" }, "URL pattern"), )), @@ -13258,11 +13227,11 @@ function tabKnownSpam() { ), sample ? h("div", { className: "list-entry" }, - h(Textarea, { className: "textarea", draftKey: "known-spam:sample", rows: 5, maxLength: 4096, "aria-label": "Full sample message", placeholder: "Paste the entire confirmed spam message. No regex needed." }), + h(FieldTextarea, { draftKey: "known-spam:sample", rows: 5, maxLength: 4096, "aria-label": "Full sample message", placeholder: "Paste the entire confirmed spam message. No regex needed." }), h("p", { className: "field-help" }, "Matches the same whole message, even with case, accent, spacing or leetspeak changes. A reworded copy may not match."), h("p", { className: "field-help entry-count" }, "Up to 4096 bytes.")) : h("div", { className: "list-entry" }, - h(Input, { className: "input", draftKey: "known-spam:url", "data-url": true, maxLength: 512, "aria-label": "URL wildcard", placeholder: "tinyurl.com/*" }), + h(FieldInput, { draftKey: "known-spam:url", "data-url": true, maxLength: 512, "aria-label": "URL wildcard", placeholder: "tinyurl.com/*" }), h("p", { className: "field-help" }, "Use * as a wildcard, for example tinyurl.com/* or *.example.com/*."), h("p", { className: "field-help entry-count" }, "Up to 512 bytes."), h(GoodToKnow, { @@ -13278,7 +13247,7 @@ function tabKnownSpam() { ], })), h(ListFormSubmit, null, - field("Note (optional, up to 512 bytes)", h(Input, { className: "input", draftKey: "known-spam:note", "data-note": true, maxLength: 512 })), + field("Note (optional, up to 512 bytes)", h(FieldInput, { draftKey: "known-spam:note", "data-note": true, maxLength: 512 })), sample ? h(ActionButton, { variant: "filled", savedFields: ["known-spam:sample", "known-spam:note", "known-spam:scope"], onClick: () => add("sample") }, "Add sample") : h(ActionButton, { variant: "filled", savedFields: ["known-spam:url", "known-spam:note", "known-spam:scope"], onClick: () => add("url") }, "Add URL pattern"), @@ -13373,14 +13342,14 @@ function tabKnownBadImages() { { className: "card-body" }, h("h3", { className: "card-title" }, "Add an image"), h("div", { className: "list-entry" }, - field("SHA-256 digest", h(Input, { - className: "input mono", draftKey: "known-bad:hash", "data-hash": true, maxLength: 64, + field("SHA-256 digest", h(FieldInput, { + className: "mono", draftKey: "known-bad:hash", "data-hash": true, maxLength: 64, })), h("p", { className: "field-help" }, "Copy it from an exact-image notice in your log channel."), ), h(ListFormSubmit, null, - field("Note (optional)", h(Input, { - className: "input", draftKey: "known-bad:note", "data-note": true, maxLength: 256, + field("Note (optional)", h(FieldInput, { + draftKey: "known-bad:note", "data-note": true, maxLength: 256, })), h(AddKnownBadImage, { guildId }), ), @@ -13532,8 +13501,8 @@ function BanReasonCell({ record, names, guildId, editor: reasonEditor, onEdit, o return h( "div", { className: "ban-reason-editor" }, - h(Box, noAutofill({ component: "textarea", - className: "textarea textarea-sm", + h(Textarea, noAutofill({ + size: "sm", "aria-label": "jModGuard reason", maxLength: 512, rows: 2, @@ -13732,9 +13701,8 @@ function BanDialog({ guildId, onDone }) { }), field( "Reason", - h(Input, { + h(FieldInput, { type: "text", - className: "input", maxLength: 512, value: reason, placeholder: "Shown in Discord's audit log", @@ -13747,8 +13715,8 @@ function BanDialog({ guildId, onDone }) { field( "Delete their messages from", h( - Select, - { className: "select", value: days, onChange: (event) => setDays(event.target.value) }, + FieldSelect, + { value: days, onChange: (event) => setDays(event.target.value) }, h("option", { value: "0" }, "Don't delete any"), h("option", { value: "1" }, "The last day"), h("option", { value: "3" }, "The last 3 days"), @@ -13757,10 +13725,10 @@ function BanDialog({ guildId, onDone }) { ), field( "Unban after (minutes, optional)", - h(Input, { + h(FieldInput, { type: "text", inputMode: "numeric", - className: `input${durationValid ? "" : " input-error"}`, + error: !durationValid, value: duration, placeholder: "Leave empty for a permanent ban", onChange: (event) => { @@ -14048,7 +14016,7 @@ function DeletionRequestControls({ request, call, onPreview, preview, where }) { { className: "deletion-controls" }, field( "How did they prove they control this account?", - h(Select, { className: "select", value: method, onChange: (event) => setMethod(event.target.value) }, + h(FieldSelect, { value: method, onChange: (event) => setMethod(event.target.value) }, DELETION_METHODS.map(([value, label]) => h("option", { key: value, value }, label))), ), h(ActionButton, { @@ -14178,8 +14146,8 @@ function TabDeletions() { { className: "card-body" }, h("h3", { className: "card-title" }, "Record a request"), h("div", { className: "row form-row", "data-no-draft": true }, - field("Requester's Discord user ID", h(Input, { - type: "text", className: "input", inputMode: "numeric", value: subject, + field("Requester's Discord user ID", h(FieldInput, { + type: "text", inputMode: "numeric", value: subject, placeholder: "123456789012345678", onChange: (event) => setSubject(event.target.value), })), h(ActionButton, { variant: "filled", disabled: !enrollment, onClick: record }, "Record request"), @@ -14317,8 +14285,8 @@ function TabOwnerDeletions() { { className: "card-body" }, h("h3", { className: "card-title" }, "Record a request for every server"), h("div", { className: "row form-row", "data-no-draft": true }, - field("Requester's Discord user ID", h(Input, { - type: "text", className: "input", inputMode: "numeric", value: subject, + field("Requester's Discord user ID", h(FieldInput, { + type: "text", inputMode: "numeric", value: subject, placeholder: "123456789012345678", onChange: (event) => setSubject(event.target.value), })), h(ActionButton, { variant: "filled", onClick: record }, "Record request"), diff --git a/frontend/appearance.js b/frontend/appearance.js index 82bfc1be..53cf6fd8 100644 --- a/frontend/appearance.js +++ b/frontend/appearance.js @@ -1,5 +1,5 @@ import React, { useEffect, useState } from "react"; -import { Box, MantineProvider, Notifications } from "../tools/webui/mantine.js"; +import { MantineProvider, NativeSelect, Notifications } from "../tools/webui/mantine.js"; const colorSchemeManager = { get: fallback => fallback, @@ -100,6 +100,7 @@ const webuiTheme = { components: { Paper: { defaultProps: { radius: "md" } }, Input: { + defaultProps: { size: "md" }, styles: (_theme, { variant, error, success }) => variant === "unstyled" ? {} : { wrapper: { "--input-bg": variant === "filled" ? "var(--panel2)" : "var(--input)", @@ -107,6 +108,30 @@ const webuiTheme = { }, }, }, + TextInput: { defaultProps: { size: "md" } }, + Textarea: { defaultProps: { size: "md" } }, + NativeSelect: { defaultProps: { size: "md" } }, + Checkbox: { + defaultProps: { size: "md" }, + vars: () => ({ + root: { + "--checkbox-size": "var(--target-min)", + "--checkbox-color": "var(--accent)", + "--checkbox-icon-color": "var(--accent-text)", + }, + }), + }, + Switch: { + defaultProps: { size: "md", withThumbIndicator: false }, + vars: () => ({ + root: { + "--switch-height": "var(--target-min)", + "--switch-width": "2.5rem", + "--switch-thumb-size": ".875rem", + "--switch-color": "var(--accent)", + }, + }), + }, Button: { defaultProps: { variant: "default", size: "md" }, vars: (_theme, { variant = "default", color }) => { @@ -298,8 +323,8 @@ export function useAppearance() { export function Appearance({ preference, setPreference }) { return React.createElement("label", { className: "theme-picker" }, "Appearance ", - React.createElement(Box, { component: "select", - className: "select select-sm", "aria-label": "Appearance", value: preference, + React.createElement(NativeSelect, { + size: "sm", "aria-label": "Appearance", value: preference, onChange: event => { const value = event.target.value; setPreference(value); diff --git a/frontend/controls.css b/frontend/controls.css index 89458b54..3a229153 100644 --- a/frontend/controls.css +++ b/frontend/controls.css @@ -20,7 +20,7 @@ html { font-size: 106.25%; } a:where(:not(.mantine-Button-root, .mantine-ActionIcon-root)) { color: inherit; text-decoration: none; } .link { text-decoration: underline; text-underline-offset: .16em; } :where(button, select) { cursor: pointer; } -:where(button, input, select, textarea):disabled { opacity: .65; } +:where(button, input:not(.mantine-Switch-input), select, textarea):disabled { opacity: .65; } .mantine-Button-root { --button-height-md: var(--control-height); @@ -57,31 +57,86 @@ a:where(:not(.mantine-Button-root, .mantine-ActionIcon-root)) { color: inherit; .mantine-Button-root .mantine-Button-section[data-position="left"] { margin-inline-end: .375rem; } .mantine-Button-root .mantine-Button-section[data-position="right"] { margin-inline-start: .375rem; } -.input, .select, .textarea { +.mantine-Input-wrapper { + --input-height-md: var(--control-height); + --input-height-sm: var(--compact-height); + --input-height-xs: var(--target-min); + --input-height: var(--control-height); + --input-radius: var(--radius-field); + --input-padding: .625rem; + --input-color: var(--text); + --input-bd-focus: var(--accent); +} +.mantine-Input-wrapper[data-size="sm"] { --input-height: var(--compact-height); --input-fz: var(--ui-font-size-sm); } +.mantine-Input-wrapper[data-size="xs"] { --input-height: var(--target-min); --input-fz: var(--ui-font-size-sm); } +.mantine-Input-wrapper:not([data-variant="unstyled"]):not([data-error]):not([data-success]) { + --input-bg: var(--input); + --input-bd: var(--input-border); +} +.mantine-Input-wrapper[data-error]:not([data-variant="unstyled"]) { --input-bd: var(--bad); } +.mantine-Input-input { max-width: 100%; - min-height: var(--control-height); - padding: .125rem .625rem; - border: 1px solid var(--input-border); - border-radius: var(--radius-field); + height: var(--input-height, var(--control-height)); + min-height: var(--input-height, var(--control-height)); + border: 1px solid var(--input-bd, var(--input-border)); + border-radius: var(--input-radius, var(--radius-field)); + background-color: var(--input-bg, var(--input)); + color: var(--input-color, var(--text)); +} +.mantine-Textarea-input { height: auto; min-height: 4rem; padding-block: .375rem; } + +.mantine-Checkbox-root { + --checkbox-size-xs: var(--target-min); + --checkbox-size-sm: var(--target-min); + --checkbox-size-md: var(--target-min); + --checkbox-size: var(--target-min); + --checkbox-color: var(--accent); + --checkbox-icon-color: var(--accent-text); + --label-offset-start: .5rem; +} +.mantine-Checkbox-body, .mantine-Switch-body { align-items: center; } +.mantine-Checkbox-input { + width: var(--checkbox-size, var(--target-min)); + height: var(--checkbox-size, var(--target-min)); background-color: var(--input); - color: var(--text); + border: 1px solid var(--input-border); + cursor: pointer; } -.input-sm, .select-sm, .textarea-sm { min-height: var(--compact-height); font-size: var(--ui-font-size-sm); } -.select:not(select) { display: inline-flex; align-items: center; gap: .375rem; } -.select:not(select)::after { - content: ""; - width: .375rem; - height: .375rem; - border-bottom: 1px solid currentColor; - border-inline-end: 1px solid currentColor; - transform: translateY(-.125rem) rotate(45deg); +.mantine-Checkbox-input:checked { background-color: var(--accent); border-color: var(--accent); } +.mantine-Checkbox-input:disabled { cursor: not-allowed; background-color: var(--panel2); border-color: var(--shell-border); } +.mantine-Checkbox-label, .mantine-Switch-label { font-size: .75rem; font-weight: 650; color: var(--text); } + +.mantine-Switch-root { + --switch-height-xs: var(--target-min); + --switch-height-sm: var(--target-min); + --switch-height-md: var(--target-min); + --switch-height: var(--target-min); + --switch-width-xs: 2.5rem; + --switch-width-sm: 2.5rem; + --switch-width-md: 2.5rem; + --switch-width: 2.5rem; + --switch-thumb-size-xs: .875rem; + --switch-thumb-size-sm: .875rem; + --switch-thumb-size-md: .875rem; + --switch-thumb-size: .875rem; + --switch-track-label-padding-xs: .1875rem; + --switch-track-label-padding-sm: .1875rem; + --switch-track-label-padding-md: .1875rem; + --switch-track-label-padding: .1875rem; + --switch-color: var(--accent); + --label-offset-start: .5rem; +} +.mantine-Switch-track { + min-height: var(--switch-height, var(--target-min)); + min-width: var(--switch-width, 2.5rem); + border: 1px solid var(--input-border); + background-color: var(--panel2); } -.textarea { min-height: 4rem; padding-block: .375rem; } -.checkbox, .toggle { width: var(--target-min); height: var(--target-min); margin: 0; accent-color: var(--accent); flex: none; cursor: pointer; } -.toggle { appearance: none; display: inline-grid; place-items: center start; height: var(--target-min); width: 2.5rem; padding: .1875rem; border: 1px solid var(--input-border); border-radius: 1rem; background: var(--panel2); } -.toggle::before { content: ""; width: .875rem; height: .875rem; border-radius: 50%; background: var(--muted); } -.toggle:checked { background: var(--accent); border-color: var(--accent); justify-items: end; } -.toggle:checked::before { background: var(--accent-text); } +.mantine-Switch-thumb { background-color: var(--muted); } +.mantine-Switch-input:checked + .mantine-Switch-track { background-color: var(--accent); border-color: var(--accent); } +.mantine-Switch-input:checked + .mantine-Switch-track > .mantine-Switch-thumb { background-color: var(--accent-text); } +.mantine-Switch-input:disabled { opacity: 0; } +.mantine-Switch-input:disabled + .mantine-Switch-track { opacity: .65; cursor: not-allowed; } :is(button, input, select, textarea):disabled { cursor: not-allowed; } .card { min-width: 0; background: var(--panel); border-radius: var(--radius-box); } diff --git a/frontend/list-controls.js b/frontend/list-controls.js index 92152567..cb5e15d7 100644 --- a/frontend/list-controls.js +++ b/frontend/list-controls.js @@ -1,4 +1,4 @@ -import { Box, Button, Table, UnstyledButton } from "../tools/webui/mantine.js"; +import { Button, NativeSelect, Table, TextInput, UnstyledButton } from "../tools/webui/mantine.js"; import React, { useEffect, useRef, useState } from "react"; import { Icon } from "./icons.js"; import { noAutofill } from "./no-autofill.js"; @@ -244,8 +244,8 @@ function ListField({ label, children }) { export function ListPageSize({ controls }) { return h(ListField, { label: "Rows per page" }, - h(Box, { component: "select", - className: "select select-sm", + h(NativeSelect, { + size: "sm", value: controls.view.pageSize, onChange: (event) => controls.setPageSize(event.target.value), }, ...PAGE_SIZES.map((size) => h("option", { key: size, value: size }, size === "all" ? "All" : size))), @@ -257,8 +257,8 @@ export function ListControls({ controls, UserPicker, userPickerProps, filterOpti const { filters } = view; const { from: fromLabel = "From", to: toLabel = "To" } = config.dateLabels ?? {}; const date = (key, label, bounds) => h(ListField, { label }, - h(Box, noAutofill({ component: "input", - className: "input input-sm", + h(TextInput, noAutofill({ + size: "sm", type: "date", value: filters[key], ...bounds, @@ -266,8 +266,8 @@ export function ListControls({ controls, UserPicker, userPickerProps, filterOpti })), ); const text = (key, label, placeholder, type = "text") => h(ListField, { key, label }, - h(Box, noAutofill({ component: "input", - className: "input input-sm", + h(TextInput, noAutofill({ + size: "sm", type, value: drafts[key] ?? filters[key], placeholder, @@ -304,8 +304,8 @@ export function ListControls({ controls, UserPicker, userPickerProps, filterOpti if (kind === "text") return text(key, label, placeholder); if (render) return h(ListField, { key, label }, render(filters[key], (value) => setFilter(key, value))); return h(ListField, { key, label }, - h(Box, { component: "select", - className: "select select-sm", + h(NativeSelect, { + size: "sm", value: filters[key], onChange: (event) => setFilter(key, event.target.value), }, diff --git a/frontend/style.css b/frontend/style.css index cfa277f9..807046f0 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -40,7 +40,8 @@ body { background: var(--bg); } /* WCAG 2.2 target size: compact controls (xs/sm/square buttons, fields, tooltip triggers) never render below 24px. */ .mantine-ActionIcon-root, .tooltip-trigger { min-width: var(--target-min); } /* One visible focus ring for every control; --accent keeps 3:1 on all shell surfaces in both themes. */ -:is(.mantine-Button-root, .mantine-ActionIcon-root, .input, .select, .textarea, .checkbox, .toggle, .menu button, .tooltip-trigger, .mantine-Notification-closeButton, a, summary, .sf-hub-pill, .sf-srv-btn, .sf-ribbon-link, .sf-tri button, .sf-log-nav-btn, .sf-wb-select-btn):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +:is(.mantine-Button-root, .mantine-ActionIcon-root, .mantine-Input-input, .mantine-Checkbox-input, .server-picker-trigger, .menu button, .tooltip-trigger, .mantine-Notification-closeButton, a, summary, .sf-hub-pill, .sf-srv-btn, .sf-ribbon-link, .sf-tri button, .sf-log-nav-btn, .sf-wb-select-btn):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.mantine-Switch-input:focus-visible + .mantine-Switch-track { outline: 2px solid var(--accent); outline-offset: 2px; } .hidden, [hidden] { display: none !important; } .w-full { width: 100%; } .bg-base-100 { background-color: var(--panel); } @@ -96,12 +97,35 @@ body { background: var(--bg); } .field { margin-bottom: .75rem; min-width: 0; } .fieldset.field { padding: 0; gap: 0; } .field > .fieldset-legend { padding: 0; margin: 0 0 .25rem; } -.field > .input, .field > .select, .field > .textarea, .field > input:not([type=checkbox]), .field > select, .field > textarea { width: 100%; } +.field > .mantine-InputWrapper-root, .field > input:not([type=checkbox]), .field > select, .field > textarea { width: 100%; } -.server-picker > .select { width: 100%; margin-top: 0; } .server-picker > label { text-transform: uppercase; } /* The header server switcher uses a select-sized trigger and a listbox with server icons. */ -.server-picker-trigger { cursor: pointer; text-align: start; } +.server-picker-trigger { + display: inline-flex; + align-items: center; + gap: .375rem; + width: 100%; + max-width: 100%; + min-height: var(--compact-height); + margin-top: 0; + padding: .125rem .625rem; + border: 1px solid var(--input-border); + border-radius: var(--radius-field); + background-color: var(--input); + color: var(--text); + font-size: var(--ui-font-size-sm); + cursor: pointer; + text-align: start; +} +.server-picker-trigger::after { + content: ""; + width: .375rem; + height: .375rem; + border-bottom: 1px solid currentColor; + border-inline-end: 1px solid currentColor; + transform: translateY(-.125rem) rotate(45deg); +} .server-picker-trigger:disabled { cursor: not-allowed; } .server-enrollment-marker { flex: 0 0 auto; } .server-picker-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } @@ -116,7 +140,7 @@ body { background: var(--bg); } .server-picker-list [role=option].menu-focus { outline: 2px solid var(--accent); outline-offset: 0; } .table-scroll { overflow-x: auto; } -.mono { font-family: var(--font-mono); } +.mono { font-family: var(--font-mono); --input-font-family: var(--font-mono); } .muted { color: var(--muted); } .ok { color: var(--good); } .err, .error { color: var(--bad); } @@ -142,7 +166,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .workspace-footer .legal-links a { display: inline-flex; align-items: center; } .theme-picker { display: flex; align-items: center; gap: .375rem; color: var(--muted); font-size: .75rem; padding: 0; } .sidebar-footer .theme-picker { width: auto; padding: 0; } -.theme-picker .select { flex: 0 1 auto; min-width: 0; } +.theme-picker .mantine-NativeSelect-root { flex: 0 1 auto; min-width: 0; } .welcome-view > .theme-picker { position: absolute; top: 1.25rem; right: 1.25rem; padding: 0; } .preview-banner { position: sticky; top: 0; z-index: 50; } .owner-tools { display: flex; align-items: center; flex-wrap: wrap; gap: .375rem; margin: 0; } @@ -207,10 +231,8 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .member-sync-details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .25rem 1rem; margin: 0; font-size: var(--ui-font-size-sm); } .member-sync-details dt { color: var(--muted); } .member-sync-details dd { margin: 0; overflow-wrap: anywhere; } -#content .input, #content .select, #content .textarea { background-color: var(--input); border-color: var(--input-border); } -.field > label > input, .field > label > select, .field > label > textarea { width: 100%; margin-top: .25rem; } +.field > label > .mantine-InputWrapper-root, .field > label > input, .field > label > select, .field > label > textarea { width: 100%; margin-top: .25rem; font-weight: 400; } .field > label > input, .field > label > textarea { display: block; } -.field > label > input, .field > label > select, .field > label > textarea { font-weight: 400; } .field-help { margin: 0 0 .625rem; font-size: var(--ui-font-size-sm); color: var(--muted); } .tag-group { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; } .rule-heading { display: flex; flex-direction: column; gap: .375rem; } @@ -251,7 +273,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .modal-action { display: flex; justify-content: flex-end; margin-top: 1rem; } .editor-heading { margin-bottom: 1rem; } .editor-heading h3 { margin: .25rem 0 .375rem; } -.rule-editor .textarea { min-height: 10rem; line-height: 1.65; } +.rule-editor .mantine-Textarea-input { min-height: 10rem; line-height: 1.65; } /* Automod rule editor (#621): header toggles, live summary, then compact sections. */ .rule-editor { padding-bottom: 0; } .rule-editor-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .625rem; } @@ -267,17 +289,17 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .editor-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; align-items: start; } .trigger-sentence, .escalation-row { display: flex; align-items: center; flex-wrap: wrap; gap: .375rem .5rem; } .trigger-field { display: inline-flex; align-items: center; gap: .375rem; } -.input.input-num { width: calc(7ch + 1.25rem); } +.input-num { width: calc(7ch + 1.25rem); } .escalation-step { display: flex; flex-direction: column; gap: .375rem; padding: .5rem .625rem; border: 1px solid var(--shell-border); border-radius: .5rem; background: var(--panel2); } .escalation-label { font-size: .75rem; font-weight: 650; } .escalation-remove { margin-left: auto; } .escalation-reason { display: flex; align-items: center; gap: .5rem; } -.escalation-reason .input { flex: 1; min-width: 0; } +.escalation-reason .mantine-TextInput-root { flex: 1; min-width: 0; } .editor-section > .mantine-Button-root { align-self: flex-start; } -.rule-scope .select { width: min(20rem, 100%); } +.rule-scope .mantine-NativeSelect-root { width: min(20rem, 100%); } .ban-options { display: inline-flex; align-items: center; gap: .25rem; } .id-picker .fieldset { padding: 0; gap: .25rem; } -.id-picker .select, .id-picker .input { width: 100%; } +.id-picker .mantine-InputWrapper-root { width: 100%; } /* List pages (#622): Badwords, Known spam and Known-bad images share one column at the rule editor's width: status, add form, list, then a collapsible tester or preview. Every control uses the shared height so inputs, selects and buttons line up. */ @@ -285,7 +307,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .list-card > .card-body, .list-card > details > .card-body { padding: .875rem 1.125rem; gap: .625rem; } .list-card .card-title { margin: 0; } .list-card .field { margin-bottom: 0; padding-block: 0; } -.list-card .input, .list-card .select, .list-card .textarea { width: 100%; } +.list-card .mantine-InputWrapper-root { width: 100%; } .list-status .rule-editor-header, .list-status .rule-summary { margin: 0; } .list-status-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; } .list-status-actions > .badge { margin-inline-end: auto; } @@ -294,11 +316,11 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .list-entry .field-help, .list-card .field-help { margin: 0; } .list-entry .good-to-know { margin: .125rem 0 0; } .list-form-submit { display: flex; align-items: flex-end; flex-wrap: wrap; gap: .5rem 1rem; } -.list-form-submit > .field, .list-form-submit > .input { flex: 1 1 16rem; } +.list-form-submit > .field, .list-form-submit > .mantine-TextInput-root { flex: 1 1 16rem; } .list-form-submit > .mantine-Button-root { margin-inline-start: auto; } .list-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; } -.list-toolbar > .input { flex: 2 1 14rem; width: auto; } -.list-toolbar > .select { flex: 1 1 10rem; width: auto; } +.list-toolbar > .mantine-TextInput-root { flex: 2 1 14rem; width: auto; } +.list-toolbar > .mantine-NativeSelect-root { flex: 1 1 10rem; width: auto; } .list-table .table-scroll { border: 1px solid var(--shell-border); } .list-entry-cell { overflow-wrap: anywhere; min-width: 12rem; } .list-entry-cell > .badge { margin-inline-start: .375rem; } @@ -324,13 +346,13 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .modal-action { flex-wrap: wrap; align-items: flex-end; gap: .5rem; padding-top: .75rem; border-top: 1px solid var(--shell-border); } /* The rule editor keeps Save, Reset and Cancel in view while its sections scroll. */ /* Command editor (#623): the #621 layout with compact step rows. */ -.command-editor .textarea { min-height: 3.5rem; } +.command-editor .mantine-Textarea-input { min-height: 3.5rem; } .command-step .id-picker { margin: 0; } .emoji-select { width: auto; } .raw-behavior { margin: 0; max-height: 14rem; overflow: auto; padding: .5rem .625rem; border: 1px solid var(--shell-border); border-radius: .5rem; background: var(--panel2); font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; } .rule-editor > .modal-action { position: sticky; bottom: 0; z-index: 1; margin-top: .25rem; padding-bottom: 1rem; background: var(--panel); } .modal-action > .field { margin: 0 auto 0 0; flex: 1 1 13.75rem; } -.modal-action > .field > select { width: 100%; } +.modal-action > .field > .mantine-NativeSelect-root, .modal-action > .field > select { width: 100%; } .commands-table { width: 100%; } .commands-table th { background: var(--panel2); padding-block: .5rem; color: var(--muted); font-size: .75rem; } @@ -356,7 +378,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .event-heading code { font-size: .75rem; } .template-workspace { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; } .template-workspace .field { margin: 0; } -.template-input { min-height: 14rem; line-height: 1.6; resize: vertical; } +.template-input .mantine-Textarea-input { min-height: 14rem; line-height: 1.6; resize: vertical; } .template-preview { min-width: 0; } .template-preview > strong { display: block; font-size: .75rem; margin-bottom: .5rem; } .template-preview .discord-markdown { background: var(--panel2); border: 1px solid var(--shell-border); border-radius: .5rem; padding: .75rem; overflow-wrap: anywhere; white-space: pre-wrap; } @@ -433,7 +455,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .administration-policy { display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; margin: 0; padding: .625rem 0 0; border: 0; border-top: 1px solid var(--shell-border); min-width: 0; } .administration-policy legend { padding-right: .5rem; font-size: .75rem; color: var(--muted); } .administration-policy .field { margin: 0; } -.administration-policy .select { max-width: 100%; } +.administration-policy .mantine-NativeSelect-root { max-width: 100%; } .administration-browser { display: flex; align-items: start; flex-wrap: wrap; gap: .75rem; min-width: 0; overflow-wrap: anywhere; } .administration-browser details { flex: 1 1 18.75rem; min-width: 0; } .administration-page #automatic-state { margin: 0; font-size: var(--ui-font-size-sm); } @@ -577,8 +599,8 @@ svg.icon-neutral { color: var(--icon-neutral); } /* Platform analytics (#618): the owner fleet view on the analytics dashboard styles above. Every selector below starts with a pa- class. */ .pa-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 6px; } -.pa-controls .input { width: min(16rem, 100%); } -.pa-controls .select { width: auto; } +.pa-controls .mantine-TextInput-root { width: min(16rem, 100%); } +.pa-controls .mantine-NativeSelect-root { width: auto; } .pa-count { font-size: .75rem; } .pa-table th, .pa-table td { padding-inline: 6px; white-space: nowrap; vertical-align: middle; } .pa-sort { display: inline-flex; align-items: center; gap: 2px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; } @@ -641,7 +663,7 @@ svg.icon-neutral { color: var(--icon-neutral); } /* ==== Shared dashboard list controls ==== */ .list-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem .75rem; } .list-filters > .field, .list-filters > .id-picker { flex: 1 1 10rem; min-width: 0; max-width: 16rem; margin: 0; } -.list-filters .select { width: 100%; } +.list-filters .mantine-NativeSelect-root { width: 100%; } .list-sort { display: inline-flex; align-items: center; gap: .35rem; color: inherit; font: inherit; cursor: pointer; } .list-sort-order { font-size: var(--ui-font-size-sm); font-weight: 400; } .list-sort-mark { width: 1rem; height: 1rem; flex: none; } @@ -706,7 +728,8 @@ svg.icon-neutral { color: var(--icon-neutral); } .case-file-meta { display: flex; align-items: center; justify-content: space-between; gap: .375rem; font-size: var(--ui-font-size-sm); } .case-actions { position: sticky; bottom: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem 1rem; padding: .75rem 0 1rem; border-top: 1px solid var(--shell-border); background: var(--panel); } .case-note-form { display: flex; flex: 1 1 20rem; align-items: flex-end; gap: .5rem; min-width: 0; } -.case-note-form .textarea { flex: 1 1 auto; min-width: 0; min-height: 2.5rem; } +.case-note-form .mantine-Textarea-root { flex: 1 1 auto; min-width: 0; } +.case-note-form .mantine-Textarea-input { min-height: 2.5rem; } .case-remove { margin-inline-start: auto; } @media (max-width: 720px) { .case-who { grid-template-columns: minmax(0, 1fr); } @@ -736,11 +759,11 @@ svg.icon-neutral { color: var(--icon-neutral); } .ban-reason-open { display: block; -webkit-line-clamp: unset; line-clamp: none; } .ban-reason-history { flex: 1 1 100%; order: 3; margin: 0; font-size: var(--ui-font-size-sm); overflow-wrap: anywhere; } .ban-reason-editor { display: flex; flex-direction: column; gap: .375rem; min-width: 14rem; } -.ban-reason-editor .textarea { width: 100%; } +.ban-reason-editor .mantine-Textarea-root { width: 100%; } .ban-reason-editor .field-help { margin: 0; } .modal-box.ban-dialog { display: flex; flex-direction: column; gap: 1rem; } .ban-form { display: flex; flex-direction: column; gap: .25rem; } -.ban-form .input, .ban-form .select { width: 100%; } +.ban-form .mantine-InputWrapper-root { width: 100%; } .ban-receipt p { margin: 0 0 .5rem; } /* ==== end Bans (#625) ==== */ diff --git a/scripts/administration-state-test.mjs b/scripts/administration-state-test.mjs index b1b4aa4f..2850a3d9 100644 --- a/scripts/administration-state-test.mjs +++ b/scripts/administration-state-test.mjs @@ -1047,3 +1047,17 @@ test("Administration page controls show colored SVG icons, never glyphs", async const back = find(view.elements.get("refresh-status").parentElement, (item) => item.localName === "a" && textOf(item) === "Back to workspace"); assert.equal(find(back, (item) => item.localName === "svg")?.getAttribute("data-icon"), "arrow-left"); }); + +test("Administration form controls render Mantine NativeSelect and TextInput without daisy classes", async () => { + const view = await ready(async (url) => response(url === "/api/me" ? { is_bot_owner: true } : state([record("bot")]))); + const content = view.elements.get("content"); + const selects = [...content.querySelectorAll("select")]; + assert.ok(selects.length >= 3, "Appearance and release policy selects render"); + for (const select of selects) { + assert.ok(select.classList.contains("mantine-NativeSelect-input"), select.getAttribute("aria-label")); + assert.equal(select.classList.contains("select"), false); + } + const alertInput = content.querySelector("input#alert-channel-id"); + assert.ok(alertInput?.classList.contains("mantine-TextInput-input")); + assert.equal(alertInput.classList.contains("input"), false); +}); diff --git a/scripts/frontend-contrast-test.mjs b/scripts/frontend-contrast-test.mjs index cee4a71c..074ed8d7 100644 --- a/scripts/frontend-contrast-test.mjs +++ b/scripts/frontend-contrast-test.mjs @@ -5,7 +5,7 @@ import vm from "node:vm"; import { JSDOM } from "../tools/webui/node_modules/jsdom/lib/api.js"; import React, { useEffect, useState } from "../tools/webui/node_modules/react/index.js"; import { renderToStaticMarkup } from "../tools/webui/node_modules/react-dom/server.node.js"; -import { ActionIcon, Box, Button, MantineProvider, Notifications } from "../tools/webui/mantine.js"; +import { ActionIcon, Box, Button, MantineProvider, NativeSelect, Notifications } from "../tools/webui/mantine.js"; const controls = readFileSync(new URL("../frontend/controls.css", import.meta.url), "utf8"); const css = readFileSync(new URL("../frontend/style.css", import.meta.url), "utf8"); @@ -19,7 +19,7 @@ const webuiStyleEntry = readFileSync(new URL("../tools/webui/style.css", import. function loadAppearance(extraGlobals = {}) { const runnable = appearanceSource.replace(/^import .*;$/gm, "").replaceAll("export function", "function"); return vm.runInNewContext(`${runnable}\n({ WebuiTheme, useAppearance, Appearance })`, { - React, useEffect, useState, Box, MantineProvider, Notifications, ...extraGlobals, + React, useEffect, useState, MantineProvider, NativeSelect, Notifications, ...extraGlobals, }); } @@ -141,7 +141,9 @@ for (const [theme, selector] of [["light", ":root"], ["dark", ':root[data-theme= assert.ok(contrast(colors["--accent"], colors["--input"]) >= 3, `${theme} checked checkbox must contrast with its field background`); assert.ok(contrast(colors["--accent-text"], colors["--accent"]) >= 3, - `${theme} check mark must contrast with its checked background`); + `${theme} check mark and checked switch thumb must contrast with their checked background`); + assert.ok(contrast(colors["--muted"], colors["--panel2"]) >= 3, + `${theme} unchecked switch thumb must contrast with its track background`); }); } @@ -228,17 +230,46 @@ test("component borders use the contrast-tested theme colors", () => { const appearance = readFileSync(new URL("../frontend/appearance.js", import.meta.url), "utf8"); assert.match(css, /--shell-border:\s*#[\da-fA-F]{6}/); assert.match(css, /border:\s*1px solid var\(--shell-border\)/); - assert.equal(declaration(rule(".input, .select, .textarea", controls), "border"), "1px solid var(--input-border)"); + assert.equal(declaration(rule(".mantine-Input-input", controls), "border"), "1px solid var(--input-bd, var(--input-border))"); assert.equal(declaration(rule(".mantine-Button-root", controls), "border"), "var(--button-bd, 1px solid var(--input-border))"); assert.match(appearance, /"--mantine-color-default-border":\s*"var\(--input-border\)"/); - assert.equal(declaration(rule(".toggle", controls), "border"), "1px solid var(--input-border)"); - assert.equal(declaration(rule(".checkbox, .toggle", controls), "accent-color"), "var(--accent)"); + assert.equal(declaration(rule(".mantine-Checkbox-input", controls), "border"), "1px solid var(--input-border)"); + assert.equal(declaration(rule(".mantine-Checkbox-root", controls), "--checkbox-color"), "var(--accent)"); + assert.equal(declaration(rule(".mantine-Checkbox-root", controls), "--checkbox-icon-color"), "var(--accent-text)"); + assert.equal(declaration(rule(".mantine-Switch-track", controls), "border"), "1px solid var(--input-border)"); + assert.equal(declaration(rule(".mantine-Switch-root", controls), "--switch-color"), "var(--accent)"); + assert.equal(declaration(rule(".mantine-Switch-input:disabled", controls), "opacity"), "0"); + assert.equal(declaration(rule(".mantine-Switch-input:disabled + .mantine-Switch-track", controls), "opacity"), ".65"); + assert.equal(declaration(rule(".server-picker-trigger"), "border"), "1px solid var(--input-border)"); const logHoverIdx = css.indexOf(".sf-log-nav-btn:hover:where(:not(:disabled))"); const logActiveIdx = css.indexOf(".sf-log-nav-btn.sf-log-nav-active"); assert.ok(logHoverIdx >= 0 && logActiveIdx > logHoverIdx, "active Log Channels nav rule must follow equal-specificity hover rule"); assert.match(css, /\.sf-log-nav-btn:hover:where\(:not\(:disabled\)\)\s*\{[^}]*border-color:\s*var\(--shell-border\)/); }); +test("daisy-era form control classes are removed from frontend sources", () => { + for (const file of [ + "app.js", "administration.js", "appearance.js", "charts.js", "list-controls.js", + "controls.css", "style.css", "index.html", "administration/index.html", + ]) { + const source = readFileSync(new URL(`../frontend/${file}`, import.meta.url), "utf8"); + assert.doesNotMatch(source, /\b(?:input|select|textarea|toggle|checkbox)-(?:xs|sm|md|lg|xl|bordered|ghost|error)\b/, file); + if (file.endsWith(".css")) { + assert.doesNotMatch(source, /(?:^|[^a-zA-Z0-9_-])\.(?:input|select|textarea|toggle|checkbox)(?=[^a-zA-Z0-9_-]|$)/, file); + } + if (file.endsWith(".js")) { + for (const [, literal] of source.matchAll(/className:\s*("[^"\n]*"|`[^`]*`)/g)) { + assert.doesNotMatch(literal, /(?:^|[\s"`])(?:input|select|textarea|toggle|checkbox)(?=$|[\s"`])/, `${file}: ${literal}`); + } + } + if (file.endsWith(".html")) { + for (const [, literal] of source.matchAll(/class="([^"]*)"/g)) { + assert.doesNotMatch(literal, /(?:^|\s)(?:input|select|textarea|toggle|checkbox)(?=$|\s)/, `${file}: ${literal}`); + } + } + } +}); + test("daisy-era .btn classes are removed from frontend sources", () => { for (const file of [ "app.js", "administration.js", "appearance.js", "charts.js", "list-controls.js", @@ -521,10 +552,13 @@ test("the page uses the scale tokens instead of the old touch-sized values", () test("compact controls keep a visible focus ring with 3:1 contrast on every surface", () => { const focus = css.match(/^:is\(([^)]*)\):focus-visible\s*\{([^}]*)\}/m); assert.ok(focus, "missing the shared :focus-visible rule"); - for (const control of [".mantine-Button-root", ".mantine-ActionIcon-root", ".input", ".select", ".textarea", ".checkbox", ".menu button", ".tooltip-trigger", ".mantine-Notification-closeButton", "a", "summary"]) + for (const control of [".mantine-Button-root", ".mantine-ActionIcon-root", ".mantine-Input-input", ".mantine-Checkbox-input", ".server-picker-trigger", ".menu button", ".tooltip-trigger", ".mantine-Notification-closeButton", "a", "summary"]) assert.ok(focus[1].split(/,\s*/).includes(control), `focus ring must cover ${control}`); assert.match(focus[2], /outline:\s*2px solid var\(--accent\)/); assert.match(focus[2], /outline-offset:\s*2px/); + const switchFocus = rule(".mantine-Switch-input:focus-visible + .mantine-Switch-track"); + assert.match(switchFocus, /outline:\s*2px solid var\(--accent\)/); + assert.match(switchFocus, /outline-offset:\s*2px/); // No first-party rule removes the outline from a focused control. for (const [, selectors, body] of css.matchAll(/([^{}]*:focus(?:-visible|-within)?[^{}]*)\{([^}]*)\}/g)) assert.doesNotMatch(body, /outline(?:-style)?:\s*(?:none|0)\b/, selectors.trim()); @@ -540,7 +574,11 @@ test("compact controls keep a visible focus ring with 3:1 contrast on every surf test("the smallest interactive controls keep 24px targets", () => { assert.equal(declaration(rule('.mantine-Button-root[data-size="xs"]', controls), "min-height"), "var(--target-min)"); assert.equal(declaration(rule('.mantine-Button-root[data-size="sm"]', controls), "min-height"), "var(--compact-height)"); - assert.equal(declaration(rule(".input, .select, .textarea", controls), "min-height"), "var(--control-height)"); + assert.equal(declaration(rule(".mantine-Input-input", controls), "min-height"), "var(--input-height, var(--control-height))"); + assert.equal(declaration(rule(".mantine-Checkbox-input", controls), "width"), "var(--checkbox-size, var(--target-min))"); + assert.equal(declaration(rule(".mantine-Checkbox-input", controls), "height"), "var(--checkbox-size, var(--target-min))"); + assert.equal(declaration(rule(".mantine-Switch-track", controls), "min-height"), "var(--switch-height, var(--target-min))"); + assert.equal(declaration(rule(".server-picker-trigger"), "min-height"), "var(--compact-height)"); assert.match(rule(".tooltip-trigger"), /min-height:\s*var\(--target-min\)/); assert.match(rule(".mantine-ActionIcon-root, .tooltip-trigger"), /min-width:\s*var\(--target-min\)/); assert.match(rule("#tabs button"), /min-height:\s*var\(--target-min\)/); @@ -549,7 +587,7 @@ test("the smallest interactive controls keep 24px targets", () => { for (const [, selectors, body] of (css + controls).matchAll(/([^{}]+)\{([^{}]*)\}/g)) { // Only rules whose subject (the last compound selector) is the control itself. const subjects = selectors.split(",").map((part) => part.trim().split(/\s+|>/).filter(Boolean).at(-1) ?? ""); - if (!subjects.some((subject) => !subject.includes("::") && /^(?:\.(?:mantine-Button-root|mantine-ActionIcon-root|input|select|checkbox|tooltip-trigger)\b|button$)/.test(subject.replace(/^[^.]*(?=\.)/, "")))) continue; + if (!subjects.some((subject) => !subject.includes("::") && /^(?:\.(?:mantine-Button-root|mantine-ActionIcon-root|mantine-Input-input|mantine-Checkbox-input|mantine-Switch-track|server-picker-trigger|tooltip-trigger)\b|button$)/.test(subject.replace(/^[^.]*(?=\.)/, "")))) continue; for (const [, property, value] of body.matchAll(/(?:^|;)\s*((?:min-)?(?:height|width)):\s*([\d.]+(?:px|rem))/g)) assert.ok(px(value) >= 24, `${selectors.trim()} ${property}: ${value}`); } diff --git a/scripts/frontend-state-test.mjs b/scripts/frontend-state-test.mjs index 66c583c3..4d092f44 100644 --- a/scripts/frontend-state-test.mjs +++ b/scripts/frontend-state-test.mjs @@ -202,9 +202,9 @@ function harness(fetchImpl = async () => {}, storage = new Map(), session = new function measureDraftRenders() { const counts = new Map(); const instrument = vm.runInContext(`(count) => { - const originalTextarea = Textarea, originalSelect = Select, originalServerPicker = ServerPicker; - Textarea = (props) => { count(props.draftKey); return originalTextarea(props); }; - Select = (props) => { count(props.draftKey); return originalSelect(props); }; + const originalTextarea = FieldTextarea, originalSelect = FieldSelect, originalServerPicker = ServerPicker; + FieldTextarea = (props) => { count(props.draftKey); return originalTextarea(props); }; + FieldSelect = (props) => { count(props.draftKey); return originalSelect(props); }; ServerPicker = (props) => { count('sidebar'); return originalServerPicker(props); }; }`, context); instrument(key => counts.set(key, (counts.get(key) || 0) + 1)); @@ -5615,12 +5615,19 @@ const densityProbe = `(async () => { const probes = document.createElement('div'); probes.style.cssText = 'position:absolute;top:0;left:0;visibility:hidden'; probes.innerHTML = '' + - '' + - ''; + '' + + '
' + + '
' + + '
' + + '
'; document.body.append(probes); await frame(); - result.controls = Object.fromEntries(['btn', 'sm', 'xs', 'square', 'input', 'select', 'checkbox'] - .map((name, index) => [name, rect(probes.children[index])])); + result.controls = Object.fromEntries(['btn', 'sm', 'xs', 'square', 'input', 'select', 'checkbox', 'switch'] + .map((name, index) => { + const node = probes.children[index]; + const target = node.querySelector('input, select, .mantine-Switch-track') ?? node; + return [name, rect(target)]; + })); probes.remove(); const trigger = document.querySelector('.tooltip-trigger'); result.trigger = rect(trigger); @@ -5671,7 +5678,7 @@ test('dashboard density fits 1280x800 and keeps 24px targets in both themes', { assert.ok(Math.abs(m.bodyFont - 16 * ROOT_UI_SCALE * 0.875) <= 0.05, `${name}: body text (${m.bodyFont}px)`); assert.ok(m.bodyFont > 14 && m.bodyFont <= 16, `${name}: body text scaled slightly above 14px (${m.bodyFont}px)`); assert.ok(m.statFont > 20 && m.statFont <= 22, `${name}: stat numeral ${m.statFont}px`); - for (const control of ['sm', 'xs', 'square', 'checkbox']) + for (const control of ['sm', 'xs', 'square', 'checkbox', 'switch']) assert.ok(m.controls[control].height >= 24 && m.controls[control].width >= 24, `${name}: ${control} ${JSON.stringify(m.controls[control])}`); assert.ok(m.trigger.height >= 24 && m.trigger.width >= 24, `${name}: tooltip trigger ${JSON.stringify(m.trigger)}`); assert.ok(m.tabs >= 24, `${name}: navigation targets ${m.tabs}px`); @@ -7691,15 +7698,16 @@ test('server switcher name truncation keeps open rows inside the list and reuses assert.match(rule('.server-picker-name'), declaration); assert.match(rule('.server-icon'), /width:\s*1\.25rem/); assert.match(rule('.server-icon'), /border-radius:\s*50%/); - assert.match(rule('.server-picker > .select'), /width:\s*100%/); + assert.match(rule('.server-picker-trigger'), /width:\s*100%/); + assert.match(rule('.server-picker-trigger'), /min-height:\s*var\(--compact-height\)/); assert.match(rule('.server-picker-list > li'), /flex-wrap:\s*nowrap/); assert.match(rule('.server-picker-list > li'), /(?:^|;)\s*min-width:\s*0/); for (const declaration of [/(?:^|;)\s*width:\s*100%/, /max-width:\s*100%/, /(?:^|;)\s*min-width:\s*0/, /display:\s*flex/]) assert.match(rule('.server-picker-list [role=option]'), declaration); assert.match(rule('.server-icon'), /flex:\s*0 0 auto/); - // The trigger is the existing compact select control, not a new size scale. + // The trigger reuses the shared compact control height token, not a new size scale. const source = fs.readFileSync(new URL('../frontend/app.js', import.meta.url), 'utf8'); - assert.match(source, /className: "select select-sm w-full server-picker-trigger"/); + assert.match(source, /className: "w-full server-picker-trigger"/); }); test('server switcher keyboard moves the active option, selects with Enter and closes with Escape', async () => { @@ -17512,3 +17520,62 @@ test('DataTable and direct Mantine Table use Mantine striping and row borders wi assert.equal(diffTable.classList.contains('table'), false); assert.equal(diffTable.querySelector('tbody tr').getAttribute('data-striped'), null, 'direct Table stays unstriped'); }); + +test('workspace form controls render Mantine TextInput, NativeSelect, Textarea, Switch, and Checkbox without daisy classes', async () => { + const { fetchImpl } = caseFixture(); + const h = harness(fetchImpl); + const casesRoot = await casesView(h); + await settle(); + const dateInput = casesRoot.querySelector('input[type="date"]'); + assert.ok(dateInput, 'list filters retain native type="date" inputs'); + assert.ok(dateInput.classList.contains('mantine-TextInput-input'), 'date filter uses Mantine TextInput'); + assert.equal(dateInput.classList.contains('input'), false); + const filterSelect = casesRoot.querySelector('.list-filters select'); + assert.ok(filterSelect.classList.contains('mantine-NativeSelect-input'), 'list filter uses Mantine NativeSelect'); + assert.equal(filterSelect.classList.contains('select'), false); + + h.app.state.config = { + enrollment_id: 'e1', + settings: { prefix: '!', bot_name: '' }, + global_settings: { prefix: '!' }, + rules: [], + commands: [], + log_channels: [{ event: 'message_delete', effective: '123456789012345678', ignore: { users: [], channels: [] } }], + badwords: [], + templates: [], + }; + const modal = await h.app.editRule({ + rule_id: 'custom:12345678', + name: 'Custom', + custom: true, + effective: { + name: 'Custom', + enabled: true, + dry_run: true, + skip_moderators: true, + log_automod: true, + open_case: false, + params: { kind: 'channel_content', links: true, attachments: false, gifs: false, stickers: false, allowed_domains: [] }, + actions: [{ at: 1, action: 'warn', reason: '' }], + whitelist_roles: [], + whitelist_channels: [], + whitelist_users: [], + include_channels: [], + }, + }); + const switchInput = modal.querySelector('input[role="switch"]'); + assert.ok(switchInput?.classList.contains('mantine-Switch-input'), 'rule toggles use Mantine Switch'); + assert.equal(switchInput.classList.contains('toggle'), false); + const checkboxInput = modal.querySelector('.checkbox-group input[type="checkbox"]'); + assert.ok(checkboxInput?.classList.contains('mantine-Checkbox-input'), 'rule checkboxes use Mantine Checkbox'); + assert.equal(checkboxInput.classList.contains('checkbox'), false); + const textInput = modal.querySelector('input[type="text"]'); + assert.ok(textInput?.classList.contains('mantine-TextInput-input'), 'rule text inputs use Mantine TextInput'); + assert.equal(textInput.classList.contains('input'), false); + + h.app.navigate('badwords'); + await settle(); + const textarea = h.document.querySelector('#content textarea'); + assert.ok(textarea?.classList.contains('mantine-Textarea-input'), 'multiline fields use Mantine Textarea'); + assert.equal(textarea.classList.contains('textarea'), false); +}); diff --git a/scripts/package-webui-test.mjs b/scripts/package-webui-test.mjs index 728181a7..27f08df5 100644 --- a/scripts/package-webui-test.mjs +++ b/scripts/package-webui-test.mjs @@ -97,7 +97,7 @@ test("WebUI ships Mantine components without the retired UI libraries", () => { emitted.add(input); } } - for (const name of ["ActionIcon", "Badge", "Button", "Modal", "NativeSelect", "Notification", "Paper", "Progress", "Table", "Tooltip", "UnstyledButton"]) { + for (const name of ["ActionIcon", "Badge", "Button", "Checkbox", "Input", "Modal", "NativeSelect", "Notification", "Paper", "Progress", "Switch", "Table", "TextInput", "Textarea", "Tooltip", "UnstyledButton"]) { assert.ok([...emitted].some((file) => file.includes(`/@mantine/core/esm/components/${name}/`)), name); } assert.ok([...emitted].some((file) => file.includes("/@mantine/notifications/esm/Notifications.mjs")), "Notifications"); @@ -105,12 +105,12 @@ test("WebUI ships Mantine components without the retired UI libraries", () => { test("WebUI CSS retains used widgets and excludes unused component families", () => { const css = fs.readFileSync(path.join(repo, "dist/frontend/style.css"), "utf8"); - for (const name of ["alert", "badge", "card", "checkbox", "hero", "input", "menu", "modal-overlay", "select", "stat", "textarea", "toggle"]) { + for (const name of ["alert", "badge", "card", "hero", "menu", "modal-overlay", "stat"]) { assert.ok(new RegExp("\\." + name + "(?=[^a-zA-Z0-9_-])").test(css), "missing " + name); } - assert.ok(!/\.btn(?=[^a-zA-Z0-9_-])/.test(css), "retired daisy .btn must not be emitted"); - assert.ok(!/\.table(?=[^a-zA-Z0-9_-])/.test(css), "retired daisy .table must not be emitted"); - assert.ok(!/\.table-zebra(?=[^a-zA-Z0-9_-])/.test(css), "retired daisy .table-zebra must not be emitted"); + for (const name of ["btn", "checkbox", "input", "select", "table", "table-zebra", "textarea", "toggle"]) { + assert.ok(!new RegExp("\\." + name + "(?=[^a-zA-Z0-9_-])").test(css), `retired daisy .${name} must not be emitted`); + } assert.ok(css.includes(".table-scroll{"), "horizontal table scroll wrapper must stay emitted"); for (const name of ["carousel", "chat", "countdown", "dock", "drawer", "rating", "timeline"]) { assert.ok(!new RegExp("\\." + name + "(?=[^a-zA-Z0-9_-])").test(css), "unused " + name); @@ -121,7 +121,7 @@ test("WebUI CSS retains used widgets and excludes unused component families", () // Selective imports keep unused Mantine component styles out of the release. const { css: metadata } = JSON.parse(fs.readFileSync(path.join(repo, "dist/webui-metafile.json"), "utf8")); assert.ok(!Object.keys(metadata.inputs).some((name) => /@mantine\/core\/styles(?:\.layer)?\.css$/.test(name))); - for (const name of ["ActionIcon", "Button", "Table"]) { + for (const name of ["ActionIcon", "Button", "Checkbox", "Combobox", "InlineInput", "Input", "Switch", "Table"]) { assert.ok(Object.keys(metadata.inputs).some((file) => file.endsWith(`/@mantine/core/styles/${name}.layer.css`)), "missing Mantine CSS " + name); } for (const name of ["bg-base-300", "text-secondary", "rounded-t-box", "rounded-selector"]) { diff --git a/tools/webui/mantine.js b/tools/webui/mantine.js index 03ecba65..f8750323 100644 --- a/tools/webui/mantine.js +++ b/tools/webui/mantine.js @@ -1,4 +1,4 @@ export { - ActionIcon, Badge, Box, Button, FocusTrap, MantineProvider, Modal, NativeSelect, Paper, Progress, Table, Tooltip, UnstyledButton, + ActionIcon, Badge, Box, Button, Checkbox, FocusTrap, MantineProvider, Modal, NativeSelect, Paper, Progress, Switch, Table, TextInput, Textarea, Tooltip, UnstyledButton, } from "@mantine/core"; export { Notifications, notifications } from "@mantine/notifications"; diff --git a/tools/webui/style.css b/tools/webui/style.css index 06b55c48..340340eb 100644 --- a/tools/webui/style.css +++ b/tools/webui/style.css @@ -9,6 +9,9 @@ @import "@mantine/core/styles/Button.layer.css"; @import "@mantine/core/styles/Combobox.layer.css"; @import "@mantine/core/styles/Input.layer.css"; +@import "@mantine/core/styles/InlineInput.layer.css"; +@import "@mantine/core/styles/Checkbox.layer.css"; +@import "@mantine/core/styles/Switch.layer.css"; @import "@mantine/core/styles/Notification.layer.css"; @import "@mantine/core/styles/Paper.layer.css"; @import "@mantine/core/styles/Progress.layer.css";