Tyble
tyble
is a typesafe React table written in TypeScript.
Table of Contents
- Features
- Installation
- Example
- Types
- Data
- Columns
- Rendering
- Tests and Linting
- Contributing
- License
- FAQ
Features
- Typed property selectors for cell data
- Customizable and controllable (React class, JSX, callbacks)
- Themeable (styled-components, sass)
- Column sorting and custom sorting functionality provided
Installation
Yarn
yarn add tyble
NPM
npm i tyble
or for the in development branch:
npm i tyble@next
Example
import * as React from 'react';import * as ReactDOM from 'react-dom'; import Tyble SortOrder TableColumn from 'tyble'; interface Person name: string; lastname: string; skills: Skill; company: Company; interface Skill name: string; level: number; interface Company name: string; const data: Person = name: 'Jason' lastname: 'Watson' skills: name: 'TypeScript' level: 100 company: name: 'Caspian' name: 'Charles' lastname: 'Xavier' skills: name: 'Telepathy' level: 90 company: name: 'X-Men' ; const columns: Array<TableColumn<Person>> = heading: content: 'First' sortOrder: SortOrderDESC sort: sortFunc <span>propsname</span> heading: content: 'Last' <span>propslastname</span> heading: content: 'Company' <span>propscompanyname</span> ; ReactDOM;
There are some more examples in the example
directory.
Props
Tyble
These are all of the props for <Tyble />
component.
Name | Type | Description |
---|---|---|
data | T[] |
T is the type your data uses. |
columns | TableColumn<T>[] |
Provide columns to shape and connect data to tyble . |
theme | ThemeProps |
Override or replace default theme. By default it uses an internal theme. |
defaultSort | optional SortFunc |
If no sorting function is provided, no sorting will be available. |
onHeadingClick | optional MouseClickFunc |
Heading click callback. |
onRowClick | optional MouseClickFunc |
Row click callback. |
className | optional string |
Top level className for styling. |
caption | optional string |
<caption> text |
Theme Props
Here are all the props and defaults for the ThemeProps
object. Creating your own allows you to customize the default theme. You can also, if you prefer, create only a partial theme to only override certain parts.
Name | Default |
---|---|
headingFontColor | #4a4a4a |
headingBgColor | #f7f7f7 |
headingFontFamily | News Cycle |
headingBorder | 1px solid #e6e6e6 |
headingFontSize | 14px |
headingFontWeight | normal |
headingCursor | pointer |
headingTextTransform | uppercase |
headingPadding | 15px |
rowSeparatorColor | 1px solid #e6e6e6 |
rowBgColor | none |
rowFontFamily | Lato |
rowAltBgColor | undefined |
rowHoverColor | #f5f8fc |
rowPadding | 15px |
rowTextAlign | center |
rowTransition | all 0.5s ease |
cellFontSize | 12px |
cellFontColor | #4a4a4a |
cellBgColor | none |
captionBgColor | undefined |
captionFontColor | undefined |
captionPadding | .8em .8em |
Types
You can define our interfaces and types to be used by tyble
.
;; ;
Data
Pass any data into tyble
in an array. See below an example of what data
might look like. This could be from an external web api etc.
;
If you want sorting you can write a custom sorting method to enable it on a column.
;
Columns
Define your columns and use them to populate your cells. No accessor id needed because we have type safety!
const columns: Array<TableColumn<Person>> = heading: content: 'First' sortOrder: SortOrderDESC sort: sortFunc <span>propsname</span> heading: content: 'Last' <span>propslastname</span> heading: content: 'Company' <span>propscompanyname</span> ;
Rendering
Standard
ReactDOM;
JSX Style
Alternatively you can write a tyble
using JSX manually.
<Table => <HeadingSection> <Heading ='Heading 1' /> </HeadingSection> <RowSection> <Row> <Cell ='Cell 1' /> <Cell ='Cell 2' /> <Cell ='Cell 3' /> </Row> </RowSection></Table>;
Styling
There are a number of ways to style tyble
we try to be unopinionated about styling and offer a few ways to do it.
- Sass
- Theme (
styled-components
) - Overriding default theme
Sass
} }}
Classes
- tyble, heading-section, heading, row, cell
Theme
You can pass a theme object to the theme
prop to use your own.
Override default theme
tyble
ships with a clean and minimal theme but you can
override this style with your own.
Tests and Linting
Running the tests and linters
yarn run test
yarn run lint:ts yarn run lint:css
Contributing
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
License
This project is licensed under the MIT License - see the LICENSE file for details.
FAQ
- Is this production ready?
Until version 1.0.0
this component will not be production ready. It is being developed and changed at pace.