1 | /**
|
2 | * @license
|
3 | * Copyright 2021 Google Inc.
|
4 | *
|
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 | * of this software and associated documentation files (the "Software"), to deal
|
7 | * in the Software without restriction, including without limitation the rights
|
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 | * copies of the Software, and to permit persons to whom the Software is
|
10 | * furnished to do so, subject to the following conditions:
|
11 | *
|
12 | * The above copyright notice and this permission notice shall be included in
|
13 | * all copies or substantial portions of the Software.
|
14 | *
|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 | * THE SOFTWARE.
|
22 | */
|
23 | import { CssClasses } from './constants';
|
24 | /**
|
25 | * The state of the switch.
|
26 | */
|
27 | export interface MDCSwitchState {
|
28 | /**
|
29 | * Indicates whether or not the switch is disabled.
|
30 | */
|
31 | disabled: boolean;
|
32 | /**
|
33 | * Indicates whether or not the switch is processing and showing a loading
|
34 | * indicator. A disabled switch cannot be processing.
|
35 | */
|
36 | processing: boolean;
|
37 | /**
|
38 | * If true, the switch is on. If false, the switch is off.
|
39 | */
|
40 | selected: boolean;
|
41 | }
|
42 | /**
|
43 | * Defines the shape of the adapter expected by the foundation.
|
44 | *
|
45 | * This adapter is used to delegate state-only updates from the foundation
|
46 | * to the component. It does not delegate DOM or rendering logic, such as adding
|
47 | * or removing classes.
|
48 | */
|
49 | export interface MDCSwitchAdapter {
|
50 | /**
|
51 | * The state of the component.
|
52 | */
|
53 | state: MDCSwitchState;
|
54 | }
|
55 | /**
|
56 | * Defines the shape of the adapter expected by the rendering foundation.
|
57 | *
|
58 | * This adapter is used to delegate state and rendering logic updates from the
|
59 | * rendering foundation to the component.
|
60 | */
|
61 | export interface MDCSwitchRenderAdapter extends MDCSwitchAdapter {
|
62 | /**
|
63 | * Adds a class to the root element.
|
64 | * @param className The class to add.
|
65 | */
|
66 | addClass(className: CssClasses): void;
|
67 | /**
|
68 | * Returns whether or not the root element has a class.
|
69 | * @param className The class to check.
|
70 | * @return true if the root element has the class, or false if not.
|
71 | */
|
72 | hasClass(className: CssClasses): boolean;
|
73 | /**
|
74 | * Checks if the root element is disabled.
|
75 | * @return true if the root element is disabled, or false if not.
|
76 | */
|
77 | isDisabled(): boolean;
|
78 | /**
|
79 | * Removes a class from the root element.
|
80 | * @param className The class to remove.
|
81 | */
|
82 | removeClass(className: CssClasses): void;
|
83 | /**
|
84 | * Sets the `aria-checked` attribute of the root element.
|
85 | * @param ariaChecked The value of the attribute to set.
|
86 | */
|
87 | setAriaChecked(ariaChecked: string): void;
|
88 | /**
|
89 | * Disables or enables the root element.
|
90 | * @param disabled True to disable the root element, or false to enable.
|
91 | */
|
92 | setDisabled(disabled: boolean): void;
|
93 | }
|