Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/lite/e2e/tests/screenshots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test.describe("screenshots", () => {
.getByRole("treeitem", { name: "C", exact: true })
.getByTitle("C", { exact: true })
.click();
await appWindow.getByRole("button", { name: "Pull Request", exact: true }).click();
await appWindow.getByRole("tab", { name: "Pull Request", exact: true }).click();
await expect(appWindow.getByPlaceholder("PR title")).toBeVisible();
await shoot(appWindow, "pr-form", "#details-panel");
});
Expand Down
8 changes: 4 additions & 4 deletions apps/lite/e2e/tests/workspace-reviews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test.beforeEach(async ({ appWindow, electronApp, reviewState }) => {

const selectBranch = (page: Page, name: string) =>
page.getByRole("treeitem", { name, exact: true }).getByTitle(name, { exact: true }).click();
const branchTabs = (page: Page) => page.getByRole("group", { name: "Branch tab", exact: true });
const branchTabs = (page: Page) => page.getByRole("tablist", { name: "Branch tab", exact: true });

test("shows PR titles and labels on workspace branches without hover shifts", async ({
appWindow,
Expand Down Expand Up @@ -172,14 +172,14 @@ for (const { reviewState, defaultTab, showCreateButton } of [
exact: true,
});
await expect(createPullRequest).toBeVisible({ visible: showCreateButton });
await expect(tabs.getByRole("button", { name: defaultTab, pressed: true })).toBeVisible();
await expect(tabs.getByRole("tab", { name: defaultTab, selected: true })).toBeVisible();
await expect(appWindow.getByPlaceholder("PR title")).toBeHidden();

const chosenTab = defaultTab === "Diff" ? "Pull Request" : "Diff";
await tabs.getByRole("button", { name: chosenTab, exact: true }).click();
await tabs.getByRole("tab", { name: chosenTab, exact: true }).click();
await selectBranch(appWindow, "B");
await selectBranch(appWindow, "C");
await expect(tabs.getByRole("button", { name: chosenTab, pressed: true })).toBeVisible();
await expect(tabs.getByRole("tab", { name: chosenTab, selected: true })).toBeVisible();
});
});
}
Expand Down
5 changes: 5 additions & 0 deletions apps/lite/scripts/check-tokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const KNOWN_RUNTIME = new Map([
// Base UI's scroll area writes the thumb's length on its scrollbar element.
["--scroll-area-thumb-height", "@base-ui/react scroll area scrollbar"],
["--scroll-area-thumb-width", "@base-ui/react scroll area scrollbar"],
// Base UI's tabs indicator carries the selected tab's box.
["--active-tab-top", "@base-ui/react tabs indicator"],
["--active-tab-height", "@base-ui/react tabs indicator"],
["--active-tab-width", "@base-ui/react tabs indicator"],
["--active-tab-left", "@base-ui/react tabs indicator"],
// Shiki's dual-theme output carries both themes as inline style.
["--shiki-light", "shiki dual-theme inline style"],
["--shiki-dark", "shiki dual-theme inline style"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
flex-direction: column;
/* Symmetric so the header actions share a right edge with the content
columns below, which all inset by the same token. */
/* 12px below: the tabs' underline hangs 8px under them and is 4px thick,
so it sits on the header's bottom edge. */
padding-inline: var(--panel-padding-inline);
padding-block: var(--panel-padding-block) 12px;
/* The header draws its own bottom edge, so the tab row reads as a strip
Expand Down
23 changes: 10 additions & 13 deletions apps/lite/ui/src/routes/project/$id/workspace/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { projectSlice } from "#ui/projects/state.ts";
import { interfaceSlice } from "#ui/interface/state.ts";
import { Badge } from "@gitbutler/ui-react/Badge.tsx";
import { Button, getButtonClassName } from "@gitbutler/ui-react/Button.tsx";
import { Tab, Tabs } from "@gitbutler/ui-react/Tabs.tsx";
import { Icon } from "@gitbutler/ui-react/Icon.tsx";
import { Tooltip } from "@gitbutler/ui-react/Tooltip.tsx";
import { useCopied } from "#ui/components/useCopied.ts";
Expand Down Expand Up @@ -3141,23 +3142,19 @@ const BranchTabToggle: FC<{
prDisabled?: boolean;
className?: string;
}> = ({ branchTab, setBranchTab, prDisabled = false, className }) => (
<ToggleGroup
render={<ToggleGroupStyles className={className} />}
value={[branchTab]}
onValueChange={(value: Array<BranchTab>) => {
const head = value[0];
if (head === undefined) return;
setBranchTab(head);
}}
<Tabs
className={className}
value={branchTab}
onValueChange={(value: BranchTab) => setBranchTab(value)}
aria-label="Branch tab"
>
<Toggle render={<ToggleStyles />} value={"diff" satisfies BranchTab}>
<Tab value={"diff" satisfies BranchTab} icon={<Icon name="diff" />}>
Diff
</Toggle>
<Toggle render={<ToggleStyles />} value={"pr" satisfies BranchTab} disabled={prDisabled}>
</Tab>
<Tab value={"pr" satisfies BranchTab} icon={<Icon name="pr" />} disabled={prDisabled}>
{prDisabled ? "No pull request" : "Pull Request"}
</Toggle>
</ToggleGroup>
</Tab>
</Tabs>
);

/** `[` and `]` step between a branch's tabs; with two of them, either key toggles. */
Expand Down
82 changes: 82 additions & 0 deletions packages/ui-react/src/Tabs.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.list {
/* The tab's inset, which the underline keeps too, so it runs under the tab's content. */
--tab-padding-inline: 10px;

display: flex;
position: relative;
column-gap: 2px;
align-items: center;
}

.tab {
display: inline-flex;
column-gap: 6px;
align-items: center;
height: var(--size-control);
padding-inline: var(--tab-padding-inline);
border-radius: var(--radius-control);
color: var(--text-1);
white-space: nowrap;
cursor: var(--control-cursor);
transition: background-color var(--transition-fast);

&:hover:not([data-active], [data-disabled]) {
background-color: var(--bg-hover);
}

/* Unavailable for now: it stays faded under the pointer, and its label says why. */
&[data-disabled] {
cursor: default;
}

&:focus-visible {
outline: var(--focus-ring);
}
}

.icon {
display: flex;
opacity: 0.5;

/* Only on a tab that isn't selected: the selected one doesn't answer the pointer. */
.tab:hover:not([data-active], [data-disabled]) & {
opacity: 0.8;
}

.tab[data-active] & {
opacity: 0.7;
}
}

/* The label and its shortcut fade together. */
.label {
display: inline-flex;
column-gap: 3px;
align-items: center;
opacity: 0.5;

:is(.tab:hover:not([data-disabled]), .tab[data-active]) & {
opacity: 1;
}
}

/* Under the selected tab's content, 8px below it; moves and resizes to the next as the
selection moves. */
.indicator {
position: absolute;
top: calc(var(--active-tab-top) + var(--active-tab-height) + 8px);
left: 0;
width: calc(var(--active-tab-width) - 2 * var(--tab-padding-inline));
height: 4px;
translate: calc(var(--active-tab-left) + var(--tab-padding-inline)) 0;
background-color: var(--fill-gray-bg);
transition:
translate var(--transition-medium) ease-out,
width var(--transition-medium) ease-out;
}

@media (prefers-reduced-motion: reduce) {
.indicator {
transition: none;
}
}
101 changes: 101 additions & 0 deletions packages/ui-react/src/Tabs.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import preview from "#storybook/preview";
import { useState } from "react";
import { Icon } from "./Icon.tsx";
import { Tab, Tabs } from "./Tabs.tsx";

const meta = preview.meta({
component: Tabs,
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/design/cqdnAotT8n9op8WGYLOHg4/%E2%9A%9B%EF%B8%8F-Lite-Core?node-id=2374-4526",
},
},
decorators: [
(Story) => (
<div style={{ paddingBlock: 24 }}>
<Story />
</div>
),
],
});

/** Tabs that switch a pane's contents; the underline follows the selected one. */
export const Default = meta.story({
render: () => (
<Tabs defaultValue="diff" aria-label="Branch">
<Tab value="diff">Diff</Tab>
<Tab value="pr">Pull Request</Tab>
<Tab value="sessions">Sessions</Tab>
<Tab value="activity">Activity</Tab>
</Tabs>
),
});

/** With an `icon` before each label and a `count` after the ones that hold things. */
export const IconsAndCounts = meta.story({
render: () => (
<Tabs defaultValue="changes" aria-label="Worktree">
<Tab value="changes" icon={<Icon name="diff" />} count={3}>
Changes
</Tab>
<Tab value="pr" icon={<Icon name="pr" />}>
Pull Request
</Tab>
<Tab value="sessions" icon={<Icon name="ai" />} count={2}>
Sessions
</Tab>
<Tab value="activity" icon={<Icon name="history" />}>
Activity
</Tab>
</Tabs>
),
});

/** With `kbd`, the shortcut that selects each tab, faint after its label. */
export const Shortcuts = meta.story({
render: () => (
<Tabs defaultValue="diff" aria-label="Branch">
<Tab value="diff" kbd="Mod+1">
Diff
</Tab>
<Tab value="pr" kbd="Mod+2" count={4}>
Pull Request
</Tab>
<Tab value="activity" kbd="Mod+3">
Activity
</Tab>
</Tabs>
),
});

/**
* In a pane's header, controlled by the pane. The header leaves 12px below the row, the underline's
* 8px gap and its 4px, so the underline sits on the divider rather than across it.
*/
export const InAHeader = meta.story({
render: function Render() {
const [tab, setTab] = useState("changes");
return (
<div style={{ width: 480, border: "1px solid var(--border-2)" }}>
<div
style={{
paddingInline: 12,
paddingBlock: "6px 12px",
borderBlockEnd: "1px solid var(--border-2)",
}}
>
<Tabs value={tab} onValueChange={setTab} aria-label="Worktree">
<Tab value="changes" count={3}>
Changes
</Tab>
<Tab value="activity">Activity</Tab>
</Tabs>
</div>
<p className="text-13" style={{ padding: 12, margin: 0 }}>
{tab === "changes" ? "Three changed files." : "Nothing happened yet."}
</p>
</div>
);
},
});
59 changes: 59 additions & 0 deletions packages/ui-react/src/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Tabs as BaseTabs } from "@base-ui/react";
import type { HotkeySequence } from "@tanstack/react-hotkeys";
import type { FC, ReactNode } from "react";
import { Badge } from "./Badge.tsx";
import { classes } from "./classes.ts";
import { Kbd } from "./Kbd.tsx";
import styles from "./Tabs.module.css";

