Skip to content

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

TypeScript fluxerfluxerapp

feat(app): mirror profile banner cutouts in RTL layouts

Hampus653aefcb36e2
diff --git a/fluxer_app/src/features/user/components/modals/user_profile_modal/ProfileMediaHeader.tsx b/fluxer_app/src/features/user/components/modals/user_profile_modal/ProfileMediaHeader.tsx
index 72505b272..f1538d38a 100644
--- a/fluxer_app/src/features/user/components/modals/user_profile_modal/ProfileMediaHeader.tsx
+++ b/fluxer_app/src/features/user/components/modals/user_profile_modal/ProfileMediaHeader.tsx
@@ -18,10 +18,12 @@ import {
type ProfileMediaHeaderProps,
} from '@app/features/user/components/modals/user_profile_modal/UserProfileModalShared';
import {
+ getBannerCutoutCx,
PROFILE_MODAL_BANNER_AVATAR_CUTOUT,
PROFILE_MODAL_GEOMETRY,
PROFILE_MODAL_GEOMETRY_STYLE,
} from '@app/features/user/constants/UserProfileSurfaceGeometry';
+import {useDirection} from '@base-ui/react/direction-provider';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
@@ -63,6 +65,7 @@ export const ProfileMediaHeader: React.FC<ProfileMediaHeaderProps> = observer(
const reactId = useId();
const safeId = reactId.replace(/[^a-zA-Z0-9_-]/g, '');
const maskId = `uid_${safeId}`;
+ const direction = useDirection();
const {
hoverRef: bannerHoverRef,
imageUrl: activeBannerUrl,
@@ -176,7 +179,7 @@ export const ProfileMediaHeader: React.FC<ProfileMediaHeaderProps> = observer(
/>
<circle
fill="black"
- cx={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.cx}
+ cx={getBannerCutoutCx(PROFILE_MODAL_BANNER_AVATAR_CUTOUT, direction)}
cy={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.cy}
r={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.r}
data-flx="user.user-profile-modal.profile-media-header.circle"
diff --git a/fluxer_app/src/features/user/components/profile/UserProfileLoadingSkeleton.tsx b/fluxer_app/src/features/user/components/profile/UserProfileLoadingSkeleton.tsx
index b5bd85458..05ded7911 100644
--- a/fluxer_app/src/features/user/components/profile/UserProfileLoadingSkeleton.tsx
+++ b/fluxer_app/src/features/user/components/profile/UserProfileLoadingSkeleton.tsx
@@ -4,11 +4,13 @@ import Accessibility from '@app/features/accessibility/state/Accessibility';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import styles from '@app/features/user/components/profile/UserProfileLoadingSkeleton.module.css';
import {
+ getBannerCutoutCx,
PROFILE_MODAL_BANNER_AVATAR_CUTOUT,
PROFILE_MODAL_GEOMETRY_STYLE,
PROFILE_POPOUT_BANNER_AVATAR_CUTOUT,
PROFILE_POPOUT_GEOMETRY_STYLE,
} from '@app/features/user/constants/UserProfileSurfaceGeometry';
+import {useDirection} from '@base-ui/react/direction-provider';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {clsx} from 'clsx';
@@ -31,89 +33,95 @@ interface UserProfileLoadingSkeletonProps {
[themeAttr: `data-flx${string}`]: string | undefined;
}
-const PopoutBannerMask: React.FC<{maskId: string}> = ({maskId}) => (
- <svg
- className={styles.bannerMask}
- viewBox={`0 0 ${PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxWidthPx} ${PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}`}
- preserveAspectRatio="none"
- aria-hidden
- data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.banner-mask"
- >
- <mask id={maskId} data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.mask">
- <rect
- fill="white"
+const PopoutBannerMask: React.FC<{maskId: string}> = ({maskId}) => {
+ const direction = useDirection();
+ return (
+ <svg
+ className={styles.bannerMask}
+ viewBox={`0 0 ${PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxWidthPx} ${PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}`}
+ preserveAspectRatio="none"
+ aria-hidden
+ data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.banner-mask"
+ >
+ <mask id={maskId} data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.mask">
+ <rect
+ fill="white"
+ x="0"
+ y="0"
+ width={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
+ height={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
+ data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.rect"
+ />
+ <circle
+ fill="black"
+ cx={getBannerCutoutCx(PROFILE_POPOUT_BANNER_AVATAR_CUTOUT, direction)}
+ cy={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.cy}
+ r={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.r}
+ data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.circle"
+ />
+ </mask>
+ <foreignObject
x="0"
y="0"
width={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
height={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
- data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.rect"
- />
- <circle
- fill="black"
- cx={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.cx}
- cy={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.cy}
- r={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.r}
- data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.circle"
- />
- </mask>
- <foreignObject
- x="0"
- y="0"
- width={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
- height={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
- overflow="visible"
- mask={`url(#${maskId})`}
- data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.foreign-object"
- >
- <div
- className={styles.bannerFill}
- data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.banner-fill"
- />
- </foreignObject>
- </svg>
-);
+ overflow="visible"
+ mask={`url(#${maskId})`}
+ data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.foreign-object"
+ >
+ <div
+ className={styles.bannerFill}
+ data-flx="user.profile.user-profile-loading-skeleton.popout-banner-mask.banner-fill"
+ />
+ </foreignObject>
+ </svg>
+ );
+};
-const ModalBannerMask: React.FC<{maskId: string}> = ({maskId}) => (
- <svg
- className={styles.bannerMask}
- viewBox={`0 0 ${PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxWidthPx} ${PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}`}
- preserveAspectRatio="none"
- aria-hidden
- data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.banner-mask"
- >
- <mask id={maskId} data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.mask">
- <rect
- fill="white"
+const ModalBannerMask: React.FC<{maskId: string}> = ({maskId}) => {
+ const direction = useDirection();
+ return (
+ <svg
+ className={styles.bannerMask}
+ viewBox={`0 0 ${PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxWidthPx} ${PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}`}
+ preserveAspectRatio="none"
+ aria-hidden
+ data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.banner-mask"
+ >
+ <mask id={maskId} data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.mask">
+ <rect
+ fill="white"
+ x="0"
+ y="0"
+ width={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
+ height={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
+ data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.rect"
+ />
+ <circle
+ fill="black"
+ cx={getBannerCutoutCx(PROFILE_MODAL_BANNER_AVATAR_CUTOUT, direction)}
+ cy={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.cy}
+ r={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.r}
+ data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.circle"
+ />
+ </mask>
+ <foreignObject
x="0"
y="0"
width={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
height={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
- data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.rect"
- />
- <circle
- fill="black"
- cx={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.cx}
- cy={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.cy}
- r={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.r}
- data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.circle"
- />
- </mask>
- <foreignObject
- x="0"
- y="0"
- width={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxWidthPx}
- height={PROFILE_MODAL_BANNER_AVATAR_CUTOUT.viewBoxHeightPx}
- overflow="visible"
- mask={`url(#${maskId})`}
- data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.foreign-object"
- >
- <div
- className={styles.bannerFill}
- data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.banner-fill"
- />
- </foreignObject>
- </svg>
-);
+ overflow="visible"
+ mask={`url(#${maskId})`}
+ data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.foreign-object"
+ >
+ <div
+ className={styles.bannerFill}
+ data-flx="user.profile.user-profile-loading-skeleton.modal-banner-mask.banner-fill"
+ />
+ </foreignObject>
+ </svg>
+ );
+};
const SkeletonLine: React.FC<{className?: string}> = ({className}) => (
<div
diff --git a/fluxer_app/src/features/user/components/profile/profile_card/ProfileCardBanner.tsx b/fluxer_app/src/features/user/components/profile/profile_card/ProfileCardBanner.tsx
index 814cb00dc..1672049fd 100644
--- a/fluxer_app/src/features/user/components/profile/profile_card/ProfileCardBanner.tsx
+++ b/fluxer_app/src/features/user/components/profile/profile_card/ProfileCardBanner.tsx
@@ -7,10 +7,12 @@ import {StatusAwareAvatar} from '@app/features/ui/components/StatusAwareAvatar';
import FocusRing from '@app/features/ui/focus_ring/FocusRing';
import styles from '@app/features/user/components/profile/profile_card/ProfileCardBanner.module.css';
import {
+ getBannerCutoutCx,
PROFILE_POPOUT_BANNER_AVATAR_CUTOUT,
PROFILE_POPOUT_GEOMETRY,
} from '@app/features/user/constants/UserProfileSurfaceGeometry';
import type {User} from '@app/features/user/models/User';
+import {useDirection} from '@base-ui/react/direction-provider';
import {observer} from 'mobx-react-lite';
import type React from 'react';
import {useId, useMemo} from 'react';
@@ -47,6 +49,7 @@ export const ProfileCardBanner: React.FC<ProfileCardBannerProps> = observer(
const reactId = useId();
const safeId = reactId.replace(/[^a-zA-Z0-9_-]/g, '');
const maskId = `uid_${safeId}`;
+ const direction = useDirection();
const headerStyle = useMemo<React.CSSProperties>(
() => ({height: remFromPx(PROFILE_POPOUT_GEOMETRY.headerHeightPx)}),
[],
@@ -103,7 +106,7 @@ export const ProfileCardBanner: React.FC<ProfileCardBannerProps> = observer(
/>
<circle
fill="black"
- cx={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.cx}
+ cx={getBannerCutoutCx(PROFILE_POPOUT_BANNER_AVATAR_CUTOUT, direction)}
cy={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.cy}
r={PROFILE_POPOUT_BANNER_AVATAR_CUTOUT.r}
data-flx="user.profile.profile-card.profile-card-banner.circle"
diff --git a/fluxer_app/src/features/user/constants/UserProfileSurfaceGeometry.ts b/fluxer_app/src/features/user/constants/UserProfileSurfaceGeometry.ts
index b1fe13506..40a8072c1 100644
--- a/fluxer_app/src/features/user/constants/UserProfileSurfaceGeometry.ts
+++ b/fluxer_app/src/features/user/constants/UserProfileSurfaceGeometry.ts
@@ -51,6 +51,13 @@ export const PROFILE_MODAL_BANNER_AVATAR_CUTOUT = {
cy: PROFILE_MODAL_GEOMETRY.bannerViewBoxHeightPx,
r: PROFILE_MODAL_AVATAR_OUTER_RADIUS_PX,
} as const;
+export function getBannerCutoutCx(
+ cutout: {readonly viewBoxWidthPx: number; readonly cx: number},
+ direction: 'ltr' | 'rtl',
+): number {
+ return direction === 'rtl' ? cutout.viewBoxWidthPx - cutout.cx : cutout.cx;
+}
+
export const PROFILE_POPOUT_GEOMETRY_STYLE: CssLengthVariables = {
'--profile-popout-content-width': remFromPx(PROFILE_POPOUT_GEOMETRY.contentWidthPx),
'--profile-popout-content-height': remFromPx(PROFILE_POPOUT_GEOMETRY.contentHeightPx),