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

Custom icon in a launcher card #7887

Closed
jtpio opened this issue Feb 17, 2020 · 3 comments
Closed

Custom icon in a launcher card #7887

jtpio opened this issue Feb 17, 2020 · 3 comments
Labels
status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@jtpio
Copy link
Member

jtpio commented Feb 17, 2020

At the moment in 1.x, users can pass an iconClass to a command:

commands.addCommand(command, {
  label: 'Custom Command',
  caption: 'Launch Custom Command',
  iconClass: args => (args['isPalette'] ? '' : 'jp-CustomIcon'),
  ...
});

And define an icon as CSS background:

.jp-CustomIcon {
  background-image: url('custom.svg');
}

The icon should show up correctly in the launcher card.

In 2.x, it looks like the DOM element is not created unless a new LabIcon was instantiated beforehand:

if (LabIcon._instancesByNameAndClassName.has(className)) {
const icon = LabIcon._instancesByNameAndClassName.get(className)!;
return <icon.react {...props} />;
}

See this commit as an example: jupyterlab/extension-examples@b81943d

It works for the default icons in core because their LabIcon is defined in iconimports.ts.

I wonder if the behavior in 1.x should be kept (keeping the DOM element with the CSS class)? When a user sees "class" in iconClass, she might expect it to correspond to the class added to the DOM element, which could then be styled in CSS.

Maybe something to consider in #7864? cc @telamonian

@telamonian
Copy link
Member

What you described was indeed the intended behavior (if no LabIcon existed matching iconClass, it was supposed to render a blank div with class=iconClass), but basically UNSTABLE_getReact had some problems (there was a reason I marked it UNSTABLE) and couldn't handle this situation correctly.

#7864 is now done, and it should make things much simpler. Every interface that has an .iconClass field now also has an .icon field, and they are completely orthogonal. For example, you can set a LabIcon on a command like so:

commands.addCommand(command, {
  icon: args => args['isPalette'] ? undefined : fooIcon,
  ...
});

and if you want the old icon-as-css-background behavior, you can just use iconClass the same way as you did in 1.x, unchanged:

commands.addCommand(command, {
  iconClass: args => (args['isPalette'] ? '' : 'jp-CustomIcon'),
  ...
});

If for whatever reason you set both icon and iconClass, iconClass will be ignored.

@jtpio
Copy link
Member Author

jtpio commented Feb 25, 2020

Thanks @telamonian.

Indeed it sounds like we can consolidate the documentation to make these cases more discoverable to extension developers.

@jtpio
Copy link
Member Author

jtpio commented Mar 12, 2020

This should now be fixed in 2.0, thanks @telamonian!

@jtpio jtpio closed this as completed Mar 12, 2020
@jtpio jtpio added this to the 2.0 milestone Mar 12, 2020
@lock lock bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Apr 15, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

No branches or pull requests

2 participants