Skip to content

Commit 01482f6

Browse files
feat(core): expand plugin tabs when no plugin selected (#81)
1 parent 433a47f commit 01482f6

File tree

5 files changed

+75
-21
lines changed

5 files changed

+75
-21
lines changed

packages/devtools/src/components/main-panel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export const MainPanel = (props: {
3232
styles().devtoolsPanelContainerResizing(props.isResizing),
3333
)}
3434
>
35-
<DrawClientProvider>{props.children}</DrawClientProvider>
35+
<DrawClientProvider animationMs={400}>
36+
{props.children}
37+
</DrawClientProvider>
3638
</div>
3739
)
3840
}

packages/devtools/src/context/draw-context.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
1-
import { createContext, createSignal, useContext } from 'solid-js'
1+
import {
2+
createContext,
3+
createMemo,
4+
createSignal,
5+
onCleanup,
6+
useContext,
7+
} from 'solid-js'
28
import type { ParentComponent } from 'solid-js'
39

4-
const useDraw = () => {
5-
const [activeMenuHover, setActiveMenuHover] = createSignal<boolean>(false)
10+
const useDraw = (props: { animationMs: number }) => {
11+
const [activeHover, setActiveHover] = createSignal<boolean>(false)
12+
const [forceExpand, setForceExpand] = createSignal<boolean>(false)
13+
14+
const expanded = createMemo(() => activeHover() || forceExpand())
15+
616
let hoverTimeout: ReturnType<typeof setTimeout> | null = null
17+
onCleanup(() => {
18+
if (hoverTimeout) clearTimeout(hoverTimeout)
19+
})
720

821
const hoverUtils = {
922
enter: () => {
1023
if (hoverTimeout) {
1124
clearTimeout(hoverTimeout)
1225
hoverTimeout = null
1326
}
14-
setActiveMenuHover(true)
27+
setActiveHover(true)
1528
},
1629

1730
leave: () => {
1831
hoverTimeout = setTimeout(() => {
19-
setActiveMenuHover(false)
20-
}, 400)
32+
setActiveHover(false)
33+
}, props.animationMs)
2134
},
2235
}
2336

24-
return { activeMenuHover, hoverUtils }
37+
return {
38+
expanded,
39+
setForceExpand,
40+
hoverUtils,
41+
animationMs: props.animationMs,
42+
}
2543
}
2644

2745
type ContextType = ReturnType<typeof useDraw>
2846

2947
const DrawContext = createContext<ContextType | undefined>(undefined)
3048

31-
export const DrawClientProvider: ParentComponent = (props) => {
32-
const value = useDraw()
49+
export const DrawClientProvider: ParentComponent<{
50+
animationMs: number
51+
}> = (props) => {
52+
const value = useDraw({ animationMs: props.animationMs })
3353

3454
return (
3555
<DrawContext.Provider value={value}>{props.children}</DrawContext.Provider>

packages/devtools/src/context/use-devtools-context.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createMemo, useContext } from 'solid-js'
1+
import { createEffect, createMemo, useContext } from 'solid-js'
22
import { DevtoolsContext } from './devtools-context.jsx'
3-
/* import type { DevtoolsPlugin } from './devtools-context' */
3+
import { useDrawContext } from './draw-context.jsx'
4+
45
import type { DevtoolsStore } from './devtools-store.js'
56

67
/**
@@ -19,10 +20,19 @@ const useDevtoolsContext = () => {
1920

2021
export const usePlugins = () => {
2122
const { store, setStore } = useDevtoolsContext()
23+
const { setForceExpand } = useDrawContext()
2224

2325
const plugins = createMemo(() => store.plugins)
2426
const activePlugin = createMemo(() => store.state.activePlugin)
2527

28+
createEffect(() => {
29+
if (activePlugin() == null) {
30+
setForceExpand(false)
31+
} else {
32+
setForceExpand(true)
33+
}
34+
})
35+
2636
const setActivePlugin = (pluginId: string) => {
2737
setStore((prev) => ({
2838
...prev,

packages/devtools/src/styles/use-styles.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { tokens } from './tokens'
44
import type { TanStackDevtoolsConfig } from '../context/devtools-context'
55
import type { Accessor } from 'solid-js'
66

7+
const mSecondsToCssSeconds = (mSeconds: number) =>
8+
`${(mSeconds / 1000).toFixed(2)}s`
9+
710
const stylesFactory = () => {
811
const { colors, font, size, alpha, border } = tokens
912
const { fontFamily, size: fontSize } = font
@@ -231,26 +234,37 @@ const stylesFactory = () => {
231234
height: 100%;
232235
overflow: hidden;
233236
`,
237+
234238
pluginsTabDraw: css`
235239
width: 0px;
236240
height: 100%;
237241
background-color: ${colors.darkGray[800]};
238242
box-shadow: 0 1px 0 ${colors.gray[700]};
239-
transition: width 0.3s ease;
240243
`,
241244
pluginsTabDrawExpanded: css`
242245
width: ${size[48]};
243246
border-right: 1px solid ${colors.gray[700]};
244247
`,
248+
pluginsTabDrawTransition: (mSeconds: number) => {
249+
return css`
250+
transition: width ${mSecondsToCssSeconds(mSeconds)} ease;
251+
`
252+
},
253+
245254
pluginsTabSidebar: css`
246255
width: ${size[48]};
247256
overflow-y: auto;
248-
transition: transform 0.3s ease;
249257
transform: translateX(-100%);
250258
`,
251259
pluginsTabSidebarExpanded: css`
252260
transform: translateX(0);
253261
`,
262+
pluginsTabSidebarTransition: (mSeconds: number) => {
263+
return css`
264+
transition: transform ${mSecondsToCssSeconds(mSeconds)} ease;
265+
`
266+
},
267+
254268
pluginName: css`
255269
font-size: ${fontSize.xs};
256270
font-family: ${fontFamily.sans};

packages/devtools/src/tabs/plugins-tab.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from '../constants'
77

88
export const PluginsTab = () => {
99
const { plugins, activePlugin, setActivePlugin } = usePlugins()
10-
const { activeMenuHover, hoverUtils } = useDrawContext()
10+
const { expanded, hoverUtils, animationMs } = useDrawContext()
1111
let activePluginRef: HTMLDivElement | undefined
1212

1313
createEffect(() => {
@@ -23,9 +23,13 @@ export const PluginsTab = () => {
2323
return (
2424
<div class={styles().pluginsTabPanel}>
2525
<div
26-
class={clsx(styles().pluginsTabDraw, {
27-
[styles().pluginsTabDrawExpanded]: activeMenuHover(),
28-
})}
26+
class={clsx(
27+
styles().pluginsTabDraw,
28+
{
29+
[styles().pluginsTabDrawExpanded]: expanded(),
30+
},
31+
styles().pluginsTabDrawTransition(animationMs),
32+
)}
2933
onMouseEnter={() => {
3034
hoverUtils.enter()
3135
}}
@@ -34,9 +38,13 @@ export const PluginsTab = () => {
3438
}}
3539
>
3640
<div
37-
class={clsx(styles().pluginsTabSidebar, {
38-
[styles().pluginsTabSidebarExpanded]: activeMenuHover(),
39-
})}
41+
class={clsx(
42+
styles().pluginsTabSidebar,
43+
{
44+
[styles().pluginsTabSidebarExpanded]: expanded(),
45+
},
46+
styles().pluginsTabSidebarTransition(animationMs),
47+
)}
4048
>
4149
<For each={plugins()}>
4250
{(plugin) => {

0 commit comments

Comments
 (0)