make chips, and messages have the right formatting

This commit is contained in:
Shea Duma committed 2026-04-23 00:38:52 +03:00
1 parent 51d476672c
commit e32376b6d5
4 files changed
+241 -46

No files matched your search

+30 -5
View File
@@ -43,6 +43,7 @@ import { useRoomPermissions } from '$hooks/useRoomPermissions';
import { useMemberPowerCompare } from '$hooks/useMemberPowerCompare';
import { CutoutCard } from '$components/cutout-card';
import { PowerColorBadge, PowerIcon } from '$components/power';
import * as css from './styles.css';
type SelfDemoteAlertProps = {
power: number;
@@ -144,7 +145,19 @@ function SharedPowerAlert({ power, onCancel, onChange }: SharedPowerAlertProps)
);
}
export function PowerChip({ userId }: { userId: string }) {
export function PowerChip({
userId,
backgroundColor,
innerColor,
cardColor,
textColor,
}: {
userId: string;
backgroundColor?: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
}) {
const mx = useMatrixClient();
const room = useRoom();
const space = useSpaceOptionally();
@@ -239,7 +252,11 @@ export function PowerChip({ userId }: { userId: string }) {
<Box
direction="Column"
gap="100"
style={{ padding: config.space.S100, maxWidth: toRem(200) }}
style={{
padding: config.space.S100,
maxWidth: toRem(200),
backgroundColor: innerColor,
}}
>
{error && (
<CutoutCard style={{ padding: config.space.S200 }} variant="Critical">
@@ -268,6 +285,7 @@ export function PowerChip({ userId }: { userId: string }) {
radii="300"
aria-disabled={changing || !canChangePowers || !canAssignPower}
aria-pressed={selected}
style={{ backgroundColor: cardColor, color: textColor }}
before={<PowerColorBadge color={powerTag.color} />}
after={
powerTagIconSrc ? (
@@ -285,13 +303,14 @@ export function PowerChip({ userId }: { userId: string }) {
);
})}
</Box>
<Line size="300" />
<div style={{ padding: config.space.S100 }}>
<Line size="300" color={textColor} />
<div style={{ padding: config.space.S100, backgroundColor: innerColor }}>
<MenuItem
variant="Surface"
fill="None"
size="300"
radii="300"
style={{ backgroundColor: cardColor, color: textColor }}
onClick={() => {
if (room.isSpaceRoom()) {
openSpaceSettings(
@@ -317,8 +336,14 @@ export function PowerChip({ userId }: { userId: string }) {
}
>
<Chip
variant={error ? 'Critical' : 'SurfaceVariant'}
variant={error ? 'Critical' : undefined}
radii="Pill"
className={css.UserHeroChip}
style={{
backgroundColor: (!error && cardColor) || undefined,
borderColor: backgroundColor,
color: textColor,
}}
before={
cords ? (
<Icon size="50" src={Icons.ChevronBottom} />
+118 -26
View File
@@ -29,7 +29,6 @@ import {
Avatar,
} from 'folds';
import { useMatrixClient } from '$hooks/useMatrixClient';
import { getMxIdServer } from '$utils/matrix';
import { useCloseUserRoomProfile } from '$state/hooks/userRoomProfile';
import { stopPropagation } from '$utils/keyboard';
import { copyToClipboard } from '$utils/dom';
@@ -50,10 +49,21 @@ import { useNickname, useSetNickname } from '$hooks/useNickname';
import { CutoutCard } from '$components/cutout-card';
import { SettingTile } from '$components/setting-tile';
import { RoomAvatar, RoomIcon } from '$components/room-avatar';
import * as css from './styles.css';
export function ServerChip({ server }: { server: string }) {
const mx = useMatrixClient();
const myServer = getMxIdServer(mx.getSafeUserId());
export function ServerChip({
server,
innerColor,
cardColor,
textColor,
backgroundColor,
}: {
server: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
backgroundColor?: string;
}) {
const navigate = useNavigate();
const closeProfile = useCloseUserRoomProfile();
const [copied, setCopied] = useTimeoutToggle();
@@ -84,9 +94,14 @@ export function ServerChip({ server }: { server: string }) {
}}
>
<Menu>
<div style={{ padding: config.space.S100 }}>
<div
style={{
padding: config.space.S100,
maxWidth: toRem(200),
backgroundColor: innerColor,
}}
>
<MenuItem
variant="Surface"
fill="None"
size="300"
radii="300"
@@ -95,11 +110,11 @@ export function ServerChip({ server }: { server: string }) {
setCopied();
close();
}}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">Copy Server</Text>
</MenuItem>
<MenuItem
variant="Surface"
fill="None"
size="300"
radii="300"
@@ -107,14 +122,16 @@ export function ServerChip({ server }: { server: string }) {
navigate(getExploreServerPath(server));
closeProfile();
}}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">Explore Community</Text>
</MenuItem>
</div>
<Line size="300" />
<div style={{ padding: config.space.S100 }}>
<div
style={{ padding: config.space.S100, backgroundColor: cardColor, color: textColor }}
>
<MenuItem
variant={myServer === server ? 'Surface' : 'Critical'}
fill="None"
size="300"
radii="300"
@@ -122,6 +139,7 @@ export function ServerChip({ server }: { server: string }) {
window.open(`https://${server}`, '_blank');
close();
}}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">Open in Browser</Text>
</MenuItem>
@@ -131,7 +149,6 @@ export function ServerChip({ server }: { server: string }) {
}
>
<Chip
variant={myServer === server ? 'SurfaceVariant' : 'Warning'}
radii="Pill"
before={
cords ? (
@@ -142,6 +159,12 @@ export function ServerChip({ server }: { server: string }) {
}
onClick={open}
aria-pressed={!!cords}
className={css.UserHeroChip}
style={{
backgroundColor: cardColor,
borderColor: backgroundColor,
color: textColor,
}}
>
<Text size="B300" truncate>
{server}
@@ -151,7 +174,19 @@ export function ServerChip({ server }: { server: string }) {
);
}
export function ShareChip({ userId }: { userId: string }) {
export function ShareChip({
userId,
innerColor,
cardColor,
textColor,
backgroundColor,
}: {
userId: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
backgroundColor?: string;
}) {
const [cords, setCords] = useState<RectCords>();
const [copied, setCopied] = useTimeoutToggle();
@@ -180,12 +215,12 @@ export function ShareChip({ userId }: { userId: string }) {
}}
>
<Menu>
<div style={{ padding: config.space.S100 }}>
<div style={{ padding: config.space.S100, backgroundColor: innerColor }}>
<MenuItem
variant="Surface"
fill="None"
size="300"
radii="300"
style={{ backgroundColor: cardColor, color: textColor }}
onClick={() => {
copyToClipboard(userId);
setCopied();
@@ -195,10 +230,10 @@ export function ShareChip({ userId }: { userId: string }) {
<Text size="B300">Copy User ID</Text>
</MenuItem>
<MenuItem
variant="Surface"
fill="None"
size="300"
radii="300"
style={{ backgroundColor: cardColor, color: textColor }}
onClick={() => {
copyToClipboard(getMatrixToUser(userId));
setCopied();
@@ -213,7 +248,7 @@ export function ShareChip({ userId }: { userId: string }) {
}
>
<Chip
variant={copied ? 'Success' : 'SurfaceVariant'}
variant={copied ? 'Success' : undefined}
radii="Pill"
before={
cords ? (
@@ -224,6 +259,12 @@ export function ShareChip({ userId }: { userId: string }) {
}
onClick={open}
aria-pressed={!!cords}
className={css.UserHeroChip}
style={{
backgroundColor: (!copied && cardColor) || undefined,
borderColor: backgroundColor,
color: textColor,
}}
>
<Text size="B300" truncate>
Share
@@ -239,7 +280,19 @@ type MutualRoomsData = {
directs: Room[];
};
export function MutualRoomsChip({ userId }: { userId: string }) {
export function MutualRoomsChip({
userId,
backgroundColor,
innerColor,
cardColor,
textColor,
}: {
userId: string;
backgroundColor?: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
}) {
const mx = useMatrixClient();
const mutualRoomSupported = useMutualRoomsSupport();
const mutualRoomsState = useMutualRooms(userId);
@@ -305,7 +358,7 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
fill="None"
size="300"
radii="300"
style={{ paddingLeft: config.space.S100 }}
style={{ paddingLeft: config.space.S100, backgroundColor: cardColor, color: textColor }}
onClick={() => {
if (room.isSpaceRoom()) {
navigateSpace(roomId);
@@ -332,12 +385,17 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
)}
/>
) : (
<RoomIcon size="100" joinRule={room.getJoinRule()} roomType={room.getType()} />
<RoomIcon
size="100"
joinRule={room.getJoinRule()}
roomType={room.getType()}
style={{ color: textColor }}
/>
)}
</Avatar>
}
>
<Text size="B300" truncate>
<Text size="B300" truncate style={{ color: textColor }}>
{room.name}
</Text>
</MenuItem>
@@ -367,6 +425,7 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
display: 'flex',
maxWidth: toRem(200),
maxHeight: '80vh',
backgroundColor: innerColor,
}}
>
<Box grow="Yes">
@@ -374,7 +433,7 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
<Box
direction="Column"
gap="400"
style={{ padding: config.space.S200, paddingRight: 0 }}
style={{ padding: config.space.S200, paddingRight: 0, color: textColor }}
>
{mutual.spaces.length > 0 && (
<Box direction="Column" gap="100">
@@ -409,7 +468,6 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
}
>
<Chip
variant="SurfaceVariant"
radii="Pill"
before={mutualRoomsState.status === AsyncStatus.Loading && <Spinner size="50" />}
disabled={
@@ -417,8 +475,14 @@ export function MutualRoomsChip({ userId }: { userId: string }) {
}
onClick={open}
aria-pressed={!!cords}
className={css.UserHeroChip}
style={{
backgroundColor: cardColor,
borderColor: backgroundColor,
color: textColor,
}}
>
<Text size="B300">
<Text size="B300" style={{ color: textColor }}>
{mutualRoomsState.status === AsyncStatus.Success &&
`${mutualRoomsState.data.length} Mutual Rooms`}
{mutualRoomsState.status === AsyncStatus.Loading && 'Mutual Rooms'}
@@ -445,7 +509,19 @@ export function IgnoredUserAlert() {
);
}
export function OptionsChip({ userId }: { userId: string }) {
export function OptionsChip({
userId,
backgroundColor,
innerColor,
cardColor,
textColor,
}: {
userId: string;
backgroundColor?: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
}) {
const mx = useMatrixClient();
const [cords, setCords] = useState<RectCords>();
const [editingNick, setEditingNick] = useState(false);
@@ -510,7 +586,7 @@ export function OptionsChip({ userId }: { userId: string }) {
}}
>
<Menu>
<div style={{ padding: config.space.S100 }}>
<div style={{ padding: config.space.S100, backgroundColor: innerColor }}>
{editingNick ? (
<Box
direction="Column"
@@ -541,6 +617,7 @@ export function OptionsChip({ userId }: { userId: string }) {
variant="Success"
fill="None"
onClick={handleSaveNick}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">Save</Text>
</MenuItem>
@@ -554,6 +631,7 @@ export function OptionsChip({ userId }: { userId: string }) {
setNickname(userId, undefined);
close();
}}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">Clear</Text>
</MenuItem>
@@ -568,6 +646,7 @@ export function OptionsChip({ userId }: { userId: string }) {
radii="300"
before={<Icon size="50" src={Icons.Pencil} />}
onClick={() => setEditingNick(true)}
style={{ backgroundColor: cardColor, color: textColor }}
>
<Text size="B300">{currentNick ? 'Edit Nickname' : 'Set Nickname'}</Text>
</MenuItem>
@@ -581,6 +660,7 @@ export function OptionsChip({ userId }: { userId: string }) {
toggleIgnore();
close();
}}
style={{ backgroundColor: cardColor }}
before={
ignoring ? (
<Spinner variant="Critical" size="50" />
@@ -590,14 +670,26 @@ export function OptionsChip({ userId }: { userId: string }) {
}
disabled={ignoring}
>
<Text size="B300">{ignored ? 'Unblock User' : 'Block User'}</Text>
<Text size="B300" style={{ color: textColor }}>
{ignored ? 'Unblock User' : 'Block User'}
</Text>
</MenuItem>
</div>
</Menu>
</FocusTrap>
}
>
<Chip variant="SurfaceVariant" radii="Pill" onClick={open} aria-pressed={!!cords}>
<Chip
radii="Pill"
onClick={open}
aria-pressed={!!cords}
className={css.UserHeroChip}
style={{
backgroundColor: cardColor,
borderColor: backgroundColor,
color: textColor,
}}
>
{ignoring ? (
<Spinner variant="Secondary" size="50" />
) : (
@@ -74,6 +74,8 @@ type UserExtendedSectionProps = {
profile: UserProfile;
htmlReactParserOptions: HTMLReactParserOptions;
linkifyOpts: LinkifyOpts;
backgroundColor?: string;
innerColor?: string;
cardColor?: string;
textColor?: string;
};
@@ -82,6 +84,8 @@ function UserExtendedSection({
profile,
htmlReactParserOptions,
linkifyOpts,
backgroundColor,
innerColor,
cardColor,
textColor,
}: Readonly<UserExtendedSectionProps>) {
@@ -175,13 +179,24 @@ function UserExtendedSection({
return null;
}
return (
<Menu style={{ position: 'absolute', zIndex: '100', transform: `translateY(${toRem(32)})` }}>
<Menu
style={{
position: 'absolute',
zIndex: '100',
transform: `translateY(${toRem(32)})`,
backgroundColor: innerColor,
}}
>
<MenuItem
size="300"
radii="300"
fill="None"
variant="Primary"
style={{ justifyContent: 'Center', textAlign: 'center' }}
style={{
justifyContent: 'Center',
textAlign: 'center',
backgroundColor: cardColor,
color: textColor,
}}
onClick={() => handleMiscSelector(-1)}
>
<Icon src={Icons.ChevronTop} size="50" />
@@ -192,8 +207,7 @@ function UserExtendedSection({
size="300"
radii="300"
fill="None"
variant="Secondary"
style={{ justifyContent: 'Center' }}
style={{ justifyContent: 'Center', backgroundColor: cardColor, color: textColor }}
onClick={() => handleMiscSelector(index)}
>
<Text>{key}</Text>
@@ -201,7 +215,7 @@ function UserExtendedSection({
))}
</Menu>
);
}, [miscDataIndex, showMisc, unknownFields]);
}, [cardColor, innerColor, miscDataIndex, showMisc, textColor, unknownFields]);
const miscHeader = useMemo(
() => (
<Box justifyContent="Center" grow="Yes">
@@ -271,6 +285,9 @@ function UserExtendedSection({
style={{
backgroundColor: cardColor,
borderRadius: config.radii.R400,
borderColor: backgroundColor,
borderStyle: 'solid',
borderWidth: '1px',
maxHeight: '200px',
marginTop: config.space.S0,
overflowY: 'auto',
@@ -299,6 +316,7 @@ function UserExtendedSection({
backgroundColor: cardColor,
borderColor: 'var(--sable-surface-container-line)',
borderRadius: config.radii.R400,
borderWidth: '1px',
}}
>
<Box
@@ -311,7 +329,6 @@ function UserExtendedSection({
>
{unknownFields.length > 1 && (
<Button
variant="Secondary"
size="300"
fill="None"
onClick={() =>
@@ -319,6 +336,7 @@ function UserExtendedSection({
miscDataIndex === 0 ? unknownFields.length - 1 : miscDataIndex - 1
)
}
style={{ color: textColor }}
>
<Icon src={Icons.ArrowLeft} size="50" />
</Button>
@@ -326,16 +344,23 @@ function UserExtendedSection({
{miscHeader}
{unknownFields.length > 1 && (
<Button
variant="Secondary"
size="300"
fill="None"
onClick={() => setMiscDataIndex((miscDataIndex + 1) % unknownFields.length)}
style={{ color: textColor }}
>
<Icon src={Icons.ArrowRight} size="50" />
</Button>
)}
</Box>
<Scroll size="300" direction="Both">
<Scroll
size="300"
direction="Both"
style={{
backgroundColor: color.Background.Container,
color: color.Background.OnContainer,
}}
>
<Box
direction="Column"
style={{
@@ -509,7 +534,14 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
radii="300"
before={<Icon size="50" src={Icons.Message} filled />}
onClick={handleMessage}
style={{ marginLeft: 'auto' }}
style={{
marginLeft: 'auto',
backgroundColor: cardColor,
borderColor: backgroundColor,
color: textColor,
borderStyle: 'solid',
borderWidth: '1px',
}}
>
<Text size="B300">Message</Text>
</Button>
@@ -519,15 +551,57 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
profile={extendedProfile}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
<Box alignItems="Center" gap="100" wrap="Wrap" justifyContent="Center">
{server && <ServerChip server={server} />}
<ShareChip userId={userId} />
{creator ? <CreatorChip /> : <PowerChip userId={userId} />}
{userId !== myUserId && <MutualRoomsChip userId={userId} />}
{userId !== myUserId && <OptionsChip userId={userId} />}
{server && (
<ServerChip
server={server}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
)}
<ShareChip
userId={userId}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
{creator ? (
<CreatorChip />
) : (
<PowerChip
userId={userId}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
)}
{userId !== myUserId && (
<MutualRoomsChip
userId={userId}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
)}
{userId !== myUserId && (
<OptionsChip
userId={userId}
backgroundColor={backgroundColor}
innerColor={innerColor}
cardColor={cardColor}
textColor={textColor}
/>
)}
</Box>
</Box>
{ignored && <IgnoredUserAlert />}
@@ -78,3 +78,7 @@ export const UserHeroAvatarImg = style({
},
},
});
export const UserHeroChip = style({
borderStyle: 'solid',
borderWidth: '1px',
});