Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): preview instance branding in the setup wizard

Hampus6ffe5f27e46c
diff --git a/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.module.css b/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.module.css
new file mode 100644
index 000000000..52c72c805
--- /dev/null
+++ b/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.module.css
@@ -0,0 +1,726 @@
+/* SPDX-License-Identifier: AGPL-3.0-or-later */
+
+.hotspot {
+ appearance: none;
+ margin: 0;
+ padding: 0;
+ border: 0;
+ background: none;
+ color: inherit;
+ font: inherit;
+ text-align: inherit;
+ cursor: pointer;
+}
+
+.hotspot:hover:not(.highlighted) {
+ outline: calc(2 * var(--u, 1px)) solid color-mix(in srgb, var(--brand-primary-light, #a5a2ff) 45%, transparent);
+ outline-offset: calc(4 * var(--u, 1px));
+}
+
+.highlighted {
+ outline: calc(2 * var(--u, 1px)) dashed var(--brand-primary-light, #a5a2ff);
+ outline-offset: calc(4 * var(--u, 1px));
+}
+
+.preview {
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+ height: 100%;
+ min-width: 0;
+ min-height: 0;
+}
+
+.tabsScroller {
+ flex: 0 0 auto;
+ overflow-x: auto;
+ scrollbar-width: none;
+}
+
+.tabsScroller::-webkit-scrollbar {
+ display: none;
+}
+
+.tabsScroller .tabs {
+ min-width: max-content;
+ padding: 0;
+}
+
+.tabs button {
+ white-space: nowrap;
+}
+
+.stage {
+ container-type: size;
+ display: flex;
+ flex: 1 1 auto;
+ align-items: center;
+ justify-content: center;
+ height: var(--preview-stage-height, auto);
+ min-height: 0;
+ overflow: hidden;
+ padding: clamp(0.75rem, 2.5cqw, 2rem);
+ border-radius: 0.75rem;
+ background: color-mix(in srgb, var(--background-tertiary) 55%, transparent);
+}
+
+.scene {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 100%;
+ height: 100%;
+ min-width: 0;
+ min-height: 0;
+}
+
+.caption {
+ display: var(--preview-caption-display, block);
+ flex: 0 0 auto;
+ min-height: calc(1.45em * 3);
+ color: var(--text-secondary);
+ font-size: 0.8125rem;
+ line-height: 1.45;
+}
+
+.caption p {
+ margin: 0;
+}
+
+.caption p + p {
+ margin-block-start: 0.25rem;
+ color: var(--text-tertiary);
+}
+
+.computerFrame {
+ --u: calc(100cqw / 1280);
+ container-type: inline-size;
+ display: flex;
+ flex: 0 0 auto;
+ flex-direction: column;
+ width: min(100cqw, calc(100cqh * 1280 / 808));
+ overflow: hidden;
+ border: 0.0625rem solid rgb(255 255 255 / 0.12);
+ border-radius: 0.625rem;
+ background: #202024;
+ box-shadow: 0 1rem 3rem -1rem rgb(0 0 0 / 0.6);
+}
+
+.browserChrome {
+ display: flex;
+ flex-direction: column;
+ background: #202024;
+ color: #e3e3e8;
+}
+
+.browserTabs {
+ display: flex;
+ align-items: flex-end;
+ height: calc(40 * var(--u));
+ padding-inline: calc(84 * var(--u)) calc(16 * var(--u));
+}
+
+.browserTab {
+ display: flex;
+ align-items: center;
+ gap: calc(10 * var(--u));
+ width: calc(260 * var(--u));
+ height: calc(32 * var(--u));
+ padding-inline: calc(12 * var(--u));
+ border-radius: calc(10 * var(--u)) calc(10 * var(--u)) 0 0;
+ background: #35353b;
+ font-size: calc(13 * var(--u));
+}
+
+.favicon {
+ display: flex;
+ flex: 0 0 auto;
+ width: calc(16 * var(--u));
+ height: calc(16 * var(--u));
+}
+
+.favicon img,
+.favicon svg {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+}
+
+.browserTabTitle {
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.browserTabClose {
+ flex: 0 0 auto;
+ width: calc(12 * var(--u));
+ height: calc(12 * var(--u));
+ opacity: 0.7;
+}
+
+.addressBar {
+ display: flex;
+ align-items: center;
+ gap: calc(8 * var(--u));
+ height: calc(30 * var(--u));
+ margin: calc(6 * var(--u)) calc(12 * var(--u)) calc(8 * var(--u));
+ padding-inline: calc(14 * var(--u));
+ border-radius: calc(15 * var(--u));
+ background: #35353b;
+ color: #c8c8d0;
+ font-size: calc(13 * var(--u));
+}
+
+.addressIcon {
+ width: calc(12 * var(--u));
+ height: calc(12 * var(--u));
+}
+
+.computerPage {
+ position: relative;
+ isolation: isolate;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: calc(720 * var(--u));
+ overflow: hidden;
+}
+
+.pageBackground {
+ position: absolute;
+ inset: 0;
+ z-index: -1;
+ display: block;
+ background:
+ radial-gradient(circle at 18% 22%, rgb(226 218 255 / 0.5) 0 0.06rem, transparent 0.07rem),
+ radial-gradient(circle at 72% 14%, rgb(255 255 255 / 0.45) 0 0.05rem, transparent 0.06rem),
+ radial-gradient(circle at 86% 68%, rgb(213 202 255 / 0.4) 0 0.06rem, transparent 0.07rem),
+ radial-gradient(circle at 34% 82%, rgb(255 255 255 / 0.35) 0 0.05rem, transparent 0.06rem),
+ radial-gradient(circle at 58% 48%, rgb(237 231 255 / 0.3) 0 0.05rem, transparent 0.06rem),
+ linear-gradient(145deg, #05040d 0%, #080616 48%, #0d0a1c 100%);
+}
+
+.pageBackground.highlighted,
+.pageBackground.hotspot:hover {
+ outline-offset: calc(-6 * var(--u));
+}
+
+.backdropImage {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.backdropScrim {
+ position: absolute;
+ inset: 0;
+ background-color: rgb(5 4 13 / 0.55);
+}
+
+.backdropScrimPhone {
+ background-color: rgb(5 4 13 / 0.75);
+}
+
+.card {
+ display: flex;
+ flex-direction: column;
+ width: calc(512 * var(--u));
+ overflow: hidden;
+ border: calc(1 * var(--u)) solid rgb(255 255 255 / 0.08);
+ border-radius: calc(8 * var(--u));
+ background: var(--background-secondary);
+ box-shadow: 0 calc(20 * var(--u)) calc(64 * var(--u)) calc(-24 * var(--u)) rgb(0 0 0 / 0.7);
+}
+
+.cardSplit {
+ flex-direction: row;
+ width: calc(800 * var(--u));
+ min-height: calc(448 * var(--u));
+}
+
+.cardBrand {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: calc(10 * var(--u));
+ padding: calc(40 * var(--u)) calc(56 * var(--u)) 0;
+ color: var(--text-primary);
+ text-align: center;
+}
+
+.cardSplit .cardBrand {
+ flex: 0 0 calc(288 * var(--u));
+ gap: calc(24 * var(--u));
+ padding: calc(40 * var(--u)) calc(24 * var(--u));
+ border-inline-end: calc(1 * var(--u)) solid var(--background-modifier-accent);
+}
+
+.cardLogoBox {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.cardLogo {
+ display: block;
+ width: auto;
+ max-width: calc(208 * var(--u));
+ height: calc(128 * var(--u));
+ object-fit: contain;
+}
+
+.cardWordmarkBox {
+ display: flex;
+ justify-content: center;
+ max-width: calc(208 * var(--u));
+}
+
+.cardWordmark {
+ display: block;
+ max-width: 100%;
+ height: calc(32 * var(--u));
+ font-size: calc(24 * var(--u));
+ line-height: 1.1;
+ overflow-wrap: anywhere;
+ object-fit: contain;
+}
+
+span.cardWordmark,
+span.phoneWordmark,
+span.titlebarWordmark {
+ height: auto;
+}
+
+.cardHost {
+ margin-block-start: calc(-12 * var(--u));
+ color: var(--text-tertiary);
+ font-size: calc(13 * var(--u));
+}
+
+.card:not(.cardSplit) .cardHost {
+ margin-block-start: 0;
+}
+
+.cardForm {
+ display: flex;
+ flex: 1 1 auto;
+ flex-direction: column;
+ justify-content: center;
+ padding: calc(40 * var(--u));
+}
+
+.formSkeleton {
+ display: flex;
+ flex-direction: column;
+ gap: calc(14 * var(--u));
+}
+
+.skeletonTitle,
+.skeletonLine,
+.skeletonInput,
+.skeletonButton {
+ border-radius: calc(6 * var(--u));
+}
+
+.skeletonTitle {
+ width: 55%;
+ height: calc(22 * var(--u));
+ background: color-mix(in srgb, var(--text-primary) 22%, transparent);
+}
+
+.skeletonLine {
+ width: 80%;
+ height: calc(12 * var(--u));
+ margin-block-end: calc(8 * var(--u));
+ background: color-mix(in srgb, var(--text-primary) 12%, transparent);
+}
+
+.skeletonInput {
+ height: calc(40 * var(--u));
+ border: calc(1 * var(--u)) solid var(--background-modifier-accent);
+ background: var(--background-tertiary);
+}
+
+.skeletonButton {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: calc(40 * var(--u));
+ margin-block-start: calc(6 * var(--u));
+ background: var(--brand-primary, #4641d9);
+}
+
+.skeletonButtonText {
+ width: calc(64 * var(--u));
+ height: calc(10 * var(--u));
+ border-radius: calc(5 * var(--u));
+ background: #fff;
+}
+
+.phoneFrame {
+ --u: calc(100cqw / 390);
+ container-type: inline-size;
+ display: flex;
+ flex: 0 0 auto;
+ flex-direction: column;
+ width: min(100cqw, calc((100cqh - 0.75rem) * 390 / 844), 26rem);
+ overflow: hidden;
+ border: 0.375rem solid #232327;
+ border-radius: 1.75rem;
+ background: #080616;
+ box-shadow: 0 1rem 3rem -1rem rgb(0 0 0 / 0.6);
+}
+
+.phoneToolbar {
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ height: calc(92 * var(--u));
+ padding-block-end: calc(10 * var(--u));
+ background: #18171f;
+}
+
+.phoneToolbar.highlighted,
+.phoneToolbar.hotspot:hover {
+ outline-offset: calc(-4 * var(--u));
+}
+
+.phoneAddress {
+ padding: calc(6 * var(--u)) calc(18 * var(--u));
+ border-radius: calc(16 * var(--u));
+ background: color-mix(in srgb, currentColor 14%, transparent);
+ font-size: calc(14 * var(--u));
+}
+
+.phonePage {
+ position: relative;
+ isolation: isolate;
+ height: calc(752 * var(--u));
+ overflow: hidden;
+}
+
+.phoneContent {
+ display: flex;
+ flex-direction: column;
+ align-items: stretch;
+ padding: calc(40 * var(--u)) calc(24 * var(--u));
+ color: var(--text-primary);
+}
+
+.phoneIdentity {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: calc(10 * var(--u));
+}
+
+.phoneLogoBox {
+ display: flex;
+}
+
+.phoneLogo {
+ display: block;
+ width: auto;
+ max-width: calc(64 * var(--u));
+ height: calc(28 * var(--u));
+ object-fit: contain;
+}
+
+.phoneWordmarkBox {
+ display: flex;
+ justify-content: center;
+ max-width: calc(224 * var(--u));
+}
+
+.phoneWordmark {
+ display: block;
+ max-width: 100%;
+ height: calc(32 * var(--u));
+ font-size: calc(24 * var(--u));
+ line-height: 1.1;
+ object-fit: contain;
+}
+
+.phoneHost {
+ margin-block: calc(6 * var(--u)) calc(32 * var(--u));
+ color: var(--text-tertiary);
+ font-size: calc(13 * var(--u));
+ text-align: center;
+}
+
+.phoneContent .formSkeleton {
+ padding: calc(4 * var(--u));
+}
+
+.desktopScene {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 1rem;
+ width: min(100cqw, calc((100cqh - 7.5rem) * 2.4));
+}
+
+@container (max-height: 16rem) {
+ .desktopScene {
+ gap: 0.5rem;
+ width: min(100cqw, calc((100cqh - 3.5rem) * 2.4));
+ }
+
+ .windows {
+ gap: 0.5rem;
+ }
+
+ .titlebarLabel {
+ display: none;
+ }
+}
+
+.desktopScene .platformTabs {
+ width: min(100%, 22rem);
+ padding: 0;
+}
+
+.windows {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+ width: 100%;
+}
+
+.titlebarFigure {
+ display: flex;
+ flex-direction: column;
+ gap: 0.375rem;
+ min-width: 0;
+ margin: 0;
+}
+
+.titlebarLabel {
+ color: var(--text-secondary);
+ font-size: 0.8125rem;
+}
+
+.window {
+ --u: calc(100cqw / 720);
+ container-type: inline-size;
+ overflow: hidden;
+ border: 0.0625rem solid rgb(255 255 255 / 0.12);
+ border-radius: 0.5rem;
+}
+
+.windowDark {
+ --titlebar-bg: #121214;
+ --titlebar-fg: #b9b9c4;
+ --window-rail: #0c0c0e;
+ --window-sidebar: #18181b;
+ --window-body: #1f1f23;
+ --window-line: rgb(255 255 255 / 0.08);
+}
+
+.windowLight {
+ --titlebar-bg: #e3e5e8;
+ --titlebar-fg: #4e5058;
+ --window-rail: #d7d9dc;
+ --window-sidebar: #f2f3f5;
+ --window-body: #ffffff;
+ --window-line: rgb(0 0 0 / 0.08);
+ border-color: rgb(0 0 0 / 0.12);
+}
+
+.titlebar {
+ display: flex;
+ align-items: center;
+ gap: calc(8 * var(--u));
+ height: calc(32 * var(--u));
+ padding-inline: calc(12 * var(--u)) 0;
+ background: var(--titlebar-bg);
+ color: var(--titlebar-fg);
+}
+
+.titlebarBrand {
+ display: flex;
+ align-items: center;
+ color: var(--titlebar-fg);
+ opacity: 0.8;
+}
+
+.titlebarMacos {
+ direction: ltr;
+ padding-inline: calc(12 * var(--u));
+}
+
+.titlebarWordmark {
+ display: block;
+ width: auto;
+ max-width: calc(200 * var(--u));
+ height: calc(13 * var(--u));
+ color: var(--titlebar-fg);
+ font-size: calc(13 * var(--u));
+ line-height: 1;
+ object-fit: contain;
+}
+
+.titlebarSpacer {
+ flex: 1 1 auto;
+}
+
+.trafficLights {
+ display: flex;
+ gap: calc(8 * var(--u));
+}
+
+.trafficLights > span {
+ width: calc(12 * var(--u));
+ height: calc(12 * var(--u));
+ border-radius: 50%;
+ background: #ff5f57;
+}
+
+.trafficLights > span:nth-child(2) {
+ background: #febc2e;
+}
+
+.trafficLights > span:nth-child(3) {
+ background: #28c840;
+}
+
+.windowControls {
+ display: flex;
+ align-self: stretch;
+}
+
+.windowControls > svg {
+ box-sizing: content-box;
+ width: calc(14 * var(--u));
+ height: calc(14 * var(--u));
+ padding: calc(9 * var(--u)) calc(17 * var(--u));
+}
+
+.windowBody {
+ display: flex;
+ height: calc(112 * var(--u));
+ background: var(--window-body);
+}
+
+.windowRail {
+ width: calc(56 * var(--u));
+ background: var(--window-rail);
+}
+
+.windowSidebar {
+ width: calc(160 * var(--u));
+ background: var(--window-sidebar);
+}
+
+.windowMain {
+ display: flex;
+ flex: 1 1 auto;
+ flex-direction: column;
+ gap: calc(10 * var(--u));
+ padding: calc(18 * var(--u));
+}
+
+.windowLine,
+.windowLineShort {
+ height: calc(10 * var(--u));
+ border-radius: calc(5 * var(--u));
+ background: var(--window-line);
+}
+
+.windowLine {
+ width: 70%;
+}
+
+.windowLineShort {
+ width: 40%;
+}
+
+.instanceStage {
+ --u: calc(100cqw / 360);
+ container-type: inline-size;
+ display: flex;
+ flex-direction: column;
+ gap: calc(4 * var(--u));
+ width: min(100cqw, 30rem);
+ padding: calc(8 * var(--u));
+ border: 0.0625rem solid var(--background-modifier-accent);
+ border-radius: 0.75rem;
+ background: var(--background-secondary);
+ box-shadow: 0 1rem 3rem -1rem rgb(0 0 0 / 0.6);
+}
+
+.instanceRow {
+ display: flex;
+ align-items: center;
+ gap: calc(12 * var(--u));
+ padding: calc(10 * var(--u)) calc(12 * var(--u));
+ border-radius: calc(6 * var(--u));
+ background: var(--background-modifier-hover);
+}
+
+.instanceRowOther {
+ background: none;
+ opacity: 0.6;
+}
+
+.instanceMark {
+ display: flex;
+ flex: 0 0 auto;
+ align-items: center;
+ justify-content: center;
+ width: calc(36 * var(--u));
+ height: calc(36 * var(--u));
+ border-radius: calc(8 * var(--u));
+ background: var(--background-tertiary);
+ color: var(--text-secondary);
+}
+
+.instanceMark img,
+.instanceMark svg {
+ width: calc(20 * var(--u));
+ height: calc(20 * var(--u));
+ object-fit: contain;
+}
+
+.instanceMeta {
+ display: flex;
+ flex-direction: column;
+ gap: calc(4 * var(--u));
+ min-width: 0;
+}
+
+.instanceName {
+ overflow: hidden;
+ color: var(--text-primary);
+ font-size: calc(15 * var(--u));
+ font-weight: 600;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.instanceHost {
+ color: var(--text-tertiary);
+ font-size: calc(13 * var(--u));
+}
+
+.instanceNameSkeleton,
+.instanceHostSkeleton {
+ height: calc(10 * var(--u));
+ border-radius: calc(5 * var(--u));
+ background: color-mix(in srgb, var(--text-primary) 14%, transparent);
+}
+
+.instanceNameSkeleton {
+ width: calc(120 * var(--u));
+}
+
+.instanceHostSkeleton {
+ width: calc(84 * var(--u));
+ opacity: 0.7;
+}
diff --git a/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.tsx b/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.tsx
new file mode 100644
index 000000000..67dc540ec
--- /dev/null
+++ b/fluxer_app/src/features/app/components/setup/SetupBrandingPreview.tsx
@@ -0,0 +1,822 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import styles from '@app/features/app/components/setup/SetupBrandingPreview.module.css';
+import type {SetupBrandingAssetKind} from '@app/features/app/components/setup/SetupWizardClient';
+import {PRODUCT_NAME} from '@app/features/app/config/ProductConstants';
+import {getLocaleDirection} from '@app/features/i18n/utils/LocaleDirection';
+import {contrastRatio, getInstanceBrandVariables} from '@app/features/theme/utils/InstanceBrandColors';
+import {FluxerWordmark} from '@app/features/ui/components/icons/FluxerWordmark';
+import {SegmentedTabs} from '@app/features/ui/segmented_tabs/SegmentedTabs';
+import FluxerLogoAsset from '@app/media/images/fluxer-logo-color.svg?react';
+import {msg} from '@lingui/core/macro';
+import {useLingui} from '@lingui/react/macro';
+import {GlobeIcon, LockSimpleIcon, MinusIcon, SquareIcon, XIcon} from '@phosphor-icons/react';
+import {clsx} from 'clsx';
+import type React from 'react';
+import {useEffect, useMemo, useRef, useState} from 'react';
+
+export type BrandingPreviewTab = 'sign_in' | 'phone' | 'desktop' | 'instances';
+export type BrandingPreviewTarget = SetupBrandingAssetKind | 'theme_color';
+type DesktopPlatform = 'controls' | 'macos';
+
+const PREVIEW_TABS_DESCRIPTOR = msg({
+ message: 'Preview',
+ comment: 'Accessible label for the tabs that switch between branding previews in the setup wizard.',
+});
+const TAB_SIGN_IN_DESCRIPTOR = msg({
+ message: 'Sign-in page',
+ comment: 'Setup wizard branding preview tab that shows the sign-in page on a computer.',
+});
+const TAB_PHONE_DESCRIPTOR = msg({
+ message: 'Phone',
+ comment: 'Setup wizard branding preview tab that shows the sign-in page on a phone.',
+});
+const TAB_DESKTOP_DESCRIPTOR = msg({
+ message: 'Desktop app',
+ comment: 'Setup wizard branding preview tab that shows the desktop app title bar.',
+});
+const TAB_INSTANCES_DESCRIPTOR = msg({
+ message: 'Instance list',
+ comment:
+ 'Setup wizard branding preview tab that shows how the instance appears in the account switcher and instance list.',
+});
+const CAPTION_SIGN_IN_DESCRIPTOR = msg({
+ message: 'The sign-in page in a browser on a computer. The desktop app shows the same page.',
+ comment: 'Caption under the sign-in page preview in the setup wizard branding step.',
+});
+const CAPTION_PHONE_DESCRIPTOR = msg({
+ message: 'The sign-in page on a phone, in a mobile browser or the Fluxer mobile app.',
+ comment: 'Caption under the phone preview in the setup wizard branding step.',
+});
+const CAPTION_DESKTOP_DESCRIPTOR = msg({
+ message: 'The wordmark in the desktop app title bar, which follows the light or dark theme each person picks.',
+ comment: 'Caption under the desktop app title bar preview in the setup wizard branding step.',
+});
+const CAPTION_INSTANCES_DESCRIPTOR = msg({
+ message:
+ 'People who use more than one instance see this in the account switcher and when they pick an instance to sign in to.',
+ comment: 'Caption under the instance list preview in the setup wizard branding step.',
+});
+const WINDOWS_LINUX_DESCRIPTOR = msg({
+ message: 'Windows and Linux',
+ comment: 'Label above the Windows and Linux title bar preview in the setup wizard branding step.',
+});
+const MACOS_DESCRIPTOR = msg({
+ message: 'macOS',
+ comment: 'Label above the macOS title bar preview in the setup wizard branding step.',
+});
+const DARK_THEME_DESCRIPTOR = msg({
+ message: 'Dark theme',
+ comment: 'Label for the dark theme title bar preview in the setup wizard branding step.',
+});
+const LIGHT_THEME_DESCRIPTOR = msg({
+ message: 'Light theme',
+ comment: 'Label for the light theme title bar preview in the setup wizard branding step.',
+});
+
+export interface BrandingPreviewDraft {
+ productName: string;
+ themeColor: string | null;
+ sources: Readonly<Record<SetupBrandingAssetKind, string | null>>;
+}
+
+interface BrandingPreviewProps {
+ draft: BrandingPreviewDraft;
+ tab: BrandingPreviewTab;
+ highlight: BrandingPreviewTarget | null;
+ caption: React.ReactNode;
+ onTabChange: (tab: BrandingPreviewTab) => void;
+ onTargetSelect: (target: BrandingPreviewTarget) => void;
+}
+
+interface ResolvedPreviewBrand {
+ productName: string;
+ usesDefaultName: boolean;
+ logoUrl: string | null;
+ showBundledLogo: boolean;
+ wordmarkUrl: string | null;
+ backdropUrl: string | null;
+ faviconUrl: string | null;
+ faviconTarget: 'favicon' | 'favicon_dark';
+ symbolUrl: string | null;
+ accent: string | null;
+ textOnAccent: string | null;
+ toolbarColor: string | null;
+ toolbarText: string;
+ host: string;
+}
+
+const DEFAULT_ACCENT = '#4641d9';
+const TOOLBAR_LIGHT_TEXT = [0xf2, 0xf2, 0xf5] as const;
+const TOOLBAR_DARK_TEXT = [0x18, 0x17, 0x1f] as const;
+
+function toolbarTextFor(color: string | null): string {
+ if (color == null) return 'rgb(242 242 245)';
+ const value = Number.parseInt(color.slice(1, 7), 16);
+ const rgb = [(value >>> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff] as const;
+ return contrastRatio(rgb, TOOLBAR_LIGHT_TEXT) >= contrastRatio(rgb, TOOLBAR_DARK_TEXT)
+ ? 'rgb(242 242 245)'
+ : 'rgb(24 23 31)';
+}
+
+function resolvePreviewBrand(draft: BrandingPreviewDraft): ResolvedPreviewBrand {
+ const {sources} = draft;
+ const productName = draft.productName.trim() || PRODUCT_NAME;
+ const usesDefaultName = productName === PRODUCT_NAME;
+ const logoUrl = sources.logo ?? sources.icon ?? sources.symbol;
+ const accentVariables = getInstanceBrandVariables(draft.themeColor ?? DEFAULT_ACCENT, 'dark', 1);
+ return {
+ productName,
+ usesDefaultName,
+ logoUrl,
+ showBundledLogo: logoUrl == null && usesDefaultName,
+ wordmarkUrl: sources.wordmark,
+ backdropUrl: sources.sign_in_backdrop,
+ faviconUrl: sources.favicon_dark ?? sources.favicon ?? sources.icon,
+ faviconTarget: sources.favicon_dark != null ? 'favicon_dark' : 'favicon',
+ symbolUrl: sources.symbol ?? sources.icon ?? sources.logo,
+ accent: accentVariables?.['--instance-brand-primary'] ?? null,
+ textOnAccent: accentVariables?.['--instance-text-on-brand-primary'] ?? null,
+ toolbarColor: draft.themeColor,
+ toolbarText: toolbarTextFor(draft.themeColor),
+ host: window.location.host,
+ };
+}
+
+function phoneShowsLogo(brand: ResolvedPreviewBrand): boolean {
+ return brand.wordmarkUrl == null && !brand.usesDefaultName && brand.logoUrl != null;
+}
+
+export function brandingPreviewTabsFor(
+ target: BrandingPreviewTarget,
+ draft: BrandingPreviewDraft,
+): ReadonlyArray<BrandingPreviewTab> {
+ switch (target) {
+ case 'theme_color':
+ return ['sign_in', 'phone'];
+ case 'logo':
+ return phoneShowsLogo(resolvePreviewBrand(draft)) ? ['sign_in', 'phone'] : ['sign_in'];
+ case 'wordmark':
+ return ['sign_in', 'phone', 'desktop'];
+ case 'sign_in_backdrop':
+ return ['sign_in', 'phone'];
+ case 'icon':
+ return ['sign_in', 'instances'];
+ case 'symbol':
+ return ['instances'];
+ case 'favicon':
+ case 'favicon_dark':
+ return ['sign_in'];
+ }
+}
+
+interface HotspotProps {
+ target: BrandingPreviewTarget;
+ highlightTargets?: ReadonlyArray<BrandingPreviewTarget>;
+ highlight: BrandingPreviewTarget | null;
+ onSelect: (target: BrandingPreviewTarget) => void;
+ className?: string;
+ style?: React.CSSProperties;
+ children?: React.ReactNode;
+ 'data-flx': string;
+}
+
+function Hotspot({
+ target,
+ highlightTargets = [target],
+ highlight,
+ onSelect,
+ className,
+ style,
+ children,
+ 'data-flx': dataFlx,
+}: HotspotProps) {
+ return (
+ <button
+ type="button"
+ tabIndex={-1}
+ className={clsx(
+ styles.hotspot,
+ className,
+ highlight != null && highlightTargets.includes(highlight) && styles.highlighted,
+ )}
+ style={style}
+ onClick={() => onSelect(target)}
+ data-flx={dataFlx}
+ >
+ {children}
+ </button>
+ );
+}
+
+interface SceneProps {
+ brand: ResolvedPreviewBrand;
+ highlight: BrandingPreviewTarget | null;
+ onSelect: (target: BrandingPreviewTarget) => void;
+}
+
+function PreviewWordmark({brand, className}: {brand: ResolvedPreviewBrand; className: string}) {
+ const branding = useMemo(
+ () => ({productName: brand.productName, wordmarkUrl: brand.wordmarkUrl}),
+ [brand.productName, brand.wordmarkUrl],
+ );
+ return (
+ <FluxerWordmark
+ key={brand.wordmarkUrl ?? brand.productName}
+ className={className}
+ branding={branding}
+ aria-hidden="true"
+ data-flx="app.setup.setup-branding-preview.preview-wordmark.fluxer-wordmark"
+ />
+ );
+}
+
+function PreviewLogo({brand, className}: {brand: ResolvedPreviewBrand; className: string}) {
+ if (brand.logoUrl != null) {
+ return (
+ <img
+ className={className}
+ src={brand.logoUrl}
+ alt=""
+ draggable={false}
+ data-flx="app.setup.setup-branding-preview.preview-logo.img"
+ />
+ );
+ }
+ if (brand.showBundledLogo) {
+ return (
+ <FluxerLogoAsset
+ className={className}
+ aria-hidden="true"
+ data-flx="app.setup.setup-branding-preview.preview-logo.fluxer-logo-asset"
+ />
+ );
+ }
+ return null;
+}
+
+function PreviewBackground({brand, scrim, highlight, onSelect}: SceneProps & {scrim: 'card' | 'phone'}) {
+ return (
+ <Hotspot
+ target="sign_in_backdrop"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.pageBackground}
+ data-flx="app.setup.setup-branding-preview.preview-background.page-background"
+ >
+ {brand.backdropUrl != null && (
+ <>
+ <img
+ className={styles.backdropImage}
+ src={brand.backdropUrl}
+ alt=""
+ draggable={false}
+ data-flx="app.setup.setup-branding-preview.preview-background.backdrop-image"
+ />
+ <span
+ className={clsx(styles.backdropScrim, scrim === 'phone' && styles.backdropScrimPhone)}
+ data-flx="app.setup.setup-branding-preview.preview-background.backdrop-scrim"
+ />
+ </>
+ )}
+ </Hotspot>
+ );
+}
+
+function FormSkeleton({brand, highlight, onSelect}: SceneProps) {
+ return (
+ <div className={styles.formSkeleton} data-flx="app.setup.setup-branding-preview.form-skeleton.form-skeleton">
+ <div className={styles.skeletonTitle} data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-title" />
+ <div className={styles.skeletonLine} data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-line" />
+ <div className={styles.skeletonInput} data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-input" />
+ <div
+ className={styles.skeletonInput}
+ data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-input--2"
+ />
+ <Hotspot
+ target="theme_color"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.skeletonButton}
+ style={brand.accent ? {backgroundColor: brand.accent} : undefined}
+ data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-button"
+ >
+ <span
+ className={styles.skeletonButtonText}
+ style={brand.textOnAccent ? {backgroundColor: brand.textOnAccent} : undefined}
+ data-flx="app.setup.setup-branding-preview.form-skeleton.skeleton-button-text"
+ />
+ </Hotspot>
+ </div>
+ );
+}
+
+function SignInPreview({brand, highlight, onSelect}: SceneProps) {
+ const hasLogo = brand.logoUrl != null || brand.showBundledLogo;
+ return (
+ <div className={styles.computerFrame} data-flx="app.setup.setup-branding-preview.sign-in-preview.computer-frame">
+ <div className={styles.browserChrome} data-flx="app.setup.setup-branding-preview.sign-in-preview.browser-chrome">
+ <div className={styles.browserTabs} data-flx="app.setup.setup-branding-preview.sign-in-preview.browser-tabs">
+ <div className={styles.browserTab} data-flx="app.setup.setup-branding-preview.sign-in-preview.browser-tab">
+ <Hotspot
+ target={brand.faviconTarget}
+ highlightTargets={['favicon', 'favicon_dark', 'icon']}
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.favicon}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.favicon"
+ >
+ {brand.faviconUrl != null ? (
+ <img
+ src={brand.faviconUrl}
+ alt=""
+ draggable={false}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.img"
+ />
+ ) : (
+ <FluxerLogoAsset
+ aria-hidden="true"
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.fluxer-logo-asset"
+ />
+ )}
+ </Hotspot>
+ <span
+ className={styles.browserTabTitle}
+ dir="auto"
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.browser-tab-title"
+ >
+ {brand.productName}
+ </span>
+ <XIcon
+ className={styles.browserTabClose}
+ weight="bold"
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.browser-tab-close"
+ />
+ </div>
+ </div>
+ <div className={styles.addressBar} data-flx="app.setup.setup-branding-preview.sign-in-preview.address-bar">
+ <LockSimpleIcon
+ weight="bold"
+ className={styles.addressIcon}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.address-icon"
+ />
+ <span dir="ltr" data-flx="app.setup.setup-branding-preview.sign-in-preview.span">
+ {brand.host}
+ </span>
+ </div>
+ </div>
+ <div className={styles.computerPage} data-flx="app.setup.setup-branding-preview.sign-in-preview.computer-page">
+ <PreviewBackground
+ brand={brand}
+ scrim="card"
+ highlight={highlight}
+ onSelect={onSelect}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.preview-background"
+ />
+ <div
+ className={clsx(styles.card, hasLogo && styles.cardSplit)}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card"
+ >
+ <div className={styles.cardBrand} data-flx="app.setup.setup-branding-preview.sign-in-preview.card-brand">
+ {hasLogo && (
+ <Hotspot
+ target="logo"
+ highlightTargets={['logo', 'icon']}
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.cardLogoBox}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card-logo-box"
+ >
+ <PreviewLogo
+ brand={brand}
+ className={styles.cardLogo}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card-logo"
+ />
+ </Hotspot>
+ )}
+ <Hotspot
+ target="wordmark"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.cardWordmarkBox}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card-wordmark-box"
+ >
+ <PreviewWordmark
+ brand={brand}
+ className={styles.cardWordmark}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card-wordmark"
+ />
+ </Hotspot>
+ <span
+ className={styles.cardHost}
+ dir="ltr"
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.card-host"
+ >
+ {brand.host}
+ </span>
+ </div>
+ <div className={styles.cardForm} data-flx="app.setup.setup-branding-preview.sign-in-preview.card-form">
+ <FormSkeleton
+ brand={brand}
+ highlight={highlight}
+ onSelect={onSelect}
+ data-flx="app.setup.setup-branding-preview.sign-in-preview.form-skeleton"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function PhonePreview({brand, highlight, onSelect}: SceneProps) {
+ return (
+ <div className={styles.phoneFrame} data-flx="app.setup.setup-branding-preview.phone-preview.phone-frame">
+ <Hotspot
+ target="theme_color"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.phoneToolbar}
+ style={{backgroundColor: brand.toolbarColor ?? undefined, color: brand.toolbarText}}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-toolbar"
+ >
+ <span
+ className={styles.phoneAddress}
+ dir="ltr"
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-address"
+ >
+ {brand.host}
+ </span>
+ </Hotspot>
+ <div className={styles.phonePage} data-flx="app.setup.setup-branding-preview.phone-preview.phone-page">
+ <PreviewBackground
+ brand={brand}
+ scrim="phone"
+ highlight={highlight}
+ onSelect={onSelect}
+ data-flx="app.setup.setup-branding-preview.phone-preview.preview-background"
+ />
+ <div className={styles.phoneContent} data-flx="app.setup.setup-branding-preview.phone-preview.phone-content">
+ <div
+ className={styles.phoneIdentity}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-identity"
+ >
+ {phoneShowsLogo(brand) && (
+ <Hotspot
+ target="logo"
+ highlightTargets={['logo', 'icon']}
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.phoneLogoBox}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-logo-box"
+ >
+ <PreviewLogo
+ brand={brand}
+ className={styles.phoneLogo}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-logo"
+ />
+ </Hotspot>
+ )}
+ <Hotspot
+ target="wordmark"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.phoneWordmarkBox}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-wordmark-box"
+ >
+ <PreviewWordmark
+ brand={brand}
+ className={styles.phoneWordmark}
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-wordmark"
+ />
+ </Hotspot>
+ </div>
+ <span
+ className={styles.phoneHost}
+ dir="ltr"
+ data-flx="app.setup.setup-branding-preview.phone-preview.phone-host"
+ >
+ {brand.host}
+ </span>
+ <FormSkeleton
+ brand={brand}
+ highlight={highlight}
+ onSelect={onSelect}
+ data-flx="app.setup.setup-branding-preview.phone-preview.form-skeleton"
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function TitlebarPreview({
+ brand,
+ platform,
+ theme,
+ label,
+ highlight,
+ onSelect,
+}: SceneProps & {platform: DesktopPlatform; theme: 'dark' | 'light'; label: string}) {
+ const {i18n} = useLingui();
+ const rtl = getLocaleDirection(i18n.locale) === 'rtl';
+ const wordmark = (
+ <Hotspot
+ target="wordmark"
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.titlebarBrand}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-brand"
+ >
+ <PreviewWordmark
+ brand={brand}
+ className={styles.titlebarWordmark}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-wordmark"
+ />
+ </Hotspot>
+ );
+ return (
+ <figure
+ className={styles.titlebarFigure}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-figure"
+ >
+ <figcaption
+ className={styles.titlebarLabel}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-label"
+ >
+ {label}
+ </figcaption>
+ <div
+ className={clsx(styles.window, theme === 'light' ? styles.windowLight : styles.windowDark)}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window"
+ >
+ <div
+ className={clsx(styles.titlebar, platform === 'macos' && styles.titlebarMacos)}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar"
+ >
+ {platform === 'macos' ? (
+ <>
+ <span
+ className={styles.trafficLights}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.traffic-lights"
+ >
+ <span data-flx="app.setup.setup-branding-preview.titlebar-preview.span" />
+ <span data-flx="app.setup.setup-branding-preview.titlebar-preview.span--2" />
+ <span data-flx="app.setup.setup-branding-preview.titlebar-preview.span--3" />
+ </span>
+ {rtl && wordmark}
+ <span
+ className={styles.titlebarSpacer}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-spacer"
+ />
+ {!rtl && wordmark}
+ </>
+ ) : (
+ <>
+ {wordmark}
+ <span
+ className={styles.titlebarSpacer}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.titlebar-spacer--2"
+ />
+ <span
+ className={styles.windowControls}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-controls"
+ >
+ <MinusIcon weight="bold" data-flx="app.setup.setup-branding-preview.titlebar-preview.minus-icon" />
+ <SquareIcon weight="bold" data-flx="app.setup.setup-branding-preview.titlebar-preview.square-icon" />
+ <XIcon weight="bold" data-flx="app.setup.setup-branding-preview.titlebar-preview.x-icon" />
+ </span>
+ </>
+ )}
+ </div>
+ <div className={styles.windowBody} data-flx="app.setup.setup-branding-preview.titlebar-preview.window-body">
+ <span
+ className={styles.windowRail}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-rail"
+ />
+ <span
+ className={styles.windowSidebar}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-sidebar"
+ />
+ <span className={styles.windowMain} data-flx="app.setup.setup-branding-preview.titlebar-preview.window-main">
+ <span
+ className={styles.windowLine}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-line"
+ />
+ <span
+ className={styles.windowLine}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-line--2"
+ />
+ <span
+ className={styles.windowLineShort}
+ data-flx="app.setup.setup-branding-preview.titlebar-preview.window-line-short"
+ />
+ </span>
+ </div>
+ </div>
+ </figure>
+ );
+}
+
+function DesktopPreview({brand, highlight, onSelect}: SceneProps) {
+ const {i18n} = useLingui();
+ const [platform, setPlatform] = useState<DesktopPlatform>('controls');
+ const platforms = useMemo(
+ () => [
+ {id: 'controls' as const, label: i18n._(WINDOWS_LINUX_DESCRIPTOR)},
+ {id: 'macos' as const, label: i18n._(MACOS_DESCRIPTOR)},
+ ],
+ [i18n],
+ );
+ return (
+ <div className={styles.desktopScene} data-flx="app.setup.setup-branding-preview.desktop-preview.desktop-scene">
+ <SegmentedTabs
+ tabs={platforms}
+ selectedTab={platform}
+ onTabChange={setPlatform}
+ ariaLabel={i18n._(TAB_DESKTOP_DESCRIPTOR)}
+ semantics="radio"
+ className={styles.platformTabs}
+ data-flx="app.setup.setup-branding-preview.desktop-preview.platform-tabs"
+ />
+ <div
+ className={styles.windows}
+ aria-hidden="true"
+ data-flx="app.setup.setup-branding-preview.desktop-preview.windows"
+ >
+ {(['dark', 'light'] as const).map((theme) => (
+ <TitlebarPreview
+ key={theme}
+ brand={brand}
+ platform={platform}
+ theme={theme}
+ highlight={highlight}
+ onSelect={onSelect}
+ label={i18n._(theme === 'dark' ? DARK_THEME_DESCRIPTOR : LIGHT_THEME_DESCRIPTOR)}
+ data-flx="app.setup.setup-branding-preview.desktop-preview.titlebar-preview"
+ />
+ ))}
+ </div>
+ </div>
+ );
+}
+
+function InstancesPreview({brand, highlight, onSelect}: SceneProps) {
+ return (
+ <div className={styles.instanceStage} data-flx="app.setup.setup-branding-preview.instances-preview.instance-stage">
+ <div className={styles.instanceRow} data-flx="app.setup.setup-branding-preview.instances-preview.instance-row">
+ <Hotspot
+ target="symbol"
+ highlightTargets={['symbol', 'icon', 'logo']}
+ highlight={highlight}
+ onSelect={onSelect}
+ className={styles.instanceMark}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-mark"
+ >
+ {brand.symbolUrl != null ? (
+ <img
+ src={brand.symbolUrl}
+ alt=""
+ draggable={false}
+ data-flx="app.setup.setup-branding-preview.instances-preview.img"
+ />
+ ) : (
+ <GlobeIcon weight="regular" data-flx="app.setup.setup-branding-preview.instances-preview.globe-icon" />
+ )}
+ </Hotspot>
+ <span
+ className={styles.instanceMeta}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-meta"
+ >
+ <span
+ className={styles.instanceName}
+ dir="auto"
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-name"
+ >
+ {brand.productName}
+ </span>
+ <span
+ className={styles.instanceHost}
+ dir="ltr"
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-host"
+ >
+ {brand.host}
+ </span>
+ </span>
+ </div>
+ {[0, 1].map((row) => (
+ <div
+ key={row}
+ className={clsx(styles.instanceRow, styles.instanceRowOther)}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-row--2"
+ >
+ <span
+ className={styles.instanceMark}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-mark"
+ >
+ <GlobeIcon weight="regular" data-flx="app.setup.setup-branding-preview.instances-preview.globe-icon--2" />
+ </span>
+ <span
+ className={styles.instanceMeta}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-meta--2"
+ >
+ <span
+ className={styles.instanceNameSkeleton}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-name-skeleton"
+ />
+ <span
+ className={styles.instanceHostSkeleton}
+ data-flx="app.setup.setup-branding-preview.instances-preview.instance-host-skeleton"
+ />
+ </span>
+ </div>
+ ))}
+ </div>
+ );
+}
+
+const TAB_CAPTIONS = {
+ sign_in: CAPTION_SIGN_IN_DESCRIPTOR,
+ phone: CAPTION_PHONE_DESCRIPTOR,
+ desktop: CAPTION_DESKTOP_DESCRIPTOR,
+ instances: CAPTION_INSTANCES_DESCRIPTOR,
+} as const;
+
+export function SetupBrandingPreview({
+ draft,
+ tab,
+ highlight,
+ caption,
+ onTabChange,
+ onTargetSelect,
+}: BrandingPreviewProps): React.ReactElement {
+ const {i18n} = useLingui();
+ const brand = useMemo(() => resolvePreviewBrand(draft), [draft]);
+ const tabs = useMemo(
+ () => [
+ {id: 'sign_in' as const, label: i18n._(TAB_SIGN_IN_DESCRIPTOR)},
+ {id: 'phone' as const, label: i18n._(TAB_PHONE_DESCRIPTOR)},
+ {id: 'desktop' as const, label: i18n._(TAB_DESKTOP_DESCRIPTOR)},
+ {id: 'instances' as const, label: i18n._(TAB_INSTANCES_DESCRIPTOR)},
+ ],
+ [i18n],
+ );
+ const scene = {brand, highlight, onSelect: onTargetSelect};
+ const tabsScrollerRef = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ tabsScrollerRef.current
+ ?.querySelector<HTMLElement>(`[role="radio"][aria-checked="true"]`)
+ ?.scrollIntoView({block: 'nearest', inline: 'nearest'});
+ }, [tab]);
+ const stageRef = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ const stage = stageRef.current;
+ if (!stage) return;
+ const keepFocus = (event: MouseEvent) => {
+ if (event.target instanceof Element && event.target.closest('[role="radio"]')) return;
+ event.preventDefault();
+ };
+ stage.addEventListener('mousedown', keepFocus);
+ return () => stage.removeEventListener('mousedown', keepFocus);
+ }, []);
+ return (
+ <div className={styles.preview} data-flx="app.setup.setup-branding-preview.preview">
+ <div
+ ref={tabsScrollerRef}
+ className={styles.tabsScroller}
+ data-flx="app.setup.setup-branding-preview.tabs-scroller"
+ >
+ <SegmentedTabs
+ tabs={tabs}
+ selectedTab={tab}
+ onTabChange={onTabChange}
+ ariaLabel={i18n._(PREVIEW_TABS_DESCRIPTOR)}
+ semantics="radio"
+ className={styles.tabs}
+ data-flx="app.setup.setup-branding-preview.tabs"
+ />
+ </div>
+ <div ref={stageRef} className={styles.stage} data-flx="app.setup.setup-branding-preview.stage">
+ <div
+ className={styles.scene}
+ aria-hidden={tab === 'desktop' ? undefined : true}
+ data-flx="app.setup.setup-branding-preview.scene"
+ >
+ {tab === 'sign_in' && (
+ <SignInPreview data-flx="app.setup.setup-branding-preview.sign-in-preview" {...scene} />
+ )}
+ {tab === 'phone' && <PhonePreview data-flx="app.setup.setup-branding-preview.phone-preview" {...scene} />}
+ {tab === 'desktop' && (
+ <DesktopPreview data-flx="app.setup.setup-branding-preview.desktop-preview" {...scene} />
+ )}
+ {tab === 'instances' && (
+ <InstancesPreview data-flx="app.setup.setup-branding-preview.instances-preview" {...scene} />
+ )}
+ </div>
+ </div>
+ <div className={styles.caption} data-flx="app.setup.setup-branding-preview.caption">
+ {caption ?? <p data-flx="app.setup.setup-branding-preview.p">{i18n._(TAB_CAPTIONS[tab])}</p>}
+ </div>
+ </div>
+ );
+}