/**
* A row of {@link Tab}s that switch what a pane shows, one at a time, with an underline under the
* selected one that slides to the next as the selection moves.
*
* - Controlled with `value` and `onValueChange`, or left to itself with `defaultValue`.
* - The arrow keys move between the tabs, as a tab list does.
* - The underline runs under the selected tab's content and hangs outside the row, 8px below it
* and 4px thick, so the header holding the tabs leaves 12px below them: the underline then
* sits on the header's divider.
*
* @public
* @import import { Tabs, Tab } from "@gitbutler/ui-react/Tabs.tsx";
*/
export const Tabs: FC<
Omit<BaseTabs.Root.Props, "className"> & {
className?: string;
"aria-label"?: string;
}
> = ({ className, children, "aria-label": ariaLabel, ...props }) => (
<BaseTabs.Root {...props} className={className}>
<BaseTabs.List className={styles.list} aria-label={ariaLabel}>
{children}
<BaseTabs.Indicator className={styles.indicator} />
</BaseTabs.List>
</BaseTabs.Root>
);

/**
* One tab in {@link Tabs}: its label, an optional `icon` before it and an optional `count` after
* it, for how many things the tab holds. `kbd` names the shortcut that selects it, faint after
* the label. Faded until it is hovered or selected.
*
* @public
*/
export const Tab: FC<
Omit<BaseTabs.Tab.Props, "className"> & {
className?: string;
icon?: ReactNode;
count?: number;
kbd?: string | HotkeySequence;
}
> = ({ className, icon, count, kbd, children, ...props }) => (
<BaseTabs.Tab {...props} className={classes(className, "text-13", "text-semibold", styles.tab)}>
{icon !== undefined && <span className={styles.icon}>{icon}</span>}
<span className={styles.label}>
{children}
{kbd !== undefined && <Kbd hotkey={kbd} variant="button" />}
</span>
{count !== undefined && <Badge variant="lightGray">{count}</Badge>}
</BaseTabs.Tab>
);
Loading