Skip to content

Commit

Permalink
fix: react core build and move knockfeedcontainer (#10)
Browse files Browse the repository at this point in the history
* feat: add build process to react-core and move KnockFeedContainer to react

* rename component to NotificationFeedContainer

* update peer dependency version minimums

* add build:packages command
  • Loading branch information
connorlindsey authored Jan 6, 2024
1 parent 64b7cd5 commit d8a216e
Show file tree
Hide file tree
Showing 15 changed files with 2,962 additions and 2,429 deletions.
8 changes: 8 additions & 0 deletions .changeset/thin-cups-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@knocklabs/react-core": patch
"@knocklabs/react": patch
---

fix: react-core build process
fix: remove headless prop from KnockFeedProvider
fix: move KnockFeedContainer from react-core to react and rename to NotificationFeedContainer
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"scripts": {
"build": "turbo build",
"build:packages": "turbo build --filter=\"./packages/*\"",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
Expand Down
7 changes: 5 additions & 2 deletions packages/react-core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@knocklabs/eslint-config/react-internal.js"],
extends: [
"@knocklabs/eslint-config/library.js",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
projects: ["tsconfig.json", "tsconfig.node.json"],
},
};
55 changes: 52 additions & 3 deletions packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,56 @@
"author": "@knocklabs",
"version": "0.1.0",
"license": "MIT",
"main": "src/index.ts",
"types": "src/index.ts",
"dependencies": {}
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"types": "dist/types/index.d.ts",
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"default": "./dist/esm/index.mjs"
}
},
"files": [
"dist",
"README.md"
],
"scripts": {
"clean": "rimraf dist",
"dev": "tsc && vite build --watch",
"build": "yarn clean && yarn build:esm && yarn build:cjs",
"build:esm": "export BUILD_TARGET=esm; tsc && vite build",
"build:cjs": "export BUILD_TARGET=cjs; tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"repository": {
"type": "git",
"url": "git+https://github.com/knocklabs/javascript.git"
},
"bugs": {
"url": "https://github.com/knocklabs/javascript/issues"
},
"peerDependencies": {
"react": ">=16.8.0"
},
"dependencies": {
"@knocklabs/client": "*"
},
"devDependencies": {
"@types/react": "^18.2.37",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.53.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"rimraf": "^5.0.5",
"rollup-plugin-execute": "^1.1.1",
"typescript": "^5.2.2",
"vite": "^5.0.0",
"vite-plugin-dts": "^3.6.3",
"vite-plugin-no-bundle": "^3.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import create, { StoreApi, UseStore } from "zustand";
import { ColorMode } from "../../core/constants";
import useNotifications from "../hooks/useNotifications";
import { feedProviderKey } from "../../core/utils";
import { KnockFeedContainer } from "./KnockFeedContainer";
import { useKnockClient } from "../../core";

export interface KnockFeedProviderState {
Expand All @@ -29,7 +28,6 @@ export interface KnockFeedProviderProps {

// Extra options
children?: React.ReactElement;
rootless?: boolean;
colorMode?: ColorMode;

// Feed client options
Expand All @@ -40,20 +38,13 @@ export const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({
feedId,
children,
defaultFeedOptions = {},
rootless = false,
colorMode = "light",
}) => {
const knock = useKnockClient();

const feedClient = useNotifications(knock, feedId, defaultFeedOptions);
const useFeedStore = create(feedClient.store as StoreApi<FeedStoreState>);

const content = rootless ? (
children
) : (
<KnockFeedContainer>{children}</KnockFeedContainer>
);

return (
<FeedStateContext.Provider
key={feedProviderKey(feedId, defaultFeedOptions)}
Expand All @@ -64,7 +55,7 @@ export const KnockFeedProvider: React.FC<KnockFeedProviderProps> = ({
colorMode,
}}
>
{content}
{children}
</FeedStateContext.Provider>
);
};
Expand Down
1 change: 0 additions & 1 deletion packages/react-core/src/modules/feed/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./KnockFeedProvider";
export * from "./KnockFeedContainer";
4 changes: 4 additions & 0 deletions packages/react-core/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@knocklabs/typescript-config/node.json",
"include": ["vite.config.ts"]
}
39 changes: 39 additions & 0 deletions packages/react-core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig, LibraryFormats, loadEnv } from "vite";
import { resolve } from "path";
import react from "@vitejs/plugin-react";
import noBundlePlugin from "vite-plugin-no-bundle";
import dts from "vite-plugin-dts";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const CJS = env.BUILD_TARGET?.toLocaleLowerCase()?.match("cjs");
const formats: LibraryFormats[] = CJS ? ["cjs"] : ["es"];

return {
plugins: [
dts({
outDir: "dist/types",
}),
react(),
noBundlePlugin({ root: "./src" }),
],
build: {
outDir: CJS ? "dist/cjs" : "dist/esm",
sourcemap: true,
lib: {
entry: resolve(__dirname, "src/index.ts"),
name: "react-core",
formats,
},
rollupOptions: {
output: {
interop: "compat",
format: formats[0],
},
// External packages that should not be bundled
external: ["react"],
},
},
};
});
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A set of components for integrating [Knock](https://knock.app) into a React appl
[See a live demo](https://knock-in-app-notifications-react.vercel.app/)

![In-app feed component example](NotificationFeed.png)
![In-app feed component example](/NotificationFeed.png)

**Note: these components are designed to be used via React for web only.**

Expand Down
8 changes: 5 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
"bugs": {
"url": "https://github.com/knocklabs/javascript/issues"
},
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"dependencies": {
"@knocklabs/client": "*",
"@knocklabs/react-core": "0.1.0",
"@knocklabs/react-core": "*",
"date-fns": "^2.30.0",
"lodash.debounce": "^4.0.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-popper": "^2.3.0",
"react-popper-tooltip": "^4.4.2",
"zustand": "^3.5.10"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PropsWithChildren } from "react";
import "./styles.css";

export const KnockFeedContainer: React.FC<PropsWithChildren> = ({
export const NotificationFeedContainer: React.FC<PropsWithChildren> = ({
children,
}) => {
return <div className="rnf-feed-provider">{children}</div>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./NotificationFeedContainer";
1 change: 1 addition & 0 deletions packages/react/src/modules/feed/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./components/EmptyFeed";
export * from "./components/NotificationCell";
export * from "./components/NotificationFeed";
export * from "./components/NotificationFeedContainer";
export * from "./components/NotificationFeedPopover";
export * from "./components/NotificationIconButton";
export * from "./components/UnseenBadge";
Loading

0 comments on commit d8a216e

Please sign in to comment.