Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { ComponentProps } from 'svelte';
import MessageInput from './MessageInput.svelte';

export default {
title: 'UI/MessageInput',
component: MessageInput,
tags: ['autodocs'],
render: (args: { Component: MessageInput; props: ComponentProps<typeof MessageInput> }) => ({
Component: MessageInput,
props: args
})
};

export const Comment = {
args: {
variant: 'comment',
placeholder: 'Write your comment',
handleSend: () => alert('sent')
}
};

export const Dm = {
args: {
variant: 'dm',
placeholder: 'Write your message',
handleAdd: () => alert('add'),
handleSend: () => alert('sent')
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<script lang="ts">
import { Avatar, Input } from '$lib/ui';
import { cn } from '$lib/utils';
import { ImageCompositionOvalIcon, PlusSignIcon, SentIcon } from '@hugeicons/core-free-icons';
import { HugeiconsIcon } from '@hugeicons/svelte';
import type { HTMLAttributes } from 'svelte/elements';

interface IMessageInputProps extends HTMLAttributes<HTMLElement> {
variant: 'comment' | 'dm';
src: string;
value: string;
placeholder?: string;
files?: FileList | undefined;
handleAdd?: () => void;
handleSend: () => Promise<void>;
}

let {
variant = 'comment',
src = 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250',
value,
placeholder,
files = $bindable(),
handleAdd,
handleSend,
...restProps
}: IMessageInputProps = $props();

let fileInput: HTMLInputElement | undefined = $state();

const cBase = 'flex items-center justify-between gap-2';
</script>

<div {...restProps} class={cn([cBase, restProps.class].join(' '))}>
{#if variant === 'comment'}
<Avatar size="sm" {src} />
{:else}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<button
type="button"
class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full border-0 p-0"
onclick={handleAdd}
aria-label="Add attachment"
>
<HugeiconsIcon size="24px" icon={PlusSignIcon} color="var(--color-black-400)" />
</button>
{/if}
<Input type="text" bind:value {placeholder} />
{#if value || variant === 'dm'}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full"
onclick={handleSend}
>
<HugeiconsIcon size="24px" icon={SentIcon} color="var(--color-black-400)" />
</div>
{:else}
<div class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full">
<input
id="add-image"
type="file"
class="hidden"
accept="image/*"
bind:files
bind:this={fileInput}
/>
<button
type="button"
class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full border-0 p-0"
aria-label="add-image"
onclick={() => fileInput?.click()}
>
<HugeiconsIcon
size="24px"
icon={ImageCompositionOvalIcon}
color="var(--color-black-400)"
/>
</button>
</div>
{/if}
</div>
67 changes: 32 additions & 35 deletions platforms/metagram/src/lib/fragments/Post/Post.stories.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
import type { ComponentProps } from "svelte";
import Post from "./Post.svelte";
import type { ComponentProps } from 'svelte';
import Post from './Post.svelte';

export default {
title: "Fragments/Post",
component: Post,
tags: ["autodocs"],
render: (args: {
Component: Post;
props: ComponentProps<typeof Post>;
}) => ({
Component: Post,
props: args,
}),
title: 'Fragments/Post',
component: Post,
tags: ['autodocs'],
render: (args: { Component: Post; props: ComponentProps<typeof Post> }) => ({
Component: Post,
props: args
})
};

export const Primary = {
args: {
avatar: "https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250",
username: "blurryface",
imgUri: "https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg",
postAlt: "Sample",
text: "Took some pictures today! Really love how this one in particular turned out! ",
time: "2 hours ago",
count: {
likes: 100,
comments: 50,
},
callback: {
like: () => {
alert("Like clicked");
},
comment: () => {
alert("Comment clicked");
},
menu: () => {
alert("Menu clicked");
},
},
},
args: {
avatar: 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250',
username: 'blurryface',
imgUri: 'https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg',
postAlt: 'Sample',
text: 'Took some pictures today! Really love how this one in particular turned out! ',
time: '2 hours ago',
count: {
likes: 100,
comments: 50
},
callback: {
like: () => {
alert('Like clicked');
},
comment: () => {
alert('Comment clicked');
},
menu: () => {
alert('Menu clicked');
}
}
}
};
1 change: 1 addition & 0 deletions platforms/metagram/src/lib/fragments/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as BottomNav } from './BottomNav/BottomNav.svelte';
export { default as SettingsNavigationButton } from './SettingsNavigationButton/SettingsNavigationButton.svelte';
export { default as MessageInput } from './MessageInput/MessageInput.svelte';
export { default as InputFile } from './InputFile/InputFile.svelte';
20 changes: 4 additions & 16 deletions platforms/metagram/src/lib/ui/Input/Input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ export default {
export const Text = {
args: {
type: 'text',
placeholder: 'Joe Biden',
isRequired: true
placeholder: 'Joe Biden'
}
};

export const Tel = {
args: {
type: 'tel',
placeholder: '987654321',
isRequired: true
placeholder: '987654321'
}
};

export const isError = {
args: {
type: 'text',
placeholder: 'Enter something',
isError: true
errorClass: 'border border-red text-red focus:text-black-800 focus:border-transparent'
}
};

Expand All @@ -44,16 +42,6 @@ export const Email = {
export const Password = {
args: {
type: 'password',
placeholder: 'Please enter password',
isRequired: true
}
};

export const Disabled = {
args: {
type: 'text',
placeholder: 'Joe Biden',
isRequired: true,
isDisabled: true
placeholder: 'Please enter password'
}
};
12 changes: 2 additions & 10 deletions platforms/metagram/src/lib/ui/Input/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
interface IInputProps extends HTMLInputAttributes {
type: 'text' | 'number' | 'email' | 'tel' | 'password';
value: string | number;
placeholder: string;
isRequired: boolean;
isDisabled: boolean;
isError: boolean;
placeholder?: string;
}
let {
type = 'text',
value = $bindable(),
placeholder = '',
isRequired = false,
isDisabled = false,
isError = false,
...restProps
}: IInputProps = $props();
const cbase = $derived(
`w-full bg-grey py-3.5 px-6 text-[15px] text-black-800 font-geist font-normal placeholder:text-black-600 rounded-4xl outline-0 border border-transparent ${isError && 'border border-red text-red focus:text-black-800 focus:border-transparent'} ${isDisabled && 'cursor-not-allowed'}`
`w-full bg-grey py-3.5 px-6 text-[15px] text-black-800 font-geist font-normal placeholder:text-black-600 rounded-4xl outline-0 border border-transparent`
);
</script>

Expand All @@ -31,8 +25,6 @@
{type}
{placeholder}
bind:value
required={isRequired}
disabled={isDisabled}
class={cn([cbase, restProps.class].join(' '))}
tabindex="0"
/>
2 changes: 1 addition & 1 deletion platforms/metagram/src/lib/ui/Toggle/Toggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<label
{...restProps}
for={uniqueId}
class={cn(["relative",restProps.class].join(" "))}
class={cn(['relative', restProps.class].join(' '))}
aria-label={restProps['aria-label'] || 'Toggle'}
role="switch"
aria-checked={checked}
Expand Down
Loading