-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: resign `<Input />` Signed-off-by: Innei <[email protected]> * fix: unify styles and prevent `esc` to trigger input event Signed-off-by: Innei <[email protected]> * fix: adjust button height Signed-off-by: Innei <[email protected]> * fix: unify button style Signed-off-by: Innei <[email protected]> * fix: popover button Signed-off-by: Innei <[email protected]> --------- Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
21 changed files
with
372 additions
and
105 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
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
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
import { useInputComposition } from "@renderer/hooks/common/use-input-composition" | ||
import { cn } from "@renderer/lib/utils" | ||
import type { DetailedHTMLProps, InputHTMLAttributes } from "react" | ||
import { forwardRef } from "react" | ||
|
||
// This composition handler is not perfect | ||
// @see https://foxact.skk.moe/use-composition-input | ||
export const Input = forwardRef< | ||
HTMLInputElement, | ||
Omit< | ||
DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, | ||
"ref" | ||
> | ||
>(({ className, ...props }, ref) => { | ||
const inputProps = useInputComposition(props) | ||
return ( | ||
<input | ||
ref={ref} | ||
className={cn( | ||
"min-w-0 flex-auto appearance-none rounded-lg text-sm", | ||
"bg-background px-3 py-[calc(theme(spacing.2)-1px)] placeholder:text-zinc-400 dark:bg-zinc-700/[0.15]", | ||
"ring-theme-accent/20 duration-200 focus:border-theme-accent/80 focus:outline-none focus:ring-2", | ||
"border border-border", | ||
"dark:text-zinc-200 dark:placeholder:text-zinc-500", | ||
props.type === "password" ? | ||
"font-mono placeholder:font-sans" : | ||
"font-sans", | ||
"w-full", | ||
className, | ||
)} | ||
{...props} | ||
{...inputProps} | ||
/> | ||
) | ||
}) | ||
Input.displayName = "Input" |
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,114 @@ | ||
"use client" | ||
|
||
import { useInputComposition } from "@renderer/hooks/common/use-input-composition" | ||
import { cn } from "@renderer/lib/utils" | ||
import clsx from "clsx" | ||
import { useMotionValue } from "framer-motion" | ||
import type { | ||
DetailedHTMLProps, | ||
PropsWithChildren, | ||
TextareaHTMLAttributes, | ||
} from "react" | ||
import { forwardRef, useCallback, useState } from "react" | ||
|
||
const roundedMap = { | ||
"sm": "rounded-sm", | ||
"md": "rounded-md", | ||
"lg": "rounded-lg", | ||
"xl": "rounded-xl", | ||
"2xl": "rounded-2xl", | ||
"3xl": "rounded-3xl", | ||
"default": "rounded", | ||
} | ||
export const TextArea = forwardRef< | ||
HTMLTextAreaElement, | ||
DetailedHTMLProps< | ||
TextareaHTMLAttributes<HTMLTextAreaElement>, | ||
HTMLTextAreaElement | ||
> & | ||
PropsWithChildren<{ | ||
wrapperClassName?: string | ||
onCmdEnter?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void | ||
rounded?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "default" | ||
bordered?: boolean | ||
}> | ||
>((props, ref) => { | ||
const { | ||
className, | ||
wrapperClassName, | ||
children, | ||
rounded = "xl", | ||
bordered = true, | ||
onCmdEnter, | ||
...rest | ||
} = props | ||
const mouseX = useMotionValue(0) | ||
const mouseY = useMotionValue(0) | ||
const handleMouseMove = useCallback( | ||
({ clientX, clientY, currentTarget }: React.MouseEvent) => { | ||
const bounds = currentTarget.getBoundingClientRect() | ||
mouseX.set(clientX - bounds.left) | ||
mouseY.set(clientY - bounds.top) | ||
}, | ||
[mouseX, mouseY], | ||
) | ||
|
||
const inputProps = useInputComposition(props) | ||
const [isFocus, setIsFocus] = useState(false) | ||
return ( | ||
<div | ||
className={cn( | ||
"group relative h-full border ring-0 ring-accent/20 duration-200 [--spotlight-color:oklch(var(--a)_/_0.12)]", | ||
roundedMap[rounded], | ||
|
||
"border-transparent", | ||
isFocus && "border-accent/80 ring-2", | ||
|
||
"dark:text-zinc-200 dark:placeholder:text-zinc-500", | ||
wrapperClassName, | ||
)} | ||
onMouseMove={handleMouseMove} | ||
> | ||
{bordered && ( | ||
<div | ||
className={clsx( | ||
"border-border pointer-events-none absolute inset-0 z-0 border", | ||
roundedMap[rounded], | ||
)} | ||
aria-hidden="true" | ||
/> | ||
)} | ||
<textarea | ||
ref={ref} | ||
className={cn( | ||
"size-full resize-none bg-transparent", | ||
"overflow-auto px-3 py-4", | ||
"!outline-none", | ||
"text-neutral-900/80 dark:text-slate-100/80", | ||
roundedMap[rounded], | ||
className, | ||
)} | ||
{...rest} | ||
onFocus={(e) => { | ||
setIsFocus(true) | ||
rest.onFocus?.(e) | ||
}} | ||
onBlur={(e) => { | ||
setIsFocus(false) | ||
rest.onBlur?.(e) | ||
}} | ||
{...inputProps} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { | ||
onCmdEnter?.(e) | ||
} | ||
rest.onKeyDown?.(e) | ||
inputProps.onKeyDown?.(e) | ||
}} | ||
/> | ||
|
||
{children} | ||
</div> | ||
) | ||
}) | ||
TextArea.displayName = "TextArea" |
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,2 @@ | ||
export * from "./Input" | ||
export * from "./TextArea" |
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.