feat: 1)add font source 2)add validator in ListItem 3)settings page ui optiminize

This commit is contained in:
Dean-YZG
2024-05-07 15:05:29 +08:00
parent 4e4431339f
commit 240d330001
16 changed files with 77 additions and 19 deletions

View File

@@ -42,7 +42,7 @@ export default function Btn(props: BtnProps) {
} text-text-btn-primary `;
break;
case "danger":
btnClassName = `bg-danger-btn text-text-btn-danger hover:bg-hovered-btn`;
btnClassName = `bg-danger-btn text-text-btn-danger hover:bg-hovered-danger-btn`;
break;
default:
btnClassName = `bg-default-btn text-text-btn-default hover:bg-hovered-btn`;

View File

@@ -4,7 +4,6 @@ import {
DetailedHTMLProps,
InputHTMLAttributes,
useContext,
useEffect,
useLayoutEffect,
useState,
} from "react";
@@ -17,6 +16,7 @@ export interface CommonInputProps
> {
className?: string;
}
export interface NumberInputProps {
onChange?: (v: number) => void;
type?: "number";
@@ -49,12 +49,16 @@ export default function Input(props: CommonInputProps & InputProps) {
const internalType = (show && "text") || type;
const { update } = useContext(List.ListContext);
const { update, handleValidate } = useContext(List.ListContext);
useLayoutEffect(() => {
update?.({ type: "input" });
}, []);
useLayoutEffect(() => {
handleValidate?.(value);
}, [value]);
return (
<div
className={` group/input w-[100%] rounded-chat-input bg-input transition-colors duration-300 ease-in-out flex gap-3 items-center px-3 py-2 ${className} hover:bg-select-hover ${inputClassName}`}

View File

@@ -17,6 +17,7 @@ interface WidgetStyle {
interface ChildrenMeta {
type?: "unknown" | "input" | "range";
error?: string;
}
export interface ListProps {
@@ -27,6 +28,15 @@ export interface ListProps {
widgetStyle?: WidgetStyle;
}
type Error =
| {
error: true;
message: string;
}
| {
error: false;
};
export interface ListItemProps {
title: string;
subTitle?: string;
@@ -34,10 +44,15 @@ export interface ListItemProps {
className?: string;
onClick?: () => void;
nextline?: boolean;
validator?: (v: any) => Error | Promise<Error>;
}
export const ListContext = createContext<
{ isMobileScreen?: boolean; update?: (m: ChildrenMeta) => void } & WidgetStyle
{
isMobileScreen?: boolean;
update?: (m: ChildrenMeta) => void;
handleValidate?: (v: any) => void;
} & WidgetStyle
>({ isMobileScreen: false });
export function ListItem(props: ListItemProps) {
@@ -48,6 +63,7 @@ export function ListItem(props: ListItemProps) {
subTitle,
children,
nextline,
validator,
} = props;
const context = useContext(ListContext);
@@ -56,9 +72,11 @@ export function ListItem(props: ListItemProps) {
const { inputNextLine, rangeNextLine } = context;
const { type, error } = childrenMeta;
let internalNextLine;
switch (childrenMeta.type) {
switch (type) {
case "input":
internalNextLine = !!(nextline || inputNextLine);
break;
@@ -70,7 +88,22 @@ export function ListItem(props: ListItemProps) {
}
const update = useCallback((m: ChildrenMeta) => {
setMeta(m);
setMeta((pre) => ({ ...pre, ...m }));
}, []);
const handleValidate = useCallback((v: any) => {
const insideValidator = validator || (() => {});
Promise.resolve(insideValidator(v)).then((result) => {
if (result && result.error) {
return update({
error: result.message,
});
}
update({
error: undefined,
});
});
}, []);
return (
@@ -88,13 +121,18 @@ export function ListItem(props: ListItemProps) {
<div className={` text-sm text-text-list-subtitle`}>{subTitle}</div>
)}
</div>
<ListContext.Provider value={{ ...context, update }}>
<ListContext.Provider value={{ ...context, update, handleValidate }}>
<div
className={`${
internalNextLine ? "mt-[0.625rem]" : "max-w-[70%]"
} flex items-center justify-center`}
} flex flex-col items-center justify-center`}
>
{children}
<div>{children}</div>
{!!error && (
<div className="text-text-btn-danger text-sm-mobile-tab mt-[0.3125rem] flex items-start w-[100%]">
<div className="">{error}</div>
</div>
)}
</div>
</ListContext.Provider>
</div>

View File

@@ -96,7 +96,7 @@ const Select = <Value extends number | string>(props: SearchProps<Value>) => {
className={selectClassName}
>
<div
className={`flex items-center gap-3 py-2 px-3 bg-select rounded-action-btn font-time text-sm-title cursor-pointer hover:bg-select-hover transition duration-300 ease-in-out`}
className={`flex items-center gap-3 py-2 px-3 bg-select rounded-action-btn font-common text-sm-title cursor-pointer hover:bg-select-hover transition duration-300 ease-in-out`}
ref={contentRef}
>
<div