Skip to content

Commit b1e4dab

Browse files
committed
feat(demo): add demo with Binder
1 parent 7524274 commit b1e4dab

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-
2+
* #%L
3+
* Markdown Editor Add-on
4+
* %%
5+
* Copyright (C) 2024-2025 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.markdown;
21+
22+
import com.flowingcode.vaadin.addons.demo.DemoSource;
23+
import com.vaadin.flow.component.button.Button;
24+
import com.vaadin.flow.component.notification.Notification;
25+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
26+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
27+
import com.vaadin.flow.data.binder.Binder;
28+
import com.vaadin.flow.router.PageTitle;
29+
import com.vaadin.flow.router.Route;
30+
31+
@DemoSource
32+
@PageTitle("Markdown Editor with Binder")
33+
@SuppressWarnings("serial")
34+
@Route(value = "markdown-editor/binder", layout = MarkdownDemoView.class)
35+
public class MarkdownBinderDemo extends VerticalLayout {
36+
37+
public MarkdownBinderDemo() {
38+
setSizeFull();
39+
Binder<Bean> binder = new Binder<>();
40+
MarkdownEditor mde = new MarkdownEditor();
41+
mde.setSizeFull();
42+
mde.setPlaceholder("Enter Markdown here");
43+
mde.setMaxLength(500);
44+
45+
binder.forField(mde).bind(Bean::getText, Bean::setText);
46+
binder.setBean(new Bean());
47+
48+
Button getContentButton =
49+
new Button("Show content", ev -> Notification.show(binder.getBean().getText()));
50+
Button setSampleContent =
51+
new Button("Set sample content", ev -> mde.setValue("**Hello** _world_"));
52+
add(mde, new HorizontalLayout(getContentButton, setSampleContent));
53+
}
54+
55+
private static class Bean {
56+
String text;
57+
58+
public String getText() {
59+
return text;
60+
}
61+
62+
public void setText(String text) {
63+
this.text = text;
64+
}
65+
}
66+
67+
}

src/test/java/com/flowingcode/vaadin/addons/markdown/MarkdownDemoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class MarkdownDemoView extends TabbedDemo {
3434
public MarkdownDemoView() {
3535
addDemo(MarkdownViewerDemo.class);
3636
addDemo(MarkdownEditorDemo.class);
37+
addDemo(MarkdownBinderDemo.class);
3738
setSizeFull();
3839
}
3940
}

0 commit comments

Comments
 (0)