Skip to content

Commit 123ab83

Browse files
committed
feat(dory): fix up mermaid colors
1 parent eb2058e commit 123ab83

File tree

8 files changed

+218
-38
lines changed

8 files changed

+218
-38
lines changed

docs/features.mdx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ description: 'Overview of available components and features'
3232
```
3333
# Heading 6
3434

35+
<br />
36+
37+
## Lists Examples
38+
39+
```mdx
40+
- List item 1
41+
- List item 2
42+
- List item 3
43+
```
44+
45+
- List item 1
46+
- List item 2
47+
- List item 3
48+
49+
```mdx
50+
1. List item 1
51+
2. List item 2
52+
3. List item 3
53+
```
54+
55+
1. List item 1
56+
2. List item 2
57+
3. List item 3
58+
59+
60+
3561
<br />
3662

3763
### Images
@@ -79,6 +105,89 @@ function example() {
79105

80106
## Interactive Components
81107

108+
### Mermaid
109+
110+
```mdx
111+
mermaid
112+
graph TD
113+
114+
%% Main Start
115+
Start([Start Process]) --> Validate[Validate Input]
116+
117+
%% Decision Point
118+
Validate -->|Valid| ProcessData{Is Data Clean?}
119+
Validate -->|Invalid| Error[Show Error Message]
120+
121+
%% Clean Data Branch
122+
ProcessData -->|Yes| Clean[Clean Data]
123+
Clean --> Analyze[Analyze Data]
124+
125+
%% Dirty Data Branch
126+
ProcessData -->|No| Notify[Notify User]
127+
Notify --> Wait[Wait for Input]
128+
Wait --> Validate
129+
130+
%% Parallel Branches After Analysis
131+
Analyze --> Split1 & Split2
132+
133+
subgraph Parallel Tasks
134+
Split1[Generate Report] --> Merge
135+
Split2[Update Dashboard] --> Merge
136+
end
137+
138+
Merge --> Decision2{Is More Input Needed?}
139+
Decision2 -->|Yes| WaitMore[Wait for More Input]
140+
WaitMore --> Validate
141+
Decision2 -->|No| End([End Process])
142+
143+
%% Style and Class Definitions
144+
classDef decision fill:#f9f,stroke:#333,stroke-width:2px;
145+
class ProcessData,Decision2 decision;
146+
147+
```
148+
149+
<strong>
150+
<p>Note: Mermaid should be inside a code block with type "mermaid"</p>
151+
</strong>
152+
153+
```mermaid
154+
graph TD
155+
156+
%% Main Start
157+
Start([Start Process]) --> Validate[Validate Input]
158+
159+
%% Decision Point
160+
Validate -->|Valid| ProcessData{Is Data Clean?}
161+
Validate -->|Invalid| Error[Show Error Message]
162+
163+
%% Clean Data Branch
164+
ProcessData -->|Yes| Clean[Clean Data]
165+
Clean --> Analyze[Analyze Data]
166+
167+
%% Dirty Data Branch
168+
ProcessData -->|No| Notify[Notify User]
169+
Notify --> Wait[Wait for Input]
170+
Wait --> Validate
171+
172+
%% Parallel Branches After Analysis
173+
Analyze --> Split1 & Split2
174+
175+
subgraph Parallel Tasks
176+
Split1[Generate Report] --> Merge
177+
Split2[Update Dashboard] --> Merge
178+
end
179+
180+
Merge --> Decision2{Is More Input Needed?}
181+
Decision2 -->|Yes| WaitMore[Wait for More Input]
182+
WaitMore --> Validate
183+
Decision2 -->|No| End([End Process])
184+
185+
%% Style and Class Definitions
186+
classDef decision fill:#f9f,stroke:#333,stroke-width:2px;
187+
class ProcessData,Decision2 decision;
188+
189+
```
190+
82191
### Accordion
83192

84193
```mdx
@@ -203,6 +312,20 @@ function example() {
203312
This is an expandable section that can be toggled.
204313
</Expandable>
205314

315+
### Source
316+
317+
```mdx
318+
<Source url="https://github.com/clidey/dory" paths={[
319+
{ path: "src/mdx/source.tsx", range: "1-46" },
320+
{ path: "docs/features.mdx", range: "318-322" },
321+
]} />
322+
```
323+
324+
<Source url="https://github.com/clidey/dory" paths={[
325+
{ path: "src/mdx/source.tsx", range: "1-46" },
326+
{ path: "docs/features.mdx", range: "318-322" },
327+
]} />
328+
206329
<br />
207330
<br />
208331
<br />

src/components/routes.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export default function Routes() {
7272
}
7373
}, [routes, pathname]);
7474

75+
useEffect(() => {
76+
window.scrollTo({ top: 0, behavior: 'smooth' });
77+
}, [pathname]);
78+
79+
7580
if (loading) return <div className="h-[25vh] flex grow"><Loading /></div>;
7681

