@flagdown/react 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kieran Bond
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @flagdown/react
2
+
3
+ React bindings for [Flagdown](https://github.com/flagdown/flagdown) feature
4
+ flags.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install @flagdown/react
10
+ ```
11
+
12
+ ## Current bootstrap API
13
+
14
+ Wrap the part of the React tree that reads flags in `FlagdownProvider`, then
15
+ read a flag with `useFlag`:
16
+
17
+ ```tsx
18
+ import { FlagdownProvider, useFlag } from "@flagdown/react";
19
+
20
+ function BetaFeature() {
21
+ return useFlag("beta-feature") ? <p>Enabled</p> : null;
22
+ }
23
+
24
+ export function App() {
25
+ return (
26
+ <FlagdownProvider>
27
+ <BetaFeature />
28
+ </FlagdownProvider>
29
+ );
30
+ }
31
+ ```
32
+
33
+ This initial provider returns `false` for every flag. A future release will
34
+ provide an adapter generated from Flagdown's OpenAPI contract.
35
+
36
+ For tests or custom adapters, supply a `FlagEvaluator` implementation:
37
+
38
+ ```tsx
39
+ <FlagdownProvider evaluator={{ isEnabled: (key) => key === "beta-feature" }}>
40
+ <BetaFeature />
41
+ </FlagdownProvider>
42
+ ```
@@ -0,0 +1,27 @@
1
+ import * as react from 'react';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ /** A port for resolving a feature flag's enabled state. */
5
+ interface FlagEvaluator {
6
+ isEnabled(flagKey: string): boolean;
7
+ }
8
+ /**
9
+ * Temporary adapter used until the SDK is connected to the Flagdown API.
10
+ *
11
+ * It deliberately keeps every flag disabled so applications can install the
12
+ * provider and hook safely before remote evaluation is available.
13
+ */
14
+ declare const disabledFlagEvaluator: FlagEvaluator;
15
+
16
+ interface FlagdownProviderProps extends PropsWithChildren {
17
+ /**
18
+ * Optional evaluation port. This enables a future Flagdown API adapter and
19
+ * keeps consumers independent from the transport that supplies flag values.
20
+ */
21
+ evaluator?: FlagEvaluator;
22
+ }
23
+ declare function FlagdownProvider({ children, evaluator, }: FlagdownProviderProps): react.JSX.Element;
24
+
25
+ declare function useFlag(flagKey: string): boolean;
26
+
27
+ export { type FlagEvaluator, FlagdownProvider, type FlagdownProviderProps, disabledFlagEvaluator, useFlag };
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ // src/FlagdownContext.tsx
2
+ import { createContext, useContext } from "react";
3
+ var FlagdownContext = createContext(void 0);
4
+ function useFlag(flagKey) {
5
+ const evaluator = useContext(FlagdownContext);
6
+ if (!evaluator) {
7
+ throw new Error("useFlag must be used within a FlagdownProvider");
8
+ }
9
+ return evaluator.isEnabled(flagKey);
10
+ }
11
+
12
+ // src/flags.ts
13
+ var disabledFlagEvaluator = {
14
+ isEnabled: () => false
15
+ };
16
+
17
+ // src/FlagdownProvider.tsx
18
+ import { jsx } from "react/jsx-runtime";
19
+ function FlagdownProvider({
20
+ children,
21
+ evaluator = disabledFlagEvaluator
22
+ }) {
23
+ return /* @__PURE__ */ jsx(FlagdownContext.Provider, { value: evaluator, children });
24
+ }
25
+ export {
26
+ FlagdownProvider,
27
+ disabledFlagEvaluator,
28
+ useFlag
29
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@flagdown/react",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "description": "React SDK for evaluating Flagdown feature flags.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/flagdown/flagdown.git",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ }
24
+ },
25
+ "files": ["dist", "README.md", "LICENSE"],
26
+ "scripts": {
27
+ "build": "tsup src/index.ts --format esm --dts --clean",
28
+ "test": "bun test",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "peerDependencies": {
32
+ "react": ">=18",
33
+ "react-dom": ">=18"
34
+ },
35
+ "devDependencies": {
36
+ "@types/react": "^18",
37
+ "react": "^18",
38
+ "react-dom": "^18",
39
+ "tsup": "^8",
40
+ "typescript": "^5"
41
+ }
42
+ }