Skip to content

Build your personal knowledge base with Trilium Notes

client/options/password & auth: switch to the new card component

Adorian Doran6e443472be0a
diff --git a/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.css b/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.css
index 6ceb949923..7624ddb1a5 100644
--- a/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.css
+++ b/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.css
@@ -1,10 +1,3 @@
-/* Section-title layout: the title text with its status badge inline just after it. */
-.mfa-status-title {
- display: inline-flex;
- align-items: center;
- gap: 10px;
-}
-
/* The badge itself: a colored outline whose hue is driven by --color per tone. */
.mfa-status-badge.active {
--color: var(--admonition-tip-accent-color, #40c025);
diff --git a/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.tsx b/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.tsx
index 42dec86e72..3682c89b0c 100644
--- a/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/MfaStatusBadge.tsx
@@ -14,7 +14,8 @@ const TONE_ICON: Record<MfaStatusTone, string> = {
/**
* Status badge shared by the sign-in method cards (OpenID Connect, TOTP): a colored outline whose hue
* and icon are driven by `tone` — green when the method is active, amber when it's configured but not
- * yet bound, muted when it's off. Wrap it in a `.mfa-status-title` span to sit inline after a section title.
+ * yet bound, muted when it's off. Pass it as a card's `actions`, where it sits at the far end of the
+ * heading line.
*/
export default function MfaStatusBadge({ tone, text }: { tone: MfaStatusTone, text: string }) {
return <Badge className={`mfa-status-badge ${tone}`} icon={TONE_ICON[tone]} text={text} outline />;
diff --git a/apps/client/src/widgets/type_widgets/options/password.css b/apps/client/src/widgets/type_widgets/options/password.css
index 735b9b661f..24ce9e5984 100644
--- a/apps/client/src/widgets/type_widgets/options/password.css
+++ b/apps/client/src/widgets/type_widgets/options/password.css
@@ -1,3 +1,26 @@
+/* A figure and the scale it is read in, sized to the figure rather than to the row it stands in. */
+.password-number input[type="number"] {
+ width: 7em;
+}
+
+/* Bootstrap gives a select the whole width of what holds it, which in a card row leaves the label
+ beside it a word to the line. */
+.signin-method select {
+ width: auto;
+ min-width: 150px;
+ max-width: 260px;
+}
+
+/* Sentences rather than a control, so the segment carries them with no margin of their own. */
+.signin-method-description p {
+ margin-bottom: 0;
+}
+
+/* An admonition brings its own frame and spacing; the segment holding it adds none. */
+.mfa-notice .admonition {
+ margin-bottom: 0;
+}
+
/* Provider row: the issuer icon (or a fallback key glyph) sitting just before its display name. */
.oauth-provider {
display: inline-flex;
diff --git a/apps/client/src/widgets/type_widgets/options/password.tsx b/apps/client/src/widgets/type_widgets/options/password.tsx
index 633c8c694f..9dc2c25d6d 100644
--- a/apps/client/src/widgets/type_widgets/options/password.tsx
+++ b/apps/client/src/widgets/type_widgets/options/password.tsx
@@ -13,6 +13,7 @@ import toast from "../../../services/toast";
import { isElectron } from "../../../services/utils";
import { ExtendedAdmonition } from "../../react/Admonition";
import Button from "../../react/Button";
+import { Card, CardOption, CardSection } from "../../react/Card";
import FormGroup from "../../react/FormGroup";
import FormSelect from "../../react/FormSelect";
import FormText from "../../react/FormText";
@@ -22,8 +23,6 @@ import Modal from "../../react/Modal";
import RawHtml from "../../react/RawHtml";
import MfaStatusBadge, { MfaStatusTone } from "./components/MfaStatusBadge";
import OptionsPageHeader from "./components/OptionsPageHeader";
-import OptionsRow, { OptionsRowWithButton } from "./components/OptionsRow";
-import OptionsSection from "./components/OptionsSection";
import TimeSelector from "./components/TimeSelector";
import { TotpSettings } from "./totp";
@@ -45,33 +44,45 @@ function ChangePassword() {
const [showModal, setShowModal] = useState(false);
return (
- <OptionsSection title={t("password.heading")}>
- <OptionsRowWithButton
- label={t("password.change_password")}
- description={t("password.change_password_description")}
- buttonText={t("password.change_password_button")}
- onClick={() => setShowModal(true)}
- />
-
- <OptionsRowWithButton
- label={t("password.reset_password")}
- description={t("password.reset_password_description")}
- buttonText={t("password.reset_password_button")}
- onClick={async () => {
- if (!await dialog.confirm(t("password.reset_confirmation"))) {
- return;
- }
-
- await server.post("password/reset?really=yesIReallyWantToResetPasswordAndLoseAccessToMyProtectedNotes");
- toast.showError(t("password.reset_success_message"));
- }}
- />
+ <div className="options-section">
+ <Card heading={t("password.heading")}>
+ <CardOption
+ label={t("password.change_password")}
+ description={t("password.change_password_description")}
+ >
+ <Button
+ name="change-password-button"
+ text={t("password.change_password_button")}
+ size="micro"
+ onClick={() => setShowModal(true)}
+ />
+ </CardOption>
+
+ <CardOption
+ label={t("password.reset_password")}
+ description={t("password.reset_password_description")}
+ >
+ <Button
+ name="reset-password-button"
+ text={t("password.reset_password_button")}
+ size="micro"
+ onClick={async () => {
+ if (!await dialog.confirm(t("password.reset_confirmation"))) {
+ return;
+ }
+
+ await server.post("password/reset?really=yesIReallyWantToResetPasswordAndLoseAccessToMyProtectedNotes");
+ toast.showError(t("password.reset_success_message"));
+ }}
+ />
+ </CardOption>
+ </Card>
{createPortal(
<ChangePasswordModal show={showModal} onHidden={() => setShowModal(false)} />,
document.body
)}
- </OptionsSection>
+ </div>
);
}
@@ -162,20 +173,23 @@ function ChangePasswordModal({ show, onHidden }: ChangePasswordModalProps) {
function ProtectedSessionTimeout() {
return (
- <OptionsSection title={t("password.protected_session_timeout")}>
- <OptionsRow
- name="protected-session-timeout"
- label={t("password.protected_session_timeout_label")}
- description={<>{t("password.protected_session_timeout_description")} <a class="tn-link" href="https://triliumnext.github.io/Docs/Wiki/protected-notes.html">{t("password.wiki")}</a> {t("password.for_more_info")}</>}
- >
- <TimeSelector
+ <div className="options-section">
+ <Card heading={t("password.protected_session_timeout")}>
+ <CardOption
+ className="password-number"
name="protected-session-timeout"
- optionValueId="protectedSessionTimeout"
- optionTimeScaleId="protectedSessionTimeoutTimeScale"
- minimumSeconds={60}
- />
- </OptionsRow>
- </OptionsSection>
+ label={t("password.protected_session_timeout_label")}
+ description={<>{t("password.protected_session_timeout_description")} <a class="tn-link" href="https://triliumnext.github.io/Docs/Wiki/protected-notes.html">{t("password.wiki")}</a> {t("password.for_more_info")}</>}
+ >
+ <TimeSelector
+ name="protected-session-timeout"
+ optionValueId="protectedSessionTimeout"
+ optionTimeScaleId="protectedSessionTimeoutTimeScale"
+ minimumSeconds={60}
+ />
+ </CardOption>
+ </Card>
+ </div>
);
}
@@ -209,25 +223,31 @@ function SignInMethod() {
return (
<>
- <OptionsSection className="signin-method" title={t("multi_factor_authentication.authentication_title")}>
- <OptionsRow name="signin-method" label={t("multi_factor_authentication.signin_method")}>
- <FormSelect
- values={[
- { value: "local", label: t("multi_factor_authentication.signin_local") },
- { value: "oauth", label: t("multi_factor_authentication.signin_oauth") }
- ]}
- keyProperty="value" titleProperty="label"
- currentValue={usingOAuth ? "oauth" : "local"}
- onChange={(value) => setMfaMethod(value === "oauth" ? "oauth" : "totp")}
- />
- </OptionsRow>
-
- <FormText>
- { usingOAuth
- ? <RawHtml html={t("multi_factor_authentication.oauth_description")} />
- : t("multi_factor_authentication.signin_local_description") }
- </FormText>
- </OptionsSection>
+ <div className="options-section signin-method">
+ <Card heading={t("multi_factor_authentication.authentication_title")}>
+ <CardOption name="signin-method" label={t("multi_factor_authentication.signin_method")}>
+ <FormSelect
+ values={[
+ { value: "local", label: t("multi_factor_authentication.signin_local") },
+ { value: "oauth", label: t("multi_factor_authentication.signin_oauth") }
+ ]}
+ keyProperty="value" titleProperty="label"
+ currentValue={usingOAuth ? "oauth" : "local"}
+ onChange={(value) => setMfaMethod(value === "oauth" ? "oauth" : "totp")}
+ />
+ </CardOption>
+
+ {/* What the chosen method means, below the choice rather than above it — it
+ describes what was picked, not what is on offer. */}
+ <CardSection className="signin-method-description">
+ <FormText>
+ { usingOAuth
+ ? <RawHtml html={t("multi_factor_authentication.oauth_description")} />
+ : t("multi_factor_authentication.signin_local_description") }
+ </FormText>
+ </CardSection>
+ </Card>
+ </div>
{ usingOAuth
? <OAuthStatusCard status={oauthStatus} refreshStatus={refreshOauthStatus} />
@@ -283,76 +303,87 @@ function OAuthStatusCard({ status, refreshStatus }: { status?: OAuthStatus, refr
}, [ status, refreshStatus ]);
return (
- <OptionsSection
- title={
- <span className="mfa-status-title">
- {t("multi_factor_authentication.oauth_title")}
- <MfaStatusBadge tone={badge.tone} text={badge.text} />
- </span>
- }
- noCard={!configured}
- >
- { !configured ? (
- <ExtendedAdmonition
- type="note"
- icon="bx bx-info-circle"
- title={t("multi_factor_authentication.oauth_not_configured_title")}
- detailsLabel={t("multi_factor_authentication.oauth_how_to_enable")}
- details={<OAuthConfigInstructions />}
- >
- <p>{t("multi_factor_authentication.oauth_not_configured_hint")}</p>
-
- { status?.missingVars && status.missingVars.length > 0 && (
- <p>
- {t("multi_factor_authentication.oauth_missing_vars", {
- variables: status.missingVars.map(v => `"${v}"`).join(", ")
- })}
- </p>
- )}
- </ExtendedAdmonition>
- ) : enrolled ? (
- <>
- <OAuthProviderRows status={status} />
- <OptionsRow name="oauth-user-account" label={t("multi_factor_authentication.oauth_user_account")}>
- <span>{status?.name ?? t("multi_factor_authentication.oauth_user_not_logged_in")}</span>
- </OptionsRow>
- <OptionsRow name="oauth-user-email" label={t("multi_factor_authentication.oauth_user_email")}>
- <span>{status?.email ?? t("multi_factor_authentication.oauth_user_not_logged_in")}</span>
- </OptionsRow>
-
- <OptionsRowWithButton
- label={t("multi_factor_authentication.oauth_disconnect_label")}
- description={t("multi_factor_authentication.oauth_disconnect_description")}
- icon="bx-trash"
- buttonClassName="oauth-disconnect-button"
- buttonText={t("multi_factor_authentication.oauth_disconnect_button")}
- onClick={() => void disconnectAccount()}
- />
- </>
- ) : (
- <>
- <ExtendedAdmonition
- type="note"
- icon="bx bx-info-circle"
- title={t("multi_factor_authentication.oauth_not_enrolled_title")}
- detailsLabel={t("multi_factor_authentication.oauth_not_enrolled_details_label")}
- details={t("multi_factor_authentication.oauth_not_enrolled_details")}
- >
- {t("multi_factor_authentication.oauth_not_enrolled_hint")}
- </ExtendedAdmonition>
-
- <OAuthProviderRows status={status} />
-
- <OptionsRowWithButton
- label={t("multi_factor_authentication.oauth_connect_label")}
- description={t("multi_factor_authentication.oauth_connect_description")}
- icon="bx-log-in"
- buttonText={t("multi_factor_authentication.oauth_connect_button")}
- onClick={connectAccount}
- />
- </>
- )}
- </OptionsSection>
+ <div className="options-section">
+ <Card
+ heading={t("multi_factor_authentication.oauth_title")}
+ actions={<MfaStatusBadge tone={badge.tone} text={badge.text} />}
+ >
+ { !configured ? (
+ <CardSection className="mfa-notice">
+ <ExtendedAdmonition
+ type="note"
+ icon="bx bx-info-circle"
+ title={t("multi_factor_authentication.oauth_not_configured_title")}
+ detailsLabel={t("multi_factor_authentication.oauth_how_to_enable")}
+ details={<OAuthConfigInstructions />}
+ >
+ <p>{t("multi_factor_authentication.oauth_not_configured_hint")}</p>
+
+ { status?.missingVars && status.missingVars.length > 0 && (
+ <p>
+ {t("multi_factor_authentication.oauth_missing_vars", {
+ variables: status.missingVars.map(v => `"${v}"`).join(", ")
+ })}
+ </p>
+ )}
+ </ExtendedAdmonition>
+ </CardSection>
+ ) : enrolled ? (
+ <>
+ <OAuthProviderRows status={status} />
+ <CardOption label={t("multi_factor_authentication.oauth_user_account")}>
+ <span>{status?.name ?? t("multi_factor_authentication.oauth_user_not_logged_in")}</span>
+ </CardOption>
+ <CardOption label={t("multi_factor_authentication.oauth_user_email")}>
+ <span>{status?.email ?? t("multi_factor_authentication.oauth_user_not_logged_in")}</span>
+ </CardOption>
+
+ <CardOption
+ label={t("multi_factor_authentication.oauth_disconnect_label")}
+ description={t("multi_factor_authentication.oauth_disconnect_description")}
+ >
+ <Button
+ name="oauth-disconnect-button"
+ className="oauth-disconnect-button"
+ icon="bx-trash"
+ text={t("multi_factor_authentication.oauth_disconnect_button")}
+ size="micro"
+ onClick={() => void disconnectAccount()}
+ />
+ </CardOption>
+ </>
+ ) : (
+ <>
+ <CardSection className="mfa-notice">
+ <ExtendedAdmonition
+ type="note"
+ icon="bx bx-info-circle"
+ title={t("multi_factor_authentication.oauth_not_enrolled_title")}
+ detailsLabel={t("multi_factor_authentication.oauth_not_enrolled_details_label")}
+ details={t("multi_factor_authentication.oauth_not_enrolled_details")}
+ >
+ {t("multi_factor_authentication.oauth_not_enrolled_hint")}
+ </ExtendedAdmonition>
+ </CardSection>
+
+ <OAuthProviderRows status={status} />
+
+ <CardOption
+ label={t("multi_factor_authentication.oauth_connect_label")}
+ description={t("multi_factor_authentication.oauth_connect_description")}
+ >
+ <Button
+ name="oauth-connect-button"
+ icon="bx-log-in"
+ text={t("multi_factor_authentication.oauth_connect_button")}
+ size="micro"
+ onClick={connectAccount}
+ />
+ </CardOption>
+ </>
+ )}
+ </Card>
+ </div>
);
}
@@ -364,16 +395,16 @@ function OAuthProviderRows({ status }: { status?: OAuthStatus }) {
const displayName = oauthProviderDisplayName(status);
return (
<>
- <OptionsRow name="oauth-provider" label={t("multi_factor_authentication.oauth_provider")}>
+ <CardOption label={t("multi_factor_authentication.oauth_provider")}>
<span className="oauth-provider">
<OAuthProviderIcon src={status?.issuerIcon} />
<span>{displayName}</span>
</span>
- </OptionsRow>
+ </CardOption>
{ status?.issuerUrl && (
- <OptionsRow name="oauth-provider-url" label={t("multi_factor_authentication.oauth_provider_url")}>
+ <CardOption label={t("multi_factor_authentication.oauth_provider_url")}>
<span>{status.issuerUrl}</span>
- </OptionsRow>
+ </CardOption>
)}
</>
);
diff --git a/apps/client/src/widgets/type_widgets/options/totp.tsx b/apps/client/src/widgets/type_widgets/options/totp.tsx
index 86cb07f888..4b0d32080b 100644
--- a/apps/client/src/widgets/type_widgets/options/totp.tsx
+++ b/apps/client/src/widgets/type_widgets/options/totp.tsx
@@ -14,6 +14,7 @@ import toast from "../../../services/toast";
import utils from "../../../services/utils";
import Admonition from "../../react/Admonition";
import Button from "../../react/Button";
+import { Card, CardOption } from "../../react/Card";
import FormCheckbox from "../../react/FormCheckbox";
import FormGroup from "../../react/FormGroup";
import FormText from "../../react/FormText";
@@ -22,8 +23,6 @@ import { useStaticTooltip } from "../../react/hooks";
import Modal from "../../react/Modal";
import { RawHtmlBlock } from "../../react/RawHtml";
import MfaStatusBadge from "./components/MfaStatusBadge";
-import { OptionsRowWithButton } from "./components/OptionsRow";
-import OptionsSection from "./components/OptionsSection";
/**
* TOTP (authenticator-app) two-factor settings. Owns the recovery-codes state and the enrollment /
@@ -105,16 +104,13 @@ export function TotpSettings({ totpStatus, refreshTotpStatus }: {
// Status badge mirroring the OpenID card: TOTP is either enabled (a secret is set) or off.
const totpEnabled = totpStatus?.set ?? false;
- const totpTitle = (
- <span className="mfa-status-title">
- {t("multi_factor_authentication.totp_section_title")}
- <MfaStatusBadge
- tone={totpEnabled ? "active" : "inactive"}
- text={totpEnabled
- ? t("multi_factor_authentication.totp_status_active")
- : t("multi_factor_authentication.totp_status_inactive")}
- />
- </span>
+ const totpBadge = (
+ <MfaStatusBadge
+ tone={totpEnabled ? "active" : "inactive"}
+ text={totpEnabled
+ ? t("multi_factor_authentication.totp_status_active")
+ : t("multi_factor_authentication.totp_status_inactive")}
+ />
);
return (<>
@@ -123,20 +119,27 @@ export function TotpSettings({ totpStatus, refreshTotpStatus }: {
by the recovery-codes panel; recovery codes are part of TOTP and never exist without it. */}
{totpStatus?.set
? <TotpRecoveryKeys
- title={totpTitle}
+ badge={totpBadge}
status={recoveryStatus}
onRegenerate={regenerateRecoveryCodes}
onRemoveTotp={removeTotp}
/>
- : <OptionsSection title={totpTitle}>
- <OptionsRowWithButton
- label={t("multi_factor_authentication.totp_setup_label")}
- description={t("multi_factor_authentication.totp_setup_description")}
- icon="bx-plus"
- buttonText={t("multi_factor_authentication.totp_setup_button")}
- onClick={() => setShowEnroll(true)}
- />
- </OptionsSection>}
+ : <div className="options-section">
+ <Card heading={t("multi_factor_authentication.totp_section_title")} actions={totpBadge}>
+ <CardOption
+ label={t("multi_factor_authentication.totp_setup_label")}
+ description={t("multi_factor_authentication.totp_setup_description")}
+ >
+ <Button
+ name="totp-setup-button"
+ icon="bx-plus"
+ text={t("multi_factor_authentication.totp_setup_button")}
+ size="micro"
+ onClick={() => setShowEnroll(true)}
+ />
+ </CardOption>
+ </Card>
+ </div>}
{createPortal(
<TotpEnrollmentModal
@@ -493,8 +496,9 @@ function downloadRecoveryCodes(codes: string[]) {
* remove-TOTP action. The codes themselves are only ever shown once — in a modal right after
* enrollment or regeneration (see {@link RecoveryCodesModal}).
*/
-function TotpRecoveryKeys({ title, status, onRegenerate, onRemoveTotp }: {
- title: ComponentChildren,
+function TotpRecoveryKeys({ badge, status, onRegenerate, onRemoveTotp }: {
+ /** The card's status badge, built by the caller since both of its states share one. */
+ badge: ComponentChildren,
status?: string[],
onRegenerate: () => void,
onRemoveTotp: () => void
@@ -502,31 +506,43 @@ function TotpRecoveryKeys({ title, status, onRegenerate, onRemoveTotp }: {
const remaining = status?.filter(isUnusedRecoveryCode).length ?? 0;
return (
- <OptionsSection title={title}>
- <OptionsRowWithButton
- label={
- <span className="recovery-codes-title">
- {t("multi_factor_authentication.recovery_keys_label")}
- {status && status.length > 0 && <RecoveryCodeDots status={status} />}
- </span>
- }
- description={status && status.length > 0
- ? t("multi_factor_authentication.recovery_keys_remaining", { remaining, total: status.length })
- : t("multi_factor_authentication.recovery_keys_no_key_set")}
- icon="bx-refresh"
- buttonText={t("multi_factor_authentication.recovery_keys_regenerate")}
- onClick={onRegenerate}
- />
+ <div className="options-section">
+ <Card heading={t("multi_factor_authentication.totp_section_title")} actions={badge}>
+ <CardOption
+ label={
+ <span className="recovery-codes-title">
+ {t("multi_factor_authentication.recovery_keys_label")}
+ {status && status.length > 0 && <RecoveryCodeDots status={status} />}
+ </span>
+ }
+ description={status && status.length > 0
+ ? t("multi_factor_authentication.recovery_keys_remaining", { remaining, total: status.length })
+ : t("multi_factor_authentication.recovery_keys_no_key_set")}
+ >
+ <Button
+ name="regenerate-recovery-keys-button"
+ icon="bx-refresh"
+ text={t("multi_factor_authentication.recovery_keys_regenerate")}
+ size="micro"
+ onClick={onRegenerate}
+ />
+ </CardOption>
- <OptionsRowWithButton
- label={t("multi_factor_authentication.totp_remove_label")}
- description={t("multi_factor_authentication.totp_remove_description")}
- icon="bx-trash"
- buttonClassName="totp-remove-button"
- buttonText={t("multi_factor_authentication.totp_remove_button")}
- onClick={onRemoveTotp}
- />
- </OptionsSection>
+ <CardOption
+ label={t("multi_factor_authentication.totp_remove_label")}
+ description={t("multi_factor_authentication.totp_remove_description")}
+ >
+ <Button
+ name="totp-remove-button"
+ className="totp-remove-button"
+ icon="bx-trash"
+ text={t("multi_factor_authentication.totp_remove_button")}
+ size="micro"
+ onClick={onRemoveTotp}
+ />
+ </CardOption>
+ </Card>
+ </div>
);
}