redux-devtools/packages/redux-devtools-inspector-monitor/src/ActionPreviewHeader.tsx

77 lines
2.2 KiB
TypeScript
Raw Normal View History

import React, { FunctionComponent } from 'react';
import PropTypes from 'prop-types';
import { Action } from 'redux';
import { StylingFunction } from 'react-base16-styling';
import { Tab } from './ActionPreview';
interface Props<S, A extends Action<unknown>> {
tabs: Tab<S, A>[];
styling: StylingFunction;
inspectedPath: (string | number)[];
onInspectPath: (path: (string | number)[]) => void;
tabName: string;
onSelectTab: (tabName: string) => void;
}
const ActionPreviewHeader: FunctionComponent<Props<unknown, Action<unknown>>> =
({ styling, inspectedPath, onInspectPath, tabName, onSelectTab, tabs }) => (
<div key="previewHeader" {...styling('previewHeader')}>
<div {...styling('tabSelector')}>
{tabs.map((tab) => (
<div
onClick={() => onSelectTab(tab.name)}
key={tab.name}
{...styling(
[
'selectorButton',
tab.name === tabName && 'selectorButtonSelected',
],
tab.name === tabName
)}
2019-01-10 21:51:14 +03:00
>
{tab.name}
</div>
))}
</div>
<div {...styling('inspectedPath')}>
{inspectedPath.length ? (
<span {...styling('inspectedPathKey')}>
2019-01-10 21:51:14 +03:00
<a
onClick={() => onInspectPath([])}
2019-01-10 21:51:14 +03:00
{...styling('inspectedPathKeyLink')}
>
{tabName}
</a>
2019-01-10 21:51:14 +03:00
</span>
) : (
tabName
)}
{inspectedPath.map((key, idx) =>
idx === inspectedPath.length - 1 ? (
<span key={key}>{key}</span>
) : (
<span key={key} {...styling('inspectedPathKey')}>
<a
onClick={() => onInspectPath(inspectedPath.slice(0, idx + 1))}
{...styling('inspectedPathKeyLink')}
>
{key}
</a>
</span>
)
)}
</div>
2019-01-10 21:51:14 +03:00
</div>
);
ActionPreviewHeader.propTypes = {
tabs: PropTypes.array.isRequired,
styling: PropTypes.func.isRequired,
inspectedPath: PropTypes.array.isRequired,
onInspectPath: PropTypes.func.isRequired,
tabName: PropTypes.string.isRequired,
onSelectTab: PropTypes.func.isRequired,
};
export default ActionPreviewHeader;