forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
widgets.ts
56 lines (49 loc) · 2.11 KB
/
widgets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { ComponentType } from 'react'
import { ActionCategoryMaker, ActionComponentProps } from './actions'
export enum WidgetLocation {
// Widget is displayed on the homepage (the first tab).
Home = 'home',
// Widget is displayed in its own tab. `Icon` must be provided as well.
Tab = 'tab',
}
export enum WidgetVisibilityContext {
// Widget is always visible.
Always = 'always',
// Widget is visible only for members.
OnlyMembers = 'onlyMembers',
// Widget is visible only for non-members. This is also visible when no wallet
// is connected, as the user is not known to be a member.
OnlyNonMembers = 'onlyNonMembers',
}
export type WidgetRendererProps<Variables extends Record<string, unknown>> = {
variables: Variables
}
export type WidgetEditorProps<Variables extends Record<string, unknown> = any> =
ActionComponentProps<undefined, Variables>
export type Widget<Variables extends Record<string, unknown> = any> = {
// A unique identifier for the widget.
id: string
// An icon for the widget. Used when `location` is `WidgetLocation.Tab`.
Icon?: ComponentType<{ className: string }>
// The location where the widget is displayed.
location: WidgetLocation
// The context in which the widget is visible.
visibilityContext: WidgetVisibilityContext
// If defined, the widget is only available on these chains.
supportedChainIds?: string[]
// The default values for the widget's variables.
defaultValues?: Variables
// Component that renders the widget.
Renderer: ComponentType<WidgetRendererProps<Variables>>
// Component that allows the user to edit the widget's variables in an action.
Editor?: ComponentType<WidgetEditorProps<Variables>>
// Actions that are available in proposals when this widget is enabled.
getActionCategoryMakers?: (variables: Variables) => ActionCategoryMaker[]
}
// DaoWidget is the structure of a widget as stored in the DAO's core item map
// as a JSON-encoded object. It stores the unique identifier of the widget and
// the values for the widget's variables so that it can be rendered.
export type DaoWidget = {
id: string
values?: Record<string, unknown>
}