7782
return (

src/mdx/list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export const UnorderedList = (props: JSX.IntrinsicElements['ul']) => <ul classNa
44

55
export const OrderedList = (props: JSX.IntrinsicElements['ol']) => <ol className="list-decimal list-inside" {...props} />;
66

7-
export const ListItem = (props: JSX.IntrinsicElements['li']) => <li className="ml-4 mb-1" {...props} />;
7+
export const ListItem = (props: JSX.IntrinsicElements['li']) => <li className="ml-4 mt-2" {...props} />;

src/mdx/mdx.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export { Steps, Step } from './step';
1414
export { Table as table, Th as th, Td as td } from './table';
1515
export { UnorderedList as ul, OrderedList as ol, ListItem as li } from './list';
1616
export { APIPlayground } from './api-playground';
17+
export { Source } from './source';
1718

1819
export const wrapper = ({ children }: { children: preact.ComponentChildren }) => {
1920
return <div className="flex flex-col w-full">{children}</div>;

src/mdx/mermaid.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ export function MermaidRenderer({ content }: { content: string }) {
3434
rankSpacing: 80, // vertical spacing between layers
3535
padding: 20,
3636
useMaxWidth: true,
37-
}
37+
},
3838
})
3939

4040
if (mermaidRef.current) {
4141
mermaidRef.current.innerHTML = ''
4242
}
4343

44-
const { svg } = await mermaid.render(diagramId, content)
44+
const contentWithoutStyle = content.replace(/classDef.*\n.*class.*\n/, '')
45+
46+
const { svg } = await mermaid.render(diagramId, contentWithoutStyle)
4547

4648
if (mounted && mermaidRef.current) {
4749
mermaidRef.current.innerHTML = svg

src/mdx/source.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
type PathRange = {
2+
path: string;
3+
range: string;
4+
};
5+
6+
type SourceProps = {
7+
url: string;
8+
paths: PathRange[];
9+
};
10+
11+
export const Source = ({ url, paths }: SourceProps) => {
12+
const createSourceUrl = (path: string, range: string) => {
13+
const [start, end] = range.split('-');
14+
15+
if (url.includes('github.com')) {
16+
return `${url}/blob/main/${path}#L${start}${end ? `-L${end}` : ''}`;
17+
} else if (url.includes('bitbucket.org')) {
18+
return `${url}/src/main/${path}#lines-${start}${end ? `:${end}` : ''}`;
19+
} else if (url.includes('gitlab.com')) {
20+
return `${url}/-/blob/main/${path}#L${range.replace('-', '-')}`;
21+
}
22+
23+
return url;
24+
};
25+
26+
return (
27+
<div>
28+
<p className="text-sm text-slate-900 dark:text-white">Sources:</p>
29+
<ul className="list-none pl-0 flex flex-wrap gap-2 mt-2">
30+
{paths.map(({ path, range }) => (
31+
<li key={path + range}>
32+
<a
33+
href={createSourceUrl(path, range)}
34+
target="_blank"
35+
rel="noopener noreferrer"
36+
className="rounded px-3 py-1 font-mono text-sm text-slate-700 dark:text-slate-400 hover:opacity-80 transition-colors border border-slate-200 dark:border-slate-700"
37+
>
38+
{path}
39+
<span className="ml-2 opacity-70">{range}</span>
40+
</a>
41+
</li>
42+
))}
43+
</ul>
44+
</div>
45+
);
46+
};

src/mdx/text.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export const h1 = function H1(props: preact.JSX.HTMLAttributes<HTMLHeadingElemen
77
}
88

99
export const h2 = function H2(props: preact.JSX.HTMLAttributes<HTMLHeadingElement>) {
10-
return <h2 className="text-3xl font-bold mb-3 mt-8" {...props} />
10+
return <h2 className="text-3xl font-bold mb-3 mt-10" {...props} />
1111
}
1212

1313
export const h3 = function H3(props: preact.JSX.HTMLAttributes<HTMLHeadingElement>) {
14-
return <h3 className="text-2xl font-bold mb-2" {...props} />
14+
return <h3 className="text-2xl font-bold mb-2 mt-8" {...props} />
1515
}
1616

1717
export const h4 = function H4(props: preact.JSX.HTMLAttributes<HTMLHeadingElement>) {
18-
return <h4 className="text-xl font-bold mb-2" {...props} />
18+
return <h4 className="text-xl font-bold mb-2 mt-6" {...props} />
1919
}
2020

2121
export const h5 = function H5(props: preact.JSX.HTMLAttributes<HTMLHeadingElement>) {
@@ -27,7 +27,7 @@ export const h6 = function H6(props: preact.JSX.HTMLAttributes<HTMLHeadingElemen
2727
}
2828

2929
export const p = function P(props: preact.JSX.HTMLAttributes<HTMLParagraphElement>) {
30-
return <p className="mb-2" {...props} />
30+
return <p className="mb-2 inline-block" {...props} />
3131
}
3232

3333
export function Row({ children, cols = 1 }: { children: preact.ComponentChildren, cols?: number }) {

0 commit comments

Comments
 (0)