@vaadin/crud 22.0.0-rc1 → 23.0.0-alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,26 +2,24 @@ import '@vaadin/vaadin-lumo-styles/typography.js';
2
2
  import '@vaadin/vaadin-lumo-styles/color.js';
3
3
  import '@vaadin/vaadin-lumo-styles/font-icons.js';
4
4
  import '@vaadin/vaadin-lumo-styles/style.js';
5
- import '../vaadin-dialog-layout-overlay-styles.js';
6
5
  import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
6
 
8
7
  registerStyles(
9
8
  'vaadin-crud-edit',
10
9
  css`
11
10
  :host {
11
+ min-width: auto;
12
+ margin: 0;
12
13
  font-family: 'lumo-icons', var(--lumo-font-family);
13
14
  font-size: var(--lumo-icon-size-m);
14
15
  line-height: 1;
15
- color: var(--lumo-primary-text-color);
16
16
  position: relative;
17
- background-color: var(--lumo-contrast-5pct);
18
- border-radius: var(--lumo-border-radius-m);
19
17
  width: var(--lumo-size-s);
20
18
  height: var(--lumo-size-s);
21
- cursor: var(--lumo-clickable-cursor);
19
+ outline: none;
22
20
  }
23
21
 
24
- :host::before {
22
+ [part='icon']::before {
25
23
  content: var(--lumo-icons-edit);
26
24
  width: var(--lumo-size-m);
27
25
  height: var(--lumo-size-m);
@@ -31,111 +29,102 @@ registerStyles(
31
29
  top: calc((var(--lumo-size-m) - var(--lumo-size-s)) / -2);
32
30
  left: calc((var(--lumo-size-m) - var(--lumo-size-s)) / -2);
33
31
  }
34
-
35
- :host::after {
36
- content: '';
37
- display: block;
38
- position: absolute;
39
- top: 0;
40
- left: 0;
41
- width: 100%;
42
- height: 100%;
43
- border-radius: inherit;
44
- background-color: currentColor;
45
- opacity: 0;
46
- transition: opacity 100ms;
47
- }
48
-
49
- :host(:hover)::after {
50
- opacity: 0.05;
51
- }
52
-
53
- :host(:active)::after {
54
- opacity: 0.12;
55
- }
56
32
  `,
57
33
  { moduleId: 'lumo-crud-grid-edit' }
58
34
  );
59
35
 
