@launchdarkly/toolbar 0.10.1 → 0.11.1-beta.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.
Files changed (30) hide show
  1. package/README.md +138 -125
  2. package/dist/index.d.ts +3 -0
  3. package/dist/js/index.js +1730 -994
  4. package/dist/plugins/FlagOverridePlugin.d.ts +57 -0
  5. package/dist/plugins/index.d.ts +2 -0
  6. package/dist/tests/DevServerProvider.test.d.ts +1 -0
  7. package/dist/tests/ExpandedToolbarContent.test.d.ts +1 -0
  8. package/dist/tests/FlagSdkOverrideProvider.test.d.ts +1 -0
  9. package/dist/types/devServer.d.ts +2 -2
  10. package/dist/types/plugin.d.ts +31 -0
  11. package/dist/ui/Toolbar/Header/Header.d.ts +2 -0
  12. package/dist/ui/Toolbar/Header/components/ActionButtons.d.ts +1 -0
  13. package/dist/ui/Toolbar/LaunchDarklyToolbar.d.ts +8 -2
  14. package/dist/ui/Toolbar/TabContent/FlagDevServerTabContent.d.ts +1 -0
  15. package/dist/ui/Toolbar/TabContent/FlagSdkOverrideTabContent.d.ts +6 -0
  16. package/dist/ui/Toolbar/TabContent/SettingsTabContent.d.ts +6 -1
  17. package/dist/ui/Toolbar/components/ExpandedToolbarContent.d.ts +4 -1
  18. package/dist/ui/Toolbar/components/LocalFlagControls.css.d.ts +4 -0
  19. package/dist/ui/Toolbar/components/LocalFlagControls.d.ts +20 -0
  20. package/dist/ui/Toolbar/components/TabContentRenderer.d.ts +4 -1
  21. package/dist/ui/Toolbar/constants/index.d.ts +1 -1
  22. package/dist/ui/Toolbar/constants/virtualization.d.ts +4 -0
  23. package/dist/ui/Toolbar/context/{LaunchDarklyToolbarProvider.d.ts → DevServerProvider.d.ts} +6 -6
  24. package/dist/ui/Toolbar/context/FlagSdkOverrideProvider.d.ts +19 -0
  25. package/dist/ui/Toolbar/context/index.d.ts +3 -0
  26. package/dist/ui/Toolbar/types/toolbar.d.ts +7 -1
  27. package/package.json +5 -3
  28. package/dist/ui/Toolbar/TabContent/FlagTabContent.d.ts +0 -1
  29. package/dist/ui/Toolbar/constants/config.d.ts +0 -3
  30. /package/dist/ui/Toolbar/TabContent/{FlagTabContent.css.d.ts → FlagDevServerTabContent.css.d.ts} +0 -0
package/README.md CHANGED
@@ -1,184 +1,201 @@
1
1
  # LaunchDarkly Toolbar
2
2
 
3
- > ⚠️ **Warning:** This package is currently not ready for production use and is considered unsupported. Features, APIs, and behavior may change without notice.
3
+ > 🚧 **Beta:** This package is currently in beta. While functional and tested, APIs may still evolve based on feedback. Please report any issues or suggestions!
4
4
 
5
- A React component that provides a developer-friendly toolbar for interacting with LaunchDarkly during development.
5
+ A React component that provides a developer-friendly toolbar for interacting with LaunchDarkly during development. The toolbar supports two modes:
6
+
7
+ - **SDK Mode**: Integrate with your LaunchDarkly SDK for local flag overrides and testing (recommended)
8
+ - **Dev Server Mode**: Connect to a LaunchDarkly CLI dev server for flag browsing and real-time updates
6
9
 
7
10
  ## Installation
8
11
 
9
12
  ```bash
10
- npm install @launchdarkly/toolbar
11
- # or
12
- yarn add @launchdarkly/toolbar
13
- # or
14
- pnpm add @launchdarkly/toolbar
15
- ```
13
+ # npm
14
+ npm install @launchdarkly/toolbar@next
16
15
 
17
- 1. **Import the component and styles:**
16
+ # yarn
17
+ yarn add @launchdarkly/toolbar@next
18
18
 
19
- ```tsx
20
- import { LaunchDarklyToolbar } from '@launchdarkly/toolbar';
19
+ # pnpm
20
+ pnpm add @launchdarkly/toolbar@next
21
21
  ```
