@jetbrains/ring-ui 5.0.50 → 5.0.52

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.
@@ -0,0 +1,10 @@
1
+ import { PureComponent, ReactNode } from 'react';
2
+ interface InputLabelProps {
3
+ htmlFor?: string;
4
+ disabled?: boolean;
5
+ label: ReactNode;
6
+ }
7
+ export declare class InputLabel extends PureComponent<InputLabelProps> {
8
+ render(): JSX.Element;
9
+ }
10
+ export default InputLabel;
@@ -0,0 +1,18 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import styles from './input.css';
5
+ export class InputLabel extends PureComponent {
6
+ render() {
7
+ const { htmlFor, label, disabled } = this.props;
8
+ return (<label htmlFor={htmlFor} className={classNames(styles.label, {
9
+ [styles.disabledLabel]: disabled
10
+ })}>{label}</label>);
11
+ }
12
+ }
13
+ InputLabel.propTypes = {
14
+ label: PropTypes.node,
15
+ disabled: PropTypes.bool,
16
+ id: PropTypes.string
17
+ };
18
+ export default InputLabel;
@@ -9,6 +9,7 @@ import Icon from '../icon/icon';
9
9
  import composeRefs from '../global/composeRefs';
10
10
  import { ControlsHeightContext } from '../global/controls-height';
11
11
  import styles from './input.css';
12
+ import { InputLabel } from './input-label';
12
13
  function noop() { }
