TootAuthorGroup: remove css module
This commit is contained in:
parent
edfbf5505b
commit
f56b92fff0
3 changed files with 66 additions and 59 deletions
|
@ -10,23 +10,19 @@ import {
|
||||||
createContext,
|
createContext,
|
||||||
useContext,
|
useContext,
|
||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import tootStyle from "./toot.module.css";
|
|
||||||
import { formatRelative } from "date-fns";
|
|
||||||
import Img from "~material/Img.js";
|
|
||||||
import { Body2 } from "~material/typography.js";
|
import { Body2 } from "~material/typography.js";
|
||||||
import { SmartToySharp, Lock } from "@suid/icons-material";
|
|
||||||
import { useTimeSource } from "~platform/timesrc.js";
|
import { useTimeSource } from "~platform/timesrc.js";
|
||||||
import { resolveCustomEmoji } from "../masto/toot.js";
|
import { resolveCustomEmoji } from "../masto/toot.js";
|
||||||
import { Divider } from "@suid/material";
|
import { Divider } from "@suid/material";
|
||||||
import cardStyle from "~material/cards.module.css";
|
import cardStyle from "~material/cards.module.css";
|
||||||
import MediaAttachmentGrid from "./toots/MediaAttachmentGrid.jsx";
|
import MediaAttachmentGrid from "./toots/MediaAttachmentGrid.jsx";
|
||||||
import { useDateFnLocale } from "~platform/i18n";
|
|
||||||
import { makeAcctText, useDefaultSession } from "../masto/clients";
|
import { makeAcctText, useDefaultSession } from "../masto/clients";
|
||||||
import TootContent from "./toots/TootContent";
|
import TootContent from "./toots/TootContent";
|
||||||
import BoostIcon from "./toots/BoostIcon";
|
import BoostIcon from "./toots/BoostIcon";
|
||||||
import PreviewCard from "./toots/PreviewCard";
|
import PreviewCard from "./toots/PreviewCard";
|
||||||
import TootPoll from "./toots/TootPoll";
|
import TootPoll from "./toots/TootPoll";
|
||||||
import TootActionGroup from "./toots/TootActionGroup.js";
|
import TootActionGroup from "./toots/TootActionGroup.js";
|
||||||
|
import TootAuthorGroup from "./toots/TootAuthorGroup.js";
|
||||||
import "./RegularToot.css";
|
import "./RegularToot.css";
|
||||||
|
|
||||||
export type TootEnv = {
|
export type TootEnv = {
|
||||||
|
@ -66,63 +62,17 @@ type RegularTootProps = {
|
||||||
|
|
||||||
export function findRootToot(element: HTMLElement) {
|
export function findRootToot(element: HTMLElement) {
|
||||||
let current: HTMLElement | null = element;
|
let current: HTMLElement | null = element;
|
||||||
while (current && !current.classList.contains(tootStyle.toot)) {
|
while (current && !current.classList.contains("RegularToot")) {
|
||||||
current = current.parentElement;
|
current = current.parentElement;
|
||||||
}
|
}
|
||||||
if (!current) {
|
if (!current) {
|
||||||
throw Error(
|
throw Error(
|
||||||
`the element must be placed under a element with ${tootStyle.toot}`,
|
`the element must be placed under a element with .RegularToot`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
function TootAuthorGroup(
|
|
||||||
props: {
|
|
||||||
status: mastodon.v1.Status;
|
|
||||||
now: Date;
|
|
||||||
} & JSX.HTMLElementTags["div"],
|
|
||||||
) {
|
|
||||||
const [managed, rest] = splitProps(props, ["status", "now"]);
|
|
||||||
const toot = () => managed.status;
|
|
||||||
const dateFnLocale = useDateFnLocale();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={tootStyle.tootAuthorGrp} {...rest}>
|
|
||||||
<Img src={toot().account.avatar} class={tootStyle.tootAvatar} />
|
|
||||||
<div class={tootStyle.tootAuthorNameGrp}>
|
|
||||||
<div class={tootStyle.tootAuthorNamePrimary}>
|
|
||||||
<Show when={toot().account.bot}>
|
|
||||||
<SmartToySharp class="acct-mark" aria-label="Bot" />
|
|
||||||
</Show>
|
|
||||||
<Show when={toot().account.locked}>
|
|
||||||
<Lock class="acct-mark" aria-label="Locked" />
|
|
||||||
</Show>
|
|
||||||
<Body2
|
|
||||||
component="span"
|
|
||||||
ref={(e: { innerHTML: string }) => {
|
|
||||||
createRenderEffect(() => {
|
|
||||||
e.innerHTML = resolveCustomEmoji(
|
|
||||||
toot().account.displayName,
|
|
||||||
toot().account.emojis,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<time datetime={toot().createdAt}>
|
|
||||||
{formatRelative(toot().createdAt, managed.now, {
|
|
||||||
locale: dateFnLocale(),
|
|
||||||
})}
|
|
||||||
</time>
|
|
||||||
<span>
|
|
||||||
@{toot().account.username}@{new URL(toot().account.url).hostname}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find bottom-to-top the element with `data-action`.
|
* find bottom-to-top the element with `data-action`.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.tootAuthorGrp {
|
.TootAuthorGroup {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tootAuthorNameGrp {
|
.TootAuthorGroup > .name-grp {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
color: var(--tutu-color-secondary-text-on-surface);
|
color: var(--tutu-color-secondary-text-on-surface);
|
||||||
|
@ -30,10 +30,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tootAuthorNamePrimary {
|
.TootAuthorGroup > .name-grp > .name-primary {
|
||||||
color: var(--tutu-color-on-surface);
|
color: var(--tutu-color-on-surface);
|
||||||
|
|
||||||
> :global(.acct-mark) {
|
> .acct-mark {
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
color: var(--tutu-color-secondary-text-on-surface);
|
color: var(--tutu-color-secondary-text-on-surface);
|
||||||
vertical-align: sub;
|
vertical-align: sub;
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tootAvatar {
|
.TootAuthorGroup > .avatar {
|
||||||
width: calc(var(--toot-avatar-size, 40px) - 1px);
|
width: calc(var(--toot-avatar-size, 40px) - 1px);
|
||||||
aspect-ratio: 1/1;
|
aspect-ratio: 1/1;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
|
@ -49,4 +49,4 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 1px solid var(--tutu-color-surface);
|
border: 1px solid var(--tutu-color-surface);
|
||||||
background-color: var(--tutu-color-surface-d);
|
background-color: var(--tutu-color-surface-d);
|
||||||
}
|
}
|
57
src/timelines/toots/TootAuthorGroup.tsx
Normal file
57
src/timelines/toots/TootAuthorGroup.tsx
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { SmartToySharp, Lock } from "@suid/icons-material";
|
||||||
|
import { formatRelative } from "date-fns";
|
||||||
|
import type { mastodon } from "masto";
|
||||||
|
import { createRenderEffect, Show, splitProps, type JSX } from "solid-js";
|
||||||
|
import Img from "~material/Img";
|
||||||
|
import { Body2 } from "~material/typography";
|
||||||
|
import { useAppLocale } from "~platform/i18n";
|
||||||
|
import { resolveCustomEmoji } from "../../masto/toot";
|
||||||
|
import "./TootAuthorGroup.css";
|
||||||
|
|
||||||
|
function TootAuthorGroup(
|
||||||
|
props: {
|
||||||
|
status: mastodon.v1.Status;
|
||||||
|
now: Date;
|
||||||
|
} & JSX.HTMLElementTags["div"],
|
||||||
|
) {
|
||||||
|
const [managed, rest] = splitProps(props, ["status", "now"]);
|
||||||
|
const toot = () => managed.status;
|
||||||
|
const { dateFn: dateFnLocale } = useAppLocale();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="TootAuthorGroup" {...rest}>
|
||||||
|
<Img src={toot().account.avatar} class="avatar" />
|
||||||
|
<div class={"name-grp"}>
|
||||||
|
<div class="name-primary">
|
||||||
|
<Show when={toot().account.bot}>
|
||||||
|
<SmartToySharp class="acct-mark" aria-label="Bot" />
|
||||||
|
</Show>
|
||||||
|
<Show when={toot().account.locked}>
|
||||||
|
<Lock class="acct-mark" aria-label="Locked" />
|
||||||
|
</Show>
|
||||||
|
<Body2
|
||||||
|
component="span"
|
||||||
|
ref={(e: { innerHTML: string }) => {
|
||||||
|
createRenderEffect(() => {
|
||||||
|
e.innerHTML = resolveCustomEmoji(
|
||||||
|
toot().account.displayName,
|
||||||
|
toot().account.emojis,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<time datetime={toot().createdAt}>
|
||||||
|
{formatRelative(toot().createdAt, managed.now, {
|
||||||
|
locale: dateFnLocale(),
|
||||||
|
})}
|
||||||
|
</time>
|
||||||
|
<span>
|
||||||
|
@{toot().account.username}@{new URL(toot().account.url).hostname}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TootAuthorGroup;
|
Loading…
Reference in a new issue