36
+ /**
37
+ * Shared styles used for the CRUD editor content and buttons regardless of `editorPosition`.
38
+ * They are applied to both `vaadin-crud` and `vaadin-crud-dialog-overlay` components.
39
+ */
40
+ const editorStyles = css`
41
+ [part='scroller'] {
42
+ padding: var(--lumo-space-l);
43
+ }
44
+
45
+ ::slotted([slot='header']) {
46
+ margin-top: var(--lumo-space-s);
47
+ margin-bottom: var(--lumo-space-s);
48
+ }
49
+
50
+ [part='footer'] {
51
+ background-color: var(--lumo-contrast-5pct);
52
+ padding: var(--lumo-space-s);
53
+ }
54
+
55
+ [part='footer'] ::slotted(*) {
56
+ margin-left: var(--lumo-space-s);
57
+ margin-right: var(--lumo-space-s);
58
+ }
59
+
60
+ :host(:not([dir='rtl'])) ::slotted([slot='delete-button']) {
61
+ margin-right: auto;
62
+ }
63
+
64
+ :host([dir='rtl']) ::slotted([slot='delete-button']) {
65
+ margin-left: auto;
66
+ }
67
+ `;
68
+
60
69
  registerStyles(
61
70
  'vaadin-crud',
62
- css`
63
- :host {
64
- font-family: var(--lumo-font-family);
65
- }
66
-
67
- [part='toolbar'] {
68
- padding: var(--lumo-space-s) var(--lumo-space-m);
69
- background-color: var(--lumo-contrast-5pct);
70
- border: 1px solid var(--lumo-contrast-10pct);
71
- border-top: none;
72
- }
73
-
74
- :host(:not([dir='rtl'])) [part='toolbar'] ::slotted(*:not(:first-child)) {
75
- margin-left: var(--lumo-space-s);
76
- }
77
-
78
- :host([dir='rtl']) [part='toolbar'] ::slotted(*:not(:first-child)) {
79
- margin-right: var(--lumo-space-s);
80
- }
81
-
82
- :host([theme~='no-border']) [part='toolbar'] {
83
- border: 0;
84
- }
85
-
86
- vaadin-grid-cell-content {
87
- text-overflow: ellipsis;
88
- }
89
- `,
71
+ [
72
+ editorStyles,
73
+ css`
74
+ :host {
75
+ font-family: var(--lumo-font-family);
76
+ }
77
+
78
+ [part='toolbar'] {
79
+ padding: var(--lumo-space-s) var(--lumo-space-m);
80
+ background-color: var(--lumo-contrast-5pct);
81
+ border: 1px solid var(--lumo-contrast-10pct);
82
+ border-top: none;
83
+ }
84
+
85
+ :host(:not([dir='rtl'])) [part='toolbar'] ::slotted(*:not(:first-child)) {
86
+ margin-left: var(--lumo-space-s);
87
+ }
88
+
89
+ :host([dir='rtl']) [part='toolbar'] ::slotted(*:not(:first-child)) {
90
+ margin-right: var(--lumo-space-s);
91
+ }
92
+
93
+ :host([theme~='no-border']) [part='toolbar'] {
94
+ border: 0;
95
+ }
96
+
97
+ [part='editor'] {
98
+ background: var(--lumo-base-color);
99
+ box-sizing: border-box;
100
+ }
101
+
102
+ :host(:not([editor-position=''])) [part='editor']:not([hidden]) {
103
+ box-shadow: var(--lumo-box-shadow-m);
104
+ }
105
+
106
+ :host(:not([theme~='no-border']):not([editor-position=''])) [part='editor']:not([hidden]) {
107
+ border: 1px solid var(--lumo-contrast-20pct);
108
+ }
109
+
110
+ :host(:not([theme~='no-border'])[editor-position='bottom']) [part='editor']:not([hidden]) {
111
+ border-top: 0;
112
+ }
113
+
114
+ :host(:not([dir='rtl'])[editor-position='aside']) [part='editor']:not([hidden]) {
115
+ border-left: 0;
116
+ }
117
+
118
+ :host([dir='rtl']:not([theme~='no-border'])[editor-position='aside']) [part='editor']:not([hidden]) {
119
+ border-right: 0;
120
+ }
121
+
122
+ vaadin-grid-cell-content {
123
+ text-overflow: ellipsis;
124
+ }
125
+ `
126
+ ],
90
127
  { moduleId: 'lumo-crud' }
91
128
  );
92
129
 
