@@ -14,6 +14,8 @@ const Container = styled.div`
1414` ;
1515
1616const Table = styled ( BaseTable ) `
17+ border: 1px solid #ececec;
18+
1719 .react-fluid-table-header {
1820 background-color: #282a36;
1921 }
@@ -406,6 +408,315 @@ const Props = () => (
406408 </ Item >
407409 ) ) }
408410 </ List >
411+ < Header dividing size = "small" color = "grey" >
412+ Interfaces
413+ </ Header >
414+ < Snippet code = { `import { CSSProperties, ForwardedRef, ReactNode } from "react";
415+
416+ type SortDirection = "ASC" | "DESC" | null;
417+
418+ interface ExpanderProps {
419+ /**
420+ * whether or not the row is expanded
421+ */
422+ isExpanded: boolean;
423+ /**
424+ * handler for clicking the expansion button
425+ */
426+ onClick: (event?: React.MouseEvent<Element, MouseEvent>) => void;
427+ /**
428+ * required style for the expander
429+ */
430+ style: CSSProperties;
431+ }
432+
433+ interface CellProps<T> {
434+ /**
435+ * the data for the row
436+ */
437+ row: T;
438+ /**
439+ * the index of the row
440+ */
441+ index: number;
442+ /**
443+ * an optional function that can be used to clear the size cache
444+ */
445+ clearSizeCache: (dataIndex: number, forceUpdate?: boolean) => void;
446+ /**
447+ * optional custom styles for each cell
448+ */
449+ style?: CSSProperties;
450+ }
451+
452+ interface HeaderProps {
453+ /**
454+ * the onclick handler for the header cell
455+ * @param e mouse event
456+ * @returns void
457+ */
458+ onClick: (e: React.MouseEvent<Element, MouseEvent>) => void;
459+ /**
460+ * required style for the header
461+ */
462+ style: CSSProperties;
463+ /**
464+ * the direction of the sort, if applicable
465+ */
466+ sortDirection: SortDirection;
467+ }
468+
469+ interface RowRenderProps<T> {
470+ /**
471+ * the data for the row
472+ */
473+ row: T;
474+ /**
475+ * the index of the row
476+ */
477+ index: number;
478+ /**
479+ * required row position styles
480+ */
481+ style: CSSProperties;
482+ /**
483+ * the cells for the row
484+ */
485+ children: ReactNode;
486+ /**
487+ * the className for the row-renderer
488+ */
489+ className?: string;
490+ }
491+
492+ interface SubComponentProps<T> {
493+ /**
494+ * the data for the row
495+ */
496+ row: T;
497+ /**
498+ * the index of the row
499+ */
500+ index: number;
501+ /**
502+ * whether or not the row is expanded
503+ */
504+ isExpanded: boolean;
505+ /**
506+ * an optional function that can be used to clear the size cache
507+ */
508+ clearSizeCache: (dataIndex: number, forceUpdate?: boolean) => void;
509+ }
510+
511+ interface FooterProps<T> {
512+ /**
513+ * exposes the widths of each column to the footer
514+ */
515+ widths: number[];
516+ rows: T[];
517+ }
518+
519+ interface FooterCellProps<T> {
520+ /**
521+ * the column that the current footer cell is pulling from
522+ */
523+ column: ColumnProps<T>;
524+ /**
525+ * the calculated width of the cell
526+ */
527+ width: number;
528+ /**
529+ * all the rows in the table. this can be useful for aggregation
530+ */
531+ rows: T[];
532+ }
533+
534+ interface ColumnProps<T> {
535+ /**
536+ * The unique identifier for a particular column. This is also used as an index
537+ * to get the particular value out of the row in order to display.
538+ */
539+ key: string;
540+ /**
541+ * The name of the header column, or a component to return a customized header cell.
542+ */
543+ header?: string | ((props: HeaderProps) => JSX.Element);
544+ /**
545+ * The width of a column in pixels. If this is set, the column will not resize.
546+ */
547+ width?: number;
548+ /**
549+ * The minimum width of a column in pixels. On resize, the column will never
550+ * dip below this width.
551+ */
552+ minWidth?: number;
553+ /**
554+ * The maximum width of a column in pixels. On resize, the column will never
555+ * grow beyond this width.
556+ */
557+ maxWidth?: number;
558+ /**
559+ * Determines whether or not a column is sortable.
560+ */
561+ sortable?: boolean;
562+ /**
563+ * Marks this cell as an expansion cell. The style is pre-determined, and does the
564+ * functionalitty of collapsing/expanding a row.
565+ */
566+ expander?: boolean | ((props: ExpanderProps) => ReactNode);
567+ /**
568+ * Used to render custom content inside of a cell. This is useful for rendering different
569+ * things inside of the react-fluid-table cell container.
570+ */
571+ content?: string | number | ((props: CellProps<T>) => ReactNode);
572+ /**
573+ * An advanced feature, this is used to render an entire cell, including the cell container.
574+ * The \`content\` prop is ignored if this property is enabled.
575+ */
576+ cell?: (props: CellProps<T>) => JSX.Element;
577+ /**
578+ * specifies whether or not to display a footer cell
579+ */
580+ footer?: (props: FooterCellProps<T>) => ReactNode;
581+ }
582+
583+ interface TableRef {
584+ scrollTo: (scrollOffset: number) => void;
585+ scrollToItem: (index: number, align?: string) => void;
586+ }
587+
588+ interface TableProps<T> {
589+ // required props
590+ /**
591+ * A list of rows that are to be displayed in the table.
592+ */
593+ data: T[];
594+ /**
595+ * This property determines how each cell is going to be rendered.
596+ */
597+ columns: ColumnProps<T>[];
598+
599+ // optional props
600+ /**
601+ * The id of the table.
602+ */
603+ id?: string;
604+ /**
605+ * Optional className to override CSS styles.
606+ */
607+ className?: string;
608+ /**
609+ * Function that is called when a header cell is sorted.
610+ */
611+ onSort?: (col: string | null, dir: SortDirection) => void;
612+ /**
613+ * The column that is sorted by default.
614+ */
615+ sortColumn?: string;
616+ /**
617+ * The direction that is sorted by default.
618+ */
619+ sortDirection?: SortDirection;
620+ /**
621+ * Specify the height of the table in pixels.
622+ */
623+ tableHeight?: number;
624+ /**
625+ * Specify the minimum height of the table in pixels.
626+ */
627+ minTableHeight?: number;
628+ /**
629+ * Specify the maximum height of the table in pixels.
630+ */
631+ maxTableHeight?: number;
632+ /**
633+ * Specify the width of the table in pixels.
634+ */
635+ tableWidth?: number;
636+ /**
637+ * Specify the minimum width of any column. Default: \`80\`.
638+ */
639+ minColumnWidth?: number;
640+ /**
641+ * The fixed height of each row in pixels. If \`subComponent\` is specified,
642+ * then this will be the fixed height of the portion of the row that is
643+ * NOT the subComponent.
644+ */
645+ rowHeight?: number;
646+ /**
647+ * specify a fixed header height
648+ */
649+ headerHeight?: number;
650+ /**
651+ * Enable or disable row borders. Default: \`false\`.
652+ */
653+ borders?: boolean;
654+ /**
655+ * React styles used for customizing the table.
656+ */
657+ tableStyle?: CSSProperties;
658+ /**
659+ * React styles used for customizing the header.
660+ */
661+ headerStyle?: CSSProperties;
662+ /**
663+ * a className used to customize the header
664+ */
665+ headerClassname?: string;
666+ /**
667+ * React styles used for customizing each row. Could be an object or
668+ * a function that takes the index of the row and returns an object.
669+ */
670+ rowStyle?: CSSProperties | ((index: number) => CSSProperties);
671+ /**
672+ * React className used for customizing each row. Could be an object or
673+ * a function that takes the index of the row and returns an object.
674+ */
675+ rowClassname?: string | ((index: number) => string);
676+ /**
677+ * React styles used for customizing the footer.
678+ */
679+ footerStyle?: CSSProperties;
680+ /**
681+ * a className used to customize the footer
682+ */
683+ footerClassname?: string;
684+ /**
685+ * generates a unique identifier for the row
686+ * @param row the row
687+ * @returns string or number representing the item key
688+ */
689+ itemKey?: (row: T) => string | number;
690+ /**
691+ * controlls whether or not the footer is sticky. this is only used if
692+ * \`footerComponent\` is specified.
693+ */
694+ stickyFooter?: boolean;
695+ /**
696+ * optionally add a footer. NOTE: this overrides the \`footer\` prop of a
697+ * column, so use wisely. This gives the user more control over how the
698+ * footer is rendered. Can return any value.
699+ */
700+ footerComponent?: (props: FooterProps<T>) => ReactNode;
701+ /**
702+ * When a column has \`expander\`, this component will be rendered under the row.
703+ */
704+ subComponent?: (props: SubComponentProps<T>) => ReactNode;
705+ /**
706+ * The callback that gets called every time a row is clicked.
707+ */
708+ onRowClick?: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
709+ /**
710+ * Custom component to wrap a table row. This provides another way of providing
711+ * more row customization options.
712+ */
713+ rowRenderer?: (props: RowRenderProps<T>) => JSX.Element;
714+ /**
715+ * a ref for specific table functions
716+ */
717+ ref?: ForwardedRef<TableRef>;
718+ }
719+ ` } />
409720 </ Container >
410721) ;
411722
0 commit comments