Skip to content
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

Added horizontal wheel scroll on tabs #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/node_modules/
/build/
/node_modules/
1 change: 0 additions & 1 deletion .gitignore.ghpages

This file was deleted.

155 changes: 155 additions & 0 deletions build/main.js

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions build/main.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
34 changes: 25 additions & 9 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function Container(props: {
tabHeight={ tabHeight }
onClickPanel={ () => handleClickedPanel(props.state, panelRect.panel, null) }
onClickTab={ (tabNumber) => handleClickedPanel(props.state, panelRect.panel, tabNumber) }
onCloseTab={ (ev, tabNumber) => handleClosedTab(ev, props.state, panelRect.panel, tabNumber) }
onCloseTab={ (ev, tabNumber) => handleClosedTab(props.state, panelRect.panel, tabNumber, ev) }
onDragHeader={ (ev, tabNumber) => handleDraggedHeader(ev, props.state, layoutRef, rectRef, panelRect.panel, tabNumber) }
/>
)}
Expand All @@ -195,9 +195,16 @@ export function Container(props: {
}}>
<Dockable.ContentContext.Provider value={{
layoutContent,

content: layoutContent.content,
setTitle: (title) => setTitle(layoutContent, title),
setPreferredSize: (w, h) => setPreferredSize(layoutContent, w, h),
close: () =>
handleClosedTab(
props.state,
layoutContent.panel,
layoutContent.tabIndex,
undefined
),
}}>
<StyledContentInner>
{ layoutContent.content.element }
Expand Down Expand Up @@ -495,15 +502,24 @@ function handleClickedPanel(


function handleClosedTab(
ev: React.MouseEvent<HTMLButtonElement, MouseEvent>,
state: Dockable.RefState<Dockable.State>,
panel: Dockable.Panel,
tabNumber: number)
tabNumber: number,
ev?: React.MouseEvent<HTMLButtonElement, MouseEvent>
)
{
ev.preventDefault()
if (ev) {
ev.preventDefault();
}

const content = panel.contentList[tabNumber]
Dockable.removeContent(state.ref.current, panel, content.contentId)
Dockable.coallesceEmptyPanels(state.ref.current)
state.commit()
const content = panel.contentList[tabNumber];

if (content && content.isClosable && !content.isClosable()) {
// Don't close the tab
return;
}

Dockable.removeContent(state.ref.current, panel, content.contentId);
Dockable.coallesceEmptyPanels(state.ref.current);
state.commit();
}
9 changes: 8 additions & 1 deletion src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react"
import React, { useRef } from "react";
import * as Dockable from "./index.js"
import styled from "styled-components"

Expand Down Expand Up @@ -52,6 +52,7 @@ const StyledTabRowInner = styled.div<{
{
width: 4px;
height: 4px;
display: none;
}

&::-webkit-scrollbar-track
Expand Down Expand Up @@ -141,6 +142,7 @@ export function ContainerPanel(props: {
})
{
const panelRect: Dockable.LayoutPanel = props.panelRect
const refTabRowInner = useRef<HTMLDivElement>(null);

const isActivePanel = props.state.ref.current.activePanel === panelRect.panel

Expand All @@ -159,6 +161,11 @@ export function ContainerPanel(props: {
draggable
tabHeight={ props.tabHeight }
tabCount={ panelRect.panel.contentList.length }
onWheel={(ev) => {
if (refTabRowInner && refTabRowInner.current)
refTabRowInner.current.scrollLeft += ev.deltaY;
ev.preventDefault();
}}
onMouseDown={ ev => {
props.onClickPanel()
props.onDragHeader(ev, null)
Expand Down
8 changes: 5 additions & 3 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ export function spawnFloatingEphemeral(

export interface ContentContextProps
{
layoutContent: Dockable.LayoutContent
layoutContent: Dockable.LayoutContent;
content: Dockable.Content;

setTitle: (title: string) => void
setPreferredSize: (w: number, h: number) => void
setTitle: (title: string) => void;
setPreferredSize: (w: number, h: number) => void;
close: () => void;
}


Expand Down
1 change: 1 addition & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface Content
{
contentId: ContentId
title: string
isClosable?: () => boolean;
element: JSX.Element
}

Expand Down