forked from ForgeRock/forgerock-javascript-sdk-ui
/
interfaces.ts
77 lines (67 loc) · 1.74 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
/*
* @forgerock/javascript-sdk-ui
*
* interfaces.ts
*
* Copyright (c) 2020 ForgeRock. All rights reserved.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { FRCallback, FRStep } from '@forgerock/javascript-sdk';
/**
* Represents a callback renderer that can be consumed by a step handler.
*/
interface CallbackRenderer {
/**
* Handles any cleanup necessary after a step has been handled.
*/
destroy?: () => void;
/**
* Prepares the UI element for user interaction.
*/
focus?: () => void;
/**
* Gets whether the callback is valid for submission.
*/
isValid?: () => boolean;
/**
* Handles any actions required after the callback's UI has been added to the DOM.
*/
onInjected?: () => void;
/**
* Generates the UI for the callback and returns its top-level DOM element.
*/
render: () => HTMLElement;
}
/**
* A callback renderer that implements `focus()`.
*/
interface FocusableCallbackRenderer extends CallbackRenderer {
focus: () => void;
}
/**
* A callback renderer that implements `destroy()`.
*/
interface DestroyableCallbackRenderer extends CallbackRenderer {
destroy: () => void;
}
/**
* Represents a callback renderer factory.
*
* @param cb The callback to render
* @param index The index position of the callback in the step
* @param step The step that contains the callback
* @param onChange A function to call when the callback value changes
*/
type CallbackRendererFactory = (
cb: FRCallback,
index: number,
step: FRStep,
onChange: () => void,
) => CallbackRenderer | undefined;
export {
CallbackRenderer,
CallbackRendererFactory,
DestroyableCallbackRenderer,
FocusableCallbackRenderer,
};