-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move display options to icon button in header (#1138)
- Loading branch information
1 parent
d899e73
commit b0911b1
Showing
12 changed files
with
214 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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 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
87 changes: 87 additions & 0 deletions
87
packages/web/src/javascripts/Components/ContentListView/Header/ContentListHeader.tsx
This file contains 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,87 @@ | ||
import { WebApplication } from '@/Application/Application' | ||
import { Disclosure, DisclosurePanel } from '@reach/disclosure' | ||
import { memo, useCallback, useRef, useState } from 'react' | ||
import Icon from '../../Icon/Icon' | ||
import { DisplayOptionsMenuPositionProps } from './DisplayOptionsMenuProps' | ||
import DisplayOptionsMenuPortal from './DisplayOptionsMenuPortal' | ||
import StyledDisplayOptionsButton from './StyledDisplayOptionsButton' | ||
|
||
type Props = { | ||
application: { | ||
getPreference: WebApplication['getPreference'] | ||
setPreference: WebApplication['setPreference'] | ||
} | ||
panelTitle: string | ||
addButtonLabel: string | ||
addNewItem: () => void | ||
isFilesSmartView: boolean | ||
optionsSubtitle?: string | ||
} | ||
|
||
const ContentListHeader = ({ | ||
application, | ||
panelTitle, | ||
addButtonLabel, | ||
addNewItem, | ||
isFilesSmartView, | ||
optionsSubtitle, | ||
}: Props) => { | ||
const [displayOptionsMenuPosition, setDisplayOptionsMenuPosition] = useState<DisplayOptionsMenuPositionProps>() | ||
const displayOptionsContainerRef = useRef<HTMLDivElement>(null) | ||
const displayOptionsButtonRef = useRef<HTMLButtonElement>(null) | ||
|
||
const [showDisplayOptionsMenu, setShowDisplayOptionsMenu] = useState(false) | ||
|
||
const toggleDisplayOptionsMenu = useCallback(() => { | ||
if (displayOptionsButtonRef.current) { | ||
const buttonBoundingRect = displayOptionsButtonRef.current.getBoundingClientRect() | ||
setDisplayOptionsMenuPosition({ | ||
top: buttonBoundingRect.bottom, | ||
left: buttonBoundingRect.right - buttonBoundingRect.width, | ||
}) | ||
} | ||
|
||
setShowDisplayOptionsMenu((show) => !show) | ||
}, []) | ||
|
||
return ( | ||
<div className="section-title-bar-header"> | ||
<div className="flex flex-col"> | ||
<div className="text-lg font-semibold title">{panelTitle}</div> | ||
{optionsSubtitle && <div className="text-xs color-passive-0">{optionsSubtitle}</div>} | ||
</div> | ||
<div className="flex"> | ||
<div className="relative" ref={displayOptionsContainerRef}> | ||
<Disclosure open={showDisplayOptionsMenu} onChange={toggleDisplayOptionsMenu}> | ||
<StyledDisplayOptionsButton pressed={showDisplayOptionsMenu} ref={displayOptionsButtonRef}> | ||
<Icon type="sort-descending" className="w-5 h-5" /> | ||
</StyledDisplayOptionsButton> | ||
<DisclosurePanel> | ||
{showDisplayOptionsMenu && displayOptionsMenuPosition && ( | ||
<DisplayOptionsMenuPortal | ||
application={application} | ||
closeDisplayOptionsMenu={toggleDisplayOptionsMenu} | ||
containerRef={displayOptionsContainerRef} | ||
isOpen={showDisplayOptionsMenu} | ||
isFilesSmartView={isFilesSmartView} | ||
top={displayOptionsMenuPosition.top} | ||
left={displayOptionsMenuPosition.left} | ||
/> | ||
)} | ||
</DisclosurePanel> | ||
</Disclosure> | ||
</div> | ||
<button | ||
className="flex justify-center items-center min-w-8 h-8 ml-3 bg-info hover:brightness-130 color-info-contrast border-1 border-solid border-transparent rounded-full cursor-pointer" | ||
title={addButtonLabel} | ||
aria-label={addButtonLabel} | ||
onClick={addNewItem} | ||
> | ||
<Icon type="add" className="w-5 h-5" /> | ||
</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default memo(ContentListHeader) |
This file contains 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
Oops, something went wrong.