import pipe from "ramda/es/pipe" import React from "react" import ChevronUp from "../../icons/chevron-up.svg" import { traversePaths } from "../../utils" import { IFileOrFolder } from "../ResourcesSidebar/index" import * as SC from "./styles" interface IResourceBreadcrumbProps { relativePath: any } function capitalize(str: string): string { return str .split(" ") .map(word => `${word.charAt(0).toUpperCase()}${word.substring(1)}`) .join(" ") } function dashToSpace(str: string): string { return str.replace("-", " ") } function humanize(str: string): string { return pipe( dashToSpace, capitalize )(str) } function Link({ item }: { item: IFileOrFolder }) { return {humanize(item.title)} } function flatten([ currNode, ...previousNodes ]: IFileOrFolder[]): IFileOrFolder[] { if (currNode.type === "file") { return [...previousNodes, currNode] } return flatten([...currNode.children, ...previousNodes, currNode]) } export function ResourceBreadcrumb({ relativePath }: IResourceBreadcrumbProps) { const paths = relativePath.split("/") const breadcrumbItems = flatten([traversePaths(paths)]) return ( {breadcrumbItems.map(item => { if (item.type === "folder") { return ( ) } return {item.title} })} ) }