Skip to content

Commit 16ed780

Browse files
authored
DEVREL-2727: Get and set component settings (#29)
1 parent 849c23d commit 16ed780

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/components/PermissionsMap.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const permissionsMap: PermissionsMap = {
6161
openCanvas: { permissions: ['canModifyComponents'] },
6262
selectComponent: { permissions: ['canModifyComponents'] },
6363
exitComponent: { permissions: ['canAccessCanvas'] },
64+
getSettings: { permissions: ['canAccessCanvas'] },
65+
setSettings: { permissions: ['canModifyComponents'] },
6466
},
6567

6668
// Elements

src/designer-extension-typings/components.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ interface Component {
3131
* ```
3232
*/
3333
setName(name: string): Promise<null>;
34+
/**
35+
* Get the settings (name, group, description) of a component.
36+
* @returns A Promise resolving to the component's settings.
37+
* @example
38+
* ```ts
39+
* const component = (await webflow.getAllComponents())[0];
40+
* const settings = await component.getSettings();
41+
* console.log(settings.name); // 'Hero Section'
42+
* console.log(settings.group); // 'Sections'
43+
* console.log(settings.description); // 'A reusable hero'
44+
* ```
45+
*/
46+
getSettings(): Promise<ComponentSettings>;
47+
/**
48+
* Update one or more settings on a component. All fields are optional.
49+
* Updates happen immediately without requiring an explicit save().
50+
* @param settings - A partial object of settings to update.
51+
* @returns A Promise that resolves when the update is complete.
52+
* @example
53+
* ```ts
54+
* await component.setSettings({
55+
* name: 'Hero Section v2',
56+
* group: 'Sections',
57+
* description: 'Updated hero with new CTA layout',
58+
* });
59+
* ```
60+
*/
61+
setSettings(settings: Partial<ComponentSettings>): Promise<null>;
3462
/**
3563
* Retrieve all variants of a component.
3664
* @returns A Promise resolving to an array containing all variants of the component
@@ -75,6 +103,15 @@ interface Component {
75103

76104
type ComponentId = string;
77105

106+
interface ComponentSettings {
107+
/** The name of the component */
108+
name: string;
109+
/** The group/folder the component belongs to (empty string if not set) */
110+
group: string;
111+
/** The description of the component (empty string if not set) */
112+
description: string;
113+
}
114+
78115
interface Variant {
79116
id: string;
80117
name: string;

src/examples/components.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@ export const Components = {
6969
console.log(heroes);
7070
},
7171

72+
getSettings: async () => {
73+
// Get the first component's settings
74+
const component = (await webflow.getAllComponents())[0]
75+
const settings = await component.getSettings()
76+
console.log(settings)
77+
/*
78+
{
79+
name: 'Hero Section',
80+
group: 'Sections',
81+
description: 'A reusable hero with heading and CTA'
82+
}
83+
*/
84+
},
85+
86+
setSettings: async () => {
87+
const component = (await webflow.getAllComponents())[0]
88+
89+
// Update only the description
90+
await component.setSettings({
91+
description: 'Updated hero layout with video background',
92+
})
93+
94+
// Move to a different group
95+
await component.setSettings({ group: 'Legacy' })
96+
97+
// Update everything at once
98+
await component.setSettings({
99+
name: 'Hero Section v2',
100+
group: 'Sections',
101+
description: 'Redesigned hero component',
102+
})
103+
},
104+
72105
getInstanceCount: async () => {
73106
// Audit component usage across the site
74107
const components = await webflow.getAllComponents();

0 commit comments

Comments
 (0)