-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: Collapsible Bottom View #33441
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c44f52e
feat: Collapsible Bottom View
hetunandu 780411c
add comments
hetunandu c689177
add classnames
hetunandu 51c1340
Merge branch 'refs/heads/release' into feat/collapsible-bottom-view
hetunandu e54befb
fix for JS editor
hetunandu 28fd251
fix selector
hetunandu bcafdd1
use tabs instead
hetunandu 30ecce4
Review comments
hetunandu 49fcdc8
min height
hetunandu 5c1add8
Merge branch 'refs/heads/release' into feat/collapsible-bottom-view
hetunandu 72a8ba7
init test
hetunandu c32cea1
add tests
hetunandu 46b8d48
Merge branch 'refs/heads/release' into feat/collapsible-bottom-view
hetunandu 8f3b96e
Fix classname change
hetunandu 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 hidden or 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 hidden or 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,153 @@ | ||
| import React, { useEffect, useRef, useState } from "react"; | ||
| import styled from "styled-components"; | ||
| import Resizer, { | ||
| ResizerCSS, | ||
| } from "components/editorComponents/Debugger/Resizer"; | ||
| import { CodeEditorWithGutterStyles } from "pages/Editor/JSEditor/constants"; | ||
| import { ViewHideBehaviour, ViewDisplayMode } from "IDE/Interfaces/View"; | ||
| import { Button } from "design-system"; | ||
|
|
||
| const VIEW_MIN_HEIGHT = 38; | ||
|
|
||
| const Container = styled.div<{ displayMode: ViewDisplayMode }>` | ||
| ${ResizerCSS}; | ||
| width: 100%; | ||
| background-color: var(--ads-v2-color-bg); | ||
| border-top: 1px solid var(--ads-v2-color-border); | ||
| ${(props) => { | ||
| switch (props.displayMode) { | ||
| case ViewDisplayMode.OVERLAY: | ||
| return ` | ||
| position: absolute; | ||
| bottom: 0; | ||
| `; | ||
| } | ||
| }} | ||
| `; | ||
|
|
||
| const ViewWrapper = styled.div` | ||
| height: 100%; | ||
| &&& { | ||
| ul.ads-v2-tabs__list { | ||
| margin: 0 ${(props) => props.theme.spaces[11]}px; | ||
| height: ${VIEW_MIN_HEIGHT}px; | ||
| } | ||
| } | ||
|
|
||
| & { | ||
| .ads-v2-tabs__list { | ||
| padding: var(--ads-v2-spaces-1) var(--ads-v2-spaces-7); | ||
| } | ||
| } | ||
|
|
||
| & { | ||
| .ads-v2-tabs__panel { | ||
| ${CodeEditorWithGutterStyles}; | ||
| overflow-y: auto; | ||
| height: 100%; | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const MIN_HEIGHT = { | ||
| [ViewHideBehaviour.COLLAPSE]: `${VIEW_MIN_HEIGHT}px`, | ||
| [ViewHideBehaviour.CLOSE]: "0px", | ||
| }; | ||
|
|
||
| interface Props { | ||
| className?: string; | ||
| behaviour: ViewHideBehaviour; | ||
| displayMode?: ViewDisplayMode; | ||
| height: number; | ||
| setHeight: (height: number) => void; | ||
| hidden: boolean; | ||
| onHideClick: () => void; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const ViewHideButton = styled(Button)` | ||
| &.view-hide-button { | ||
| position: absolute; | ||
| top: 3px; | ||
| right: 0; | ||
| padding: 9px 11px; | ||
| } | ||
| `; | ||
|
|
||
| interface ViewHideProps { | ||
| hideBehaviour: ViewHideBehaviour; | ||
| isHidden: boolean; | ||
| onToggle: () => void; | ||
| } | ||
|
|
||
| const ViewHide = (props: ViewHideProps) => { | ||
| const [icon, setIcon] = useState(() => { | ||
| return props.hideBehaviour === ViewHideBehaviour.CLOSE | ||
| ? "close-modal" | ||
| : "arrow-down-s-line"; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (props.hideBehaviour === ViewHideBehaviour.COLLAPSE) { | ||
| if (props.isHidden) { | ||
| setIcon("arrow-up-s-line"); | ||
| } else { | ||
| setIcon("arrow-down-s-line"); | ||
| } | ||
| } | ||
| }, [props.isHidden]); | ||
|
|
||
| return ( | ||
| <ViewHideButton | ||
| className="view-hide-button" | ||
| data-testid="t--view-hide-button" | ||
| isIconButton | ||
| kind="tertiary" | ||
| onClick={props.onToggle} | ||
| size="md" | ||
| startIcon={icon} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const BottomView = (props: Props) => { | ||
| const panelRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| // Handle the height of the tabs when toggling the hidden state | ||
| useEffect(() => { | ||
| const panel = panelRef.current; | ||
| if (!panel) return; | ||
| if (props.hidden) { | ||
| panel.style.height = MIN_HEIGHT[props.behaviour]; | ||
| } else { | ||
| panel.style.height = `${props.height}px`; | ||
| } | ||
| }, [props.hidden, props.behaviour]); | ||
|
|
||
| return ( | ||
| <Container | ||
| className={`select-text ${props.className}`} | ||
| displayMode={props.displayMode || ViewDisplayMode.BLOCK} | ||
| ref={panelRef} | ||
| > | ||
| {!props.hidden && ( | ||
| <Resizer | ||
| initialHeight={props.height} | ||
| minHeight={VIEW_MIN_HEIGHT + 50} | ||
| onResizeComplete={props.setHeight} | ||
| panelRef={panelRef} | ||
| /> | ||
| )} | ||
| <ViewWrapper> | ||
| {props.children} | ||
| <ViewHide | ||
| hideBehaviour={props.behaviour} | ||
| isHidden={props.hidden} | ||
| onToggle={props.onHideClick} | ||
| /> | ||
| </ViewWrapper> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default BottomView; | ||
This file contains hidden or 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,26 @@ | ||
| /** | ||
| * Close: | ||
| * - View is not visible at all | ||
| * - View is not interactable till opened again | ||
| * | ||
| * Collapse: | ||
| * - View is visible but cannot be resized | ||
| * - Top part of the view is visible with open to reopen it | ||
| * - Children can have extra view that changes when hidden that can have different behaviours | ||
| */ | ||
| export enum ViewHideBehaviour { | ||
| CLOSE = "CLOSE", | ||
| COLLAPSE = "COLLAPSE", | ||
| } | ||
|
|
||
| /** | ||
| * OVERLAY: | ||
| * - Sets an absolute position to make the view render on top of other components | ||
| * | ||
| * BLOCK: | ||
| * - Sets a block position to make the view rendered next to other components | ||
| */ | ||
| export enum ViewDisplayMode { | ||
| OVERLAY = "OVERLAY", | ||
| BLOCK = "BLOCK", | ||
| } |
This file contains hidden or 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.
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.
Consider using a named constant for the minimum height value.
To improve code readability and maintainability, consider using a named constant for the minimum height value, as suggested in previous comments.
Committable suggestion