-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TitleBar): ActionButton, ActionButtonBar, used to make responsiv…
…e title bar - if there is a long title, truncate and show and ellipsis. If the title is long, and you click it, it expands to show the full title - Action buttons in the ActionBar look at the width of the div, if they are too large to fit in the width, they collapse to the hamburger.
- Loading branch information
Showing
11 changed files
with
294 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react' | ||
import ActionButton, { ActionButtonProps } from './ActionButton' | ||
import Hamburger from './Hamburger' | ||
import classNames from 'classnames' | ||
import sizeMe, { SizeMeProps } from 'react-sizeme' | ||
|
||
interface ActionButtonBarProps { | ||
data: ActionButtonProps[] | ||
size: SizeMeProps['size'] | ||
} | ||
|
||
const ActionButtonBar: React.FunctionComponent<ActionButtonBarProps> = (props) => { | ||
const { data, size } = props | ||
if (data.length === 0) return null | ||
if (size.width && size.width < 40) { | ||
return <Hamburger data={data} /> | ||
} | ||
const [areVisible, setAreVisible] = React.useState<boolean[]>(data.map(() => true)) | ||
|
||
const [buttonSizes, setButtonSizes] = React.useState<number[]>(data.map(() => 0)) | ||
|
||
const handleSize = (width: number | null, index: number) => { | ||
setButtonSizes((prev: number[]) => { | ||
if (width === null) return prev | ||
let buttonSizes = prev.slice() | ||
buttonSizes[index] = width | ||
return buttonSizes | ||
}) | ||
} | ||
|
||
const buttons = data.map((d: ActionButtonProps, i: number) => | ||
<div className={classNames({ 'closed': !areVisible[i] })} key={i}> | ||
<ActionButton icon={d.icon} onClick={d.onClick} text={d.text} onSize={(size: { width: number | null, height: number | null }) => handleSize(size.width, i)}/> | ||
</div> | ||
) | ||
|
||
React.useEffect(() => { | ||
console.log(size) | ||
console.log(buttonSizes) | ||
if (size.width === null) return | ||
|
||
let cumulativeSize = 40 // hamburger width | ||
for (let i = 0; i < data.length; i++) { | ||
cumulativeSize += buttonSizes[i] | ||
// if the cumulativeSize is larger then size, set all the buttons before this | ||
// point visible, and after this point not visible. | ||
if (cumulativeSize > size.width) { | ||
setAreVisible((prev: boolean[]) => { | ||
return prev.map((val: boolean, j: number) => j < i) | ||
}) | ||
break | ||
} | ||
if (i === data.length - 1) { | ||
setAreVisible((prev: boolean[]) => prev.map(() => true)) | ||
} | ||
} | ||
}, [size, buttonSizes]) | ||
return ( | ||
<div className='action-button-bar'> | ||
{buttons} | ||
{/* If any are not visible, show the hamburger */} | ||
{areVisible.some((val: boolean) => val === false) && <Hamburger data={data.filter((d: ActionButtonProps, i: number) => { | ||
if (!areVisible[i]) return d | ||
else return undefined | ||
})}/>} | ||
</div> | ||
) | ||
} | ||
|
||
export default sizeMe()(ActionButtonBar) |
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
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
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
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.