Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/PermissionsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const permissionsMap: PermissionsMap = {
getVariants: { permissions: ['canAccessCanvas'] },
getSelectedVariant: { permissions: ['canAccessCanvas'] },
enterComponent: { permissions: ['canModifyComponents'] },
setSelectedVariant: { permissions: ['canModifyComponents'] },
openCanvas: { permissions: ['canModifyComponents'] },
selectComponent: { permissions: ['canModifyComponents'] },
exitComponent: { permissions: ['canAccessCanvas'] },
Expand Down
27 changes: 27 additions & 0 deletions src/designer-extension-typings/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
interface SetSelectedVariantByName {
name: string;
}
interface SetSelectedVariantById {
id: string;
}

type SetSelectedVariantOptions = SetSelectedVariantByName | SetSelectedVariantById;

interface Component {
readonly [brand]: 'Component';

Expand Down Expand Up @@ -70,6 +79,24 @@ interface Component {
* ```
*/
getSelectedVariant(): Promise<Variant>;
/**
* Selects the specified variant of a selected component when the component canvas is open.
* @returns A promise that resolves when the specified variant is selected.
* @example
* ```typescript
* interface SetSelectedVariantByName {
* name: string;
* }
* interface SetSelectedVariantById {
* id: string;
* }
*
* type SetSelectedVariantOptions = SetSelectedVariantByName | SetSelectedVariantById;
*
* setSelectedVariant(options: SetSelectedVariantOptions | string): Promise<void>;
* ```
*/
setSelectedVariant(options: SetSelectedVariantOptions | string): Promise<void>;
getRootElement(): Promise<null | AnyElement>;
}

Expand Down
7 changes: 7 additions & 0 deletions src/examples/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export const Components = {
*/
},

setSelectedVariant: async () => {
const heroComponent = await webflow.getComponentByName('Hero');
if (heroComponent) {
await heroComponent.setSelectedVariant({ id: 'base' });
}
},

createComponent: async () => {
// Get selected element
const rootElement = await webflow.getSelectedElement()
Expand Down