0.1.1 • Published 5 years ago

fucking-react-table v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

npm version

npm.io

Fucking React Table

A react table component with fucking difficult features, including

  • Virtualized rows with fucking native table elements
  • Sticky header
  • Freeze column
  • Placeholder(WIP)
  • Sticky horizontal scrollbar(WIP)
  • Resizable column(WIP)

for both fit-content height table and fixed height table.

Playground

Storybook

Why

  • Why using native table element?

    Because it is fucking semantic and elegant.

  • Why reinventing the wheel?

    Considering sticky headers or freeze columns, I think reinventing is fucking more efficient than reusing.

  • Why the project is named fucking-react-table?

    I originally named it react-virtual-table, but this name was fucking registered. The package even seems like a fucking useless hello world project. So I just give a fucking name.

Installation

npm install --save fucking-react-table

Quick Start

import FuckTable from 'fucking-react-table'

const data = [
  { id: 'a', value: 'Apple' },
  { id: 'b', value: 'Banana' },
]
const Tr = FuckTable.Tr
const Th = FuckTable.Th
const Td = FuckTable.Td

return (
  <FuckTable
    data={data}
    headerRowHeight={60}
    rowHeight={80}
    renderHeader={() => (
      <Tr>
        <Th cellWidth={100}>ID</Th>
        <Th cellWidth={150}>Fruit</Th>
      </Tr>
    )}
    renderRow={row => (
      <Tr key={row.id}>
        <Td cellWidth={100}>{row.id}</Td>
        <Td cellWidth={150}>{row.value}</Td>
      </Tr>
    )}
  />
)

Custom Styling

import FuckTable from 'fucking-react-table'
import styled from 'styled-components'

const Table = styled(FuckTable)`
  background-color: #26282b;
`

const Tr = styled(FuckTable.Tr)`
  background-color: rgb(53, 55, 58);
`

const Th = styled(FuckTable.Th)`
  background-color: rgb(62, 63, 66);
  color: rgb(156, 157, 158);
`

const Td = styled(FuckTable.Td)`
  background-color: rgb(53, 55, 58);
  color: #ffffff;
`

Props

FuckTable

prop nametyperequireddefaultdescription
dataarrayyes-Data source of table rows. Each row will be passed as argument into renderRow.
headerRowHeightnumberyes-Fixed row height of table header. Table header is not virtualized and is always rendered.
rowHeightnumberyes-Fixed row height of table row.
columnCountnumberconditionalundefinedIf your column count will change during runtime, you must pass current column count. This prop is only for detecting width changing and won't affect any other table behaviors.
maxHeightnumberoptional-1Set a fixed max height value (in pixel). If maxHeight is negative (default to -1), the table will fit its height to contents.
throttleWaitnumberoptional16Throttle wait interval in milliseconds for restoring virtualized table rows. Default to 16ms, which is about 60fps (1000ms / 60).
preRenderRowCountnumberoptional0Set how many margin rows should be pre-render before they are displayed in viewport.
globalStickyHeaderbooloptionalfalseToggle sticky header when global page scrolls
localStickyHeaderboolconditionalfalseRequired when rowHeight is set. Toggle sticky header when table container scrolls.
enableStickyHeaderShadowbooloptionaltrueToggle scroll shadow of sticky header.
enableFreezeColumnShadowbooloptionaltrueToggle scroll shadow of frozen column.
freezeColumnShadowLeftOffsetnumberconditionalnullRequired when enableFreezeColumnShadow is true. This prop decides the x-axis position of shadow.
renderHeaderfuncoptional() => {}A render function for table head section.
renderRowfuncoptional() => {}A render function for table body section.

FuckTable.Tr

No props.

FuckTable.Th

prop nametyperequireddefaultdescription
cellWidthnumberyes-Fixed value in px to decide the width of current FuckTable.Th
freezeLeftOffsetnumber | undefinedconditionalundefinedIf you want to freeze columns, this prop sets the freeze left offset in px. You should set the same offset to FuckTable.Td for the same column.

FuckTable.Td

prop nametyperequireddefaultdescription
cellWidthnumberyes-Fixed value in px to decide the width of current FuckTable.Td
freezeLeftOffsetnumber | undefinedconditionalundefinedIf you want to freeze columns, this prop sets the freeze left offset in px. You should set the same offset to FuckTable.Th for the same column.

Development

npm start

Storybook

Launch local storybook

yarn storybook

Deploy to gh-pages

yarn deploy-storybook

Changelog

0.1.1

Reduce bundle size by removing unnecessary dependencies

0.1.0

Initial release with following features:

  • virtualized rows
  • sticky header
  • freeze column