Skip to content

Commit 474aed3

Browse files
authored
add labels to mermaidwrapper (#93)
1 parent cee6f11 commit 474aed3

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@astrojs/starlight": "^0.34.4",
13-
"@interledger/docs-design-system": "^0.8.0",
13+
"@interledger/docs-design-system": "^0.9.0",
1414
"astro": "^5.11.0",
1515
"rehype-mathjax": "^7.1.0",
1616
"remark-math": "^6.0.0",

src/content/docs/shared/mermaidwrapper.mdx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ This component allows users to open a Mermaid diagram in a new tab, as well as d
1010
We assume that you have already imported the [Mermaid component](/shared/mermaid), otherwise, what on earth are you wrapping with this?
1111
:::
1212

13-
The component adds a link to "View full image" with an external link indicator under the bottom-right corner of the image, as well as a link to "Download diagram", which will download the diagram as an SVG file when clicked. Do use the `diagramName` prop to specify the name of the diagram file that will be saved to the user's local machine (otherwise it will default to `diagram.svg`).
13+
The component adds a link to "View full image" with an external link indicator under the bottom-right corner of the image, as well as a link to "Download diagram", which will download the diagram as an SVG file when clicked. It takes in a `viewLabel`, `downloadLabel` and `diagramName` properties.
14+
15+
The `viewLabel` and `downloadLabel` props allow you to customize the text of the buttons, the use case being for pages that are not in English. If you don't provide these props, they will default to "View full diagram" and "Download diagram", respectively.
16+
17+
Do use the `diagramName` prop to specify the name of the diagram file that will be saved to the user's local machine (otherwise it will default to `diagram.svg`).
1418

1519
To use the component, the page must be in `.mdx` format. Change the format from `.md` to `.mdx` if necessary. All your existing markdown will still be supported without issue.
1620

@@ -63,6 +67,24 @@ By default, there will be a border around the diagram. To remove the border, pas
6367
</MermaidWrapper>
6468
```
6569

70+
To translate the labels for the diagram's available actions, pass in the `viewLabel` and `downloadLabel` attributes.
71+
72+
{/* prettier-ignore */}
73+
````jsx
74+
<MermaidWrapper diagramName="alice-to-john" viewLabel="查看图表" downloadLabel="下载">
75+
76+
{/* prettier-ignore */}
77+
<Mermaid
78+
graph={`sequenceDiagram
79+
小丽->>阿韩: 阿韩, 近来好吗?
80+
阿韩-->>小丽: 好得很!
81+
小丽-)阿韩: 行,待会儿见!
82+
`}
83+
/>
84+
85+
</MermaidWrapper>
86+
````
87+
6688
If you're using some sort of format-on-save functionality in your code editor, like Prettier, it might mess up your formatting. Ask Prettier, for example, to ignore your Mermaid block just in case. Refer to the example code above.
6789

6890
```
@@ -109,3 +131,20 @@ When `hasBorder: false` is used:
109131
/>
110132

111133
</MermaidWrapper>
134+
135+
### Translated labels
136+
137+
When `viewLabel` and `downloadLabel` are used:
138+
139+
<MermaidWrapper diagramName="alice-to-john" viewLabel="查看图表" downloadLabel="下载">
140+
141+
{/* prettier-ignore */}
142+
<Mermaid
143+
graph={`sequenceDiagram
144+
小丽->>阿韩: 阿韩, 近来好吗?
145+
阿韩-->>小丽: 好得很!
146+
小丽-)阿韩: 行,待会儿见!
147+
`}
148+
/>
149+
150+
</MermaidWrapper>

0 commit comments

Comments
 (0)