Create helper function for converting dashes names for display

This commit is contained in:
Fabio Berger
2018-03-22 11:56:12 +00:00
parent e1341bc6d9
commit 46b7fecafe
4 changed files with 7 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd
const { sectionName, markdownContent, headerSize, githubLink } = this.props as PropsWithDefaults; const { sectionName, markdownContent, headerSize, githubLink } = this.props as PropsWithDefaults;
const id = utils.getIdFromName(sectionName); const id = utils.getIdFromName(sectionName);
const finalSectionName = sectionName.replace(/-/g, ' '); const finalSectionName = utils.convertDashesToSpaces(sectionName);
return ( return (
<div <div
className="md-px1 sm-px2 overflow-hidden" className="md-px1 sm-px2 overflow-hidden"

View File

@@ -45,7 +45,7 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
}; };
public render() { public render() {
const navigation = _.map(this.props.topLevelMenu, (menuItems: string[], sectionName: string) => { const navigation = _.map(this.props.topLevelMenu, (menuItems: string[], sectionName: string) => {
const finalSectionName = sectionName.replace(/-/g, ' '); const finalSectionName = utils.convertDashesToSpaces(sectionName);
if (this.props.shouldDisplaySectionHeaders) { if (this.props.shouldDisplaySectionHeaders) {
const id = utils.getIdFromName(sectionName); const id = utils.getIdFromName(sectionName);
return ( return (
@@ -85,7 +85,7 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
: styles.menuItemWithoutHeaders; : styles.menuItemWithoutHeaders;
const menuItemInnerDivStyles = this.props.shouldDisplaySectionHeaders ? styles.menuItemInnerDivWithHeaders : {}; const menuItemInnerDivStyles = this.props.shouldDisplaySectionHeaders ? styles.menuItemInnerDivWithHeaders : {};
const menuItems = _.map(menuItemNames, menuItemName => { const menuItems = _.map(menuItemNames, menuItemName => {
const finalMenuItemName = menuItemName.replace(/-/g, ' '); const finalMenuItemName = utils.convertDashesToSpaces(menuItemName);
const id = utils.getIdFromName(menuItemName); const id = utils.getIdFromName(menuItemName);
return ( return (
<div key={menuItemName}> <div key={menuItemName}>

View File

@@ -35,7 +35,7 @@ export class SectionHeader extends React.Component<SectionHeaderProps, SectionHe
public render() { public render() {
const { sectionName, headerSize } = this.props as PropsWithDefaults; const { sectionName, headerSize } = this.props as PropsWithDefaults;
const finalSectionName = this.props.sectionName.replace(/-/g, ' '); const finalSectionName = utils.convertDashesToSpaces(this.props.sectionName);
const id = utils.getIdFromName(finalSectionName); const id = utils.getIdFromName(finalSectionName);
return ( return (
<div <div

View File

@@ -30,6 +30,9 @@ export const utils = {
const id = name.replace(/ /g, '-'); const id = name.replace(/ /g, '-');
return id; return id;
}, },
convertDashesToSpaces(text: string) {
return text.replace(/-/g, ' ');
},
getEtherScanLinkIfExists( getEtherScanLinkIfExists(
addressOrTxHash: string, addressOrTxHash: string,
networkId: number, networkId: number,