Skip to content

Commit

Permalink
accept arrays for snapOffset in splitjs
Browse files Browse the repository at this point in the history
  • Loading branch information
johsunds committed May 11, 2021
1 parent 3259899 commit aa66209
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/splitjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare namespace Split {
gutterAlign?: string

// Snap to minimum size offset in pixels.
snapOffset?: number
snapOffset?: number | number[]

dragInterval?: number

Expand Down
10 changes: 6 additions & 4 deletions packages/splitjs/src/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const Split = (idsOption, options = {}) => {
const gutterSize = getOption(options, 'gutterSize', 10)
const gutterAlign = getOption(options, 'gutterAlign', 'center')
const snapOffset = getOption(options, 'snapOffset', 30)
const snapOffsets = Array.isArray(snapOffset) ? snapOffset : ids.map(() => snapOffset)
const dragInterval = getOption(options, 'dragInterval', 1)
const direction = getOption(options, 'direction', HORIZONTAL)
const cursor = getOption(
Expand Down Expand Up @@ -297,20 +298,20 @@ const Split = (idsOption, options = {}) => {
// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers a.minSize and b.minSize, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
if (offset <= a.minSize + snapOffset + this[aGutterSize]) {
if (offset <= a.minSize + a.snapOffset + this[aGutterSize]) {
offset = a.minSize + this[aGutterSize]
} else if (
offset >=
this.size - (b.minSize + snapOffset + this[bGutterSize])
this.size - (b.minSize + b.snapOffset + this[bGutterSize])
) {
offset = this.size - (b.minSize + this[bGutterSize])
}

if (offset >= a.maxSize - snapOffset + this[aGutterSize]) {
if (offset >= a.maxSize - a.snapOffset + this[aGutterSize]) {
offset = a.maxSize + this[aGutterSize]
} else if (
offset <=
this.size - (b.maxSize - snapOffset + this[bGutterSize])
this.size - (b.maxSize - b.snapOffset + this[bGutterSize])
) {
offset = this.size - (b.maxSize + this[bGutterSize])
}
Expand Down Expand Up @@ -589,6 +590,7 @@ const Split = (idsOption, options = {}) => {
size: sizes[i],
minSize: minSizes[i],
maxSize: maxSizes[i],
snapOffset: snapOffsets[i],
i,
}

Expand Down

0 comments on commit aa66209

Please sign in to comment.