add maxSize option

This commit is contained in:
Nathan Cahill
2021-04-02 09:17:11 -04:00
parent db9591a011
commit 2f74e84777
2 changed files with 29 additions and 5 deletions

View File

@@ -155,10 +155,12 @@ const Split = (idsOption, options = {}) => {
// Set default options.sizes to equal percentages of the parent element.
let sizes = getOption(options, 'sizes') || ids.map(() => 100 / ids.length)
// Standardize minSize to an array if it isn't already. This allows minSize
// to be passed as a number.
// Standardize minSize and maxSize to an array if it isn't already.
// This allows minSize and maxSize to be passed as a number.
const minSize = getOption(options, 'minSize', 100)
const minSizes = Array.isArray(minSize) ? minSize : ids.map(() => minSize)
const maxSize = getOption(options, 'maxSize', Infinity)
const maxSizes = Array.isArray(maxSize) ? maxSize : ids.map(() => maxSize)
// Get other options
const expandToMin = getOption(options, 'expandToMin', false)
@@ -304,6 +306,15 @@ const Split = (idsOption, options = {}) => {
offset = this.size - (b.minSize + this[bGutterSize])
}
if (offset >= a.maxSize - snapOffset + this[aGutterSize]) {
offset = a.maxSize + this[aGutterSize]
} else if (
offset <=
this.size - (b.maxSize - snapOffset + this[bGutterSize])
) {
offset = this.size - (b.maxSize + this[bGutterSize])
}
// Actually adjust the size.
adjust.call(this, offset)
@@ -577,6 +588,7 @@ const Split = (idsOption, options = {}) => {
element: elementOrSelector(id),
size: sizes[i],
minSize: minSizes[i],
maxSize: maxSizes[i],
i,
}