A ToolsPanel-based component that provides attribute management for blocks in the Site Editor, with ComboboxControl for selecting from available meta fields and HTML attributes.
- Uses WordPress ToolsPanel for consistent UI
- ComboboxControl populated with:
- Common HTML attributes (id, class, style, etc.)
- ARIA attributes
- Data attributes
- Available post meta fields
- Dynamic attribute addition/removal
- Per-attribute reset functionality
- Global reset all attributes
import { AttributesPanel, useAttributes } from '@builtnorth/wp-component-library/components/attributes-panel';
function MyComponent() {
const { attributes, setAttributes } = useAttributes([
{ id: 'id', label: 'ID', value: '' },
{ id: 'alt', label: 'Alt Text', value: '' }
]);
return (
<AttributesPanel
attributes={attributes}
onChange={setAttributes}
panelId="my-attributes-panel"
/>
);
}attributes(Array): Array of attribute objects withid,label, andvaluepropertiesonChange(Function): Callback when attributes change, receives updated attributes arraypanelId(string): Unique ID for the tools panel (default: 'attributes-panel')
Returns an object with:
attributes: Current attributes arraysetAttributes: Set entire attributes arrayupdateAttribute(id, value): Update a specific attributeaddAttribute(label, value): Add new attributeremoveAttribute(id): Remove attribute by idresetAttributes(): Reset all attribute valuesgetAttributeValue(id): Get value for specific attribute
The component is integrated into the Site Editor for specific core blocks (image, paragraph, heading, button) via the block extension system. It automatically:
- Detects when in Site Editor context
- Shows appropriate default attributes for each block type
- Populates ComboboxControl with available meta fields
- Saves attributes to block's customAttributes array
The ComboboxControl is populated with:
- id, class, style, title, alt, rel, target, href, src
- data-id, data-type, data-value
- aria-label, aria-describedby, aria-hidden
- All available post meta fields (prefixed with "Meta:")
- Common WordPress meta fields like _thumbnail_id, _wp_page_template
Users can also type custom attribute names not in the list.