-
Notifications
You must be signed in to change notification settings - Fork 178
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(protocol-designer): make timeline responsive #17109
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a3a0bae
add draggable sidebar component for timeline
koji 31e12fd
Merge branch 'edge' into feat_add-resizeable-sidebar
koji 6f81ca4
update add step button
koji f7d013a
Merge branch 'edge' into feat_add-resizeable-sidebar
koji 041bda1
modify icon position with sidebarWidth
koji 7e7127e
fix hotkey info position issue
koji 37a66db
fix empty spacing issue
koji 892b2cc
restore flex to keep the fixed two col
koji 1856da6
Merge branch 'edge' into feat_add-resizeable-sidebar
koji d79b7ee
fix check-js errors
koji 9b88d76
modify a component name
koji 8c96b57
fix test error
koji e5dcda6
add test
koji 5daede5
fix check-js errors
koji 996fde6
added a base test
koji 7b99baf
fix format errors
koji ea625d2
clean up draggable sidebar a little bit
koji ad6b69e
Merge branch 'feat_add-resizeable-sidebar' of https://github.com/Open…
koji 3671140
address feedback
koji 0cf372b
fix check-js errors
koji e2711d9
Merge branch 'edge' into feat_add-resizeable-sidebar
koji eca5df7
fix check-js error
koji 25bc420
resolve the pointed-out UI issues
koji 7d2fbed
Merge branch 'edge' into feat_add-resizeable-sidebar
koji 22538f2
remove unused lines
koji 8237107
fix lint errors
koji bcaf94b
fix check-js errors
koji f6525ac
modify styles a little bit
koji 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 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
119 changes: 119 additions & 0 deletions
119
protocol-designer/src/pages/Designer/ProtocolSteps/DraggableSidebar.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,119 @@ | ||
import { useState, useRef, useCallback, useEffect } from 'react' | ||
import styled from 'styled-components' | ||
import { | ||
Box, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
DISPLAY_FLEX, | ||
Flex, | ||
JUSTIFY_SPACE_BETWEEN, | ||
} from '@opentrons/components' | ||
import { TimelineToolbox } from './Timeline/TimelineToolbox' | ||
|
||
const INITIAL_SIDEBAR_WIDTH = 276 | ||
const MIN_SIDEBAR_WIDTH = 80 | ||
const MAX_SIDEBAR_WIDTH = 350 | ||
|
||
interface DraggableSidebarProps { | ||
setTargetWidth: (width: number) => void | ||
} | ||
|
||
// Note (kk:2024/12/20 the designer will revisit responsive sidebar design in 2025 | ||
// we will need to update the details to align with the updated design | ||
export function DraggableSidebar({ | ||
setTargetWidth, | ||
}: DraggableSidebarProps): JSX.Element { | ||
const sidebarRef = useRef<HTMLDivElement>(null) | ||
const [isResizing, setIsResizing] = useState(false) | ||
const [sidebarWidth, setSidebarWidth] = useState(INITIAL_SIDEBAR_WIDTH) | ||
|
||
const startResizing = useCallback(() => { | ||
setIsResizing(true) | ||
}, []) | ||
|
||
const stopResizing = useCallback(() => { | ||
setIsResizing(false) | ||
}, []) | ||
|
||
const resize = useCallback( | ||
(mouseMoveEvent: MouseEvent) => { | ||
if (isResizing && sidebarRef.current != null) { | ||
const newWidth = | ||
mouseMoveEvent.clientX - | ||
sidebarRef.current.getBoundingClientRect().left | ||
|
||
if (newWidth >= MIN_SIDEBAR_WIDTH && newWidth <= MAX_SIDEBAR_WIDTH) { | ||
setSidebarWidth(newWidth) | ||
setTargetWidth(newWidth) | ||
} | ||
} | ||
}, | ||
[isResizing, setTargetWidth] | ||
) | ||
|
||
useEffect(() => { | ||
window.addEventListener('mousemove', resize) | ||
window.addEventListener('mouseup', stopResizing) | ||
|
||
return () => { | ||
window.removeEventListener('mousemove', resize) | ||
window.removeEventListener('mouseup', stopResizing) | ||
} | ||
}, [resize, stopResizing]) | ||
|
||
return ( | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
justifyContent={JUSTIFY_SPACE_BETWEEN} | ||
height="100%" | ||
> | ||
<SidebarContainer ref={sidebarRef} resizedWidth={sidebarWidth}> | ||
<SidebarContent> | ||
<TimelineToolbox sidebarWidth={sidebarWidth} /> | ||
</SidebarContent> | ||
<SidebarResizer dragging={isResizing} onMouseDown={startResizing} /> | ||
</SidebarContainer> | ||
</Flex> | ||
) | ||
} | ||
|
||
const SidebarContainer = styled(Box)` | ||
display: ${DISPLAY_FLEX}; | ||
flex-direction: ${DIRECTION_COLUMN}; | ||
border-right: 1px solid #ccc; | ||
position: relative; | ||
/* overflow: hidden; */ | ||
height: 100%; | ||
` | ||
|
||
const SidebarContent = styled(Flex)` | ||
flex: 1; | ||
` | ||
|
||
interface SidebarResizerProps { | ||
dragging: boolean | ||
} | ||
|
||
const SidebarResizer = styled(Flex)<SidebarResizerProps>` | ||
user-select: none; | ||
width: 2px; | ||
cursor: ew-resize; | ||
background-color: #ddd; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
margin: 0; | ||
padding: 0; | ||
transition: background-color 0.2s ease; | ||
|
||
&:hover { | ||
background-color: ${COLORS.blue50}; /* Hover state */ | ||
} | ||
|
||
${props => | ||
props.dragging === true && | ||
` | ||
background-color: ${COLORS.blue55}; /* Dragging state */ | ||
`} | ||
` |
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.
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.
Do we have a constant for this?
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.
you mean box-shadow or the entire style?
i think we don't have the constant for this part.