Skip to content

Commit b6ff6fb

Browse files
yuzhang9804Innei
andauthored
feat: add support for pointer cursor (#517)
* feat: add support for pointer cursor (cherry picked from commit dcabf91) * fix: correct useEffect update (cherry picked from commit cbf0a82) * feat: remove default values * feat: pointer cursor Signed-off-by: Innei <i@innei.in> * fix: remove select content animation when position is `item-aligned` Signed-off-by: Innei <i@innei.in> * update hover Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in> Co-authored-by: Innei <i@innei.in>
1 parent 4dadd31 commit b6ff6fb

File tree

34 files changed

+97
-49
lines changed

34 files changed

+97
-49
lines changed

apps/renderer/src/atoms/settings/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const createDefaultSettings = (): UISettings => ({
1919
modalDraggable: true,
2020
modalOpaque: true,
2121
reduceMotion: false,
22+
usePointerCursor: false,
2223

2324
// Font
2425
uiFontFamily: "SN Pro",

apps/renderer/src/components/common/ShadowDOM.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const ShadowDOM: FC<PropsWithChildren<React.HTMLProps<HTMLElement>>> & {
103103

104104
const uiFont = useUISettingKey("uiFontFamily")
105105
const reduceMotion = useReduceMotion()
106+
const usePointerCursor = useUISettingKey("usePointerCursor")
106107

107108
return (
108109
<root.div {...rest}>
@@ -111,8 +112,9 @@ export const ShadowDOM: FC<PropsWithChildren<React.HTMLProps<HTMLElement>>> & {
111112
style={useMemo(
112113
() => ({
113114
fontFamily: `${uiFont},"SN Pro", system-ui, sans-serif`,
115+
"--pointer": usePointerCursor ? "pointer" : "default",
114116
}),
115-
[uiFont],
117+
[uiFont, usePointerCursor],
116118
)}
117119
id="shadow-html"
118120
data-motion-reduce={reduceMotion}

apps/renderer/src/components/ui/button/variants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cn } from "~/lib/utils"
77

88
export const styledButtonVariant = cva(
99
[
10-
"inline-flex cursor-default select-none items-center justify-center gap-2 outline-offset-2 transition active:transition-none disabled:cursor-not-allowed",
10+
"inline-flex cursor-button select-none items-center justify-center gap-2 outline-offset-2 transition active:transition-none disabled:cursor-not-allowed",
1111
"ring-accent/20 duration-200 disabled:ring-0",
1212
"align-middle",
1313
],

apps/renderer/src/components/ui/context-menu/context-menu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ContextMenuSubTrigger = React.forwardRef<
2424
<ContextMenuPrimitive.SubTrigger
2525
ref={ref}
2626
className={cn(
27-
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[state=open]:bg-theme-item-hover data-[state=open]:text-theme-foreground",
27+
"flex cursor-menu select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[state=open]:bg-theme-item-hover data-[state=open]:text-theme-foreground",
2828
inset && "pl-8",
2929
"center gap-2",
3030
className,
@@ -81,7 +81,7 @@ const ContextMenuItem = React.forwardRef<
8181
<ContextMenuPrimitive.Item
8282
ref={ref}
8383
className={cn(
84-
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
84+
"relative flex cursor-menu select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
8585
"focus-within:outline-transparent data-[highlighted]:bg-theme-item-hover dark:data-[highlighted]:bg-neutral-800",
8686
inset && "pl-8",
8787
className,
@@ -98,7 +98,7 @@ const ContextMenuCheckboxItem = React.forwardRef<
9898
<ContextMenuPrimitive.CheckboxItem
9999
ref={ref}
100100
className={cn(
101-
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
101+
"relative flex cursor-checkbox select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-theme-item-hover focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
102102
"focus-within:outline-transparent",
103103
className,
104104
)}

apps/renderer/src/components/ui/dropdown-menu/dropdown-menu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
2424
<DropdownMenuPrimitive.SubTrigger
2525
ref={ref}
2626
className={cn(
27-
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover data-[state=open]:bg-theme-item-active",
27+
"flex cursor-menu select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-theme-item-hover data-[state=open]:bg-theme-item-active",
2828
inset && "pl-8",
2929
className,
3030
)}
@@ -80,7 +80,7 @@ const DropdownMenuItem = React.forwardRef<
8080
<DropdownMenuPrimitive.Item
8181
ref={ref}
8282
className={cn(
83-
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-theme-item-hover data-[disabled]:pointer-events-none data-[state=open]:bg-theme-item-active data-[disabled]:opacity-50",
83+
"relative flex cursor-menu select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-theme-item-hover data-[disabled]:pointer-events-none data-[state=open]:bg-theme-item-active data-[disabled]:opacity-50",
8484
inset && "pl-8",
8585
"focus-within:!outline-transparent",
8686
className,
@@ -104,7 +104,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
104104
<DropdownMenuPrimitive.CheckboxItem
105105
ref={ref}
106106
className={cn(
107-
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-theme-item-hover data-[disabled]:pointer-events-none data-[state=open]:bg-theme-item-active data-[disabled]:opacity-50",
107+
"relative flex cursor-menu select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-theme-item-hover data-[disabled]:pointer-events-none data-[state=open]:bg-theme-item-active data-[disabled]:opacity-50",
108108
className,
109109
)}
110110
checked={checked}

apps/renderer/src/components/ui/media.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const MediaImpl: FC<MediaProps> = ({
108108
onError={errorHandle}
109109
className={cn(
110110
!(props.width || props.height) && "size-full",
111-
"bg-gray-200 object-cover duration-200 dark:bg-neutral-800",
111+
"cursor-card bg-gray-200 object-cover duration-200 dark:bg-neutral-800",
112112
popper && "cursor-zoom-in",
113113
mediaLoadState === "loaded" ? "opacity-100" : "opacity-0",
114114

@@ -126,7 +126,7 @@ const MediaImpl: FC<MediaProps> = ({
126126
className={cn(
127127
"center",
128128
!(props.width || props.height) && "size-full",
129-
"relative bg-stone-100 object-cover",
129+
"relative cursor-card bg-stone-100 object-cover",
130130
mediaContainerClassName,
131131
)}
132132
onClick={handleClick}

apps/renderer/src/components/ui/media/SwipeMedia.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function SwipeMedia({
5959
<div
6060
ref={hoverRef}
6161
className={cn(
62-
"relative flex w-full items-center overflow-hidden",
62+
"relative flex w-full items-center overflow-hidden ",
6363
styles["swipe-wrapper"],
6464
className,
6565
)}

apps/renderer/src/components/ui/select.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const SelectTrigger = React.forwardRef<
2222
"ring-accent/20 duration-200 focus:border-accent/80 focus:outline-none focus:ring-2",
2323
"border border-border",
2424
size === "sm" ? "h-7 p-2 text-sm" : "h-9 px-3 py-2 text-sm",
25+
"hover:border-accent/80",
2526
className,
2627
)}
2728
{...props}
@@ -40,7 +41,7 @@ const SelectScrollUpButton = React.forwardRef<
4041
>(({ className, ...props }, ref) => (
4142
<SelectPrimitive.ScrollUpButton
4243
ref={ref}
43-
className={cn("flex cursor-default items-center justify-center py-1", className)}
44+
className={cn("flex cursor-select items-center justify-center py-1", className)}
4445
{...props}
4546
>
4647
<i className="i-mingcute-up-line" />
@@ -54,7 +55,7 @@ const SelectScrollDownButton = React.forwardRef<
5455
>(({ className, ...props }, ref) => (
5556
<SelectPrimitive.ScrollDownButton
5657
ref={ref}
57-
className={cn("flex cursor-default items-center justify-center py-1", className)}
58+
className={cn("flex cursor-select items-center justify-center py-1", className)}
5859
{...props}
5960
>
6061
<i className="i-mingcute-down-line" />
@@ -70,9 +71,11 @@ const SelectContent = React.forwardRef<
7071
<SelectPrimitive.Content
7172
ref={ref}
7273
className={cn(
73-
"shadow-perfect relative z-[1000] max-h-96 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
74-
position === "popper" &&
74+
"shadow-perfect relative z-[1000] max-h-96 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground",
75+
position === "popper" && [
7576
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
77+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
78+
],
7679
className,
7780
)}
7881
position={position}
@@ -113,7 +116,7 @@ const SelectItem = React.forwardRef<
113116
<SelectPrimitive.Item
114117
ref={ref}
115118
className={cn(
116-
"pointer-events-auto relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-theme-item-active focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
119+
"pointer-events-auto relative flex w-full cursor-select items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-theme-item-active focus:text-theme-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
117120
className,
118121
)}
119122
{...props}

apps/renderer/src/components/ui/switch.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ const Switch = React.forwardRef<
99
>(({ className, ...props }, ref) => (
1010
<SwitchPrimitives.Root
1111
className={cn(
12-
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
12+
"peer inline-flex h-5 w-9 shrink-0 cursor-switch items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
1313
"duration-200 data-[state=checked]:bg-accent data-[state=unchecked]:bg-theme-inactive dark:data-[state=unchecked]:bg-theme-accent-100/10",
14+
"hover:data-[state=unchecked]:bg-theme-inactive/80 dark:hover:data-[state=unchecked]:bg-theme-accent-100/15",
15+
"hover:data-[state=checked]:bg-accent/80 dark:hover:data-[state=checked]:bg-accent",
16+
"group",
1417
className,
1518
)}
1619
{...props}
1720
ref={ref}
1821
>
19-
<SwitchPrimitives.Thumb className="pointer-events-none block size-4 rounded-full bg-background ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0" />
22+
<SwitchPrimitives.Thumb className="pointer-events-none block size-4 rounded-full bg-background ring-0 transition-transform duration-200 data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0 group-hover:dark:data-[state=checked]:!bg-black/80" />
2023
</SwitchPrimitives.Root>
2124
))
2225
Switch.displayName = SwitchPrimitives.Root.displayName

apps/renderer/src/initialize/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import duration from "dayjs/plugin/duration"
77
import localizedFormat from "dayjs/plugin/localizedFormat"
88
import relativeTime from "dayjs/plugin/relativeTime"
99
import { enableMapSet } from "immer"
10+
import React from "react"
11+
import ReactDOM from "react-dom"
1012
import { toast } from "sonner"
1113

1214
import { getUISettings } from "~/atoms/settings/ui"
@@ -119,6 +121,10 @@ export const initializeApp = async () => {
119121
data_hydrated_time: dataHydratedTime,
120122
version: APP_VERSION,
121123
})
124+
125+
// expose `React` `ReactDOM` to global, it's easier for developers to make plugins
126+
window.React = React
127+
window.ReactDOM = ReactDOM
122128
}
123129

124130
import.meta.hot?.dispose(cleanup)

0 commit comments

Comments
 (0)