mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: reset sidebar width on double click resize handler
This commit is contained in:
parent
88e506cac7
commit
16eb77be63
3 changed files with 17 additions and 3 deletions
|
|
@ -5,13 +5,20 @@ import { Size } from './SideBarBodyWrapper'
|
|||
type Props = {
|
||||
size: Size
|
||||
onResize(size: Size): void
|
||||
onResetSize?(): void
|
||||
onResizeStateChange?(state: ResizeState): void
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
type ResizeState = 'idle' | 'resizing'
|
||||
|
||||
export function HorizontalResizeHandler({ onResize, onResizeStateChange, size, style }: Props) {
|
||||
export function HorizontalResizeHandler({
|
||||
onResize,
|
||||
onResetSize,
|
||||
onResizeStateChange,
|
||||
size,
|
||||
style,
|
||||
}: Props) {
|
||||
const pointerDown = React.useRef(false)
|
||||
const startX = React.useRef(0)
|
||||
const baseSize = React.useRef(size)
|
||||
|
|
@ -51,7 +58,12 @@ export function HorizontalResizeHandler({ onResize, onResizeStateChange, size, s
|
|||
}, [])
|
||||
|
||||
return (
|
||||
<div className={'gitako-resize-handler'} onMouseDown={onPointerDown} style={style}>
|
||||
<div
|
||||
className={'gitako-resize-handler'}
|
||||
onMouseDown={onPointerDown}
|
||||
onDoubleClick={onResetSize}
|
||||
style={style}
|
||||
>
|
||||
<Icon type={'grabber'} className={'grabber-icon'} size={20} />
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { HorizontalResizeHandler } from 'components/ResizeHandler'
|
|||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import * as React from 'react'
|
||||
import { useDebounce, useWindowSize } from 'react-use'
|
||||
import { defaultConfigs } from 'utils/config/helper'
|
||||
import { cx } from 'utils/cx'
|
||||
import { setResizingState } from 'utils/DOMHelper'
|
||||
import * as features from 'utils/features'
|
||||
|
|
@ -69,6 +70,7 @@ export function SideBarBodyWrapper({
|
|||
{features.resize && (
|
||||
<HorizontalResizeHandler
|
||||
onResize={onResize}
|
||||
onResetSize={() => setSize(defaultConfigs.sideBarWidth)}
|
||||
onResizeStateChange={state => {
|
||||
blockLeaveRef.current = state === 'resizing'
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ enum configKeys {
|
|||
sidebarToggleMode = 'sidebarToggleMode',
|
||||
}
|
||||
|
||||
const defaultConfigs: Config = {
|
||||
export const defaultConfigs: Config = {
|
||||
sideBarWidth: 260,
|
||||
shortcut: undefined,
|
||||
accessToken: '',
|
||||
|
|
|
|||
Loading…
Reference in a new issue