feat: add TextProps component for reusable text modifications

This commit is contained in:
Xylight committed 2024-09-08 17:23:29 -07:00
1 parent 21ae0f8272
commit 848992175b
6 files changed
+61 -53

No files matched your search

@@ -56,8 +56,10 @@
import { hidePost, postLink } from './helpers'
import { feature } from '$lib/version'
import Switch from '$lib/components/input/Switch.svelte'
import { instanceToURL } from '$lib/util'
import { instanceId, instanceToURL } from '$lib/util'
import { publishedToDate } from '$lib/components/util/date'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { communityLink, userLink } from '$lib/lemmy/generic'
export let post: PostView
export let view: View = 'cozy'
@@ -68,10 +70,6 @@
let editing = false
let saving = false
let fediseerOpen = false
let fediseerData: Data | null = null
let fediseerLoading = false
let translating = false
let localShare = false
@@ -80,12 +78,6 @@
$: buttonSquare = view == 'compact' ? 'w-[30px] h-[30px]' : 'w-8 h-8'
</script>
{#if fediseerData}
{#await import('$lib/fediseer/Fediseer.svelte') then { default: Fediseer }}
<Fediseer bind:open={fediseerOpen} data={fediseerData} />
{/await}
{/if}
{#if editing}
<Modal bind:open={editing}>
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
@@ -223,47 +215,39 @@
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
</Button>
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
<MenuButton
link
href="/u/{post.creator.name}@{new URL(post.creator.actor_id).hostname}"
>
<Icon src={UserCircle} size="16" micro slot="prefix" class="flex-shrink-0" />
<span class="overflow-hidden overflow-ellipsis whitespace-nowrap">{post.creator.name}</span>
<MenuButton link href={userLink(post.creator)}>
<Icon
src={UserCircle}
size="16"
micro
slot="prefix"
class="flex-shrink-0"
/>
<TextProps wrap="no-wrap">
{post.creator.name}
</TextProps>
</MenuButton>
<MenuButton
link
href="/c/{post.community.name}@{new URL(post.community.actor_id)
.hostname}"
>
<Icon src={Newspaper} size="16" micro slot="prefix" class="flex-shrink-0" />
<span class="overflow-hidden overflow-ellipsis whitespace-nowrap">{post.community.title}</span>
<MenuButton link href={communityLink(post.community)}>
<Icon
src={Newspaper}
size="16"
micro
slot="prefix"
class="flex-shrink-0"
/>
<TextProps wrap="no-wrap">
{post.community.title}
</TextProps>
</MenuButton>
<MenuButton
loading={fediseerLoading}
on:click={async (e) => {
e.stopImmediatePropagation()
fediseerLoading = true
const data = await fediseer.getInstanceInfo(
new URL(post.community.actor_id).hostname
)
fediseerData = data
fediseerOpen = true
fediseerLoading = false
return
}}
>
<!-- <MenuButton href="/instances/{instanceId(post.community.actor_id)}">
<svelte:fragment slot="prefix">
{#if fediseerLoading}
<Spinner width={14} />
{:else}
<Icon src={ServerStack} size="16" micro class="flex-shrink-0" />
{/if}
<Icon src={ServerStack} size="16" micro class="flex-shrink-0" />
</svelte:fragment>
<span class="overflow-hidden overflow-ellipsis whitespace-nowrap">{new URL(post.community.actor_id).hostname}</span>
</MenuButton>
<hr class="w-[90%] mx-auto opacity-100 dark:opacity-10 my-2" />
<TextProps wrap="no-wrap">
{instanceId(post.community.actor_id)}
</TextProps>
</MenuButton> -->
<hr class="border-slate-200 dark:border-zinc-800 mx-2 my-2" />
<MenuDivider>{$t('post.actions.more.actions')}</MenuDivider>
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
<MenuButton on:click={() => (editing = true)}>
+4 -3
View File
@@ -79,10 +79,11 @@
{/if}
</div>
{#if bio}
<div class="relative {center ? 'text-center' : 'text-left'}">
<div class="relative w-full {center ? 'text-center' : 'text-left'}">
<div
class="p-4 relative bg-white/30 dark:bg-zinc-900/30 border border-slate-300 dark:border-zinc-800 border-opacity-50
rounded-xl"
class="p-4 relative bg-white/30 dark:bg-zinc-900/30 border border-slate-300
dark:border-zinc-800 border-opacity-50 rounded-xl
max-w-full w-full"
>
<PostBody class="text-sm" view="list" body={bio} clickThrough />
</div>
+5 -2
View File
@@ -3,6 +3,7 @@
import { Icon, XMark } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import TextProps from '../text/TextProps.svelte'
type T = $$Generic
@@ -49,12 +50,14 @@
filters = filters
}}
color={filters.has(identifier) ? 'primary' : 'ghost'}
class="text-inherit dark:text-inherit text-xs px-2.5"
class="text-xs px-2.5"
rounding="pill"
size="sm"
>
<slot name="identifier" string={identifier}>
{identifier}
<TextProps wrap="no-wrap">
{identifier}
</TextProps>
</slot>
</Button>
{/each}
@@ -0,0 +1,16 @@
<script lang="ts" context="module">
const wrapClass = {
wrap: '',
'no-wrap': 'overflow-hidden overflow-ellipsis whitespace-nowrap',
}
</script>
<script lang="ts">
export let wrap: keyof typeof wrapClass = 'wrap'
$: classes = `${wrapClass[wrap]} ${$$props.class ?? ''}`
</script>
<span class={classes}>
<slot />
</span>
+4
View File
@@ -191,3 +191,7 @@ export function canParseUrl(url: string): boolean {
return false
}
}
export function instanceId(actorId: string) {
return new URL(actorId).hostname
}