2020-08-31 00:49:06 +03:00
|
|
|
import React, { FunctionComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Action } from 'redux';
|
|
|
|
import { StylingFunction } from 'react-base16-styling';
|
|
|
|
import { Tab } from './ActionPreview';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:56:36 +03:00
|
|
|
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
|
|
|
>
|
2021-06-18 06:56:36 +03:00
|
|
|
{tab.name}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div {...styling('inspectedPath')}>
|
|
|
|
{inspectedPath.length ? (
|
|
|
|
<span {...styling('inspectedPathKey')}>
|
2019-01-10 21:51:14 +03:00
|
|
|
<a
|
2021-06-18 06:56:36 +03:00
|
|
|
onClick={() => onInspectPath([])}
|
2019-01-10 21:51:14 +03:00
|
|
|
{...styling('inspectedPathKeyLink')}
|
|
|
|
>
|
2021-06-18 06:56:36 +03:00
|
|
|
{tabName}
|
2018-12-22 03:10:49 +03:00
|
|
|
</a>
|
2019-01-10 21:51:14 +03:00
|
|
|
</span>
|
2021-06-18 06:56:36 +03:00
|
|
|
) : (
|
|
|
|
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>
|
2021-06-18 06:56:36 +03:00
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-31 00:49:06 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-12-22 03:10:49 +03:00
|
|
|
export default ActionPreviewHeader;
|