93
- registerStyles(
94
- 'vaadin-dialog-layout',
95
- css`
96
- [part='header'] ::slotted(*) {
97
- margin-top: var(--lumo-space-s);
98
- margin-bottom: var(--lumo-space-s);
99
- }
100
-
101
- [part='scroller'] {
102
- padding: var(--lumo-space-l);
103
- }
104
-
105
- [part='footer'] {
106
- background-color: var(--lumo-contrast-5pct);
107
- padding: var(--lumo-space-s) var(--lumo-space-s);
108
- }
109
-
110
- [part='footer'] ::slotted(*) {
111
- margin-left: var(--lumo-space-s);
112
- margin-right: var(--lumo-space-s);
113
- }
114
-
115
- [part='editor'] {
116
- background: var(--lumo-base-color);
117
- box-sizing: border-box;
118
- }
119
-
120
- :host(:not([editor-position=''])) [part='editor']:not([hidden]) {
121
- box-shadow: var(--lumo-box-shadow-m);
122
- }
123
-
124
- :host(:not([theme~='no-border']):not([editor-position=''])) [part='editor']:not([hidden]) {
125
- border: 1px solid var(--lumo-contrast-20pct);
126
- }
127
-
128
- :host(:not([theme~='no-border'])[editor-position='bottom']) [part='editor']:not([hidden]) {
129
- border-top: 0;
130
- }
131
-
132
- :host(:not([dir='rtl'])[editor-position='aside']) [part='editor']:not([hidden]) {
133
- border-left: 0;
134
- }
135
-
136
- :host([dir='rtl']:not([theme~='no-border'])[editor-position='aside']) [part='editor']:not([hidden]) {
137
- border-right: 0;
138
- }
139
- `,
140
- { moduleId: 'lumo-dialog-layout' }
141
- );
130
+ registerStyles('vaadin-crud-dialog-overlay', editorStyles, { moduleId: 'lumo-crud-dialog-overlay' });
@@ -1,12 +1,13 @@
1
1
  import '@vaadin/vaadin-material-styles/typography.js';
2
2
  import '@vaadin/vaadin-material-styles/color.js';
3
- import '../vaadin-dialog-layout-overlay-styles.js';
4
3
  import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
5
4
 
6
5
  registerStyles(
7
6
  'vaadin-crud-edit',
8
7
  css`
9
8
  :host {
9
+ display: block;
10
+ min-width: auto;
10
11
  font-size: var(--material-button-font-size);
11
12
  line-height: 1;
12
13
  color: var(--material-text-color);
@@ -15,9 +16,14 @@ registerStyles(
15
16
  border-radius: 4px;
16
17
  width: 2em;
17
18
  height: 2em;
19
+ outline: none;
20
+ /* Reset button styles */
21
+ letter-spacing: normal;
22
+ -webkit-font-smoothing: auto;
23
+ -moz-font-smoothing: auto;
18
24
  }
19
25
 
20
- :host::before {
26
+ [part='icon']::before {
21
27
  font-family: serif;
22
28
  font-size: var(--material-button-font-size);
23
29
  color: var(--material-primary-text-color);
@@ -27,102 +33,99 @@ registerStyles(
27
33
  line-height: 2em;
28
34
  text-align: center;
29
35
  position: absolute;
30
- }
31
-
32
- :host::after {
33
- content: '';
34
- display: block;
35
- width: 100%;
36
- height: 100%;
37
- border-radius: inherit;
38
- background-color: currentColor;
39
- opacity: 0;
40
- transition: opacity 100ms;
41
- }
42
-
43
- :host(:hover)::after {
44
- opacity: 0.05;
45
- }
46
-
47
- :host(:active)::after {
48
- opacity: 0.12;
36
+ top: 0;
37
+ left: 0;
49
38
  }
50
39
  `,
51
40
  { moduleId: 'material-crud-grid-edit' }
52
41
  );
53
42
 
