Toasts are small messages designed to mimic push notifications. They are used to provide users with application level information.
import { DaffToastPositionService } from '@daffodil/design/toast'
@Injectable()
class DaffToastPositionService {
config: DaffToastPosition
setPosition(position: DaffToastPosition): void
}
DaffToastPosition
Default | – |
---|---|
Description | Reads the current position of the toast. Defaults to bottom center on mobile devices. |
void
Changes the position of the toast.
Parameter | position: DaffToastPosition |
---|---|
Description | The position of the toast. |
import { DaffToastService } from '@daffodil/design/toast'
Service to display toasts.
@Injectable()
class DaffToastService implements OnDestroy {
open(
toast: DaffToastData
configuration?: Partial<DaffToastConfiguration>
): DaffToast
close(toast: DaffToast): void
}
DaffToast
Opens the toast.
Parameter | toast: DaffToastData |
---|---|
Description | Data that can be shown on a toast. |
Parameter | configuration: Partial<DaffToastConfiguration> |
---|---|
Description | Additional configuration options such as duration. The default duration is set to 5000ms. |
void
Closes the toast.
Parameter | toast: DaffToast |
---|---|
Description | The instance of toast that you wish to close. |
import { DAFF_TOAST_OPTIONS } from '@daffodil/design/toast'
const DAFF_TOAST_OPTIONS: InjectionToken<DaffToastOptions>
import { DaffToastConfiguration } from '@daffodil/design/toast'
interface DaffToastConfiguration {
duration: number
}
duration number |
---|
The duration (in milliseconds) for which a toast remains visible before dismissal. While you can set a duration for toasts with actions, it's generally not recommended, as users should have ample time to interact with them. |
import { DaffToast } from '@daffodil/design/toast'
interface DaffToast {
dismiss: () => void
dismissalStream: Observable<void | number>
}
dismiss () => void |
---|
Closes the toast. |
dismissalStream Observable<void | number> |
---|
The observable that emits when the toast is closed. |
import { DaffToastData } from '@daffodil/design/toast'
Possible data that can be shown on a toast
interface DaffToastData {
title: string
message: string
status: DaffStatus
actions: DaffToastAction[]
dismissible: boolean
}
title string |
---|
A title that provides a quick oveview of the toast. |
message string |
---|
A short message used to provide additional details about the toast. |
status DaffStatus |
---|
Sets a status on the toast. |
actions DaffToastAction[] |
---|
Used to display actions in the toast. |
dismissible boolean |
---|
Whether or not the toast is dismissible. |
import { DaffToastAction } from '@daffodil/design/toast'
The configurations for an action button rendered inside a toast
displayed using the DaffButtonComponent
.
interface DaffToastAction {
type: DaffToastActionButtonType
content: string
size: DaffToastActionButtonSize
color: DaffPalette
status: DaffStatus
data: Record<string, any>
eventEmitter: EventEmitter<DaffToastAction>
}
type DaffToastActionButtonType |
---|
The type of button. Matches one of the predefined types supported by |
content string |
---|
The text displayed on the button. |
size DaffToastActionButtonSize |
---|
The size of the button. Matches one of the predefined sizes supported by |
color DaffPalette |
---|
The color of the button. Do not use both |
status DaffStatus |
---|
The button status. Do not use both |
data Record<string, any> |
---|
Data associated with the action. |
eventEmitter EventEmitter<DaffToastAction> |
---|
An event emitter that fires when the action is triggered. |
import { DaffToastActionButtonSize } from '@daffodil/design/toast'
The available button sizes that can be used in DaffToastAction
.
These correspond to the types supported by DaffButtonComponent
.
type DaffToastActionButtonSize = 'sm' | 'md' | 'lg' | undefined
import { DaffToastActionButtonType } from '@daffodil/design/toast'
The available button styles that can be used in DaffToastAction
.
These correspond to the types supported by DaffButtonComponent
.
type DaffToastActionButtonType = 'raised' | 'underline' | 'stroked' | 'flat' | undefined
import { provideDaffToastOptions } from '@daffodil/design/toast'
const provideDaffToastOptions: <R extends DaffToastOptions = DaffToastOptions>(config: Partial<R> | InjectionToken<Partial<R>>) => FactoryProvider
import { provideDaffToast } from '@daffodil/design/toast'
Registers the DaffToastService
and DaffToastPositionService
for displaying a toast. This provider ensures
toasts function correctly within your application.
import { provideDaffToast } from '@daffodil/design/toast';
@NgModule({
providers: [
provideDaffToast(),
]
)}
export class AppModule {}
const provideDaffToast: () => Provider[]