Skip to content

Commit

Permalink
docs(dynamicWidgets): implement tsdoc for parameters (#4920)
Browse files Browse the repository at this point in the history
* docs(dynamicWidgets): implement tsdoc for parameters

* Apply suggestions from code review

Co-authored-by: Sarah Dayan <[email protected]>

Co-authored-by: Sarah Dayan <[email protected]>
  • Loading branch information
Haroenv and sarahdayan authored Oct 13, 2021
1 parent 76afacb commit 041b70e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/connectors/dynamic-widgets/connectDynamicWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,24 @@ export type DynamicWidgetsRenderState = {
};

export type DynamicWidgetsConnectorParams = {
/**
* An array of widgets, displayed in the order defined by `facetOrdering`.
*/
widgets: Widget[];
fallbackWidget?(args: { attribute: string }): Widget;

/**
* Function to return a fallback widget when an attribute isn't found in
* `widgets`.
*/
fallbackWidget?(args: {
/** The attribute name to create a widget for. */
attribute: string;
}): Widget;

/**
* Function to transform the items to render.
* The function also exposes the full search response.
*/
transformItems?(
items: string[],
metadata: { results: SearchResults }
Expand Down
22 changes: 20 additions & 2 deletions src/widgets/dynamic-widgets/dynamic-widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,27 @@ const withUsage = createDocumentationMessageGenerator({
const suit = component('DynamicWidgets');

export type DynamicWidgetsWidgetParams = {
container: HTMLElement | string;
/**
* CSS Selector or HTMLElement to insert the widget.
*/
container: string | HTMLElement;

/**
* An array of widget creator functions, displayed in the order defined by
* `facetOrdering`.
*/
widgets: Array<(container: HTMLElement) => Widget>;
fallbackWidget?(args: { attribute: string; container: HTMLElement }): Widget;

/**
* Function to return a fallback widget when an attribute isn't found in
* `widgets`.
*/
fallbackWidget?(args: {
/** The attribute name to create a widget for. */
attribute: string;
/** CSS Selector or HTMLElement to insert the widget */
container: HTMLElement;
}): Widget;
};

export type DynamicWidgetsWidget = WidgetFactory<
Expand Down

0 comments on commit 041b70e

Please sign in to comment.