Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mangoweb/hiding-header

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mangoweb/hiding-header - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

3

lib/index.d.ts
import { Component } from '@mangoweb/scripts-base';
interface HidingHeaderProps {
export interface HidingHeaderProps {
contentSelector?: string;

@@ -20,3 +20,2 @@ heightPropertyName?: string;

}
export {};
//# sourceMappingURL=index.d.ts.map

@@ -1,64 +0,45 @@

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var scripts_base_1 = require("@mangoweb/scripts-base");
var DEFAULT_CONTENT_SELECTOR = '*';
var DEFAULT_HEIGHT_PROPERTY_NAME = '--hidingHeader-height';
var DEFAULT_SCROLL_CAP_PROPERTY_NAME = '--hidingHeader-scrollCap';
var HidingHeader = /** @class */ (function (_super) {
__extends(HidingHeader, _super);
function HidingHeader() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.lastScrollTop = 0;
_this.contentHeight = 0;
_this.content = _this.getChild(_this.getPropOrElse('contentSelector', DEFAULT_CONTENT_SELECTOR), HTMLElement);
_this.wasScrollingDown = true;
_this.lastScrollCap = 0;
_this.heightPropertyName = _this.getPropOrElse('heightPropertyName', DEFAULT_HEIGHT_PROPERTY_NAME);
_this.scrollCapPropertyName = _this.getPropOrElse('scrollCapPropertyName', DEFAULT_SCROLL_CAP_PROPERTY_NAME);
_this.onScroll = function () {
var contentHeight = _this.getContentHeight(); // @TODO: throttle/cache
if (_this.contentHeight !== contentHeight) {
_this.contentHeight = contentHeight;
_this.el.style.setProperty(_this.heightPropertyName, contentHeight + "px");
import { Component } from '@mangoweb/scripts-base';
const DEFAULT_CONTENT_SELECTOR = '*';
const DEFAULT_HEIGHT_PROPERTY_NAME = '--hidingHeader-height';
const DEFAULT_SCROLL_CAP_PROPERTY_NAME = '--hidingHeader-scrollCap';
export class HidingHeader extends Component {
constructor() {
super(...arguments);
this.lastScrollTop = 0;
this.contentHeight = 0;
this.content = this.getChild(this.getPropOrElse('contentSelector', DEFAULT_CONTENT_SELECTOR), HTMLElement);
this.wasScrollingDown = true;
this.lastScrollCap = 0;
this.heightPropertyName = this.getPropOrElse('heightPropertyName', DEFAULT_HEIGHT_PROPERTY_NAME);
this.scrollCapPropertyName = this.getPropOrElse('scrollCapPropertyName', DEFAULT_SCROLL_CAP_PROPERTY_NAME);
this.onScroll = () => {
const contentHeight = this.getContentHeight(); // @TODO: throttle/cache
if (this.contentHeight !== contentHeight) {
this.contentHeight = contentHeight;
this.el.style.setProperty(this.heightPropertyName, `${contentHeight}px`);
}
var scrollTop = window.scrollY;
var isScrollingDown = scrollTop > _this.lastScrollTop;
if (isScrollingDown !== _this.wasScrollingDown) {
var scrollCap = isScrollingDown ? scrollTop : Math.max(0, scrollTop - contentHeight);
const scrollTop = window.scrollY;
const isScrollingDown = scrollTop > this.lastScrollTop;
if (isScrollingDown !== this.wasScrollingDown) {
const scrollCap = isScrollingDown ? scrollTop : Math.max(0, scrollTop - contentHeight);
// @TODO: handle changes in scroll direction if header is partially visible
if (scrollCap !== _this.lastScrollCap) {
_this.wasScrollingDown = isScrollingDown;
_this.el.style.setProperty(_this.scrollCapPropertyName, scrollCap + "px");
_this.lastScrollCap = scrollCap;
if (scrollCap !== this.lastScrollCap) {
this.wasScrollingDown = isScrollingDown;
this.el.style.setProperty(this.scrollCapPropertyName, `${scrollCap}px`);
this.lastScrollCap = scrollCap;
}
}
_this.lastScrollTop = scrollTop;
this.lastScrollTop = scrollTop;
};
return _this;
}
HidingHeader.prototype.getContentHeight = function () {
getContentHeight() {
return this.content.clientHeight;
};
HidingHeader.prototype.init = function () {
}
init() {
window.addEventListener('scroll', this.onScroll);
window.addEventListener('resize', this.onScroll);
this.onScroll();
};
HidingHeader.componentName = 'HidingHeader';
return HidingHeader;
}(scripts_base_1.Component));
exports.HidingHeader = HidingHeader;
}
}
HidingHeader.componentName = 'HidingHeader';
//# sourceMappingURL=index.js.map
{
"name": "@mangoweb/hiding-header",
"version": "0.0.2",
"version": "0.0.3",
"description": "Hides and reveals header on scroll.",

@@ -10,2 +10,3 @@ "main": "lib/index.js",

"build": "tsc",
"start": "tsc --watch",
"eslint:lint": "eslint \"src/**/*.{ts,tsx}\" ",

@@ -12,0 +13,0 @@ "eslint:fix": "eslint --fix \"src/**/*.{ts,tsx}\" ",

import { Component } from '@mangoweb/scripts-base'
interface HidingHeaderProps {
export interface HidingHeaderProps {
contentSelector?: string

@@ -5,0 +5,0 @@ heightPropertyName?: string

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc