@jetbrains/ring-ui 6.0.37 → 6.0.38

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.
@@ -13,6 +13,7 @@ export interface ConfirmProps {
13
13
  onConfirm: ((event: React.MouseEvent<HTMLButtonElement>) => void);
14
14
  onReject: ((event?: React.MouseEvent<HTMLButtonElement>) => void);
15
15
  className?: string | undefined;
16
+ native?: boolean;
16
17
  }
17
18
  /**
18
19
  * @name Confirm
@@ -41,8 +41,8 @@ export default class Confirm extends PureComponent {
41
41
  }
42
42
  };
43
43
  render() {
44
- const { show, className, inProgress, cancelIsDefault, text, description, confirmLabel, rejectLabel, onConfirm, onReject } = this.props;
45
- return (<Dialog label={text || (typeof description === 'string' ? description : undefined)} className={className} onEscPress={this.onEscPress} show={show} trapFocus data-test="ring-confirm">
44
+ const { show, className, inProgress, cancelIsDefault, text, description, confirmLabel, rejectLabel, onConfirm, onReject, native } = this.props;
45
+ return (<Dialog label={text || (typeof description === 'string' ? description : undefined)} className={className} onEscPress={this.onEscPress} show={show} trapFocus data-test="ring-confirm" native={native}>
46
46
  {text && <Header>{text}</Header>}
47
47
  {description && (<Content>
48
48
  <div className={styles.description}>{description}</div>
@@ -1,6 +1,6 @@
1
1
  @import "../global/variables.css";
2
2
 
3
- @value header from "../island/island.css";
3
+ @value header, scrollableWrapper from "../island/island.css";
4
4
 
5
5
  .container {
6
6
  position: fixed;
@@ -16,7 +16,18 @@
16
16
  justify-content: center;
17
17
 
18
18
  padding: calc(var(--ring-unit) * 4) var(--ring-unit);
19
+ }
20
+
21
+ .nativeDialog {
22
+ overflow: visible;
23
+
24
+ padding: 0;
25
+
26
+ border: none;
27
+ }
19
28
 
29
+ .container,
30
+ .nativeDialog::backdrop {
20
31
  background-color: rgba(var(--ring-dialog-overlay-components), var(--ring-dialog-overlay-opacity));
21
32
  }
22
33
 
@@ -37,7 +48,7 @@
37
48
  cursor: default;
38
49
  overflow-wrap: break-word;
39
50
 
40
- & [data-scrollable-container] {
51
+ & .scrollableWrapper {
41
52
  padding-bottom: var(--ring-unit);
42
53
  }
43
54
 
@@ -121,7 +132,7 @@
121
132
  }
122
133
  }
123
134
 
124
- .container .header {
135
+ .innerContainer .header {
125
136
  padding-top: calc(var(--ring-unit) * 4);
126
137
 
127
138
  font-size: 24px;
@@ -19,6 +19,8 @@ export interface DialogProps extends Partial<TabTrapProps> {
19
19
  portalTarget?: Element | null | undefined;
20
20
  'data-test'?: string | null | undefined;
21
21
  dense?: boolean | null | undefined;
22
+ native?: boolean;
23
+ modal?: boolean;
22
24
  }
23
25
  export default class Dialog extends PureComponent<DialogProps> {
24
26
  static propTypes: {
@@ -52,6 +54,7 @@ export default class Dialog extends PureComponent<DialogProps> {
52
54
  reset: () => void;
53
55
  };
54
56
  uid: string;
57
+ toggleNativeDialog(): void;
55
58
  toggleScrollPreventer(): void;
56
59
  handleClick: (event: React.MouseEvent<HTMLElement>) => void;
57
60
  onCloseClick: (event: React.MouseEvent<HTMLElement>) => void;
@@ -60,6 +63,7 @@ export default class Dialog extends PureComponent<DialogProps> {
60
63
  };
61
64
  dialog?: HTMLElement | null;
62
65
  dialogRef: (tabTrap: TabTrap | null) => void;
63
- render(): false | React.ReactPortal;
66
+ nativeDialog: React.RefObject<HTMLDialogElement>;
67
+ render(): false | React.JSX.Element;
64
68
  }
65
69
  export type DialogAttrs = JSX.LibraryManagedAttributes<typeof Dialog, DialogProps>;
@@ -1,4 +1,4 @@
1
- import { PureComponent } from 'react';
1
+ import { createRef, PureComponent } from 'react';
2
2
  import * as React from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import PropTypes from 'prop-types';
@@ -53,15 +53,24 @@ export default class Dialog extends PureComponent {
53
53
  closeButtonInside: false,
54
54
  shortcutOptions: { modal: false },
55
55
  trapFocus: false,
56
- autoFocusFirst: true
56
+ autoFocusFirst: true,
57
+ modal: true
57
58
  };
58
59
  state = {
59
60
  shortcutsScope: getUID('ring-dialog-')
60
61
  };
61
62
  componentDidMount() {
63
+ const { show, native } = this.props;
64
+ if (native && show) {
65
+ this.toggleNativeDialog();
66
+ }
62
67
  this.toggleScrollPreventer();
63
68
  }
64
69
  componentDidUpdate(prevProps) {
70
+ const { show, native } = this.props;
71
+ if (native && show !== prevProps.show) {
72
+ this.toggleNativeDialog();
73
+ }
65
74
  if (prevProps.show !== this.props.show) {
66
75
  this.toggleScrollPreventer();
67
76
  }
@@ -71,6 +80,17 @@ export default class Dialog extends PureComponent {
71
80
  }
72
81
  scrollPreventer = scrollPreventerFactory(getUID('preventer-'));
73
82
  uid = getUID('dialog-');
83
+ toggleNativeDialog() {
84
+ const { show, modal } = this.props;
85
+ if (this.nativeDialog.current != null) {
86
+ if (show) {
87
+ modal ? this.nativeDialog.current.showModal() : this.nativeDialog.current.show();
88
+ }
89
+ else {
90
+ this.nativeDialog.current.close();
91
+ }
92
+ }
93
+ }
74
94
  toggleScrollPreventer() {
75
95
  if (this.props.show) {
76
96
  this.scrollPreventer.prevent();
@@ -102,26 +122,37 @@ export default class Dialog extends PureComponent {
102
122
  dialogRef = (tabTrap) => {
103
123
  this.dialog = tabTrap && tabTrap.node;
104
124
  };
125
+ nativeDialog = createRef();
105
126
  render() {
106
- const { show, showCloseButton, onOverlayClick, onCloseAttempt, onEscPress, onCloseClick, children, className, contentClassName, trapFocus, 'data-test': dataTest, closeButtonInside, portalTarget, label, closeButtonTitle, dense, shortcutOptions, ...restProps } = this.props;
127
+ const { show, showCloseButton, onOverlayClick, onCloseAttempt, onEscPress, onCloseClick, children, className, contentClassName, trapFocus, 'data-test': dataTest, closeButtonInside, portalTarget, label, closeButtonTitle, dense, shortcutOptions, native, modal, ...restProps } = this.props;
107
128
  const classes = classNames(styles.container, className);
108
129
  const shortcutsMap = this.getShortcutsMap();
130
+ const content = (<>
131
+ <Shortcuts map={shortcutsMap} scope={this.state.shortcutsScope} options={this.props.shortcutOptions}/>
132
+ {(onOverlayClick !== noop || onCloseAttempt !== noop) && (<div
133
+ // click handler is duplicated in close button
134
+ role="presentation" className={styles.clickableOverlay} onClick={this.handleClick}/>)}
135
+ <div className={styles.innerContainer}>
136
+ <AdaptiveIsland className={classNames(styles.content, contentClassName, { [styles.dense]: dense })} data-test="ring-dialog" role="dialog" aria-label={label}>
137
+ {children}
138
+ {showCloseButton &&
139
+ (<Button icon={closeIcon} data-test="ring-dialog-close-button" className={classNames(styles.closeButton, {
140
+ [styles.closeButtonOutside]: !closeButtonInside,
141
+ [styles.closeButtonInside]: closeButtonInside
142
+ })} iconClassName={styles.closeIcon} onClick={this.onCloseClick} title={closeButtonTitle} aria-label={closeButtonTitle || 'close dialog'}/>)}
143
+ </AdaptiveIsland>
144
+ </div>
145
+ </>);
146
+ if (native) {
147
+ return (<dialog className={classNames(styles.nativeDialog, className)} ref={this.nativeDialog}>
148
+ <PopupTarget id={this.uid} className={styles.popupTarget}>
149
+ {target => <>{content}{target}</>}
150
+ </PopupTarget>
151
+ </dialog>);
152
+ }
109
153
  return show && createPortal(<PopupTarget id={this.uid} className={styles.popupTarget}>
110
154
  {target => (<TabTrap trapDisabled={!trapFocus} data-test={dataTests('ring-dialog-container', dataTest)} ref={this.dialogRef} className={classes} role="presentation" {...restProps}>
111
- <Shortcuts map={shortcutsMap} scope={this.state.shortcutsScope} options={this.props.shortcutOptions}/>
112
- {(onOverlayClick !== noop || onCloseAttempt !== noop) && (<div
113
- // click handler is duplicated in close button
114
- role="presentation" className={styles.clickableOverlay} onClick={this.handleClick}/>)}
115
- <div className={styles.innerContainer}>
116
- <AdaptiveIsland className={classNames(styles.content, contentClassName, { [styles.dense]: dense })} data-test="ring-dialog" role="dialog" aria-label={label}>
117
- {children}
118
- {showCloseButton &&
119
- (<Button icon={closeIcon} data-test="ring-dialog-close-button" className={classNames(styles.closeButton, {
120
- [styles.closeButtonOutside]: !closeButtonInside,
121
- [styles.closeButtonInside]: closeButtonInside
122
- })} iconClassName={styles.closeIcon} onClick={this.onCloseClick} title={closeButtonTitle} aria-label={closeButtonTitle || 'close dialog'}/>)}
123
- </AdaptiveIsland>
124
- </div>
155
+ {content}
125
156
  {target}
126
157
  </TabTrap>)}
127
158
  </PopupTarget>, portalTarget instanceof HTMLElement ? portalTarget : document.body);
@@ -1,3 +1,3 @@
1
1
  import { Ref } from 'react';
2
- declare const _default: <T>(...refs: (Ref<T> | undefined)[]) => (value: T | null) => void;
3
- export default _default;
2
+ export default function composeRefs<T>(...refs: (Ref<T> | undefined)[]): (value: T | null) => void;
3
+ export declare function createComposedRef<T>(): import("memoize-one").MemoizedFn<(...refs: (Ref<T> | undefined)[]) => (value: T | null) => void>;
@@ -1,8 +1,14 @@
1
- export default (...refs) => (value) => refs.forEach(ref => {
2
- if (typeof ref === 'function') {
3
- ref(value);
4
- }
5
- else if (ref != null) {
6
- ref.current = value;
7
- }
8
- });
1
+ import memoizeOne from 'memoize-one';
2
+ export default function composeRefs(...refs) {
3
+ return (value) => refs.forEach(ref => {
4
+ if (typeof ref === 'function') {
5
+ ref(value);
6
+ }
7
+ else if (ref != null) {
8
+ ref.current = value;
9
+ }
10
+ });
11
+ }
12
+ export function createComposedRef() {
13
+ return memoizeOne((composeRefs));
14
+ }
@@ -64,6 +64,7 @@ export declare class Input extends PureComponent<InputProps> {
64
64
  stretch(el: HTMLElement | null | undefined): void;
65
65
  adapt(): void;
66
66
  inputRef: (el: HTMLInputElement | HTMLTextAreaElement | null) => void;
67
+ composedInputRef: import("memoize-one").MemoizedFn<(...refs: (Ref<HTMLInputElement | HTMLTextAreaElement> | undefined)[]) => (value: HTMLInputElement | HTMLTextAreaElement | null) => void>;
67
68
  clear: (e: React.MouseEvent<HTMLButtonElement>) => void;
68
69
  handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
69
70
  handleTextareaChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
@@ -8,7 +8,7 @@ import Button from '../button/button';
8
8
  import getUID from '../global/get-uid';
9
9
  import Icon from '../icon/icon';
10
10
  import { I18nContext } from '../i18n/i18n-context';
11
- import composeRefs from '../global/composeRefs';
11
+ import { createComposedRef } from '../global/composeRefs';
12
12
  import { ControlsHeightContext } from '../global/controls-height';
13
13
  import { ControlLabel } from '../control-label/control-label';
14
14
  import ControlHelp from '../control-help/control-help';
@@ -75,6 +75,7 @@ export class Input extends PureComponent {
75
75
  inputRef = (el) => {
76
76
  this.input = el;
77
77
  };
78
+ composedInputRef = createComposedRef();
78
79
  clear = (e) => {
79
80
  this.props.onClear && this.props.onClear(e);
80
81
  };
@@ -109,7 +110,7 @@ export class Input extends PureComponent {
109
110
  const inputClasses = classNames(styles.input, inputClassName);
110
111
  const text = value != null ? value : children;
111
112
  const commonProps = {
112
- ref: composeRefs(this.inputRef, inputRef),
113
+ ref: this.composedInputRef(this.inputRef, inputRef),
113
114
  className: inputClasses,
114
115
  value: text,
115
116
  disabled,
@@ -67,7 +67,7 @@ class Content extends Component {
67
67
  this.calculateScrollPosition();
68
68
  };
69
69
  render() {
70
- const { children, className, bottomBorder, scrollableWrapperClassName, onScroll, onScrollToBottom, fade, ...restProps } = this.props;
70
+ const { children, className, bottomBorder, scrollableWrapperClassName, onScroll, onScrollToBottom, fade, tabIndex, ...restProps } = this.props;
71
71
  const { scrolledToTop, scrolledToBottom } = this.state;
72
72
  const classes = classNames(styles.content, className, {
73
73
  [styles.contentWithTopFade]: fade && !scrolledToTop,
@@ -77,10 +77,7 @@ class Content extends Component {
77
77
  });
78
78
  const scrollableWrapperClasses = classNames(styles.scrollableWrapper, scrollableWrapperClassName);
79
79
  return (<div {...restProps} data-test="ring-island-content" className={classes}>
80
- <div
81
- // it has to be focusable because it can be scrollable
82
- // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
83
- tabIndex={0} data-scrollable-container className={scrollableWrapperClasses} ref={this.setScrollableNodeAndCalculatePosition} onScroll={fade ? this.calculateScrollPosition : noop}>
80
+ <div tabIndex={tabIndex} className={scrollableWrapperClasses} ref={this.setScrollableNodeAndCalculatePosition} onScroll={fade ? this.calculateScrollPosition : noop}>
84
81
  {fade && (<div ref={this.setWrapper}>
85
82
  {children}
86
83
  </div>)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui",
3
- "version": "6.0.37",
3
+ "version": "6.0.38",
4
4
  "description": "JetBrains UI library",
5
5
  "author": "JetBrains",
6
6
  "license": "Apache-2.0",
@@ -98,7 +98,7 @@
98
98
  "@storybook/react-webpack5": "8.1.10",
99
99
  "@storybook/test-runner": "^0.18.2",
100
100
  "@storybook/theming": "8.1.10",
101
- "@testing-library/dom": "^10.1.0",
101
+ "@testing-library/dom": "^10.2.0",
102
102
  "@testing-library/react": "^16.0.0",
103
103
  "@testing-library/user-event": "^14.5.2",
104
104
  "@types/chai": "^4.3.16",
@@ -112,14 +112,14 @@
112
112
  "@types/sinon": "^17.0.3",
113
113
  "@types/sinon-chai": "^3.2.12",
114
114
  "@types/webpack-env": "^1.18.5",
115
- "@typescript-eslint/eslint-plugin": "^7.13.1",
116
- "@typescript-eslint/parser": "^7.13.1",
115
+ "@typescript-eslint/eslint-plugin": "^7.14.1",
116
+ "@typescript-eslint/parser": "^7.14.1",
117
117
  "@vitejs/plugin-react": "^4.3.1",
118
118
  "@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
119
119
  "acorn": "^8.12.0",
120
120
  "axe-playwright": "^2.0.1",
121
121
  "babel-plugin-require-context-hook": "^1.0.0",
122
- "caniuse-lite": "^1.0.30001636",
122
+ "caniuse-lite": "^1.0.30001638",
123
123
  "chai": "^5.1.1",
124
124
  "chai-as-promised": "^8.0.0",
125
125
  "chai-dom": "^1.10.0",
@@ -143,7 +143,7 @@
143
143
  "identity-obj-proxy": "^3.0.0",
144
144
  "jest": "~29.7.0",
145
145
  "jest-environment-jsdom": "^29.7.0",
146
- "jest-teamcity": "^1.10.0",
146
+ "jest-teamcity": "^1.12.0",
147
147
  "lint-staged": "^15.2.7",
148
148
  "markdown-it": "^14.1.0",
149
149
  "merge-options": "^3.0.4",