Skip to content

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

TypeScript fluxerfluxerapp

feat(app): add directional icons and RTL-aware placement

Hampus0b5eeb2be754
diff --git a/fluxer_app/src/app/I18n.ts b/fluxer_app/src/app/I18n.ts
index 5590b892a..ec0f8311a 100644
--- a/fluxer_app/src/app/I18n.ts
+++ b/fluxer_app/src/app/I18n.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {messages as messagesEnUS} from '@app/features/i18n/locales/en-US/messages.mjs';
+import {getLocaleDirection} from '@app/features/i18n/utils/LocaleDirection';
import {AppStorageKey} from '@app/features/platform/state/AppStorageKeys';
import AppStorage from '@app/features/platform/state/PersistentStorage';
import {getNativeLocaleIdentifier} from '@app/features/platform/types/Platform';
@@ -161,11 +162,17 @@ function detectPreferredLocale(forceLocale?: string): LocaleCode {
return DEFAULT_LOCALE;
}
+function applyDocumentLocale(localeCode: LocaleCode): void {
+ if (typeof document === 'undefined') {
+ return;
+ }
+ document.documentElement.lang = localeCode;
+ document.documentElement.dir = getLocaleDirection(localeCode);
+}
+
function activateLocale(localeCode: LocaleCode, messages: Messages): void {
i18n.loadAndActivate({locale: localeCode, messages});
- if (typeof document !== 'undefined') {
- document.documentElement.lang = localeCode;
- }
+ applyDocumentLocale(localeCode);
noteLocale(localeCode);
}
@@ -174,9 +181,7 @@ export function ensureActiveLocale(): void {
return;
}
i18n.loadAndActivate({locale: DEFAULT_LOCALE, messages: messagesEnUS});
- if (typeof document !== 'undefined') {
- document.documentElement.lang = DEFAULT_LOCALE;
- }
+ applyDocumentLocale(DEFAULT_LOCALE);
}
const inFlightLoads = new Map<LocaleCode, Promise<Messages>>();
diff --git a/fluxer_app/src/features/channel/components/pickers/shared/PickerCategoryHeaderRow.tsx b/fluxer_app/src/features/channel/components/pickers/shared/PickerCategoryHeaderRow.tsx
index baacfeed2..cafb2ef28 100644
--- a/fluxer_app/src/features/channel/components/pickers/shared/PickerCategoryHeaderRow.tsx
+++ b/fluxer_app/src/features/channel/components/pickers/shared/PickerCategoryHeaderRow.tsx
@@ -5,6 +5,7 @@ import type {PickerHeaderRow} from '@app/features/channel/components/pickers/sha
import {GuildIcon} from '@app/features/guild/components/popouts/GuildIcon';
import Guilds from '@app/features/guild/state/Guilds';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
+import {getCollapsedCaretAngle} from '@app/features/ui/icons/DirectionalIcons';
import {CaretDownIcon, ClockIcon, StarIcon} from '@phosphor-icons/react';
import type React from 'react';
export function PickerCategoryHeaderRow({
@@ -65,8 +66,7 @@ export function PickerCategoryHeaderRow({
height: remFromPx(PICKER_CATEGORY_HEADER_HEIGHT),
display: 'flex',
alignItems: 'center',
- paddingLeft: '0.75rem',
- paddingRight: '0.75rem',
+ paddingInline: '0.75rem',
marginBottom: '0.5rem',
position: 'sticky',
top: 0,
@@ -74,7 +74,7 @@ export function PickerCategoryHeaderRow({
cursor: 'pointer',
border: 'none',
width: '100%',
- textAlign: 'left',
+ textAlign: 'start',
gap: '0.5rem',
minWidth: 0,
}}
@@ -101,7 +101,7 @@ export function PickerCategoryHeaderRow({
<CaretDownIcon
weight="bold"
className={styles.caretIcon}
- style={{transform: `rotate(${isCollapsed ? -90 : 0}deg)`, marginLeft: '0.5rem'}}
+ style={{transform: `rotate(${isCollapsed ? getCollapsedCaretAngle() : 0}deg)`, marginInlineStart: '0.5rem'}}
data-flx="channel.emoji-picker.virtual-row.virtual-row-renderer.caret-icon"
/>
</div>
diff --git a/fluxer_app/src/features/theme/styles/Markup.module.css b/fluxer_app/src/features/theme/styles/Markup.module.css
index 8ae956b21..bf5be7975 100644
--- a/fluxer_app/src/features/theme/styles/Markup.module.css
+++ b/fluxer_app/src/features/theme/styles/Markup.module.css
@@ -16,7 +16,7 @@
white-space: break-spaces;
user-select: text;
-webkit-user-select: text;
- text-align: left;
+ text-align: start;
}
.bio {
@@ -191,6 +191,8 @@
.markup code.inline,
.inlineFormat code.inline {
display: inline;
+ direction: ltr;
+ unicode-bidi: isolate;
box-sizing: border-box;
max-width: 100%;
font-family: var(--font-mono);
@@ -264,6 +266,8 @@
}
.markup pre {
+ direction: ltr;
+ text-align: left;
font-family: var(--font-mono);
font-size: 0.75em;
line-height: 1.333333;
@@ -289,7 +293,7 @@
.markup .codeActions {
position: absolute;
top: 0.25rem;
- right: 0.25rem;
+ inset-inline-end: 0.25rem;
display: flex;
gap: 0.125rem;
opacity: 0;
@@ -343,7 +347,7 @@
border-radius: 0.25rem;
background-color: var(--interactive-muted);
flex-shrink: 0;
- margin-right: 0.75rem;
+ margin-inline-end: 0.75rem;
}
.markup .blockquoteContent {
@@ -418,13 +422,13 @@
word-wrap: break-word;
overflow-wrap: break-word;
min-inline-size: var(--message-compact-table-min-cell-width, 5rem);
- text-align: left;
+ text-align: start;
}
.markup .tableCell {
border-bottom: 0.0625rem solid var(--border-color);
padding: 0.5rem 0.75rem;
- text-align: left;
+ text-align: start;
background: var(--bg-table-row-odd);
vertical-align: middle;
line-height: 1.4;
@@ -448,7 +452,7 @@
}
.markup .alignLeft {
- text-align: left;
+ text-align: start;
}
.markup .alignCenter {
@@ -456,12 +460,13 @@
}
.markup .alignRight {
- text-align: right;
+ text-align: end;
}
.markup .alert {
position: relative;
- padding: 0.375rem 0.75rem 0.375rem 1rem;
+ padding-block: 0.375rem;
+ padding-inline: 1rem 0.75rem;
margin-top: 0.25rem;
border-radius: var(--radius-md);
background: transparent;
@@ -470,7 +475,7 @@
.markup .alert::before {
content: '';
position: absolute;
- left: 0;
+ inset-inline-start: 0;
top: 0;
bottom: 0;
width: 0.25rem;
@@ -482,7 +487,7 @@
display: inline-block;
width: 1em;
height: 1em;
- margin-right: 0.25rem;
+ margin-inline-end: 0.25rem;
vertical-align: text-bottom;
}
@@ -850,7 +855,7 @@
font-weight: 600;
font-size: inherit;
white-space: normal;
- padding-right: 0.75rem;
+ padding-inline-end: 0.75rem;
line-height: 1.25em;
color: inherit;
border: none;
@@ -868,20 +873,21 @@
.markup .inlineFormat ol {
display: inline;
margin: 0;
- padding: 0 0.5rem 0 0;
+ padding-block: 0;
+ padding-inline: 0 0.5rem;
}
.markup.inlineFormat li,
.markup .inlineFormat li {
display: inline;
margin: 0;
- padding-right: 0.5rem;
+ padding-inline-end: 0.5rem;
}
.markup.inlineFormat li:before,
.markup .inlineFormat li:before {
content: '•';
- padding-right: 0.25rem;
+ padding-inline-end: 0.25rem;
}
.markup.inlineFormat li li:before,
@@ -1113,7 +1119,7 @@
background-color: hsla(358, calc(85% * var(--saturation-factor)), 60%, 0.1);
border-radius: var(--radius-md);
margin: 0.25rem 0;
- border-left: 0.1875rem solid var(--accent-danger);
+ border-inline-start: 0.1875rem solid var(--accent-danger);
font-family: var(--font-mono);
font-size: 0.9em;
}
@@ -1147,7 +1153,8 @@
}
.markup .alert {
- padding: 0.375rem 0.5rem 0.375rem calc(0.5rem + 0.1875rem);
+ padding-block: 0.375rem;
+ padding-inline: calc(0.5rem + 0.1875rem) 0.5rem;
}
.markup .codeContainer {
diff --git a/fluxer_app/src/features/ui/action_menu/ContextMenuIcons.tsx b/fluxer_app/src/features/ui/action_menu/ContextMenuIcons.tsx
index 05ef2d222..28b9f287f 100644
--- a/fluxer_app/src/features/ui/action_menu/ContextMenuIcons.tsx
+++ b/fluxer_app/src/features/ui/action_menu/ContextMenuIcons.tsx
@@ -7,6 +7,10 @@ import {
ArrowBendUpRightIcon,
ArrowLeftIcon,
ArrowRightIcon,
+ CaretRightIcon,
+ getCollapsedCaretAngle,
+} from '@app/features/ui/icons/DirectionalIcons';
+import {
ArrowSquareOutIcon,
ArrowsClockwiseIcon,
AtIcon,
@@ -19,7 +23,6 @@ import {
CameraIcon,
CameraSlashIcon,
CaretDownIcon,
- CaretRightIcon,
CaretUpIcon,
ChatCircleIcon,
ChatsIcon,
@@ -770,7 +773,7 @@ export const CollapseCategoryIcon: React.FC<IconProps & {collapsed?: boolean}> =
<CaretDownIcon
size={remFromPx(size)}
weight="bold"
- style={{transform: collapsed ? 'rotate(-90deg)' : undefined}}
+ style={{transform: collapsed ? `rotate(${getCollapsedCaretAngle()}deg)` : undefined}}
data-flx="ui.action-menu.context-menu-icons.collapse-category-icon.caret-down-icon"
/>
),
diff --git a/fluxer_app/src/features/ui/components/Slider.module.css b/fluxer_app/src/features/ui/components/Slider.module.css
index 0d8142155..d61cdf214 100644
--- a/fluxer_app/src/features/ui/components/Slider.module.css
+++ b/fluxer_app/src/features/ui/components/Slider.module.css
@@ -65,13 +65,13 @@
.resetAccessory {
color: var(--text-muted);
font-size: 0.875rem;
- margin-left: auto;
+ margin-inline-start: auto;
}
@media (max-width: 480px) {
.resetAccessory {
flex-basis: 100%;
- margin-left: 0;
+ margin-inline-start: 0;
}
}
@@ -262,7 +262,7 @@
min-width: 1.5rem;
position: absolute;
top: 0;
- transform: translateX(-50%);
+ transform: translateX(calc(-50% * var(--slider-mark-direction, 1)));
user-select: none;
-webkit-user-select: none;
}
@@ -280,7 +280,11 @@
.markEndpointEnd {
align-items: flex-end;
- transform: translateX(-100%);
+ transform: translateX(calc(-100% * var(--slider-mark-direction, 1)));
+}
+
+:global(html[dir='rtl']) .mark {
+ --slider-mark-direction: -1;
}
.markValue {
diff --git a/fluxer_app/src/features/ui/components/Slider.tsx b/fluxer_app/src/features/ui/components/Slider.tsx
index 726b83fdb..676a9136f 100644
--- a/fluxer_app/src/features/ui/components/Slider.tsx
+++ b/fluxer_app/src/features/ui/components/Slider.tsx
@@ -287,7 +287,7 @@ export const Slider = React.forwardRef<HTMLDivElement, SliderProps>(
i === markerState.markerPositions.length - 1 && i !== 0 && styles.markEndpointEnd,
isFactoryDefaultValue && styles.defaultValue,
)}
- style={{left: `${position}%`}}
+ style={{insetInlineStart: `${position}%`}}
data-flx="ui.slider.mark"
>
<div className={styles.markValue} data-flx="ui.slider.mark-value">
diff --git a/fluxer_app/src/features/ui/components/SliderTooltip.module.css b/fluxer_app/src/features/ui/components/SliderTooltip.module.css
index f5643b2b6..1fffcc912 100644
--- a/fluxer_app/src/features/ui/components/SliderTooltip.module.css
+++ b/fluxer_app/src/features/ui/components/SliderTooltip.module.css
@@ -47,6 +47,7 @@
border-right: var(--slider-tooltip-border-width) solid var(--slider-tooltip-border);
border-bottom: var(--slider-tooltip-border-width) solid var(--slider-tooltip-border);
transform: rotate(45deg);
+ clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
.tooltipContent {
diff --git a/fluxer_app/src/features/ui/icons/DirectionalIcons.module.css b/fluxer_app/src/features/ui/icons/DirectionalIcons.module.css
new file mode 100644
index 000000000..b02e30757
--- /dev/null
+++ b/fluxer_app/src/features/ui/icons/DirectionalIcons.module.css
@@ -0,0 +1,3 @@
+:global(html[dir='rtl']) .mirrored {
+ scale: -1 1;
+}
diff --git a/fluxer_app/src/features/ui/icons/DirectionalIcons.tsx b/fluxer_app/src/features/ui/icons/DirectionalIcons.tsx
new file mode 100644
index 000000000..350f73e1c
--- /dev/null
+++ b/fluxer_app/src/features/ui/icons/DirectionalIcons.tsx
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import styles from '@app/features/ui/icons/DirectionalIcons.module.css';
+import {
+ ArrowBendUpLeftIcon as BaseArrowBendUpLeftIcon,
+ ArrowBendUpRightIcon as BaseArrowBendUpRightIcon,
+ ArrowLeftIcon as BaseArrowLeftIcon,
+ ArrowRightIcon as BaseArrowRightIcon,
+ CaretLeftIcon as BaseCaretLeftIcon,
+ CaretRightIcon as BaseCaretRightIcon,
+ type Icon,
+ type IconProps,
+} from '@phosphor-icons/react';
+import {clsx} from 'clsx';
+import {forwardRef} from 'react';
+
+function mirrorInRtl(BaseIcon: Icon): Icon {
+ const MirroredIcon = forwardRef<SVGSVGElement, IconProps>(({className, ...props}, ref) => (
+ <BaseIcon
+ ref={ref}
+ className={clsx(styles.mirrored, className)}
+ data-flx="ui.icons.directional-icons.mirrored-icon.mirrored"
+ {...props}
+ />
+ ));
+ MirroredIcon.displayName = BaseIcon.displayName;
+ return MirroredIcon;
+}
+
+export const ArrowBendUpLeftIcon = mirrorInRtl(BaseArrowBendUpLeftIcon);
+export const ArrowBendUpRightIcon = mirrorInRtl(BaseArrowBendUpRightIcon);
+export const ArrowLeftIcon = mirrorInRtl(BaseArrowLeftIcon);
+export const ArrowRightIcon = mirrorInRtl(BaseArrowRightIcon);
+export const CaretLeftIcon = mirrorInRtl(BaseCaretLeftIcon);
+export const CaretRightIcon = mirrorInRtl(BaseCaretRightIcon);
+
+export function getCollapsedCaretAngle(): number {
+ return document.documentElement.dir === 'rtl' ? 90 : -90;
+}
diff --git a/fluxer_app/src/features/ui/popover/PopoverPopouts.tsx b/fluxer_app/src/features/ui/popover/PopoverPopouts.tsx
index 05ad72947..097377261 100644
--- a/fluxer_app/src/features/ui/popover/PopoverPopouts.tsx
+++ b/fluxer_app/src/features/ui/popover/PopoverPopouts.tsx
@@ -14,6 +14,7 @@ import {observePopoutKeyboardDismiss, resolvePopoutReturnFocus} from '@app/featu
import KeyboardMode from '@app/features/ui/state/KeyboardMode';
import LayerManager from '@app/features/ui/state/LayerManager';
import PopoutState from '@app/features/ui/state/Popout';
+import {toDocumentPlacement} from '@app/features/ui/utils/DocumentPlacement';
import {isScrollbarDragActive} from '@app/features/ui/utils/ScrollbarDragState';
import {canUseWindowFocusedHoverControls} from '@app/features/ui/utils/WindowFocusInteractionGuard';
import {wasPointerDownInside} from '@app/lib/overlay/DismissGuard';
@@ -193,7 +194,7 @@ const PopoutItem: React.FC<PopoutItemProps> = observer(
style,
beginManualPositioning,
} = useAntiShiftFloating(positionReference, {
- placement: position,
+ placement: toDocumentPlacement(position, target),
offsetMainAxis,
offsetCrossAxis,
shouldAutoUpdate: frozenTargetRect ? false : shouldAutoUpdate,
diff --git a/fluxer_app/src/features/ui/tooltip/Tooltip.module.css b/fluxer_app/src/features/ui/tooltip/Tooltip.module.css
index 6b5ec4559..53521382c 100644
--- a/fluxer_app/src/features/ui/tooltip/Tooltip.module.css
+++ b/fluxer_app/src/features/ui/tooltip/Tooltip.module.css
@@ -126,24 +126,28 @@
border-right: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
border-bottom: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
background: var(--tooltip-pointer-surface);
+ clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
.tooltipBottom .tooltipPointer.tooltipPointerBg {
border-top: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
border-left: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
background: var(--tooltip-pointer-surface);
+ clip-path: polygon(0 0, 100% 0, 0 100%);
}
.tooltipLeft .tooltipPointer.tooltipPointerBg {
border-top: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
border-right: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
background: var(--tooltip-pointer-surface);
+ clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.tooltipRight .tooltipPointer.tooltipPointerBg {
border-bottom: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
border-left: var(--tooltip-border-width) solid var(--tooltip-pointer-border);
background: var(--tooltip-pointer-surface);
+ clip-path: polygon(0 0, 100% 100%, 0 100%);
}
.tooltipRed {
diff --git a/fluxer_app/src/features/ui/tooltip/Tooltip.tsx b/fluxer_app/src/features/ui/tooltip/Tooltip.tsx
index 30fd8300e..72a9ef3c6 100644
--- a/fluxer_app/src/features/ui/tooltip/Tooltip.tsx
+++ b/fluxer_app/src/features/ui/tooltip/Tooltip.tsx
@@ -26,6 +26,7 @@ import {
transitionTooltipSnapshot,
} from '@app/features/ui/tooltip/TooltipStateMachine';
import {appZoomCssPx, appZoomLayoutPx} from '@app/features/ui/utils/AppZoomUtils';
+import {toDocumentPlacement} from '@app/features/ui/utils/DocumentPlacement';
import {getReducedMotionProps, TOOLTIP_MOTION} from '@app/features/ui/utils/ReducedMotionAnimation';
import {
canUseWindowFocusedHoverControls,
@@ -417,7 +418,7 @@ export const Tooltip = observer(
...(arrowRef.current ? [arrow({element: arrowRef.current})] : []),
];
const {x, y, placement, middlewareData} = await computePosition(target, tooltip, {
- placement: position,
+ placement: toDocumentPlacement(position, target),
strategy: 'fixed',
middleware,
});
diff --git a/fluxer_app/src/features/ui/utils/DocumentPlacement.ts b/fluxer_app/src/features/ui/utils/DocumentPlacement.ts
new file mode 100644
index 000000000..34453df85
--- /dev/null
+++ b/fluxer_app/src/features/ui/utils/DocumentPlacement.ts
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {Placement} from '@floating-ui/react-dom';
+
+const MIRRORED_SIDE: Record<string, string> = {left: 'right', right: 'left'};
+
+export function toDocumentPlacement<T extends Placement>(placement: T, element: Element | null | undefined): T {
+ const root =
+ element?.ownerDocument?.documentElement ?? (typeof document === 'undefined' ? null : document.documentElement);
+ if (root?.dir !== 'rtl') {
+ return placement;
+ }
+ const [side, align] = placement.split('-');
+ const mirrored = MIRRORED_SIDE[side];
+ if (!mirrored) {
+ return placement;
+ }
+ return (align ? `${mirrored}-${align}` : mirrored) as T;
+}