✨ 특징
- 🎯 스키마 기반: JSON 설정만으로 완성되는 폼
- 🛡️ 타입 안전: Zod 유효성 검사와 TypeScript 지원
- ⚡ 빠른 개발: 반복적인 폼 작성 작업 제거
- 🎨 커스터마이징: 독립적인 스타일 적용
🚀 빠른 시작
설치
npm install @formgen-he2e2/core
# 또는
pnpm add @formgen-he2e2/core
# 또는
yarn add @formgen-he2e2/core
기본 사용법
import { FormGenerator, type FormSchema } from "@formgen-he2e2/core";
import "@formgen-he2e2/core/styles.css";
import { z } from "zod";
const schema: FormSchema = [
{ type: "text", name: "username", label: "사용자명", required: true },
{ type: "email", name: "email", label: "이메일", required: true },
{ type: "password", name: "password", label: "비밀번호", required: true },
];
const customValidation = z.object({
username: z.string().min(3, "사용자명은 최소 3자 이상이어야 합니다"),
email: z.string().email("올바른 이메일을 입력하세요"),
password: z.string().min(8, "비밀번호는 최소 8자 이상이어야 합니다"),
});
function MyForm() {
const handleSubmit = (data) => {
console.log("폼 데이터:", data);
};
return (
<FormGenerator
schema={schema}
customSchema={customValidation}
onSubmit={handleSubmit}
/>
);
}
📚 지원하는 필드 타입
타입 | 설명 | 예시 |
---|
text | 기본 텍스트 입력 | 이름, 제목 등 |
email | 이메일 입력 | user@example.com |
password | 비밀번호 입력 | ••••••••• |
number | 숫자 입력 | 나이, 가격 등 |
textarea | 긴 텍스트 입력 | 설명, 메모 등 |
select | 드롭다운 선택 | 옵션 목록에서 선택 |
radio | 라디오 버튼 | 단일 선택 |
checkbox | 체크박스 | 다중 선택 |
date | 날짜 선택 | 2025-01-01 |
각 타입별 인터페이스는 schema.ts에서 확인하실 수 있습니다.
🎨 고급 사용법
커스텀 스타일링
const schema: FormSchema = [
{
type: 'text',
name: 'username',
label: '사용자명',
wrapperClassName: 'custom-wrapper',
},
];
복잡한 유효성 검사
const validationSchema = z.object({
password: z
.string()
.min(8, '비밀번호는 최소 8자 이상이어야 합니다')
.regex(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/,
'대문자, 소문자, 숫자, 특수문자를 각각 하나 이상 포함해야 합니다',
),
});
🎮 예제
회원가입 폼
const signupSchema: FormSchema = [
{ type: 'text', name: 'name', label: '이름', required: true },
{ type: 'email', name: 'email', label: '이메일', required: true },
{ type: 'password', name: 'password', label: '비밀번호', required: true },
{
type: 'password',
name: 'confirmPassword',
label: '비밀번호 확인',
required: true,
},
{
type: 'select',
name: 'age',
label: '연령대',
options: ['10대', '20대', '30대', '40대 이상'],
},
{
type: 'checkbox',
name: 'terms',
label: '이용약관에 동의합니다',
required: true,
},
];
🛠️ 기술 스택

🔗 링크