-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAncestorsPath.js
51 lines (45 loc) · 1.24 KB
/
AncestorsPath.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { Fragment, useState } from 'react';
import PropTypes from 'prop-types';
import { More } from '@strapi/icons';
import { Delimiter, ExpandButton, HideButton, PathLabel } from './styled';
const AncestorsPath = ({ hasError, path }) => {
const [expanded, setExpanded] = useState(false);
if (expanded) {
return (
<HideButton onClick={() => setExpanded(false)} label="Show ancestor path">
<PathLabel hasError={hasError}>
{path.split(/(?:\/|~)+/).map((part, i) => (
<Fragment
key={
/* eslint-disable-next-line react/no-array-index-key */
`${part}-${i}`
}
>
{part}
<Delimiter hasError={hasError}>/</Delimiter>
</Fragment>
))}
</PathLabel>
</HideButton>
);
} else {
return (
<ExpandButton
hasError={hasError}
variant="secondary"
label="Show ancestor path"
onClick={() => setExpanded(true)}
>
<More />
</ExpandButton>
);
}
};
AncestorsPath.defaultProps = {
hasError: false,
};
AncestorsPath.propTypes = {
hasError: PropTypes.bool,
path: PropTypes.string.isRequired,
};
export default AncestorsPath;