mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
7 files changed
+123
-109
No files matched your search
Vendored
+2
-1
@@ -26,5 +26,6 @@
|
||||
".env": ".env.*",
|
||||
"flake.nix": "flake.lock",
|
||||
".gitattributes": ".gitignore"
|
||||
}
|
||||
},
|
||||
"i18n-ally.localesPaths": ["public/locales"]
|
||||
}
|
||||
@@ -445,31 +445,35 @@ export function MImage({ content, renderImageContent, outlined, fitParent }: MIm
|
||||
if (!mxcUrl) {
|
||||
return <BrokenContent body={content.body ?? content.filename} />;
|
||||
}
|
||||
const MIN_SIZE = 150;
|
||||
const MAX_SIZE = 400;
|
||||
const imgW = imgInfo?.w ?? MAX_SIZE;
|
||||
const imgH = imgInfo?.h ?? MAX_SIZE;
|
||||
const aspectRatio = imgInfo?.w && imgInfo?.h ? `${imgW} / ${imgH}` : undefined;
|
||||
// this garbage is for portrait images, we cap the width so the card doesn't exceed the bounds of the image
|
||||
const displayWidth = imgH > imgW ? Math.round(MAX_SIZE * (imgW / imgH)) : MAX_SIZE;
|
||||
const height = scaleYDimension(imgInfo?.w || 400, displayWidth, imgInfo?.h || 400);
|
||||
const filename = getAttachmentFilename(content.filename, content.body, 'Image');
|
||||
|
||||
// lazy approach to make sure that both horizontal and vertical images fit
|
||||
// checks whether the image has width and height and if it does it sets a width that matches the aspect ratio
|
||||
const portraitWidth =
|
||||
!imgInfo || !imgInfo.w || !imgInfo.h || imgInfo.w > imgInfo.h
|
||||
? undefined
|
||||
: toRem((MAX_SIZE * imgInfo.w) / imgInfo.h);
|
||||
|
||||
return (
|
||||
<Attachment
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
flexShrink: 0,
|
||||
width: fitParent ? '100%' : toRem(displayWidth),
|
||||
height: fitParent ? '100%' : 'auto',
|
||||
width: fitParent ? '100%' : portraitWidth,
|
||||
height: fitParent ? '100%' : undefined,
|
||||
maxWidth: fitParent ? undefined : toRem(MAX_SIZE),
|
||||
maxHeight: fitParent ? undefined : toRem(MAX_SIZE),
|
||||
minWidth: fitParent ? undefined : MIN_SIZE,
|
||||
minHeight: fitParent ? undefined : MIN_SIZE,
|
||||
}}
|
||||
outlined={outlined}
|
||||
>
|
||||
<AttachmentBox
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
aspectRatio: fitParent ? undefined : aspectRatio,
|
||||
width: fitParent ? '100%' : toRem(displayWidth),
|
||||
height: fitParent ? '100%' : toRem(height < 48 ? 48 : height),
|
||||
width: fitParent ? '100%' : portraitWidth,
|
||||
height: fitParent ? '100%' : undefined,
|
||||
}}
|
||||
>
|
||||
{renderImageContent({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import type { CSSProperties, ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Badge,
|
||||
@@ -91,6 +91,7 @@ type RenderImageProps = {
|
||||
onLottieError: () => void;
|
||||
onClick: () => void;
|
||||
tabIndex: number;
|
||||
style?: CSSProperties;
|
||||
};
|
||||
export type ImageContentProps = {
|
||||
body?: string;
|
||||
@@ -317,6 +318,7 @@ export const ImageContent = as<'div', ImageContentProps>(
|
||||
title: body ?? '',
|
||||
src: srcState.data,
|
||||
info,
|
||||
style: { objectFit: isContained ? 'contain' : undefined },
|
||||
onLoad: handleLoad,
|
||||
onError: handleError,
|
||||
onLottieLoad: handleLoad,
|
||||
|
||||
@@ -93,34 +93,91 @@ export function ThemePreviewCard({
|
||||
>
|
||||
<Box direction="Row" alignItems="Start" justifyContent="SpaceBetween" gap="200">
|
||||
<Box direction="Column" gap="100" grow="Yes">
|
||||
<Box direction="Row" gap="100" alignItems="Center" wrap="Wrap">
|
||||
<Text size="H6">{title}</Text>
|
||||
{thirdParty && (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
tooltip={
|
||||
<Tooltip style={{ maxWidth: toRem(280) }}>
|
||||
<Text size="T200">
|
||||
Third-party theme. Only use themes from Providers you trust.
|
||||
</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(triggerRef) => (
|
||||
<span
|
||||
ref={triggerRef}
|
||||
aria-label="Third-party theme"
|
||||
style={{
|
||||
color: 'var(--sable-warn-on-container)',
|
||||
flexShrink: 0,
|
||||
display: 'inline-flex',
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Warning, '100', { filled: true })}
|
||||
</span>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
)}
|
||||
<Box direction="Row" alignItems="Center" justifyContent="SpaceBetween">
|
||||
<Box gap="100" wrap="Wrap">
|
||||
<Text size="H6">{title}</Text>
|
||||
{thirdParty && (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
tooltip={
|
||||
<Tooltip style={{ maxWidth: toRem(280) }}>
|
||||
<Text size="T200">
|
||||
Third-party theme. Only use themes from Providers you trust.
|
||||
</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(triggerRef) => (
|
||||
<span
|
||||
ref={triggerRef}
|
||||
aria-label="Third-party theme"
|
||||
style={{
|
||||
color: 'var(--sable-warn-on-container)',
|
||||
flexShrink: 0,
|
||||
display: 'inline-flex',
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Warning, '100', { filled: true })}
|
||||
</span>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
)}
|
||||
</Box>
|
||||
<Box gap="100" shrink="No">
|
||||
<CssViewerButton
|
||||
title={`${title} — CSS`}
|
||||
cssText={fullCssText}
|
||||
loadCssText={loadFullCssText}
|
||||
ariaLabel="View theme CSS"
|
||||
/>
|
||||
{copyText && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label={copied ? 'Copied theme link' : 'Copy theme link'}
|
||||
onClick={() => {
|
||||
handleCopy().catch(() => undefined);
|
||||
}}
|
||||
>
|
||||
{sizedIcon(copied ? Check : Link, '200')}
|
||||
</IconButton>
|
||||
)}
|
||||
|
||||
{onExport && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label="Export theme CSS"
|
||||
onClick={() => {
|
||||
onExport();
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Download, '200')}
|
||||
</IconButton>
|
||||
)}
|
||||
|
||||
{typeof isFavorited === 'boolean' && onToggleFavorite && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant={isFavorited ? 'Primary' : 'Secondary'}
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label={isFavorited ? 'Remove from saved' : 'Save theme'}
|
||||
onClick={() => {
|
||||
Promise.resolve(onToggleFavorite()).catch(() => undefined);
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Star, '200', { filled: isFavorited })}
|
||||
</IconButton>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
{subtitle && (
|
||||
<Text size="T200" priority="300" style={{ wordBreak: 'break-word' }}>
|
||||
@@ -133,62 +190,6 @@ export function ThemePreviewCard({
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Box direction="Row" gap="100" alignItems="Center" shrink="No">
|
||||
<CssViewerButton
|
||||
title={`${title} — CSS`}
|
||||
cssText={fullCssText}
|
||||
loadCssText={loadFullCssText}
|
||||
ariaLabel="View theme CSS"
|
||||
/>
|
||||
{copyText && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label={copied ? 'Copied theme link' : 'Copy theme link'}
|
||||
onClick={() => {
|
||||
handleCopy().catch(() => undefined);
|
||||
}}
|
||||
>
|
||||
{sizedIcon(copied ? Check : Link, '200')}
|
||||
</IconButton>
|
||||
)}
|
||||
|
||||
{onExport && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label="Export theme CSS"
|
||||
onClick={() => {
|
||||
onExport();
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Download, '200')}
|
||||
</IconButton>
|
||||
)}
|
||||
|
||||
{typeof isFavorited === 'boolean' && onToggleFavorite && (
|
||||
<IconButton
|
||||
size="300"
|
||||
variant={isFavorited ? 'Primary' : 'Secondary'}
|
||||
fill="Soft"
|
||||
outlined
|
||||
radii="300"
|
||||
aria-label={isFavorited ? 'Remove from saved' : 'Save theme'}
|
||||
onClick={() => {
|
||||
Promise.resolve(onToggleFavorite()).catch(() => undefined);
|
||||
}}
|
||||
>
|
||||
{sizedIcon(Star, '200', { filled: isFavorited })}
|
||||
</IconButton>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{beforePreview}
|
||||
|
||||
@@ -185,7 +185,8 @@ export function UserHero({
|
||||
maxHeight: isFullStatus ? toRem(105) : toRem(48),
|
||||
cursor: allowEditing || isExpandable ? 'pointer' : 'default',
|
||||
display: 'flex',
|
||||
width: allowEditing ? '100%' : 'fit-content',
|
||||
width: allowEditing && !status ? '100%' : 'fit-content',
|
||||
textAlign: 'center',
|
||||
padding: `${toRem(8)} ${toRem(12)}`,
|
||||
backgroundColor: statusSurfaceColor,
|
||||
color: textColor,
|
||||
|
||||
@@ -105,6 +105,7 @@ export function ProfileMobile() {
|
||||
radii="300"
|
||||
before={menuIcon(PencilSimpleIcon)}
|
||||
onClick={() => openSettings('account')}
|
||||
style={{ background: color.Background.Container }}
|
||||
>
|
||||
<Text style={{ flexGrow: 1 }} size="T300">
|
||||
Edit profile
|
||||
|
||||
@@ -273,11 +273,13 @@ export function AccountMenuOption({ isMobile, isRight }: { isMobile: boolean; is
|
||||
after={isOpen && isMobile ? menuIcon(CaretDownIcon) : menuIcon(CaretRightIcon)}
|
||||
style={{
|
||||
position: 'relative',
|
||||
background: isOpen
|
||||
? isMobile
|
||||
? color.Surface.Container
|
||||
: color.Surface.ContainerHover
|
||||
: color.Background.Container,
|
||||
background: isMobile
|
||||
? isOpen
|
||||
? color.Background.ContainerHover
|
||||
: color.Background.Container
|
||||
: isOpen
|
||||
? color.Surface.ContainerHover
|
||||
: color.Surface.Container,
|
||||
}}
|
||||
onClick={() => isMobile && setIsOpen(!isOpen)}
|
||||
{...hoverProps}
|
||||
@@ -487,11 +489,13 @@ export function PresenceMenuOption({
|
||||
after={isOpen && isMobile ? menuIcon(CaretDownIcon) : menuIcon(CaretRightIcon)}
|
||||
style={{
|
||||
position: 'relative',
|
||||
background: isOpen
|
||||
? isMobile
|
||||
? color.Surface.Container
|
||||
: color.Surface.ContainerHover
|
||||
: color.Background.Container,
|
||||
background: isMobile
|
||||
? isOpen
|
||||
? color.Background.ContainerHover
|
||||
: color.Background.Container
|
||||
: isOpen
|
||||
? color.Surface.ContainerHover
|
||||
: color.Surface.Container,
|
||||
}}
|
||||
onClick={() => isMobile && setIsOpen(!isOpen)}
|
||||
{...hoverProps}
|
||||
|
||||
Reference in new issue
Block a user