-
-
Notifications
You must be signed in to change notification settings - Fork 458
Sidebar resize react panels #1870
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
Open
KanishJebaMathewM
wants to merge
14
commits into
maplibre:main
Choose a base branch
from
KanishJebaMathewM:sidebar-resize-react-panels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
08e73f6
feat: add adjustable sidebar width with drag handles
sank64 b33a920
Merge branch 'main' into feature/sidebar-resize
HarelM 7219c55
fix: address review feedback driver pattern, i18n titles, inline sty…
sank64 a2c5acf
Merge branch 'main' into feature/sidebar-resize
sank64 28f5a4b
feat: implement sidebar resizing using react-resizable-panels
KanishJebaMathewM fbea51a
Add Chinese and French translations for resize UI strings
KanishJebaMathewM be05842
updated translations
KanishJebaMathewM b099797
e22e test passing
KanishJebaMathewM 5aebb40
Merge branch 'main' into sidebar-resize-react-panels
HarelM 7267aac
test: replace cy.visit with helper.when.visit based on PR feedback
KanishJebaMathewM f64fe0b
test: move pointer drag events to helper
KanishJebaMathewM 631220c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 35a05ab
Merge branch 'main' into sidebar-resize-react-panels
HarelM 167977e
test: reset react-resizable-panels storage between tests
KanishJebaMathewM 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
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,44 @@ | ||
| import { MaputnikDriver } from "./maputnik-driver"; | ||
|
|
||
| describe("sidebar resize", () => { | ||
| const { beforeAndAfter, get, when, then } = new MaputnikDriver(); | ||
| beforeAndAfter(); | ||
|
|
||
| beforeEach(() => { | ||
| when.setStyle("both"); | ||
| }); | ||
|
|
||
| it("resize handle is visible", () => { | ||
| then(get.elementByTestId("sidebar-resize-handle")).shouldBeVisible(); | ||
| }); | ||
|
|
||
| it("inner resize handle is visible", () => { | ||
| then(get.elementByTestId("inner-resize-handle")).shouldBeVisible(); | ||
| }); | ||
|
|
||
| it("dragging the handle changes sidebar width", () => { | ||
| get.element(".maputnik-layout-list").then(($list) => { | ||
| const initialWidth = $list[0].getBoundingClientRect().width; | ||
|
|
||
| when.pointerDrag("sidebar-resize-handle", 100); | ||
|
|
||
| get.element(".maputnik-layout-list").should(($listAfter) => { | ||
| const newWidth = $listAfter[0].getBoundingClientRect().width; | ||
| expect(newWidth).to.be.greaterThan(initialWidth); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it("dragging inner handle changes list/drawer split", () => { | ||
| get.element(".maputnik-layout-list").then(($list) => { | ||
| const initialWidth = $list[0].getBoundingClientRect().width; | ||
|
|
||
| when.pointerDrag("inner-resize-handle", 80); | ||
|
|
||
| get.element(".maputnik-layout-list").should(($listAfter) => { | ||
| const newWidth = $listAfter[0].getBoundingClientRect().width; | ||
| expect(newWidth).to.be.greaterThan(initialWidth); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,54 +1,144 @@ | ||
| import React from "react"; | ||
| import React, {useEffect, useState} from "react"; | ||
| import {Group, Panel, Separator, useDefaultLayout} from "react-resizable-panels"; | ||
| import ScrollContainer from "./ScrollContainer"; | ||
| import { type WithTranslation, withTranslation } from "react-i18next"; | ||
| import { IconContext } from "react-icons"; | ||
| import {useTranslation} from "react-i18next"; | ||
| import {IconContext} from "react-icons"; | ||
|
|
||
| type AppLayoutInternalProps = { | ||
| const DEFAULT_LIST_WIDTH = 200; | ||
| const DEFAULT_DRAWER_WIDTH = 370; | ||
| const DEFAULT_SIDEBAR_WIDTH = DEFAULT_LIST_WIDTH + DEFAULT_DRAWER_WIDTH; | ||
| const DEFAULT_LIST_RATIO = DEFAULT_LIST_WIDTH / DEFAULT_SIDEBAR_WIDTH; | ||
|
|
||
| const SIDEBAR_LAYOUT_STORAGE_ID = "maputnik:sidebar-layout"; | ||
| const SIDEBAR_INNER_LAYOUT_STORAGE_ID = "maputnik:sidebar-inner-layout"; | ||
| const SIDEBAR_PANEL_ID = "sidebar"; | ||
| const MAP_PANEL_ID = "map"; | ||
| const LIST_PANEL_ID = "list"; | ||
| const DRAWER_PANEL_ID = "drawer"; | ||
|
|
||
| const getDefaultSidebarPercent = () => { | ||
| const viewportWidth = window.innerWidth || DEFAULT_SIDEBAR_WIDTH; | ||
| return Math.min(100, (DEFAULT_SIDEBAR_WIDTH / viewportWidth) * 100); | ||
| }; | ||
|
|
||
| const getDefaultListPercent = () => DEFAULT_LIST_RATIO * 100; | ||
|
|
||
| type AppLayoutProps = { | ||
| toolbar: React.ReactElement | ||
| layerList: React.ReactElement | ||
| layerEditor?: React.ReactElement | ||
| codeEditor?: React.ReactElement | ||
| map: React.ReactElement | ||
| bottom?: React.ReactElement | ||
| modals?: React.ReactNode | ||
| } & WithTranslation; | ||
|
|
||
| class AppLayoutInternal extends React.Component<AppLayoutInternalProps> { | ||
|
|
||
| render() { | ||
| document.body.dir = this.props.i18n.dir(); | ||
|
|
||
| return <IconContext.Provider value={{size: "14px"}}> | ||
| <div className="maputnik-layout"> | ||
| {this.props.toolbar} | ||
| <div className="maputnik-layout-main"> | ||
| {this.props.codeEditor && <div className="maputnik-layout-code-editor"> | ||
| <ScrollContainer> | ||
| {this.props.codeEditor} | ||
| </ScrollContainer> | ||
| </div> | ||
| } | ||
| {!this.props.codeEditor && <> | ||
| <div className="maputnik-layout-list"> | ||
| {this.props.layerList} | ||
| </div> | ||
| <div className="maputnik-layout-drawer"> | ||
| <ScrollContainer> | ||
| {this.props.layerEditor} | ||
| </ScrollContainer> | ||
| </div> | ||
| </>} | ||
| {this.props.map} | ||
| </div> | ||
| {this.props.bottom && <div className="maputnik-layout-bottom"> | ||
| {this.props.bottom} | ||
| </div> | ||
| } | ||
| {this.props.modals} | ||
| }; | ||
|
|
||
| export default function AppLayout(props: AppLayoutProps) { | ||
| const {t, i18n} = useTranslation(); | ||
|
|
||
| const sidebarLayout = useDefaultLayout({ | ||
| id: SIDEBAR_LAYOUT_STORAGE_ID, | ||
| panelIds: [SIDEBAR_PANEL_ID, MAP_PANEL_ID], | ||
| }); | ||
| const sidebarInnerLayout = useDefaultLayout({ | ||
| id: SIDEBAR_INNER_LAYOUT_STORAGE_ID, | ||
| panelIds: [LIST_PANEL_ID, DRAWER_PANEL_ID], | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| document.body.dir = i18n.dir(); | ||
| }, [i18n]); | ||
|
|
||
| const [sidebarSize, setSidebarSize] = useState<number>( | ||
| () => sidebarLayout.defaultLayout?.[SIDEBAR_PANEL_ID] ?? getDefaultSidebarPercent() | ||
| ); | ||
| const [listSize, setListSize] = useState<number>( | ||
| () => sidebarInnerLayout.defaultLayout?.[LIST_PANEL_ID] ?? getDefaultListPercent() | ||
| ); | ||
|
|
||
| return <IconContext.Provider value={{size: "14px"}}> | ||
| <div className="maputnik-layout" style={{ | ||
| "--sidebar-list-width": `${listSize}%`, | ||
| "--sidebar-drawer-width": `${100 - listSize}%`, | ||
| "--sidebar-total-width": `${sidebarSize}%`, | ||
| } as React.CSSProperties}> | ||
| {props.toolbar} | ||
| <div className="maputnik-layout-main"> | ||
| <Group | ||
| className="maputnik-layout-panels" | ||
| orientation="horizontal" | ||
| id={SIDEBAR_LAYOUT_STORAGE_ID} | ||
| defaultLayout={sidebarLayout.defaultLayout} | ||
| onLayoutChanged={(layout) => { | ||
| setSidebarSize(layout[SIDEBAR_PANEL_ID] ?? sidebarSize); | ||
| sidebarLayout.onLayoutChanged(layout); | ||
| }} | ||
| > | ||
| <Panel | ||
| id={SIDEBAR_PANEL_ID} | ||
| className={props.codeEditor ? "maputnik-layout-code-editor" : "maputnik-layout-sidebar"} | ||
| defaultSize="570px" | ||
| minSize="280px" | ||
| > | ||
| {props.codeEditor ? <ScrollContainer> | ||
| {props.codeEditor} | ||
| </ScrollContainer> : <Group | ||
| className="maputnik-layout-sidebar-panels" | ||
| orientation="horizontal" | ||
| id={SIDEBAR_INNER_LAYOUT_STORAGE_ID} | ||
| defaultLayout={sidebarInnerLayout.defaultLayout} | ||
| onLayoutChanged={(layout) => { | ||
| setListSize(layout[LIST_PANEL_ID] ?? listSize); | ||
| sidebarInnerLayout.onLayoutChanged(layout); | ||
| }} | ||
| > | ||
| <Panel | ||
| id={LIST_PANEL_ID} | ||
| className="maputnik-layout-list" | ||
| defaultSize={`${getDefaultListPercent()}%`} | ||
| groupResizeBehavior="preserve-relative-size" | ||
| minSize="100px" | ||
| > | ||
| {props.layerList} | ||
| </Panel> | ||
| <Separator | ||
| className="maputnik-layout-resize-handle maputnik-layout-resize-handle--inner" | ||
| data-wd-key="inner-resize-handle" | ||
| title={t("Drag to resize list / editor split")} | ||
| aria-label={t("Drag to resize list / editor split")} | ||
| /> | ||
| <Panel | ||
| id={DRAWER_PANEL_ID} | ||
| className="maputnik-layout-drawer" | ||
| defaultSize={`${100 - getDefaultListPercent()}%`} | ||
| minSize="150px" | ||
| > | ||
| <ScrollContainer> | ||
| {props.layerEditor} | ||
| </ScrollContainer> | ||
| </Panel> | ||
| </Group>} | ||
| </Panel> | ||
| <Separator | ||
| className="maputnik-layout-resize-handle" | ||
| data-wd-key="sidebar-resize-handle" | ||
| title={t("Drag to resize sidebar")} | ||
| aria-label={t("Drag to resize sidebar")} | ||
| /> | ||
| <Panel | ||
| id={MAP_PANEL_ID} | ||
| className="maputnik-layout-map" | ||
| minSize={0} | ||
| > | ||
| {props.map} | ||
| </Panel> | ||
| </Group> | ||
| </div> | ||
| </IconContext.Provider>; | ||
| } | ||
| {props.bottom && <div className="maputnik-layout-bottom"> | ||
| {props.bottom} | ||
| </div> | ||
| } | ||
| {props.modals} | ||
| </div> | ||
| </IconContext.Provider>; | ||
| } | ||
|
|
||
| const AppLayout = withTranslation()(AppLayoutInternal); | ||
| export default AppLayout; |
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
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.
No need to add this, this is part of the feature...