Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Restore support for icons passed directly. (#179)
Browse files Browse the repository at this point in the history
* Restore support for icons passed directly.

This was inadvertantly removed when adding support for titles for
outline nodes that gave a `kind`.

In the case the passed icon is itself an Atomicon, we look up the
corresponding name of the Atomicon and use that.

This also removes the `aria-label` set on the icon as the title should
suffice.

* resolve lint

* AtomiconName -> AtomiconType
  • Loading branch information
wbinnssmith committed Mar 2, 2018
1 parent f50e75d commit cece913
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
21 changes: 18 additions & 3 deletions modules/atom-ide-ui/pkg/atom-ide-outline-view/lib/OutlineView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import type {OutlineForUi, OutlineTreeForUi} from './createOutlines';
import type {TextToken} from 'nuclide-commons/tokenized-text';
import type {TreeNode, NodePath} from 'nuclide-commons-ui/SelectableTree';

import Atomicon from 'nuclide-commons-ui/Atomicon';
import Atomicon, {getTypeFromIconName} from 'nuclide-commons-ui/Atomicon';
import HighlightedText from 'nuclide-commons-ui/HighlightedText';
import {arrayEqual} from 'nuclide-commons/collection';
import memoizeUntilChanged from 'nuclide-commons/memoizeUntilChanged';
import UniversalDisposable from 'nuclide-commons/UniversalDisposable';

import * as React from 'react';
import classnames from 'classnames';
import invariant from 'assert';
import nullthrows from 'nullthrows';

Expand Down Expand Up @@ -412,9 +413,23 @@ function renderItem(
): React.Element<string> | string {
const r = [];

if (outline.kind != null) {
const iconName = outline.icon;
if (iconName != null) {
const correspondingAtomicon = getTypeFromIconName(iconName);
if (correspondingAtomicon == null) {
r.push(
<span
key="type-icon"
className={classnames('icon', `icon-${iconName}`)}
/>,
);
} else {
// If we're passed an icon name rather than a type, and it maps directly
// to an atomicon, use that.
r.push(<Atomicon key="type-icon" type={correspondingAtomicon} />);
}
} else if (outline.kind != null) {
r.push(<Atomicon key="type-icon" type={outline.kind} />);
// Note: icons here are fixed-width, so the text lines up.
}

if (outline.tokenizedText != null) {
Expand Down
16 changes: 11 additions & 5 deletions modules/nuclide-commons-ui/Atomicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import * as React from 'react';
import {capitalize} from 'nuclide-commons/string';
import classnames from 'classnames';
import {invert} from 'lodash';

const TYPE_TO_CLASSNAME_SUFFIX = {
const TYPE_TO_ICON_NAME = {
array: 'type-array',
boolean: 'type-boolean',
class: 'type-class',
Expand All @@ -35,16 +36,21 @@ const TYPE_TO_CLASSNAME_SUFFIX = {
variable: 'type-variable',
};

type AtomiconName = $Keys<typeof TYPE_TO_CLASSNAME_SUFFIX>;
const ICON_NAME_TO_TYPE = invert(TYPE_TO_ICON_NAME);

export default function Atomicon({type}: {type: AtomiconName}) {
type AtomiconType = $Keys<typeof TYPE_TO_ICON_NAME>;

export default function Atomicon({type}: {type: AtomiconType}) {
const displayName = capitalize(type);
return (
<span
aria-label={displayName}
className={classnames('icon', 'icon-' + TYPE_TO_CLASSNAME_SUFFIX[type])}
className={classnames('icon', 'icon-' + TYPE_TO_ICON_NAME[type])}
role="presentation"
title={displayName}
/>
);
}

export function getTypeFromIconName(iconName: string): ?AtomiconType {
return ICON_NAME_TO_TYPE[iconName];
}
1 change: 1 addition & 0 deletions modules/nuclide-commons-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"escape-string-regexp": "1.0.5",
"idx": "1.2.0",
"invariant": "2.2.2",
"lodash": "4.17.4",
"nuclide-commons": "0.5.1",
"nuclide-commons-atom": "0.5.0",
"nullthrows": "1.0.0",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"idx": "1.2.0",
"immutable": "4.0.0-rc.9",
"invariant": "2.2.2",
"lodash": "4.17.4",
"log4js": "1.1.1",
"lru-cache": "4.0.2",
"marked": "0.3.9",
Expand Down

0 comments on commit cece913

Please sign in to comment.