2.0.0-rc.4 • Published 9 months ago

@asphalt-react/flag v2.0.0-rc.4

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
9 months ago

Flag

npm

Flag component is used to provide any information from the application to the user. They should be used for successful, cautious, destructive kind of messages. Flags can be inlined, floated, embedded or shown as a banner.

Usage

import {
  InlineFlag,
  FloatingFlag,
  BannerFlag,
  PageFlag
} from "@asphalt-react/flag"

<InlineFlag success>
  Email format is incorrect
</InlineFlag>

<FloatingFlag title="Remove user?" danger>
  This action is irreversible
</FloatingFlag>

<BannerFlag title="Policy changes" warning>
  Tax rules are changing in the next month
</BannerFlag>

<PageFlag title="We don't spam" neutral>
  We will only send you useful emails
</PageFlag>

Variants

There are four variants of Flags, each available as named exports:

  1. InlineFlag: Used to show information related to form fields, for example, a validation error.

  2. FloatingFlag: Used for showing alerts or toasts. Floating flags are responsive to viewport sizes. Floating flags have support intent background color by default.

  3. BannerFlag: Used to show information that demands more user attention. It adjusts to the container's width always.

  4. PageFlag: Used to show contextual background information for filling a form. Embeds the Flag into the page and adjusts to the container's width.

Intents

All Flags support multiple support intents:

  • info (default): a generic information
  • success: information with successful intent
  • warning: information with warning intent; demands more attention that info
  • danger: critical information that demands the most attention. Used for information leading to destructive actions like removing a user.
  • neutral: information that demands least user attention
  • invalid: used to show form field error messages; applicable for "inline" variant only.

Competing intents

If a Flag receives multiple intents, it fallbacks to the "info" intent. For example:

<PageFlag warning danger title="Required fields">
  All fields are mandatory
</PageFlag>

This will render a Page flag with "info" intent.

Purposeful Areas

Flags is composed of predefined areas to serve a particular purpose. They adapt to different variants and intents.

  • Title - a brief one-line message.
  • Description - main content of the flag.
  • Icon - a qualifier SVG according to the variant; can be overridden with a custom SVG
  • Action - a container for actionable elements like buttons or links.
  • Dismiss - a button to dismiss the flag. Renders by default in all flags except "inline" variant

InlineFlag only has icon and text in them and they are not dismissible.

Positioning in Banner and Page variants

Icon & Title can be center aligned when there is no description and action area. Actions render in the start of the flag. They can be moved to the end as well.

InlineFlag

Props

children

React node for the main content.

typerequireddefault
nodefalsenull

icon

To override the default qualifier icon. Pass false to hide it.

Accepts SVG.

typerequireddefault
unionfalsenull

size

Size of the flag, controls the icon and text size.

typerequireddefault
enumfalse"m"

info

Enables the info intent.

typerequireddefault
boolfalsefalse

success

Enables the success intent.

typerequireddefault
boolfalsefalse

danger

Enables the danger intent.

typerequireddefault
boolfalsefalse

warning

Enables the warning intent.

typerequireddefault
boolfalsefalse

neutral

Enables the neutral intent.

typerequireddefault
boolfalsefalse

invalid

Enables the invalid intent.

typerequireddefault
boolfalsefalse

FloatingFlag

Props

children

React node for the description content.

typerequireddefault
nodefalsenull

title

React node for the title content.

typerequireddefault
nodefalsenull

icon

To override the default qualifier icon. Pass false to hide it.

Accepts SVG.

typerequireddefault
unionfalsenull

actions

List of actionable elements.

typerequireddefault
nodefalsenull

info

Enables the info intent.

typerequireddefault
boolfalsefalse

success

Enables the success intent.

typerequireddefault
boolfalsefalse

danger

Enables the danger intent.

typerequireddefault
boolfalsefalse

warning

Enables the warning intent.

typerequireddefault
boolfalsefalse

neutral

Enables the neutral intent.

typerequireddefault
boolfalsefalse

highlight

Adds a support intent background color to make the flag prominent.

typerequireddefault
boolfalsetrue

onDismiss

Callback for dismiss action.

typerequireddefault
funcfalseN/A

BannerFlag

Props

children

React node for the description content.

typerequireddefault
nodefalsenull

title

React node for the title content.

typerequireddefault
nodefalsenull

titleCenter

Centers the title horizontally.

typerequireddefault
boolfalsefalse

icon

To override the default qualifier icon. Pass false to hide it.

Accepts SVG.

typerequireddefault
unionfalsenull

actions

List of actionable elements.

typerequireddefault
elementfalsenull

actionsEnd

Positions the actionable element towards the end of the container

typerequireddefault
boolfalsefalse

info

Enables the info intent.

typerequireddefault
boolfalsefalse

success

Enables the success intent.

typerequireddefault
boolfalsefalse

danger

Enables the danger intent.

typerequireddefault
boolfalsefalse

warning

Enables the warning intent.

typerequireddefault
boolfalsefalse

neutral

Enables the neutral intent.

typerequireddefault
boolfalsefalse

onDismiss

Callback for the dismiss action.

typerequireddefault
funcfalseN/A

PageFlag

Props

children

React node for the description content.

typerequireddefault
nodefalsenull

title

React node for the title content.

typerequireddefault
nodefalsenull

titleCenter

Centers the title horizontally.

typerequireddefault
boolfalsefalse

icon

To override the default qualifier icon. Pass false to hide it.

Accepts SVG.

typerequireddefault
unionfalsenull

actions

List of actionable elements.

typerequireddefault
elementfalsenull

actionsEnd

Positions the actionable element towards the end of the container

typerequireddefault
boolfalsefalse

info

Enables the info intents.

typerequireddefault
boolfalsefalse

success

Enables the success intents.

typerequireddefault
boolfalsefalse

danger

Enables the danger intents.

typerequireddefault
boolfalsefalse

warning

Enables the warning intents.

typerequireddefault
boolfalsefalse

neutral

Enables the neutral intents.

typerequireddefault
boolfalsefalse

dismiss

Renders a dismiss button.

typerequireddefault
boolfalsetrue

onDismiss

Callback for dismiss action.

typerequireddefault
funcfalsenull