Skip to content

Commit

Permalink
fixed up signature of IRenderer.render, can now flexibly take options
Browse files Browse the repository at this point in the history
- related to code added to @lumino/virtualdom in jupyterlab/lumino#44. Once that's pulled in, the TODOs added in this PR will then be able to be cleared
  • Loading branch information
telamonian committed Jan 26, 2020
1 parent 3923fe7 commit 1cc6735
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/rendermime-interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export namespace IRenderMime {
* Interface for generic renderer.
*/
export interface IRenderer {
readonly render: (container: HTMLElement) => void;
readonly render: (container: HTMLElement, options?: any) => void;
// TODO: make unrenderer optional once @lumino/virtualdom > 1.4.1 is used
readonly unrender: (container: HTMLElement) => void;
}

Expand Down
31 changes: 24 additions & 7 deletions packages/ui-components/src/icon/jlicon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { UUID } from '@lumino/coreutils';
import { Signal } from '@lumino/signaling';
import { ElementAttrs, VirtualNode } from '@lumino/virtualdom';
import React from 'react';
import ReactDOM from 'react-dom';

Expand Down Expand Up @@ -554,10 +555,16 @@ export namespace JLIcon {
* Title.iconRenderer from @lumino/widgets
*/
export interface IRenderer {
readonly render: (container: HTMLElement) => void;
readonly render: (container: HTMLElement, options: any) => void;
readonly unrender: (container: HTMLElement) => void;
}

export interface IRendererOptions {
attrs?: ElementAttrs;
children?: ReadonlyArray<VirtualNode>;
props?: IProps;
}

/**
* The IJLIcon interface. Outside of this interface the actual
* implementation of JLIcon may vary
Expand Down Expand Up @@ -635,10 +642,14 @@ export namespace JLIcon {
* Base implementation of IRenderer.
*/
export class Renderer implements IRenderer {
constructor(protected _icon: JLIcon, protected _props?: IProps) {}
constructor(
protected _icon: JLIcon,
protected _options: IRendererOptions = {}
) {}

// tslint:disable-next-line:no-empty
render(container: HTMLElement): void {}
render(container: HTMLElement, _options: IRendererOptions = {}): void {}
// TODO: make unrenderer optional once @lumino/virtualdom > 1.4.1 is used
// tslint:disable-next-line:no-empty
unrender(container: HTMLElement): void {}
}
Expand All @@ -648,11 +659,16 @@ export namespace JLIcon {
* as a DOM element.
*/
export class ElementRenderer extends Renderer {
render(container: HTMLElement, props: JLIcon.IProps = {}): void {
render(container: HTMLElement, _options: IRendererOptions = {}): void {
// TODO: move this title fix to the Lumino side
container.removeAttribute('title');

this._icon.element({ container, ...this._props, ...props });
// TODO: decide how to implement rendering of passed in child virtual nodes
this._icon.element({
container,
...this._options.props,
..._options.props
});
}

// tslint:disable-next-line:no-empty
Expand All @@ -664,14 +680,15 @@ export namespace JLIcon {
* as a React component.
*/
export class ReactRenderer extends Renderer {
render(container: HTMLElement, props: JLIcon.IProps = {}): void {
render(container: HTMLElement, _options: IRendererOptions = {}): void {
// TODO: move this title fix to the Lumino side
container.removeAttribute('title');

// TODO: decide how to implement rendering of passed in child virtual nodes
return ReactDOM.render(
<this._icon.react
container={container}
{...{ ...this._props, ...props }}
{...{ ...this._options.props, ..._options.props }}
/>,
container
);
Expand Down

0 comments on commit 1cc6735

Please sign in to comment.