@kubex/zinc 1.0.100 → 1.0.101

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.100",
3
+ "version": "1.0.101",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -2,6 +2,7 @@ import type {DataProviderOption, LocalDataProvider} from "./provider";
2
2
 
3
3
  const currencyCodeToName: { [key: string]: string } = {
4
4
  'ALL': 'Albania Lek',
5
+ 'AED': 'United Arab Emirates Dirham',
5
6
  'AFN': 'Afghanistan Afghani',
6
7
  'ARS': 'Argentina Peso',
7
8
  'AWG': 'Aruba Guilder',
@@ -6,26 +6,31 @@ import {keyed} from 'lit/directives/keyed.js';
6
6
  import {live} from 'lit/directives/live.js';
7
7
  import {property, state} from 'lit/decorators.js';
8
8
  import ZincElement from '../../internal/zinc-element';
9
+ import ZnButton from '../button';
10
+ import ZnButtonGroup from '../button-group';
11
+ import ZnDropdown from '../dropdown';
9
12
  import ZnInlineEdit from '../inline-edit';
10
13
  import ZnInput from '../input';
11
- import ZnNavbar from '../navbar';
14
+ import ZnMenu from '../menu';
12
15
  import type {PropertyValues} from 'lit';
13
16
  import type {ZincFormControl} from '../../internal/zinc-element';
14
17
  import type {ZnMenuSelectEvent} from '../../events/zn-menu-select';
15
- import type {ZnSelectEvent} from "../../events/zn-select";
16
18
 
17
19
  import styles from './translations.scss';
18
20
 
19
21
  export default class ZnTranslations extends ZincElement implements ZincFormControl {
20
22
  static styles = unsafeCSS(styles);
21
23
  static dependencies = {
22
- 'zn-navbar': ZnNavbar,
24
+ 'zn-button': ZnButton,
25
+ 'zn-button-group': ZnButtonGroup,
26
+ 'zn-dropdown': ZnDropdown,
27
+ 'zn-inline-edit': ZnInlineEdit,
23
28
  'zn-input': ZnInput,
24
- 'zn-inline-edit': ZnInlineEdit
29
+ 'zn-menu': ZnMenu
25
30
  };
26
31
 
27
32
  private readonly formControlController: FormControlController = new FormControlController(this);
28
- private readonly hasSlotController = new HasSlotController(this, 'label');
33
+ private readonly hasSlotController = new HasSlotController(this, 'label', 'expand');
29
34
 
30
35
  @property() name = '';
31
36
  @property() value = '{"en":""}';
@@ -147,6 +152,7 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
147
152
  }
148
153
 
149
154
  private handleLanguageAdd = (e: ZnMenuSelectEvent) => {
155
+ e.stopPropagation();
150
156
  const element = e.detail.element as HTMLElement;
151
157
  const languageCode = element.getAttribute('data-path');
152
158
  if (languageCode) {
@@ -157,16 +163,9 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
157
163
  }
158
164
  };
159
165
 
160
- private handleNavbarClick = (e: ZnSelectEvent) => {
161
- e.stopPropagation();
162
- const li = e.detail.item as HTMLElement;
163
- if (li) {
164
- const tab = li.getAttribute('tab') || li.getAttribute('data-tab');
165
- if (tab) {
166
- this._activeLanguage = tab;
167
- this.requestUpdate();
168
- }
169
- }
166
+ private switchLanguage = (lang: string) => {
167
+ this._activeLanguage = lang;
168
+ this.requestUpdate();
170
169
  };
171
170
 
172
171
  private handleValueUpdate = (e: CustomEvent) => {
@@ -223,48 +222,67 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
223
222
  visibleTabs.unshift('en');
224
223
  }
225
224
 
226
- const navigation = visibleTabs.map(code => ({
227
- title: code.toUpperCase(),
228
- active: code === this._activeLanguage,
229
- tab: code
230
- }));
231
-
232
225
  const currentTranslation = this.values[this._activeLanguage] ?? '';
233
226
  const isRTL = this.isRTLLanguage(this._activeLanguage);
234
227
 
235
228
  const hasLabelSlot = this.hasSlotController.test('label');
236
229
  const hasLabel = this.label ? true : hasLabelSlot;
230
+ const hasExpandSlot = this.hasSlotController.test('expand');
231
+ const hasMultipleLanguages = Object.keys(this.languages).length > 1;
232
+ const showActions = !this.grouped && (hasMultipleLanguages || hasExpandSlot);
237
233
 
238
234
  return html`
239
235
  <div part="form-control"
240
236
  class="${classMap({
241
237
  'translations': true,
242
238
  'translations--grouped': this.grouped,
239
+ 'translations--flush': this.flush,
243
240
  'form-control': true,
244
241
  'form-control--medium': true,
245
242
  'form-control--has-label': hasLabel,
246
243
  })}"
247
244
  @keydown="${this.handleKeyDown}">
248
- <label part="form-control-label" class="form-control__label" for="input"
249
- aria-hidden=${hasLabel ? 'false' : 'true'}>
250
- <slot name="label">${this.label}</slot>
251
- </label>
252
-
253
- ${!this.grouped ? html`
254
- <zn-navbar
255
- .navigation="${navigation}"
256
- .dropdown="${availableLanguages}"
257
- name="${this.name}-translations-navbar"
258
- @zn-select="${this.handleNavbarClick}"
259
- @zn-menu-select="${this.handleLanguageAdd}"
260
- flush=${this.flush || nothing}
261
- isolated
262
- manual-add-items
263
- >
264
- <slot name="expand" slot="expand"></slot>
265
- </zn-navbar>
266
- ` : nothing}
267
- <div class="input-container">
245
+ <div class="translations__header">
246
+ <label part="form-control-label" class="form-control__label" for="input"
247
+ aria-hidden=${hasLabel ? 'false' : 'true'}>
248
+ <slot name="label">${this.label}</slot>
249
+ </label>
250
+ ${showActions ? html`
251
+ <div class="translations__actions">
252
+ ${hasExpandSlot ? html`<slot name="expand"></slot>` : nothing}
253
+ ${hasMultipleLanguages ? html`
254
+ <zn-button-group>
255
+ ${visibleTabs.map(code => html`
256
+ <zn-button
257
+ size="x-small"
258
+ color="default"
259
+ ?outline="${code !== this._activeLanguage}"
260
+ @click="${() => this.switchLanguage(code)}"
261
+ >${code.toUpperCase()}
262
+ </zn-button>
263
+ `)}
264
+ ${availableLanguages.length > 0 ? html`
265
+ <zn-dropdown placement="bottom-end">
266
+ <zn-button
267
+ slot="trigger"
268
+ size="x-small"
269
+ color="default"
270
+ outline
271
+ >+
272
+ </zn-button>
273
+ <zn-menu
274
+ .actions=${availableLanguages}
275
+ @zn-menu-select="${this.handleLanguageAdd}"
276
+ ></zn-menu>
277
+ </zn-dropdown>
278
+ ` : nothing}
279
+ </zn-button-group>
280
+ ` : nothing}
281
+ </div>
282
+ ` : nothing}
283
+ </div>
284
+
285
+ <div part="form-control-input" class="translations__body">
268
286
  ${keyed(this._activeLanguage, html`
269
287
  <zn-inline-edit
270
288
  .value=${live(currentTranslation)}
@@ -5,41 +5,40 @@
5
5
  }
6
6
 
7
7
  .translations {
8
+ padding: var(--zn-spacing-small) var(--zn-spacing-medium);
9
+ }
10
+
11
+ .translations__header {
8
12
  display: flex;
9
- flex-direction: column;
10
- padding: 0 var(--zn-spacing-medium);
11
- gap: var(--zn-spacing-3x-small);
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ gap: var(--zn-spacing-small);
16
+ margin-bottom: var(--zn-spacing-2x-small);
17
+ min-height: var(--zn-input-height-small);
12
18
  }
13
19
 
14
- .translations--grouped {
15
- padding: 0;
20
+ .translations__actions {
21
+ display: flex;
22
+ align-items: center;
23
+ gap: var(--zn-spacing-x-small);
24
+ margin-left: auto;
16
25
  }
17
26
 
18
- .input-container {
19
- padding: var(--zn-spacing-small) 0;
27
+ .translations__body {
28
+ display: block;
20
29
  }
21
30
 
22
31
  .form-control__label {
23
32
  margin-bottom: 0 !important;
24
33
  }
25
34
 
26
-
27
- zn-navbar {
28
- overflow: hidden;
29
- margin-top: var(--zn-spacing-x-small);
30
- }
31
-
32
- zn-navbar::part(navbar) {
33
- padding: 0 0 0 7px;
34
- gap: 15px;
35
- }
36
-
37
- zn-navbar::part(navbar-item) {
38
- font-size: var(--zn-font-size-small);
39
-
40
- --zn-spacing-medium: 7px;
35
+ .translations--flush,
36
+ .translations--grouped {
37
+ padding: 0;
41
38
  }
42
39
 
43
- zn-navbar::part(button__base) {
44
- //padding: 0 5px;
40
+ .translations--grouped {
41
+ .translations__header {
42
+ margin-bottom: 0;
43
+ }
45
44
  }