Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up handling of Icons under unified LabIcon #7767

Merged
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
40d8bc6
replaced JLIcon (and unwanted React sub-dep) in rendermime-interfaces
telamonian Jan 9, 2020
542a428
improved accuracy of IFileType.iconRenderer typing
telamonian Jan 10, 2020
00adfd5
use render method for listings icons, simplify iconRenderer typing
telamonian Jan 10, 2020
076cc66
integrity
telamonian Jan 10, 2020
5e2842e
delinted
telamonian Jan 10, 2020
b9aae6b
initital stab at minimal IJLIcon interface
telamonian Jan 18, 2020
fedda16
bugfix
telamonian Jan 18, 2020
43570ea
full revert of rendermime-interfaces; totally removed iconRenderer
telamonian Jan 18, 2020
b185d80
added namespacing to the JLIcon name prop
telamonian Jan 18, 2020
ddfcada
type cleanup
telamonian Jan 18, 2020
77ae24e
fixed unittests to deal with icon namespacing
telamonian Jan 21, 2020
49b3ffb
refined handling of icon container className
telamonian Jan 21, 2020
30d390a
added `icon: string | {name: string, svgstr: string}` field
telamonian Jan 23, 2020
346a52d
added JLIcon.resolve static method
telamonian Jan 24, 2020
8edce2f
added complete implementation of dynamic icon svg replacement
telamonian Jan 24, 2020
11fa636
split out JLIcon.IRenderer from JLIcon
telamonian Jan 24, 2020
a5ccf4f
fixed up FileType handling to match new icon stuff
telamonian Jan 24, 2020
6756532
removed icon backwards compatibility shim from filebrowser listing
telamonian Jan 24, 2020
ebe90e8
some type fixes
telamonian Jan 24, 2020
884726d
small cleanup of vega icon svg
telamonian Jan 24, 2020
83111f6
fixed up typings related to JLIcon.IRenderer; added lots of docstrings
telamonian Jan 24, 2020
65cdd2a
untangled IFileType vs FileType mess in DocumentRegistry
telamonian Jan 24, 2020
b1a8127
picked lint
telamonian Jan 25, 2020
cca887d
`IFileType.icon` now working in rendermime-interfaces;
telamonian Jan 25, 2020
b54af80
Merge branch 'master' into remove-jlicon-rendermime-interfaces
telamonian Jan 25, 2020
5f22efd
added index.ts to src/style subpkg of ui-components
telamonian Jan 25, 2020
73b9252
fixed external import of exports from src/style in ui-components pkg
telamonian Jan 25, 2020
5219caf
added render-related fields to `IFileType.icon` interface
telamonian Jan 25, 2020
7ad325a
removed outdated IconRegistry based stories
telamonian Jan 26, 2020
52a6b68
added stories based on new JLIcon icons
telamonian Jan 26, 2020
be2f1ba
cleanup for new story
telamonian Jan 26, 2020
67c8b8c
cleanup of interfaces/types and related docstrings
telamonian Jan 26, 2020
8c82f28
bugfix to Renderer constructor signature typing
telamonian Jan 26, 2020
4f6c104
use full icon implementation for `.icon` field in docregistry
telamonian Jan 26, 2020
655a20f
added icon upconversion to rendermime plugin creation routine
telamonian Jan 26, 2020
126a78e
removed DocumentRegistry.FileType and reverts all usages to IFileType
telamonian Jan 26, 2020
9e51d8f
bind passed render/unrender funcs in JLIcon constructor
telamonian Jan 26, 2020
8964804
minor cleanup of ensureUiComponents func
telamonian Jan 26, 2020
554a73e
change all refs to iconRenderer => icon across codebase
telamonian Jan 26, 2020
3923fe7
fixed handling of compolex cases in JLIcon.resolve and .constructor
telamonian Jan 26, 2020
1cc6735
fixed up signature of IRenderer.render, can now flexibly take options
telamonian Jan 26, 2020
66bc3e6
bugfix
telamonian Jan 26, 2020
43c0959
refactored all refs JLIcon => LabIcon; still need to move jlicon.tsx
telamonian Jan 27, 2020
1abde8d
finished JLIcon => LabIcon refactor by moving jlicon.tsx => labicon.tsx
telamonian Jan 27, 2020
9d393f9
added functions to help render icon-as-css-background nodes
telamonian Jan 27, 2020
6d75ad5
added a `LabIcon` user guide
telamonian Jan 27, 2020
1c10a5e
bugfix (for code) and formatting fix (for docs)
telamonian Jan 27, 2020
7a8eca5
added resolveElement and resolveReact static methods to LabIcon
telamonian Jan 27, 2020
8607a27
fixed resolveX methods; removed getElement, marked getReact => UNSTABLE
telamonian Jan 27, 2020
6671fc8
added the jupyter.lab.setting-icon field
telamonian Jan 27, 2020
a56f389
fixed up and simplified item icon handling in filebrowser listing
telamonian Jan 27, 2020
000e153
removed UNSTABLE_getReact from settingeditor
telamonian Jan 27, 2020
097c987
fixed wrong casing in icon name "textEditor" => "text-editor"
telamonian Jan 27, 2020
51c281b
bugfix; was passing extraneous props into LabIcon.resolveX methods
telamonian Jan 27, 2020
617c2bd
iconClass => iconName conversion shim mostly removed; one special case
telamonian Jan 28, 2020
59b2713
Merge branch 'master' into remove-jlicon-rendermime-interfaces
telamonian Jan 28, 2020
46543f5
adding optional fallback arg to LabIcon.resolveX methods
telamonian Jan 28, 2020
3316ea1
added in test-ui-components, build broken, need to fix
telamonian Jan 28, 2020
433ce6a
bugfix
telamonian Jan 28, 2020
2de04f2
implemented fallback arg for LabIcon.resolveX methods
telamonian Jan 29, 2020
d3b84f8
README now has just user docs; all dev docs now in CONTRIBUTING
telamonian Jan 29, 2020
7f464d3
iconStyle no longer exported; exposed LabIcon.UNSTABLE_style to replace
telamonian Jan 29, 2020
f2fd38d
removed last vestige of iconClass => icon name shim, with one exception
telamonian Jan 29, 2020
6877db5
added first actual unittest to test-ui-components
telamonian Jan 29, 2020
c384fc7
integrity
telamonian Jan 29, 2020
0170ca8
removed stranded `if (icon)` statement
telamonian Jan 29, 2020
e465195
better test icons for test-ui-components, care of @tgeorgeux
telamonian Jan 29, 2020
b221606
alphabetized existing extension point docs
telamonian Jan 29, 2020
6e53b50
added Icon section to extension points docs
telamonian Jan 29, 2020
6ec8cf3
added note/link about LabIcon to extension migration docs
telamonian Jan 29, 2020
b03c8d3
fix docs and add changelog entry
Jan 30, 2020
19e94a6
update ci_script
Jan 30, 2020
947f932
fixed typing error wrt latest lumino; removed unsafe widening of IRen…
telamonian Feb 3, 2020
282584c
allow other svg attributes in test
Feb 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cleanignore
Expand Up @@ -20,4 +20,6 @@
@.idea/

