import React, { FunctionComponent } from 'react'; import { Action } from 'redux'; import { css } from '@emotion/react'; import type { Interpolation, Theme } from '@emotion/react'; import { Tab } from './ActionPreview'; import { selectorButtonCss, selectorButtonSelectedCss, } from './utils/selectorButtonStyles'; const inspectedPathKeyCss = css({ '&:not(:last-child):after': { content: '" > "', }, }); const inspectedPathKeyLinkCss: Interpolation = (theme) => ({ cursor: 'pointer', color: theme.LINK_COLOR, '&:hover': { textDecoration: 'underline', color: theme.LINK_HOVER_COLOR, }, }); interface Props> { tabs: Tab[]; inspectedPath: (string | number)[]; onInspectPath: (path: (string | number)[]) => void; tabName: string; onSelectTab: (tabName: string) => void; } const ActionPreviewHeader: FunctionComponent< Props> > = ({ inspectedPath, onInspectPath, tabName, onSelectTab, tabs }) => (
({ flex: '0 0 30px', padding: '5px 10px', alignItems: 'center', borderBottomWidth: '1px', borderBottomStyle: 'solid', backgroundColor: theme.HEADER_BACKGROUND_COLOR, borderBottomColor: theme.HEADER_BORDER_COLOR, })} >
{tabs.map((tab) => (
onSelectTab(tab.name)} key={tab.name} css={[ selectorButtonCss, tab.name === tabName && selectorButtonSelectedCss, ]} > {tab.name}
))}
{inspectedPath.length ? ( onInspectPath([])} css={inspectedPathKeyLinkCss}> {tabName} ) : ( tabName )} {inspectedPath.map((key, idx) => idx === inspectedPath.length - 1 ? ( {key} ) : ( onInspectPath(inspectedPath.slice(0, idx + 1))} css={inspectedPathKeyLinkCss} > {key} ), )}
); export default ActionPreviewHeader;