@sonamu-kit/react-components 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/components/index.d.ts +3 -5
- package/dist/components/ui/common-modal.d.ts +2 -0
- package/dist/components/ui/date-input.d.ts +1 -1
- package/dist/components/ui/file-input.d.ts +27 -0
- package/dist/components/ui/input.d.ts +1 -1
- package/dist/components/ui/select.d.ts +1 -1
- package/dist/components/ui/table.d.ts +3 -1
- package/dist/components/ui/textarea.d.ts +1 -1
- package/dist/contexts/index.d.ts +2 -0
- package/dist/contexts/sonamu-context.d.ts +12 -0
- package/dist/contexts/types.d.ts +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib/base-helpers.d.ts +15 -0
- package/dist/lib/form-helpers.d.ts +12 -0
- package/dist/lib/index.d.ts +5 -3
- package/dist/lib/list-helpers.d.ts +20 -0
- package/dist/lib/modal-helpers.d.ts +6 -0
- package/dist/lib/types.d.ts +26 -0
- package/dist/lib/utils.d.ts +15 -0
- package/dist/react-components.es.js +12116 -12032
- package/dist/react-components.es.js.map +1 -0
- package/package.json +7 -3
- package/dist/components/ui/image-uploader.d.ts +0 -14
- package/dist/components/ui/multi-image-uploader.d.ts +0 -15
- package/dist/lib/helpers.d.ts +0 -72
- package/dist/lib/lazy-upload.d.ts +0 -9
package/README.md
CHANGED
|
@@ -35,8 +35,8 @@ src/
|
|
|
35
35
|
## 설치
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
cd
|
|
39
|
-
|
|
38
|
+
cd modules/react-components
|
|
39
|
+
pnpm install
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
## 사용
|
|
@@ -50,9 +50,9 @@ import { useTypeForm } from "@sonamu-kit/react-components/hooks";
|
|
|
50
50
|
|
|
51
51
|
## 개발
|
|
52
52
|
|
|
53
|
-
- `
|
|
54
|
-
- `
|
|
55
|
-
- `
|
|
53
|
+
- `pnpm dev`: TypeScript watch 모드
|
|
54
|
+
- `pnpm build`: 빌드
|
|
55
|
+
- `pnpm lint`: 린팅
|
|
56
56
|
|
|
57
57
|
## 향후 계획
|
|
58
58
|
|
|
@@ -27,18 +27,16 @@ export { DateSelectorMultiple } from './ui/date-selector-multiple';
|
|
|
27
27
|
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from './ui/dialog';
|
|
28
28
|
export { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, } from './ui/drawer';
|
|
29
29
|
export { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from './ui/dropdown-menu';
|
|
30
|
+
export type { FileInputProps } from './ui/file-input';
|
|
31
|
+
export { FileInput } from './ui/file-input';
|
|
30
32
|
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField, } from './ui/form';
|
|
31
33
|
export { HoverCard, HoverCardContent, HoverCardTrigger } from './ui/hover-card';
|
|
32
|
-
export type
|
|
33
|
-
export { ImageUploader } from './ui/image-uploader';
|
|
34
|
-
export { Input } from './ui/input';
|
|
34
|
+
export { Input, type InputProps } from './ui/input';
|
|
35
35
|
export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from './ui/input-otp';
|
|
36
36
|
export { Label } from './ui/label';
|
|
37
37
|
export { Menubar, MenubarCheckboxItem, MenubarContent, MenubarGroup, MenubarItem, MenubarLabel, MenubarMenu, MenubarPortal, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, } from './ui/menubar';
|
|
38
38
|
export type { MonthPickerValue } from './ui/month-picker-multiple';
|
|
39
39
|
export { MonthPickerMultiple } from './ui/month-picker-multiple';
|
|
40
|
-
export type { MultiImageUploaderProps } from './ui/multi-image-uploader';
|
|
41
|
-
export { MultiImageUploader } from './ui/multi-image-uploader';
|
|
42
40
|
export type { MultiSelectOption, MultiSelectProps, MultiSelectRef, } from './ui/multi-select';
|
|
43
41
|
export { MultiSelect } from './ui/multi-select';
|
|
44
42
|
export { NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, navigationMenuTriggerStyle, } from './ui/navigation-menu';
|
|
@@ -4,6 +4,8 @@ type ExtendedModalProps = {
|
|
|
4
4
|
description?: string;
|
|
5
5
|
className?: string;
|
|
6
6
|
onCompleted?: (data?: unknown) => void;
|
|
7
|
+
onControlledOpen?: () => void;
|
|
8
|
+
onControlledClose?: () => void;
|
|
7
9
|
};
|
|
8
10
|
export declare const commonModalAtom: import('jotai').PrimitiveAtom<{
|
|
9
11
|
open: boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { SonamuFile } from '../../contexts';
|
|
3
|
+
export type PreviewSize = "sm" | "md" | "lg" | "xl";
|
|
4
|
+
type BaseProps = {
|
|
5
|
+
uploadMode: "eager" | "lazy";
|
|
6
|
+
viewMode: "image" | "file";
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
accept?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
previewSize?: PreviewSize;
|
|
12
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement>;
|
|
13
|
+
};
|
|
14
|
+
type SingleModeProps = BaseProps & {
|
|
15
|
+
multiple?: false;
|
|
16
|
+
value: SonamuFile | File | null;
|
|
17
|
+
onValueChange?: (value: SonamuFile | File | null) => void;
|
|
18
|
+
};
|
|
19
|
+
type MultipleModeProps = BaseProps & {
|
|
20
|
+
multiple: true;
|
|
21
|
+
value: (SonamuFile | File)[] | null;
|
|
22
|
+
onValueChange?: (value: (SonamuFile | File)[]) => void;
|
|
23
|
+
maxFiles?: number;
|
|
24
|
+
};
|
|
25
|
+
export type FileInputProps = SingleModeProps | MultipleModeProps;
|
|
26
|
+
export declare function FileInput(props: FileInputProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -7,7 +7,9 @@ type TableCol<T> = {
|
|
|
7
7
|
className?: string;
|
|
8
8
|
align?: TableAlign;
|
|
9
9
|
};
|
|
10
|
-
declare function Table({ className, ...props }: React.ComponentProps<"table">
|
|
10
|
+
declare function Table({ className, containerClassName, ...props }: React.ComponentProps<"table"> & {
|
|
11
|
+
containerClassName?: string;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
declare function TableHeader({ className, ...props }: React.ComponentProps<"thead">): import("react/jsx-runtime").JSX.Element;
|
|
12
14
|
declare function TableBody({ className, ...props }: React.ComponentProps<"tbody">): import("react/jsx-runtime").JSX.Element;
|
|
13
15
|
declare function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Dictionary, SDReturnType, SonamuAuth, SonamuFile } from './types';
|
|
3
|
+
export interface SonamuContextValue<D extends Dictionary = Dictionary> {
|
|
4
|
+
uploader?: (files: File[]) => Promise<SonamuFile[]>;
|
|
5
|
+
auth?: SonamuAuth;
|
|
6
|
+
SD: <K extends keyof D>(key: K) => SDReturnType<D, K>;
|
|
7
|
+
}
|
|
8
|
+
export interface SonamuProviderProps<D extends Dictionary = Dictionary> extends SonamuContextValue<D> {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare function SonamuProvider<D extends Dictionary = Dictionary>({ children, ...value }: SonamuProviderProps<D>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function useSonamuContext<D extends Dictionary = Dictionary>(): Required<SonamuContextValue<D>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: 제네릭 기본값으로 any 사용 */
|
|
2
|
+
/**
|
|
3
|
+
* ⚠️ 이 타입은 sonamu/types.ts와 동기화되어야 함
|
|
4
|
+
*/
|
|
5
|
+
export type SonamuFile = {
|
|
6
|
+
name: string;
|
|
7
|
+
url: string;
|
|
8
|
+
mime_type: string;
|
|
9
|
+
size: number;
|
|
10
|
+
};
|
|
11
|
+
export type SonamuAuth<TUser = any, TLoginParams = any> = {
|
|
12
|
+
user: TUser | null;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
login: (params: TLoginParams) => void;
|
|
15
|
+
logout: () => void;
|
|
16
|
+
refetch: () => void;
|
|
17
|
+
};
|
|
18
|
+
export type Dictionary = Record<string, string | ((...args: any[]) => string)>;
|
|
19
|
+
/**
|
|
20
|
+
* SD 반환 타입 - 제네릭으로 키에 따라 정확한 타입 반환
|
|
21
|
+
*
|
|
22
|
+
* 주의: union type (string | function)을 반환하므로, 함수로 호출할 때는 타입 단언 필요
|
|
23
|
+
* @example (SD("key") as unknown as (param) => string)(param)
|
|
24
|
+
* (이는 TypeScript가 union type을 직접 호출할 수 없기 때문)
|
|
25
|
+
*/
|
|
26
|
+
export type SDReturnType<D extends Dictionary, K extends keyof D> = D[K] extends (...args: infer P) => string ? ((...args: P) => string) | string : string;
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare function hidden(condition: boolean | undefined): string;
|
|
3
|
+
export declare function searchParamsToParams<T extends z.ZodType<any>>(searchParams: URLSearchParams, paramsSchema: T): z.infer<T>;
|
|
4
|
+
export declare function paramsToSearchParams<T>(params: T): {
|
|
5
|
+
[key in string]: string | string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function sqlDateToDateString(sqlDateString: string | null): string | null;
|
|
8
|
+
export declare function numF(num: number | null | undefined): string | number | undefined | null;
|
|
9
|
+
export declare function dateF(dateValue: string | Date | null | undefined): string | null;
|
|
10
|
+
export declare function datetimeF(dateValue: string | Date | null | undefined): string | null;
|
|
11
|
+
export declare function arrayableToArray<T extends number | string | boolean>(val: T | T[] | undefined): T[];
|
|
12
|
+
export declare function caller<T extends Function>(): {
|
|
13
|
+
set: (func: T) => void;
|
|
14
|
+
call: T;
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ErrorObj } from './types';
|
|
3
|
+
export declare function useTypeForm<T extends z.ZodObject<any> | z.ZodArray<any>, U extends z.infer<T>>(zType: T, defaultValue: U): {
|
|
4
|
+
form: z.core.output<T>;
|
|
5
|
+
setForm: import('react').Dispatch<import('react').SetStateAction<z.core.output<T>>>;
|
|
6
|
+
register: (objPath: string, _emptyStringTo?: "normal" | "nullable" | "optional") => any;
|
|
7
|
+
submit: <R>(callback: (formData: z.infer<T>) => Promise<R>) => () => Promise<R>;
|
|
8
|
+
addError: (objPath: string, errorMessage: string | ErrorObj) => void;
|
|
9
|
+
removeError: (objPath: string) => void;
|
|
10
|
+
clearError: () => void;
|
|
11
|
+
reset: () => void;
|
|
12
|
+
};
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { arrayableToArray, caller, dateF, datetimeF, hidden, numF, paramsToSearchParams, searchParamsToParams, sqlDateToDateString, } from './base-helpers';
|
|
2
2
|
export { caster, fastifyCaster } from './caster';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
3
|
+
export { useTypeForm } from './form-helpers';
|
|
4
|
+
export { useListParams, useSelection } from './list-helpers';
|
|
5
|
+
export { useModal } from './modal-helpers';
|
|
6
|
+
export type { ControlledModalProps, DistributiveOmit, ErrorObj, Override, PaginationProps, SonamuCol, TableColumnWidth, } from './types';
|
|
5
7
|
export { useIsMobile } from './use-mobile';
|
|
6
8
|
export { cn } from './utils';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
type ZodKeys<T extends z.ZodType<any>> = keyof z.infer<T>;
|
|
4
|
+
export declare function useListParams<U extends z.ZodType<any>, T extends Partial<z.infer<U>>>(zType: U, defaultValue: T, options?: {
|
|
5
|
+
disableSearchParams?: boolean;
|
|
6
|
+
}): {
|
|
7
|
+
listParams: T;
|
|
8
|
+
setListParams: (newParams: T) => void;
|
|
9
|
+
register: (name: ZodKeys<U>) => any;
|
|
10
|
+
};
|
|
11
|
+
export declare function useSelection<T>(allKeys: T[], defaultSelectedKeys?: T[]): {
|
|
12
|
+
getSelected: (key: T) => boolean;
|
|
13
|
+
toggle: (key: T) => void;
|
|
14
|
+
selectedKeys: T[];
|
|
15
|
+
deselectAll: () => void;
|
|
16
|
+
selectAll: () => void;
|
|
17
|
+
isAllSelected: boolean;
|
|
18
|
+
handleCheckboxClick: (e: React.MouseEvent<HTMLInputElement, MouseEvent>, index: number) => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ControlledModalProps } from './types';
|
|
3
|
+
export declare function useModal<T extends object>(ModalComponent: (props: T & ControlledModalProps) => React.ReactElement, defaultProps: T): {
|
|
4
|
+
open: (newProps: T) => void;
|
|
5
|
+
modal: React.FunctionComponentElement<T & ControlledModalProps>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export type PaginationProps = {
|
|
3
|
+
activePage?: number;
|
|
4
|
+
totalPages?: number;
|
|
5
|
+
};
|
|
6
|
+
export type TableColumnWidth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16;
|
|
7
|
+
export type ErrorObj = {
|
|
8
|
+
content: string;
|
|
9
|
+
pointing?: "above" | "below" | "left" | "right";
|
|
10
|
+
};
|
|
11
|
+
export type ControlledModalProps = {
|
|
12
|
+
open: boolean;
|
|
13
|
+
close: () => void;
|
|
14
|
+
};
|
|
15
|
+
export type SonamuCol<T> = {
|
|
16
|
+
label: string;
|
|
17
|
+
th?: ReactElement;
|
|
18
|
+
tc: (row: T, index: number) => ReactElement;
|
|
19
|
+
className?: string;
|
|
20
|
+
collapsing?: boolean;
|
|
21
|
+
width?: TableColumnWidth;
|
|
22
|
+
hidden?: boolean;
|
|
23
|
+
parentLabel?: string;
|
|
24
|
+
};
|
|
25
|
+
export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
26
|
+
export type Override<T, U> = Omit<T, keyof U> & U;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
import { ClassValue } from 'clsx';
|
|
2
2
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
3
|
+
/**
|
|
4
|
+
* useObjectUrls 훅
|
|
5
|
+
*
|
|
6
|
+
* 로컬 File 객체 배열을 받아서 브라우저 메모리 기반 미리보기용 Object URL을 생성하고,
|
|
7
|
+
* 컴포넌트가 언마운트되거나 파일이 변경될 때 자동으로 메모리를 해제합니다.
|
|
8
|
+
*
|
|
9
|
+
* **동작 방식**:
|
|
10
|
+
* 1. File 배열을 받아서 각 파일마다 `URL.createObjectURL()`로 임시 URL 생성
|
|
11
|
+
* 2. 생성된 URL은 `blob:http://...` 형태로, 브라우저 메모리를 직접 참조
|
|
12
|
+
* 3. 컴포넌트 언마운트나 파일 변경 시 cleanup 함수가 `URL.revokeObjectURL()`로 메모리 해제
|
|
13
|
+
*
|
|
14
|
+
* @param files - 미리보기할 File 객체 배열
|
|
15
|
+
* @returns 생성된 Object URL 문자열 배열
|
|
16
|
+
*/
|
|
17
|
+
export declare function useObjectUrls(files: File[]): string[];
|