siakad-itm/resources/js/hooks/use-initials.tsx
Yoga Pangestu fbf29ad4e9
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: Refactor UI components and add new Drawer, Table, and Tabs components
- Removed unnecessary "use client" directive from checkbox and select components.
- Added new Drawer component with associated subcomponents (DrawerTrigger, DrawerClose, etc.) for better UI management.
- Introduced Table component with TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, and TableCaption for structured data display.
- Added Tabs component with TabsList, TabsTrigger, and TabsContent for tabbed navigation.
- Updated user-info component to use full_name instead of name for better clarity.
- Modified user-menu-content to include translations for settings and logout options.
- Added data.json file for mock data in the dashboard.
- Updated dashboard page to utilize new components and improved layout.
- Refactored User type to replace name with full_name for consistency across the application.
2026-08-03 15:57:38 +07:00

28 lines
745 B
TypeScript

import { useCallback } from 'react';
export type GetInitialsFn = (fullName: string) => string;
function getInitial(name: string): string {
return Array.from(name)[0] ?? '';
}
export function useInitials(): GetInitialsFn {
return useCallback((fullName: string): string => {
console.log(fullName)
const names = fullName.trim().split(/\s+/u).filter(Boolean);
if (names.length === 0) {
return '';
}
if (names.length === 1) {
return getInitial(names[0]).toUpperCase();
}
const firstInitial = getInitial(names[0]);
const lastInitial = getInitial(names[names.length - 1]);
return `${firstInitial}${lastInitial}`.toUpperCase();
}, []);
}