Flags provider

Flags provider creates a flag group and manages the state of flags.

Default

To show flags without managing a FlagGroup, wrap your application in a FlagsProvider, which provides context to its children.

import React from 'react'; import { FlagsProvider } from '@atlaskit/flag'; const FlagProviderExample = () => { return ( <FlagsProvider> <h3>I'm wrapped in a flags provider.</h3> </FlagsProvider> ); }; export default FlagProviderExample;

Using showFlags

Any components within your application can now access the function showFlags from the context by calling useFlags. Call showFlags with an object of type CreateFlagArgs and a Flag will be displayed. CreateFlagArgs is defined as follows:

actions

Description

Array of clickable actions to be shown at the bottom of the flag. For flags where appearance is 'normal', actions will be shown as links. For all other appearance values, actions will shown as buttons. If href is passed the action will be shown as a link with the passed href prop.

TypeActionType[]

analyticsContext

Description

Additional information to be included in the context of analytics events that come from flag.

Type{ [x: string]: any; }

appearance

Description

Makes the flag appearance bold. Setting this to anything other than 'normal' hides the dismiss button.

Type"error" | "info" | "success" | "warning" | "normal"

createAnalyticsEvent

Description

You should not be accessing this prop under any circumstances. It is provided by @atlaskit/analytics-next and integrated in the component

Type(payload: AnalyticsEventPayload) => UIAnalyticsEvent

delayAnnouncement

Description

Milliseconds to delay the screen reader announcement due to announcement conflict.

Typenumber

description

Description

The secondary content shown below the flag title.

Typestring | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal

headingLevel

Description

Specifies the heading level in the document structure. If not specified, the default is 2.

Type1 | 2 | 3 | 4 | 5 | 6

icon

Description

The icon displayed in the top-left of the flag. Should be an instance of @atlaskit/icon. Your icon will receive the appropriate default color, which you can override by setting the color prop on the icon to your preferred icon color. If no icon is provided, a default icon will be used based on the appearance prop.

Typestring | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal

id

Description

A unique identifier used for rendering and onDismissed callbacks. This will be autogenerated if you don’t supply one. If you don’t want the same flag showing multiple times, provide a unique id.

Typestring | number

isAutoDismiss

Description

Marks whether the flag should render as an AutoDismissFlag

Typeboolean

linkComponent

Description

A link component that is passed down to the @atlaskit/button used by actions, to allow custom routers to be used. See the button with router example of what this component should look like.

TypeComponentClass<CustomThemeButtonProps, any> | FunctionComponent<CustomThemeButtonProps>

onBlur

Description

Standard onBlur event, applied to Flag by AutoDismissFlag.

Type(e: FocusEvent<HTMLElement, Element>, analyticsEvent: UIAnalyticsEvent) => void

onDismissed

Description

Handler which will be called when a Flag's dismiss button is clicked. Receives the id of the dismissed Flag as a parameter.

Type(id: string | number, analyticsEvent: UIAnalyticsEvent) => void

onFocus

Description

Standard onFocus event, applied to Flag by AutoDismissFlag.

Type(e: FocusEvent<HTMLElement, Element>, analyticsEvent: UIAnalyticsEvent) => void

onMouseOut

Description

Standard onMouseOut event, applied to Flag by AutoDismissFlag.

Type(event: MouseEvent<Element, MouseEvent>) => void

onMouseOver

Description

Standard onMouseOver event, applied to Flag by AutoDismissFlag.

Type(event: MouseEvent<Element, MouseEvent>) => void

ref

Description
No description.
Type((instance: any) => void) | RefObject<any>

testId

Description

A testId prop is provided for specified elements, which is a unique string that appears as a data attribute data-testid in the rendered code, serving as a hook for automated tests.

Will set these elements when defined:

  • Flag root element - {testId}
  • Close button visible on default flags - {testId}-dismiss
  • Toggle button visible on bold flags - {testId}-toggle
  • Flag content which wraps the description and actions - {testId}-expander
  • Flag description - {testId}-description
  • Flag actions - {testId}-actions
Typestring

title

Required
Description

The bold text shown at the top of the flag.

Typestring | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal

The return value of showFlags is a function that dismisses the flag that was just created.

import React, { useRef } from 'react'; import ButtonGroup from '@atlaskit/button/button-group'; import Button from '@atlaskit/button/new'; import noop from '@atlaskit/ds-lib/noop'; import { FlagsProvider, useFlags } from '@atlaskit/flag'; import InformationIcon from '@atlaskit/icon/glyph/info'; import { token } from '@atlaskit/tokens'; const actions = [ { content: 'Nice one!', onClick: noop, }, ]; const FlagGroupExample = () => { const flagCount = useRef(1); const { showFlag } = useFlags(); const addFlag = () => { const id = flagCount.current++; showFlag({ actions, description: 'Added from the context.', icon: ( <InformationIcon label="Info" primaryColor={token('color.icon.information')} /> ), id: id, title: `${id}: Whoa a new flag!`, }); }; const addFlagNoId = () => { showFlag({ actions, description: 'I was not given an id.', icon: ( <InformationIcon label="Info" primaryColor={token('color.icon.information')} /> ), title: `${flagCount.current++}: Whoa a new flag!`, }); }; const addAutoDismissFlag = () => { showFlag({ actions, description: 'I will automatically dismiss after 8 seconds.', icon: ( <InformationIcon label="Info" primaryColor={token('color.icon.information')} /> ), title: `${flagCount.current++}: Whoa a new flag!`, isAutoDismiss: true, }); }; return ( <ButtonGroup label="Choose a flag"> <Button onClick={addFlag}>Add Flag</Button> <Button onClick={addFlagNoId}>Add Flag without id</Button> <Button onClick={addAutoDismissFlag}>Add AutoDismissFlag</Button> </ButtonGroup> ); }; export default () => ( <FlagsProvider> <FlagGroupExample /> </FlagsProvider> );
Was this page helpful?
We use this feedback to improve our documentation.
Navigated to Flags provider