-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
384 additions
and
115 deletions.
There are no files selected for viewing
This file contains 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 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 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
43 changes: 43 additions & 0 deletions
43
src/renderer/src/components/resizable-panel/DragHandler.tsx
This file contains 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,43 @@ | ||
import { Component } from "solid-js"; | ||
import { useResizablePanel } from "./ResizablePanel"; | ||
import { cn } from "@renderer/lib/css.utils"; | ||
|
||
type DragHandlerProps = { | ||
class?: string; | ||
}; | ||
export const DragHandler: Component<DragHandlerProps> = (props) => { | ||
const state = useResizablePanel(); | ||
|
||
return ( | ||
<div | ||
onPointerDown={(event) => { | ||
const target = event.target as HTMLElement; | ||
target.setPointerCapture(event.pointerId); | ||
event.preventDefault(); | ||
|
||
state.handlePointerStart(event); | ||
}} | ||
onPointerMove={(event) => { | ||
const target = event.target as HTMLElement; | ||
if (!target.hasPointerCapture(event.pointerId)) { | ||
return; | ||
} | ||
|
||
state.handlePointerMove(event); | ||
}} | ||
onPointerUp={(event) => { | ||
const target = event.target as HTMLElement; | ||
if (target.hasPointerCapture(event.pointerId)) { | ||
target.releasePointerCapture(event.pointerId); | ||
state.handlePointerEnd(); | ||
} | ||
}} | ||
class={cn( | ||
"opacity-0 hover:opacity-100 h-full w-4 translate-x-[-50%] cursor-w-resize flex flex-col items-center justify-center", | ||
props.class, | ||
)} | ||
> | ||
<div class="bg-white/60 flex-1 w-0.5" /> | ||
</div> | ||
); | ||
}; |
97 changes: 97 additions & 0 deletions
97
src/renderer/src/components/resizable-panel/ResizablePanel.tsx
This file contains 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,97 @@ | ||
import { Accessor, createContext, ParentComponent, useContext } from "solid-js"; | ||
import { DragHandler } from "./DragHandler"; | ||
import useControllableState from "@renderer/lib/controllable-state"; | ||
import { DOMElement } from "solid-js/jsx-runtime"; | ||
import { clamp } from "@renderer/lib/tungsten/math"; | ||
|
||
const DEFAULT_RESIZABLE_PANEL_VALUE = 100; | ||
const DEFAULT_MIN = 0; | ||
const DEFAULT_MAX = Infinity; | ||
|
||
type Event = PointerEvent & { | ||
currentTarget: HTMLDivElement; | ||
target: DOMElement; | ||
}; | ||
|
||
export type Props = { | ||
min?: number; | ||
max?: number; | ||
|
||
offsetFromPanel?: number; | ||
|
||
defaultValue?: number; | ||
value?: Accessor<number>; | ||
onValueChange?: (newValue: number) => void; | ||
onValueCommit?: (value: number) => void; | ||
onValueStart?: () => void; | ||
}; | ||
|
||
export type Context = ReturnType<typeof useProviderValue>; | ||
function useProviderValue(props: Props) { | ||
let startDragValue: number | undefined; | ||
const [value, setValue] = useControllableState({ | ||
defaultProp: props.defaultValue ?? DEFAULT_RESIZABLE_PANEL_VALUE, | ||
prop: props.value, | ||
onChange: props.onValueChange, | ||
}); | ||
|
||
const getValueFromPointer = (pointerPosition: number) => { | ||
if (!startDragValue) { | ||
return; | ||
} | ||
|
||
const min = props.min ?? DEFAULT_MIN; | ||
const max = props.max ?? DEFAULT_MAX; | ||
|
||
const value = pointerPosition - (props.offsetFromPanel ?? 0); | ||
return clamp(min, max, value); | ||
}; | ||
|
||
const handlePointerStart = (event: Event) => { | ||
startDragValue = value(); | ||
const newValue = getValueFromPointer(event.clientX); | ||
if (typeof newValue === "undefined") { | ||
return; | ||
} | ||
|
||
setValue(newValue); | ||
props.onValueStart?.(); | ||
}; | ||
const handlePointerMove = (event: Event) => { | ||
const newValue = getValueFromPointer(event.clientX); | ||
if (typeof newValue === "undefined") { | ||
return; | ||
} | ||
|
||
setValue(newValue); | ||
}; | ||
const handlePointerEnd = () => { | ||
props.onValueCommit?.(value()); | ||
}; | ||
|
||
return { value, handlePointerStart, handlePointerMove, handlePointerEnd }; | ||
} | ||
|
||
export const ResizablePanelContext = createContext<Context>(); | ||
const ResizablePanelRoot: ParentComponent<Props> = (props) => { | ||
const value = useProviderValue(props); | ||
return ( | ||
<ResizablePanelContext.Provider value={value}>{props.children}</ResizablePanelContext.Provider> | ||
); | ||
}; | ||
|
||
export function useResizablePanel(): Context { | ||
const state = useContext(ResizablePanelContext); | ||
if (!state) { | ||
throw new Error( | ||
"useResizablePanel needs to be used inisde of the `ResizablePanelContext` component.", | ||
); | ||
} | ||
return state; | ||
} | ||
|
||
const ResizablePanel = Object.assign(ResizablePanelRoot, { | ||
DragHandler, | ||
}); | ||
|
||
export default ResizablePanel; |
This file contains 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
11 changes: 11 additions & 0 deletions
11
src/renderer/src/components/song/song-item/SongItemAnimations.ts
This file contains 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,11 @@ | ||
export const songItemAnimations = { | ||
keyframes: { | ||
"song-item-slide-in": { | ||
from: { transform: "translateX(100%)", opacity: 0 }, | ||
to: { transform: "translateX(0)", opacity: 1 }, | ||
}, | ||
}, | ||
animation: { | ||
"song-item-slide-in": "song-item-slide-in 160ms cubic-bezier(0.4, 0, 0.2, 1) forwards", | ||
}, | ||
}; |
This file contains 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.