@sveltia/ui 0.14.0 → 0.15.1

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.
@@ -89,6 +89,16 @@
89
89
  * @type {Modal}
90
90
  */
91
91
  let modal;
92
+ /**
93
+ * @type {HTMLElement | undefined}
94
+ */
95
+ let content;
96
+
97
+ $: {
98
+ if (open && content) {
99
+ /** @type {HTMLElement} */ (content.querySelector('input, button.primary'))?.focus();
100
+ }
101
+ }
92
102
  </script>
93
103
 
94
104
  <Modal
@@ -111,7 +121,7 @@
111
121
  on:close
112
122
  >
113
123
  <slot name="extra-content" slot="extra-content" />
114
- <div role="none" class="content {className} {size}">
124
+ <div role="none" class="content {className} {size}" bind:this={content}>
115
125
  {#if title || showClose || $$slots.header || $$slots['header-extra']}
116
126
  <div role="none" class="header">
117
127
  {#if $$slots.header}
@@ -44,9 +44,14 @@
44
44
  * @type {string}
45
45
  */
46
46
  export let searchValue = label;
47
+ /**
48
+ * Whether to wrap a long label.
49
+ * @type {boolean}
50
+ */
51
+ export let wrap = false;
47
52
  </script>
48
53
 
49
- <div role="none" class="sui option {className}" hidden={hidden || undefined}>
54
+ <div role="none" class="sui option {className}" class:wrap hidden={hidden || undefined}>
50
55
  <Button
51
56
  role="option"
52
57
  tabindex="-1"
@@ -103,9 +108,15 @@
103
108
  border-radius: var(--sui-option-border-radius);
104
109
  padding: var(--sui-option-padding);
105
110
  width: 100%;
106
- height: var(--sui-option-height);
111
+ height: auto;
112
+ min-height: var(--sui-option-height);
113
+ overflow: hidden;
114
+ text-overflow: ellipsis;
107
115
  white-space: nowrap;
108
116
  }
117
+ .option.wrap :global(button) {
118
+ white-space: normal;
119
+ }
109
120
  .option :global(.focused),
110
121
  .option :global(button:hover) {
111
122
  color: var(--sui-highlight-foreground-color);
@@ -15,6 +15,7 @@ export default class Option extends SvelteComponent<{
15
15
  hidden?: boolean | undefined;
16
16
  selected?: boolean | undefined;
17
17
  searchValue?: string | undefined;
18
+ wrap?: boolean | undefined;
18
19
  }, {
19
20
  click: MouseEvent;
20
21
  dblclick: MouseEvent;
@@ -53,6 +54,7 @@ declare const __propDef: {
53
54
  hidden?: boolean | undefined;
54
55
  selected?: boolean | undefined;
55
56
  searchValue?: string | undefined;
57
+ wrap?: boolean | undefined;
56
58
  };
57
59
  events: {
58
60
  click: MouseEvent;
@@ -194,7 +194,7 @@
194
194
  --sui-control-background-color: hsl(var(--sui-background-color-4-hsl));
195
195
  --sui-control-font-family: var(--sui-font-family-default);
196
196
  --sui-control-font-size: var(--sui-font-size-default);
197
- --sui-control-line-height: var(--sui-line-height-default);
197
+ --sui-control-line-height: var(--sui-line-height-compact);
198
198
  --sui-button-small-border-radius: var(--sui-control-small-border-radius);
199
199
  --sui-button-small-padding: var(--sui-control-small-padding);
200
200
  --sui-button-small-height: var(--sui-control-small-height);
@@ -211,7 +211,8 @@
211
211
  --sui-checkbox-border-color: hsl(var(--sui-border-color-1-hsl));
212
212
  --sui-checkbox-background-color: var(--sui-control-background-color);
213
213
  --sui-option-border-radius: var(--sui-control-medium-border-radius);
214
- --sui-option-padding: var(--sui-control-medium-padding);
214
+ --sui-option-padding: calc((var(--sui-control-medium-height) / 6))
215
+ calc((var(--sui-control-medium-height) / 2));
215
216
  --sui-option-height: var(--sui-control-medium-height);
216
217
  --sui-listbox-border-radius: var(--sui-control-medium-border-radius);
217
218
  --sui-listbox-border-color: var(--sui-control-border-color);
@@ -137,7 +137,8 @@
137
137
  class:touch
138
138
  style:inset={$style.inset}
139
139
  style:z-index={$style.zIndex}
140
- style:min-width={$style.width}
140
+ style:width={$style.width}
141
+ style:min-width={$style.minWidth}
141
142
  style:max-height={$style.height}
142
143
  style:visibility={$style.inset ? undefined : 'hidden'}
143
144
  bind:this={content}
@@ -26,8 +26,8 @@ class Popup {
26
26
  return;
27
27
  }
28
28
 
29
- const { scrollHeight: contentHeight, scrollWidth: contentWidth } =
30
- /** @type {HTMLElement} */ (this.popupElement.querySelector('.content'));
29
+ const content = /** @type {HTMLElement} */ (this.popupElement.querySelector('.content'));
30
+ const { scrollHeight: contentHeight, scrollWidth: contentWidth } = content;
31
31
  const topMargin = intersectionRect.top - 8;
32
32
  const bottomMargin = rootBounds.height - intersectionRect.bottom - 8;
33
33
  let { position } = this;
@@ -77,7 +77,8 @@ class Popup {
77
77
  const style = {
78
78
  inset: [top, right, bottom, left].join(' '),
79
79
  zIndex: anchorPopup ? Number(anchorPopup.style.zIndex) + 1 : 1000,
80
- width: `${Math.round(intersectionRect.width)}px`,
80
+ width: content.matches('.menu') ? 'auto' : `${Math.round(intersectionRect.width)}px`,
81
+ minWidth: `${Math.round(intersectionRect.width)}px`,
81
82
  height: height ? `${Math.round(height)}px` : 'auto',
82
83
  };
83
84
 
@@ -170,6 +171,11 @@ class Popup {
170
171
 
171
172
  this.anchorElement.setAttribute('aria-expanded', String(open));
172
173
  });
174
+
175
+ // Update the popup width when the base element is resized
176
+ new ResizeObserver(() => {
177
+ this.checkPosition();
178
+ }).observe(this.positionBaseElement);
173
179
  }
174
180
 
175
181
  /**
@@ -184,7 +184,7 @@
184
184
  --sui-control-background-color: hsl(var(--sui-background-color-4-hsl));
185
185
  --sui-control-font-family: var(--sui-font-family-default);
186
186
  --sui-control-font-size: var(--sui-font-size-default);
187
- --sui-control-line-height: var(--sui-line-height-default);
187
+ --sui-control-line-height: var(--sui-line-height-compact);
188
188
  // Button
189
189
  --sui-button-small-border-radius: var(--sui-control-small-border-radius);
190
190
  --sui-button-small-padding: var(--sui-control-small-padding);
@@ -204,7 +204,8 @@
204
204
  --sui-checkbox-background-color: var(--sui-control-background-color);
205
205
  // Option & menu item
206
206
  --sui-option-border-radius: var(--sui-control-medium-border-radius);
207
- --sui-option-padding: var(--sui-control-medium-padding);
207
+ --sui-option-padding: calc((var(--sui-control-medium-height) / 6))
208
+ calc((var(--sui-control-medium-height) / 2));
208
209
  --sui-option-height: var(--sui-control-medium-height);
209
210
  // Listbox
210
211
  --sui-listbox-border-radius: var(--sui-control-medium-border-radius);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {