@amritanshu3011/mdx-renderer 1.0.3 → 1.0.4
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 +142 -0
- package/package.json +1 -1
- package/README.md +0 -102
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
```markdown
|
|
2
|
+
# MDX Renderer
|
|
3
|
+
|
|
4
|
+
A robust, theme-able visualization and MDX rendering system for React applications. It supports both direct MDX file rendering and programmatic visualization injection (Intent-based UI).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @amritanshu3011/mdx-renderer
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 1. Intent-Based Usage (Programmatic)
|
|
14
|
+
|
|
15
|
+
Use this pattern when you want to render specific components based on backend data (e.g., from an LLM or API). This effectively turns JSON responses into React UI.
|
|
16
|
+
|
|
17
|
+
### Step 1: Wrap your App
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { VisualizationProvider } from '@amritanshu3011/mdx-renderer';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<VisualizationProvider>
|
|
25
|
+
<YourAppContent />
|
|
26
|
+
</VisualizationProvider>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Step 2: Inject & Render
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useVisualizations, visualizationRegistry } from '@amritanshu3011/mdx-renderer';
|
|
36
|
+
|
|
37
|
+
function ResultsPage() {
|
|
38
|
+
const { visualizations, addVisualization } = useVisualizations();
|
|
39
|
+
|
|
40
|
+
// Simulate receiving data from a backend
|
|
41
|
+
const handleLoadData = () => {
|
|
42
|
+
addVisualization({
|
|
43
|
+
type: 'pros_cons', // Key must match the registry (see table below)
|
|
44
|
+
data: {
|
|
45
|
+
title: 'React vs Angular',
|
|
46
|
+
pros: ['Virtual DOM', 'Huge Ecosystem'],
|
|
47
|
+
cons: ['Steep Learning Curve']
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div>
|
|
54
|
+
<button onClick={handleLoadData}>Load Analysis</button>
|
|
55
|
+
|
|
56
|
+
{/* Render the Dynamic Components */}
|
|
57
|
+
<div className="results-container">
|
|
58
|
+
{visualizations.map((viz, index) => {
|
|
59
|
+
const Component = visualizationRegistry[viz.type];
|
|
60
|
+
|
|
61
|
+
if (!Component) return null;
|
|
62
|
+
|
|
63
|
+
return <Component key={index} {...viz.data} />;
|
|
64
|
+
})}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 2. Standard MDX Usage
|
|
73
|
+
|
|
74
|
+
Use this pattern if you are importing and rendering `.mdx` files directly.
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { MDXRenderer, ThemeProvider } from '@amritanshu3011/mdx-renderer';
|
|
78
|
+
import Content from './document.mdx';
|
|
79
|
+
|
|
80
|
+
function DocumentPage() {
|
|
81
|
+
return (
|
|
82
|
+
<ThemeProvider>
|
|
83
|
+
<MDXRenderer>
|
|
84
|
+
<Content />
|
|
85
|
+
</MDXRenderer>
|
|
86
|
+
</ThemeProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Component Registry & Data Structures
|
|
93
|
+
|
|
94
|
+
When using the intent-based approach, your backend must return the correct `type` string.
|
|
95
|
+
|
|
96
|
+
### Smart Analysis Blocks
|
|
97
|
+
|
|
98
|
+
| Component | Type Key | Required Data Structure |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| **Pros & Cons** | `pros_cons` | `{ title: string, pros: string[], cons: string[] }` |
|
|
101
|
+
| **Comparison** | `comparison` | `{ title: string, items: [{ name, price, features[] }] }` |
|
|
102
|
+
| **Flow Chart** | `flow` | `{ title: string, steps: [{ id, label, status }] }` |
|
|
103
|
+
| **Concept Tree** | `concept_tree` | `{ title: string, data: { name, children: [] } }` |
|
|
104
|
+
| **Sunburst** | `sunburst` | `{ title: string, data: { name, children: [{ name, value }] } }` |
|
|
105
|
+
| **Composite** | `interactive_composite` | `{ title: string, selector: object, views: object }` |
|
|
106
|
+
|
|
107
|
+
### Data Visualizations
|
|
108
|
+
|
|
109
|
+
| Component | Type Key | Required Data Structure |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| **Line Chart** | `line_chart` | `{ title: string, xAxisKey: string, data: object[], series: [{ key, color }] }` |
|
|
112
|
+
|
|
113
|
+
## Theme Customization
|
|
114
|
+
|
|
115
|
+
You can inject a custom theme to match your brand colors.
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { ThemeProvider } from '@amritanshu3011/mdx-renderer';
|
|
119
|
+
|
|
120
|
+
const myTheme = {
|
|
121
|
+
colors: {
|
|
122
|
+
primary: '#007bff',
|
|
123
|
+
secondary: '#6c757d',
|
|
124
|
+
background: '#ffffff',
|
|
125
|
+
text: '#333333'
|
|
126
|
+
},
|
|
127
|
+
spacing: {
|
|
128
|
+
small: '8px',
|
|
129
|
+
medium: '16px',
|
|
130
|
+
large: '24px'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
<ThemeProvider initialTheme={myTheme}>
|
|
135
|
+
<App />
|
|
136
|
+
</ThemeProvider>
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```
|
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# MDX Renderer
|
|
2
|
-
|
|
3
|
-
Reusable MDX rendering system with theme support and rich component library.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
```bash
|
|
7
|
-
# If published as package
|
|
8
|
-
npm install @yourorg/mdx-renderer
|
|
9
|
-
|
|
10
|
-
# If local
|
|
11
|
-
import { MDXRenderer, ThemeProvider } from './mdx-renderer';
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Quick Start
|
|
15
|
-
```tsx
|
|
16
|
-
import { MDXRenderer, ThemeProvider } from './mdx-renderer';
|
|
17
|
-
import Content from './content.mdx';
|
|
18
|
-
|
|
19
|
-
function App() {
|
|
20
|
-
return (
|
|
21
|
-
<ThemeProvider>
|
|
22
|
-
<MDXRenderer>
|
|
23
|
-
<Content />
|
|
24
|
-
</MDXRenderer>
|
|
25
|
-
</ThemeProvider>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Features
|
|
31
|
-
|
|
32
|
-
✅ **Theme Support** - Light/dark themes with fallbacks
|
|
33
|
-
✅ **Classless CSS** - Works without any class names
|
|
34
|
-
✅ **Default Props** - All widgets work with sensible defaults
|
|
35
|
-
✅ **Rich Components** - Text, data, interactive, and composite widgets
|
|
36
|
-
✅ **Zero Config** - Works out of the box
|
|
37
|
-
|
|
38
|
-
## Components
|
|
39
|
-
|
|
40
|
-
### Text Widgets
|
|
41
|
-
- `Heading` - Themed headings
|
|
42
|
-
- `Paragraph` - Themed paragraphs
|
|
43
|
-
- `Blockquote` - Quote blocks with optional author
|
|
44
|
-
- `List` - Ordered/unordered lists
|
|
45
|
-
|
|
46
|
-
### Data Widgets
|
|
47
|
-
- `SimpleChart` - JSON display
|
|
48
|
-
- `LineChart` - Line graphs (Recharts)
|
|
49
|
-
- `BarChart` - Bar graphs (Recharts)
|
|
50
|
-
|
|
51
|
-
### Interactive Widgets
|
|
52
|
-
- `Accordion` - Collapsible content
|
|
53
|
-
- `Tabs` - Tabbed interface
|
|
54
|
-
|
|
55
|
-
### Composite Widgets
|
|
56
|
-
- `Dashboard` - Grid layout for metrics
|
|
57
|
-
- `DataExplorer` - Searchable data viewer
|
|
58
|
-
|
|
59
|
-
## Usage in MDX
|
|
60
|
-
```mdx
|
|
61
|
-
import { Accordion, Tabs, Dashboard, DataExplorer } from './mdx-renderer';
|
|
62
|
-
|
|
63
|
-
# My Document
|
|
64
|
-
|
|
65
|
-
<Accordion title="Click to expand">
|
|
66
|
-
Hidden content here
|
|
67
|
-
</Accordion>
|
|
68
|
-
|
|
69
|
-
<Tabs tabs={[
|
|
70
|
-
{ label: 'Tab 1', content: <div>Content 1</div> },
|
|
71
|
-
{ label: 'Tab 2', content: <div>Content 2</div> }
|
|
72
|
-
]} />
|
|
73
|
-
|
|
74
|
-
<Dashboard title="Metrics" columns={3}>
|
|
75
|
-
<Card>Metric 1</Card>
|
|
76
|
-
<Card>Metric 2</Card>
|
|
77
|
-
<Card>Metric 3</Card>
|
|
78
|
-
</Dashboard>
|
|
79
|
-
|
|
80
|
-
<DataExplorer data={myData} searchable />
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Theme Customization
|
|
84
|
-
```tsx
|
|
85
|
-
const customTheme = {
|
|
86
|
-
colors: { primary: '#ff0000', ... },
|
|
87
|
-
spacing: { small: '4px', ... },
|
|
88
|
-
typography: { h1Size: '48px', ... }
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
<ThemeProvider initialTheme={customTheme}>
|
|
92
|
-
<MDXRenderer>
|
|
93
|
-
<Content />
|
|
94
|
-
</MDXRenderer>
|
|
95
|
-
</ThemeProvider>
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Dependencies
|
|
99
|
-
|
|
100
|
-
- `react` >= 18.0.0
|
|
101
|
-
- `@mdx-js/react` >= 2.0.0
|
|
102
|
-
- `recharts` >= 2.0.0 (for charts)
|