@theia/core 1.38.0-next.0 → 1.38.0-next.7

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.
@@ -34,11 +34,12 @@ export interface SelectOption {
34
34
  }
35
35
 
36
36
  export interface SelectComponentProps {
37
- options: SelectOption[]
37
+ options: readonly SelectOption[]
38
38
  defaultValue?: string | number
39
39
  onChange?: (option: SelectOption, index: number) => void,
40
40
  onBlur?: () => void,
41
- onFocus?: () => void
41
+ onFocus?: () => void,
42
+ alignment?: 'left' | 'right';
42
43
  }
43
44
 
44
45
  export interface SelectComponentState {
@@ -81,7 +82,7 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
81
82
  this.dropdownElement = list;
82
83
  }
83
84
 
84
- get options(): SelectOption[] {
85
+ get options(): readonly SelectOption[] {
85
86
  return this.props.options;
86
87
  }
87
88
 
@@ -105,6 +106,10 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
105
106
  }
106
107
  }
107
108
 
109
+ protected get alignLeft(): boolean {
110
+ return this.props.alignment !== 'right';
111
+ }
112
+
108
113
  protected getOptimalWidth(): number {
109
114
  const textWidth = measureTextWidth(this.props.options.map(e => e.label || e.value || '' + (e.detail || '')));
110
115
  return Math.ceil(textWidth + 16);
@@ -168,7 +173,7 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
168
173
  if (options[selected]?.separator) {
169
174
  selected = this.nextNotSeparator('forwards');
170
175
  }
171
- const selectedItemLabel = options[selected].label ?? options[selected].value;
176
+ const selectedItemLabel = options[selected]?.label ?? options[selected]?.value;
172
177
  return <>
173
178
  <div
174
179
  key="select-component"
@@ -279,6 +284,9 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
279
284
  if (!this.state.dimensions) {
280
285
  return;
281
286
  }
287
+
288
+ const shellArea = document.getElementById('theia-app-shell')!.getBoundingClientRect();
289
+ const maxWidth = this.alignLeft ? shellArea.width - this.state.dimensions.left : this.state.dimensions.right;
282
290
  if (this.mountedListeners.size === 0) {
283
291
  // Only attach our listeners once we render our dropdown menu
284
292
  this.attachListeners();
@@ -286,11 +294,11 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
286
294
  this.optimalWidth = this.getOptimalWidth();
287
295
  this.optimalHeight = this.getOptimalHeight(Math.max(this.state.dimensions.width, this.optimalWidth));
288
296
  }
289
- const clientRect = document.getElementById('theia-app-shell')!.getBoundingClientRect();
290
- const availableTop = this.state.dimensions.top - clientRect.top;
291
- const availableBottom = clientRect.top + clientRect.height - this.state.dimensions.bottom;
297
+ const availableTop = this.state.dimensions.top - shellArea.top;
298
+ const availableBottom = shellArea.top + shellArea.height - this.state.dimensions.bottom;
292
299
  // prefer rendering to the bottom unless there is not enough space and more content can be shown to the top
293
300
  const invert = availableBottom < this.optimalHeight && (availableBottom - this.optimalHeight) < (availableTop - this.optimalHeight);
301
+
294
302
  const { options } = this.props;
295
303
  const { hover } = this.state;
296
304
  const description = options[hover].description;
@@ -313,14 +321,14 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
313
321
  items.push(descriptionNode);
314
322
  }
315
323
  }
316
- const calculatedWidth = Math.max(this.state.dimensions.width, this.optimalWidth);
317
- const maxWidth = clientRect.width - this.state.dimensions.left;
324
+
318
325
  return <div key="dropdown" className="theia-select-component-dropdown" style={{
319
326
  top: invert ? 'none' : this.state.dimensions.bottom,
320
- bottom: invert ? clientRect.top + clientRect.height - this.state.dimensions.top : 'none',
321
- left: this.state.dimensions.left,
322
- width: Math.min(calculatedWidth, maxWidth),
323
- maxHeight: clientRect.height - (invert ? clientRect.height - this.state.dimensions.bottom : this.state.dimensions.top) - this.state.dimensions.height,
327
+ bottom: invert ? shellArea.top + shellArea.height - this.state.dimensions.top : 'none',
328
+ left: this.alignLeft ? this.state.dimensions.left : 'none',
329
+ right: this.alignLeft ? 'none' : shellArea.width - this.state.dimensions.right,
330
+ width: Math.min(Math.max(this.state.dimensions.width, this.optimalWidth), maxWidth),
331
+ maxHeight: shellArea.height - (invert ? shellArea.height - this.state.dimensions.bottom : this.state.dimensions.top) - this.state.dimensions.height,
324
332
  position: 'absolute'
325
333
  }} ref={this.dropdownRef}>
326
334
  {items}