@pikas-ui/dialog

This package contains a dialog component that can be used to show a modal.

This library is based on Radix Ui.

Change Log

Requirements

To use this package, you must install the @pikas-ui/styles package.

Installation

You can install this package using npm, yarn, or pnpm.

npm install @pikas-ui/dialog
yarn add @pikas-ui/dialog
pnpm add @pikas-ui/dialog

Usage

DefaultDialog

This is the default dialog component. It can be used to show a modal with a title, a content, and a validate button.

import { DefaultDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <DefaultDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        content="Hello world!"
        title="Hello"
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring-
contentSets the content of the dialogReactNode-
validateButtonLabelSets the label of the validate buttonstring"Ok"
onValidateCallback when the dialog is validated() => void-
validateButtonColorNameSets the color of the validate buttonPikasColors"primary"
validateButtonDisabledSets the disabled state of the validate buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-

SuccessDialog

This is the success dialog component. It can be used to show a modal with a title, a content, and a validate button.

import { SuccessDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <SuccessDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        content="You have successfully completed the task."
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring"Yeah ! You did it !"
contentSets the content of the dialogReactNoderequired
validateButtonLabelSets the label of the validate buttonstring"Ok"
onValidateCallback when the dialog is validated() => void-
validateButtonColorNameSets the color of the validate buttonPikasColors"primary"
validateButtonDisabledSets the disabled state of the validate buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-

ValidateDialog

This is the validate dialog component. It can be used to show a modal with a title, a content, a validate button, and a cancel button.

import { ValidateDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <ValidateDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        content="Are you sure you want to do this ?"
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring"Are you sure ?"
contentSets the content of the dialogReactNoderequired
validateButtonLabelSets the label of the validate buttonstring"Ok"
onValidateCallback when the dialog is validated() => void-
cancelButtonLabelSets the label of the cancel buttonstring"Cancel"
onCancelCallback when the dialog is canceled() => void-
validateButtonColorNameSets the color of the validate buttonPikasColors"success"
cancelButtonColorNameSets the color of the cancel buttonPikasColors"danger"
validateButtonDisabledSets the disabled state of the validate buttonboolean-
cancelButtonDisabledSets the disabled state of the cancel buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-
cancelButtonLoadingSets the loading state of the cancel buttonboolean-

ErrorDialog

This is the error dialog component. It can be used to show a modal with a title, a content, and a validate button.

import { ErrorDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <ErrorDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        content="Please try again later."
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring"Oops ! A error occurred..."
contentSets the content of the dialogReactNoderequired
validateButtonLabelSets the label of the validate buttonstring"Ok"
onValidateCallback when the dialog is validated() => void-
validateButtonColorNameSets the color of the validate buttonPikasColors"danger"
validateButtonDisabledSets the disabled state of the validate buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-

InfoDialog

This is the info dialog component. It can be used to show a modal with a title, a content, and a validate button.

import { InfoDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <InfoDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        content="You have successfully completed the task."
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring"We have a information for you !"
contentSets the content of the dialogReactNoderequired
validateButtonLabelSets the label of the validate buttonstring"Ok"
onValidateCallback when the dialog is validated() => void-
validateButtonColorNameSets the color of the validate buttonPikasColors"primary"
validateButtonDisabledSets the disabled state of the validate buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-

CustomDialog

This is the custom dialog component. It can be used to show a modal with a custom header, content, and footer.

import { CustomDialog } from '@pikas-ui/dialog';
import { useState } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <CustomDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
        header={<h2>Hello world !</h2>}
        content={<p>This is a custom dialog.</p>}
        footer={
          <Button onClick={(): void => setVisible(false)} width="auto">
            Ok
          </Button>
        }
        padding={{
          container: 'md',
        }}
        gap={{
          container: 'md',
        }}
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
closeIfClickOutsideCloses the dialog if the user clicks outside of itbooleanfalse
hasCloseIconAdds a close icon to the dialogbooleantrue
cssCustom CSS of the dialogCustomDialogCSS-
widthSets the width of the dialogstring or number500
heightSets the height of the dialogstring or number-
paddingSets the padding of the dialogCustomDialogPadding-
gapSets the gap of the dialogCustomDialogGap-
headerSets the header of the dialogReactNode-
contentSets the content of the dialogReactNode-
footerSets the footer of the dialogReactNode-

SelectImageDialog

This is the select image dialog component. You can use it to select an image from your computer. It will return the image as a base64 string compressed.

import { SelectImageDialog } from '@pikas-ui/dialog';

const Example: React.FC = () => {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <SelectImageDialog
        visible={visible}
        onClose={(): void => setVisible(false)}
      />

      <Button onClick={(): void => setVisible((lastState) => !lastState)}>
        {visible ? 'Hide' : 'Show'}
      </Button>
    </>
  );
};

Props

PropDescriptionTypeDefault
visibleSets the visibility of the dialogbooleanrequired
onOpenCallback when the dialog is openedfunction-
onCloseCallback when the dialog is closedfunction-
titleSets the title of the dialogstring"Image selection"
selectImageLabelSets the label of the select image buttonstring"Select an image"
defaultImageSets the default imagestring-
defaultImageFullSets the default image (full)string-
cancelButtonLabelSets the label of the cancel buttonstring"Cancel"
validateButtonLabelSets the label of the validate buttonstring"Validate"
cancelButtonColorNameSets the color of the cancel buttonPikasColors"danger"
validateButtonColorNameSets the color of the validate buttonPikasColors"success"
cancelButtonDisabledSets the disabled state of the cancel buttonboolean-
validateButtonDisabledSets the disabled state of the validate buttonboolean-
cancelButtonLoadingSets the loading state of the cancel buttonboolean-
validateButtonLoadingSets the loading state of the validate buttonboolean-
onCancelCallback when the cancel button is clickedfunction-
onValidateCallback when the validate button is clickedfunction-
maxZoomSets the max zoom of the imagenumber5
minZoomSets the min zoom of the imagenumber1
defaultZoomSets the default zoom of the imagenumber1
aspectSets the aspect of the imagenumber1 / 1
cropShapeSets the shape of the cropstring"rect"
cropSizeSets the size of the cropobject-

Contributing

This documentation can be edited on GitHub here