forked from finos/a11y-theme-builder-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.ts
181 lines (149 loc) · 4.71 KB
/
interfaces.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Copyright (c) 2023 Discover Financial Services
* Licensed under Apache-2.0 License. See License.txt in the project root for license information
*/
import { Storage } from "./storage/index";
import { Shade } from "./common/shade";
import { PropertyTitledShade, PropertyStringSelectable, PropertyString } from "./common";
/**
* The node interface, representing the node of a tree.
*/
export interface INode {
/** The unique key of the node */
key: string;
/**
* Set a listener for events on this node.
* @param name The listener name
* @param callback The callback for each event.
* @param eventTypes The event types requiring notification, or undefined if all event types.
*/
setListener(name: string, callback: EventCallback, eventTypes?: EventType[]): IListenerSubscription;
/**
* Remove a listener from this node.
* @param name Name of the listener to remove.
*/
removeListener(name: string): void;
notifyListeners(event: Event): void;
}
export interface IListenerSubscription {
cancel(): void; // Same as calling removeListener above
}
export interface IProperty extends INode {
required: boolean;
getDefaultValue(): any;
isInitialized(): boolean;
}
export interface IAtoms extends INode {
colorPalette: IColorPalette;
colorThemes: IColorThemes;
gridSettings: IGridSettings;
inputBackground: IInputBackground;
fontsSettings: IFontsSettings;
addAtom(atom: IAtom): void;
}
export interface IColorPalette extends IAtom {
setColorListener(name: string, listener: ColorListener): void;
}
export interface IColorThemes extends IAtom {
defaultTheme: PropertyStringSelectable;
getDefaultTheme(): IColorTheme | undefined;
atoms: IAtoms;
}
export interface IGridSettings extends IAtom {}
export interface IInputBackground extends IAtom {
overlayColor: PropertyTitledShade;
}
export interface IFontsSettings {
primaryFont: PropertyString;
secondaryFont: PropertyString;
}
export interface IAtom extends INode {}
export interface IMolecules extends INode {}
export interface IMolecule extends INode {}
export interface IOrganisms extends INode {}
export interface IOrganism extends INode {}
export interface IColorTheme extends IAtom {}
export enum EventType {
NodeEnabled = "NodeEnabled",
NodeDisabled = "NodeDisabled",
NodeDeleted = "NodeDeleted",
ValueChanged = "ValueChanged",
ValueDeleted = "ValueDeleted",
SelectablesChanged = "SelectablesChanged",
}
export interface Event {
type: EventType
node: INode;
}
export interface EventValueChange<T> extends Event {
oldValue?: T;
newValue?: T;
}
export type EventCallback = (event: Event) => void;
export type EventValueChangeCallback<T> = (event: EventValueChange<T>) => void;
export interface EventListener {
eventTypes?: EventType[];
callback: EventCallback;
}
export type IVarGroupListener = (group: IVarGroup) => void;
export interface IVarGroup {
vars: {[name: string]: string};
setListener(name: string, listener: IVarGroupListener): void;
}
export interface IDesignSystemMetadata {
/** Denotes whether or not this is a sample design system */
sample: boolean;
/** Time stamps */
time: {
/** The created time in milliseconds */
createdInMs: number;
/** The last update time in milliseconds */
lastUpdateInMs: number;
};
/** Colors */
colors: {
/** The hex or RGBA string for the primary color */
primary: string;
/** The hex or RGBA string for the secondary color */
secondary: string;
/** The hex or RGBA string for the tertiary color */
tertiary: string;
/** The hex or RGBA string for the background color */
background: string;
};
}
export interface IDesignSystem extends INode {
atoms: IAtoms;
molecules: IMolecules;
organisms: IOrganisms;
registerNode(node: INode): void;
getNode(key: string): INode | undefined;
registerShade(key: string, shade: Shade): void;
getShade(key: string): Shade | undefined;
findShade(key: string): Shade;
getCSSVarGroup(node: INode): IVarGroup;
listProperties(): IProperty[];
}
export interface IThemeBuilder {
storage: Storage;
}
export type VarListener = (name: string, value?: string) => void;
export type ShadeFilter = (shade: Shade) => boolean;
export type ColorListener = (name: string, color?: IColor) => void;
export interface IColor {
name: string;
hex: IProperty;
light: IColorMode;
dark: IColorMode;
}
export interface IColorMode {
key: string;
name: string;
color: IColor;
shades: Shade[];
}
export interface IGeneratedVar {
name: string;
unit: string;
props: IProperty[];
}