43
+ /**
44
+ * Shared styles used for the CRUD editor content and buttons regardless of `editorPosition`.
45
+ * They are applied to both `vaadin-crud` and `vaadin-crud-dialog-overlay` components.
46
+ */
47
+ const editorStyles = css`
48
+ [part='scroller'] {
49
+ padding: 16px;
50
+ background: var(--material-background-color);
51
+ }
52
+
53
+ [part='footer'] {
54
+ background-color: var(--material-secondary-background-color);
55
+ padding: 8px 4px;
56
+ }
57
+
58
+ [part='footer'] ::slotted(*) {
59
+ margin-left: 4px;
60
+ margin-right: 4px;
61
+ }
62
+
63
+ :host(:not([dir='rtl'])) ::slotted([slot='delete-button']) {
64
+ margin-right: auto;
65
+ }
66
+
67
+ :host([dir='rtl']) ::slotted([slot='delete-button']) {
68
+ margin-left: auto;
69
+ }
70
+ `;
71
+
54
72
  registerStyles(
55
73
  'vaadin-crud',
56
- css`
57
- :host {
58
- font-family: var(--material-font-family);
59
- }
60
-
61
- [part='toolbar'] {
62
- padding: 8px;
63
- background-color: var(--material-secondary-background-color);
64
- }
65
-
66
- :host(:not([dir='rtl'])) [part='toolbar'] ::slotted(*:not(:first-child)) {
67
- margin-left: 0.5em;
68
- }
69
-
70
- :host([dir='rtl']) [part='toolbar'] ::slotted(*:not(:first-child)) {
71
- margin-right: 0.5em;
72
- }
74
+ [
75
+ editorStyles,
76
+ css`
77
+ :host {
78
+ font-family: var(--material-font-family);
79
+ }
73
80
 
74
- vaadin-text-field[theme~='small'] {
75
- height: 24px;
76
- font-size: var(--material-small-font-size);
77
- margin: 0;
78
- padding: 0;
79
- }
80
- `,
81
- { moduleId: 'material-crud' }
82
- );
81
+ [part='toolbar'] {
82
+ padding: 8px;
83
+ background-color: var(--material-secondary-background-color);
84
+ }
83
85
 
84
- registerStyles(
85
- 'vaadin-dialog-layout',
86
- css`
87
- :host(:not([editor-position=''])) [part='editor']:not([hidden]) {
88
- box-shadow: var(--material-shadow-elevation-12dp);
89
- }
86
+ :host(:not([editor-position=''])) [part='editor']:not([hidden]) {
87
+ box-shadow: var(--material-shadow-elevation-12dp);
88
+ }
90
89
 
91
- [part='scroller'] {
92
- padding: 16px;
93
- background: var(--material-background-color);
94
- }
90
+ :host(:not([dir='rtl'])) [part='toolbar'] ::slotted(*:not(:first-child)) {
91
+ margin-left: 0.5em;
92
+ }
95
93
 
96
- [part='footer'] {
97
- background-color: var(--material-secondary-background-color);
98
- padding: 8px 4px;
99
- }
94
+ :host([dir='rtl']) [part='toolbar'] ::slotted(*:not(:first-child)) {
95
+ margin-right: 0.5em;
96
+ }
100
97
 
101
- [part='footer'] ::slotted(*) {
102
- margin-left: 4px;
103
- margin-right: 4px;
104
- }
105
- `,
106
- { moduleId: 'material-dialog-layout' }
98
+ vaadin-text-field[theme~='small'] {
99
+ height: 24px;
100
+ font-size: var(--material-small-font-size);
101
+ margin: 0;
102
+ padding: 0;
103
+ }
104
+ `
105
+ ],
106
+ { moduleId: 'material-crud' }
107
107
  );
108
108
 
109
109
  registerStyles(
110
- 'vaadin-dialog-overlay',
111
- css`
112
- @keyframes material-overlay-dummy-animation {
113
- 0% {
114
- opacity: 1;
110
+ 'vaadin-crud-dialog-overlay',
111
+ [
112
+ editorStyles,
113
+ css`
114
+ @keyframes material-overlay-dummy-animation {
115
+ 0% {
116
+ opacity: 1;
117
+ }
118
+
119
+ 100% {
120
+ opacity: 1;
121
+ }
115
122
  }
116
123
 
117
- 100% {
118
- opacity: 1;
124
+ :host([opening]),
125
+ :host([closing]) {
126
+ animation: 0.25s material-overlay-dummy-animation;
119
127
  }
120
- }
121
-
122
- :host([opening]),
123
- :host([closing]) {
124
- animation: 0.25s material-overlay-dummy-animation;
125
- }
126
- `,
128
+ `
129
+ ],
127
130
  { moduleId: 'material-crud-dialog-overlay' }
128
131
  );
