-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/metagram header #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/metagram header #133
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac4aeb0
feat: added metagram header primary linear gradient.
Sahil2004 5c1a310
feat: added flash icon.
Sahil2004 9037b45
feat: added secondary state of header.
Sahil2004 9aba8a9
feat: added secondary state of header with menu.
Sahil2004 11b3eb4
chore: cleaned some code.
Sahil2004 0eb9b05
docs: updated component docs.
Sahil2004 eacbb2f
Merge branch 'main' into feat/metagram-header
sosweetham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
platforms/metagram/src/lib/fragments/Header/Header.stories.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { ComponentProps } from "svelte"; | ||
import Header from "./Header.svelte"; | ||
|
||
export default { | ||
title: "Fragments/Header", | ||
component: Header, | ||
tags: ["autodocs"], | ||
render: (args: { | ||
Component: Header; | ||
props: ComponentProps<typeof Header>; | ||
}) => ({ | ||
Component: Header, | ||
props: args, | ||
}), | ||
}; | ||
|
||
export const Primary = { | ||
args: { | ||
variant: "primary", | ||
heading: "metagram", | ||
callback: () => alert("clicked"), | ||
}, | ||
}; | ||
|
||
export const PrimaryWithNoFlash = { | ||
args: { | ||
variant: "primary", | ||
heading: "messages", | ||
}, | ||
}; | ||
|
||
export const Secondary = { | ||
args: { | ||
variant: "secondary", | ||
heading: "Account", | ||
}, | ||
}; | ||
|
||
export const SecondaryWithMenu = { | ||
args: { | ||
variant: "secondary", | ||
heading: "Account", | ||
callback: () => alert("menu clicked"), | ||
}, | ||
}; | ||
|
||
export const Tertiary = { | ||
args: { | ||
variant: "tertiary", | ||
callback: () => alert("clicked"), | ||
}, | ||
}; |
108 changes: 108 additions & 0 deletions
108
platforms/metagram/src/lib/fragments/Header/Header.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<script lang="ts"> | ||
import { cn } from '$lib/utils'; | ||
import { | ||
ArrowLeft01Icon, | ||
ArrowLeft02Icon, | ||
MoreVerticalIcon, | ||
ZapIcon | ||
} from '@hugeicons/core-free-icons'; | ||
import { HugeiconsIcon } from '@hugeicons/svelte'; | ||
import type { HTMLAttributes } from 'svelte/elements'; | ||
|
||
interface IHeaderProps extends HTMLAttributes<HTMLElement> { | ||
variant: 'primary' | 'secondary' | 'tertiary'; | ||
heading?: string; | ||
callback?: () => void; | ||
} | ||
|
||
const { variant, callback, heading, ...restProps }: IHeaderProps = $props(); | ||
|
||
const variantClasses = { | ||
primary: { | ||
text: 'text-transparent bg-clip-text bg-[image:var(--color-brand-gradient)]', | ||
background: '' | ||
}, | ||
secondary: { | ||
text: '', | ||
background: '' | ||
}, | ||
tertiary: { | ||
text: '', | ||
background: 'bg-white/60' | ||
} | ||
}; | ||
|
||
const backButton = { | ||
secondary: ArrowLeft01Icon, | ||
tertiary: ArrowLeft02Icon | ||
}; | ||
|
||
const menuButton = { | ||
primary: ZapIcon, | ||
secondary: MoreVerticalIcon, | ||
tertiary: MoreVerticalIcon | ||
}; | ||
|
||
const classes = $derived({ | ||
common: cn('flex items-center justify-between p-4'), | ||
text: variantClasses[variant].text, | ||
background: variantClasses[variant].background | ||
}); | ||
|
||
const backButtonCallback = () => { | ||
window.history.back(); | ||
}; | ||
</script> | ||
|
||
<header {...restProps} class={cn([classes.common, restProps.class])}> | ||
<span class="flex items-center gap-2"> | ||
{#if variant !== 'primary'} | ||
<button | ||
class={cn([ | ||
'cursor-pointer rounded-full p-2 hover:bg-gray-100', | ||
classes.background | ||
])} | ||
onclick={backButtonCallback} | ||
> | ||
<HugeiconsIcon | ||
icon={backButton[variant]} | ||
size={24} | ||
color="var(--color-black-500)" | ||
/> | ||
</button> | ||
{/if} | ||
{#if variant !== 'tertiary'} | ||
<h1 class={cn([classes.text])}> | ||
{heading} | ||
</h1> | ||
{/if} | ||
</span> | ||
{#if callback} | ||
<button | ||
class={cn(['cursor-pointer rounded-full p-2 hover:bg-gray-100', classes.background])} | ||
onclick={callback} | ||
> | ||
<HugeiconsIcon icon={menuButton[variant]} size={24} color="var(--color-black-500)" /> | ||
</button> | ||
{/if} | ||
</header> | ||
|
||
<!-- | ||
@component | ||
@name Header | ||
@description Header fragment. | ||
@props | ||
- variant: Can be 'primary' for home screen header with a flash, 'secondary' without flash, or 'tertiary'. | ||
- heading: The main heading text. | ||
- callback: A function to be called when the header is clicked. | ||
@usage | ||
<script> | ||
import { Header } from "$lib/fragments"; | ||
</script> | ||
|
||
<Header variant="primary" heading="metagram" callback={() => alert("clicked")} /> | ||
<Header variant="primary" heading="messages" /> | ||
<Header variant="secondary" heading="Account" /> | ||
<Header variant="secondary" heading="Account" callback={() => alert("clicked")} /> | ||
<Header variant="tertiary" callback={() => alert("clicked")} /> | ||
--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Header } from "./Header/Header.svelte"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use Svelte event handlers and add accessibility attributes.
Replace
onclick
with Svelte'son:click
directive and add appropriate aria attributes for better accessibility.📝 Committable suggestion