22
22
 
23
- 2. **Add the toolbar to your app:**
23
+ ## Quick Start
24
+
25
+ **SDK Mode** (recommended - integrates with your LaunchDarkly SDK):
24
26
 
25
27
  ```tsx
28
+ import { useEffect, useState } from 'react';
29
+ import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
30
+ import { LaunchDarklyToolbar, FlagOverridePlugin } from '@launchdarkly/toolbar';
31
+
32
+ // Create the plugin instance
33
+ const flagOverridePlugin = new FlagOverridePlugin();
34
+
26
35
  function App() {
27
- return (
28
- <div>
29
- {/* Your app content */}
30
- <h1>My App</h1>
36
+ const [LDProvider, setLDProvider] = useState(null);
37
+
38
+ useEffect(() => {
39
+ const initializeLD = async () => {
40
+ const Provider = await asyncWithLDProvider({
41
+ clientSideID: 'your-client-side-id',
42
+ context: { key: 'user-key', name: 'User Name' },
43
+ options: {
44
+ // Pass the plugin to the SDK
45
+ plugins: [flagOverridePlugin],
46
+ },
47
+ });
48
+ setLDProvider(() => Provider);
49
+ };
50
+
51
+ initializeLD();
52
+ }, []);
53
+
54
+ if (!LDProvider) {
55
+ return <div>Loading LaunchDarkly...</div>;
56
+ }
31
57
 
32
- {/* LaunchDarkly Toolbar */}
33
- <LaunchDarklyToolbar devServerUrl="http://localhost:8765" position="right" />
34
- </div>
58
+ return (
59
+ <LDProvider>
60
+ <div>
61
+ <h1>My App</h1>
62
+ {/* Pass the same plugin instance to the toolbar */}
63
+ <LaunchDarklyToolbar flagOverridePlugin={flagOverridePlugin} />
64
+ </div>
65
+ </LDProvider>
35
66
  );
36
67
  }
37
68
  ```
38
69
 
39
- 3. **Start your LaunchDarkly dev server:**
40
-
41
- ```bash
42
- # Make sure your LaunchDarkly dev server is running
43
- # The toolbar will automatically connect and display your flags
44
- ```
45
-
46
- ## Props
47
-
48
- | Prop | Type | Default | Description |
49
- | -------------- | ------------------- | ------------------------- | --------------------------------------------- |
50
- | `devServerUrl` | `string` | `"http://localhost:8765"` | URL of your LaunchDarkly development server |
51
- | `position` | `"left" \| "right"` | `"right"` | Position of the toolbar on screen |
52
- | `projectKey` | `string` | `undefined` | Optional project key for multi-project setups |
53
-
54
- ## Usage Examples
55
-
56
- ### Basic Usage
70
+ **Dev Server Mode** (connects to LaunchDarkly CLI dev server):
57
71
 
58
72
  ```tsx
59
73
  import { LaunchDarklyToolbar } from '@launchdarkly/toolbar';
60
74
 
61
75
  function App() {
62
76
  return (
63
- <>
64
- <main>
65
- <h1>My Application</h1>
66
- {/* Your app content */}
67
- </main>
68
-
69
- <LaunchDarklyToolbar />
70
- </>
77
+ <div>
78
+ <h1>My App</h1>
79
+ <LaunchDarklyToolbar devServerUrl="http://localhost:8765" />
80
+ </div>
71
81
  );
72
82
  }
73
83
  ```
74
84
 
75
- ### Custom Configuration
85
+ ## Props
76
86
 
77
- ```tsx
78
- import { LaunchDarklyToolbar } from '@launchdarkly/toolbar';
87
+ | Prop | Type | Default | Description |
88
+ | -------------------- | --------------------- | ----------- | ------------------------------------------------------------------------- |
89
+ | `flagOverridePlugin` | `IFlagOverridePlugin` | `undefined` | Flag override plugin for SDK Mode. Enables flag overrides and testing |
90
+ | `devServerUrl` | `string` (optional) | `undefined` | URL of your LaunchDarkly dev server. If provided, enables Dev Server Mode |
91
+ | `position` | `"left" \| "right"` | `"right"` | Position of the toolbar on screen |
92
+ | `projectKey` | `string` (optional) | `undefined` | Optional project key for multi-project setups (Dev Server Mode only) |
93
+ | `pollIntervalInMs` | `number` (optional) | `5000` | Polling interval for dev server updates (Dev Server Mode only) |
79
94
 
80
- function App() {
81
- return (
82
- <>
83
- <main>{/* Your app content */}</main>
95
+ ## Configuration
84
96
 
85
- <LaunchDarklyToolbar devServerUrl="http://localhost:3001" position="left" projectKey="my-project" />
86
- </>
87
- );
88
- }
89
- ```
97
+ ### Mode Determination
90
98
 
