App patterns
SecretRow
A secret setting: shows only whether it is set, and when it changed. The new value goes in a sheet; its title is "Set" or "Change" with the label and its button has the same word. sheetDescription adds a line under the title and hint a line under the field. file adds a button that reads a chosen text file (a key or a certificate) into the field. A file of another type, or over 1 MB, is refused with a message. removeLabel replaces the word "Remove" in the menu and the confirm dialog. action adds a second action in the row, for example a "Test" button, after the Set button and before the menu; it shows only when the person can edit.
import { SecretRow, type SecretRowProps } from "@percentsa/ui";Examples
Secrets
Payment key
SetChanged by Sara
Mail password
Not setWithout it: Order emails
TLS certificate key
Set
Signing key
SetOnly the owner can change it.
Code
export function SecretRowExample() {
const t = useT();
const save = (_value: string) => new Promise<void>((done) => setTimeout(done, 600));
return (
<SettingsSection className="w-full max-w-2xl" title={t("Secrets", "الأسرار")}>
<SecretRow label={t("Payment key", "مفتاح الدفع")} canEdit secret={{ set: true, changedAt: Date.now() - 3 * 86_400_000, changedBy: "Sara" }} onSave={save} onRemove={async () => {}} action={<Button variant="secondary" size="sm">{t("Test", "اختبار")}</Button>} />
<SecretRow label={t("Mail password", "كلمة مرور البريد")} required stops={t("Order emails", "رسائل الطلبات")} canEdit secret={{ set: false }} onSave={save} />
<SecretRow
label={t("TLS certificate key", "مفتاح شهادة TLS")}
pem
canEdit
secret={{ set: true }}
onRemove={async () => {}}
sheetDescription={t("The private key for shop.example.com.", "المفتاح الخاص لـ shop.example.com.")}
hint={t("Starts with -----BEGIN PRIVATE KEY-----.", "يبدأ بـ -----BEGIN PRIVATE KEY-----.")}
file={{ accept: ".pem,.key,text/plain", label: t("Choose a key file", "اختر ملف المفتاح") }}
removeLabel={t("Delete key", "حذف المفتاح")}
onSave={save}
/>
<SecretRow label={t("Signing key", "مفتاح التوقيع")} canEdit={false} owner={t("Only the owner can change it.", "المالك وحده يستطيع تغييره.")} secret={{ set: true }} onSave={save} />
</SettingsSection>
);
}