2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-09-04 19:59:02 +08:00
|
|
|
|
2023-06-05 13:29:55 +08:00
|
|
|
import { SpaceContext } from './context';
|
2023-09-04 19:59:02 +08:00
|
|
|
import type { SpaceContextType } from './context';
|
2020-08-25 16:43:52 +08:00
|
|
|
|
|
|
|
export interface ItemProps {
|
|
|
|
className: string;
|
|
|
|
children: React.ReactNode;
|
|
|
|
index: number;
|
2023-04-28 16:09:14 +08:00
|
|
|
split?: React.ReactNode;
|
2023-05-31 13:43:38 +08:00
|
|
|
style?: React.CSSProperties;
|
2020-08-25 16:43:52 +08:00
|
|
|
}
|
|
|
|
|
2023-09-05 10:17:56 +08:00
|
|
|
const Item: React.FC<ItemProps> = ({ className, index, children, split, style }) => {
|
|
|
|
const { latestIndex } = React.useContext<SpaceContextType>(SpaceContext);
|
2020-08-25 16:43:52 +08:00
|
|
|
|
|
|
|
if (children === null || children === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-10-08 18:41:40 +08:00
|
|
|
<>
|
2023-09-05 10:17:56 +08:00
|
|
|
<div className={className} style={style}>
|
2020-10-08 18:41:40 +08:00
|
|
|
{children}
|
|
|
|
</div>
|
2023-09-05 10:17:56 +08:00
|
|
|
{index < latestIndex && split && <span className={`${className}-split`}>{split}</span>}
|
2020-10-08 18:41:40 +08:00
|
|
|
</>
|
2020-08-25 16:43:52 +08:00
|
|
|
);
|
2023-07-13 01:46:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|