-
Notifications
You must be signed in to change notification settings - Fork 928
refactor: update the navbar to match the new designs #15964
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 11 commits
3900600
916c0a7
8837484
f365421
072a6d8
a040a3b
2a79316
1b0c075
7956d56
7f9a95d
7e11d46
07ce677
0699cb4
2830801
08f92e5
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 |
---|---|---|
|
@@ -13,7 +13,8 @@ export const buttonVariants = cva( | |
text-sm font-semibold font-medium cursor-pointer | ||
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-content-link | ||
disabled:pointer-events-none disabled:text-content-disabled | ||
[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`, | ||
[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 | ||
px-3 py-2`, | ||
{ | ||
variants: { | ||
variant: { | ||
|
@@ -25,10 +26,15 @@ export const buttonVariants = cva( | |
"border-none bg-transparent text-content-secondary hover:text-content-primary", | ||
warning: | ||
"border border-border-error text-content-primary bg-surface-error hover:bg-transparent", | ||
ghost: | ||
"text-content-primary bg-transparent border-0 hover:bg-surface-secondary", | ||
}, | ||
|
||
size: { | ||
default: "h-9 px-3 py-2", | ||
sm: "h-8 px-2 text-xs", | ||
lg: "h-10", | ||
default: "h-9", | ||
sm: "h-8 px-2 py-1.5 text-xs", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
|
@@ -44,16 +50,16 @@ export interface ButtonProps | |
asChild?: boolean; | ||
} | ||
|
||
export const Button: FC<ButtonProps> = forwardRef< | ||
HTMLButtonElement, | ||
ButtonProps | ||
>(({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}); | ||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Button.displayName = "Button"; | ||
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. I know there were some conversations about getting rid of 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. Ah, okay, I wasn’t aware of that. Thanks for letting me know! I’ve just been copying and pasting the default implementation and making changes only when necessary. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,12 @@ | |
*/ | ||
|
||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; | ||
import { Check, ChevronRight, Circle } from "lucide-react"; | ||
import { Button } from "components/Button/Button"; | ||
import { Check, ChevronDownIcon, ChevronRight, Circle } from "lucide-react"; | ||
import { | ||
type ComponentPropsWithoutRef, | ||
type ElementRef, | ||
type FC, | ||
type HTMLAttributes, | ||
forwardRef, | ||
} from "react"; | ||
|
@@ -196,7 +198,7 @@ export const DropdownMenuSeparator = forwardRef< | |
>(({ className, ...props }, ref) => ( | ||
<DropdownMenuPrimitive.Separator | ||
ref={ref} | ||
className={cn(["-mx-1 my-1 h-px bg-border"], className)} | ||
className={cn(["-mx-1 my-3 h-px bg-border"], className)} | ||
{...props} | ||
/> | ||
)); | ||
|
@@ -214,3 +216,23 @@ export const DropdownMenuShortcut = ({ | |
); | ||
}; | ||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"; | ||
|
||
export interface DropdownMenuButtonProps | ||
extends ComponentPropsWithoutRef<typeof Button> {} | ||
|
||
export const DropdownMenuButton = forwardRef< | ||
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. I'm wondering if it's a little confusing to have a file export both a trigger and a button, especially since the button doesn't use the trigger internally 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. Hm... I hadn’t thought of that 🤔. Honestly—maybe it’s just personal—I don’t see any confusion since a trigger is a behavioral component and a button is a visual component. To me, it feels okay to have both. What would you suggest? 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. @BrunoQuaresma It looks like you are adding DropdownMenuButton to the shadcn DropdownMenu component? Im curious why it is necessary to add this? 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 purpose of this component is to make dropdown button styling consistent. For example, instead of composing a Before: <Button ref={ref} variant="outline">
Admin settings
<DropdownMenuChevronDown />
</Button> After: <DropdownMenuButton>Admin settings</DropdownMenuButton> However, while writing this, I thought of another approach that might be better—creating a new <Button ref={ref} variant="dropdown">
Admin settings
</Button> Thoughts? 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. If every DropdownMenu component will always use the DropdownMenuButton with this styling then it could make sense. However. that may not always be the case. I personally like having a dropdown variant for the button component more than altering the DropdownMenu component. 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. I decided to remove the |
||
HTMLButtonElement, | ||
DropdownMenuButtonProps | ||
>(({ children, ...props }, ref) => { | ||
return ( | ||
<Button ref={ref} variant="outline" {...props}> | ||
{children} | ||
<DropdownMenuChevronDown /> | ||
</Button> | ||
); | ||
}); | ||
DropdownMenuButton.displayName = "DropdownMenuButton"; | ||
|
||
export const DropdownMenuChevronDown: FC = () => { | ||
return <ChevronDownIcon className="text-content-primary !size-icon-xs" />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,10 @@ | |
* { | ||
@apply border-border; | ||
} | ||
|
||
/** Related to https://github.com/radix-ui/primitives/issues/3251 */ | ||
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. Could the comment also be updated to list what components rely on this patch? |
||
html body[data-scroll-locked] { | ||
--removed-body-scroll-bar-size: 0 !important; | ||
margin-right: 0 !important; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { fn, userEvent, within } from "@storybook/test"; | ||
import { PointerEventsCheckLevel } from "@testing-library/user-event"; | ||
import type { FC } from "react"; | ||
import { chromaticWithTablet } from "testHelpers/chromatic"; | ||
import { | ||
MockPrimaryWorkspaceProxy, | ||
MockProxyLatencies, | ||
MockSupportLinks, | ||
MockUser, | ||
MockUser2, | ||
MockWorkspaceProxies, | ||
} from "testHelpers/entities"; | ||
import { MobileMenu } from "./MobileMenu"; | ||
|
||
const meta: Meta<typeof MobileMenu> = { | ||
title: "modules/dashboard/MobileMenu", | ||
parameters: { | ||
layout: "fullscreen", | ||
viewport: { | ||
defaultViewport: "iphone12", | ||
}, | ||
}, | ||
component: MobileMenu, | ||
args: { | ||
proxyContextValue: { | ||
proxy: { | ||
preferredPathAppURL: "", | ||
preferredWildcardHostname: "", | ||
proxy: MockPrimaryWorkspaceProxy, | ||
}, | ||
isLoading: false, | ||
isFetched: true, | ||
setProxy: fn(), | ||
clearProxy: fn(), | ||
refetchProxyLatencies: fn(), | ||
proxyLatencies: MockProxyLatencies, | ||
proxies: MockWorkspaceProxies, | ||
}, | ||
user: MockUser, | ||
supportLinks: MockSupportLinks, | ||
docsHref: "https://coder.com/docs", | ||
onSignOut: fn(), | ||
isDefaultOpen: true, | ||
canViewAuditLog: true, | ||
canViewDeployment: true, | ||
canViewHealth: true, | ||
canViewOrganizations: true, | ||
}, | ||
decorators: [withNavbarMock], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof MobileMenu>; | ||
|
||
export const Closed: Story = { | ||
args: { | ||
isDefaultOpen: false, | ||
}, | ||
}; | ||
|
||
export const Admin: Story = { | ||
play: openAdminSettings, | ||
}; | ||
|
||
export const Auditor: Story = { | ||
args: { | ||
user: MockUser2, | ||
canViewAuditLog: true, | ||
canViewDeployment: false, | ||
canViewHealth: false, | ||
canViewOrganizations: false, | ||
}, | ||
play: openAdminSettings, | ||
}; | ||
|
||
export const OrgAdmin: Story = { | ||
args: { | ||
user: MockUser2, | ||
canViewAuditLog: true, | ||
canViewDeployment: false, | ||
canViewHealth: false, | ||
canViewOrganizations: true, | ||
}, | ||
play: openAdminSettings, | ||
}; | ||
|
||
export const Member: Story = { | ||
args: { | ||
user: MockUser2, | ||
canViewAuditLog: false, | ||
canViewDeployment: false, | ||
canViewHealth: false, | ||
canViewOrganizations: false, | ||
}, | ||
}; | ||
|
||
export const ProxySettings: Story = { | ||
play: async ({ canvasElement }) => { | ||
const user = setupUser(); | ||
const body = within(canvasElement.ownerDocument.body); | ||
const menuItem = await body.findByRole("menuitem", { | ||
name: /workspace proxy settings/i, | ||
}); | ||
await user.click(menuItem); | ||
}, | ||
}; | ||
|
||
export const UserSettings: Story = { | ||
play: async ({ canvasElement }) => { | ||
const user = setupUser(); | ||
const body = within(canvasElement.ownerDocument.body); | ||
const menuItem = await body.findByRole("menuitem", { | ||
name: /user settings/i, | ||
}); | ||
await user.click(menuItem); | ||
}, | ||
}; | ||
|
||
function withNavbarMock(Story: FC) { | ||
return ( | ||
<div className="h-[72px] border-0 border-b border-solid px-6 flex items-center justify-end"> | ||
<Story /> | ||
</div> | ||
); | ||
} | ||
|
||
function setupUser() { | ||
// It seems the dropdown component is disabling pointer events, which is | ||
// causing Testing Library to throw an error. As a workaround, we can | ||
// disable the pointer events check. | ||
return userEvent.setup({ | ||
pointerEventsCheck: PointerEventsCheckLevel.Never, | ||
}); | ||
} | ||
|
||
async function openAdminSettings({ | ||
canvasElement, | ||
}: { canvasElement: HTMLElement }) { | ||
const user = setupUser(); | ||
const body = within(canvasElement.ownerDocument.body); | ||
const menuItem = await body.findByRole("menuitem", { | ||
name: /admin settings/i, | ||
}); | ||
await user.click(menuItem); | ||
} |
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.
I'm just now realizing: do we want the ref type to always be
HTMLButtonElement
? I'm thinking about cases like this:Where TypeScript will think it's a button, but the actual HTML node will be for an anchor. I'm not sure what properties are on one but not the other, but calling a button method that doesn't exist could blow up the app
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.
Only thing is, I'm not actually sure how you would add a generic ref type to forwardRef, since it's just a function call, and not a full function signature
I don't think this is worth blocking over, but I'll try to figure out a fix next week
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.
I think your concern is totally valid, but this is the default implementation from the shadcn/ui Button. I’d be open to changing it only if necessary, as I’d prefer not to add complexity without bringing justifiable value to us.