91
- ### Usage
99
+ The toolbar automatically determines its mode:
92
100
 
93
- ```tsx
94
- import { LaunchDarklyToolbar } from '@launchdarkly/toolbar';
101
+ - **SDK Mode**: When `flagOverridePlugin` is provided (recommended for most use cases)
102
+ - **Dev Server Mode**: When `devServerUrl` is provided
95
103
 
96
- function App() {
97
- return (
98
- <>
99
- <main>{/* Your app content */}</main>
104
+ ### Available Features by Mode
100
105
 
101
- {/* Only show toolbar in development */}
102
- {process.env.NODE_ENV === 'development' && <LaunchDarklyToolbar />}
103
- </>
104
- );
105
- }
106
- ```
106
+ | Mode | Available Tabs |
107
+ | ------------------- | ------------------- |
108
+ | **SDK Mode** | Overrides, Settings |
109
+ | **Dev Server Mode** | Flags, Settings |
107
110
 
108
- ## How It Works
111
+ ## Setup
109
112
 
110
- The LaunchDarkly Toolbar connects to your LaunchDarkly development server to provide real-time flag management capabilities:
113
+ ### SDK Mode (Recommended)
111
114
 
112
- 1. **Automatic Discovery** - The toolbar automatically discovers available flags from your dev server
113
- 2. **Real-time Updates** - Flag changes are reflected immediately in your application
114
- 3. **Event Stream** - Monitor flag evaluation events as they happen
115
- 4. **Search & Filter** - Quickly find flags using the built-in search functionality
115
+ SDK Mode integrates directly with your LaunchDarkly client, allowing you to:
116
116
 
117
- ## Toolbar Visibility Control
117
+ - Override flag values locally without affecting other users
118
+ - Test different flag variations instantly
119
+ - Work offline or with any LaunchDarkly environment
120
+ - Maintain full type safety with your existing SDK setup
118
121
 
119
- The toolbar includes built-in visibility controls that allow developers to easily show/hide the toolbar during development. When the toolbar loads, it automatically exposes a global API on the browser's window object.
122
+ Setup is straightforward:
120
123
 
121
- ### Global API
124
+ 1. Create a `FlagOverridePlugin` instance
125
+ 2. Pass the plugin to your LaunchDarkly SDK's `plugins` array
126
+ 3. Pass the same plugin instance to the toolbar component
127
+ 4. Wrap your app with the LaunchDarkly provider
122
128
 
123
- The toolbar provides a `window.ldToolbar` API with the following methods:
129
+ ```tsx
130
+ import { useEffect, useState } from 'react';
131
+ import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
132
+ import { LaunchDarklyToolbar, FlagOverridePlugin } from '@launchdarkly/toolbar';
124
133
 
125
- ```javascript
126
- // Enable the toolbar (removes it from localStorage and shows the toolbar)
127
- window.ldToolbar.enable();
134
+ // Create the plugin instance (outside component to avoid recreating)
135
+ const flagOverridePlugin = new FlagOverridePlugin({
136
+ storageNamespace: 'my-app-overrides', // Optional: customize storage key
137
+ });
128
138
 
