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

auto-fit-grid

v1.0.3

Published

A robust JavaScript library for dynamically adjusting grid column widths based on content.

Downloads

10

Readme

AutoFitGrid

AutoFitGrid is a robust JavaScript library for dynamically adjusting grid column widths based on content. It ensures that columns are optimally sized to fit their content, improving the layout and readability of grid-based interfaces.

Features

  • Dynamic column width adjustment
  • Support for various data types including text, email, date, and number
  • Option to distribute remaining space equally across columns
  • Customizable wrap ratios for different data types
  • Fixed-width columns support
  • Easy to integrate and configure

Installation

You can install AutoFitGrid using npm:

npm install auto-fit-grid

Example

https://autofitgrid.codeutility.io

AutoFitGrid Example

Usage

Basic Usage

First, include the AutoFitGrid script in your HTML file:

<script src="node_modules/auto-fit-grid/dist/auto-fit-grid-1.0.1.min.js"></script>

Next, create a grid container with header and column elements:

<div class="grid-container">
    <div class="grid-header" data-type="text">Company Name</div>
    <div class="grid-header" data-type="text">Country</div>
    <div class="grid-header" data-type="email">Email</div>
    <div class="grid-header" data-type="date">Established Date</div>
    <div class="grid-header" data-type="number">Revenue</div>

    <div class="grid-item">OpenAI, Inc.</div>
    <div class="grid-item">USA</div>
    <div class="grid-item">[email protected]</div>
    <div class="grid-item">2024-07-26</div>
    <div class="grid-item">$100,000,000</div>
</div>

Then, initialize AutoFitGrid for your grid container:

document.addEventListener('DOMContentLoaded', function() {
    new AutoFitGrid({
        container: document.querySelector('.grid-container'), // Required
        headerSelector: '.grid-header', // Required
        columnSelector: '.grid-item', // Required

        defaultWrapRatios: { // Optional, default: { text: 4.5, date: 8.0, datetime: 7.0, number: 7.0, email: 12.0 }
            text: 4.5,
            date: 8.0,
            datetime: 7.0,
            number: 7.0,
            email: 12.0,
        },
        defaultMinWidth: 50, // Optional, default: 50
        defaultMaxWidth: Infinity, // Optional, default: Infinity
        adjustmentThreshold: 200, // Optional, default: 200
        distributeRemainingSpace: true // Optional, default: true
    });
});

Using AutoFitGrid in ReactJS

First, install AutoFitGrid using npm:

npm install auto-fit-grid

Then, import and use it in your React component:

import React, { useEffect, useRef } from 'react';
import AutoFitGrid from 'auto-fit-grid';

const GridComponent = () => {
    const gridContainerRef = useRef(null);

    useEffect(() => {
        if (gridContainerRef.current) {
            new AutoFitGrid({
                container: gridContainerRef.current,
                headerSelector: '.grid-header',
                columnSelector: '.grid-item',
            });
        }
    }, []);

    return (
        <div className="grid-container" ref={gridContainerRef} data-distribute-remaining-space="true">
            <div className="grid-header" data-type="text">Company Name</div>
            <div className="grid-header" data-type="text">Country</div>
            <div className="grid-header" data-type="email">Email</div>
            <div className="grid-header" data-type="date">Established Date</div>
            <div className="grid-header" data-type="number">Revenue</div>

            <div className="grid-item">OpenAI, Inc.</div>
            <div className="grid-item">USA</div>
            <div className="grid-item">[email protected]</div>
            <div className="grid-item">2024-07-26</div>
            <div className="grid-item">$100,000,000</div>
        </div>
    );
};

export default GridComponent;

Using AutoFitGrid in AngularJS

First, install AutoFitGrid using npm:

npm install auto-fit-grid

Then, import and use it in your Angular component:

import angular from 'angular';
import AutoFitGrid from 'auto-fit-grid';

const app = angular.module('gridApp', []);

app.controller('GridController', ['$scope', '$element', function($scope, $element) {
    $scope.$on('$viewContentLoaded', function() {
        new AutoFitGrid({
            container: $element[0].querySelector('.grid-container'),
            headerSelector: '.grid-header',
            columnSelector: '.grid-item',
        });
    });
}]);

app.component('gridComponent', {
    template: `
        <div class="grid-container" data-distribute-remaining-space="true">
            <div class="grid-header" data-type="text">Company Name</div>
            <div class="grid-header" data-type="text">Country</div>
            <div class="grid-header" data-type="email">Email</div>
            <div class="grid-header" data-type="date">Established Date</div>
            <div class="grid-header" data-type="number">Revenue</div>

            <div class="grid-item">OpenAI, Inc.</div>
            <div class="grid-item">USA</div>
            <div class="grid-item">[email protected]</div>
            <div class="grid-item">2024-07-26</div>
            <div class="grid-item">$100,000,000</div>
        </div>
    `,
    controller: 'GridController'
});

Options

  • container: The grid container element (required).
  • defaultWrapRatios: Object defining wrap ratios for different data types (optional).
  • defaultMinWidth: Default minimum width for columns (optional).
  • defaultMaxWidth: Default maximum width for columns (optional).
  • adjustmentThreshold: Threshold for width adjustment in pixels (optional).
  • headerSelector: CSS selector for header elements (optional).
  • columnSelector: CSS selector for column elements (optional).
  • showDebug: Boolean to enable or disable debug logging (optional).
  • distributeRemainingSpace: Boolean to enable or disable distribution of remaining space (optional).

License

This project is licensed under the MIT License.

Author

Hien Tran

Links