New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pagination-ui-less

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination-ui-less

A Pagination manager library without UI.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Pagination-UI-LESS

How to use

  1. use npm or yarn to install

    npm i pagination-ui-less
    

    or

    yarn add pagination-ui-less
    
  2. use CDN include

    <script src="https://cdn.jsdelivr.net/npm/pagination-ui-less"></script>
    

    then you can use the following example to create a Pagination manager:

    const pagination = paginationUiLess({
        pagesLength: 1,
        currentPage: 1,
        onChange: () => {}
    })
    

types

export declare type TCreatePaginationProps = {
    pagesLength: number;
    onChange: (pages: TPages) => void;
    currentPage?: number;
};
export declare type TPages = {
    currentPage: number;
    pages: {
        action: string | null;
        value: number | string;
        isActive?: boolean;
    }[];
};

Methods

  1. setPage

    (n: number) => TPages;

  2. setPagesLength

    (newPagesLength: number, newCurrentPage: number) => TPages

  3. getPages

    () => TPages

  4. getCurrentPage

    () => number

  5. nextPage

    () => TPages

  6. previousPage

    () => TPages

  7. firstPage

    () => TPages

  8. lastPage

    () => TPages

Example

https://github.com/SidStraw/Pagination-UI-LESS/blob/main/example/main.js

import { createPaginationItem } from './module/createElements.js'

async function main() {
  const paginationElement = document.querySelector('#pagination')

  // declare type TCreatePaginationProps = {
  //   pagesLength: number;
  //   onChange: (pages: TPages) => void;
  //   currentPage?: number;
  // };
  const pagination = paginationUiLess({
    pagesLength: 10,
    onChange: updateElements,
  })

  function updateElements({ currentPage, pages }) {
    // declare type TPages = {
    //   currentPage: number;
    //   pages: {
    //      action: string | null;
    //      value: number | string;
    //      isActive?: boolean;
    //   }[];
    // };
    paginationElement.innerHTML = pages.map(createPaginationItem).join('')
  }

  paginationElement.addEventListener('click', e => {
    const { action, value } = e.target.dataset
    const newPage = Number(value)
    const currentPage = pagination.getCurrentPage()

    if (!action || currentPage === newPage) return

    pagination[action](newPage)
  })

  updateElements(1)
}

main()

Keywords

FAQs

Package last updated on 09 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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