13
14
  /**
14
15
  * @name Input
@@ -117,9 +118,7 @@ export class Input extends PureComponent {
117
118
  'data-enabled-shortcuts': Array.isArray(enableShortcuts) ? enableShortcuts.join(',') : null
118
119
  };
119
120
  return (<div className={classes} data-test="ring-input">
120
- {label && (<label htmlFor={this.getId()} className={classNames(styles.label, {
121
- [styles.disabledLabel]: disabled
122
- })}>{label}</label>)}
121
+ {label && (<InputLabel htmlFor={this.getId()} disabled={disabled} label={label}/>)}
123
122
  <div className={styles.container}>
124
123
  {icon && <Icon glyph={icon} className={styles.icon}/>}
125
124
  {multiline
@@ -800,7 +800,7 @@ export default class QueryAssist extends Component {
800
800
 
801
801
  <PopupMenu hidden={!this.state.showPopup} onCloseAttempt={this.closePopup} ref={this.popupRef} anchorElement={this.node} keepMounted attached className={this.props.popupClassName} directions={[PopupMenu.PopupProps.Directions.BOTTOM_RIGHT]} data={useCustomItemRender ? this.state.suggestions : this.renderSuggestions()} data-test="ring-query-assist-popup" hint={this.props.hint} hintOnSelection={this.props.hintOnSelection} left={this.getPopupOffset(this.state.suggestions)} maxHeight={PopupMenu.PopupProps.MaxHeight.SCREEN} onMouseDown={this.trackPopupMouseState} onMouseUp={this.trackPopupMouseState} onSelect={item => this.handleComplete(item)}/>
802
802
 
803
- {glass && huge && (<div className={styles.rightSearchButton}>
803
+ {glass && huge && (<div className={styles.rightSearchButton} data-test="query-assist-search-button">
804
804
  <Icon glyph={searchIcon} className={styles.rightSearchIcon} title={this.props.translations.searchTitle} onClick={this.handleApply} ref={this.glassRef} data-test="query-assist-search-icon"/>
805
805
  </div>)}
806
806
  </div>
@@ -236,6 +236,7 @@ export default class Select<T = unknown> extends Component<SelectProps<T>, Selec
236
236
  clear: (event?: Event | SyntheticEvent) => boolean;
237
237
  _selectionIsEmpty(): boolean;
238
238
  private _getLabel;
239
+ private _getPlaceholder;
239
240
  _getSelectedString(): string | null;
240
241
  private _getIcons;
241
242
  private _getAvatar;
@@ -9,6 +9,7 @@ import Avatar, { Size as AvatarSize } from '../avatar/avatar';
9
9
  import Popup from '../popup/popup';
10
10
  import List, { ActiveItemContext } from '../list/list';
11
11
  import Input, { Size } from '../input/input';
12
+ import InputLabel from '../input/input-label';
12
13
  import Shortcuts from '../shortcuts/shortcuts';
13
14
  import Button from '../button/button';
14
15
  import dataTests from '../global/data-tests';
@@ -717,6 +718,12 @@ export default class Select extends Component {
717
718
  _getLabel() {
718
719
  return this.props.label ?? this.props.selectedLabel ?? 'Select an option';
719
720
  }
721
+ _getPlaceholder() {
722
+ if (this._selectionIsEmpty()) {
723
+ return this.props.label ?? 'Select an option';
724
+ }
725
+ return this._getSelectedString();
726
+ }
720
727
  _getSelectedString() {
721
728
  if (Array.isArray(this.state.selected)) {
722
729
  const labels = [];
@@ -767,6 +774,7 @@ export default class Select extends Component {
767
774
  }
768
775
  renderSelect(activeItemId) {
769
776
  const dataTest = this.props['data-test'];
777
+ const { selectedLabel } = this.props;
770
778
  const { shortcutsEnabled } = this.state;
771
779
  const classes = classNames(styles.select, 'ring-js-shortcuts', this.props.className, styles[`height${this.props.height || this.context}`], {
772
780
  [styles[`size${this.props.size}`]]: this.props.type !== Type.INLINE,
@@ -798,13 +806,14 @@ export default class Select extends Component {
798
806
  </div>);
799
807
  case Type.BUTTON:
800
808
  return (<div ref={this.nodeRef} className={classNames(classes, styles.buttonMode)} data-test={dataTests('ring-select', dataTest)}>
809
+ {selectedLabel && (<InputLabel label={selectedLabel} disabled={this.props.disabled} htmlFor={this.props.id}/>)}
801
810
  {shortcutsEnabled && (<Shortcuts map={this.getShortcutsMap()} scope={this.shortcutsScope}/>)}
802
811
  <div className={styles.buttonContainer}>
803
812
  <Button {...ariaProps} height={this.props.height} id={this.props.id} onClick={this._clickHandler} className={classNames(this.props.buttonClassName, styles.buttonValue, {
804
813
  [styles.buttonValueOpen]: this.state.showPopup
805
814
  })} disabled={this.props.disabled} style={style} data-test="ring-select__button ring-select__focus">
806
815
  {this._getAvatar()}
807
- {this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString()}
816
+ {this._getPlaceholder()}
808
817
  </Button>
809
818
  {iconsNode}
810
819
  </div>
@@ -814,7 +823,7 @@ export default class Select extends Component {
814
823
  return (<div className={classes} ref={this.nodeRef} data-test={dataTests('ring-select', dataTest)}>
815
824
  {shortcutsEnabled && (<Shortcuts map={this.getShortcutsMap()} scope={this.shortcutsScope}/>)}
816
825
  <Anchor {...ariaProps} id={this.props.id} onClick={this._clickHandler} data-test="ring-select__focus" disabled={this.props.disabled} active={this.state.showPopup}>
817
- {this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString()}
826
+ {this._getPlaceholder()}
818
827
  </Anchor>
819
828
  {this._renderPopup()}
820
829
  </div>);
@@ -832,7 +841,7 @@ export default class Select extends Component {
832
841
  id: this.props.id,
833
842
  onClick: this._clickHandler,
834
843
  disabled: this.props.disabled,
835
- children: this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString(),
844
+ children: this._getPlaceholder(),
836
845
  'data-test': 'ring-select_focus'
837
846
  },
838
847
  popup: this._renderPopup()
@@ -22,6 +22,7 @@ import '../_helpers/button__classes.js';
22
22
  import '../global/get-uid.js';
23
23
  import '../global/composeRefs.js';
24
24
  import '../_helpers/input.js';
25
+ import '../input/input-label.js';
25
26
  import 'date-fns/add';
26
27
 
27
28
  class DateInput extends React.PureComponent {
@@ -83,6 +83,7 @@ import '@jetbrains/icons/close-12px';
83
83
  import '../global/prop-types.js';
84
84
  import '../global/composeRefs.js';
85
85
  import '../_helpers/input.js';
86
+ import '../input/input-label.js';
86
87
 
87
88
  const PopupComponent = _ref => {
88
89
  let {
@@ -30,6 +30,7 @@ import '../_helpers/button__classes.js';
30
30
  import '../global/get-uid.js';
31
31
  import '../global/composeRefs.js';
32
32
  import '../_helpers/input.js';
33
+ import '../input/input-label.js';
33
34
  import 'date-fns/add';
34
35
  import 'date-fns/addMonths';
35
36
  import 'date-fns/getDay';
@@ -24,6 +24,7 @@ import '../_helpers/button__classes.js';
24
24
  import '@jetbrains/icons/close-12px';
25
25
  import '../global/prop-types.js';
26
26
  import '../global/composeRefs.js';
27
+ import '../input/input-label.js';
27
28
  import '../shortcuts/core.js';
28
29
  import 'combokeys';
29
30
  import '../global/sniffer.js';
@@ -0,0 +1,10 @@
1
+ import { PureComponent, ReactNode } from 'react';
2
+ interface InputLabelProps {
3
+ htmlFor?: string;
4
+ disabled?: boolean;
5
+ label: ReactNode;
6
+ }
7
+ export declare class InputLabel extends PureComponent<InputLabelProps> {
8
+ render(): JSX.Element;
9
+ }
10
+ export default InputLabel;
@@ -0,0 +1,27 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import { m as modules_88cfaf40 } from '../_helpers/input.js';
5
+
6
+ class InputLabel extends PureComponent {
7
+ render() {
8
+ const {
9
+ htmlFor,
10
+ label,
11
+ disabled
12
+ } = this.props;
13
+ return /*#__PURE__*/React.createElement("label", {
14
+ htmlFor: htmlFor,
15
+ className: classNames(modules_88cfaf40.label, {
16
+ [modules_88cfaf40.disabledLabel]: disabled
17
+ })
18
+ }, label);
19
+ }
20
+ }
21
+ InputLabel.propTypes = {
22
+ label: PropTypes.node,
23
+ disabled: PropTypes.bool,
24
+ id: PropTypes.string
25
+ };
26
+
27
+ export { InputLabel, InputLabel as default };
@@ -10,6 +10,7 @@ import Icon from '../icon/icon.js';
10
10
  import composeRefs from '../global/composeRefs.js';