@@ -1,241 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2017 - 2021 Vaadin Ltd.
4
- * This program is available under Commercial Vaadin Developer License 4.0, available at https://vaadin.com/license/cvdl-4.0.
5
- */
6
- import '@vaadin/dialog/src/vaadin-dialog.js';
7
- import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
- import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
-
11
- /**
12
- * An element used internally by `<vaadin-crud>`. Not intended to be used separately.
13
- *
14
- * @extends HTMLElement
15
- * @mixes ElementMixin
16
- * @mixes ThemableMixin
17
- * @private
18
- */
19
- class DialogLayout extends ElementMixin(ThemableMixin(PolymerElement)) {
20
- static get is() {
21
- return 'vaadin-dialog-layout';
22
- }
23
-
24
- static get template() {
25
- return html`
26
- <style>
27
- :host {
28
- z-index: 1;
29
- }
30
-
31
- :host(:not([editor-position=''])[opened]:not([mobile])) {
32
- flex: 1 0 100%;
33
- }
34
-
35
- :host([editor-position='bottom'][opened]:not([mobile])) {
36
- max-height: var(--vaadin-crud-editor-max-height);
37
- }
38
-
39
- :host([editor-position='aside'][opened]:not([mobile])) {
40
- min-width: 300px;
41
- max-width: var(--vaadin-crud-editor-max-width);
42
- }
43
-
44
- [part='editor'] {
45
- display: flex;
46
- flex-direction: column;
47
- height: 100%;
48
- }
49
-
50
- [part='editor'][hidden] {
51
- display: none;
52
- }
53
-
54
- :host([editor-position='bottom']) [part='editor']:not([hidden]) {
55
- height: 100%;
56
- display: flex;
57
- flex-direction: column;
58
- }
59
-
60
- [part='scroller'] {
61
- display: flex;
62
- flex-direction: column;
63
- overflow: auto;
64
- -webkit-overflow-scrolling: touch;
65
- flex: auto;
66
- }
67
-
68
- [part='footer'] {
69
- display: flex;
70
- flex: none;
71
- flex-direction: row-reverse;
72
- }
73
- </style>
74
-
75
- <div id="editor" part="editor" hidden$="[[!_computeEditorOpened(opened, mobile, 'bottom','aside')]]">
76
- <div part="scroller" id="scroller" role="group" aria-labelledby="header">
77
- <div part="header" id="header">
78
- <slot name="header"></slot>
79
- </div>
80
- <slot></slot>
81
- </div>
82
-
83
- <div part="footer" role="toolbar">
84
- <slot name="footer"></slot>
85
- </div>
86
- </div>
87
-
88
- <vaadin-dialog
89
- id="dialog"
90
- opened="[[_computeEditorOpened(opened, mobile, '')]]"
91
- aria-label="[[__ariaLabel]]"
92
- no-close-on-outside-click="[[noCloseOnOutsideClick]]"
93
- no-close-on-esc="[[noCloseOnEsc]]"
94
- theme$="[[theme]] layout"
95
- ></vaadin-dialog>
96
-
97
- <template id="dialogTemplate"></template>
98
- `;
99
- }
100
-
101
- static get properties() {
102
- return {
103
- /**
104
- * True if the overlay is currently displayed.
105
- */
106
- opened: {
107
- type: Boolean,
108
- value: false,
109
- notify: true,
110
- reflectToAttribute: true,
111
- observer: '_openedChanged'
112
- },
113
-
114
- editorPosition: {
115
- type: String,
116
- reflectToAttribute: true
117
- },
118
-
119
- /** Theme to use */
120
- theme: String,
121
-
122
- /** Disable closing when user clicks outside */
123
- noCloseOnOutsideClick: Boolean,
124
-
125
- /** Disable closing when user presses escape */
126
- noCloseOnEsc: Boolean,
127
-
128
- /** Reference to the edit form */
129
- form: Object,
130
-
131
- /** Reference to the edit save button */
132
- saveButton: Object,
133
-
134
- /** Reference to the edit delete button */
135
- deleteButton: Object,
136
-
137
- /** Reference to the edit cancel button */
138
- cancelButton: Object,
139
-
140
- mobile: {
141
- type: Boolean,
142
- observer: '__mobileChanged',
143
- reflectToAttribute: true
144
- },
145
-
146
- __ariaLabel: String
147
- };
148
- }
149
-
150
- ready() {
151
- super.ready();
152
- this._dialogOpenedChangedListener = this._dialogOpenedChangedListener.bind(this);
153
- this.$.dialog.addEventListener('opened-changed', this._dialogOpenedChangedListener);
154
- this.__header = this.querySelector('[slot=header]');
155
- this.__footer = Array.from(this.querySelectorAll('[slot="footer"]'));
156
- }
157
-
158
- _dialogOpenedChangedListener() {
159
- this.opened = this.$.dialog.opened;
160
- }
161
-
162
- _openedChanged(opened) {
163
- if (opened) {
164
- this._ensureChildren();
165
- }
166
-
167
- // TODO: A temporary hack as far as `vaadin-dialog` doesn't support the Polymer Template API anymore.
168
- this.$.dialog.$.overlay.template = this.$.dialogTemplate;
169
-
170
- // Make sure to reset scroll position
171
- this.$.scroller.scrollTop = 0;
172
- }
173
-
174
- __mobileChanged() {
175
- this._ensureChildren();
176
- }
177
-
178
- __moveChildNodes(target) {
179
- // Teleport header node
180
- target.appendChild(this.__header);
181
-
182
- // For custom form, remove slot attribute
183
- // so that it is properly moved to dialog.
184
- if (this.form.hasAttribute('slot')) {
185
- this.form.removeAttribute('slot');
186
- }
187
-
188
- // Teleport edit form
189
- target.appendChild(this.form);
190
-
191
- // This order is important so the spacing (coming from this.__footer) is correctly placed
192
- if (this.saveButton) {
193
- this.saveButton.setAttribute('slot', 'footer');
194
- target.appendChild(this.saveButton);
195
- }
196
-
197
- if (this.cancelButton) {
198
- this.cancelButton.setAttribute('slot', 'footer');
199
- target.appendChild(this.cancelButton);
200
- }
201
-
202
- // Teleport footer nodes
203
- this.__footer.forEach((node) => target.appendChild(node));
204
-
205
- if (this.deleteButton) {
206
- this.deleteButton.setAttribute('slot', 'footer');
207
- target.appendChild(this.deleteButton);
208
- }
209
-
210
- // Wait to set label until slotted element has been moved.
211
- setTimeout(() => {
212
- this.__ariaLabel = this.__header.textContent.trim();
213
- });
214
- }
215
-
216
- _ensureChildren() {
217
- const content = this.$.dialog.$.overlay.$.content;
218
- if (!this.form || !content.shadowRoot) {
219
- return;
220
- }
221
-
222
- if (this.editorPosition === '' || this.mobile) {
223
- // Move children from editor to dialog
224
- Array.from(this.$.editor.childNodes).forEach((node) => content.shadowRoot.appendChild(node));
225
- this.__moveChildNodes(content);
226
- } else {
227
- // Move children from dialog to editor
228
- Array.from(content.shadowRoot.childNodes).forEach((c) => this.$.editor.appendChild(c));
229
- this.__moveChildNodes(this);
230
- }
231
- }
232
-
233
- _computeEditorOpened(opened, isMobile, ...editorPositions) {
234
- if (isMobile && editorPositions.indexOf('') !== -1) {
235
- return opened;
236
- }
237
- return editorPositions.indexOf(this.editorPosition) !== -1 && opened;
238
- }
239
- }
240
-
241
- customElements.define(DialogLayout.is, DialogLayout);