You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/howto/extensibility/pluggable-widgets/create-a-pluggable-widget-one.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,10 +95,6 @@ As part of the widget scaffolding, the generator builds the widget for the first
95
95
96
96
There is also a watcher available that will rebuild your widget as you make changes to files. Start the watcher by running `npm start`.
97
97
98
-
{{% alert color="info" %}}
99
-
NPM version 7 changed the resolution behavior of peerDependencies. Try adding `--legacy-peer-deps` to your install command if it results in peer dependency resolution errors.
100
-
{{% /alert %}}
101
-
102
98
### Using the Widget
103
99
104
100
When the build script completes it will package your widget as a `.mpk` file and copy it to the `widgets/` directory in your Mendix app. Now that the generator has finished its job it is time to use the widget in Studio Pro. To use the widget, do the following:
@@ -118,9 +114,9 @@ Open the *(YourMendixApp)/myPluggableWidgets/textBox* folder in your IDE of choi
118
114
1. Remove the file *src/components/HelloWorldSample.tsx*. Errors in *TextBox.editorPreview.tsx* will be dealt with in step 6 below.
119
115
2. The generator creates the widget definition file `src/TextBox.xml` with preset properties. Replace the `sampleText` property following this snippet:
@@ -141,7 +137,7 @@ Open the *(YourMendixApp)/myPluggableWidgets/textBox* folder in your IDE of choi
141
137
Explaining the code:
142
138
143
139
* *TextBox.xml* is the [widget definition file](/apidocs-mxsdk/apidocs/pluggable-widgets/#widget-definition) used in Studio Pro which reads the widget's capabilities
144
-
* The property `pluginWidget=true` will make the widget work with the new widget API
140
+
* The property `pluginWidget=true` will make the widget work with the [Pluggable Widgets API](/apidocs-mxsdk/apidocs/pluggable-widgets/)
145
141
* The property `needsEntityContext=true` is set up to allow the attribute to be taken from context
146
142
* The property of the [type attribute](/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#attribute) only allows the selection of string attributes from the domain model
147
143
@@ -156,7 +152,7 @@ Open the *(YourMendixApp)/myPluggableWidgets/textBox* folder in your IDE of choi
156
152
Paste the following [React function component](https://react.dev/learn/your-first-component) into the newly create `TextInput.tsx` file.
157
153
158
154
```tsx
159
-
import { createElement, ReactElement } from "react";
155
+
import { ReactElement } from "react";
160
156
161
157
export interface TextInputProps {
162
158
value: string;
@@ -172,14 +168,14 @@ Open the *(YourMendixApp)/myPluggableWidgets/textBox* folder in your IDE of choi
172
168
5. The container component *src/TextBox.tsx* receives the properties in the runtime, and forwards the data to the display component. The container works like glue between the Mendix application and the display component. In *TextBox.tsx* update the component to look like this:
173
169
174
170
```tsx
175
-
import { createElement, ReactElement } from "react";
171
+
import { ReactElement } from "react";
176
172
import { TextBoxContainerProps } from "../typings/TextBoxProps";
177
173
import { TextInput } from "./components/TextInput";
178
174
179
175
import "./ui/TextBox.css";
180
176
181
177
export function TextBox(props: TextBoxContainerProps): ReactElement {
182
-
const value = props.textAttribute.value || "";
178
+
const value = props.textAttribute.value ?? "";
183
179
return <TextInputvalue={value} />;
184
180
}
185
181
```
@@ -193,7 +189,7 @@ Open the *(YourMendixApp)/myPluggableWidgets/textBox* folder in your IDE of choi
193
189
6. Pluggable Widgets also have a Preview component, which is used in the design mode of the Studio Pro page editor. Update *src/TextBox.editorPreview.tsx* such that the deleted `HelloWorldSample` component is replaced by our `TextInput` component. This will resolve the errors thrown by `npm start`.
194
190
195
191
```tsx
196
-
import { ReactElement, createElement } from "react";
192
+
import { ReactElement } from "react";
197
193
import { TextBoxPreviewProps } from "../typings/TextBoxProps";
198
194
import { TextInput } from "./components/TextInput";
199
195
@@ -224,7 +220,7 @@ The input works, but the styling could be improved. In the next code snippets, y
224
220
225
221
```tsx
226
222
export function TextBox(props: TextBoxContainerProps): ReactElement {
227
-
const value = props.textAttribute.value || "";
223
+
const value = props.textAttribute.value ?? "";
228
224
return <TextInput
229
225
value={value}
230
226
style={props.style}
@@ -239,7 +235,7 @@ The input works, but the styling could be improved. In the next code snippets, y
239
235
2. Until we update the type of our TextInputProps, Typescript will display errors in *TextBox.tsx*. In *src/components/TextInput.tsx*, add the missing properties to the interface and pass them to the `input` component:
240
236
241
237
```tsx
242
-
import { createElement, CSSProperties, ReactElement } from "react";
238
+
import { CSSProperties, ReactElement } from "react";
243
239
244
240
export interface TextInputProps {
245
241
value: string;
@@ -282,8 +278,11 @@ Comparing our widget to the Mendix text input widget we are still missing a labe
282
278
283
279
1. Open *src/TextBox.tsx* and remove the `style` and `className` props from `TextInput`. Now that the widget is a labeled input, it should no longer have the layout styling applied to it. In fact, the `pluggable-widget-tools` removed them from the type definition in *typings/TextBoxProps.d.ts*.
@@ -194,7 +194,7 @@ This section teaches you how to add validation to your TextBox widget. Using mic
194
194
5. Add `Fragment` to the current React import (shown below), and add a new `Alert` import underneath the existing imports in *TextBox.tsx*:
195
195
196
196
```tsx
197
-
import { createElement, ReactElement, Fragment } from "react";
197
+
import { ReactElement, Fragment } from "react";
198
198
import { Alert } from "./components/Alert";
199
199
```
200
200
@@ -314,7 +314,7 @@ Until now the components did not keep any state. Each keystroke passed through t
314
314
2. In *TextBox.tsx*, check if `onChangeAction` is available and call the execute function `onLeave` when the value is changed. When doing this, replace the `onUpdate` function with your new `onLeave` function:
315
315
316
316
```tsx
317
-
import { createElement, Fragment, ReactElement, useEffect } from "react";
317
+
import { Fragment, ReactElement, useEffect } from "react";
318
318
import { TextBoxContainerProps } from "../typings/TextBoxProps";
319
319
import { TextInput } from "./components/TextInput";
320
320
@@ -357,7 +357,7 @@ Until now the components did not keep any state. Each keystroke passed through t
357
357
3. In *components/TextInput.tsx*, introduce a state for input changes and use the `onBlur` function to call the `onLeave` function by replacing the `onUpdate` function:
358
358
359
359
```tsx
360
-
import { createElement, CSSProperties, ReactElement, useEffect, useState } from "react";
360
+
import { CSSProperties, ReactElement, useEffect, useState } from "react";
361
361
362
362
export interface TextInputProps {
363
363
value: string;
@@ -546,7 +546,7 @@ To easily view changes to your widget while in Studio Pro's **Design mode**, you
546
546
To add preview mode functionality, create a new file *src/TextBox.editorPreview.tsx* and add this code to it:
547
547
548
548
```tsx
549
-
import { createElement, ReactElement } from "react";
549
+
import { ReactElement } from "react";
550
550
import { TextBoxPreviewProps } from "../typings/TextBoxProps";
551
551
import { TextInput } from "./components/TextInput";
0 commit comments