Skip to content

Commit

Permalink
Improve the default icon renderer
Browse files Browse the repository at this point in the history
- allow the default renderer to receive additional classes
- rename it for consistency
- avoid sending non related props to div element
  • Loading branch information
brichet committed Nov 22, 2024
1 parent 04359c5 commit 228a246
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/collaboration/src/users-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { DocumentRegistry } from '@jupyterlab/docregistry';
import { User } from '@jupyterlab/services';
import { ReactWidget } from '@jupyterlab/ui-components';
import { classes, ReactWidget } from '@jupyterlab/ui-components';
import * as React from 'react';

const USERS_ITEM_CLASS = 'jp-toolbar-users-item';
Expand Down Expand Up @@ -119,7 +119,7 @@ export class UsersItem extends React.Component<
}

render(): React.ReactNode {
const IconRenderer = this._iconRenderer ?? DefaultUserIcon;
const IconRenderer = this._iconRenderer ?? DefaultIconRenderer;
return (
<div className={USERS_ITEM_CLASS}>
{this.filterDuplicated(this.state.usersList).map(user => {
Expand Down Expand Up @@ -161,34 +161,38 @@ export class UsersItem extends React.Component<
}

/**
* Default function displaying a user icon.
* Default renderer for the user icon.
*/
export function DefaultUserIcon(
export function DefaultIconRenderer(
props: UsersItem.IIconRendererProps
): JSX.Element {
let el: JSX.Element;
const { userId, userData } = props.user;
if (userData.avatar_url) {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { user, model, ...htmlProps } = props;

const iconClasses = classes('lm-MenuBar-itemIcon', props.className || '');
if (user.userData.avatar_url) {
el = (
<div
{...props}
key={userId}
title={userData.display_name}
className={'lm-MenuBar-itemIcon jp-MenuBar-imageIcon'}
{...htmlProps}
key={user.userId}
title={user.userData.display_name}
className={classes(iconClasses, 'jp-MenuBar-imageIcon')}
>
<img src={userData.avatar_url} alt="" />
<img src={user.userData.avatar_url} alt="" />
</div>
);
} else {
el = (
<div
{...props}
key={userId}
title={userData.display_name}
className={'lm-MenuBar-itemIcon jp-MenuBar-anonymousIcon'}
style={{ backgroundColor: userData.color }}
{...htmlProps}
key={user.userId}
title={user.userData.display_name}
className={classes(iconClasses, 'jp-MenuBar-anonymousIcon')}
style={{ backgroundColor: user.userData.color }}
>
<span>{userData.initials}</span>
<span>{user.userData.initials}</span>
</div>
);
}
Expand Down

0 comments on commit 228a246

Please sign in to comment.