1.0.6 • Published 7 months ago

emirkucukosman-feedbacky v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Feedbacky

Feedbacky is a fully customizable, lightweight (37 kB) Modal component which enables customers to give feedback about your e-commerce website.

Feedbacky is built using React & TypeScript and it has only one dependency which is clsx library

How it works?

Customers writes their feedback into a text box, clicks submit and that's it! By default feedbacks are saved into a Google Sheet via SheetDB API. But this default behaviour can be changed via providing a custom onSubmit prop to the Modal. See more below.

How to use?

First install the package by running:

npm install emirkucukosman-feedbacky

There are two ways to manage the modal:

  1. Managing the Modal state by-yourself and rendering conditionally
import { useState } from "react";
import { Modal } from "emirkucukosman-feedbacky";

const App = () => {
  const [isOpen, setIsOpen] = useState(false);

  const handleOpen = () => {
    setIsOpen(true);
  };

  const handleClose = () => {
    setIsOpen(false);
  };

  return (
    <div>
      <Modal.Trigger onClick={handleOpen} />
      {isOpen && <Modal onClose={handleClose} {...otherProps} />}
    </div>
  );
};
  1. Using the ModalProvider and useModalContext hook
import {
  Modal,
  ModalProvider,
  useModalContext,
} from "emirkucukosman-feedbacky";

const Example = () => {
  const { openModal } = useModalContext();

  const handleOpen = () => {
    openModal({
      header: {
        title: "Modal Title",
      },
      ...otherProps,
    });
  };

  return (
    <div>
      <Modal.Trigger onClick={handleOpen}>Open Modal</Modal.Trigger>
    </div>
  );
};

const App = () => {
  return (
    <ModalProvider>
      <Example />
    </ModalProvider>
  );
};

Customization

Modal component has 4 sub-components as it's children which are Header, Body, Footer and Success. By default these components are used if you don't provide any custom children. If any children is provided inside Modal component than only those elements will be rendered

import { Modal } from "emirkucukosman-feedbacky";

<Modal />
// so this is actually rendered as:
<Modal>
  <Modal.Header />
  <Modal.Body />
  <Modal.Footer />
  <Modal.Success />
</Modal>
// note that Modal.Success is only rendered when submit is successful or showSuccess prop is true

Each of this child components can also be customizable by props like:

import { Modal } from "emirkucukosman-feedbacky";

<Modal
  header={{ title: 'Modal Title' }}
  body={{
    textAreaPlaceholder: 'Feedback placeholder...'
  }}
  ...otherProps
/>

It is also possible to both use the default components and your custom components ones like:

import { Modal } from "emirkucukosman-feedbacky";

<Modal>
  <Modal.Header />
  <Modal.Body />
  <Modal.Footer>
    <CustomFooter />
  </Modal.Footer>
  <Modal.Success />
</Modal>;

Props List

Modal Props

PropertyDescriptionTypesRequired
overlayClassNameclasses to apply to overlay elementstringoptional
modalClassNameclasses to apply to modal elementstringoptional
modalContentClassNameclasses to apply to modal content elementstringoptional
formClassNameclasses to apply to form elementstringoptional
headerheader propsHeaderPropsoptional
bodybody propsBodyPropsoptional
footerfooter propsFooterPropsoptional
successsuccess propsSuccessPropsoptional
childrenchildren to render inside modalReactNodeoptional
sheetDbApiUrlSheetDB API URL to save the feedback responsestringoptional
showSuccessshows or hides the Modal.Success componentbooleanoptional
onSubmitcustom onSubmit function which will get called when submit is clickedfunctionoptional
onClosefunction which will be called when modal is closedfunctionrequired

Modal.Trigger Props

PropertyDescriptionTypesRequired
triggerContainerClassNameclasses to apply to trigger container elementstringoptional
triggerButtonClassNameclasses to apply to trigger button elementstringoptional
childrenchildren to render inside triggerReactNodeoptional
onClickfunction which will be called when trigger is clickedfunctionoptional

Modal.Header Props

PropertyDescriptionTypesRequired
titletitle to be display on the modalstringoptional
headerClassNameclasses to apply to header elementstringoptional
titleClassNameclasses to apply to title elementstringoptional
closeButtonRowClassNameclasses to apply to close button row elementstringoptional
closeButtonClassNameclasses to apply to close button elementstringoptional
childrenchildren to render inside headerReactNodeoptional
onClosefunction which will be called when close is clickedfunctionoptional

Modal.Body Props

PropertyDescriptionTypesRequired
descriptiondescription to be display on the modalstringoptional
bodyClassNameclasses to apply to body elementstringoptional
descriptionClassNameclasses to apply to description elementstringoptional
textAreaClassNameclasses to apply to text area elementstringoptional
textAreaPlaceholderplaceholder to show on text areastringoptional
textAreaRowsrow count for text areanumberoptional
feedbackValuestring value for the feedback text area elementstringoptional
childrenchildren to render inside bodyReactNodeoptional
onFeedbackChangefunction which will be called when feedback is changedfunctionoptional

Modal.Footer Props

PropertyDescriptionTypesRequired
submitLabeltext to display inside submit buttonstringoptional
submittingLabeltext to display inside submit button when submittingstringoptional
isSubmittingsubmit status of the buttonbooleanoptional
submitButtonClassNameclasses to apply to submit button elementstringoptional
footerClassNameclasses to apply to footrr elementstringoptional
childrenchildren to render inside footerReactNodeoptional

Modal.Success Props

PropertyDescriptionTypesRequired
messagetext to display for success messagestringoptional
messageClassNameclasses to apply to message elementstringoptional
childrenchildren to render inside successReactNodeoptional
1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago