2018-06-20 20:19:53 +00:00
|
|
|
import { Component } from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link AbstractDialogTab}.
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
export interface IProps {
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that closes the dialog.
|
|
|
|
*/
|
2022-09-15 12:20:11 +00:00
|
|
|
closeDialog: Function;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to invoke on change.
|
|
|
|
*/
|
2022-09-15 12:20:11 +00:00
|
|
|
onTabStateChange: Function;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the tab.
|
|
|
|
*/
|
2022-09-15 12:20:11 +00:00
|
|
|
tabId: number;
|
2022-11-03 08:35:51 +00:00
|
|
|
}
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract React {@code Component} for tabs of the DialogWithTabs component.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-06-20 20:19:53 +00:00
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
class AbstractDialogTab<P extends IProps, S> extends Component<P, S> {
|
2018-06-20 20:19:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AbstractDialogTab} instance.
|
|
|
|
*
|
2019-09-13 13:03:40 +00:00
|
|
|
* @param {P} props - The read-only properties with which the new
|
2018-06-20 20:19:53 +00:00
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2019-09-13 13:03:40 +00:00
|
|
|
constructor(props: P) {
|
2018-06-20 20:19:53 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
this._onChange = this._onChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses the onTabStateChange function to pass the changed state of the
|
|
|
|
* controlled tab component to the controlling DialogWithTabs component.
|
|
|
|
*
|
|
|
|
* @param {Object} change - Object that contains the changed property and
|
|
|
|
* value.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-15 12:20:11 +00:00
|
|
|
_onChange(change: Object) {
|
2018-06-20 20:19:53 +00:00
|
|
|
const { onTabStateChange, tabId } = this.props;
|
|
|
|
|
|
|
|
onTabStateChange(tabId, {
|
|
|
|
...this.props,
|
|
|
|
...change
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AbstractDialogTab;
|