11
11
  import { ControlsHeightContext } from '../global/controls-height.js';
12
12
  import { m as modules_88cfaf40 } from '../_helpers/input.js';
13
+ import { InputLabel } from './input-label.js';
13
14
  import 'focus-visible';
14
15
  import '@jetbrains/icons/chevron-10px';
15
16
  import '../link/clickableLink.js';
@@ -150,12 +151,11 @@ class Input extends PureComponent {
150
151
  return /*#__PURE__*/React.createElement("div", {
151
152
  className: classes,
152
153
  "data-test": "ring-input"
153
- }, label && /*#__PURE__*/React.createElement("label", {
154
+ }, label && /*#__PURE__*/React.createElement(InputLabel, {
154
155
  htmlFor: this.getId(),
155
- className: classNames(modules_88cfaf40.label, {
156
- [modules_88cfaf40.disabledLabel]: disabled
157
- })
158
- }, label), /*#__PURE__*/React.createElement("div", {
156
+ disabled: disabled,
157
+ label: label
158
+ }), /*#__PURE__*/React.createElement("div", {
159
159
  className: modules_88cfaf40.container
160
160
  }, icon && /*#__PURE__*/React.createElement(Icon, {
161
161
  glyph: icon,
@@ -72,6 +72,7 @@ import '../input/input.js';
72
72
  import '../global/prop-types.js';
73
73
  import '../global/composeRefs.js';
74
74
  import '../_helpers/input.js';
75
+ import '../input/input-label.js';
75
76
  import '../global/rerender-hoc.js';
76
77
  import '../global/react-render-adapter.js';
77
78
  import '../global/fuzzy-highlight.js';
@@ -78,6 +78,7 @@ import '../input/input.js';
78
78
  import '../global/prop-types.js';
79
79
  import '../global/composeRefs.js';
80
80
  import '../_helpers/input.js';
81
+ import '../input/input-label.js';
81
82
  import '../global/rerender-hoc.js';
82
83
  import '../global/fuzzy-highlight.js';
83
84
  import '../select/select__popup.js';
@@ -71,6 +71,7 @@ import '../global/composeRefs.js';
71
71
  import '@jetbrains/icons/chevron-10px';
72
72
  import '../_helpers/button__classes.js';
73
73
  import '../global/prop-types.js';
74
+ import '../input/input-label.js';
74
75
 
75
76
  const POPUP_COMPENSATION = PopupMenu.ListProps.Dimension.ITEM_PADDING + PopupMenu.PopupProps.Dimension.BORDER_WIDTH;
76
77
  const ngModelStateField = 'query';
@@ -860,7 +861,8 @@ class QueryAssist extends Component {
860
861
  onMouseUp: this.trackPopupMouseState,
861
862
  onSelect: item => this.handleComplete(item)
862
863
  }), glass && huge && /*#__PURE__*/React.createElement("div", {
863
- className: modules_da7ab055.rightSearchButton
864
+ className: modules_da7ab055.rightSearchButton,
865
+ "data-test": "query-assist-search-button"
864
866
  }, /*#__PURE__*/React.createElement(Icon, {
865
867
  glyph: searchIcon,
866
868
  className: modules_da7ab055.rightSearchIcon,
@@ -75,6 +75,7 @@ import '../_helpers/button__classes.js';
75
75
  import '../input/input.js';
76
76
  import '../global/prop-types.js';
77
77
  import '../_helpers/input.js';
78
+ import '../input/input-label.js';
78
79
  import '../_helpers/query-assist__suggestions.js';
79
80
 
80
81
  var queryAssistNg = angularComponentFactory(QueryAssist, 'QueryAssist').name;
@@ -236,6 +236,7 @@ export default class Select<T = unknown> extends Component<SelectProps<T>, Selec
236
236
  clear: (event?: Event | SyntheticEvent) => boolean;
237
237
  _selectionIsEmpty(): boolean;
238
238
  private _getLabel;
239
+ private _getPlaceholder;
239
240
  _getSelectedString(): string | null;
240
241
  private _getIcons;
241
242
  private _getAvatar;
@@ -10,6 +10,7 @@ import Avatar, { Size as Size$1 } from '../avatar/avatar.js';
10
10
  import Popup from '../popup/popup.js';
11
11
  import List, { ActiveItemContext } from '../list/list.js';
12
12
  import { Size, Input } from '../input/input.js';
13
+ import { InputLabel } from '../input/input-label.js';
13
14
  import Shortcuts from '../shortcuts/shortcuts.js';
14
15
  import { Button } from '../button/button.js';
15
16
  import joinDataTestAttributes from '../global/data-tests.js';
@@ -830,6 +831,13 @@ class Select extends Component {
830
831
  var _ref2, _this$props$label;
831
832
  return (_ref2 = (_this$props$label = this.props.label) !== null && _this$props$label !== void 0 ? _this$props$label : this.props.selectedLabel) !== null && _ref2 !== void 0 ? _ref2 : 'Select an option';
832
833
  }
834
+ _getPlaceholder() {
835
+ if (this._selectionIsEmpty()) {
836
+ var _this$props$label2;
837
+ return (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : 'Select an option';
838
+ }
839
+ return this._getSelectedString();
840
+ }
833
841
  _getSelectedString() {
834
842
  if (Array.isArray(this.state.selected)) {
835
843
  const labels = [];
@@ -911,8 +919,11 @@ class Select extends Component {
911
919
  };
912
920
  }
913
921
  renderSelect(activeItemId) {
914
- var _this$props$label2, _this$props$label3, _this$_popup5, _this$_popup5$list;
922
+ var _this$props$label3, _this$props$label4, _this$_popup5, _this$_popup5$list;
915
923
  const dataTest = this.props['data-test'];
924
+ const {
925
+ selectedLabel
926
+ } = this.props;
916
927
  const {
917
928
  shortcutsEnabled
918
929
  } = this.state;
@@ -928,9 +939,9 @@ class Select extends Component {
928
939
  const ariaProps = this.state.showPopup ? {
929
940
  'aria-owns': this.listId,
930
941
  'aria-activedescendant': activeItemId,
931
- 'aria-label': (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : undefined
932
- } : {
933
942
  'aria-label': (_this$props$label3 = this.props.label) !== null && _this$props$label3 !== void 0 ? _this$props$label3 : undefined
943
+ } : {
944
+ 'aria-label': (_this$props$label4 = this.props.label) !== null && _this$props$label4 !== void 0 ? _this$props$label4 : undefined
934
945
  };
935
946
  switch (this.props.type) {
936
947
  case Type.INPUT_WITHOUT_CONTROLS:
@@ -971,7 +982,11 @@ class Select extends Component {
971
982
  ref: this.nodeRef,
972
983
  className: classNames(classes, modules_9d0de074.buttonMode),
973
984
  "data-test": joinDataTestAttributes('ring-select', dataTest)
974
- }, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
985
+ }, selectedLabel && /*#__PURE__*/React.createElement(InputLabel, {
986
+ label: selectedLabel,
987
+ disabled: this.props.disabled,
988
+ htmlFor: this.props.id
989
+ }), shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
975
990
  map: this.getShortcutsMap(),
976
991
  scope: this.shortcutsScope
977
992
  }), /*#__PURE__*/React.createElement("div", {
@@ -986,7 +1001,7 @@ class Select extends Component {
986
1001
  disabled: this.props.disabled,
987
1002
  style: style,
988
1003
  "data-test": "ring-select__button ring-select__focus"
989
- }), this._getAvatar(), this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString()), iconsNode), this._renderPopup());
1004
+ }), this._getAvatar(), this._getPlaceholder()), iconsNode), this._renderPopup());
990
1005
  case Type.INLINE:
991
1006
  return /*#__PURE__*/React.createElement("div", {
992
1007
  className: classes,
@@ -1001,7 +1016,7 @@ class Select extends Component {
1001
1016
  "data-test": "ring-select__focus",
1002
1017
  disabled: this.props.disabled,
1003
1018
  active: this.state.showPopup
1004
- }), this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString()), this._renderPopup());
1019
+ }), this._getPlaceholder()), this._renderPopup());
1005
1020
  default:
