Files
dg-js-workspace/packages/ui-react/src/styles/utils/down-grade-size.ts
T
2026-12-02 09:30:54 +08:00

28 lines
631 B
TypeScript

type SizeType = ["xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
/**
*
* @returns
* Return available value or undefind
*/
export function downGradeSize(
size: "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl" | undefined,
downGrade: number = 1,
): "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl" | undefined {
if (size == undefined) {
return undefined;
}
const sizeArray: SizeType = ["xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
const index = sizeArray.findIndex((v) => v === size);
const downIndex = index - downGrade;
if (downIndex < 0) {
return undefined;
}
return sizeArray[downIndex];
}