UNPKG

4.79 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Rating {
3 settings: RatingSettings;
4
5 /**
6 * Sets rating programmatically.
7 */
8 (behavior: 'set rating', rating: number): JQuery;
9
10 /**
11 * Gets current rating.
12 */
13 (behavior: 'get rating'): number;
14
15 /**
16 * Disables interactive rating mode.
17 */
18 (behavior: 'disable'): JQuery;
19
20 /**
21 * Enables interactive rating mode.
22 */
23 (behavior: 'enable'): JQuery;
24
25 /**
26 * Clears current rating.
27 */
28 (behavior: 'clear rating'): JQuery;
29
30 (behavior: 'destroy'): JQuery;
31 <K extends keyof RatingSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<RatingSettings, keyof RatingSettings>>;
32 <K extends keyof RatingSettings>(behavior: 'setting', name: K, value: RatingSettings[K]): JQuery;
33 (behavior: 'setting', value: Partial<Pick<RatingSettings, keyof RatingSettings>>): JQuery;
34 (settings?: Partial<Pick<RatingSettings, keyof RatingSettings>>): JQuery;
35 }
36
37 /**
38 * @see {@link https://fomantic-ui.com/modules/rating.html#/settings}
39 */
40 interface RatingSettings {
41 // region Accordion Settings
42
43 /**
44 * The icon classname.
45 * @default 'star'
46 */
47 icon: string;
48
49 /**
50 * A number representing the default rating to apply.
51 * @default 0
52 */
53 initialRating: number;
54
55 /**
56 * The maximum rating value.
57 * @default 4
58 */
59 maxRating: number;
60
61 /**
62 * Whether callbacks like 'onRate' should fire immediately after initializing with the current value.
63 * @default false
64 */
65 fireOnInit: boolean;
66
67 /**
68 * By default a rating will be only clearable if there is 1 icon.
69 * Setting to 'true'/'false' will allow or disallow a user to clear their rating.
70 * @default 'auto'
71 */
72 clearable: 'auto' | boolean;
73
74 /**
75 * Whether to enable user's ability to rate.
76 * @default true
77 */
78 interactive: boolean;
79
80 // endregion
81
82 // region Callbacks
83
84 /**
85 * Is called after user selects a new rating.
86 */
87 onRate(this: JQuery, value: number): void;
88
89 // endregion
90
91 // region DOM Settings
92
93 /**
94 * DOM Selectors used internally.
95 * Selectors used to find parts of a module.
96 */
97 selector: Rating.SelectorSettings;
98
99 /**
100 * Class names used to determine element state.
101 */
102 className: Rating.ClassNameSettings;
103
104 // endregion
105
106 // region Debug Settings
107
108 /**
109 * Name used in log statements
110 * @default 'Rating'
111 */
112 name: string;
113
114 /**
115 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
116 * @default 'rating'
117 */
118 namespace: string;
119
120 /**
121 * Silences all console output including error messages, regardless of other debug settings.
122 * @default false
123 */
124 silent: boolean;
125
126 /**
127 * Debug output to console
128 * @default false
129 */
130 debug: boolean;
131
132 /**
133 * Show console.table output with performance metrics
134 * @default true
135 */
136 performance: boolean;
137
138 /**
139 * Debug output includes all internal behaviors
140 * @default false
141 */
142 verbose: boolean;
143
144 error: Rating.ErrorSettings;
145
146 // endregion
147 }
148
149 namespace Rating {
150 type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
151 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
152 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
153
154 namespace Settings {
155 interface Selectors {
156 /**
157 * @default '.icon'
158 */
159 icon: string;
160 }
161
162 interface ClassNames {
163 /**
164 * @default 'active'
165 */
166 active: string;
167
168 /**
169 * @default 'hover'
170 */
171 hover: string;
172
173 /**
174 * @default 'loading'
175 */
176 loading: string;
177 }
178
179 interface Errors {
180 /**
181 * @default 'You called a rating action that was not defined'
182 */
183 action: string;
184 }
185 }
186 }
187}