1006
1021
  if (this.props.customAnchor) {
1007
1022
  return /*#__PURE__*/React.createElement(Fragment, null, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
@@ -1017,7 +1032,7 @@ class Select extends Component {
1017
1032
  id: this.props.id,
1018
1033
  onClick: this._clickHandler,
1019
1034
  disabled: this.props.disabled,
1020
- children: this._selectionIsEmpty() ? this._getLabel() : this._getSelectedString(),
1035
+ children: this._getPlaceholder(),
1021
1036
  'data-test': 'ring-select_focus'
1022
1037
  },
1023
1038
  popup: this._renderPopup()
@@ -23,6 +23,7 @@ import '../_helpers/button__classes.js';
23
23
  import '../global/get-uid.js';
24
24
  import '../global/composeRefs.js';
25
25
  import '../_helpers/input.js';
26
+ import '../input/input-label.js';
26
27
  import 'sniffr';
27
28
  import 'react-virtualized/dist/es/List';
28
29
  import 'react-virtualized/dist/es/AutoSizer';
@@ -68,6 +68,7 @@ import '../input/input.js';
68
68
  import '../global/prop-types.js';
69
69
  import '../global/composeRefs.js';
70
70
  import '../_helpers/input.js';
71
+ import '../input/input-label.js';
71
72
 
72
73
  const FILTER_HEIGHT = 35;
73
74
  const TOOLBAR_HEIGHT = 49;
@@ -70,6 +70,7 @@ import '../input/input.js';
70
70
  import '../global/prop-types.js';
71
71
  import '../global/composeRefs.js';
72
72
  import '../_helpers/input.js';
73
+ import '../input/input-label.js';
73
74
  import '../global/rerender-hoc.js';
74
75
  import '../global/fuzzy-highlight.js';
75
76
  import '../select/select__popup.js';
@@ -67,6 +67,7 @@ import '../input/input.js';
67
67
  import '../global/prop-types.js';
68
68
  import '../global/composeRefs.js';
69
69
  import '../_helpers/input.js';
70
+ import '../input/input-label.js';
70
71
  import '../global/rerender-hoc.js';
71
72
  import '../global/fuzzy-highlight.js';
72
73
  import '../select/select__popup.js';
@@ -90,6 +90,7 @@ import '../input/input.js';
90
90
  import '../global/prop-types.js';
91
91
  import '../global/composeRefs.js';
92
92
  import '../_helpers/input.js';
93
+ import '../input/input-label.js';
93
94
  import '../global/rerender-hoc.js';
94
95
  import '../global/fuzzy-highlight.js';
95
96
  import '../select/select__popup.js';
@@ -80,6 +80,7 @@ import '../input/input.js';
80
80
  import '../global/prop-types.js';
81
81
  import '../global/composeRefs.js';
82
82
  import '../_helpers/input.js';
83
+ import '../input/input-label.js';
83
84
  import '../global/rerender-hoc.js';
84
85
  import '../global/fuzzy-highlight.js';
85
86
  import '../select/select__popup.js';
@@ -66,6 +66,7 @@ import '../list/list__title.js';
66
66
  import '../list/list__separator.js';
67
67
  import '../list/list__hint.js';
68
68
  import '../list/consts.js';
69
+ import '../input/input-label.js';
69
70
  import '../global/fuzzy-highlight.js';
70
71
  import '../select/select__popup.js';
71
72
  import '@jetbrains/icons/search';
@@ -71,6 +71,7 @@ import '../input/input.js';
71
71
  import '../global/prop-types.js';
72
72
  import '../global/composeRefs.js';
73
73
  import '../_helpers/input.js';
74
+ import '../input/input-label.js';
74
75
  import '../global/rerender-hoc.js';
75
76
  import '../global/fuzzy-highlight.js';
76
77
  import '../select/select__popup.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui",
3
- "version": "5.0.50",
3
+ "version": "5.0.52",
4
4
  "description": "JetBrains UI library",
5
5
  "author": "JetBrains",
6
6
  "license": "Apache-2.0",
@@ -259,5 +259,5 @@
259
259
  "node": ">=14.0",
260
260
  "npm": ">=6.0.0"
261
261
  },
262
- "gitHead": "f9a86300840ce2acfa803bef4d7b2d554c481a9c"
262
+ "gitHead": "497b3b0144654bd77fb90abcee949fcb6979501c"
263
263
  }