Pillar UI React Alert Component documentation

Enhance user experience with Pillar UI's versatile React Alert component. Easily create customizable alert notifications for your React applications, with various styles, and options for user interaction.

Components:

Alert

Type

Components

import

import { Pillar UI React Alert Component } from '@pillar-ui/core'

Usage

import { Alert } from '@pillar-ui/core'
function(){
    return(
        <Alert
            color="suc"
            size="md"
            corner="rounded"
            title="Success!"
            message="Your action was successful."
            variant="filled"
            inline={false}
            icon={<CheckCircleIcon />}
            closable={true}
        />
        ;
    )
}

Props

The Alert component accepts the following props:

Color

  • Type: string
  • Default: primary
  • Options: danger | warning | success | primary | secondary | bg

The color prop determines the background color of the Alert. It accepts any of the Color types defined in our library see options above. If not provided, it defaults to the primary color.

Example usage:

function AlertColors(){
    return(
        <Alert title="Success!" color="dan" />
        <Alert title="Success!" color="war" />
        <Alert title="Success!" color="suc" />
        <Alert title="Success!" color="pri" />
        <Alert title="Success!" color='bg' />
        <Alert title="Success!" color="sec" />
    )
}

Size

  • Type: string
  • Default: md
  • Options: 2xs | xs | sm | md | lg | xl | 2xl

The size prop determines the size of the Alert. It accepts any of the Size types defined in our library see options above. If not provided, it defaults to the md size.

Example usage:

function AlerSizes(){
    return(
        <Alert title="Success!" size='3xs' />
        <Alert title="Success!" size='2xs' />
        <Alert title="Success!" size='xs' />
        <Alert title="Success!" size='md' />
        <Alert title="Success!" size='lg' />
        <Alert title="Success!" size='xl' />
        <Alert title="Success!" size='2xl' />
        <Alert title="Success!" size='3xl' />
    )
}

Variant

The variant prop determines the visual style of the alert. The following are the descriptions of the different variants:

Type: string Default: solid Options: solid | outline | soft | mixed

export const AlertVariant = () => {
  return (
    <Flex direction="column" gap="sm">
      <AlertBase variant="solid" />
      <AlertBase variant="outline" />
      <AlertBase variant="soft" />
      <AlertBase variant="mixed" />
    </Flex>
  )
}

Corner

Type: string Default: md Options: sharp | xs | sm | md | lg | circle | full The size prop determines the size of the Alert. It accepts any of the Size types defined in our library see options above. If not provided, it defaults to the md size.

The corner prop determines the border radius of the Alert. It accepts any of the Corner types defined in your library, including (square, xs, sm, md, xl, full, circle), and pill. If not provided, it defaults to the square corner.

Example usage:

function AlerCorners(){
    return(
        <Alert title="Success!" corner='sharp' />
        <Alert title="Success!" corner='xs' />
        <Alert title="Success!" corner='md' />
        <Alert title="Success!" corner='lg' />
        <Alert title="Success!" corner='xl' />
        <Alert title="Success!" corner='circle' />
        <Alert title="Success!" corner='full' />
    )
}

Content

The content of the Alert the text displayed as the Alert's title. If not provided, the title section of the Alert will not be displayed.

Example usage:

function(){
    return(
        <div>
            <Alert title="Success!" />
            <Alert icon={<CheckCircle />}  title="Success!" />
            <Alert message="Success!" />
            <Alert title="Success!" message='Your prefered description' />
            <Alert icon={<CheckCircle />}  title="Success!"  message='Your prefered description' />
        </div>
    )
}

Icon

The icon prop allows you to display an icon alongside the Alert. It accepts any ReactNode, such as an icon from the @pillar-ui/icons package. If no icon is provided, no icon will be displayed. Example usage:

