Skip to content

Commit 849c23d

Browse files
authored
DEVREL-2698: Searching for Components (#25)
1 parent 13f733e commit 849c23d

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/components/PermissionsMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const permissionsMap: PermissionsMap = {
5353
getAllComponents: { permissions: ['canAccessCanvas'] },
5454
getComponentByName: { permissions: ['canAccessCanvas'] },
5555
getComponentByNameAndGroup: { permissions: ['canAccessCanvas'] },
56+
searchComponents: { permissions: ['canAccessCanvas'] },
5657
getInstanceCount: { permissions: ['canAccessCanvas'] },
5758
getVariants: { permissions: ['canAccessCanvas'] },
5859
getSelectedVariant: { permissions: ['canAccessCanvas'] },

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ interface WebflowApi {
185185
* ```
186186
*/
187187
getComponentByName(a: string, b?: string): Promise<Component>;
188+
/**
189+
* Searches for Components by name
190+
* @returns A Promise that resolves to an array or objects with information about matching Components, not the `Component` objects themselves.
191+
* @example
192+
* ```ts
193+
* const heroes = await webflow.searchComponents({ q: 'Hero' });
194+
* console.log(heroes);
195+
* ```
196+
*/
197+
searchComponents(options: SearchComponentsOptions?): Promise<Array<ComponentSearchResult>>
188198
/**
189199
* Gets the number of instances of a component.
190200
* @returns A Promise that resolves to the number of instances of the component across the entire site.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,21 @@ interface Variant {
8080
name: string;
8181
isSelected: boolean;
8282
}
83+
84+
interface SearchComponentsOptions {
85+
/** Fuzzy search query matching Component panel search behavior */
86+
q?: string;
87+
}
88+
interface ComponentLibrary {
89+
name: string;
90+
id: string;
91+
}
92+
interface ComponentSearchResult {
93+
id: string;
94+
name: string;
95+
group: string;
96+
description: string;
97+
instances: number;
98+
canEdit: boolean;
99+
library: ComponentLibrary | null;
100+
}

src/examples/components.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export const Components = {
6464
console.log(marketingHero.id);
6565
},
6666

67+
searchComponents: async () => {
68+
const heroes = await webflow.searchComponents({ q: 'Hero' });
69+
console.log(heroes);
70+
},
71+
6772
getInstanceCount: async () => {
6873
// Audit component usage across the site
6974
const components = await webflow.getAllComponents();

0 commit comments

Comments
 (0)