Skip to content
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

Add PostEvent #872

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export default meta

type Story = StoryObj<typeof DateAvatar>

// Fixed date for the example stories
const exampleDate = new Date(2024, 11, 13, 20, 0)

export const Default: Story = {
args: {
month: "January",
day: 15,
date: exampleDate,
},
}
13 changes: 8 additions & 5 deletions lib/experimental/Information/Avatars/DateAvatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { formatMonth, getDayOfMonth } from "@/lib/date"

type Props = {
month: string
day: number
date: Date
}

export const DateAvatar = ({ month, day }: Props) => {
const monthName = month.slice(0, 3)
export const DateAvatar = ({ date }: Props) => {
const dateDay = getDayOfMonth(date)
const dateMonth = formatMonth(date)
const monthName = dateMonth.slice(0, 3)

return (
<div className="flex h-10 w-10 flex-col items-center justify-center rounded border border-solid border-f1-border-secondary bg-f1-background-inverse-secondary">
<div className="pt-0.5 text-xs font-semibold uppercase leading-3 text-f1-foreground-critical dark:text-f1-foreground-inverse-secondary">
{monthName}
</div>
<div className="flex items-center justify-center text-lg font-medium leading-tight text-f1-foreground">
{day}
{dateDay}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default meta

type Story = StoryObj<typeof Celebration>

// Fixed date for the example stories
const exampleDate = new Date(2024, 11, 13, 20, 0)

export const Default: Story = {
decorators: [
(Story) => (
Expand All @@ -30,10 +33,7 @@ export const Default: Story = {
src="https://github.com/josepjaume.png"
type="birthday"
typeLabel="Birthday"
date={{
day: 29,
month: "November",
}}
date={exampleDate}
/>
</div>
<div className="w-48">
Expand All @@ -44,10 +44,7 @@ export const Default: Story = {
src="https://github.com/nlopin.png"
type="anniversary"
typeLabel="Anniversary"
date={{
day: 4,
month: "December",
}}
date={exampleDate}
/>
</div>
</>
Expand All @@ -69,10 +66,7 @@ export const NoImage: Story = {
canReact: false,
type: "first-day",
typeLabel: "First day very long name",
date: {
day: 15,
month: "December",
},
date: exampleDate,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export type CelebrationProps = {
canReact?: boolean
type?: "birthday" | "anniversary" | "first-day"
typeLabel: string
date: {
day: number
month: string
}
date: Date
}

export const BaseCelebration = ({
Expand Down Expand Up @@ -75,7 +72,7 @@ export const BaseCelebration = ({
</div>
</div>
<div className="shrink-0">
<DateAvatar month={date.month} day={date.day} />
<DateAvatar date={date} />
</div>
</div>
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { Meta, StoryObj } from "@storybook/react"
import { PostEvent } from "."

const meta: Meta<typeof PostEvent> = {
component: PostEvent,
}

export default meta

type Story = StoryObj<typeof PostEvent>

// Fixed date for the example stories
const eventDate = new Date(2024, 11, 13, 20, 0)

export const Default: Story = {
decorators: [
(Story) => (
<div className="max-w-96">
<Story />
</div>
),
],
args: {
title: "End of the Year Dinner!",
place: "Poble Espanyol",
imageUrl: "https://cataas.com/cat",
date: eventDate,
},
}

export const NoImage: Story = {
decorators: [
(Story) => (
<div className="max-w-96">
<Story />
</div>
),
],
args: {
title: "End of the Year Dinner!",
place: "Poble Espanyol",
date: eventDate,
},
}

export const Skeleton: Story = {
decorators: [
(Story) => (
<div className="max-w-96">
<Story />
</div>
),
],
args: {},
render: () => <PostEvent.Skeleton />,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { DateAvatar } from "@/experimental/Information/Avatars/DateAvatar"
import { formatTime } from "@/lib/date"
import { withSkeleton } from "@/lib/skeleton"
import { Skeleton } from "@/ui/skeleton"

type PostEventProps = {
title: string
imageUrl?: string
place: string
date: Date
}

export const BasePostEvent = ({
title,
imageUrl,
place,
date,
}: PostEventProps) => {
return (
<div className="flex w-full flex-col gap-1 rounded-xl border border-solid border-f1-border-secondary bg-f1-background-inverse-secondary p-1 shadow">
{imageUrl && (
<div className="relative aspect-video w-full">
<img
src={imageUrl}
role="presentation"
loading="lazy"
className="aspect-video h-full w-full rounded-md object-cover"
/>
<Skeleton className="absolute inset-0 h-full w-full rounded-md" />
</div>
)}
<div className="flex h-full flex-row gap-3 p-2">
<div className="w-1 shrink-0 self-stretch rounded-full bg-f1-background-accent-bold" />
<div className="flex min-w-0 grow flex-col">
<span className="truncate font-medium text-f1-foreground">
{title}
</span>
<span className="flex min-w-0 flex-row gap-1 text-f1-foreground-secondary">
{formatTime(date)} · <span className="truncate">{place}</span>
</span>
</div>
<div className="shrink-0">
<DateAvatar date={date} />
</div>
</div>
</div>
)
}

export const PostEventSkeleton = () => (
<div
className="flex w-full flex-col gap-1 rounded-xl border border-solid border-f1-border-secondary bg-f1-background-inverse-secondary p-1"
role="status"
aria-busy="true"
aria-live="polite"
>
<div>
<Skeleton className="aspect-video h-full w-full rounded-lg" />
</div>
<div className="flex h-full flex-row gap-3 p-2">
<Skeleton className="w-1 shrink-0 self-stretch rounded-full" />
<div className="flex grow flex-col gap-1.5 py-1">
<Skeleton className="mt-px h-3 w-1/2" />
<Skeleton className="mb-px h-3 w-1/4" />
</div>
</div>
</div>
)

export const PostEvent = withSkeleton(BasePostEvent, PostEventSkeleton)
13 changes: 13 additions & 0 deletions lib/lib/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { format } from "date-fns"

export function formatTime(date: Date) {
return format(date, "HH:mm")
}
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use p which is a localized version of the time to use 12h or 24h version when necessary

Screenshot 2024-12-10 at 11 01 08


export function formatMonth(date: Date) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should better name this something like getAbbrMonth

return format(date, "MMM")
}

export function getDayOfMonth(date: Date) {
return date.getDate()
}
Loading