129
- // Disable the toolbar (saves preference to localStorage and hides the toolbar)
130
- window.ldToolbar.disable();
139
+ function App() {
140
+ const [LDProvider, setLDProvider] = useState(null);
131
141
 
132
- // Toggle the toolbar visibility
133
- window.ldToolbar.toggle();
142
+ useEffect(() => {
143
+ const initializeLD = async () => {
144
+ const Provider = await asyncWithLDProvider({
145
+ clientSideID: 'your-client-side-id',
146
+ context: { key: 'user-key', name: 'User Name' },
147
+ options: {
148
+ plugins: [flagOverridePlugin], // Add plugin to SDK
149
+ },
150
+ });
151
+ setLDProvider(() => Provider);
152
+ };
153
+
154
+ initializeLD();
155
+ }, []);
134
156
 
135
- // Check current status (returns true if enabled, false if disabled)
136
- window.ldToolbar.status();
157
+ if (!LDProvider) return <div>Loading...</div>;
158
+
159
+ return (
160
+ <LDProvider>
161
+ <YourAppContent />
162
+ <LaunchDarklyToolbar flagOverridePlugin={flagOverridePlugin} />
163
+ </LDProvider>
164
+ );
165
+ }
137
166
  ```
138
167
 
139
- ### Console Information
168
+ ### Dev Server Mode
140
169
 
141
- When the toolbar loads, you'll see helpful console output showing the available commands:
170
+ For teams using the LaunchDarkly CLI dev server, start it with CORS enabled:
142
171
 
143
- ```
144
- 🔧 LaunchDarkly toolbar controls available:
145
- window.ldToolbar.enable() - Enable toolbar
146
- window.ldToolbar.disable() - Disable toolbar
147
- window.ldToolbar.toggle() - Toggle toolbar
148
- window.ldToolbar.status() - Check current status
172
+ ```bash
173
+ ldcli dev-server start --project your-project --cors-enabled true
149
174
  ```
150
175
 
151
- ### Persistent State
176
+ Then connect the toolbar:
177
+
178
+ ```tsx
179
+ <LaunchDarklyToolbar devServerUrl="http://localhost:8765" />
180
+ ```
152
181
 
153
- The toolbar's visibility state is automatically saved to localStorage and persists across browser sessions. The state is also synchronized across multiple tabs of the same application.
182
+ ## Visibility Control
154
183
 
155
- ### Usage Examples
184
+ The toolbar provides a global API for show/hide control:
156
185
 
157
186
  ```javascript
158
- // Hide the toolbar for focused development
159
- window.ldToolbar.disable();
160
- // Console: ✅ LaunchDarkly toolbar disabled.
187
+ // Toggle visibility
188
+ window.ldToolbar.toggle();
161
189
 
162
- // Show the toolbar when you need it
190
+ // Enable/disable explicitly
163
191
  window.ldToolbar.enable();
164
- // Console: ✅ LaunchDarkly toolbar enabled.
165
-
166
- // Check if the toolbar is currently visible
167
- const isEnabled = window.ldToolbar.status();
168
- // Console: LaunchDarkly toolbar is currently: ✅ ENABLED
169
- // Returns: true
192
+ window.ldToolbar.disable();
170
193
 
171
- // Quick toggle
172
- window.ldToolbar.toggle();
194
+ // Check current status
195
+ window.ldToolbar.status(); // returns true/false
173
196
  ```
174
197
 
175
- ## Development Server Setup
176
-
177
- The toolbar requires a LaunchDarkly CLI dev-server to be running with CORS enabled.
178
-
179
- ```bash
180
- ldcli dev-server start --project demo-project --cors-enabled true
181
- ```
198
+ Visibility preferences are automatically saved to localStorage.
182
199
 
183
200
  ## TypeScript
184
201
 
@@ -186,12 +203,8 @@ The package includes complete TypeScript definitions. No additional `@types` pac
186
203
 
187
204
  ```tsx
188
205
  import type { LaunchDarklyToolbarProps } from '@launchdarkly/toolbar';
189
-
190
- const toolbarConfig: LaunchDarklyToolbarProps = {
191
- devServerUrl: 'http://localhost:8765',
192
- position: 'right',
193
- projectKey: 'my-project',
194
- };
195
206
  ```
196
207
 
208
+ ---
209
+
197
210
  Built with ❤️ for the LaunchDarkly developer community.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import './globals.css';
2
2
  export { LaunchDarklyToolbar } from './ui/Toolbar/LaunchDarklyToolbar';
3
3
  export type { LaunchDarklyToolbarProps } from './ui/Toolbar/LaunchDarklyToolbar';
4
+ export type { IFlagOverridePlugin } from './types/plugin';
5
+ export { FlagOverridePlugin } from './plugins';
6
+ export type { FlagOverridePluginConfig } from './plugins';