The source code for this library is available on GitHub.

Vaiva's Pattern Library.

Modal

Modal that uses the useClickOutside hook to close upon clicking outside of it.


import React, { useState, useRef } from 'react';
    import useClickOutside from '../../lib/useClickOutside';
    import Button from './Button';
    import styled from 'styled-components';
    
    const StyledModal = styled.div`
      display: flex;
      flex-direction: column;
    
      .modal {
        display: flex;
        flex-direction: column;
        gap: 4rem;
        border: 1px solid gray;
        background: white;
        border-radius: 5px;
        padding: 1rem 2rem;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-width: 70%;
        width: 100%;
    
        button {
          max-width: 7rem;
        }
      }
    
      .openModal {
        background-color: rgba(0, 0, 0, 0.2);
        width: 100vw;
        height: 100vh;
        z-index: 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        position: fixed;
        cursor: pointer;
      }
    
      .actions {
        display: flex;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 1rem;
      }
    `;
    
    const Modal = ({ toggleText, children }) => {
      const [show, setShow] = useState(false);
      const wrapperRef = useRef(null);
    
      const showModal = () => {
        setShow(true);
      };
    
      const closeInput = () => {
        setShow(false);
      };
    
      useClickOutside(wrapperRef, closeInput);
    
      return (
        <StyledModal>
          <div className={`${show && 'openModal'}`} />
          <Button secondary func={showModal} text={toggleText} />
          {show && (
            <div className="modal" ref={wrapperRef}>
              {children}
              <div className="actions">
                <Button
                  func={console.log('You clicked the submit button')}
                  text={'Submit'}
                />
                <Button secondary func={closeInput} text='Close modal'/>
              </div>
            </div>
          )}
        </StyledModal>
      );
    };
    export default Modal;

More Components

TailwindCSS Text Carousel

The title speaks volumes.

Button

There is no description. Have a poem instead.

When I heard the learn’d astronomer,
When the proofs, the figures, were ranged in columns before me,
When I was shown the charts and diagrams, to add, divide, and measure them,
When I sitting heard the astronomer where he lectured with much applause in the lecture-room,
How soon unaccountable I became tired and sick,
Till rising and gliding out I wander’d off by myself,
In the mystical moist night-air, and from time to time,
Look’d up in perfect silence at the stars.