
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
An empty base template for publishing a React TS package to npmjs library.
BlackLightBurn table component
npm install --save blb-table
Import styles in app.js
import 'blb-table/dist/variables.css';
export default function App({ Component, pageProps }: any) {
return <Component {...pageProps} />;
}
// index.tsx
import { useState, useEffect } from 'react';
import { Table, QueryParams, ColumnDef } from 'blb-table';
import { EmptyData } from '@/components/EmptyData';
import { Pagination } from '@/components/Pagination';
import { Search } from '@/components/Search';
import { FilterForm } from '@/components/FilterForm';
interface InitialDataProps {
title: string;
subscribers: number;
views: number;
}
const initialData = {
data: [
{
title: 'One',
subscribers: 1000,
views: 123,
},
{
title: 'Two',
subscribers: 2000,
views: 544,
},
{
title: 'Three',
subscribers: 3000,
views: 56626,
},
],
count: 3
};
export default function Home() {
const [data, setData] = useState(() => initialData)
const [queryParams, setQueryParams] = useState<QueryParams>({
limit: 3,
sort: [{
id: 'title',
desc: false,
}],
});
const columns: ColumnDef<InitialDataProps>[] = [
{
accessorKey: 'title',
header: () => <span>Name</span>,
cell: (info) => info.getValue(),
enableSorting: false,
},
{
accessorKey: 'subscribers',
header: () => <span>Subscribers</span>,
cell: (info) => info.getValue(),
enableSorting: true,
},
{
accessorKey: 'views',
header: () => <span>Views</span>,
cell: (info) => info.getValue(),
enableSorting: true,
},
];
useEffect(() => {
setData((prevData) => {
const filtered = !queryParams.search
? initialData.data
: prevData.data.filter((itm) => itm.title.includes(queryParams.search || ''));
return {
data: filtered,
count: filtered.length,
};
});
}, [queryParams]);
return (
<Table
data={data}
columns={columns}
isLoading={false}
onChange={setQueryParams}
initialState={queryParams}
template={['50%', '30%', '20%']}
components={{
EmptyData: ({ isLoading, isEmpty }) => (
<EmptyData isLoading={isLoading} isEmpty={isEmpty} />
),
Pagination: ({ pageCount, pageIndex, setPageIndex }) => (
<Pagination
pageCount={pageCount}
onChange={({ selected }) => {
setQueryParams((prev) => ({ ...prev, skip: queryParams.limit * selected }));
setPageIndex({ selected });
}}
/>
),
Search: ({ openFilters }) => (
<Search
onChange={(value) => {
setQueryParams((prev) => ({
...prev,
search: value,
skip: 0,
}));
}}
openFilters={openFilters}
/>
),
Filters: () => (
<FilterForm
onSubmit={(data) => {
setQueryParams((prev) => ({
...prev,
filter: {
...prev.filter,
...data,
},
skip: 0,
}));
}}
/>
),
}}
/>
)
}
// Example FilterForm.tsx
export const FilterForm = ({ onSubmit: _onSubmit }) => {
const onSubmit = (data) => {
let _data = {};
let viewsFrom;
let viewsTo;
if (data.target.name === 'viewsFrom') {
viewsFrom = data.target.value;
}
if (data.target.name === 'viewsTo') {
viewsTo = data.target.value;
}
_data = {
views: [viewsFrom ? Number(viewsFrom) : null, viewsTo ? Number(viewsTo) : null],
};
if (_onSubmit) _onSubmit(_data);
};
return (
<form onChange={onSubmit}>
<input name="viewsFrom" />
<input name="viewsTo" />
</form>
);
};
// Example Search.tsx
import { useState } from "react";
interface SearchProps {
onChange: (value: string) => void;
openFilters: () => void;
}
export const Search = ({ onChange, openFilters }: SearchProps) => {
const [searchValue, setSearchValue] = useState('');
return (
<>
<input
value={searchValue}
onChange={(e) => {
setSearchValue(e.target.value);
onChange(e.target.value);
}}
/>
<button type="button" onClick={openFilters}>open filters</button>
</>
)
}
// Example Pagination.tsx
interface PaginationProps {
pageCount: number;
onChange: ({ selected }: { selected: number }) => void;
}
export const Pagination = ({ pageCount, onChange }: PaginationProps) => {
return (
<>
{Array.from({ length: pageCount }, (_, index) => 0 + index).map((item) => (
<button type="button" key={item} onClick={() => onChange({ selected: item })}>{item + 1}</button>
))}
</>
);
};
// Example EmptyData.tsx
interface EmptyDataProps {
isLoading: boolean;
isEmpty: boolean;
}
export const EmptyData = ({ isLoading, isEmpty }: EmptyDataProps) => {
if (isLoading) {
return 'Loading...'
}
return 'Empty';
};
Count is a total count of elements
Limit for pagination page size and for number of elements to display and default sort state
Defines the width of each column (in %). For example ['50%', '30%', '20%']
For your custom components
Pagination?: (props: { pageCount: number; pageIndex: number; setPageIndex: ({ selected }: { selected: number }) => void; }) => React.ReactElement;
pageCount - total page count
pageIndex - current index of page
setPageIndex - function for set the page number
EmptyData?: (props: { isLoading: boolean; isEmpty: boolean }) => React.ReactElement;
Search?: (props: { openFilters: () => void; }) => React.ReactElement;
openFilter - open/close filters
Filters?: () => React.ReactElement;
This project is open for improvements and maintenance. Feel free to fork and make your own modifications.
MIT
FAQs
An empty base template for publishing a React TS package to npmjs library.
The npm package blb-table receives a total of 1 weekly downloads. As such, blb-table popularity was classified as not popular.
We found that blb-table demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.