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

feat(react): add floating panel #2651

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/react/.storybook/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
@import url("./styles/toggle-group.css");
@import url("./styles/tooltip.css");
@import url("./styles/tree-view.css");
@import url("./styles/floating-panel.css");
90 changes: 90 additions & 0 deletions packages/react/.storybook/styles/floating-panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[data-scope='floating-panel'] button {
appearance: none;
border: 1px solid black;
margin: 0;
padding: 0;
}
[data-scope='floating-panel'][data-part='content'] {
box-shadow:
rgba(0, 0, 0, 0.28) 0px 16px 18px 0px,
rgba(0, 0, 0, 0.12) 0px 4px 16px 0px;
outline: 0 !important;
background-color: white;
display: flex;
flex-direction: column;

&[data-topmost] {
z-index: 999999;
}

&[data-behind] {
opacity: 0.4;
}
}

[data-scope='floating-panel'][data-part='body'] {
position: relative;
overflow: auto;
flex: 1 1 auto;
padding-block: 16px;
padding-inline: 16px;
background-color: white;
}

[data-scope='floating-panel'][data-part='header'] {
padding-block: 16px;
padding-inline: 16px;
background-color: #f5f5f5;
border-bottom: 1px solid #ebebeb;
display: flex;
justify-content: space-between;
align-items: center;
}

[data-scope='floating-panel'][data-part='header'] button {
width: 24px;
height: 24px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 14px;
padding: 0;
svg {
width: 1em;
height: 1em;
}
}

[data-scope='floating-panel'][data-part='trigger-group'] {
display: flex;
align-items: center;
gap: 8px;
}

[data-scope='floating-panel'][data-part='resize-trigger'] {
background-color: rgba(154, 18, 18, 0.396);

&[data-axis='n'],
&[data-axis='s'] {
height: 6px;
max-width: 90%;
}

&[data-axis='e'],
&[data-axis='w'] {
width: 6px;
max-height: 90%;
}

&[data-axis='ne'],
&[data-axis='nw'],
&[data-axis='se'],
&[data-axis='sw'] {
width: 10px;
height: 10px;
}
}

[hidden] {
display: none !important;
}
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
"@zag-js/editable": "0.74.2",
"@zag-js/file-upload": "0.74.2",
"@zag-js/file-utils": "0.74.2",
"@zag-js/floating-panel": "0.74.2",
"@zag-js/highlight-word": "0.74.2",
"@zag-js/hover-card": "0.74.2",
"@zag-js/i18n-utils": "0.74.2",
Expand Down
45 changes: 45 additions & 0 deletions packages/react/src/components/floating-panel/examples/basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ArrowDownLeft, Maximize2, Minus, XIcon } from 'lucide-react'
import { FloatingPanel, Portal } from '../..'

export const Basic = () => (
<FloatingPanel.Root>
<FloatingPanel.Trigger>Toggle Panel</FloatingPanel.Trigger>
<Portal>
<FloatingPanel.Positioner>
<FloatingPanel.Content>
<FloatingPanel.DragTrigger>
<FloatingPanel.Header>
<FloatingPanel.Title>Floating Panel</FloatingPanel.Title>
<div data-scope="floating-panel" data-part="trigger-group">
<FloatingPanel.MinimizeTrigger>
<Minus />
</FloatingPanel.MinimizeTrigger>
<FloatingPanel.MaximizeTrigger>
<Maximize2 />
</FloatingPanel.MaximizeTrigger>
<FloatingPanel.RestoreTrigger>
<ArrowDownLeft />
</FloatingPanel.RestoreTrigger>
<FloatingPanel.CloseTrigger>
<XIcon />
</FloatingPanel.CloseTrigger>
</div>
</FloatingPanel.Header>
</FloatingPanel.DragTrigger>
<FloatingPanel.Body>
<p>Some content</p>
</FloatingPanel.Body>

<FloatingPanel.ResizeTrigger axis="n" />
<FloatingPanel.ResizeTrigger axis="e" />
<FloatingPanel.ResizeTrigger axis="w" />
<FloatingPanel.ResizeTrigger axis="s" />
<FloatingPanel.ResizeTrigger axis="ne" />
<FloatingPanel.ResizeTrigger axis="se" />
<FloatingPanel.ResizeTrigger axis="sw" />
<FloatingPanel.ResizeTrigger axis="nw" />
</FloatingPanel.Content>
</FloatingPanel.Positioner>
</Portal>
</FloatingPanel.Root>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ArrowDownLeft, Maximize2, Minus, XIcon } from 'lucide-react'
import { useState } from 'react'
import { FloatingPanel, Portal } from '../..'