# ms IDE stuff
@*.code-workspace
@.history
@.vscode
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -57,4 +57,6 @@ junit.xml
.idea/

# ms IDE stuff
*.code-workspace
.history
.vscode
62 changes: 34 additions & 28 deletions buildutils/src/ensure-package.ts
Expand Up @@ -21,13 +21,13 @@ const HEADER_TEMPLATE = `
`;

const ICON_IMPORTS_TEMPLATE = `
import { JLIcon } from './jlicon';
import { LabIcon } from './labicon';

// icon svg import statements
{{iconImportStatements}}
{{svgImportStatements}}

// JLIcon instance construction
{{jliconConstruction}}
// LabIcon instance construction
{{labiconConstructions}}
`;

const ICON_CSS_CLASSES_TEMPLATE = `
Expand Down Expand Up @@ -355,48 +355,52 @@ export async function ensureUiComponents(
dorequire: boolean = false
): Promise<string[]> {
const funcName = 'ensureUiComponents';
const pkgName = utils.stem(pkgPath);
let messages: string[] = [];

const svgs = glob.sync(path.join(pkgPath, 'style/icons', '**/*.svg'));
const svgPaths = glob.sync(path.join(pkgPath, 'style/icons', '**/*.svg'));

/* support for glob import of icon svgs */
const iconSrcDir = path.join(pkgPath, 'src/icon');

// build the per-icon import code
let _iconImportStatements: string[] = [];
let _jliconConstruction: string[] = [];
svgs.forEach(svg => {
const name = utils.stem(svg);
const svgpath = path
.relative(iconSrcDir, svg)
let _svgImportStatements: string[] = [];
let _labiconConstructions: string[] = [];
svgPaths.forEach(svgPath => {
const svgName = utils.stem(svgPath);
const svgImportPath = path
.relative(iconSrcDir, svgPath)
.split(path.sep)
.join('/');

const svgname = utils.camelCase(name) + 'Svg';
const iconname = utils.camelCase(name) + 'Icon';
const svgstrRef = utils.camelCase(svgName) + 'Svgstr';
const iconRef = utils.camelCase(svgName) + 'Icon';
const iconName = [pkgName, utils.stem(svgPath)].join(':');

if (dorequire) {
// load the icon svg using `require`
_jliconConstruction.push(
`export const ${iconname} = new JLIcon({ name: '${name}', svgstr: require('${svgpath}').default });`
_labiconConstructions.push(
`export const ${iconRef} = new LabIcon({ name: '${iconName}', svgstr: require('${svgImportPath}').default });`
);
} else {
// load the icon svg using `import`
_iconImportStatements.push(`import ${svgname} from '${svgpath}';`);
_svgImportStatements.push(`import ${svgstrRef} from '${svgImportPath}';`);

_jliconConstruction.push(
`export const ${iconname} = new JLIcon({ name: '${name}', svgstr: ${svgname} });`
_labiconConstructions.push(
`export const ${iconRef} = new LabIcon({ name: '${iconName}', svgstr: ${svgstrRef} });`
);
}
});
const iconImportStatements = _iconImportStatements.join('\n');
const jliconConstruction = _jliconConstruction.join('\n');

// sort the statements and then join them
const svgImportStatements = _svgImportStatements.sort().join('\n');
const labiconConstructions = _labiconConstructions.sort().join('\n');

// generate the actual contents of the iconImports file
const iconImportsPath = path.join(iconSrcDir, 'iconimports.ts');
const iconImportsContents = utils.fromTemplate(
HEADER_TEMPLATE + ICON_IMPORTS_TEMPLATE,
{ funcName, iconImportStatements, jliconConstruction }
{ funcName, svgImportStatements, labiconConstructions }
);
messages.push(...ensureFile(iconImportsPath, iconImportsContents, false));

Expand All @@ -406,23 +410,25 @@ export async function ensureUiComponents(
// build the per-icon import code
let _iconCSSUrls: string[] = [];
let _iconCSSDeclarations: string[] = [];
svgs.forEach(svg => {
const name = utils.stem(svg);
const urlName = 'jp-icon-' + name;
const className = 'jp-' + utils.camelCase(name, true) + 'Icon';
svgPaths.forEach(svgPath => {
const svgName = utils.stem(svgPath);
const urlName = 'jp-icon-' + svgName;
const className = 'jp-' + utils.camelCase(svgName, true) + 'Icon';

_iconCSSUrls.push(
`--${urlName}: url('${path
.relative(iconCSSDir, svg)
.relative(iconCSSDir, svgPath)
.split(path.sep)
.join('/')}');`
);
_iconCSSDeclarations.push(
`.${className} {background-image: var(--${urlName})}`
);
});
const iconCSSUrls = _iconCSSUrls.join('\n');
const iconCSSDeclarations = _iconCSSDeclarations.join('\n');

