1.1.4 • Published 2 years ago

svelte-tailwind-table-types v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Svelte Tailwind Table

The last Svelte Table library you will ever need. A Svelte component for rendering a dynamic table using tailwind CSS

This is a hard fork of svelte-tailwind-table since the original repository on GitLab couldn't be reached and I wanted to add types and SvelteKit-style imports.


Check out the demo


Key Features

  • Inbuilt SearchBar (Can be removed using props)
  • Most components are customizable
  • You can set onclick events/hyperlinks and more...
  • Customizable Pagination and Header Icons!
  • Sort and Filter
  • Custom icon column
  • Custom component data type
  • Interactive Rows with custom onclick events
  • Multiple themes (outlined, filled and more coming soon...)

What's new

  • 8 new props showHeaderOptions, theme, onRowClickFunction, interactiveRows, activeRow, rowBorderTouch, borderRadius, numbersSmall
  • Features: Interactive rows, themes added, more customization options
  • UI improvements

Coming soon!

  • File upload

Check it out!

Demo GIF 👇(OLD)

Installation


[Tailwind css](https://tailwindcss.com/docs/installation#using-tailwind-via-cdn) in required for the table to be styled properly

npm install svelte-tailwind-table

Basic usage


<script>
  import Table from 'svelte-tailwind-table';
</script>

<Table colData={...} rowData={...}/>

Props

Prop NameData TypeDefault value
colDataarrayexample with all data types
rowDataarrayexample with 2 row values
themestringoutline
showSearchBarbooleantrue
searchStylesstring""
searchTextstring""
showFilterbooleantrue
filterButtonColorstring"red"
showHeaderIconsbooleantrue
showHeaderOptionsbooleantrue
headerEditablebooleantrue
borderBetweenColumnsbooleantrue
numberAlignstring"right"
allCenterbooleanfalse
paginationbooleantrue
paginationRowsnumber10
currentPagenumber1
paginationTypestringdefault
selectAllMenubooleantrue
onClickFunctionfunction()={}
onRowClickFunctionfunction()={}
interactiveRowsbooleanfalse
interactiveRowColorstring"gray"
activeRownumber0
rowBorderTouchbooleantrue
borderRadiustextxl
numbersSmallbooleantrue
overrideClassesstring""

colData

A 2-Dimensional array with the following properties:

colData = [
    ["Data type", {heading: "Column 1 heading", data:{...}}],
    ["Data type", {heading: "Column 2 heading", data:{...}}],
]

Refer to [Datatypes](#data-types) for information regarding the data:{...}

rowData

A 2-Dimensional array with the following properties:

rowData = [
    [ //row 1
        {value: "The value", editable: true, href: "This is optional"},     //column 1 value
        {value: "The value", editable: true, href: "hyperlink for a cell"}, //column 2 value
    ],
    [ //row 2
        {value: "The value", editable: true}, //column 1 value
        {value: "The value", editable: true}, //column 2 value
    ]
]

Refer to [Data Types](#data-types) for information regarding the The value

theme

The theme of the table. outline or filled makes the header background color white or grey. borderless makes the table borderless and transparent.

showSearchBar

A boolean value to determine if the default search bar is shown or not.

searchStyles

A string value to override the styling of the search bar.

searchText

A string value to set the searched text for the search bar.

showFilter

A boolean value to determine if the default filter is shown or not.

filterButtonColor

A string value to set the color of the filter button.

showHeaderIcons

A boolean value to determine if the header icons are shown or not.

showHeaderOptions

A boolean value to determine if the header options are shown or not.

headerEditable

A boolean value to determine if the header is editable or not.

borderBetweenColumns

A boolean value to determine if the border between columns is shown or not.

numberAlign

A string value to set the alignment of the number column ("right" or "left").

allCenter

A boolean value to determine if the cell values are centered or not.

pagination

A boolean value to determine if the pagination is done or not.

paginationRows

An integer value to set the number of rows per page.

currentPage

An integer value to set the current page.

paginationType

A string value to set the type of pagination. default or detailed - Detailed shows the number current showing data Theme of pagination is determined by the theme of the table.

selectAllMenu

A boolean value to determine if the select all box is shown or not.

onClickFunction

A function to call when a cell is clicked on The function needs to be of format

function yourFunctionName(event, cellData, colIndex, rowIndex){
    // do anything using the params
}

onRowClickFunction

A function to call when a row is clicked on (only if interactiveRows is set to true) The function needs to be of format

function yourFunctionName(event, rowIndex){
    // do anything using the params
}

interactiveRows

A boolean value to determine if the rows are interactive or not.

interactiveRowColor

A string value to set the color of the interactive rows on active and hover.

activeRow

An integer value to set the active row. This is only used if interactiveRows is set to true.

rowBorderTouch

A boolean value to determine if the row borders are touching the edges or are disconnected.

borderRadius

A string value to set the border radius of the table. One of "none", "sm", "md", "lg", "xl", "2xl", "3xl", "4xl", "5xl", "6xl", "7xl", "full"

numbersSmall

A boolean value to determine if the numbers are small or not. Makes the minimum width of the number column smaller or larger.

overrideClasses

A string value to override the default classes.

Data Types

🌐 Global Options

data: {
    align: "right"/"left"/"center", //optional
    iconAlign: "right"/"left"/"center", //optional
    iconSvg: "svg as string for overriding default svg", //optional
    showIcon: true/false, //optional
}

📄 Text

data: {}
value: "The value"

✅ Checkbox

data: {checked: true}
value: boolean(false/true)

🔢 Number

data: {}
value: 123

🔽 Select

data: {
    options: [
        {text: "Option 1", color: "#c3c3c3"}, // color is optional
        {text: "Option 2", color: "#c4c4c4"}, // When not provided random colors will be assigned
        {text: "Option 3", color: "#c5c5c5"}, // random colors will be taken from predefined light colors
    ]
}
value: {text: "Option 1", color: "#c3c3c3"}

⏬ Multiselect

data: {
    options: [
        {text: "Option 1"}, // color is optional here also
        {text: "Option 2"},
        {text: "Option 3"},
    ]
}
value: [
    {text: "Option 1"},
    {text: "Option 2"}
] // make sure to use same object value as in options

🖼 Image

data: {}
value: [
    {
        link:"https://via.placeholder.com/150",
        href:"https://www.example.com"
    }, //image 1
    {
        link:"https://via.placeholder.com/150",
        href:"https://www.example.com"
    }, //image 2
]

📅 Date

data: {}
value: "2003-02-19"

🕒 Time

data: {}
value: "12:00"

⁝ Icon

data: {
    svg: `<svg></svg>`, // default row svg string
}
value: `<svg></svg>`/"" // override row svg string otherwise ""

The above svg overrides are for row data and not the default header icon. Use [iconSvg prop](#data-types) for that

👨‍💻 Custom Component

data: {
    component: CustomComponent, // Custom Component directly from import
    defaultProps: { // props to pass to the component
        prop1: "value",
        prop2: "value"
    }
}
value: {
    props: { // props to override default props
        prop1: "value", 
        prop2: "value"
    }
}

To fire and use events on custom components, dispatch an event named as "event" from the component and use on:customEvent prop on Table component; The details passed on to the "event" dispatch will be e.detail.e for the Table listener

Example

<!-- CustomComponent.svelte -->
<script>
    import {createEventDispatcher} from "svelte";
    const dispatch = createEventDispatcher();
</script>
<div on:click={(e)=>{
    dispatch("event", {
        active: false
    })
}}>
    <!-- ... -->
</div>
<!-- Main.svelte -->
<Table on:customEvent={(e)=>{
    console.log(e.detail.e) // logs {active: false}
}}/>

Thank you so much checking out the package! 🙏

Hope you like it! 😇

Made with ❤️ by [Priyav Kaneria](https://priyavkaneria.me)


Contact me at [LinkedIn](https://www.linkedin.com/in/priyavkaneria/) or [Github](https://github.com/PriyavKaneria) or priyavkaneria@gmail.com

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago