@primer/behaviors 1.0.1-rc.c3f87ba → 1.0.2-rc.6a46764

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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # @primer/behaviors
2
2
 
3
- ## 1.0.1
3
+ ## 1.0.2
4
+
4
5
  ### Patch Changes
5
6
 
7
+ - [#17](https://github.com/primer/behaviors/pull/17) [`9194ba4`](https://github.com/primer/behaviors/commit/9194ba403502b4acba0be03bed1a765c1ba81340) Thanks [@dgreif](https://github.com/dgreif)! - Correct margin orientation for `scrollIntoView`
6
8
 
9
+ ## 1.0.1
10
+
11
+ ### Patch Changes
7
12
 
8
13
  - [#10](https://github.com/primer/behaviors/pull/10) [`88b6f34`](https://github.com/primer/behaviors/commit/88b6f34bf4874f3c81473020a01a58b197dd6e16) Thanks [@dgreif](https://github.com/dgreif)! - Set up changesets
package/README.md CHANGED
@@ -10,7 +10,7 @@ Shared behaviors for JavaScript components
10
10
  * [Anchored Position](/docs/anchored-position.md)
11
11
  * [Focus Trap](/docs/focus-trap.md)
12
12
  * [Focus Zone](/docs/focus-zone.md)
13
- * [Scroll Into Viewing Area](/docs/scroll-into-viewing-area.md)
13
+ * [Scroll Into View](/docs/scroll-into-view.md)
14
14
 
15
15
  ## Installation
16
16
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './anchored-position.js';
2
2
  export * from './focus-trap.js';
3
3
  export * from './focus-zone.js';
4
- export * from './scroll-into-viewing-area.js';
4
+ export * from './scroll-into-view.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './anchored-position.js';
2
2
  export * from './focus-trap.js';
3
3
  export * from './focus-zone.js';
4
- export * from './scroll-into-viewing-area.js';
4
+ export * from './scroll-into-view.js';
@@ -0,0 +1,7 @@
1
+ export interface ScrollIntoViewOptions {
2
+ direction?: 'horizontal' | 'vertical';
3
+ startMargin?: number;
4
+ endMargin?: number;
5
+ behavior?: ScrollBehavior;
6
+ }
7
+ export declare function scrollIntoView(child: HTMLElement, viewingArea: HTMLElement, { direction, startMargin, endMargin, behavior }?: ScrollIntoViewOptions): void;
@@ -1,17 +1,17 @@
1
- export const scrollIntoViewingArea = (child, viewingArea, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
1
+ export function scrollIntoView(child, viewingArea, { direction = 'vertical', startMargin = 0, endMargin = 0, behavior = 'smooth' } = {}) {
2
2
  const startSide = direction === 'vertical' ? 'top' : 'left';
3
3
  const endSide = direction === 'vertical' ? 'bottom' : 'right';
4
4
  const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
5
5
  const { [startSide]: childStart, [endSide]: childEnd } = child.getBoundingClientRect();
6
6
  const { [startSide]: viewingAreaStart, [endSide]: viewingAreaEnd } = viewingArea.getBoundingClientRect();
7
- const isChildStartAboveViewingArea = childStart < viewingAreaStart + endMargin;
8
- const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - startMargin;
7
+ const isChildStartAboveViewingArea = childStart < viewingAreaStart + startMargin;
8
+ const isChildBottomBelowViewingArea = childEnd > viewingAreaEnd - endMargin;
9
9
  if (isChildStartAboveViewingArea) {
10
10
  const scrollHeightToChildStart = childStart - viewingAreaStart + viewingArea[scrollSide];
11
- viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildStart - endMargin });
11
+ viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildStart - startMargin });
12
12
  }
13
13
  else if (isChildBottomBelowViewingArea) {
14
14
  const scrollHeightToChildBottom = childEnd - viewingAreaEnd + viewingArea[scrollSide];
15
- viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildBottom + startMargin });
15
+ viewingArea.scrollTo({ behavior, [startSide]: scrollHeightToChildBottom + endMargin });
16
16
  }
17
- };
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "1.0.1-rc.c3f87ba",
3
+ "version": "1.0.2-rc.6a46764",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- export declare const scrollIntoViewingArea: (child: HTMLElement, viewingArea: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;