Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                // button component for the pagination
function Button({ active, children, ...props }) {
  return (
    <button className={`inline-block py-3 mx-px text-center leading-none rounded ${ active ? "text-blue-500 font-bold" : "bg-gray-50 enabled:hover:bg-gray-100 disabled:opacity-50" } ${ typeof children === "number" ? "w-12 px-1" : "px-4"}`} {...props}>{children}</button>
  );
};


// pagination component
function Pagination({ page, setPage, pages, hasNextPage }) {
  
  // handler for the next button
  function handleNext() {
    setPage(page+1);
  };
  
  // handler for the previous button
  function handlePrevious() {
    setPage(page-1);
  };
  
  return (
    <div className="p-5 flex items-center justify-center text-gray-600">
      <Button onClick={handlePrevious} disabled={page <= 1}>Previous</Button>
      { pages - page < 1 && page - 4 > 0 && <Button onClick={() => setPage(page - 4)}>{page - 4}</Button> }
      { pages - page < 2 && page - 3 > 0 && <Button onClick={() => setPage(page - 3)}>{page - 3}</Button> }
      { pages && page - 2 > 0 && <Button onClick={() => setPage(page - 2)}>{page - 2}</Button> }
      { pages && page - 1 > 0 && <Button onClick={() => setPage(page - 1)}>{page - 1}</Button> }
      <Button active={true}>{page}</Button>
      { page + 1 <= pages && <Button onClick={() => setPage(page + 1)}>{page + 1}</Button> }
      { page + 2 <= pages && <Button onClick={() => setPage(page + 2)}>{page + 2}</Button> }
      { page + 3 <= pages && page < 3 && <Button onClick={() => setPage(page + 3)}>{page + 3}</Button> }
      { page + 4 <= pages && page < 2 && <Button onClick={() => setPage(page + 4)}>{page + 4}</Button> }
      <Button onClick={handleNext} disabled={!hasNextPage}>Next</Button>
    </div>
  );
};


// for displaying the pagination component
function App() {
  // state
  const [page, setPage] = React.useState(1);
  const pages = 12; // dummy data for example
  
  // do something when the page changes
  React.useEffect(() => {
    // go get another page of results
  }, [page]);
  
  return (
    <div className="flex flex-col w-full min-h-screen items-center justify-center p-5">
      <Pagination page={page} setPage={setPage} hasNextPage={page < pages} />
      <Pagination page={page} setPage={setPage} pages={pages} hasNextPage={page < pages} />
    </div>
  );
};


// ========================================
// render the react app
ReactDOM.render(
  <App />,
  document.getElementById('app')
);
              
            
!
999px

Console