npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ivanheriver/section-resizer

v0.0.9

Published

Make child elements of a container resizable.

Downloads

15

Readme

sectionResizer

This minimalistic JavaScript library can be used to make children of a container resizable in a simple and predictable way using only one line of code. A single sectionResizer() function has to be called with a single mandatory argument, the HTML element of a container, and voilà, the container's children can be resized!

Check out https://ivanheriver.github.io/sectionResizer/ which shows the example located in the example/ folder of this repo.

How to install

Install the library using npm:

npm install @ivanheriver/section-resizer

And then you can import the sectionResizer() function

import sectionResizer from "@ivanheriver/section-resizer";

Alternatively, you can download the section-resizer.min.js file located in the dist folder and use a script tag to load the the sectionResizer() function in you project.

How to use

Let's say you have an HTML document containing a div with the id "resizer-container". To make the children resizable you only need the following JavaScript:

import sectionResizer from "@ivanheriver/section-resizer";

const resizer = sectionResizer(document.getElementById("resizer-container"));

To customize the appearance of the separators, you can use the following CSS selectors:

.sr-separator {
  width: 1px;
  height: 1px;
  background-color: lightblue;
}
.sr-separator-highlight {
  width: 2px;
  height: 2px;
}

You can make the children be organized verically or horizontally (default):

sectionResizer(document.getElementById("resizer-container"), {
  mode: "vertical",
});

You can add data attributes on the children elements to specify their initial, minimum and maximum sizes with the [data-init], [data-min] and [data-max]. These attributes expects pixels values (without the unit px!). Default minimum sizes for the children is 100px. It is better to specify an initial value only for some of the children (not all).

<div id="resizer-container">
  <div data-min="500" data-max="1000" data-init="500">...</div>
  <div data-min="500">...</div>
  <div>...</div>
</div>

You can play around and do many cool things with the object returned by the sectionResizer() function which has several methods attached to it.

The following methods are made available:

  • resize()
  • configure()

The resize() method can be used to resize specific sections. An array of objects is expected as argument. The objects must be of the form {index: number, size: number} where index is the index of the section to resize and size the new size to apply in pixels.

The configure() can be used to (re)set the minimum and maximum size of all sections or specific sections.

  • If an array is provided, each element of the array must be in the form {index: number, min?: number, max?: number} where index is the index of the section to which min and/or max, the new minimum and maximum values (in pixels), are to be applied.

These 2 methods return promises that resolve at the next animation frame.

Instead of specifying the initial size in the HTML, you can do everything in JavaScript:

import sectionResizer from "@ivanheriver/section-resizer";

const resizer = sectionResizer(document.getElementById("resizer-container"));
resizer.configure([
  { index: 0, min: 500 },
  { index: 1, min: 500 },
]);
resizer.configure({ max: 900 });
resizer.resizer([{ index: 0, size: 500 }]);

Todos

Misc improvements:

  • make anchor width customizable

Future development may include on() and off() methods to setup listeners for specific events occuring within the sectionResizer. The events may include the following

  • resize: whenever resizing is occuring due to user interaction (initial_sizes, current_sizes, index) => {}
  • resizeend: whenever resizing due to user interaction terminates (previous_sizes, new_sizes, index) => {}
  • resizewish: whenever resizing is occuring due to user interaction even if the resizing actually doesn't occure due to min or max size conditions preventing any change. (initial_sizes, current_sizes, wished_sizes, index) => {}
  • sizechange: whenever one or more of the children size changes due to any reason (e. g. user interaction, addition/deletion of children, window resizing, ...) (sizes) => {}
  • highlight: whenever a separator highlight status is changed (index, highlighted) => {}

Licence

This is released under the MIT licence.