0.2.0 • Published 3 years ago

@n3/react-remove-button v0.2.0

Weekly downloads
3
License
MIT
Repository
gitlab
Last release
3 years ago

@n3/react-remove-button

Кнопка удаления для приложений на базе @n3/kit.

import {
  RemoveButton,
} from '@n3/react-remove-button';

Props

НазваниеОбязательностьТипЗначение по умолчаниюОписание
colorenum- buttonColors.DEFAULT- buttonColors.PRIMARY- buttonColors.TERTIARY- buttonColors.DANGERundefinedЦвет кнопки
sizeenum- buttonSizes.DEFAULT- buttonSizes.SMALLundefinedРазмер кнопки
disabledboolfalseВыключена ли кнопка
children+node
remove+funcАсинхронная функция удаления
onRemoveSuccessfuncundefinedОбработчик успешного удаления
approveTitlenodeundefinedЗаголовок подтверждения
approveContentnodeundefinedТекст подтверждения
approveButtonText+stringТекст кнопки подтвеждения
approveButtonColorenum- buttonColors.DEFAULT- buttonColors.PRIMARY- buttonColors.TERTIARY- buttonColors.DANGERbuttonColors.DANGERЦвет кнопки подтверждения
cancelButtonText+stringТекст кнопки отмены
errorsPathstring'response.data.detail'Путь до объекта ошибкок в случае ошибки удаления
redirectToanyundefinedАдрес редиректа в случае успешного удаления
notificationobjectundefinedСообщение @n3/browser-messages в случае успешного удаления

Создание кастомной кнопки удаления

import type {
  FC,
  ReactNode,
} from 'react';
import {
  useRemoveButton,
} from '@n3/react-remove-button';
import type {
  UseRemoveButtonParams,
} from '@n3/react-remove-button';

type CustomRemoveButtonProps = UseRemoveButtonParams & {
  children?: ReactNode;
};

const CustomRemoveButton: FC<CustomRemoveButtonProps> = (props) => {
  const {
    children,
    remove,
    onRemoveSuccess,
    approveTitle,
    approveContent,
    approveButtonText,
    approveButtonColor,
    cancelButtonText,
    errorsPath,
    redirectTo,
    notification,
  } = props;

  const {
    isRemoving,
    onClick,
  } = useRemoveButton({
    remove,
    onRemoveSuccess,
    approveTitle,
    approveContent,
    approveButtonText,
    approveButtonColor,
    cancelButtonText,
    errorsPath,
    redirectTo,
    notification,
  });

  return (
    <button
      type="button"
      disabled={isRemoving}
      onClick={onClick}
    >
      {children}
    </button>
  );
};