Skip to content

Commit a21be58

Browse files
committed
Migrate CollapseButton
1 parent 4a0c4d9 commit a21be58

File tree

3 files changed

+128
-2
lines changed

3 files changed

+128
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@
2525
import com.vaadin.flow.component.HasComponents;
2626
import com.vaadin.flow.component.HasSize;
2727
import com.vaadin.flow.component.Tag;
28-
import com.vaadin.flow.component.dependency.HtmlImport;
28+
import com.vaadin.flow.component.dependency.JsModule;
29+
import com.vaadin.flow.component.dependency.NpmPackage;
2930
import com.vaadin.flow.component.html.Div;
3031

3132
/**
3233
* @author mlope
3334
*
3435
*/
3536
@SuppressWarnings("serial")
36-
@HtmlImport("bower_components/iron-collapse-button/iron-collapse-button.html")
37+
//@NpmPackage(value="@polymer/iron-flex-layout")
38+
//@NpmPackage(value="@polymer/iron-iconset-svg")
39+
@NpmPackage(value="@polymer/iron-icon", version = "^3.0.1")
40+
@NpmPackage(value="@polymer/iron-collapse", version = "^3.0.1")
41+
@JsModule("./iron-collapse-button/iron-collapse-button.js")
3742
@Tag("iron-collapse-button")
3843
public class CollapseButton extends Component implements HasComponents {
3944

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
@license MIT
3+
4+
Copyright (c) 2017 Jacob Phillips
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
import '@polymer/polymer/polymer-legacy.js';
25+
26+
import '@polymer/iron-flex-layout/iron-flex-layout.js';
27+
import '@polymer/iron-iconset-svg/iron-iconset-svg.js';
28+
import '@polymer/iron-icon/iron-icon.js';
29+
import '@polymer/iron-collapse/iron-collapse.js';
30+
31+
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
32+
import {html} from '@polymer/polymer/lib/utils/html-tag.js';
33+
34+
Polymer({
35+
_template: html`
36+
<style>
37+
:host {
38+
display: block;
39+
}
40+
#trigger {
41+
@apply --layout-horizontal;
42+
@apply --layout-center;
43+
}
44+
</style>
45+
46+
<iron-iconset-svg name="iron-collapse-button-icons" size="24">
47+
<svg><defs>
48+
<g id="expand-less"><path d="M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z"/></g>
49+
<g id="expand-more"><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"/></g>
50+
</defs></svg>
51+
</iron-iconset-svg>
52+
53+
<div id="trigger" on-tap="toggle">
54+
<slot name="collapse-trigger"></slot>
55+
<iron-icon icon="[[_toggle(opened, collapseIcon, expandIcon)]]" hidden$="[[noIcons]]"></iron-icon>
56+
</div>
57+
<iron-collapse id="collapse" horizontal="[[horizontal]]" no-animation="[[noAnimation]]" opened="[[opened]]">
58+
<slot name="collapse-content"></slot>
59+
</iron-collapse>
60+
`,
61+
62+
is: 'iron-collapse-button',
63+
properties: {
64+
/**
65+
* @deprecated
66+
* Corresponds to the iron-collapse's horizontal property.
67+
*/
68+
horizontal: {
69+
type: Boolean,
70+
value: false
71+
},
72+
/**
73+
* Corresponds to the iron-collapse's noAnimation property.
74+
*/
75+
noAnimation: {
76+
type: Boolean,
77+
value: false
78+
},
79+
/**
80+
* Whether currently expanded.
81+
*/
82+
opened: {
83+
type: Boolean,
84+
value: false,
85+
notify: true
86+
},
87+
/**
88+
* The icon when collapsed.
89+
*/
90+
expandIcon: {
91+
type: String,
92+
value: 'iron-collapse-button-icons:expand-more'
93+
},
94+
/**
95+
* The icon when expanded.
96+
*/
97+
collapseIcon: {
98+
type: String,
99+
value: 'iron-collapse-button-icons:expand-less'
100+
},
101+
/**
102+
* Whether to hide the expand/collapse icon.
103+
*/
104+
noIcons: {
105+
type: Boolean,
106+
value: false
107+
},
108+
},
109+
/** @depricated Use `open()`. */
110+
show: function() { this.open(); },
111+
/** @depricated Use `close()`. */
112+
hide: function() { this.close(); },
113+
open: function() { this.opened = true; },
114+
close: function() { this.opened = false; },
115+
toggle: function() { this.opened = !this.opened; },
116+
_toggle: function(cond, t, f) { return cond ? t : f; }
117+
});

src/test/resources/META-INF/frontend/styles/shared-styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ img.applogo {
3232
height: 22px;
3333
}
3434

35+
.hamlet {
36+
user-select: none;
37+
}
38+
3539
.hamlet paper-card {
3640
max-width: 600px;
3741
min-width: 200px;

0 commit comments

Comments
 (0)