LabIcon
design referenceDesign goals for JLIcon (already implemented):
fooIcon
outside of the file in which it is defined, the pattern will be to import fooIcon
string
with name or className).svgstr
property of any LabIcon
instance to trigger replacement)LabIcon.element
methoddata-icon-id
LabIcon.react
React componentMutationObserver
Design goals for JLIcon (partially implemented):
iconClass
from a number of interfacesPossible design patterns for JLIcon:
class
. The icon is used by creating a new instanceclass
. The icon is used by calling the appropriate instance methodPatterns 1) and 2) were both initially investigated (see jupyterlab/jupyterlab#7299). Pattern 3) was found to be easiest to reason about, and had a desirable set of tradeoffs relating to features like dynamic lookup and replacability (eg you can replace the svg of an icon by just setting the svgstr
field of the icon instance).
In general, icons in JupyterLab should be consumed either by creating a new instance of LabIcon
, or by importing an existing one from another file/package. This standard usage pattern does not work with a small set of edge cases. For these cases, it is necessary to dynamically fetch or create an icon. The process by which this occurs is referred to as icon resolution.
For example, in some cases an icon needs to be specified as a string containing the icon's name (eg in one of an extension's JSON-format .schema
files). So long as the candidate icon meets a certain minimal interface:
type IResolvable = string | {name: string, svgstr: string}
it can be resolved into an actual LabIcon
instance by LabIcon.resolve
. The following is the intended specification for how icon resolution is intended to work:
icon: IResolvable
aloneicon
is an instance of LabIcon
icon
icon
is an empty string
badIcon
icon
is a non-empty string
icon
is an icon name, attempt lookup in LabIcon._instances
{name: icon, svgstr: loadingSvgstr}
. Whenever the icon actually does get defined, the loading image will be dynamically replaced with the real one (implemented in LabIcon.constructor
)icon
is an object
icon
's paramsicon.name
or icon.svgstr
are empty
badIcon
icon.name
and icon.svgstr
are non-empty
icon
is a definition of a new icon, return new LabIcon(icon)
icon: IResolvable
and iconClass: string
togethericonClass
is empty, icon
is any
icon
aloneiconClass
is non-empty, icon
is undefined
className
set to iconClass
iconClass
is non-empty, icon
is an object
icon
alone, but set things up so that on icon
render, the className
of the resulting DOM node is set to iconClass
(for support of icon-as-css-background-image).icon: IResolvable
, iconClass: string
, and fallback: LabIcon
all togethericonClass
is empty, icon
is undefined, fallback
is defined
fallback
icon
and iconClass
togetherThe following icons were originally taken from a set of material design icons:
filetype/folder.svg
ic_folder_24px.svg
sidebar/build.svg
ic_build_24px.svg
sidebar/extension.svg
ic_extension_24px.svg
sidebar/palette.svg
ic_palette_24px.svg
sidebar/tab.svg
ic_tab_24px.svg
statusbar/kernel.svg
ic_memory_24px.svg