Configuration object
Name of the field in the state
Label for the field
Array of badge items to display, or a function that returns the items based on state
Global background color for all badges. Can be a static string or a function that returns a color based on state
Global text color for all badges. Can be a static string or a function that returns a color based on state
Whether the field is required
Whether the field is disabled
Whether the field is hidden
Array of default selected values
Callback function called when selection changes
Global wrap setting for all badges. Defaults to false. Can be a static boolean or a function that returns a boolean based on state. Individual badge items can override this
Basic multi-select badge field
badgeField({
name: 'skills',
label: 'Select Skills',
items: [
{ label: 'JavaScript', value: 'js' },
{ label: 'TypeScript', value: 'ts' },
{ label: 'React', value: 'react' }
]
});
Badge field with global colors
badgeField({
name: 'categories',
label: 'Select Categories',
items: [
{ label: 'Work', value: 'work' },
{ label: 'Personal', value: 'personal' }
],
bgColor: '#e5e7eb',
color: '#374151'
});
Badge field with individual item colors
badgeField({
name: 'priorities',
label: 'Select Priorities',
items: [
{ label: 'High', value: 'high', bgColor: '#dc2626', color: '#ffffff' },
{ label: 'Medium', value: 'medium', bgColor: '#f59e0b', color: '#ffffff' },
{ label: 'Low', value: 'low', bgColor: '#10b981', color: '#ffffff' }
]
});
Dynamic colors based on params with data and value
badgeField({
name: 'tags',
label: 'Select Tags',
items: ({data}) => data.availableTags || [],
bgColor: ({data}) => data.theme === 'dark' ? '#374151' : '#f3f4f6',
color: ({data}) => data.theme === 'dark' ? '#ffffff' : '#111827'
});
Badge field with global wrap setting and individual item overrides
badgeField({
name: 'descriptions',
label: 'Select Descriptions',
wrap: true, // Global wrap setting
items: [
{ label: 'Short', value: 'short', wrap: false }, // Override: no wrap
{ label: 'This is a very long description that will wrap by default', value: 'long' },
{ label: 'Another long text that benefits from wrapping', value: 'another-long' }
]
});
BadgeField component for multi-select badges.