-
Notifications
You must be signed in to change notification settings - Fork 187
🚸 Improve ProjectHeader tab navigation user experience #3953
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| .link { | ||
| position: relative; | ||
| display: flex; | ||
| gap: var(--spacing-1half); | ||
| align-items: center; | ||
| padding: var(--spacing-1half) var(--spacing-3) var(--spacing-1half) | ||
| var(--spacing-2); | ||
| font-size: var(--font-size-4); | ||
| font-weight: 500; | ||
| color: var(--global-mute-text); | ||
| cursor: pointer; | ||
| background: transparent; | ||
| border: none; | ||
| border-radius: var(--border-radius-md); | ||
| transition: all 0.2s ease; | ||
| } | ||
|
|
||
| .link[aria-disabled='true'] { | ||
| color: var(--button-disabled-foreground); | ||
| background-color: transparent; | ||
| } | ||
|
|
||
| .link:hover:not([aria-disabled='true']) { | ||
| color: var(--global-foreground); | ||
| background-color: var(--global-muted-background); | ||
| } | ||
|
|
||
| .link[data-active='true'] { | ||
| color: var(--global-foreground); | ||
| } | ||
|
|
||
| .link[data-active='true']::after { | ||
| position: absolute; | ||
| bottom: -6px; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 1px; | ||
| content: ''; | ||
| background-color: var(--primary-accent); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { Meta, StoryObj } from '@storybook/nextjs' | ||
| import { PROJECT_TAB, type ProjectTab } from '../projectConstants' | ||
| import { TabItem } from './TabItem' | ||
|
|
||
| const TABS: readonly [ProjectTab, ProjectTab, ProjectTab] = [ | ||
| { value: PROJECT_TAB.PROJECT, label: 'Project' }, | ||
| { value: PROJECT_TAB.SCHEMA, label: 'Schema' }, | ||
| { value: PROJECT_TAB.SESSIONS, label: 'Sessions' }, | ||
| ] | ||
|
|
||
| const meta = { | ||
| component: TabItem, | ||
| parameters: { | ||
| layout: 'centered', | ||
| nextjs: { | ||
| appDirectory: true, | ||
| navigation: { | ||
| pathname: '/projects/123/ref/main', | ||
| }, | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div style={{ display: 'flex', gap: '8px' }}> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| argTypes: { | ||
| item: { | ||
| description: 'Tab item configuration', | ||
| }, | ||
| projectId: { | ||
| control: 'text', | ||
| description: 'Project ID', | ||
| }, | ||
| branchOrCommit: { | ||
| control: 'text', | ||
| description: 'Branch name or commit hash', | ||
| }, | ||
| schemaFilePath: { | ||
| control: 'text', | ||
| description: 'Schema file path (required for schema tab)', | ||
| }, | ||
| }, | ||
| args: { | ||
| projectId: 'my-project', | ||
| branchOrCommit: 'main', | ||
| item: TABS[0], | ||
| }, | ||
| } satisfies Meta<typeof TabItem> | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof TabItem> | ||
|
|
||
| export const Default: Story = { | ||
| render: (args) => { | ||
| const [projectTab, schemaTab, sessionsTab] = TABS | ||
| return ( | ||
| <> | ||
| <TabItem {...args} item={projectTab} /> | ||
| <TabItem {...args} item={schemaTab} schemaFilePath="schema.sql" /> | ||
| <TabItem {...args} item={sessionsTab} /> | ||
| </> | ||
| ) | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| 'use client' | ||
|
|
||
| import { BookMarked, ErdIcon, MessagesSquare } from '@liam-hq/ui' | ||
| import Link from 'next/link' | ||
| import { usePathname } from 'next/navigation' | ||
| import { type FC, useMemo } from 'react' | ||
| import { match } from 'ts-pattern' | ||
| import { urlgen } from '../../../../libs/routes' | ||
| import type { ProjectTab, ProjectTabValue } from '../projectConstants' | ||
| import styles from './TabItem.module.css' | ||
|
|
||
| function getActiveTabFromPath(pathname: string): ProjectTabValue { | ||
| if (pathname.endsWith('/sessions')) return 'sessions' | ||
| if (pathname.includes('/schema/')) return 'schema' | ||
| return 'project' | ||
| } | ||
|
|
||
| function getIconComponent(tabValue: ProjectTabValue) { | ||
| return match(tabValue) | ||
| .with('project', () => BookMarked) | ||
| .with('schema', () => ErdIcon) | ||
| .with('sessions', () => MessagesSquare) | ||
| .exhaustive() | ||
| } | ||
|
|
||
| type Props = { | ||
| item: ProjectTab | ||
| projectId: string | ||
| branchOrCommit: string | ||
| schemaFilePath?: string | ||
| } | ||
|
|
||
| export const TabItem: FC<Props> = ({ | ||
| item, | ||
| projectId, | ||
| branchOrCommit, | ||
| schemaFilePath, | ||
| }) => { | ||
| const pathname = usePathname() | ||
| const activeTab = getActiveTabFromPath(pathname) | ||
|
|
||
| const Icon = getIconComponent(item.value) | ||
| const isSchemaTab = item.value === 'schema' | ||
| const isDisabled = isSchemaTab && !schemaFilePath | ||
| const isActive = item.value === activeTab | ||
|
|
||
| const href = useMemo(() => { | ||
| return match(item.value) | ||
| .with('project', () => | ||
| urlgen('projects/[projectId]/ref/[branchOrCommit]', { | ||
| projectId, | ||
| branchOrCommit, | ||
| }), | ||
| ) | ||
| .with('schema', () => | ||
| urlgen( | ||
| 'projects/[projectId]/ref/[branchOrCommit]/schema/[...schemaFilePath]', | ||
| { | ||
| projectId, | ||
| branchOrCommit, | ||
| schemaFilePath: schemaFilePath || '', | ||
| }, | ||
| ), | ||
junkisai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| .with('sessions', () => | ||
| urlgen('projects/[projectId]/ref/[branchOrCommit]/sessions', { | ||
| projectId, | ||
| branchOrCommit, | ||
| }), | ||
| ) | ||
| .exhaustive() | ||
| }, [item, projectId, branchOrCommit, schemaFilePath]) | ||
|
|
||
| return ( | ||
| <Link | ||
| href={href} | ||
| data-active={isActive} | ||
| aria-disabled={isDisabled} | ||
| tabIndex={isDisabled ? -1 : undefined} | ||
| className={styles.link} | ||
| > | ||
| <Icon size={16} /> | ||
|
Comment on lines
+74
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new tab component keeps rendering a Useful? React with 👍 / 👎. |
||
| {item.label} | ||
| </Link> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './TabItem' |
Uh oh!
There was an error while loading. Please reload this page.