Skip to content

Commit

Permalink
fix: setting item support props
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Aug 29, 2024
1 parent 5e67f08 commit 0d60da6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/renderer/src/atoms/settings/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { createSettingAtom } from "./helper"

export const createDefaultSettings = (): IntegrationSettings => ({
enableEagle: true,
enableReadwise: true,
enableReadwise: false,
readwiseToken: "",
enableInstapaper: true,
enableInstapaper: false,
instapaperUsername: "",
instapaperPassword: "",
})
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/src/hooks/common/useInputComposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ export const useInputComposition = <E = HTMLInputElement>(
[onKeyDown],
)

return {
const ret = {
onCompositionEnd: handleCompositionEnd,
onCompositionStart: handleCompositionStart,
onKeyDown: handleKeyDown,
isCompositionRef,

}
Object.defineProperty(ret, "isCompositionRef", {
value: isCompositionRef,
enumerable: false,
})
return ret as typeof ret & {
isCompositionRef: typeof isCompositionRef
}
}
24 changes: 21 additions & 3 deletions src/renderer/src/modules/settings/control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,32 @@ export const SettingInput: Component<{
value: string
onChange: ChangeEventHandler<HTMLInputElement>
type: string
}> = ({ value, label, onChange, className, type }) => {
vertical?: boolean
labelClassName?: string
}> = ({
value,
label,
onChange,
labelClassName,
className,
type,
vertical,
}) => {
const id = useId()

return (
<div
className={cn("mb-1 flex items-center justify-between gap-12", className)}
className={cn(
"mb-1 flex",
vertical ?
"mb-2 flex-col gap-3" :
"flex-row items-center justify-between gap-12",
className,
)}
>
<Label className="shrink-0" htmlFor={id}>{label}</Label>
<Label className={cn("shrink-0", labelClassName)} htmlFor={id}>
{label}
</Label>
<Input
type={type}
id={id}
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/src/modules/settings/setting-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export type SettingItem<T, K extends keyof T = keyof T> = {
description?: string
onChange: (value: T[K]) => void
type?: "password"

vertical?: boolean

componentProps?: {
labelClassName?: string
className?: string
[key: string]: any
}
} & SharedSettingItem

type SectionSettingItem = {
Expand Down Expand Up @@ -97,6 +105,8 @@ export const createSettingBuilder =
case "string": {
ControlElement = (
<SettingInput
vertical={assertSetting.vertical}
labelClassName={assertSetting.componentProps?.labelClassName}
type={assertSetting.type || "text"}
className="mt-4"
value={settingObject[assertSetting.key] as string}
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/src/modules/settings/tabs/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const SettingIntegration = () => (
}),
defineSettingItem("readwiseToken", {
label: "Readwise Access Token",
vertical: true,
type: "password",
description: <>You can get it here: <a target="_blank" className="underline" rel="noreferrer noopener" href="https://readwise.io/access_token">readwise.io/access_token</a>.</>,
}),
Expand All @@ -62,10 +63,16 @@ export const SettingIntegration = () => (
}),
defineSettingItem("instapaperUsername", {
label: "Instapaper Username",
componentProps: {
labelClassName: "w-[150px]",
},
}),
defineSettingItem("instapaperPassword", {
label: "Instapaper Password",
type: "password",
componentProps: {
labelClassName: "w-[150px]",
},
}),
]}
/>
Expand Down

0 comments on commit 0d60da6

Please sign in to comment.