Skip to content

Commit 56a00b5

Browse files
committed
Updated customize-behavior for comments
1 parent 13a6995 commit 56a00b5

File tree

1 file changed

+90
-15
lines changed

1 file changed

+90
-15
lines changed

async-collaboration/comments/customize-behavior.mdx

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,29 @@ commentElement.addCommentOnSelectedText();
8888

8989
![](/images/addCommentOnElement.png)
9090

91-
9291
Adds a Comment on a specific element by ID.
9392

94-
To add a comment on a specific element through an API method, use the `addCommentOnElement()` method and pass in an object with the schema shows in the example:
93+
To add a comment on a specific element through an API method, use the `addCommentOnElement()` method and pass in an object with the schema shown in the examples:
94+
95+
**Example 1: Add comment with targetElementId only:**
9596

9697
<Tabs>
9798
<Tab title="React / Next.js">
9899

99-
100100
```jsx
101-
102101
const element = {
103102
"targetElement": {
104-
"elementId": "element_id", // optional (pass elementId if you want to add comment on a specific element)
103+
"elementId": "element_id",
105104
"targetText": "target_text", // optional (pass targetText if you want to add comment on a specific text)
106105
"occurrence": 1, // optional (default: 1) This is relevant for text comment. By default, we will attach comment to the first occurence of the target text in your document. You can change this to attach your comment on a more specific text.
107106
"selectAllContent": true, // Set to `true` if you want to select all the text content of the target element.
108107
},
109108
"commentData": [
110109
{
111-
"commentText": "This is awesome! Well done.", // To set plain text content
112-
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.", // To set HTML formatted content
113-
"replaceContentText": "This is new comment", // provide this replaceContentText to replace current text with
114-
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>", // If replacement text contains html formatted text, then provide it here
110+
"commentText": "This is awesome! Well done.",
111+
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.",
112+
"replaceContentText": "This is new comment",
113+
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>",
115114
}
116115
],
117116
"status": "open", // optional (default: open)
@@ -123,21 +122,21 @@ commentElement.addCommentOnElement(element);
123122
</Tab>
124123

125124
<Tab title="Other Frameworks">
126-
```jsx
127125

126+
```jsx
128127
const element = {
129128
"targetElement": {
130-
"elementId": "element_id", // optional (pass elementId if you want to add comment on a specific element)
129+
"elementId": "element_id",
131130
"targetText": "target_text", // optional (pass targetText if you want to add comment on a specific text)
132131
"occurrence": 1, // optional (default: 1) This is relevant for text comment. By default, we will attach comment to the first occurence of the target text in your document. You can change this to attach your comment on a more specific text.
133132
"selectAllContent": true, // Set to `true` if you want to select all the text content of the target element.
134133
},
135134
"commentData": [
136135
{
137-
"commentText": "This is awesome! Well done.", // To set plain text content
138-
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.", // To set HTML formatted content
139-
"replaceContentText": "This is new comment", // provide this replaceContentText to replace current text with
140-
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>", // If replacement text contains html formatted text, then provide it here
136+
"commentText": "This is awesome! Well done.",
137+
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.",
138+
"replaceContentText": "This is new comment",
139+
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>",
141140
}
142141
],
143142
"status": "open", // optional (default: open)
@@ -147,8 +146,58 @@ const commentElement = Velt.getCommentElement();
147146
commentElement.addCommentOnElement(element);
148147
```
149148
</Tab>
149+
</Tabs>
150150

151+
**Example 2: Add comment with context metadata:**
152+
153+
<Tabs>
154+
<Tab title="React / Next.js">
151155

156+
```jsx
157+
const element = {
158+
"targetElement": {
159+
"elementId": "element_id",
160+
},
161+
"commentData": [
162+
{
163+
"commentText": "This is awesome! Well done.",
164+
}
165+
],
166+
"context": {
167+
"product": "cheese",
168+
"location": "zurich"
169+
},
170+
"status": "open",
171+
}
172+
173+
const commentElement = client.getCommentElement();
174+
commentElement.addCommentOnElement(element);
175+
```
176+
</Tab>
177+
178+
<Tab title="Other Frameworks">
179+
180+
```jsx
181+
const element = {
182+
"targetElement": {
183+
"elementId": "element_id",
184+
},
185+
"commentData": [
186+
{
187+
"commentText": "This is awesome! Well done.",
188+
}
189+
],
190+
"context": {
191+
"product": "cheese",
192+
"location": "zurich"
193+
},
194+
"status": "open",
195+
}
196+
197+
const commentElement = Velt.getCommentElement();
198+
commentElement.addCommentOnElement(element);
199+
```
200+
</Tab>
152201
</Tabs>
153202

154203
#### addManualComment
@@ -2069,6 +2118,8 @@ Extra fields in the comment context don't prevent a match.
20692118
{ product: "cheese", category: "dairy"} ❌ No match (missing field)
20702119
```
20712120
2121+
**Example 1: Comment Bubble with Partial Match**
2122+
20722123
<Tabs>
20732124
<Tab title="React / Next.js">
20742125
```jsx
@@ -2089,6 +2140,30 @@ Extra fields in the comment context don't prevent a match.
20892140
</Tab>
20902141
</Tabs>
20912142
2143+
**Example 2: Comment Tool with Partial Match**
2144+
2145+
<Tabs>
2146+
<Tab title="React / Next.js">
2147+
```jsx
2148+
<VeltCommentTool
2149+
targetElementId="element_id"
2150+
context={{ product: "cheese" }}
2151+
contextOptions={{ partialMatch: true }}
2152+
/>
2153+
```
2154+
</Tab>
2155+
<Tab title="Other Frameworks">
2156+
```html
2157+
<velt-comment-tool
2158+
target-element-id="element_id"
2159+
context='{ "product": "cheese" }'
2160+
context-options='{ "partialMatch": true }'
2161+
>
2162+
</velt-comment-tool>
2163+
```
2164+
</Tab>
2165+
</Tabs>
2166+
20922167
---
20932168
20942169
### Grouping Matched Comment Annotations

0 commit comments

Comments
 (0)