Feedback Messages
Feedback messages are non-intrusive, informational messages that keep users informed about various events within a system. They report a system occurrence that does not require immediate actions( different from the alert dialog that requires a user action).
Prerequisites
Add FeedbackMessages component anywhere in your application. Note that:
- You do not need to wrap your application with
FeedbackMessagescomponent – it is not a provider, it is a regular component - You should not render multiple
FeedbackMessagescomponents – if you do that, your messages will be duplicated
Source Code
import { FeedbackMessages } from '@ocean-network-express/magenta-ui/react';
function Demo() {
return (
<>
<FeedbackMessages />
{/* Your app here */}
</>
)
}
All set! You can now use all FeedbackMessages system features.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function Prerequisites() {
return (
<>
<FeedbackMessages />
<Button onClick={() => message('This is a default message')}>Show Toast</Button>
</>
);
}
- The most basic usage of the
FeedbackMessagescomponent is to show a toast message. You can do this by calling themessagefunction with a string as an argument. The message will be displayed in the top right corner of the screen.
Variants
- The
messagefunction supports different message types. - You can use the
alert,banner, andtoastto display different types of messages. - Default type is
toast.
Source Code
import { InfoCircleOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
FeedbackMessages,
FeedbackMessageType,
message,
} from '@ocean-network-express/magenta-ui/react';
export function Variants({ includeFB = false }: { includeFB?: boolean }) {
return (
<div
style={{Sizes
-
FeedbackMessagessupports sizes sizessm,md,lg,responsive, and can be changed by passing thesizevalue. -
Default size is
lg.Source Code
<FeedbackMessages size="responsive" /> -
You also override another size through
messagefunction.
Source Code
import { Button, message} from '@ocean-network-express/magenta-ui/react';
function Demo() {
return (
<Button variant="outline" onClick={
() => message('This is a red message', { size: 'md' })
}>Click here</Button>
)
}Colors
- The
messagefunction supports 5 colorsred,green,blue,orangeandneutraland can be changed by passing thecolorvalue. - Default color is
blue.
Source Code
import {
Button,
FeedbackMessageColor,
FeedbackMessages,
message,
} from '@ocean-network-express/magenta-ui/react';
const upperFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
type FeedbackColor = (typeof FeedbackMessageColor)[keyof typeof FeedbackMessageColor];
const ColorOptions = Object.values(FeedbackMessageColor).map((color) => ({Positions
- The
messagefunction supports 6 positionstop-left,top-right,top-center,bottom-left,bottom-rightandbottom-centerand can be changed by passing thepositionprop. - Default position is
top-right.
Source Code
import {
Button,
FeedbackMessagePosition,
FeedbackMessages,
message,
} from '@ocean-network-express/magenta-ui/react';
const upperFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
export function Positions({ includeFB = false }: { includeFB?: boolean }) {
const PositionOptions = Object.values(FeedbackMessagePosition).map((position) => ({
label: position.split('-').map(upperFirst).join(' '),- Another way to change the position of the message is passing the
positionprop to theFeedbackMessagescomponent. - It will change the default position of all messages in the app.
Source Code
import { FeedbackMessages, FeedbackMessagePosition } from '@ocean-network-express/magenta-ui/react';
function Demo() {
return (
<>
<FeedbackMessages position={FeedbackMessagePosition.BOTTOM_CENTER} />
{/* Your app here */}
</>
)
}Prefix Icon
- The
messagefunction supports icons from the@ocean-network-express/magenta-ui/iconspackage. - The prop
iconsupport to add icon or other content to the left side.
Source Code
import { InfoCircleOutline } from '@ocean-network-express/magenta-ui/icons';
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function PrefixIcon({ includeFB = false }: { includeFB?: boolean }) {
return (
<>
<Button
onClick={() =>
message('This is a Prefix Icon message', {
icon: <InfoCircleOutline />,
})
}Actions
messagefunction can include links by passing theurlsoractionsvalue depending on whichtypeof message you are using.
Action Buttons
-
The
messagefunction supports action buttons. You can add action buttons by passing theactionsvalue. -
The
actionsvalue is an array of objects with the following properties:label: The text to display on the button.- All other props are the same as the Button component.
- Some default props in the action button are
colorissecondary,variantisoutline, andsizeismd.
-
Note: The
actionsvalue is only available forbannerandtoasttypes.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function Actions({ includeFB = false }: { includeFB?: boolean }) {
return (
<div
style={{
display: 'flex',
gap: '1rem',
}}
>
<Button
onClick={() =>Links
-
The
messagefunction can include links by passing theurlsvalue. -
The
urlsvalue is an array of objects with the following properties:displayText: The text to display on the link.- All other props are the same as the Link component.
-
Note: The
urlsvalue is only available foralertandbannertypes.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function ActionsLinks({ includeFB = false }: { includeFB?: boolean }) {
return (
<div
style={{
display: 'flex',
gap: '1rem',
}}
>
<Button
onClick={() =>Custom Links and Actions
You can custom links and actions by passing custom React components.
Source Code
import {
Button,
FeedbackMessages,
Link,
message,
Tag,
TagContent,
} from '@ocean-network-express/magenta-ui/react';
export function CustomLinks({ includeFB = false }: { includeFB?: boolean }) {
const CustomComponent = () => (
<>Close A Message
Remove Close Icon Button
- The
messagefunction can remove the close button icon or by setting theclosablevalue tofalse.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function CloseIcon({ includeFB = false }: { includeFB?: boolean }) {
return (
<>
<Button
onClick={() =>
message('This is a Un-Closable message', {
closable: false,
})
}
>Close duration
- By default, the messages will close automatically after 10 seconds.
- The
messagefunction can include the close duration by passing thedurationvalue.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function Duration({ includeFB = false }: { includeFB?: boolean }) {
return (
<>
<Button
onClick={() =>
message('This is a 2000ms duration message', {
duration: 2000,
})
}
>- To prevent the messages from closing automatically, set the duration value to
0orInfinity.
Source Code
import { Button, FeedbackMessages, message } from '@ocean-network-express/magenta-ui/react';
export function DurationInfinity({ includeFB = false }: { includeFB?: boolean }) {
return (
<>
<Button
onClick={() =>
message('This is a not auto close message', {
duration: 0,
closable: true,
})
}- Another way to change the duration of the message is passing the
durationprop to theFeedbackMessagescomponent. - It will change the default duration of all messages in the app.
Source Code
import { FeedbackMessages } from '@ocean-network-express/magenta-ui/react';
function Demo() {
return (
<>
<FeedbackMessages duration={2000} />
{/* Your app here */}
</>
)
}Placement
- Customize the placement of messages by using the
styleprop on theFeedbackMessagescomponent. This will modify the default offset for all messages. - A common use case here is to display new notifications 48px below the navigation bar.
Source Code
<div>
{/* Your navigation bar here */}
<Button
onClick={() =>
message('Service wait times', {
type: FeedbackMessageType.ALERT,
icon: <WarningOutline />,
message: 'We are experiencing longer than normal wait times at this location',
color: FeedbackMessageColor.ORANGE,
})
}
>TypeScript
FeedbackMessageType,FeedbackMessageColor,andFeedbackMessagePositionare EnumValues exported from@ocean-network-express/magenta-ui/react.
Source Code
import { FeedbackMessageType, FeedbackMessageColor, FeedbackMessagePosition } from '@ocean-network-express/magenta-ui/react';Was this page helpful?
Alert
Notification
Message
Toast
Banner