Custom Elements
Overview
Creating a Custom Element
Step 1: Define the Render Function
const colorPickerRenderer = (element, value, uniqueId) => {
const currentValue = value || element.default || '#000000';
return `
<div class="settings-input-group" data-element-id="${element.id}">
<label for="${uniqueId}">
${element.label}
${element.required ? '<span style="color: var(--col-danger)"> *</span>' : ''}
</label>
${element.description ? `<p class="settings-description">${element.description}</p>` : ''}
<div style="display: flex; align-items: center; gap: 10px;">
<input
type="color"
id="${uniqueId}-color"
value="${currentValue}"
onchange="this.nextElementSibling.value = this.value; this.dispatchEvent(new CustomEvent('setting-changed', {detail: {id: '${element.id}', value: this.value}, bubbles: true}));"
style="width: 60px; height: 40px; cursor: pointer;"
/>
<input
type="text"
id="${uniqueId}"
value="${currentValue}"
placeholder="#000000"
oninput="this.previousElementSibling.value = this.value; this.dispatchEvent(new CustomEvent('setting-changed', {detail: {id: '${element.id}', value: this.value}, bubbles: true}));"
style="flex: 1; padding: 8px 12px; background-color: var(--col-input-default); border: 1px solid var(--col-ouliner-default); border-radius: var(--radius-sm); color: var(--col-txt-primary);"
/>
</div>
${element.hint ? `<small style="color: var(--col-txt-secondary); font-size: 12px;">${element.hint}</small>` : ''}
</div>
`;
};Step 2: Register the Element Type
Step 3: Use in Settings
Render Function Reference
Parameters
Parameter
Type
Description
Return Value
Event Handling
Example with Event
Examples
Simple Rating Element
File Size Selector
Tag Input
CSS Variables
Example with Variables
Best Practices
1. Always Use uniqueId for Element IDs
2. Dispatch Events on Change
3. Escape Values Properly
4. Use CSS Variables
5. Provide Fallback Values
Troubleshooting
Element Not Rendering
Values Not Saving
Styling Issues
Next Steps
Last updated