SettingsSection, SettingsRow
Settings pages: sections with a title and a Save button. In each row the label is on the start side and the control on the end side from 768 px. status on the section is a short state at the start of the footer (“Unsaved changes”, “Changes saved.”); it is read politely, shows with footer, and wraps above the buttons below 640 px. Pass null while there is nothing to say, so the first change is announced. On a row, error shows under the control; with controlId the control gets aria-invalid and the error in aria-describedby, and a row without controlId names the error in its group description. required adds the mark and optional the word after the label, as in Field. action puts a button, for example Edit, at the end of the section heading.
import { SettingsSection, SettingsRow } from "@percentsa/ui";Examples
Profile
How your name and language appear to your team.
Emails use this language too.
Notifications
Code
export function SettingsExample() {
const t = useT();
return (
<SettingsSection
className="w-full"
title={t("Profile", "الملف الشخصي")}
description={t("How your name and language appear to your team.", "كيف يظهر اسمك ولغتك لفريقك.")}
footer={<Button>{t("Save", "حفظ")}</Button>}
>
{/* One field: give it an id and pass the same controlId, so the label names it. */}
<SettingsRow label={t("Display name", "الاسم الظاهر")} controlId="display-name" control={<Input id="display-name" defaultValue={t("Sara", "سارة")} />} />
<SettingsRow
label={t("Language", "اللغة")}
description={t("Emails use this language too.", "تصلك الرسائل بهذه اللغة أيضًا.")}
controlId="language"
control={
<Select
id="language"
defaultValue="ar"
options={[
{ value: "ar", label: "العربية" },
{ value: "en", label: "English" },
]}
/>
}
/>
{/* Several controls with their own labels: no controlId; the row label names the group. */}
<SettingsRow
label={t("Notifications", "الإشعارات")}
control={
<Stack gap={3}>
<Switch label={t("Email", "البريد الإلكتروني")} defaultChecked />
<Switch label={t("Text message", "رسالة نصية")} />
</Stack>
}
/>
</SettingsSection>
);
}
/** `status` at the start of the footer, and `error` on a row with `required` and `optional`. */Profile
Code
export function SettingsStatusExample() {
const t = useT();
const [name, setName] = useState("Sara");
const [saved, setSaved] = useState<string | null>(null);
const [dirty, setDirty] = useState(false);
const error = name.trim() ? undefined : t("Enter a name.", "أدخل اسمًا.");
return (
<SettingsSection
className="w-full"
title={t("Profile", "الملف الشخصي")}
status={dirty ? t("Unsaved changes", "تغييرات غير محفوظة") : saved}
footer={
<Button
disabled={!dirty || !!error}
onClick={() => {
setDirty(false);
setSaved(t("Changes saved.", "حُفظت التغييرات."));
}}
>
{t("Save", "حفظ")}
</Button>
}
>
<SettingsRow
label={t("Display name", "الاسم الظاهر")}
controlId="status-name"
required
error={error}
control={
<Input
id="status-name"
value={name}
onChange={(e) => {
setName(e.target.value);
setDirty(true);
}}
/>
}
/>
<SettingsRow label={t("Job title", "المسمى الوظيفي")} controlId="status-title" optional control={<Input id="status-title" />} />
</SettingsSection>
);
}Limits
The most your team can use each month.
Storage
Members
Code
export function SettingsActionExample() {
const t = useT();
return (
<SettingsSection
className="w-full"
title={t("Limits", "الحدود")}
description={t("The most your team can use each month.", "أقصى ما يستخدمه فريقك كل شهر.")}
action={<Button variant="secondary" size="sm">{t("Edit", "تعديل")}</Button>}
>
<SettingsRow label={t("Storage", "التخزين")} control={<span className="text-sm">{t("50 GB", "50 جيجابايت")}</span>} />
<SettingsRow label={t("Members", "الأعضاء")} control={<span className="text-sm">{t("10", "10")}</span>} />
</SettingsSection>
);
}