Skip to main content

Error Block

The ErrorBlock Component is a fully customizable and accessible error display component built with React and TypeScript. It provides a complete error interface with modern design patterns, flexible customization options, and support for custom error messages and actions.


πŸš€ Installation​

npm install @nodeblocks/frontend-error-block

πŸ“– Usage​

import {ErrorBlock} from '@nodeblocks/frontend-error-block';
Live Editor
function BasicErrorBlock() {
  return (
    <ErrorBlock
      errorTitle="Something went wrong"
      subtitle="We encountered an unexpected error. Please try again or contact support if the problem persists."
      actionHref="#home"
      actionText="Back to Home"
      titleErrorCode="Error 404">
      <ErrorBlock.Icon icon="error_outline" />
      <ErrorBlock.Title />
      <ErrorBlock.Subtitle />
      <ErrorBlock.Action>
        Go Back
      </ErrorBlock.Action>
    </ErrorBlock>
  );
}
Result
Loading...

πŸ”§ Props Reference​

Main Component Props​

PropTypeDefaultDescription
errorTitlestringRequiredTitle for the error message displayed prominently
subtitlestringRequiredSubtitle providing additional context about the error
actionHrefstringRequiredURL for the action button navigation
actionTextstringRequiredText to display in the action button
titleErrorCodestringundefinedError code displayed above the title (e.g., "Error 404")
classNamestringundefinedAdditional CSS class name for styling the error container
childrenBlocksOverrideundefinedCustom block components to override default rendering

Note: The main component inherits all HTML div element props.

Sub-Components​

The ErrorBlock component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.

ErrorBlock.Icon​

PropTypeDefaultDescription
iconenum"error_outline"Icon name to display - supports material design icons
iconSizeenum"3-extra-large"Size of the icon
colorenum"mid-emphasis"Color theme for the icon
classNamestringundefinedAdditional CSS class name for styling
isDisabledbooleanfalseWhether the icon is disabled
onClickfunctionundefinedFunction to handle icon click

ErrorBlock.Title​

PropTypeDefaultDescription
titleErrorCodeReactNodeFrom contextError code to display above the title
childrenReactNodeFrom contextTitle content - overrides errorTitle from context
sizeenum"2XL"Typography size for the title
typeenum"heading"Typography type
colorenum"low-emphasis"Color theme for the title
weightenum"bold"Weight of the title
classNamestringundefinedAdditional CSS class name for styling

ErrorBlock.Subtitle​

PropTypeDefaultDescription
childrenReactNodeFrom contextTitle content - overrides errorTitle from context
sizeenum"S"Typography size for the title
typeenum"heading"Typography type
colorenum"low-emphasis"Color theme for the title
weightenum"regular"Weight of the title
classNamestringundefinedAdditional CSS class name for styling

ErrorBlock.Action​

PropTypeDefaultDescription
actionHrefstringRequiredURL for the action button navigation
childrenReactNodeRequiredText to place inside the button
classNamestringundefinedAdditional CSS class name for styling
fillenum"fill"Button fill style
iconenumundefinedOptional icon for the left-hand side of the button
iconColorenumundefinedColor for the left-hand side icon. When not provided, a default color for the fill type will be used.
isDisabledbooleanfalseWhether the button is disabled and cannot be used
onClickfunctionundefinedFunction to handle button click
sizeenum"M"Button vertical size
textAlignenum"center"Button icon and text positioning within the button
textColorenum"default"Button text color
textEmphasisbooleanfalseButton text weight
textSizeenum"M"Button text size
typeenum"submit"Button purpose (affects html type)

πŸ”§ TypeScript Support​

Full TypeScript support with comprehensive type definitions:

import {ErrorBlock} from '@nodeblocks/frontend-error-block';
import {ComponentProps} from 'react';

// Main component interface
interface ErrorBlockProps extends Omit<ComponentProps<typeof ErrorBlock>, 'children'> {
className?: string;
errorTitle: string;
subtitle: string;
actionHref: string;
actionText: string;
titleErrorCode?: string;
}

// Example with prop overriding
function CustomErrorBlock() {
return (
<ErrorBlock
errorTitle="Server Error"
subtitle="Our servers are experiencing issues. Please try again later."
actionHref="/dashboard"
actionText="Back to Dashboard"
titleErrorCode="Error 500">
<ErrorBlock.Icon icon="error_outline" color="primary" iconSize="3-extra-large" />
<ErrorBlock.Title titleErrorCode="🚨 Error 500" size="3XL" color="error">
Critical Server Error
</ErrorBlock.Title>
<ErrorBlock.Subtitle color="mid-emphasis">
We're working on fixing this issue. Try refreshing in a few minutes.
</ErrorBlock.Subtitle>
<ErrorBlock.Action size="M" fill="fill" actionHref="/support">
Contact Support
</ErrorBlock.Action>
</ErrorBlock>
);
}


Built with ❀️ using React, TypeScript, and modern web standards.