diff --git a/ui/src/components/ui/@types/common.ts b/ui/src/components/ui/@types/common.ts index 5a95010c..63c48889 100644 --- a/ui/src/components/ui/@types/common.ts +++ b/ui/src/components/ui/@types/common.ts @@ -18,7 +18,7 @@ export declare namespace TypeAttributes { type Shape = 'round' | 'circle' | 'none' type Status = 'success' | 'warning' | 'danger' | 'info' type FormLayout = 'horizontal' | 'vertical' | 'inline' - type ControlSize = 'lg' | 'md' | 'sm' + type ControlSize = 'lg' | 'md' | 'sm' | 'xs' type MenuVariant = 'light' | 'dark' | 'themed' | 'transparent' type Direction = 'ltr' | 'rtl' } diff --git a/ui/src/components/ui/Pagination/Pagination.tsx b/ui/src/components/ui/Pagination/Pagination.tsx index a395c8fb..183b1f77 100644 --- a/ui/src/components/ui/Pagination/Pagination.tsx +++ b/ui/src/components/ui/Pagination/Pagination.tsx @@ -8,132 +8,130 @@ import { useConfig } from '../ConfigProvider' import type { CommonProps } from '../@types/common' export interface PaginationProps extends CommonProps { - currentPage?: number - displayTotal?: boolean - onChange?: (pageNumber: number) => void - pageSize?: number - total?: number + currentPage?: number + displayTotal?: boolean + onChange?: (pageNumber: number) => void + pageSize?: number + total?: number } const Pagination = (props: PaginationProps) => { - const { - className, - currentPage = 1, - displayTotal = false, - onChange, - pageSize = 1, - total = 5, - } = props + const { + className, + currentPage = 1, + displayTotal = false, + onChange, + pageSize = 1, + total = 5, + } = props - const [paginationTotal, setPaginationTotal] = useState(total) - const [internalPageSize, setInternalPageSize] = useState(pageSize) + const [paginationTotal, setPaginationTotal] = useState(total) + const [internalPageSize, setInternalPageSize] = useState(pageSize) - const { themeColor, primaryColorLevel } = useConfig() + const { themeColor, primaryColorLevel } = useConfig() - const getInternalPageCount = useMemo(() => { - if (typeof paginationTotal === 'number') { - return Math.ceil(paginationTotal / internalPageSize) + const getInternalPageCount = useMemo(() => { + if (typeof paginationTotal === 'number') { + return Math.ceil(paginationTotal / internalPageSize) + } + return null + }, [paginationTotal, internalPageSize]) + + const getValidCurrentPage = useCallback( + (count: number | string) => { + const value = parseInt(count as string, 10) + const internalPageCount = getInternalPageCount + let resetValue + if (!internalPageCount) { + if (isNaN(value) || value < 1) { + resetValue = 1 } - return null - }, [paginationTotal, internalPageSize]) - - const getValidCurrentPage = useCallback( - (count: number | string) => { - const value = parseInt(count as string, 10) - const internalPageCount = getInternalPageCount - let resetValue - if (!internalPageCount) { - if (isNaN(value) || value < 1) { - resetValue = 1 - } - } else { - if (value < 1) { - resetValue = 1 - } - if (value > internalPageCount) { - resetValue = internalPageCount - } - } - - if ( - (resetValue === undefined && isNaN(value)) || - resetValue === 0 - ) { - resetValue = 1 - } - - return resetValue === undefined ? value : resetValue - }, - [getInternalPageCount] - ) - - const [internalCurrentPage, setInternalCurrentPage] = useState( - currentPage ? getValidCurrentPage(currentPage) : 1 - ) - - useEffect(() => { - if (total !== paginationTotal) { - setPaginationTotal(total) + } else { + if (value < 1) { + resetValue = 1 } - - if (pageSize !== internalPageSize) { - setInternalPageSize(pageSize) + if (value > internalPageCount) { + resetValue = internalPageCount } + } - if (currentPage !== internalCurrentPage) { - setInternalCurrentPage(currentPage) - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [total, pageSize, currentPage]) + if ((resetValue === undefined && isNaN(value)) || resetValue === 0) { + resetValue = 1 + } - const onPaginationChange = (val: number) => { - setInternalCurrentPage(getValidCurrentPage(val)) - onChange?.(getValidCurrentPage(val)) + return resetValue === undefined ? value : resetValue + }, + [getInternalPageCount], + ) + + const [internalCurrentPage, setInternalCurrentPage] = useState( + currentPage ? getValidCurrentPage(currentPage) : 1, + ) + + useEffect(() => { + if (total !== paginationTotal) { + setPaginationTotal(total) } - const onPrev = useCallback(() => { - const newPage = internalCurrentPage - 1 - setInternalCurrentPage(getValidCurrentPage(newPage)) - onChange?.(getValidCurrentPage(newPage)) - }, [onChange, internalCurrentPage, getValidCurrentPage]) - - const onNext = useCallback(() => { - const newPage = internalCurrentPage + 1 - setInternalCurrentPage(getValidCurrentPage(newPage)) - onChange?.(getValidCurrentPage(newPage)) - }, [onChange, internalCurrentPage, getValidCurrentPage]) - - const pagerClass = { - default: 'pagination-pager', - inactive: 'pagination-pager-inactive', - active: `text-${themeColor}-${primaryColorLevel} bg-${themeColor}-50 hover:bg-${themeColor}-50 dark:bg-${themeColor}-${primaryColorLevel} dark:text-gray-100`, - disabled: 'pagination-pager-disabled', + if (pageSize !== internalPageSize) { + setInternalPageSize(pageSize) } - const paginationClass = classNames('pagination', className) + if (currentPage !== internalCurrentPage) { + setInternalCurrentPage(currentPage) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [total, pageSize, currentPage]) - return ( -
- {displayTotal && } - - - -
- ) + const onPaginationChange = (val: number) => { + setInternalCurrentPage(getValidCurrentPage(val)) + onChange?.(getValidCurrentPage(val)) + } + + const onPrev = useCallback(() => { + const newPage = internalCurrentPage - 1 + setInternalCurrentPage(getValidCurrentPage(newPage)) + onChange?.(getValidCurrentPage(newPage)) + }, [onChange, internalCurrentPage, getValidCurrentPage]) + + const onNext = useCallback(() => { + const newPage = internalCurrentPage + 1 + setInternalCurrentPage(getValidCurrentPage(newPage)) + onChange?.(getValidCurrentPage(newPage)) + }, [onChange, internalCurrentPage, getValidCurrentPage]) + + const pagerClass = { + default: 'pagination-pager px-2 py-1 text-xs rounded-md', // 🔽 küçük padding + küçük yazı + inactive: 'pagination-pager-inactive text-gray-500', + active: `text-${themeColor}-${primaryColorLevel} bg-${themeColor}-50 + hover:bg-${themeColor}-100 + dark:bg-${themeColor}-${primaryColorLevel} dark:text-gray-100`, + disabled: 'pagination-pager-disabled opacity-50', + } + + const paginationClass = classNames( + 'pagination flex items-center justify-center text-xs', // 🔽 daha küçük yazı + boşluk azaldı + className, + ) + + return ( +
+ {displayTotal && } + + + +
+ ) } Pagination.displayName = 'Pagination' diff --git a/ui/src/views/form/FormButtons.tsx b/ui/src/views/form/FormButtons.tsx index bff79d9c..9ea24981 100644 --- a/ui/src/views/form/FormButtons.tsx +++ b/ui/src/views/form/FormButtons.tsx @@ -104,7 +104,7 @@ const FormButtons = (props: { return ( <> -
+
{toolbarData ?.filter( (item) => @@ -168,6 +168,21 @@ const FormButtons = (props: { {!!commandColumnData?.buttons?.filter((item) => typeof item !== 'string').length && ( )} + {mode != 'new' && ( )} - {mode === 'new' && ( - - )} {(mode == 'edit' || mode == 'new') && (