<Paper borderColor="opa-6" flow="sm" ="sm" background="bg-3" corner="sm">
  <Alert icon={<CircleCheck width="32" />} title="Success!" />
  <Alert icon={<CircleCheck width="32" />} title="Success!" />
  <Alert icon={<CircleCheck width="48" />} title="Success!" message="Your prefered description" />
</Paper>

Closable

The closable prop determines whether the Alert should be closable by the user. If set to true, a close button will be displayed on the Alert. If not provided, it defaults to false.

Example usage:

<Paper borderColor="opa-6" flow="sm" ="sm" background="bg-3" corner="sm">
  <Alert closable title="Success!" />
  <Alert closable title="Success!" message="you have an error in the start of the program" />
  <Alert closable message="you have an error in the start of the program!" />
</Paper>

Inline

The inline prop determines how the alert is displayed. If set to true, the alert will be displayed horizontally, which is useful for short alerts that do not take up a lot of space, such as notifications or messages. If not set or set to false, the alert will be displayed as a vertically. Example usage:

<Flex direction="column" gap="sm">
  <Alert title="hello" message="you have an error in the start of the program" inline />
  <Alert title="hello" message="you have an error in the start of the program" inline />
  <Alert
    title="hello"
    message="you have an error in the start of the program you have an error in the start of the program you have an error in the start of the program  of the program you have an error in the start of the program"
    inline
  />
  <Alert
    title="hello"
    message="you have an error in the start of the program"
    inline
    icon={<CircleWarning width="20" />}
  />
  <Alert title="hello" message="you have an error in the start of the program" inline closable />
  <Alert
    title="hello"
    message="you have an error in the start of the program"
    inline
    icon={<CircleWarning width="20" />}
    closable
  />
</Flex>

Accessibility

Accessibility is a core feature of Pillar UI, extending to components like the Alert. Here's a guide on ensuring accessibility when employing the Alert component:

  • Clarity in Language: Opt for straightforward wording in the Alert's title and message, sidestepping jargon or multi-meaning terms that could confuse users.
  • Contrast Considerations: Guarantee that the Alert's color sharply contrasts the background, ensuring readability for those with color vision impairments or limited sight.
  • ARIA Roles and Attributes: Leverage ARIA roles and attributes for accurate interpretation by assistive tech. For example, role="alert" signifies crucial user information.
  • Support for Reduced Motion and Forced Colors: Our components also accommodate users with "Reduced Motion" preferences, ensuring a comfortable experience. Additionally, we ensure that our components remain readable and usable for users relying on the "Forced Colors" feature.

Best Practice

  • Use Alerts to provide feedback to the user when an action is successful or fails.
  • Use Alerts to inform users of important or time-sensitive information, such as system outages, maintenance, or changes in a workflow.
  • Use Alerts to communicate errors and warnings to the user, such as invalid input or unsuccessful form submissions.
  • Use Alerts sparingly and avoid overusing them, as they can be distracting and overwhelm the user.
  • Avoid using technical jargon or ambiguous language

Use case:

The Alert component can be used in a variety of situations, such as:

  • Displaying error messages or warnings
  • Providing feedback to the user after completing an action
  • Notifying the user of important information or updates
  • Asking for confirmation before performing a critical action

Troubleshooting:

If the Alert component is not behaving as expected, it may be due to an incorrect usage of the component or the props passed to it. Some common issues to check for include:

  • Incorrectly passing props to the Alert component
  • Using an invalid value for a prop, such as an invalid alert type
  • Improperly handling the onClose function or passing in an incorrect function
  • Missing required props for the Alert component
  • If you are still having issues, try checking the documentation or seeking help from the community or the @pillar-ui/core library maintainers.

Conclusion:

The Alert component is a powerful tool for displaying messages to the user in a clear and effective way. By customizing its appearance and behavior using props, the Alert component can be tailored to meet the specific needs of an application.

We hope this documentation helps you understand and use the Alert component in your projects! If you have any questions or need further assistance, don't hesitate to ask.