mirror of https://github.com/buster-so/buster.git
remove buster list row component
This commit is contained in:
parent
7b0dec266b
commit
0d2ed87d75
|
@ -49,12 +49,12 @@ const sampleColumns = [
|
||||||
{
|
{
|
||||||
dataIndex: 'address',
|
dataIndex: 'address',
|
||||||
title: 'Address',
|
title: 'Address',
|
||||||
width: 300
|
width: 200
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataIndex: 'email',
|
dataIndex: 'email',
|
||||||
title: 'Email',
|
title: 'Email',
|
||||||
width: 200
|
width: 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataIndex: 'actions',
|
dataIndex: 'actions',
|
||||||
|
@ -79,6 +79,17 @@ const generateSampleRows = (count: number): BusterListRow[] => {
|
||||||
email: faker.internet.email()
|
email: faker.internet.email()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (i === 3) {
|
||||||
|
rows.push({
|
||||||
|
id: 'section1',
|
||||||
|
data: null,
|
||||||
|
rowSection: {
|
||||||
|
title: faker.company.name(),
|
||||||
|
secondaryTitle: faker.company.catchPhrase()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a section row in the middle
|
// Add a section row in the middle
|
||||||
|
|
|
@ -4,8 +4,8 @@ import React, { useMemo } from 'react';
|
||||||
import { BusterListRow, BusterListColumn, BusterListRowItem, BusterListProps } from './interfaces';
|
import { BusterListRow, BusterListColumn, BusterListRowItem, BusterListProps } from './interfaces';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { CheckboxColumn } from './CheckboxColumn';
|
import { CheckboxColumn } from './CheckboxColumn';
|
||||||
import { createStyles } from 'antd-style';
|
|
||||||
import { HEIGHT_OF_ROW } from './config';
|
import { HEIGHT_OF_ROW } from './config';
|
||||||
|
import { cn } from '@/lib/classMerge';
|
||||||
|
|
||||||
export const BusterListRowComponent = React.memo(
|
export const BusterListRowComponent = React.memo(
|
||||||
React.forwardRef<
|
React.forwardRef<
|
||||||
|
@ -38,7 +38,6 @@ export const BusterListRowComponent = React.memo(
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const { styles, cx } = useStyles();
|
|
||||||
const link = row.link;
|
const link = row.link;
|
||||||
|
|
||||||
const onContextMenu = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => {
|
const onContextMenu = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
|
@ -56,20 +55,28 @@ export const BusterListRowComponent = React.memo(
|
||||||
row.onClick?.();
|
row.onClick?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rowStyles = {
|
||||||
|
height: `${HEIGHT_OF_ROW}px`,
|
||||||
|
minHeight: `${HEIGHT_OF_ROW}px`,
|
||||||
|
...style
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LinkWrapper href={link}>
|
<LinkWrapper href={link}>
|
||||||
<div
|
<div
|
||||||
onClick={onContainerClick}
|
onClick={onContainerClick}
|
||||||
style={style}
|
style={rowStyles}
|
||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
className={cx(
|
className={cn(
|
||||||
styles.row,
|
'border-border flex items-center border-b pr-6',
|
||||||
rowClassName,
|
checked ? 'bg-primary-background hover:bg-primary-background-hover' : '',
|
||||||
'group flex items-center pr-6',
|
isLastChild && hideLastRowBorder ? '!border-b-0' : '',
|
||||||
checked ? 'checked' : '',
|
|
||||||
isLastChild && hideLastRowBorder ? 'border-b-0!' : '',
|
|
||||||
!onSelectChange ? 'pl-3.5' : '',
|
!onSelectChange ? 'pl-3.5' : '',
|
||||||
{ clickable: !!(link || row.onClick || (onSelectChange && useRowClickSelectChange)) }
|
link || row.onClick || (onSelectChange && useRowClickSelectChange)
|
||||||
|
? 'hover:bg-item-hover cursor-pointer'
|
||||||
|
: '',
|
||||||
|
rowClassName,
|
||||||
|
'group'
|
||||||
)}
|
)}
|
||||||
ref={ref}>
|
ref={ref}>
|
||||||
{!!onSelectChange ? (
|
{!!onSelectChange ? (
|
||||||
|
@ -106,8 +113,6 @@ const BusterListCellComponent: React.FC<{
|
||||||
onSelectChange?: (v: boolean, id: string) => void;
|
onSelectChange?: (v: boolean, id: string) => void;
|
||||||
render?: (data: string | number | React.ReactNode, row: BusterListRowItem) => React.ReactNode;
|
render?: (data: string | number | React.ReactNode, row: BusterListRowItem) => React.ReactNode;
|
||||||
}> = React.memo(({ data, width, row, render, isFirstCell, isLastCell, onSelectChange }) => {
|
}> = React.memo(({ data, width, row, render, isFirstCell, isLastCell, onSelectChange }) => {
|
||||||
const { styles, cx } = useStyles();
|
|
||||||
|
|
||||||
const memoizedStyle = useMemo(() => {
|
const memoizedStyle = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
width: width || '100%',
|
width: width || '100%',
|
||||||
|
@ -117,9 +122,10 @@ const BusterListCellComponent: React.FC<{
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cx(styles.cell, 'row-cell flex items-center overflow-hidden', {
|
className={cn(
|
||||||
secondary: !isFirstCell
|
'row-cell flex h-full items-center overflow-hidden px-1',
|
||||||
})}
|
isFirstCell ? 'text-text-default text-base' : 'text-text-tertiary text-sm'
|
||||||
|
)}
|
||||||
style={memoizedStyle}>
|
style={memoizedStyle}>
|
||||||
<div className="w-full truncate">{render ? render(data, row?.data) : data}</div>
|
<div className="w-full truncate">{render ? render(data, row?.data) : data}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -138,43 +144,3 @@ const LinkWrapper: React.FC<{
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useStyles = createStyles(({ css, token }) => ({
|
|
||||||
row: css`
|
|
||||||
height: ${HEIGHT_OF_ROW}px;
|
|
||||||
min-height: ${HEIGHT_OF_ROW}px;
|
|
||||||
border-bottom: 0.5px solid ${token.colorBorder};
|
|
||||||
|
|
||||||
&.clickable {
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: ${token.controlItemBgHover};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.row-cell {
|
|
||||||
padding: 0 4px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.checked {
|
|
||||||
background-color: ${token.colorPrimaryBg};
|
|
||||||
&:hover {
|
|
||||||
background-color: ${token.colorPrimaryBgHover};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
cell: css`
|
|
||||||
color: ${token.colorText};
|
|
||||||
font-size: 13px;
|
|
||||||
@apply text-base;
|
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
color: ${token.colorTextTertiary};
|
|
||||||
@apply text-xs;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
}));
|
|
||||||
|
|
Loading…
Reference in New Issue