1.0.0 • Published 2 years ago

@eteg/react-modals v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@garden/components npm version

This package includes several varieties of modals within the Garden Design System.

Installation

npm install @garden/components

# Peer Dependencies - Also Required
npm install react react-dom styled-components @zendeskgarden/react-buttons @zendeskgarden/react-theming react-icons --save

Usage

import { ThemeProvider } from '@zendeskgarden/react-theming';
import { Modal } from '@garden/components';
import { useState } from 'react';

/**
 * Place a `ThemeProvider` at the root of your React application
 */

const modalButtons: PropsButtonModal[] = [
  {
    text: 'Loading',
    function: () => console.log('Loading'),
    isPrimary: true,
    isLoading: true
  },
  {
    text: 'Delete',
    function: () => console.log('Delete'),
    isPrimary: true,
    isDanger: true
  },
  {
    text: 'Confirm',
    function: () => console.log('Confirm'),
    isPrimary: true
  }
];

export function App() {
  const [buttonsModal, setButtonsModal] = useState < boolean > false;

  return (
    <ThemeProvider>
      <Button onClick={() => setButtonsModal(true)}>Open Buttons Modal</Button>
      <Modal
        modalClose={() => setButtonsModal(false)}
        isOpen={buttonsModal}
        title="Lorem ipsum dolor sit amet"
        buttons={modalButtons}
      >
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus quis ullamcorper lacus.
          Nunc tempor aliquet quam id ullamcorper. Nunc a ex velit. Etiam commodo a eros eget
          posuere.
        </p>
      </Modal>
    </ThemeProvider>
  );
}

Modal Component

Extends HTMLAttributes

The Modal Component applies appropriate styles based on its usage and the props provided.

Prop nameTypeDefaultDescriptionRequired
modalClosefunctionFunction that closes the Modalyes
isOpenbooleanIf true, the modal will be opened.yes
titlestringTitle that will appear in the headeryes
modalWidthstring'60%'Modal width on Screenno
alignButtonsstring'space-between'Distribution of buttons along the main-axis of a flex containerno
isScrollingbooleanfalseIf true, modal body has overflow-y: scrollno
modalIsDangerbooleanfalseIf true, applies danger stylingno
maxMenuHeightstring'150px'Maximum height of a Select input inside the Modal bodyno
buttonsButtons[]Array with the Buttons that will appear in the modal, check the section below (Modal Buttons) for the properties of each buttonno

Modal Buttons

Extends ButtonHTMLAttributes

The Modal Buttons applies appropriate styles based on its usage and the props provided.

Prop nameTypeDefaultDescriptionRequired
textstringButton Textyes
functionfunctionButton onClick functionyes
isPrimarybooleanfalseIf true, applies primary button stylingno
isBasicbooleanfalseIf true, applies basic button stylingno
isDangerbooleanfalseIf true, applies danger button stylingno
isLoadingbooleanfalseIf true, applies loading button stylingno
disabledbooleanfalseIf true, disable the button and applies disabled button stylingno
marginButtostring0Used when the buttons are aligned left or right, to leave a space between themno