// sort the statements and then join them
const iconCSSUrls = _iconCSSUrls.sort().join('\n');
const iconCSSDeclarations = _iconCSSDeclarations.sort().join('\n');

// generate the actual contents of the iconCSSClasses file
const iconCSSClassesPath = path.join(iconCSSDir, 'deprecated.css');
Expand Down
1 change: 1 addition & 0 deletions dev_mode/package.json
Expand Up @@ -391,6 +391,7 @@
"@jupyterlab/test-statedb": "../tests/test-statedb",
"@jupyterlab/test-statusbar": "../tests/test-statusbar",
"@jupyterlab/test-terminal": "../tests/test-terminal",
"@jupyterlab/test-ui-components": "../tests/test-ui-components",
"@jupyterlab/testutils": "../testutils",
"@jupyterlab/mock-extension": "../jupyterlab/tests/mock_packages/extension"
}
Expand Down
8 changes: 8 additions & 0 deletions docs/source/developer/extension_migration.rst
Expand Up @@ -168,3 +168,11 @@ For example, consider how the ``@jupyterlab/debugger`` extension's
``await sessionContext.session?.kernel?.info`` to check when a kernel is
ready and retrieve its details. --
`jupyterlab/debugger#337 <https://github.com/jupyterlab/debugger/pull/337>`__

Using the new icon system and ``LabIcon``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. note::

For full API documentation and examples of how to use
the new icon support based on ``LabIcon`` from ``@jupyterlab/ui-components``,
`consult the repository <https://github.com/jupyterlab/jupyterlab/tree/master/packages/ui-components#readme>`__.