Skip to content

Commit

Permalink
feat: ListTable component add props to customize draw width
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Jul 25, 2024
1 parent 8777266 commit 3c7d5ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/tushan/client/components/list/ListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ListTableProps {
defaultFilter?: FilterPayload;
showTotal?: boolean;
showSizeChanger?: boolean;
drawerWidth?: number;
/**
* Allow pass table props into table element
*/
Expand Down Expand Up @@ -124,7 +125,9 @@ export const ListTable: React.FC<ListTableProps> = React.memo((props) => {
} = useGetList(resource, listParams);
const action = props.action;
const batchAction = props.batchAction;
const { showTableDrawer, drawerEl } = useListTableDrawer(props.fields);
const { showTableDrawer, drawerEl } = useListTableDrawer(props.fields, {
drawerWidth: props.drawerWidth,
});
const filterFields = props.filter ?? [];
const [selectedRowKeys, setSelectedRowKeys] = useState<Identifier[]>([]);

Expand Down
4 changes: 4 additions & 0 deletions packages/tushan/client/components/list/ListTableDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface ListTableDrawerProps {
fields: FieldHandler[];
record: BasicRecord | null;
viewType: ViewType;
/**
* Drawer width
* @default 680
*/
width?: number;
}
export const ListTableDrawer: React.FC<ListTableDrawerProps> = React.memo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { useEvent } from '../../hooks/useEvent';
import type { FieldHandler } from '../fields';
import { ListTableDrawer } from './ListTableDrawer';

export function useListTableDrawer(fields: FieldHandler[]) {
export function useListTableDrawer(
fields: FieldHandler[],
options?: { drawerWidth?: number }
) {
const [visible, setVisible] = useState(false);
const [viewType, setViewType] = useState<ViewType>('detail');
const [record, setRecord] = useState<BasicRecord | null>(null);
Expand All @@ -26,6 +29,7 @@ export function useListTableDrawer(fields: FieldHandler[]) {
viewType={viewType}
fields={fields}
record={record}
width={options?.drawerWidth}
/>
),
};
Expand Down

0 comments on commit 3c7d5ae

Please sign in to comment.