Skip to content

Commit a457571

Browse files
committed
Add support for menu separator or divider with optional label #37
1 parent 1a33357 commit a457571

File tree

4 files changed

+71
-42
lines changed

4 files changed

+71
-42
lines changed

src/main/java/com/flowingcode/addons/applayout/MenuSeparator.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
import com.vaadin.flow.component.Component;
44
import com.vaadin.flow.component.Tag;
55
import com.vaadin.flow.component.dependency.JsModule;
6+
import com.vaadin.flow.dom.Element;
67

78
@JsModule("./fc-applayout/fc-separator.js")
89
@Tag("fc-separator")
910
public class MenuSeparator extends Component {
1011

1112
private static final long serialVersionUID = 1L;
1213

14+
public MenuSeparator() {}
15+
16+
public MenuSeparator(String label) {
17+
Element div = new Element("div");
18+
div.setText(label);
19+
div.setAttribute("slot", "label");
20+
getElement().removeAllChildren();
21+
getElement().appendChild(div);
22+
}
23+
24+
1325
}

src/main/resources/META-INF/frontend/fc-applayout/fc-separator.js

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,18 @@ import {html} from '@polymer/polymer/lib/utils/html-tag.js';
33

44
import {ThemableMixin} from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
55

6-
/*
7-
Styles:
8-
--fc-separator-border-color
9-
--fc-separator-text-padding
10-
*/
6+
import "@vaadin/flow-frontend/fc-applayout/paper-divider.js";
7+
118
class MenuSeparator extends ThemableMixin(PolymerElement) {
129
static get is() { return 'fc-separator'; }
1310

1411
static get template() {
15-
//Based on https://stackoverflow.com/a/28434792/1297272
16-
//(C) 2015 CC-BY-SA https://stackoverflow.com/users/677418/sleek-geek
12+
1713
return html`
18-
<style>
19-
:host {
20-
display: flex;
21-
justify-content: center;
22-
opacity: 0.6;
23-
}
24-
:host div {
25-
width: 100%;
26-
text-align: center;
27-
position: relative;
28-
}
29-
30-
:host div:after {
31-
content: '';
32-
width: 100%;
33-
position: absolute;
34-
border-bottom: solid 1px var(--fc-separator-border-color, rgba(0,0,0, 0.6));
35-
left: 0;
36-
top: 50%;
37-
z-index: 1;
38-
}
39-
40-
:host span {
41-
width: auto;
42-
display: inline-block;
43-
z-index: 3;
44-
padding: 0 var(--fc-separator-text-padding, 8px) 0 var(--fc-separator-text-padding, 8px);
45-
position: relative;
46-
}
47-
</style>
48-
<div>
49-
<span><slot></slot></span>
50-
</div>
14+
<paper-divider></paper-divider>
15+
<div><slot name="label"></slot></div>
5116
`;}
5217

53-
}
18+
}
5419

5520
customElements.define(MenuSeparator.is, MenuSeparator);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* The MIT License (MIT)
2+
Copyright (c) 2015 WebPaperElements
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8+
of the Software, and to permit persons to whom the Software is furnished to do
9+
so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
23+
import {html} from '@polymer/polymer/lib/utils/html-tag.js';
24+
25+
import {ThemableMixin} from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
26+
27+
//Based on https://github.com/WebPaperElements/paper-divider
28+
class PaperDivider extends ThemableMixin(PolymerElement) {
29+
static get is() { return 'paper-divider'; }
30+
31+
static get template() {
32+
33+
return html`
34+
<style>
35+
:host {
36+
display: block;
37+
height: 1px;
38+
min-height: 1px;
39+
max-height: 1px;
40+
background-color: var(--paper-divider-color, #000);
41+
opacity: 0.12;
42+
@apply(--paper-divider);
43+
}
44+
</style>
45+
`;}
46+
47+
}
48+
49+
customElements.define(PaperDivider.is, PaperDivider);

src/test/java/com/flowingcode/addons/applayout/DemoView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,17 @@ private Component[] createMenuItems() {
232232
.add(new MenuItem("And Again",()->showContent("And Again!")))
233233
),
234234

235-
new MenuSeparator(),
235+
new MenuSeparator("Separator"),
236236

237237
new MenuItem("Item 1"),
238238
new MenuItem("Item 2"),
239239
new MenuItem("Item 3"),
240240
new MenuItem("Item 4"),
241241
new MenuItem("Item 5"),
242242
new MenuItem("Item 6"),
243+
244+
new MenuSeparator(),
245+
243246
new MenuItem("Item 7"),
244247
new MenuItem("Item 8"),
245248
new MenuItem("Item 9"),

0 commit comments

Comments
 (0)