2018-10-17 11:38:25 +02:00
|
|
|
/*
|
2019-01-16 10:29:22 +00:00
|
|
|
Copyright 2019 New Vector Ltd
|
2018-10-17 11:38:25 +02:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-14 20:33:33 +01:00
|
|
|
import FixedDistributor from "./fixed";
|
|
|
|
|
import ResizeItem from "../item";
|
2018-09-24 16:07:42 +01:00
|
|
|
|
2019-01-14 20:24:54 +01:00
|
|
|
class CollapseItem extends ResizeItem {
|
|
|
|
|
notifyCollapsed(collapsed) {
|
|
|
|
|
const callback = this.resizer.config.onCollapsed;
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(collapsed, this.id, this.domNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-24 16:07:42 +01:00
|
|
|
|
2019-01-14 20:33:33 +01:00
|
|
|
export default class CollapseDistributor extends FixedDistributor {
|
2019-01-14 20:24:54 +01:00
|
|
|
static createItem(resizeHandle, resizer, sizer) {
|
|
|
|
|
return new CollapseItem(resizeHandle, resizer, sizer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(item, config) {
|
2018-12-19 23:51:19 +01:00
|
|
|
super(item);
|
2018-10-16 14:56:49 +02:00
|
|
|
this.toggleSize = config && config.toggleSize;
|
2018-10-16 18:43:13 +02:00
|
|
|
this.isCollapsed = false;
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-26 16:42:58 +01:00
|
|
|
resize(newSize) {
|
2018-10-16 18:43:13 +02:00
|
|
|
const isCollapsedSize = newSize < this.toggleSize;
|
|
|
|
|
if (isCollapsedSize && !this.isCollapsed) {
|
|
|
|
|
this.isCollapsed = true;
|
2019-01-14 20:24:54 +01:00
|
|
|
this.item.notifyCollapsed(true);
|
2018-10-17 13:36:15 +02:00
|
|
|
} else if (!isCollapsedSize && this.isCollapsed) {
|
2019-01-14 20:24:54 +01:00
|
|
|
this.item.notifyCollapsed(false);
|
2018-10-16 18:43:13 +02:00
|
|
|
this.isCollapsed = false;
|
|
|
|
|
}
|
|
|
|
|
if (!isCollapsedSize) {
|
2018-11-26 16:42:58 +01:00
|
|
|
super.resize(newSize);
|
2018-10-16 12:26:08 +02:00
|
|
|
}
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
}
|