Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/react-filters-bar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/coverage
33 changes: 33 additions & 0 deletions packages/react-filters-bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@cloudwalker/react-filters-bar",
"version": "0.0.0",
"scripts": {
"types": "tsc --noEmit",
"build": "tsup src/main.tsx",
"dev": "tsup src/main.tsx --watch"
},
"files": [
"dist/**"
],
"main": "dist/main.js",
"module": "dist/main.mjs",
"types": "dist/main.d.ts",
"sideEffects": false,
"author": {
"name": "Luca Barone",
"email": "baro.luc@gmail.com",
"url": "https://github.com/cloud-walker"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/react": "^18.0.21",
"react": "^18.2.0",
"tsup": "^6.2.3",
"typescript": "^4.8.4"
},
"peerDependencies": {
"react": ">=16.8"
}
}
26 changes: 26 additions & 0 deletions packages/react-filters-bar/src/filter-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createContext, PropsWithChildren, useContext } from "react";

type FilterState = {
remove: () => void;
setOperator: (value: string) => void;
setValue: (value: string) => void;
operator: string;
value: string;
};

const FilterCtx = createContext<FilterState | null>(null);

export function useFilterCtx() {
const ctx = useContext(FilterCtx);
if (ctx == null) {
throw Error("FilterCtx.Provider is missing.");
}
return ctx;
}

export function FilterProvider({
children,
...props
}: PropsWithChildren<FilterState>) {
return <FilterCtx.Provider value={props}>{children}</FilterCtx.Provider>;
}
24 changes: 24 additions & 0 deletions packages/react-filters-bar/src/filtersbar-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createContext, PropsWithChildren, useContext } from "react";

type FiltersDef = Record<string, JSX.Element>;

const FiltersBarCtx = createContext<{ filtersDef: FiltersDef } | null>(null);

export function useFiltersBarCtx() {
const ctx = useContext(FiltersBarCtx);
if (ctx == null) {
throw Error("FiltersBarCtx.Provider is missing.");
}
return ctx;
}

export function FiltersBarProvider<TFiltersDef extends FiltersDef>({
children,
filtersDef,
}: PropsWithChildren<{ filtersDef: TFiltersDef }>) {
return (
<FiltersBarCtx.Provider value={{ filtersDef }}>
{children}
</FiltersBarCtx.Provider>
);
}
5 changes: 5 additions & 0 deletions packages/react-filters-bar/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FiltersBarProvider } from "./filtersbar-context";

export function FiltersBar({filtersDef}: ) {
return <FiltersBarProvider filtersDef={}></FiltersBarProvider>
}
8 changes: 8 additions & 0 deletions packages/react-filters-bar/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"strict": true,
"jsx": "react-jsx",
"noUncheckedIndexedAccess": true
},
"include": ["src"]
}
8 changes: 8 additions & 0 deletions packages/react-filters-bar/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {defineConfig} from 'tsup'

export default defineConfig({
format: ['cjs', 'esm'],
minify: true,
sourcemap: true,
dts: true,
})