feat: setting item support secret input field
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -104,9 +104,11 @@ export const createDefineSettingItem =
|
||||
description?: string | JSX.Element
|
||||
onChange?: (value: T[K]) => void
|
||||
hide?: boolean
|
||||
},
|
||||
|
||||
} & Omit<SettingItem<any>, "onChange" | "description" | "label" | "hide" | "key">,
|
||||
): any => {
|
||||
const { label, description, onChange, hide } = options
|
||||
const { label, description, onChange, hide, ...rest } = options
|
||||
|
||||
return {
|
||||
key,
|
||||
label,
|
||||
@@ -116,6 +118,7 @@ export const createDefineSettingItem =
|
||||
setSetting(key, value as any)
|
||||
},
|
||||
disabled: hide,
|
||||
...rest,
|
||||
} as SettingItem<any>
|
||||
}
|
||||
|
||||
|
||||
@@ -52,14 +52,17 @@ export const SettingInput: Component<{
|
||||
label: string
|
||||
value: string
|
||||
onChange: ChangeEventHandler<HTMLInputElement>
|
||||
}> = ({ value, label, onChange, className }) => {
|
||||
type: string
|
||||
}> = ({ value, label, onChange, className, type }) => {
|
||||
const id = useId()
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn("mb-1 flex items-center justify-between gap-12", className)}
|
||||
>
|
||||
<Label className="shrink-0" htmlFor={id}>{label}</Label>
|
||||
<Input
|
||||
type={type}
|
||||
id={id}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
|
||||
@@ -21,6 +21,7 @@ export type SettingItem<T, K extends keyof T = keyof T> = {
|
||||
label: string
|
||||
description?: string
|
||||
onChange: (value: T[K]) => void
|
||||
type?: "password"
|
||||
} & SharedSettingItem
|
||||
|
||||
type SectionSettingItem = {
|
||||
@@ -73,7 +74,7 @@ export const createSettingBuilder =
|
||||
<SettingSectionTitle key={index} title={assertSetting.value} />
|
||||
)
|
||||
}
|
||||
if ("type" in assertSetting) {
|
||||
if ("type" in assertSetting && assertSetting.type === "title") {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -96,6 +97,7 @@ export const createSettingBuilder =
|
||||
case "string": {
|
||||
ControlElement = (
|
||||
<SettingInput
|
||||
type={assertSetting.type || "text"}
|
||||
className="mt-4"
|
||||
value={settingObject[assertSetting.key] as string}
|
||||
onChange={(event) =>
|
||||
|
||||
@@ -49,6 +49,7 @@ export const SettingIntegration = () => (
|
||||
}),
|
||||
defineSettingItem("readwiseToken", {
|
||||
label: "Readwise Access Token",
|
||||
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>.</>,
|
||||
}),
|
||||
{
|
||||
@@ -64,6 +65,7 @@ export const SettingIntegration = () => (
|
||||
}),
|
||||
defineSettingItem("instapaperPassword", {
|
||||
label: "Instapaper Password",
|
||||
type: "password",
|
||||
}),
|
||||
]}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user