export const Controlled = () => {
const [isOpen, setIsOpen] = useState(false)

return (
<FloatingPanel.Root open={isOpen} onOpenChange={(e) => setIsOpen(e.open)}>
<FloatingPanel.Trigger onClick={() => setIsOpen(true)}>Toggle Panel</FloatingPanel.Trigger>
<Portal>
<FloatingPanel.Positioner>
<FloatingPanel.Content>
<FloatingPanel.DragTrigger>
<FloatingPanel.Header>
<FloatingPanel.Title>Floating Panel</FloatingPanel.Title>
<div data-scope="floating-panel" data-part="trigger-group">
<FloatingPanel.MinimizeTrigger>
<Minus />
</FloatingPanel.MinimizeTrigger>
<FloatingPanel.MaximizeTrigger>
<Maximize2 />
</FloatingPanel.MaximizeTrigger>
<FloatingPanel.RestoreTrigger>
<ArrowDownLeft />
</FloatingPanel.RestoreTrigger>
<FloatingPanel.CloseTrigger>
<XIcon />
</FloatingPanel.CloseTrigger>
</div>
</FloatingPanel.Header>
</FloatingPanel.DragTrigger>
<FloatingPanel.Body>
<p>Some content</p>
</FloatingPanel.Body>

<FloatingPanel.ResizeTrigger axis="n" />
<FloatingPanel.ResizeTrigger axis="e" />
<FloatingPanel.ResizeTrigger axis="w" />
<FloatingPanel.ResizeTrigger axis="s" />
<FloatingPanel.ResizeTrigger axis="ne" />
<FloatingPanel.ResizeTrigger axis="se" />
<FloatingPanel.ResizeTrigger axis="sw" />
<FloatingPanel.ResizeTrigger axis="nw" />
</FloatingPanel.Content>
</FloatingPanel.Positioner>
</Portal>
</FloatingPanel.Root>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FloatingPanel, Portal } from '../..'

import { ArrowDownLeft, Maximize2, Minus, XIcon } from 'lucide-react'

export const LazyMount = () => (
<FloatingPanel.Root lazyMount onExitComplete={() => console.log('onExitComplete invoked')}>
<FloatingPanel.Trigger>Toggle Panel</FloatingPanel.Trigger>
<Portal>
<FloatingPanel.Positioner>
<FloatingPanel.Content>
<FloatingPanel.DragTrigger>
<FloatingPanel.Header>
<FloatingPanel.Title>Floating Panel</FloatingPanel.Title>
<div data-scope="floating-panel" data-part="trigger-group">
<FloatingPanel.MinimizeTrigger>
<Minus />
</FloatingPanel.MinimizeTrigger>
<FloatingPanel.MaximizeTrigger>
<Maximize2 />
</FloatingPanel.MaximizeTrigger>
<FloatingPanel.RestoreTrigger>
<ArrowDownLeft />
</FloatingPanel.RestoreTrigger>
<FloatingPanel.CloseTrigger>
<XIcon />
</FloatingPanel.CloseTrigger>
</div>
</FloatingPanel.Header>
</FloatingPanel.DragTrigger>
<FloatingPanel.Body>
<p>Some content</p>
</FloatingPanel.Body>

<FloatingPanel.ResizeTrigger axis="n" />
<FloatingPanel.ResizeTrigger axis="e" />
<FloatingPanel.ResizeTrigger axis="w" />
<FloatingPanel.ResizeTrigger axis="s" />
<FloatingPanel.ResizeTrigger axis="ne" />
<FloatingPanel.ResizeTrigger axis="se" />
<FloatingPanel.ResizeTrigger axis="sw" />
<FloatingPanel.ResizeTrigger axis="nw" />
</FloatingPanel.Content>
</FloatingPanel.Positioner>
</Portal>
</FloatingPanel.Root>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ArrowDownLeft, Maximize2, Minus, XIcon } from 'lucide-react'
import { FloatingPanel, Portal } from '../..'

export const RenderFn = () => (
<FloatingPanel.Root>
<FloatingPanel.Trigger>Toggle Panel</FloatingPanel.Trigger>
<Portal>
<FloatingPanel.Positioner>
<FloatingPanel.Content>
<FloatingPanel.DragTrigger>
<FloatingPanel.Header>
<FloatingPanel.Title>Floating Panel</FloatingPanel.Title>
<div data-scope="floating-panel" data-part="trigger-group">
<FloatingPanel.MinimizeTrigger>
<Minus />
</FloatingPanel.MinimizeTrigger>
<FloatingPanel.MaximizeTrigger>
<Maximize2 />
</FloatingPanel.MaximizeTrigger>
<FloatingPanel.RestoreTrigger>
<ArrowDownLeft />
</FloatingPanel.RestoreTrigger>
<FloatingPanel.CloseTrigger>
<XIcon />
</FloatingPanel.CloseTrigger>
</div>
</FloatingPanel.Header>
</FloatingPanel.DragTrigger>
<FloatingPanel.Body>
<p>Some content</p>
</FloatingPanel.Body>

<FloatingPanel.ResizeTrigger axis="n" />
<FloatingPanel.ResizeTrigger axis="e" />
<FloatingPanel.ResizeTrigger axis="w" />
<FloatingPanel.ResizeTrigger axis="s" />
<FloatingPanel.ResizeTrigger axis="ne" />
<FloatingPanel.ResizeTrigger axis="se" />
<FloatingPanel.ResizeTrigger axis="sw" />
<FloatingPanel.ResizeTrigger axis="nw" />
</FloatingPanel.Content>
</FloatingPanel.Positioner>
</Portal>
<FloatingPanel.Context>
{(floatingPanel) => <p>floatingPanel. is {floatingPanel.open ? 'open' : 'closed'}</p>}
</FloatingPanel.Context>
</FloatingPanel.Root>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mergeProps } from '@zag-js/react'
import { forwardRef } from 'react'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'
import { useFloatingPanelContext } from './use-floating-panel-context'

export interface FloatingPanelBodyBaseProps extends PolymorphicProps {}
export interface FloatingPanelBodyProps extends HTMLProps<'div'>, FloatingPanelBodyBaseProps {}

export const FloatingPanelBody = forwardRef<HTMLDivElement, FloatingPanelBodyProps>(
(props, ref) => {
const floatingPanel = useFloatingPanelContext()
const mergedProps = mergeProps(floatingPanel.getBodyProps(), props)

return <ark.div {...mergedProps} ref={ref} />
},
)

FloatingPanelBody.displayName = 'FloatingPanelBody'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { mergeProps } from '@zag-js/react'
import { forwardRef } from 'react'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'
import { useFloatingPanelContext } from './use-floating-panel-context'

export interface FloatingPanelCloseTriggerBaseProps extends PolymorphicProps {}
export interface FloatingPanelCloseTriggerProps
extends HTMLProps<'button'>,
FloatingPanelCloseTriggerBaseProps {}

export const FloatingPanelCloseTrigger = forwardRef<
HTMLButtonElement,
FloatingPanelCloseTriggerProps
>((props, ref) => {
const floatingPanel = useFloatingPanelContext()
const mergedProps = mergeProps(floatingPanel.getCloseTriggerProps(), props)

return <ark.button {...mergedProps} ref={ref} />
})

FloatingPanelCloseTrigger.displayName = 'FloatingPanelCloseTrigger'
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { mergeProps } from '@zag-js/react'
import { forwardRef } from 'react'
import { composeRefs } from '../../utils/compose-refs'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'
import { usePresenceContext } from '../presence'
import { useFloatingPanelContext } from './use-floating-panel-context'

export interface FloatingPanelContentBaseProps extends PolymorphicProps {}
export interface FloatingPanelContentProps
extends HTMLProps<'div'>,
FloatingPanelContentBaseProps {}

export const FloatingPanelContent = forwardRef<HTMLDivElement, FloatingPanelContentProps>(
(props, ref) => {
const floatingPanel = useFloatingPanelContext()
const presence = usePresenceContext()
const mergedProps = mergeProps(
floatingPanel.getContentProps(),
presence.getPresenceProps(),
props,
)

if (presence.unmounted) {
return null
}

return <ark.div {...mergedProps} ref={composeRefs(presence.ref, ref)} />
},
)

FloatingPanelContent.displayName = 'FloatingPanelContent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ReactNode } from 'react'
import { type UseFloatingPanelContext, useFloatingPanelContext } from './use-floating-panel-context'

export interface FloatingPanelContextProps {
children: (context: UseFloatingPanelContext) => ReactNode
}

export const FloatingPanelContext = (props: FloatingPanelContextProps) =>
props.children(useFloatingPanelContext())
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { forwardRef } from 'react'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'

export interface FloatingPanelDockBaseProps extends PolymorphicProps {}
export interface FloatingPanelDockProps extends HTMLProps<'div'>, FloatingPanelDockBaseProps {}

export const FloatingPanelDock = forwardRef<HTMLDivElement, FloatingPanelDockProps>(
(props, ref) => {
return <ark.div data-scope="floating-panel" data-part="dock" {...props} ref={ref} />
},
)

FloatingPanelDock.displayName = 'FloatingPanelDock'
Loading