UNPKG

11.5 kBTypeScriptView Raw
1import { Signal } from '@lumino/signaling';
2import { ElementAttrs, VirtualElement, VirtualNode } from '@lumino/virtualdom';
3import React from 'react';
4import { LabIconStyle } from '../style';
5export declare class LabIcon implements LabIcon.ILabIcon, VirtualElement.IRenderer {
6 /** *********
7 * statics *
8 ***********/
9 /**
10 * Remove any rendered icon from the element that contains it
11 *
12 * @param container - a DOM node into which an icon was
13 * previously rendered
14 *
15 * @returns the cleaned container
16 */
17 static remove(container: HTMLElement): HTMLElement;
18 /**
19 * Resolve an icon name or a {name, svgstr} pair into an
20 * actual LabIcon.
21 *
22 * @param icon - either a string with the name of an existing icon
23 * or an object with {name: string, svgstr: string} fields.
24 *
25 * @returns a LabIcon instance
26 */
27 static resolve({ icon }: {
28 icon: LabIcon.IResolvable;
29 }): LabIcon;
30 /**
31 * Resolve an icon name or a {name, svgstr} pair into a DOM element.
32 * If icon arg is undefined, the function will fall back to trying to render
33 * the icon as a CSS background image, via the iconClass arg.
34 * If both icon and iconClass are undefined, this function will return
35 * an empty div.
36 *
37 * @param icon - optional, either a string with the name of an existing icon
38 * or an object with {name: string, svgstr: string} fields
39 *
40 * @param iconClass - optional, if the icon arg is not set, the iconClass arg
41 * should be a CSS class associated with an existing CSS background-image
42 *
43 * @deprecated fallback - don't use, optional, a LabIcon instance that will
44 * be used if neither icon nor iconClass are defined
45 *
46 * @param props - any additional args are passed though to the element method
47 * of the resolved icon on render
48 *
49 * @returns a DOM node with the resolved icon rendered into it
50 */
51 static resolveElement({ icon, iconClass, fallback, ...props }: Partial<LabIcon.IResolverProps> & LabIcon.IProps): HTMLElement;
52 /**
53 * Resolve an icon name or a {name, svgstr} pair into a React component.
54 * If icon arg is undefined, the function will fall back to trying to render
55 * the icon as a CSS background image, via the iconClass arg.
56 * If both icon and iconClass are undefined, the returned component
57 * will simply render an empty div.
58 *
59 * @param icon - optional, either a string with the name of an existing icon
60 * or an object with {name: string, svgstr: string} fields
61 *
62 * @param iconClass - optional, if the icon arg is not set, the iconClass arg
63 * should be a CSS class associated with an existing CSS background-image
64 *
65 * @deprecated fallback - don't use, optional, a LabIcon instance that will
66 * be used if neither icon nor iconClass are defined
67 *
68 * @param props - any additional args are passed though to the React component
69 * of the resolved icon on render
70 *
71 * @returns a React component that will render the resolved icon
72 */
73 static resolveReact({ icon, iconClass, fallback, ...props }: Partial<LabIcon.IResolverProps> & LabIcon.IReactProps): JSX.Element;
74 /**
75 * Resolve a {name, svgstr} pair into an actual svg node.
76 */
77 static resolveSvg({ name, svgstr }: LabIcon.IIcon): HTMLElement | null;
78 /**
79 * Toggle icon debug from off-to-on, or vice-versa.
80 *
81 * @param debug - optional boolean to force debug on or off
82 */
83 static toggleDebug(debug?: boolean): void;
84 private static _debug;
85 private static _instances;
86 /** *********
87 * members *
88 ***********/
89 constructor({ name, svgstr, render, unrender, _loading }: LabIcon.IOptions & {
90 _loading?: boolean;
91 });
92 /**
93 * Get a view of this icon that is bound to the specified icon/style props
94 *
95 * @param optional icon/style props (same as args for .element
96 * and .react methods). These will be bound to the resulting view
97 *
98 * @returns a view of this LabIcon instance
99 */
100 bindprops(props?: LabIcon.IProps): any;
101 /**
102 * Create an icon as a DOM element
103 *
104 * @param className - a string that will be used as the class
105 * of the container element. Overrides any existing class
106 *
107 * @param container - a preexisting DOM element that
108 * will be used as the container for the svg element
109 *
110 * @param label - text that will be displayed adjacent
111 * to the icon
112 *
113 * @param title - a tooltip for the icon
114 *
115 * @param tag - if container is not explicitly
116 * provided, this tag will be used when creating the container
117 *
118 * @param stylesheet - optional string naming a builtin icon
119 * stylesheet, for example 'menuItem' or `statusBar`. Can also be an
120 * object defining a custom icon stylesheet, or a list of builtin
121 * stylesheet names and/or custom stylesheet objects. If array,
122 * the given stylesheets will be merged.
123 *
124 * See @jupyterlab/ui-components/src/style/icon.ts for details
125 *
126 * @param elementPosition - optional position for the inner svg element
127 *
128 * @param elementSize - optional size for the inner svg element.
129 * Set to 'normal' to get a standard 16px x 16px icon
130 *
131 * @param ...elementCSS - all additional args are treated as
132 * overrides for the CSS props applied to the inner svg element
133 *
134 * @returns A DOM element that contains an (inline) svg element
135 * that displays an icon
136 */
137 element(props?: LabIcon.IProps): HTMLElement;
138 render(container: HTMLElement, options?: LabIcon.IRendererOptions): void;
139 protected get svgElement(): HTMLElement | null;
140 protected get svgInnerHTML(): string | null;
141 protected get svgReactAttrs(): any | null;
142 get svgstr(): string;
143 set svgstr(svgstr: string);
144 unrender?(container: HTMLElement, options?: LabIcon.IRendererOptions): void;
145 protected _initReact(displayName: string): React.ForwardRefExoticComponent<LabIcon.IReactProps>;
146 protected _initRender({ render, unrender }: Partial<VirtualElement.IRenderer>): void;
147 protected _initSvg({ title, uuid }?: {
148 title?: string;
149 uuid?: string;
150 }): HTMLElement | null;
151 readonly name: string;
152 /**
153 * A React component that will create the icon.
154 *
155 * @param className - a string that will be used as the class
156 * of the container element. Overrides any existing class
157 *
158 * @param container - a preexisting DOM element that
159 * will be used as the container for the svg element
160 *
161 * @param label - text that will be displayed adjacent
162 * to the icon
163 *
164 * @param title - a tooltip for the icon
165 *
166 * @param tag - if container is not explicitly
167 * provided, this tag will be used when creating the container
168 *
169 * @param stylesheet - optional string naming a builtin icon
170 * stylesheet, for example 'menuItem' or `statusBar`. Can also be an
171 * object defining a custom icon stylesheet, or a list of builtin
172 * stylesheet names and/or custom stylesheet objects. If array,
173 * the given stylesheets will be merged.
174 *
175 * See @jupyterlab/ui-components/src/style/icon.ts for details
176 *
177 * @param elementPosition - optional position for the inner svg element
178 *
179 * @param elementSize - optional size for the inner svg element.
180 * Set to 'normal' to get a standard 16px x 16px icon
181 *
182 * @param ...elementCSS - all additional args are treated as
183 * overrides for the CSS props applied to the inner svg element
184 *
185 * @param ref - forwarded to the ref prop of the icon's svg element
186 */
187 readonly react: LabIcon.IReact;
188 protected _className: string;
189 protected _loading: boolean;
190 protected _props: LabIcon.IProps;
191 protected _svgReplaced: Signal<this, void>;
192 protected _svgstr: string;
193 protected _uuid: string;
194 /**
195 * Cache for svg parsing intermediates
196 * - undefined: the cache has not yet been populated
197 * - null: a valid, but empty, value
198 */
199 protected _svgElement: HTMLElement | null | undefined;
200 protected _svgInnerHTML: string | null | undefined;
201 protected _svgReactAttrs: any | null | undefined;
202}
203/**
204 * A namespace for LabIcon statics.
205 */
206export declare namespace LabIcon {
207 /** ***********
208 * interfaces *
209 *************/
210 /**
211 * The simplest possible interface for defining a generic icon.
212 */
213 interface IIcon {
214 /**
215 * The name of the icon. By convention, the icon name will be namespaced
216 * as so:
217 *
218 * "pkg-name:icon-name"
219 */
220 readonly name: string;
221 /**
222 * A string containing the raw contents of an svg file.
223 */
224 svgstr: string;
225 }
226 interface IRendererOptions {
227 attrs?: ElementAttrs;
228 children?: ReadonlyArray<VirtualNode>;
229 props?: IProps;
230 }
231 /**
232 * The ILabIcon interface. Outside of this interface the actual
233 * implementation of LabIcon may vary
234 */
235 interface ILabIcon extends IIcon, VirtualElement.IRenderer {
236 }
237 /**
238 * Interface defining the parameters to be passed to the LabIcon
239 * constructor
240 */
241 interface IOptions extends IIcon, Partial<VirtualElement.IRenderer> {
242 }
243 /**
244 * The input props for creating a new LabIcon
245 */
246 interface IProps extends LabIconStyle.IProps {
247 /**
248 * Extra classNames. Used in addition to the typestyle className to
249 * set the className of the icon's outermost container node
250 */
251 className?: string;
252 /**
253 * The icon's outermost node, which acts as a container for the actual
254 * svg node. If container is not supplied, it will be created
255 */
256 container?: HTMLElement;
257 /**
258 * Optional text label that will be added as a sibling to the icon's
259 * svg node
260 */
261 label?: string;
262 /**
263 * HTML element tag used to create the icon's outermost container node,
264 * if no container is passed in
265 */
266 tag?: 'div' | 'span';
267 /**
268 * Optional title that will be set on the icon's outermost container node
269 */
270 title?: string;
271 }
272 interface IResolverProps {
273 icon?: IMaybeResolvable;
274 iconClass?: string;
275 fallback?: LabIcon;
276 }
277 /** ******
278 * types *
279 *********/
280 /**
281 * A type that can be resolved to a LabIcon instance.
282 */
283 type IResolvable = string | (IIcon & Partial<VirtualElement.IRenderer>);
284 /**
285 * A type that maybe can be resolved to a LabIcon instance.
286 */
287 type IMaybeResolvable = IResolvable | VirtualElement.IRenderer | undefined;
288 /**
289 * The type of the svg node ref that can be passed into icon React components
290 */
291 type IReactRef = React.RefObject<SVGElement>;
292 /**
293 * The properties that can be passed into the React component stored in
294 * the .react field of a LabIcon.
295 */
296 type IReactProps = IProps & React.RefAttributes<SVGElement>;
297 /**
298 * The complete type of the React component stored in the .react
299 * field of a LabIcon.
300 */
301 type IReact = React.ForwardRefExoticComponent<IReactProps>;
302}
303export declare const badIcon: LabIcon;
304export declare const blankIcon: LabIcon;