Skip to content

Commit c62c99e

Browse files
committed
chore(use-case): add documentation for the wrex use case
CMS-1088
1 parent 3196365 commit c62c99e

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Loading

docs/javascript/use-cases.md

+114
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,120 @@ window.lumapps.customize(({ targets, components, render, placement, constants })
191191
});
192192
```
193193

194+
## Add new button on the rich text editor toolbar (widget RTE, article or event)
195+
196+
![Use case wrex button](./assets/use-case-wrex-toolbar-item.png "Use case wrex button")
197+
198+
In this use case, you'll probably want to have a new button on the rich text editor toolbar allowing you to insert specific elements from an external provider.
199+
200+
```js
201+
window.lumapps.customize(({
202+
targets,
203+
components,
204+
render,
205+
placement
206+
}) => {
207+
const { DropdownSection, DropdownItem, RawHTML } = components;
208+
209+
const onVideoButtonClick = async (context) => {
210+
// It will open a dialog with the component in it
211+
context.openWrexConfigurationDialog({
212+
componentToRender: RawHTML({ html: '<p>My HTML for my iframe configuration</p>' })
213+
});
214+
215+
// Set the element attributes to be inserted on dialog confirmation button click
216+
context.setWrexIframeAttributes({
217+
src: 'https://lumapps.com',
218+
title: 'Lumapps',
219+
provider: 'my-website',
220+
});
221+
};
222+
223+
const onImageButtonClick = async (context) => {
224+
context.openWrexConfigurationDialog({
225+
componentToRender: RawHTML({ html: '<p>My HTML for my image configuration</p>' })
226+
});
227+
228+
context.setWrexImageAttributes({
229+
images: [{
230+
id: '1234',
231+
src: 'https://picsum.photos/id/17/367/267',
232+
width: 367,
233+
height: 267,
234+
alt: 'Some alt text',
235+
}, ],
236+
});
237+
};
238+
239+
render({
240+
placement: placement.UNDER,
241+
target: targets.WREX_TOOLBAR,
242+
toRenderWithContext: (context) => {
243+
return DropdownSection({
244+
children: [
245+
DropdownItem({
246+
title: 'My videos',
247+
icon: 'video-account',
248+
onClick: () => onVideoButtonClick(context),
249+
}),
250+
DropdownItem({
251+
title: 'My images',
252+
icon: 'image-area',
253+
onClick: () => onImageButtonClick(context),
254+
}),
255+
],
256+
});
257+
},
258+
});
259+
});
260+
```
261+
### Use case information
262+
263+
**openWrexConfigurationDialog** Function
264+
265+
Open the configuration dialog and allows you to define his content.
266+
267+
| Parameter | Description | Is required? | Option type | Default Value |
268+
|-----------|------|----------|---------|-------------|
269+
| `configuration` | Configuration options | Yes | object | `{}` |
270+
| `configuration.componentToRender` | The component to render inside the dialog | Yes | Component | `undefined` |
271+
| `configuration.isLoading` | Whether the dialog should be in a loading state | No | boolean | `false` |
272+
273+
**setWrexIframeAttributes** Function
274+
275+
Allows you to define the data of the iframe to insert
276+
277+
*Note: calling this function will not insert an iframe, the insertion is done through the configuration dialog*
278+
279+
| Parameter | Description | Is required? | Option type | Default Value |
280+
|-----------|------|----------|---------|-------------|
281+
| `attributes` | Configuration options | Yes | object | `{}` |
282+
| `attributes.src` | The url of the page to embed | Yes | string | `undefined` |
283+
| `attributes.srcDoc` | The html content of the iframe | No | string | `undefined` |
284+
| `attributes.title` | The title of the iframe, used for accessibility | No | string | `undefined` |
285+
| `attributes.provider` | The name of the provider of the iframe, used to identify an iframe | No | string | `undefined` |
286+
287+
**setWrexImageAttributes** Function
288+
289+
Allows you to define the data of the image to insert
290+
291+
*Note: calling this function will not insert an image, the insertion is done through the configuration dialog*
292+
293+
| Parameter | Description | Is required? | Option type | Default Value |
294+
|-----------|------|----------|---------|-------------|
295+
| `attributes` | Configuration options | Yes | object | `{}` |
296+
| `attributes.title` | The caption of the image group | No | string | `undefined` |
297+
| `attributes.images` | The image(s) to display | Yes | Image[] | `[]` |
298+
299+
**Image** Object
300+
301+
| Parameter | Description | Is required? | Option type | Default Value |
302+
|-----------|------|----------|---------|-------------|
303+
| `src` | The image url | Yes | string | `''` |
304+
| `alt` | The image alt text, should describe the image for accessibility purpose | No | string | `''` |
305+
| `height` | The image height (in px) | No | integer | `undefined` |
306+
| `width` | The image width (in px) | No | integer | `undefined` |
307+
194308
## Disabling bookmarks
195309

196310
Bookmarks can be disabled in order to avoid them to be displayed by adding the following line of JavaScript to your site.

0 commit comments

Comments
 (0)