This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This creates an `Atomicon` component which accepts a type which currently overlaps with Outline's types and maps them to the correct class. It also includes an `aria-label` and `title` which display a more readable version (capitalized in this case) of the type Reviewed By: Goom11 Differential Revision: D7073310 fbshipit-source-id: db5bfc99c8fe3eb7b70ba55938f260c7da29fbc2
- Loading branch information
Showing
2 changed files
with
53 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import {capitalize} from 'nuclide-commons/string'; | ||
import classnames from 'classnames'; | ||
|
||
const TYPE_TO_CLASSNAME_SUFFIX = { | ||
array: 'type-array', | ||
boolean: 'type-boolean', | ||
class: 'type-class', | ||
constant: 'type-constant', | ||
constructor: 'type-constructor', | ||
enum: 'type-enum', | ||
field: 'type-field', | ||
file: 'type-file', | ||
function: 'type-function', | ||
interface: 'type-interface', | ||
method: 'type-method', | ||
module: 'type-module', | ||
namespace: 'type-namespace', | ||
number: 'type-number', | ||
package: 'type-package', | ||
property: 'type-property', | ||
string: 'type-string', | ||
variable: 'type-variable', | ||
}; | ||
|
||
type AtomiconName = $Keys<typeof TYPE_TO_CLASSNAME_SUFFIX>; | ||
|
||
export default function Atomicon({type}: {type: AtomiconName}) { | ||
const displayName = capitalize(type); | ||
return ( | ||
<span | ||
aria-label={displayName} | ||
className={classnames('icon', 'icon-' + TYPE_TO_CLASSNAME_SUFFIX[type])} | ||
role="presentation" | ||
title={displayName} | ||
/> | ||
); | ||
} |