What is an Enum?
Enum defines a limited set of values to provide:Type Safety
Prevents undefined value inputAutomatically converts to Union type in TypeScript
Auto UI Generation
Automatic selection list configurationImmediately usable in Select, ButtonSet components
Label Management
Separation of keys and display namesEasy multi-language support
Maintainability
Centralized managementOnly one place to modify when values change
Defining Enums
Defining in entity.json
Define as key-label pairs in the Entityβsenums section.
user.entity.json
- Enum ID: PascalCase (e.g.,
UserRole,PostStatus) - Key: lowercase, numbers, underscores (e.g.,
admin,draft_saved) - Label: Display text (e.g., βAdministratorβ, βDraft Savedβ)
Defining in Sonamu UI
1
Navigate to Entity edit page
Select an Entity in Sonamu UI.
2
Scroll to Enums section
The Enums section is below Props, Indexes, Subsets.
3
Click Add Enum
Add a new Enum.Enter Enum ID:
- Enter in PascalCase
- Use
{Entity}pattern to associate with Entity- Example:
$ModelRoleβUserRole(auto-converted)
- Example:
4
Add Enum values
Each Enum is displayed as a separate tab, add key-label pairs with the βAdd Rowβ button.
- Key: lowercase letters, numbers, underscores only
- Label: Display name
5
Save
When you save the Entity, the Enum is saved together.
πΈ Needed: Sonamu UI Enums section - multiple Enums displayed as tabs
Auto-Generated Code
When you define an Enum, Sonamu automatically generates the following:1. Zod Schema
sonamu.generated.ts
2. TypeScript Type
user.types.ts
3. Label Helper Function
sonamu.generated.ts
Using Enums
Using in Props
- Column type:
text - Stored value: Key value (e.g.,
"admin")
Using in API
Displaying Labels
Common Enum Patterns
1. OrderBy Enum
Define sorting options.2. SearchField Enum
Define searchable fields.3. Status Enum
Define statuses.4. Type/Category Enum
Define classifications.Enum Array Type
You can store multiple Enum values as an array.- Column type:
text[] - Stored value:
["read", "write"]
Using Enums in Frontend
Select Component
ButtonSet Component
Enum Validation
Zod automatically validates Enum values.Enum Naming Conventions
Recommended Patterns
$Model Pattern
Use$Model to dynamically include the Entity name:
UserEntity βUserRole,UserStatusPostEntity βPostRole,PostStatus
Cautions
Enum vs Separate Table
Enum use examples:
- User roles (admin, user, guest)
- Post status (draft, published, deleted)
- Notification types (email, sms, push)
- Region list (Seoul, Busan, β¦)
- Product categories (hierarchical structure)
- Country codes (many additional info)
Next Steps
Field Types
Learn about other field types
Validation
Validate data with Zod
Frontend Components
Use generated components
API Development
API development using Enums