mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Fix tabs
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
193b3c207b
commit
fa268d8d5d
@ -10,6 +10,7 @@ import Tab from './Tab';
|
||||
const Tabs = ({ children, isLoading, tabsLabel }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
|
||||
const selectedChild = React.Children.toArray(children)[selectedTabIndex];
|
||||
|
||||
const handleSelectedTab = index => {
|
||||
if (index !== selectedTabIndex) {
|
||||
@ -38,7 +39,7 @@ const Tabs = ({ children, isLoading, tabsLabel }) => {
|
||||
</Tab>
|
||||
))}
|
||||
</Flex>
|
||||
{children[selectedTabIndex]}
|
||||
{selectedChild}
|
||||
</>
|
||||
)}
|
||||
</TabsWrapper>
|
||||
|
||||
@ -21,6 +21,7 @@ const ActionRow = ({ name, value, required, propertyActions }) => {
|
||||
|
||||
return value;
|
||||
}, [value]);
|
||||
|
||||
const isCollapsable = recursiveValues.length > 0;
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Curve = props => (
|
||||
<svg
|
||||
style={{
|
||||
height: '14px',
|
||||
transform: 'translate(-3.2px, -1px)',
|
||||
position: 'relative',
|
||||
}}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 21.08 21"
|
||||
{...props}
|
||||
>
|
||||
<g>
|
||||
<path
|
||||
d="M2.58 2.5q-1.2 16 16 16"
|
||||
fill="none"
|
||||
stroke={props.fill}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="5"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
Curve.defaultProps = {
|
||||
fill: '#f3f4f4',
|
||||
};
|
||||
Curve.propTypes = {
|
||||
fill: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Curve;
|
||||
@ -0,0 +1,8 @@
|
||||
/* eslint-disable indent */
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
padding-left: 15px;
|
||||
`;
|
||||
|
||||
export default Wrapper;
|
||||
@ -0,0 +1,117 @@
|
||||
import React, { memo, useCallback, useMemo, useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Flex, Text } from '@buffetjs/core';
|
||||
import styled from 'styled-components';
|
||||
import CheckboxWithCondition from '../../../CheckboxWithCondition';
|
||||
import Chevron from '../../../Chevron';
|
||||
import CollapseLabel from '../../../CollapseLabel';
|
||||
import HiddenAction from '../../../HiddenAction';
|
||||
import RequiredSign from '../../../RequiredSign';
|
||||
import Curve from './Curve';
|
||||
import { RowStyle, RowWrapper } from './row';
|
||||
import { LeftBorderTimeline, TopTimeline } from './timeline';
|
||||
import Wrapper from './Wrapper';
|
||||
|
||||
const SubLevelWrapper = styled.div`
|
||||
padding-bottom: 8px;
|
||||
`;
|
||||
|
||||
const SubActionRow = ({ recursiveLevel, values, propertyActions }) => {
|
||||
console.log({ propertyActions });
|
||||
const [rowToOpen, setRowToOpen] = useState(null);
|
||||
const handleClickToggleSubLevel = useCallback(name => {
|
||||
setRowToOpen(prev => {
|
||||
if (prev === name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return name;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const displayedRecursiveValue = useMemo(() => {
|
||||
if (!rowToOpen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return values.find(({ value }) => value === rowToOpen);
|
||||
}, [rowToOpen, values]);
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<TopTimeline />
|
||||
{values.map((value, index) => {
|
||||
const isVisible = index + 1 < values.length;
|
||||
const isArrayType = Array.isArray(value.value);
|
||||
const isSmall = isArrayType || index + 1 === values.length;
|
||||
const isActive = rowToOpen === value.value;
|
||||
|
||||
return (
|
||||
<LeftBorderTimeline key={value.key} isVisible={isVisible}>
|
||||
<RowWrapper isSmall={isSmall}>
|
||||
<Curve fill="#a5d5ff" />
|
||||
<Flex style={{ flex: 1 }}>
|
||||
<RowStyle level={recursiveLevel} isActive={isActive} isCollapsable={isArrayType}>
|
||||
<CollapseLabel
|
||||
alignItems="center"
|
||||
isCollapsable={isArrayType}
|
||||
onClick={() => {
|
||||
if (isArrayType) {
|
||||
handleClickToggleSubLevel(value.value);
|
||||
}
|
||||
}}
|
||||
title={value.key}
|
||||
>
|
||||
<Text
|
||||
color={isActive ? 'mediumBlue' : 'grey'}
|
||||
ellipsis
|
||||
fontSize="xs"
|
||||
fontWeight="bold"
|
||||
lineHeight="20px"
|
||||
textTransform="uppercase"
|
||||
>
|
||||
{value.key}
|
||||
</Text>
|
||||
{value.required && <RequiredSign>*</RequiredSign>}
|
||||
<Chevron icon={isActive ? 'caret-up' : 'caret-down'} />
|
||||
</CollapseLabel>
|
||||
</RowStyle>
|
||||
<Flex style={{ flex: 1 }}>
|
||||
{propertyActions.map(action => {
|
||||
if (!action.isActionRelatedToCurrentProperty) {
|
||||
return <HiddenAction key={action.label} />;
|
||||
}
|
||||
|
||||
return <CheckboxWithCondition key={action.label} name="todo" />;
|
||||
})}
|
||||
</Flex>
|
||||
</Flex>
|
||||
</RowWrapper>
|
||||
{displayedRecursiveValue && isActive && (
|
||||
<SubLevelWrapper>
|
||||
<SubActionRow
|
||||
name={displayedRecursiveValue.key}
|
||||
propertyActions={propertyActions}
|
||||
recursiveLevel={recursiveLevel + 1}
|
||||
values={displayedRecursiveValue.value}
|
||||
/>
|
||||
</SubLevelWrapper>
|
||||
)}
|
||||
</LeftBorderTimeline>
|
||||
);
|
||||
})}
|
||||
</Wrapper>
|
||||
);
|
||||
};
|
||||
|
||||
SubActionRow.defaultProps = {
|
||||
recursiveLevel: 0,
|
||||
};
|
||||
|
||||
SubActionRow.propTypes = {
|
||||
propertyActions: PropTypes.array.isRequired,
|
||||
recursiveLevel: PropTypes.number,
|
||||
values: PropTypes.array.isRequired,
|
||||
};
|
||||
|
||||
export default memo(SubActionRow);
|
||||
@ -0,0 +1,47 @@
|
||||
import styled from 'styled-components';
|
||||
import { Flex, Text } from '@buffetjs/core';
|
||||
import PropTypes from 'prop-types';
|
||||
import Chevron from '../../../Chevron';
|
||||
|
||||
const activeStyle = theme => `
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
${Text} {
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
${Chevron} {
|
||||
display: block;
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
`;
|
||||
|
||||
const RowStyle = styled.div`
|
||||
padding-left: ${({ theme }) => theme.main.sizes.paddings.xs};
|
||||
width: ${({ level }) => 128 - level * 18}px;
|
||||
${Chevron} {
|
||||
width: 13px;
|
||||
}
|
||||
${({ isCollapsable, theme }) =>
|
||||
isCollapsable &&
|
||||
`
|
||||
${Chevron} {
|
||||
display: block;
|
||||
color: ${theme.main.colors.grey};
|
||||
}
|
||||
&:hover {
|
||||
${activeStyle(theme)}
|
||||
}
|
||||
`}
|
||||
${({ isActive, theme }) => isActive && activeStyle(theme)}}
|
||||
`;
|
||||
|
||||
RowStyle.propTypes = {
|
||||
isActive: PropTypes.bool.isRequired,
|
||||
isCollapsable: PropTypes.bool.isRequired,
|
||||
level: PropTypes.number.isRequired,
|
||||
};
|
||||
|
||||
const RowWrapper = styled(Flex)`
|
||||
height: ${({ isSmall }) => (isSmall ? '28px' : '36px')};
|
||||
`;
|
||||
|
||||
export { RowStyle, RowWrapper };
|
||||
@ -0,0 +1,15 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const LeftBorderTimeline = styled.div`
|
||||
border-left: ${({ isVisible }) => (isVisible ? '3px solid #a5d5ff' : '3px solid transparent')};
|
||||
`;
|
||||
|
||||
const TopTimeline = styled.div`
|
||||
padding-top: 8px;
|
||||
width: 3px;
|
||||
background-color: #a5d5ff;
|
||||
border-top-left-radius: 2px;
|
||||
border-top-right-radius: 2px;
|
||||
`;
|
||||
|
||||
export { LeftBorderTimeline, TopTimeline };
|
||||
@ -372,11 +372,11 @@ const data = {
|
||||
{
|
||||
key: 'French',
|
||||
value: 'fr',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: 'English',
|
||||
value: 'en',
|
||||
required: true,
|
||||
value: [{ key: 'EN', value: 'en' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user