-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b36742d
commit fa33491
Showing
9 changed files
with
64 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 10 additions & 21 deletions
31
svelte/demo/src/bootstrap/samples/alert/Dynamic.route.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,25 @@ | ||
<script lang="ts"> | ||
import {Alert} from '@agnos-ui/svelte-bootstrap/components/alert'; | ||
import type {AlertProps} from '@agnos-ui/svelte-bootstrap/components/alert'; | ||
import {writable} from 'svelte/store'; | ||
import {AlertService} from './alert-service.svelte'; | ||
function createAlerts() { | ||
const {subscribe, set, update} = writable([] as Partial<AlertProps>[]); | ||
return { | ||
subscribe, | ||
add: (alert: Partial<AlertProps>) => update((alerts) => [...alerts, alert]), | ||
remove: (alert: Partial<AlertProps>) => update((alerts) => alerts.filter((a) => a !== alert)), | ||
reset: () => set([]), | ||
}; | ||
} | ||
const alerts$ = createAlerts(); | ||
const alertService = new AlertService(); | ||
</script> | ||
|
||
<button class="btn btn-primary addError me-1" onclick={() => alerts$.add({type: 'danger', children: 'Error', dismissible: true, animated: true})} | ||
<button class="btn btn-primary addError me-1" onclick={() => alertService.add({type: 'danger', children: 'Error', dismissible: true, animated: true})} | ||
>Add error</button | ||
> | ||
|
||
<button class="btn btn-primary addInfo me-1" onclick={() => alerts$.add({type: 'info', children: 'Info', dismissible: true, animated: true})} | ||
<button class="btn btn-primary addInfo me-1" onclick={() => alertService.add({type: 'info', children: 'Info', dismissible: true, animated: true})} | ||
>Add info</button | ||
> | ||
|
||
<button class="btn btn-primary addWarning me-1" onclick={() => alerts$.add({type: 'warning', children: 'Warning', dismissible: true, animated: true})} | ||
>Add warning</button | ||
<button | ||
class="btn btn-primary addWarning me-1" | ||
onclick={() => alertService.add({type: 'warning', children: 'Warning', dismissible: true, animated: true})}>Add warning</button | ||
> | ||
|
||
<br /> | ||
<div class="alertCount mb-3">Alerts in the service: {$alerts$.length}</div> | ||
{#each $alerts$ as alert (alert)} | ||
<Alert {...alert} onHidden={() => alerts$.remove(alert)} /> | ||
<div class="alertCount mb-3">Alerts in the service: {alertService.alerts.length}</div> | ||
{#each alertService.alerts as alert (alert)} | ||
<Alert {...alert} onHidden={() => alertService.remove(alert)} /> | ||
{/each} |
13 changes: 13 additions & 0 deletions
13
svelte/demo/src/bootstrap/samples/alert/alert-service.svelte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type {AlertProps} from '@agnos-ui/svelte-bootstrap/components/alert'; | ||
|
||
export class AlertService { | ||
#alerts = $state<Partial<AlertProps>[]>([]); | ||
|
||
get alerts() { | ||
return this.#alerts; | ||
} | ||
|
||
readonly add = (alert: Partial<AlertProps>) => this.#alerts.push(alert); | ||
readonly remove = (alert: Partial<AlertProps>) => this.#alerts.splice(this.#alerts.indexOf(alert), 1); | ||
readonly reset = () => (this.#alerts = []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
svelte/demo/src/bootstrap/samples/toast/toast-service.svelte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {ToastPositions} from '@agnos-ui/common/samples/toast/toast-positions.enum'; | ||
import type {ToastProps} from '@agnos-ui/svelte-bootstrap/components/toast'; | ||
|
||
export class ToastService { | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly | ||
#toasts = $state(Object.fromEntries(Object.values(ToastPositions).map((entry) => [entry as string, [] as Partial<ToastProps>[]]))); | ||
|
||
get toasts() { | ||
return this.#toasts; | ||
} | ||
|
||
readonly add = (toast: Partial<ToastProps>) => this.#toasts[toast.className!].push(toast); | ||
readonly remove = (toast: Partial<ToastProps>) => this.#toasts[toast.className!].splice(this.#toasts[toast.className!].indexOf(toast), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters