@trops/dash-react 1.0.35 → 1.0.37
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/README.md +696 -72
- package/dist/README.md +696 -72
- package/dist/index.js +63 -1
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# dash-react
|
|
2
2
|
|
|
3
|
-
**dash-react** is a React UI component library for building
|
|
3
|
+
**dash-react** (`@trops/dash-react`) is a React UI component library designed for building dashboard applications. It provides a complete set of themed components, layout primitives, and context providers specifically tailored for the Dash Electron framework.
|
|
4
|
+
|
|
5
|
+
**Key Features:**
|
|
6
|
+
|
|
7
|
+
- Comprehensive UI component library (50+ components)
|
|
8
|
+
- Built-in theme system with light/dark variants
|
|
9
|
+
- TailwindCSS-based styling with theme token mapping
|
|
10
|
+
- Context providers for theme and widget data
|
|
11
|
+
- Optimized for Dash Electron but usable in any React app
|
|
12
|
+
- Published as npm package to GitHub Packages
|
|
13
|
+
|
|
14
|
+
**Primary Consumers:** [@trops/dash-core](https://github.com/trops/dash-core) (framework) and [dash-electron](https://github.com/trops/dash-electron) (template)
|
|
15
|
+
|
|
16
|
+
---
|
|
4
17
|
|
|
5
18
|
## What's Included
|
|
6
19
|
|
|
@@ -10,9 +23,86 @@
|
|
|
10
23
|
- **Theming**: Built-in theme tokens and customization via Tailwind CSS
|
|
11
24
|
- **Utilities**: Colors, strings, CSS helpers, and other shared utilities
|
|
12
25
|
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
### Core Systems
|
|
31
|
+
|
|
32
|
+
1. **Component Library** - Pre-built UI components (Panel, Button, Modal, etc.)
|
|
33
|
+
2. **Theme System** - Dynamic theming via ThemeContext with CSS class mapping
|
|
34
|
+
3. **Layout System** - Flexible layout containers for dashboard layouts
|
|
35
|
+
4. **Context Providers** - ThemeContext and WidgetContext for data sharing
|
|
36
|
+
5. **Utility Functions** - Color mapping, CSS helpers, string utilities
|
|
37
|
+
|
|
38
|
+
### Technology Stack
|
|
39
|
+
|
|
40
|
+
- **Framework**: React 18
|
|
41
|
+
- **Styling**: TailwindCSS 3
|
|
42
|
+
- **Build**: Rollup (for library bundling)
|
|
43
|
+
- **Dev Tools**: Storybook 8 (component development/documentation)
|
|
44
|
+
- **Package**: npm (published to GitHub Packages)
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Directory Structure
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
dash-react/
|
|
52
|
+
├── src/
|
|
53
|
+
│ ├── Common/ # UI Components
|
|
54
|
+
│ │ ├── Button/ # Button components
|
|
55
|
+
│ │ ├── Panel.js # Panel components (Panel, Panel2, Panel3)
|
|
56
|
+
│ │ ├── Modal/ # Modal components
|
|
57
|
+
│ │ ├── Menu/ # Menu components
|
|
58
|
+
│ │ ├── Text/ # Typography (Heading, SubHeading, etc.)
|
|
59
|
+
│ │ ├── Input/ # Form inputs
|
|
60
|
+
│ │ ├── Tag/ # Tag/label components
|
|
61
|
+
│ │ ├── Toggle/ # Toggle switches
|
|
62
|
+
│ │ ├── Notification/ # Notification components
|
|
63
|
+
│ │ ├── ErrorBoundary/ # Error handling
|
|
64
|
+
│ │ ├── Draggable/ # Drag-and-drop utilities
|
|
65
|
+
│ │ └── ... # 40+ more components
|
|
66
|
+
│ ├── Layout/ # Layout Components
|
|
67
|
+
│ │ ├── LayoutContainer.js # Flexible row/col container
|
|
68
|
+
│ │ ├── MainLayout.js # Page layout structure
|
|
69
|
+
│ │ └── ... # Layout primitives
|
|
70
|
+
│ ├── Context/ # React Context Providers
|
|
71
|
+
│ │ ├── ThemeContext.js # Theme provider (CRITICAL)
|
|
72
|
+
│ │ └── WidgetContext.js # Widget metadata provider
|
|
73
|
+
│ ├── Utils/ # Utilities
|
|
74
|
+
│ │ ├── colors.js # Theme token mapping (CRITICAL)
|
|
75
|
+
│ │ ├── themeObjects.js # Theme object definitions
|
|
76
|
+
│ │ ├── strings.js # String utilities
|
|
77
|
+
│ │ ├── css.js # CSS utilities
|
|
78
|
+
│ │ └── ... # Other utilities
|
|
79
|
+
│ ├── Mock/ # Mock data for testing
|
|
80
|
+
│ ├── index.js # Main export file
|
|
81
|
+
│ └── tailwind.css # Compiled Tailwind CSS
|
|
82
|
+
├── dist/ # Build output (published)
|
|
83
|
+
├── package/ # npm package output
|
|
84
|
+
├── rollup.config.js # Rollup build config
|
|
85
|
+
├── tailwind.config.js # TailwindCSS config
|
|
86
|
+
├── .storybook/ # Storybook configuration
|
|
87
|
+
└── package.json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Key Files
|
|
91
|
+
|
|
92
|
+
| File | Purpose |
|
|
93
|
+
| ----------------------------- | ------------------------------------------------------------------ |
|
|
94
|
+
| `src/index.js` | Main export file -- all public components, contexts, and utilities |
|
|
95
|
+
| `src/Context/ThemeContext.js` | Theme provider (CRITICAL -- must be imported from this package) |
|
|
96
|
+
| `src/Utils/colors.js` | Theme engine -- maps tokens to CSS classes (CRITICAL) |
|
|
97
|
+
| `src/Utils/themeObjects.js` | Component theme keys used by `getStylesForItem()` |
|
|
98
|
+
| `rollup.config.js` | Build configuration for library bundling |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
13
102
|
## Requirements
|
|
14
103
|
|
|
15
|
-
- Node.js
|
|
104
|
+
- Node.js v18, v20, or v22
|
|
105
|
+
- npm
|
|
16
106
|
|
|
17
107
|
## Installation
|
|
18
108
|
|
|
@@ -20,111 +110,550 @@
|
|
|
20
110
|
npm install
|
|
21
111
|
```
|
|
22
112
|
|
|
23
|
-
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Development Workflow
|
|
116
|
+
|
|
117
|
+
### Setup
|
|
24
118
|
|
|
25
119
|
```bash
|
|
26
|
-
|
|
27
|
-
npm
|
|
28
|
-
|
|
120
|
+
# Install dependencies
|
|
121
|
+
npm install
|
|
122
|
+
|
|
123
|
+
# Build Tailwind CSS
|
|
29
124
|
npm run build:css
|
|
30
|
-
|
|
125
|
+
|
|
126
|
+
# Start Storybook for component development
|
|
127
|
+
npm run storybook
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Development Commands
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Component Development
|
|
134
|
+
npm run storybook # Interactive component playground at localhost:6006
|
|
135
|
+
npm run build-storybook # Build static Storybook
|
|
136
|
+
|
|
137
|
+
# Building
|
|
138
|
+
npm run build:css # Compile Tailwind CSS
|
|
139
|
+
npm run build # Full build (prettify + CSS + rollup)
|
|
140
|
+
npm run roll # Rollup bundling only
|
|
141
|
+
npm run prod # Production build (clean + build + package)
|
|
142
|
+
|
|
143
|
+
# Publishing
|
|
144
|
+
npm run bump # Bump patch version (no git tag)
|
|
145
|
+
npm run bump-tag # Bump patch version with git tag
|
|
146
|
+
npm run pack-local-esm # Create local .tgz package
|
|
147
|
+
|
|
148
|
+
# Utilities
|
|
149
|
+
npm run prettify # Format code with Prettier
|
|
150
|
+
npm run clean-dist # Clean dist directory
|
|
151
|
+
npm run clean-package # Clean package directory
|
|
31
152
|
```
|
|
32
153
|
|
|
33
|
-
|
|
154
|
+
### Development with Storybook
|
|
155
|
+
|
|
156
|
+
Storybook provides an interactive playground for developing and testing components:
|
|
34
157
|
|
|
35
|
-
|
|
158
|
+
```bash
|
|
159
|
+
npm run storybook
|
|
160
|
+
# Opens http://localhost:6006
|
|
161
|
+
```
|
|
36
162
|
|
|
37
|
-
|
|
163
|
+
**Benefits:**
|
|
38
164
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
165
|
+
- Live component preview with hot reload
|
|
166
|
+
- Test components in isolation
|
|
167
|
+
- Document component props and usage
|
|
168
|
+
- Visual regression testing
|
|
43
169
|
|
|
44
|
-
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Build Process
|
|
173
|
+
|
|
174
|
+
**Full production build:**
|
|
45
175
|
|
|
46
176
|
```bash
|
|
47
|
-
npm run
|
|
177
|
+
npm run prod
|
|
48
178
|
```
|
|
49
179
|
|
|
50
|
-
|
|
180
|
+
**What happens:**
|
|
181
|
+
|
|
182
|
+
1. Runs Prettier to format code
|
|
183
|
+
2. Cleans `dist/` and `package/` directories
|
|
184
|
+
3. Runs Rollup to bundle source files
|
|
185
|
+
4. Copies `package.json`, `README.md`, `tailwind.css` to `dist/`
|
|
186
|
+
5. Creates `.tgz` package in `package/` directory
|
|
187
|
+
|
|
188
|
+
**Output:**
|
|
189
|
+
|
|
190
|
+
- `dist/` - Ready-to-publish npm package
|
|
191
|
+
- `package/trops-dash-react.tgz` - Installable package file
|
|
192
|
+
|
|
193
|
+
### Rollup Configuration
|
|
194
|
+
|
|
195
|
+
**File:** [rollup.config.js](rollup.config.js)
|
|
196
|
+
|
|
197
|
+
**Key Settings:**
|
|
198
|
+
|
|
199
|
+
- Input: `src/index.js`
|
|
200
|
+
- Output formats: CommonJS (cjs) and ES Module (es)
|
|
201
|
+
- Plugins:
|
|
202
|
+
- `@rollup/plugin-babel` - Transpile JSX/modern JS
|
|
203
|
+
- `@rollup/plugin-node-resolve` - Resolve node_modules
|
|
204
|
+
- `@rollup/plugin-commonjs` - Convert CommonJS to ESM
|
|
205
|
+
- `rollup-plugin-postcss` - Process CSS
|
|
206
|
+
- `@rollup/plugin-strip` - Remove console.logs in production
|
|
207
|
+
- External dependencies: React, ReactDOM, peer dependencies
|
|
51
208
|
|
|
52
|
-
|
|
209
|
+
**Build Output:**
|
|
210
|
+
|
|
211
|
+
- `dist/index.js` - CommonJS bundle
|
|
212
|
+
- `dist/index.esm.js` - ES Module bundle
|
|
213
|
+
- `dist/tailwind.css` - Compiled CSS
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Publishing Workflow
|
|
218
|
+
|
|
219
|
+
### 1. Make Changes
|
|
220
|
+
|
|
221
|
+
Edit components in `src/Common/`, `src/Layout/`, etc.
|
|
222
|
+
|
|
223
|
+
### 2. Test Changes
|
|
53
224
|
|
|
54
225
|
```bash
|
|
226
|
+
# View components in Storybook
|
|
55
227
|
npm run storybook
|
|
228
|
+
|
|
229
|
+
# Build and test locally
|
|
230
|
+
npm run build
|
|
56
231
|
```
|
|
57
232
|
|
|
58
|
-
|
|
233
|
+
### 3. Version Bump
|
|
59
234
|
|
|
60
235
|
```bash
|
|
61
|
-
|
|
236
|
+
# Patch version
|
|
237
|
+
npm run bump
|
|
238
|
+
|
|
239
|
+
# Or with git tag
|
|
240
|
+
npm run bump-tag
|
|
62
241
|
```
|
|
63
242
|
|
|
64
|
-
###
|
|
243
|
+
### 4. Build Package
|
|
65
244
|
|
|
66
|
-
|
|
245
|
+
```bash
|
|
246
|
+
npm run prod
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 5. Publish
|
|
67
250
|
|
|
68
251
|
```bash
|
|
69
|
-
|
|
70
|
-
npm run prod # Builds and creates package
|
|
252
|
+
# Push to GitHub (triggers auto-publish via GitHub Actions)
|
|
71
253
|
git push origin main
|
|
254
|
+
|
|
255
|
+
# Or manually publish
|
|
256
|
+
cd dist
|
|
257
|
+
npm publish
|
|
72
258
|
```
|
|
73
259
|
|
|
74
|
-
|
|
260
|
+
### 6. Update Consuming Projects
|
|
75
261
|
|
|
76
|
-
|
|
262
|
+
In the consuming project (e.g., dash-electron):
|
|
77
263
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- **`DashPanel`** - Dashboard-specific panel wrapper
|
|
264
|
+
```bash
|
|
265
|
+
cd ~/Development/dash-electron/dash-electron
|
|
266
|
+
# Update the @trops/dash-react version in package.json
|
|
267
|
+
npm install
|
|
268
|
+
```
|
|
84
269
|
|
|
85
|
-
|
|
270
|
+
---
|
|
86
271
|
|
|
87
|
-
|
|
88
|
-
- **`Menu` / `MenuItem`** - Dropdown and list menus
|
|
89
|
-
- **`Toggle`** - Toggle switch input
|
|
90
|
-
- **`Modal`** - Modal overlay dialogs
|
|
91
|
-
- **`SlidePanelOverlay`** - Side panel overlay
|
|
92
|
-
- **`Tag`** - Label/tag component
|
|
272
|
+
## Theme System (CRITICAL)
|
|
93
273
|
|
|
94
|
-
|
|
274
|
+
The theme system is the backbone of dash-react's styling. All components resolve their visual appearance through theme tokens rather than hardcoded CSS classes.
|
|
95
275
|
|
|
96
|
-
|
|
97
|
-
- **`ErrorBoundary` / `ErrorMessage`** - Error handling UI
|
|
98
|
-
- **`Widget`** - Base widget wrapper
|
|
99
|
-
- **`Workspace`** - Widget container with context support
|
|
276
|
+
### ThemeContext
|
|
100
277
|
|
|
101
|
-
|
|
278
|
+
**File:** [src/Context/ThemeContext.js](src/Context/ThemeContext.js)
|
|
102
279
|
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
- **`Draggable`** - Drag-and-drop helpers
|
|
280
|
+
- Exports `ThemeContext` and `ThemeProvider`
|
|
281
|
+
- **MUST** be imported by consuming apps from `@trops/dash-react` (not a local copy)
|
|
282
|
+
- Provides `currentTheme`, `themeVariant`, theme switching functions
|
|
107
283
|
|
|
108
|
-
|
|
284
|
+
### colors.js -- Theme Engine
|
|
109
285
|
|
|
110
|
-
|
|
286
|
+
**File:** [src/Utils/colors.js](src/Utils/colors.js)
|
|
111
287
|
|
|
112
|
-
|
|
113
|
-
|
|
288
|
+
- `getStylesForItem()` - Maps theme tokens to CSS classes
|
|
289
|
+
- `colorMap` - Defines default styles for each component type
|
|
290
|
+
- `prioritizeClasses()` - Merges theme overrides with defaults
|
|
114
291
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
292
|
+
### How It Works
|
|
293
|
+
|
|
294
|
+
1. Component requests styles via `getStylesForItem(themeObjects.PANEL, currentTheme, overrides)`
|
|
295
|
+
2. Function looks up default styles in `colorMap[themeObjects.PANEL]`
|
|
296
|
+
3. Merges with theme overrides from `currentTheme[themeObjects.PANEL]`
|
|
297
|
+
4. Merges with component-level overrides
|
|
298
|
+
5. Returns final CSS class string
|
|
299
|
+
|
|
300
|
+
### Theme Token Example
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
// Default mapping in colorMap
|
|
304
|
+
{
|
|
305
|
+
backgroundColor: "bg-primary-dark",
|
|
306
|
+
textColor: "text-primary-light",
|
|
307
|
+
borderColor: "border-primary-medium"
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Theme provides actual values
|
|
311
|
+
currentTheme = {
|
|
312
|
+
"bg-primary-dark": "bg-gray-800",
|
|
313
|
+
"text-primary-light": "text-gray-100",
|
|
314
|
+
"border-primary-medium": "border-gray-600"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Final output
|
|
318
|
+
"bg-gray-800 text-gray-100 border-gray-600"
|
|
119
319
|
```
|
|
120
320
|
|
|
121
|
-
|
|
321
|
+
### Theme Customization Levels
|
|
322
|
+
|
|
323
|
+
Components support multiple levels of customization, applied in order of priority:
|
|
324
|
+
|
|
325
|
+
1. **Default styles** (defined in `colorMap`)
|
|
326
|
+
2. **Theme overrides** (defined in the theme object)
|
|
327
|
+
3. **Component props** (highest priority -- wins over everything)
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
// 1. Default (colorMap)
|
|
331
|
+
backgroundColor: "bg-primary-dark"
|
|
332
|
+
|
|
333
|
+
// 2. Theme override
|
|
334
|
+
theme[themeObjects.PANEL] = {
|
|
335
|
+
backgroundColor: "bg-custom-dark"
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 3. Component prop (wins)
|
|
339
|
+
<Panel backgroundColor="bg-blue-500" />
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Available Theme Tokens
|
|
122
343
|
|
|
123
344
|
- `bg-*` - Background colors (primary, secondary, danger, etc.)
|
|
124
345
|
- `text-*` - Text colors
|
|
125
346
|
- `border-*` - Border colors
|
|
126
347
|
- Variants: `very-light`, `light`, `medium`, `dark`, `very-dark`
|
|
127
348
|
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Component Patterns
|
|
352
|
+
|
|
353
|
+
### Panel Components
|
|
354
|
+
|
|
355
|
+
**File:** [src/Common/Panel.js](src/Common/Panel.js)
|
|
356
|
+
|
|
357
|
+
Three panel variants with different padding/sizing:
|
|
358
|
+
|
|
359
|
+
| Component | Default Padding | Use Case |
|
|
360
|
+
| --------- | --------------- | ---------------------- |
|
|
361
|
+
| `Panel` | p-6 | Standard cards |
|
|
362
|
+
| `Panel2` | p-4 | Medium-density layouts |
|
|
363
|
+
| `Panel3` | p-2 | Compact/nested layouts |
|
|
364
|
+
|
|
365
|
+
**Sub-components:** `.Header`, `.Body`, `.Footer`
|
|
366
|
+
|
|
367
|
+
```javascript
|
|
368
|
+
import { Panel } from "@trops/dash-react";
|
|
369
|
+
|
|
370
|
+
<Panel border={true} scrollable={true}>
|
|
371
|
+
<Panel.Header border={true}>
|
|
372
|
+
<h1>Header</h1>
|
|
373
|
+
</Panel.Header>
|
|
374
|
+
<Panel.Body>Content here</Panel.Body>
|
|
375
|
+
<Panel.Footer>Footer</Panel.Footer>
|
|
376
|
+
</Panel>;
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### LayoutContainer
|
|
380
|
+
|
|
381
|
+
**File:** [src/Layout/LayoutContainer.js](src/Layout/LayoutContainer.js)
|
|
382
|
+
|
|
383
|
+
Flexible container for building layouts:
|
|
384
|
+
|
|
385
|
+
```javascript
|
|
386
|
+
import { LayoutContainer } from "@trops/dash-react";
|
|
387
|
+
|
|
388
|
+
<LayoutContainer
|
|
389
|
+
direction="col" // "row" or "col"
|
|
390
|
+
width="w-full"
|
|
391
|
+
height="h-full"
|
|
392
|
+
scrollable={true}
|
|
393
|
+
space={true} // Add gap between children
|
|
394
|
+
padding={true}
|
|
395
|
+
grow={true}
|
|
396
|
+
>
|
|
397
|
+
{children}
|
|
398
|
+
</LayoutContainer>;
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Theme-Aware Components
|
|
402
|
+
|
|
403
|
+
All components use `getStylesForItem()` for theme integration:
|
|
404
|
+
|
|
405
|
+
```javascript
|
|
406
|
+
import React, { useContext } from "react";
|
|
407
|
+
import { ThemeContext } from "@dash/Context";
|
|
408
|
+
import { getStylesForItem } from "@dash/Utils";
|
|
409
|
+
import { themeObjects } from "@dash/Utils/themeObjects";
|
|
410
|
+
|
|
411
|
+
function MyComponent(props) {
|
|
412
|
+
const { currentTheme } = useContext(ThemeContext);
|
|
413
|
+
const styles = getStylesForItem(themeObjects.PANEL, currentTheme, {
|
|
414
|
+
backgroundColor: props.backgroundColor,
|
|
415
|
+
textColor: props.textColor,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
return (
|
|
419
|
+
<div className={styles.string}>
|
|
420
|
+
{/* styles.string contains final CSS classes */}
|
|
421
|
+
</div>
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Standard Component Pattern
|
|
427
|
+
|
|
428
|
+
```javascript
|
|
429
|
+
import React, { useContext } from "react";
|
|
430
|
+
import { ThemeContext } from "@dash/Context";
|
|
431
|
+
import { getStylesForItem } from "@dash/Utils";
|
|
432
|
+
import { themeObjects } from "@dash/Utils/themeObjects";
|
|
433
|
+
|
|
434
|
+
export const MyComponent = ({
|
|
435
|
+
// Theme-overridable props
|
|
436
|
+
backgroundColor = null,
|
|
437
|
+
textColor = null,
|
|
438
|
+
borderColor = null,
|
|
439
|
+
// Layout props
|
|
440
|
+
width = "w-full",
|
|
441
|
+
height = "h-full",
|
|
442
|
+
padding = true,
|
|
443
|
+
// Content props
|
|
444
|
+
children,
|
|
445
|
+
className = "",
|
|
446
|
+
// Event handlers
|
|
447
|
+
onClick = null,
|
|
448
|
+
...props
|
|
449
|
+
}) => {
|
|
450
|
+
const { currentTheme } = useContext(ThemeContext);
|
|
451
|
+
|
|
452
|
+
const styles = getStylesForItem(themeObjects.MY_COMPONENT, currentTheme, {
|
|
453
|
+
backgroundColor,
|
|
454
|
+
textColor,
|
|
455
|
+
borderColor,
|
|
456
|
+
width,
|
|
457
|
+
height,
|
|
458
|
+
padding,
|
|
459
|
+
...props,
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
return (
|
|
463
|
+
<div className={`${styles.string} ${className}`} onClick={onClick}>
|
|
464
|
+
{children}
|
|
465
|
+
</div>
|
|
466
|
+
);
|
|
467
|
+
};
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Adding New Components
|
|
471
|
+
|
|
472
|
+
1. **Create component file** in `src/Common/MyComponent.js`
|
|
473
|
+
2. **Add to colorMap** in `src/Utils/colors.js`:
|
|
474
|
+
```javascript
|
|
475
|
+
[themeObjects.MY_COMPONENT]: {
|
|
476
|
+
backgroundColor: "bg-primary-dark",
|
|
477
|
+
textColor: "text-primary-light",
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
3. **Add theme object** in `src/Utils/themeObjects.js`:
|
|
481
|
+
```javascript
|
|
482
|
+
export const themeObjects = {
|
|
483
|
+
// ...
|
|
484
|
+
MY_COMPONENT: "my-component",
|
|
485
|
+
};
|
|
486
|
+
```
|
|
487
|
+
4. **Export from index** in `src/index.js` or `src/Common/index.js`:
|
|
488
|
+
```javascript
|
|
489
|
+
export { MyComponent } from "./MyComponent";
|
|
490
|
+
```
|
|
491
|
+
5. **Create Storybook story** (optional) in `src/Common/MyComponent.stories.js`
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
## Component Reference
|
|
496
|
+
|
|
497
|
+
### Layout Components
|
|
498
|
+
|
|
499
|
+
| Component | Purpose | Key Props |
|
|
500
|
+
| ---------------------- | -------------------------- | ----------------------------------------------------- |
|
|
501
|
+
| `LayoutContainer` | Flexible row/col container | `direction`, `width`, `height`, `scrollable`, `space` |
|
|
502
|
+
| `MainLayout` | Page-level layout | `children` |
|
|
503
|
+
| `MainSection` | Layout section | `children` |
|
|
504
|
+
| `MainContent` | Main content area | `children` |
|
|
505
|
+
| `Container` | Generic container | `padding`, `width`, `height` |
|
|
506
|
+
| `Header` / `SubHeader` | Header sections | `title`, `padding` |
|
|
507
|
+
| `Footer` | Footer section | `children`, `padding` |
|
|
508
|
+
|
|
509
|
+
### Interactive Components
|
|
510
|
+
|
|
511
|
+
| Component | Purpose |
|
|
512
|
+
| ------------------- | --------------------- |
|
|
513
|
+
| `Button` | Primary action button |
|
|
514
|
+
| `ButtonIcon` | Icon-only button |
|
|
515
|
+
| `Menu` / `MenuItem` | Dropdown menus |
|
|
516
|
+
| `Toggle` | Toggle switch |
|
|
517
|
+
| `Modal` | Modal dialogs |
|
|
518
|
+
| `Notification` | Toast notifications |
|
|
519
|
+
| `Tag` | Labels and tags |
|
|
520
|
+
| `SlidePanelOverlay` | Side panel overlay |
|
|
521
|
+
|
|
522
|
+
### Typography Components
|
|
523
|
+
|
|
524
|
+
| Component | Size | Weight |
|
|
525
|
+
| ------------- | -------- | ----------- |
|
|
526
|
+
| `Heading` | text-6xl | font-bold |
|
|
527
|
+
| `Heading2` | text-5xl | font-bold |
|
|
528
|
+
| `Heading3` | text-4xl | font-bold |
|
|
529
|
+
| `SubHeading` | text-3xl | font-medium |
|
|
530
|
+
| `SubHeading2` | text-2xl | font-medium |
|
|
531
|
+
| `SubHeading3` | text-2xl | normal |
|
|
532
|
+
|
|
533
|
+
### Specialized Components
|
|
534
|
+
|
|
535
|
+
| Component | Purpose |
|
|
536
|
+
| --------------------------------- | ------------------------------- |
|
|
537
|
+
| `Widget` | Widget wrapper container |
|
|
538
|
+
| `Workspace` | Workspace container |
|
|
539
|
+
| `ErrorBoundary` | Catch React errors |
|
|
540
|
+
| `ErrorMessage` | Display errors |
|
|
541
|
+
| `CodeEditor` | Monaco code editor |
|
|
542
|
+
| `CodeRenderer` | Syntax-highlighted code display |
|
|
543
|
+
| `DragComponent` / `DropComponent` | Drag-and-drop |
|
|
544
|
+
| `Form` | Form utilities |
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
## Context Providers
|
|
549
|
+
|
|
550
|
+
### ThemeContext
|
|
551
|
+
|
|
552
|
+
**Provider:** [src/Context/ThemeContext.js](src/Context/ThemeContext.js)
|
|
553
|
+
|
|
554
|
+
**Values:**
|
|
555
|
+
|
|
556
|
+
```javascript
|
|
557
|
+
{
|
|
558
|
+
currentTheme: Object, // Current theme object with CSS mappings
|
|
559
|
+
themeKey: String, // Current theme key
|
|
560
|
+
themeVariant: String, // "light" or "dark"
|
|
561
|
+
changeCurrentTheme: Function, // Switch to a different theme
|
|
562
|
+
changeThemeVariant: Function, // Toggle light/dark variant
|
|
563
|
+
themes: Object, // All available themes
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
**Usage:**
|
|
568
|
+
|
|
569
|
+
```javascript
|
|
570
|
+
import { useContext } from "react";
|
|
571
|
+
import { ThemeContext } from "@trops/dash-react";
|
|
572
|
+
|
|
573
|
+
function MyComponent() {
|
|
574
|
+
const { currentTheme, themeVariant, changeThemeVariant } =
|
|
575
|
+
useContext(ThemeContext);
|
|
576
|
+
// Use currentTheme for styling
|
|
577
|
+
}
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### WidgetContext
|
|
581
|
+
|
|
582
|
+
**Provider:** [src/Context/WidgetContext.js](src/Context/WidgetContext.js)
|
|
583
|
+
|
|
584
|
+
**Values:**
|
|
585
|
+
|
|
586
|
+
```javascript
|
|
587
|
+
{
|
|
588
|
+
uuid: String, // Widget instance ID
|
|
589
|
+
widgetData: Object, // Widget configuration data
|
|
590
|
+
selectedProviders: Array, // Selected provider IDs
|
|
591
|
+
// ... other widget metadata
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**Usage:**
|
|
596
|
+
|
|
597
|
+
```javascript
|
|
598
|
+
import { useContext } from "react";
|
|
599
|
+
import { WidgetContext } from "@trops/dash-react";
|
|
600
|
+
|
|
601
|
+
function MyWidget() {
|
|
602
|
+
const { uuid, widgetData } = useContext(WidgetContext);
|
|
603
|
+
// Access widget instance data
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Utilities Reference
|
|
610
|
+
|
|
611
|
+
### colors.js
|
|
612
|
+
|
|
613
|
+
**Key Functions:**
|
|
614
|
+
|
|
615
|
+
| Function | Purpose |
|
|
616
|
+
| -------------------------------------------------- | ---------------------------------------- |
|
|
617
|
+
| `getStylesForItem(itemName, theme, overrides, id)` | Generate CSS classes for component |
|
|
618
|
+
| `getCSSStyleForClassname(className)` | Convert CSS class to inline style object |
|
|
619
|
+
| `getClassForObjectType(type)` | Get CSS class for object type |
|
|
620
|
+
| `getStyleName(name)` | Normalize style name |
|
|
621
|
+
|
|
622
|
+
**Key Constants:**
|
|
623
|
+
|
|
624
|
+
| Constant | Purpose |
|
|
625
|
+
| --------------- | ------------------------ |
|
|
626
|
+
| `colorMap` | Default component styles |
|
|
627
|
+
| `colorNames` | Available color names |
|
|
628
|
+
| `shades` | Color shade variants |
|
|
629
|
+
| `themeVariants` | "light" / "dark" |
|
|
630
|
+
| `objectTypes` | Component type names |
|
|
631
|
+
|
|
632
|
+
### strings.js
|
|
633
|
+
|
|
634
|
+
String manipulation utilities for text processing.
|
|
635
|
+
|
|
636
|
+
### css.js
|
|
637
|
+
|
|
638
|
+
CSS utility functions for class manipulation.
|
|
639
|
+
|
|
640
|
+
### themeObjects.js
|
|
641
|
+
|
|
642
|
+
Defines component theme keys used throughout the library:
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
export const themeObjects = {
|
|
646
|
+
PANEL: "panel",
|
|
647
|
+
PANEL_HEADER: "panel-header",
|
|
648
|
+
PANEL_FOOTER: "panel-footer",
|
|
649
|
+
HEADING: "heading",
|
|
650
|
+
BUTTON: "button",
|
|
651
|
+
// ... 50+ more
|
|
652
|
+
};
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
128
657
|
## Styling Components
|
|
129
658
|
|
|
130
659
|
Override component styles with common props:
|
|
@@ -137,28 +666,123 @@ Override component styles with common props:
|
|
|
137
666
|
/>
|
|
138
667
|
```
|
|
139
668
|
|
|
140
|
-
|
|
669
|
+
---
|
|
141
670
|
|
|
142
|
-
|
|
671
|
+
## Testing Integration with Dash
|
|
143
672
|
|
|
144
|
-
|
|
145
|
-
// Access theme tokens and colors
|
|
146
|
-
import { useTheme } from "@dash/Context";
|
|
147
|
-
const { currentTheme } = useTheme();
|
|
673
|
+
### Local Testing Workflow
|
|
148
674
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
675
|
+
**Method 1: Local package install (recommended)**
|
|
676
|
+
|
|
677
|
+
```bash
|
|
678
|
+
# In dash-react
|
|
679
|
+
npm run prod
|
|
680
|
+
|
|
681
|
+
# In dash-electron
|
|
682
|
+
cd ~/Development/dash-electron/dash-electron
|
|
683
|
+
npm install ../dash-react/package/trops-dash-react.tgz
|
|
684
|
+
npm run dev
|
|
152
685
|
```
|
|
153
686
|
|
|
154
|
-
|
|
687
|
+
**Method 2: npm link** (not recommended -- can cause dual context issues)
|
|
688
|
+
|
|
689
|
+
```bash
|
|
690
|
+
# In dash-react
|
|
691
|
+
cd dist
|
|
692
|
+
npm link
|
|
693
|
+
|
|
694
|
+
# In dash-electron
|
|
695
|
+
npm link @trops/dash-react
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
### Verifying Changes
|
|
699
|
+
|
|
700
|
+
After rebuilding dash-react:
|
|
701
|
+
|
|
702
|
+
1. Check component renders correctly in Storybook
|
|
703
|
+
2. Install updated package in dash-electron
|
|
704
|
+
3. Test in dash Electron app
|
|
705
|
+
4. Verify theme system works
|
|
706
|
+
5. Check console for errors
|
|
707
|
+
|
|
708
|
+
---
|
|
709
|
+
|
|
710
|
+
## Troubleshooting
|
|
711
|
+
|
|
712
|
+
### Theme Issues
|
|
713
|
+
|
|
714
|
+
**Problem:** Components not receiving theme
|
|
715
|
+
|
|
716
|
+
**Solution:** Ensure consuming app imports ThemeContext from dash-react:
|
|
717
|
+
|
|
718
|
+
```javascript
|
|
719
|
+
// CORRECT
|
|
720
|
+
import { ThemeContext } from "@trops/dash-react";
|
|
721
|
+
|
|
722
|
+
// WRONG - creates separate context instance
|
|
723
|
+
import { ThemeContext } from "./Context/ThemeContext";
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Build Issues
|
|
727
|
+
|
|
728
|
+
**Problem:** Rollup build fails
|
|
729
|
+
|
|
730
|
+
**Solutions:**
|
|
155
731
|
|
|
156
|
-
|
|
732
|
+
- Check for syntax errors in source files
|
|
733
|
+
- Ensure all imports are valid
|
|
734
|
+
- Run `npm run prettify` to fix formatting
|
|
735
|
+
- Check rollup.config.js for plugin errors
|
|
736
|
+
|
|
737
|
+
**Problem:** CSS not updating
|
|
738
|
+
|
|
739
|
+
**Solution:**
|
|
740
|
+
|
|
741
|
+
```bash
|
|
742
|
+
npm run build:css
|
|
743
|
+
npm run build
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### Storybook Issues
|
|
747
|
+
|
|
748
|
+
**Problem:** Components not showing in Storybook
|
|
749
|
+
|
|
750
|
+
**Solutions:**
|
|
751
|
+
|
|
752
|
+
- Ensure `.stories.js` files are in component directories
|
|
753
|
+
- Restart Storybook: `npm run storybook`
|
|
754
|
+
- Check browser console for errors
|
|
755
|
+
|
|
756
|
+
### Package Installation Issues
|
|
757
|
+
|
|
758
|
+
**Problem:** Can't install @trops/dash-react in consuming app
|
|
759
|
+
|
|
760
|
+
**Solutions:**
|
|
761
|
+
|
|
762
|
+
- Ensure `.npmrc` is configured with GitHub PAT
|
|
763
|
+
- Check package is published to GitHub Packages
|
|
764
|
+
- Verify version number in `package.json`
|
|
765
|
+
|
|
766
|
+
---
|
|
767
|
+
|
|
768
|
+
## Related Projects
|
|
769
|
+
|
|
770
|
+
| Repo | Location | Relationship |
|
|
771
|
+
| -------------------- | ------------------------------------------- | ------------------------------------------------------------ |
|
|
772
|
+
| **@trops/dash-core** | `~/Development/dash-core/dash-core` | Core dashboard framework -- primary consumer of this library |
|
|
773
|
+
| **dash-electron** | `~/Development/dash-electron/dash-electron` | Electron app template built on dash-core + dash-react |
|
|
774
|
+
|
|
775
|
+
**Critical:** `@trops/dash-core` MUST import `ThemeContext` from `@trops/dash-react` to avoid dual context issues.
|
|
776
|
+
|
|
777
|
+
---
|
|
778
|
+
|
|
779
|
+
## Documentation
|
|
157
780
|
|
|
158
|
-
|
|
781
|
+
- [Documentation Index](./docs/INDEX.md) - Component library documentation
|
|
782
|
+
- [Product Requirements](./docs/requirements/README.md) - PRDs for component API design and changes
|
|
783
|
+
- [Storybook](http://localhost:6006) - Interactive component playground (run `npm run storybook`)
|
|
159
784
|
|
|
160
|
-
|
|
161
|
-
- [Dash Documentation](https://github.com/trops/dash/tree/main/docs) - Widget development, provider system, and application architecture
|
|
785
|
+
---
|
|
162
786
|
|
|
163
787
|
## Support
|
|
164
788
|
|