webflow.registerComponent(name, root)
webflow.registerComponent(name, root)
Registers a new component definition with the specified name and root element.
Syntax
webflow.registerComponent(name: string, root: AnyElement | ElementPreset<AnyElement> | Component): Promise<Component>
Parameters
name
: string - The name of the component.root
: AnyElement - The root element of the component.
Returns
Promise< Component>
A Promise that resolves to the registered component.
Example
// Get selected element
const rootElement = await webflow.getSelectedElement();
if (rootElement) {
// Create a component from the Root Element
const component = await webflow.registerComponent('MyCustomComponent', rootElement);
console.log(`Component registered with ID: ${component.id}`);
} else {
console.log("No element is currently selected. Please select a root element first.");
}
},~
Designer Ability
Designer Ability | Permission | Locale | Branch | Workflow | Sitemode |
---|---|---|---|---|---|
canCreateComponents | create siteSymbol | Primary | any | Canvas | any |