-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
141 additions
and
147 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,29 @@ | ||
import Icon from "app/core/Icon" | ||
import React from "react" | ||
import {showContextMenu} from "src/js/lib/System" | ||
import styled from "styled-components" | ||
import {toMenu} from "./action-button" | ||
import {GUTTER} from "./action-buttons" | ||
import Button from "./button" | ||
|
||
const Menu = styled(Button)` | ||
padding-right: 3px; | ||
min-width: 22px; | ||
flex-shrink: 0; | ||
margin-left: ${GUTTER / 2}px; | ||
.icon i svg { | ||
width: 9px; | ||
height: 9px; | ||
} | ||
` | ||
|
||
export default function ActionMenu({actions}) { | ||
if (actions.length === 0) return null | ||
return ( | ||
<Menu | ||
icon={<Icon name="double-chevron-right" />} | ||
onClick={() => showContextMenu(toMenu(actions))} | ||
/> | ||
) | ||
} |
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,25 @@ | ||
import MeasureLayer from "app/core/MeasureLayer" | ||
import React from "react" | ||
import ActionButtons from "./action-buttons" | ||
import ActionMenu from "./action-menu" | ||
import useVisibleActions from "./hooks/useVisibleActions" | ||
|
||
/** | ||
* We must measure how big this component will be if all the actions are visible | ||
* to set correct flex basis. This is the "fullWidth" var you see below. | ||
*/ | ||
export default function Actions({actions}) { | ||
const {visible, hidden, fullWidth, setMeasure, setParent} = useVisibleActions( | ||
actions | ||
) | ||
|
||
return ( | ||
<> | ||
<MeasureLayer> | ||
<ActionButtons actions={actions} innerRef={setMeasure} /> | ||
</MeasureLayer> | ||
<ActionButtons actions={visible} innerRef={setParent} width={fullWidth} /> | ||
<ActionMenu actions={hidden} /> | ||
</> | ||
) | ||
} |
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,35 @@ | ||
import useContentRect from "app/core/hooks/useContentRect" | ||
import {useLayoutEffect, useState} from "react" | ||
import useCallbackRef from "src/js/components/hooks/useCallbackRef" | ||
import {GUTTER} from "../action-buttons" | ||
|
||
export default function useVisibleActions(actions) { | ||
const [visible, setVisible] = useState([]) | ||
const [hidden, setHidden] = useState([]) | ||
const [fullWidth, setFullWidth] = useState(0) | ||
const [measure, setMeasure] = useCallbackRef() | ||
const [rect, setParent] = useContentRect() | ||
const actualWidth = Math.ceil(rect.width) + GUTTER | ||
|
||
useLayoutEffect(() => { | ||
let widths = [] | ||
if (measure) { | ||
setFullWidth(measure.clientWidth) | ||
widths = Array.from(measure.children).map((c) => c.clientWidth) | ||
} | ||
|
||
let offset = 0 | ||
let index = 0 | ||
for (let childWidth of widths) { | ||
offset += childWidth + GUTTER | ||
if (offset > actualWidth) break | ||
index++ | ||
} | ||
const copy = [...actions] | ||
const nextHidden = copy.splice(index) | ||
setVisible(copy) | ||
setHidden(nextHidden) | ||
}, [actions, measure, actualWidth]) | ||
|
||
return {visible, hidden, fullWidth, setMeasure, setParent} | ||
} |
This file was deleted.
Oops, something went wrong.
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