New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement generic JavaScript component wrapper #1165
Comments
Also, we should provide base class in case we need to create subclass with API. |
DescriptionA new UI component that can work with any JS wrapper without Vaadin component implementation has been added. And its name is This component has the following features:
Example: jsComponent.addDependencies(
"webjar://jquery:jquery.min.js",
"webjar://jquery-ui:jquery-ui.min.js",
"webjar://jquery-ui:jquery-ui.css",
"vaadin://slider-connector.js"
);
Example: MyState state = new MyState();
state.minValue = 0;
state.maxValue = 100;
jsComponent.setState(state); Example: jsComponent.setInitFunctionName("com_company_demo_web_toolkit_ui_slider_SliderServerComponent");
Example: jsComponent.addFunction("valueChanged", callbackEvent -> {
JsonArray arguments = callbackEvent.getArguments();
notifications.create()
.withCaption(StringUtils.join(arguments, ", "))
.show();
}); JS this.valueChanged(values);
Java jsComponent.callFunction("showNotification "); JS this.showNotification = function () {
alert("TEST");
}; ExampleLet's integrate Quill Rich Text Editor from https://quilljs.com/.
com_company_demo_web_screens_Sandbox = function () {
var connector = this;
var element = connector.getElement();
element.innerHTML = "<div id=\"editor\">" +
"<p>Hello World!</p>" +
"<p>Some initial <strong>bold</strong> text</p>" +
"<p><br></p>" +
"</div>";
connector.onStateChange = function () {
var state = connector.getState();
var data = state.data;
var quill = new Quill('#editor', data.options);
// Subscribe on textChange event
quill.on('text-change', function (delta, oldDelta, source) {
if (source === 'user') {
connector.valueChanged(quill.getText(), quill.getContents());
}
});
}
};
<jsComponent id="quill"
initFunctionName="com_company_demo_web_screens_Sandbox"
height="200px"
width="400">
<dependencies>
<dependency path="webjar://quill:dist/quill.js"/>
<dependency path="webjar://quill:dist/quill.snow.css"/>
<dependency path="vaadin://quill/quill-connector.js"/>
</dependencies>
</jsComponent>
@UiController("demo_Sandbox")
@UiDescriptor("sandbox.xml")
public class Sandbox extends Screen {
@Inject
private JavaScriptComponent quill;
@Inject
private Notifications notifications;
@Subscribe
protected void onInit(InitEvent event) {
QuillState state = new QuillState();
state.options = ParamsMap.of("theme", "snow",
"placeholder", "Compose an epic...");
quill.setState(state);
quill.addFunction("valueChanged", javaScriptCallbackEvent -> {
String value = javaScriptCallbackEvent.getArguments().getString(0);
notifications.create()
.withCaption(value)
.withPosition(Notifications.Position.BOTTOM_RIGHT)
.show();
});
}
class QuillState {
public Map<String, Object> options;
}
} Or simply download a demo project: js-component.zip |
Provide simple UI component that can work with any JS wrapper without Vaadin component implementation.
It should be easy to use it:
Provide XML element with properties for declarative configuration, e.g. we can configure dynamic properties and JS dependencies in XML.
Do not forget:
Dependency sources:
The text was updated successfully, but these errors were encountered: