Skip to content

Commit 2fbbc18

Browse files
authored
Merge pull request #739 from zihanKuang/update-embedded-docs
feat(docs): Refactor embed design shortcode and update documentation
2 parents 1d11a2e + d65153a commit 2fbbc18

File tree

3 files changed

+113
-46
lines changed

3 files changed

+113
-46
lines changed
-1.27 MB
Loading

content/en/kanvas/designer/embedding-designs/index.md

Lines changed: 104 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Meshery Design Embedding enables you to export a design in a format that can be
1515

1616
To embed your Kanvas design, follow these steps:
1717

18-
1. **Access Embed Option**: Within the Kanvas Designer, select the design you wish to embed in the design drawer. Click on the export icon in the menu for the selected design. The export modal will appear, click on the "Embed" option.
18+
1. **Access Embed Option**: Within the [Kanvas Designer](https://kanvas.new/), select the design you wish to embed. Click on the export icon in the menu for the selected design. The export modal will appear, click on the "Embed" option.
1919

2020
![Embed Designs from Kanvas](./embed-designs.gif)
2121

@@ -34,31 +34,39 @@ To embed your Kanvas design, follow these steps:
3434

3535
### Customization
3636

37-
You can customize the styles for the embedded design by targeting CSS classes exposed or by adding inline styles. The following class can be overridden:
37+
You can customize the styles for the embedded design in two ways: globally via CSS classes, or for a single instance via an inline style parameter.
3838

39-
- `embed-design-container`: for the embedding container
40-
- `cy-container`: for the canvas
39+
#### Global Styling (via CSS Classes)
4140

42-
If you have multiple embeddings on a page, you can target them all using the classes or specific ones using the div's ID in the shortcode.
41+
For advanced global styling, you can override the default CSS rules in your site's stylesheet. This will affect all embedded designs on your site. The main classes are:
4342

44-
Here is a customization example:
43+
- `.meshery-embed-container`: The main container for the embedded design. You can target its `.full` or `.half` variants for specific sizing adjustments.
44+
- `.cy-container`: The canvas element within the container where the design itself is rendered.
45+
46+
Here is an example of how you could override these classes:
4547

4648
```html
4749
<style>
48-
.embed-design-container {
49-
width: 100%;
50-
border-radius: 1rem;
51-
margin: 1rem;
52-
overflow: hidden;
53-
margin-inline: auto;
54-
height: 35rem;
55-
}
56-
.embed-canvas-container {
57-
background-color: gray;
50+
/* Make all embed containers have a different border and background */
51+
.meshery-embed-container {
52+
border: 2px solid #00B39F;
53+
background-color: #f5f5f5;
5854
}
5955
</style>
6056
```
6157

58+
#### Instance-specific Styling (via `style` Parameter)
59+
60+
For styling a single instance, the recommended method is to use the `style` parameter directly in the shortcode. This provides maximum control and will override any default styles or global CSS.
61+
62+
```html
63+
{{</* meshery-design-embed
64+
src="..."
65+
id="..."
66+
style="width: 60%; height: 28rem; border-radius: 1.5rem;"
67+
*/>}}
68+
```
69+
6270
## Embedding in React Projects
6371

6472
1. **Install the Package**: To integrate the Meshery Design into your React project, start by installing the package via npm:
@@ -70,11 +78,9 @@ Here is a customization example:
7078
```jsx
7179
import MesheryDesignEmbed from '@layer5/meshery-design-embed'
7280

73-
7481
function Design() {
7582
return (
7683
<>
77-
7884
<div>
7985
<MesheryDesignEmbed
8086
embedScriptSrc="embedded-design-embed1.js" // path to the embed script
@@ -89,60 +95,116 @@ function Design() {
8995
Make sure the `embedScriptSrc` attribute in the component points to the location of the downloaded embedding script on your react filesystem.
9096
Usually the script is located "static" folder
9197

92-
93-
### Embedding with Hugo
98+
## Embedding with Hugo
9499

95100
To prepare your Hugo site to support design embedding, perform the one-time task of adding the following shortcode definition to your site's set of supported shortcodes.
96101

97-
__Shortcode Definition__
102+
### Shortcode Definition
98103

99-
```html
104+
<details>
105+
<summary>Click to expand the full Shortcode Definition</summary>
100106

107+
```html
101108
{{ $script := .Get "src" }}
102109
{{ $id := .Get "id" }}
110+
{{ $size := .Get "size" | default "full" }}
103111
{{ $style := .Get "style" }}
104112

113+
<style>
114+
.meshery-embed-container {
115+
border: 1px solid #eee;
116+
border-radius: 4px;
117+
margin: 0rem auto;
118+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
119+
}
120+
.meshery-embed-container.full {
121+
width: 80%;
122+
height: 30rem;
123+
}
124+
.meshery-embed-container.half {
125+
width: 50%;
126+
height: 25rem;
127+
}
128+
.meshery-embed-container .cy-container {
129+
width: 100%;
130+
height: 100%;
131+
}
132+
</style>
133+
105134
<div
106135
id="{{ $id }}"
107-
{{ if $style }}
108-
style="{{ $style }}"
109-
{{ else }}
110-
style="height: 30rem; width: 100%; border: 1px solid #eee"
111-
{{ end }}
136+
{{- if $style -}}
137+
style="{{ $style | safeCSS }}"
138+
{{- else -}}
139+
class="meshery-embed-container {{ $size }}"
140+
{{- end -}}
112141
></div>
113142

114143
<script src="{{ $script }}" type="module"></script>
115144
```
145+
</details>
146+
147+
### Shortcode Explanation
148+
149+
- **`src`** (Required): The path to the exported JavaScript file for your design.
150+
- **`id`** (Required): A unique ID for the embedded design container.
151+
- **`size`** (Optional): A preset for simple sizing.
152+
- Accepts `"full"` (default) or `"half"`.
153+
- This parameter is ignored if `style` is used.
154+
- **`style`** (Optional): For advanced customization.
155+
- Allows you to provide any custom CSS inline styles.
156+
- **This parameter has higher priority and will override the `size` parameter.**
116157

117-
#### Shortcode Explaination
158+
Now that your site has shortcode support for embedding Kanvas designs, you can use the `meshery-design-embed` shortcode in any Hugo markdown file where you want to display embedded designs to your site visitors.
118159

119-
`src`: Specify the path to the exported JavaScript file.
120-
`id`: Provide a unique ID for the embedded design.
121-
`style`: (Optional) Customize the appearance of the embedded design with CSS styles. This allows you to control the height, width, border, and other visual aspects.
160+
### Using the Shortcode
122161

123-
Now that your site has shortcode support for embedding Kanvas designs, you're ready to use the shortcode in any Hugo markdown file where you want embedded the designs to be visible to your site visitors.
162+
To embed a Meshery Design in your Hugo pages, use the `meshery-design-embed` shortcode. You will need the design's exported JavaScript file and its unique ID.
124163

125-
#### Shortcode Usage
164+
### Usage Examples
126165

127-
Following the steps to export a design will generate a JavaScript file, containing your design. Add the Javascript file to your site and embed the design by using your new shortcode. In the following example, we use an exported design, "embedded-design-dapr.js".
166+
Place the exported `.js` file in an appropriate folder (e.g., a nearby `images` folder) and reference it in the shortcode.
128167

129-
Use the shortcode in your Hugo content files as shown:
168+
**Default (full-width) display:**
130169

131170
```html
132171
{{</* meshery-design-embed
133-
src="../export-designs/embedded-design-dapr.js"
134-
id="embedded-design-7d183e77-09e1-4b69-a5ee-3e3870e9c5f4"
172+
src="../path/to/your-design.js"
173+
id="your-unique-design-id-full"
135174
*/>}}
136175
```
137176

138-
This code snippet demonstrates how to embed a design named "embedded-design-dapr.js" with a specific ID. This will render an interactive diagram of a Dapr (Distributed Application Runtime) setup within your Hugo-based website.
177+
**Half-width display:**
139178

140-
#### Embedded Design Example
179+
```html
180+
{{</* meshery-design-embed
181+
src="../path/to/your-design.js"
182+
id="your-unique-design-id-half"
183+
size="half"
184+
*/>}}
185+
```
141186

142-
Finally, render your designs in your pages. When Hugo builds your website, it will process this shortcode and generate the necessary HTML and JavaScript to embed the interactive Kanvas design. After finishing the steps, the embedded design will be rendered like in the example below.
187+
**Custom styling:**
143188

144-
<!-- Design Embed Container -->
189+
```html
190+
{{</* meshery-design-embed
191+
src="../path/to/your-design.js"
192+
id="your-unique-design-id-custom"
193+
style="width: 60%; height: 28rem; border-radius: 1.5rem;"
194+
*/>}}
195+
```
145196

146-
{{< meshery-design-embed src="../export-designs/embedded-design-dapr.js" id="embedded-design-7d183e77-09e1-4b69-a5ee-3e3870e9c5f4" >}}
197+
### Embedded Design Example
147198

199+
When Hugo builds your website, it will process the shortcode and generate the necessary HTML and JavaScript to embed the interactive Kanvas design.
148200

201+
Here's an example of how an embedded design appears:
202+
203+
<!-- Design Embed Container -->
204+
```html
205+
{{</* meshery-design-embed
206+
src="../export-designs/embedded-design-dapr.js"
207+
id="embedded-design-7d183e77-09e1-4b69-a5ee-3e3870e9c5f4" */>}}
208+
```
209+
210+
{{< meshery-design-embed src="../export-designs/embedded-design-dapr.js" id="embedded-design-7d183e77-09e1-4b69-a5ee-3e3870e9c5f4" >}}

layouts/shortcodes/meshery-design-embed.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@
3333
If not provided, "full" is used as default.
3434
-->
3535
{{ $size := .Get "size" | default "full" }}
36+
{{ $style := .Get "style" }}
3637

3738
<style>
3839
.meshery-embed-container {
3940
border: 1px solid #eee;
4041
border-radius: 4px;
41-
margin: 1rem auto;
42+
margin: 0rem auto;
4243
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
4344
}
4445
.meshery-embed-container.full {
45-
width: 100%;
46+
width: 80%;
4647
height: 30rem;
4748
}
4849
.meshery-embed-container.half {
4950
width: 50%;
50-
height: 30rem;
51+
height: 25rem;
5152
}
5253
.meshery-embed-container .cy-container {
5354
width: 100%;
@@ -67,7 +68,11 @@
6768
-->
6869
<div
6970
id="{{ $id }}"
70-
class="meshery-embed-container {{ $size }}"
71+
{{- if $style -}}
72+
style="{{ $style | safeCSS }}"
73+
{{- else -}}
74+
class="meshery-embed-container {{ $size }}"
75+
{{- end -}}
7176
></div>
7277

7378
<!--

0 commit comments

Comments
 (0)