-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement drawer component to replace FullscreenModal in EntityBrowser #145
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
Open
fx
wants to merge
11
commits into
main
Choose a base branch
from
feat/143-drawer-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f971df3
feat: implement drawer component to replace FullscreenModal in Entity…
fx 83c2ff1
fix: allow all hosts in Vite dev server for custom hostnames
fx a5aea4d
fix: inherit theme appearance in Drawer portal content
fx faf950c
feat(drawer): add partial overlay support to Drawer component
fx da62dba
feat(drawer): change EntityBrowser drawer to left side with partial o…
fx 4bcd926
chore: update auto-generated route tree types
fx 48e5687
fix(drawer): use full width on mobile for left drawer
fx da4522a
fix(drawer): use absolute positioning for HA panel compatibility
fx bc4a700
fix(drawer): left drawer fills container with no borders or radius
fx adb1627
fix(drawer): remove size prop to let CSS control left drawer dimensions
fx 0c888a4
fix(drawer): use 60% width on desktop, 100% on mobile for left drawer
fx 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
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
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,136 @@ | ||
| import { forwardRef, type ReactNode } from 'react' | ||
| import * as Dialog from '@radix-ui/react-dialog' | ||
| import { Theme } from '@radix-ui/themes' | ||
| import { Cross2Icon } from '@radix-ui/react-icons' | ||
| import './drawer.css' | ||
|
|
||
| type DrawerDirection = 'left' | 'right' | 'top' | 'bottom' | ||
|
|
||
| interface DrawerProps { | ||
| /** | ||
| * Controls whether the drawer is open | ||
| */ | ||
| open: boolean | ||
| /** | ||
| * Callback when the drawer open state changes | ||
| */ | ||
| onOpenChange: (open: boolean) => void | ||
| /** | ||
| * Content to display in the drawer | ||
| */ | ||
| children: ReactNode | ||
| /** | ||
| * Direction from which the drawer slides in | ||
| * @default 'right' | ||
| */ | ||
| direction?: DrawerDirection | ||
| /** | ||
| * Whether to include the Theme wrapper. Default true for styled content. | ||
| * @default true | ||
| */ | ||
| includeTheme?: boolean | ||
| /** | ||
| * Whether clicking backdrop closes drawer. Default true. | ||
| * @default true | ||
| */ | ||
| closeOnBackdropClick?: boolean | ||
| /** | ||
| * Whether ESC key closes drawer. Default true. | ||
| * @default true | ||
| */ | ||
| closeOnEsc?: boolean | ||
| /** | ||
| * Custom width for left/right drawers or height for top/bottom drawers | ||
| */ | ||
| size?: string | ||
| /** | ||
| * Whether to show close button | ||
| * @default true | ||
| */ | ||
| showCloseButton?: boolean | ||
| /** | ||
| * Title for the drawer (for accessibility) | ||
| */ | ||
| title?: string | ||
| /** | ||
| * Description for the drawer (for accessibility) | ||
| */ | ||
| description?: string | ||
| } | ||
|
|
||
| /** | ||
| * A drawer component built on Radix UI Dialog with CSS animations. | ||
| * Provides slide-in functionality from any edge of the viewport. | ||
| * | ||
| * Features: | ||
| * - Built on Radix Dialog for proper accessibility and focus management | ||
| * - CSS-based animations for test compatibility | ||
| * - Supports all four directions | ||
| * - Portal rendering to escape shadow DOM | ||
| * - ESC key and backdrop click support | ||
| */ | ||
| export const Drawer = forwardRef<HTMLDivElement, DrawerProps>( | ||
| ( | ||
| { | ||
| open, | ||
| onOpenChange, | ||
| children, | ||
| direction = 'right', | ||
| includeTheme = true, | ||
| closeOnBackdropClick = true, | ||
| closeOnEsc = true, | ||
| size, | ||
| showCloseButton = true, | ||
| title, | ||
| description, | ||
| }, | ||
| ref | ||
| ) => { | ||
| const content = ( | ||
| <Dialog.Root open={open} onOpenChange={onOpenChange}> | ||
| <Dialog.Portal> | ||
| <Dialog.Overlay | ||
| className="drawer-overlay" | ||
| onClick={closeOnBackdropClick ? () => onOpenChange(false) : undefined} | ||
| /> | ||
| <Dialog.Content | ||
| ref={ref} | ||
| className={`drawer-content drawer-${direction}`} | ||
| style={ | ||
| size | ||
| ? { | ||
| ...(direction === 'left' || direction === 'right' | ||
| ? { width: size } | ||
| : { height: size }), | ||
| } | ||
| : undefined | ||
| } | ||
| onEscapeKeyDown={closeOnEsc ? undefined : (e) => e.preventDefault()} | ||
| onPointerDownOutside={closeOnBackdropClick ? undefined : (e) => e.preventDefault()} | ||
| onInteractOutside={closeOnBackdropClick ? undefined : (e) => e.preventDefault()} | ||
| > | ||
| {/* Always render title and description for accessibility, but hide them visually */} | ||
| <Dialog.Title className="drawer-title">{title || 'Dialog'}</Dialog.Title> | ||
| <Dialog.Description className="drawer-description"> | ||
| {description || 'Dialog content'} | ||
| </Dialog.Description> | ||
|
|
||
| {showCloseButton && ( | ||
| <Dialog.Close asChild> | ||
| <button className="drawer-close" aria-label="Close"> | ||
| <Cross2Icon /> | ||
| </button> | ||
| </Dialog.Close> | ||
| )} | ||
|
|
||
| <div className="drawer-body">{children}</div> | ||
| </Dialog.Content> | ||
| </Dialog.Portal> | ||
| </Dialog.Root> | ||
| ) | ||
|
|
||
| return includeTheme ? <Theme>{content}</Theme> : content | ||
| } | ||
| ) | ||
|
|
||
| Drawer.displayName = 'Drawer' | ||
Oops, something went wrong.
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.
The
onClickhandler on the overlay (line 94) conflicts with theonPointerDownOutsideandonInteractOutsidehandlers on the Dialog.Content (lines 109-110). WhencloseOnBackdropClickis true, clicking the overlay will trigger both the overlay'sonClick(callingonOpenChange(false)) and the Dialog's built-in outside click handlers. This creates redundant close calls.Remove the
onClickhandler from the overlay and let Radix UI's built-in outside interaction handlers manage this behavior. They already handle backdrop clicks correctly whenonPointerDownOutsideandonInteractOutsideare not prevented.