Skip to content

Description

The GlobalStatus is a complex component meant for displaying global Application notifications or a summary of a form ( displaying form errors, messages etc. ). By default, the GlobalStatus is automatically connected together with the FormStatus component. This means, that every form component showing a status, will send the status message along to the GlobalStatus.

FormStatus default behavior

  1. Once a FormStatus is shown, the main GlobalStatus will show up.
  2. The page will scroll (if needed) to the dedicated GlobalStatus.
  3. Form components will send along both the status text and its label to show a good and accessible summary.
  4. Screen reader uses will automatically hear the whole content of the GlobalStatus once it shows up.

Several Global statuses

Normally, you only want to have one GlobalStatus inside your application. But you can have several in parallel. But make sure you give every other a new ID:

Code Editor
<GlobalStatus id="other-global-status" />

Where to put it

  • The GlobalStatus component should be positioned right under the header. By default, it uses main as the ID.
  • Or as a secondary summary of errors in a submit form. Keep in mind, by default, form components like Input are using the ID main. To make sure the build in FormStatus is sending along the message to another GlobalStatus, you have to set the globalStatus, like:
Code Editor
<GlobalStatus id="other-global-status" />
<Input
  globalStatus={{
    id: 'other-global-status',
  }}
/>

But you can also make use of the Eufemia Provider where you will be able to send along the globalStatus the underlying/wrapped components, like:

Code Editor
<GlobalStatus id="other-global-status" />
<Provider
  formElement={{
    globalStatus: {
      id: 'other-global-status',
    },
  }}
>
  <Input status="Message" />
</Provider>

Manually updates

Besides the automated connection between the error states of form components (FormStatus), you can update messages from everywhere in your application at any time:

NB: The GlobalStatus will autoclose by default, once all messages are removed.

JavaScript (interceptor situation)

You can access and manipulate an existing GlobalStatus from outside of the React render tree.

  1. Given you have already defined a GlobalStatus in JSX:
Code Editor
<GlobalStatus id="other-global-status" />
  1. Then you can control it from within a JavaScript context whenever you need to:
Code Editor
// 1. Update / extend the the status like so:

const statusOne = GlobalStatus.create({
  id: 'other-global-status',
  // or main
  status_id: 'custom-id-1',
  text: 'New Text',
  item: 'Item from status #1',
  title: 'New Title',
  show: true,
})

// 2. and removes "custom-id-1" again if needed

statusOne.update({
  text: 'Updated Text',
})

// 3. and removes "custom-id-1" again if needed
statusOne.remove()
render(<GlobalStatus id="other-global-status" />)

JSX

Code Editor
{/* 1. Place it under the header bar */}
<GlobalStatus text="Optional default text" />
{/* 2. later on, you can show a message */}
<GlobalStatus.Add
  id="custom-id"
  status_id="custom-id-1"
  title="New title"
  text="First long info text ..."
  item="Item from status #1"
  on_close={({ status_id }) => {
    console.log('on_close', status_id)
  }}
/>
{/* 3. and remove it again */}
<GlobalStatus.Remove id="custom-id" status_id="custom-id-1" />

If you need an additional GlobalStatus, define a custom ID (custom-status):

Code Editor
{/* 1. Place it somewhere in your application */}
<GlobalStatus id="custom-status" />
{/* 2. later on, you can show a message */}
<GlobalStatus.Add
  id="custom-status"
  status_id="custom-id-1"
  title="New title"
  text="First long info text ..."
  item="Item from status #1"
  on_close={({ status_id }) => {
    console.log('on_close', status_id)
  }}
/>
{/* 3. and remove it again */}
<GlobalStatus.Remove id="custom-status" status_id="custom-id-1" />

Demos

GlobalStatus displaying error status

NB: Keep in mind, the items are handled automatically by all form components! This is just an example of how to define the content manually.

Custom Title

Failure text


Code Editor
<GlobalStatus
  title="Custom Title"
  text="Failure text"
  items={[
    {
      text: 'List item',
      status_anchor_url: '/uilib/components/global-status',
      status_anchor_label: 'eksempel',
    },
  ]}
  show={true}
  autoscroll={false}
  no_animation={true}
  omit_set_focus={true}
  id="demo-1"
/>

GlobalStatus displaying info status

Code Editor
<GlobalStatus
  state="info"
  title="Custom info title ..."
  text="Long info nisl tempus hendrerit tortor dapibus nascetur taciti porta risus cursus fusce platea enim curabitur proin nibh ut luctus magnis metus"
  items={['Status text 1', 'Status text 2']}
  show={true}
  autoscroll={false}
  no_animation={true}
  omit_set_focus={true}
  id="demo-4"
/>

GlobalStatus displaying warning status

Custom warning title ...

A string of text providing a warning or semi-urgent message of some kind to the user


Code Editor
<GlobalStatus
  state="warning"
  title="Custom warning title ..."
  text="A string of text providing a warning or semi-urgent message of some kind to the user"
  show={true}
  autoscroll={false}
  no_animation={true}
  omit_set_focus={true}
  id="demo-5"
/>

GlobalStatus displaying success status

Custom success title ...

A string of text providing a success message of some kind to the user


Code Editor
<GlobalStatus
  state="success"
  title="Custom success title ..."
  text="A string of text providing a success message of some kind to the user"
  show={true}
  autoscroll={false}
  no_animation={true}
  omit_set_focus={true}
  id="demo-6"
/>

To showcase the automated coupling between FormStatus and GlobalStatus

Code Editor
const InputWithError = () => {
  const [errorMessage, setErrorMessage] = React.useState(null)
  return (
    <Input
      label="Input"
      placeholder="Write less than 5 chars and dismiss the focus to show the GlobalStatus ..."
      stretch
      status={errorMessage}
      on_blur={({ value }) => {
        setErrorMessage(value.length <= 4 ? 'With a message shown' : null)
      }}
      globalStatus={{
        id: 'main-status',
      }}
    />
  )
}
render(<InputWithError />)

GlobalStatus and update routines

To showcase the custom Update and Remove possibility

To showcase the scrolling