reburn-ui 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/Notifications/NotificationContainer.svelte +56 -0
- package/dist/core/Notifications/NotificationContainer.svelte.d.ts +10 -0
- package/dist/core/Notifications/Notifications.svelte +156 -0
- package/dist/core/Notifications/Notifications.svelte.d.ts +28 -0
- package/dist/core/Notifications/NotificationsStore.svelte.d.ts +46 -0
- package/dist/core/Notifications/NotificationsStore.svelte.js +71 -0
- package/dist/core/Notifications/get-auto-close.d.ts +1 -0
- package/dist/core/Notifications/get-auto-close.js +9 -0
- package/dist/core/Notifications/notificationStackAnimation.d.ts +5 -0
- package/dist/core/Notifications/notificationStackAnimation.js +11 -0
- package/dist/core/components/CloseButton/CloseButton.svelte +6 -1
- package/dist/core/components/Floating/CreateFloating.svelte.d.ts +27 -0
- package/dist/core/components/Floating/CreateFloating.svelte.js +47 -0
- package/dist/core/components/Notification/Notification.svelte +216 -0
- package/dist/core/components/Notification/Notification.svelte.d.ts +33 -0
- package/dist/core/components/Popover/Popover.svelte +18 -24
- package/dist/core/components/Portal/Portal.svelte +8 -4
- package/dist/core/components/Progress/Progress.svelte +28 -0
- package/dist/core/components/Progress/Progress.svelte.d.ts +15 -0
- package/dist/core/components/Progress/ProgressContext.svelte.d.ts +8 -0
- package/dist/core/components/Progress/ProgressContext.svelte.js +12 -0
- package/dist/core/components/Progress/ProgressLabel.svelte +25 -0
- package/dist/core/components/Progress/ProgressLabel.svelte.d.ts +6 -0
- package/dist/core/components/Progress/ProgressRoot.svelte +72 -0
- package/dist/core/components/Progress/ProgressRoot.svelte.d.ts +17 -0
- package/dist/core/components/Progress/ProgressSection.svelte +83 -0
- package/dist/core/components/Progress/ProgressSection.svelte.d.ts +17 -0
- package/dist/core/components/Progress/index.d.ts +12 -0
- package/dist/core/components/Progress/index.js +9 -0
- package/dist/core/components/Table/Table.svelte +160 -0
- package/dist/core/components/Table/Table.svelte.d.ts +48 -0
- package/dist/core/components/Table/TableBodyContext.d.ts +2 -0
- package/dist/core/components/Table/TableBodyContext.js +5 -0
- package/dist/core/components/Table/TableCaption.svelte +30 -0
- package/dist/core/components/Table/TableCaption.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableContext.svelte.d.ts +23 -0
- package/dist/core/components/Table/TableContext.svelte.js +18 -0
- package/dist/core/components/Table/TableDataRenderer.svelte +55 -0
- package/dist/core/components/Table/TableDataRenderer.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableHeaderContext.d.ts +2 -0
- package/dist/core/components/Table/TableHeaderContext.js +5 -0
- package/dist/core/components/Table/TableTbody.svelte +20 -0
- package/dist/core/components/Table/TableTbody.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableTd.svelte +27 -0
- package/dist/core/components/Table/TableTd.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableTfoot.svelte +15 -0
- package/dist/core/components/Table/TableTfoot.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableTh.svelte +36 -0
- package/dist/core/components/Table/TableTh.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableThead.svelte +32 -0
- package/dist/core/components/Table/TableThead.svelte.d.ts +7 -0
- package/dist/core/components/Table/TableTr.svelte +62 -0
- package/dist/core/components/Table/TableTr.svelte.d.ts +7 -0
- package/dist/core/components/Table/getTableDataAttr.d.ts +11 -0
- package/dist/core/components/Table/getTableDataAttr.js +25 -0
- package/dist/core/components/Table/index.d.ts +20 -0
- package/dist/core/components/Table/index.js +17 -0
- package/dist/core/components/Tooltip/CreateTooltip.svelte.d.ts +20 -0
- package/dist/core/components/Tooltip/CreateTooltip.svelte.js +19 -0
- package/dist/core/components/Tooltip/Tooltip.svelte +235 -0
- package/dist/core/components/Tooltip/Tooltip.svelte.d.ts +46 -0
- package/dist/core/components/Tooltip/Tooltip.types.d.ts +47 -0
- package/dist/core/components/Tooltip/Tooltip.types.js +1 -0
- package/dist/core/components/Tooltip/getTooltipMiddleware.d.ts +15 -0
- package/dist/core/components/Tooltip/getTooltipMiddleware.js +32 -0
- package/dist/core/components/index.d.ts +4 -0
- package/dist/core/components/index.js +4 -0
- package/dist/tools/icon-vite-plugin/utils/generateIconComponent.js +1 -2
- package/package.json +9 -9
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
4
|
+
import Notification from '../components/Notification/Notification.svelte';
|
|
5
|
+
import { getAutoClose } from './get-auto-close.js';
|
|
6
|
+
import type { NotificationData } from './NotificationsStore.svelte.js';
|
|
7
|
+
|
|
8
|
+
export interface NotificationContainerProps extends NotificationProps {
|
|
9
|
+
data: NotificationData;
|
|
10
|
+
onHide: (id: string) => void;
|
|
11
|
+
autoClose: number | false;
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
let { data, onHide, autoClose, ...props }: NotificationContainerProps = $props();
|
|
17
|
+
|
|
18
|
+
const { autoClose: _autoClose, message, children, ...notificationProps } = $derived(data);
|
|
19
|
+
|
|
20
|
+
const autoCloseDuration = $derived(getAutoClose(autoClose, data.autoClose));
|
|
21
|
+
|
|
22
|
+
let autoCloseTimeout = $state<number>(-1);
|
|
23
|
+
|
|
24
|
+
function cancelAutoClose() {
|
|
25
|
+
window.clearTimeout(autoCloseTimeout);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleHide() {
|
|
29
|
+
onHide(data.id!);
|
|
30
|
+
cancelAutoClose();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleAutoClose() {
|
|
34
|
+
if (typeof autoCloseDuration === 'number') {
|
|
35
|
+
autoCloseTimeout = window.setTimeout(handleHide, autoCloseDuration);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onMount(() => {
|
|
40
|
+
data.onopen?.(data);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
$effect(() => {
|
|
44
|
+
handleAutoClose();
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
cancelAutoClose();
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<Notification {...props} {...notificationProps} onclose={handleHide} onmouseenter={cancelAutoClose} onmouseleave={handleAutoClose}>
|
|
53
|
+
{data.message}
|
|
54
|
+
|
|
55
|
+
{@render children?.()}
|
|
56
|
+
</Notification>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
2
|
+
import type { NotificationData } from './NotificationsStore.svelte.js';
|
|
3
|
+
export interface NotificationContainerProps extends NotificationProps {
|
|
4
|
+
data: NotificationData;
|
|
5
|
+
onHide: (id: string) => void;
|
|
6
|
+
autoClose: number | false;
|
|
7
|
+
}
|
|
8
|
+
declare const NotificationContainer: import("svelte").Component<NotificationContainerProps, {}, "">;
|
|
9
|
+
type NotificationContainer = ReturnType<typeof NotificationContainer>;
|
|
10
|
+
export default NotificationContainer;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cubicOut } from 'svelte/easing';
|
|
3
|
+
import type { TransitionConfig } from 'svelte/transition';
|
|
4
|
+
import { transitions } from '../components/index.js';
|
|
5
|
+
import OptionalPortal from '../components/Portal/OptionalPortal.svelte';
|
|
6
|
+
import type { BasePortalProps } from '../components/Portal/Portal.svelte';
|
|
7
|
+
import type { DivElement } from '../element-types.js';
|
|
8
|
+
import { reducedMotion } from '../hooks/use-reduced-motion.svelte.js';
|
|
9
|
+
import { theme } from '../MantineProvider/theme.svelte.js';
|
|
10
|
+
import { getDefaultZIndex } from '../utils/get-default-z-index.js';
|
|
11
|
+
import { rem } from '../utils/index.js';
|
|
12
|
+
import NotificationContainer from './NotificationContainer.svelte';
|
|
13
|
+
import { notifications, type CreateNotificationStore, type NotificationData, type NotificationPosition } from './NotificationsStore.svelte.js';
|
|
14
|
+
import { notificationStackAnimation } from './notificationStackAnimation.js';
|
|
15
|
+
|
|
16
|
+
export interface NotificationsProps extends DivElement {
|
|
17
|
+
/** Notifications default position, `'bottom-right'` by default */
|
|
18
|
+
position?: NotificationPosition;
|
|
19
|
+
|
|
20
|
+
/** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function, `4000` by default */
|
|
21
|
+
autoClose?: number | false;
|
|
22
|
+
|
|
23
|
+
/** Notification transition duration in ms, `250` by default */
|
|
24
|
+
transitionDuration?: number;
|
|
25
|
+
|
|
26
|
+
/** Notification width, cannot exceed 100%, `440` by default */
|
|
27
|
+
containerWidth?: number | string;
|
|
28
|
+
|
|
29
|
+
/** Notification `max-height`, used for transitions, `200` by default */
|
|
30
|
+
notificationMaxHeight?: number | string;
|
|
31
|
+
|
|
32
|
+
/** Maximum number of notifications displayed at a time, other new notifications will be added to queue, `5` by default */
|
|
33
|
+
limit?: number;
|
|
34
|
+
|
|
35
|
+
/** Notifications container z-index, `400` by default */
|
|
36
|
+
zIndex?: string | number;
|
|
37
|
+
|
|
38
|
+
/** Props passed down to the `Portal` component */
|
|
39
|
+
portalProps?: BasePortalProps;
|
|
40
|
+
|
|
41
|
+
/** Store for notifications state, can be used to create multiple instances of notifications system in your application */
|
|
42
|
+
store?: CreateNotificationStore;
|
|
43
|
+
|
|
44
|
+
/** Determines whether notifications container should be rendered inside `Portal`, `true` by default */
|
|
45
|
+
withinPortal?: boolean;
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<script lang="ts">
|
|
50
|
+
let {
|
|
51
|
+
position = 'bottom-right',
|
|
52
|
+
autoClose = 4000,
|
|
53
|
+
transitionDuration = 250,
|
|
54
|
+
containerWidth = 440,
|
|
55
|
+
notificationMaxHeight = 200,
|
|
56
|
+
limit = 5,
|
|
57
|
+
zIndex = getDefaultZIndex('overlay'),
|
|
58
|
+
store = notifications,
|
|
59
|
+
withinPortal = true,
|
|
60
|
+
portalProps,
|
|
61
|
+
}: NotificationsProps = $props();
|
|
62
|
+
|
|
63
|
+
const groupedNotifications = $derived.by(() => {
|
|
64
|
+
const groups: Record<NotificationPosition, NotificationData[]> = {
|
|
65
|
+
'top-left': [],
|
|
66
|
+
'top-right': [],
|
|
67
|
+
'top-center': [],
|
|
68
|
+
'bottom-left': [],
|
|
69
|
+
'bottom-right': [],
|
|
70
|
+
'bottom-center': [],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < store.notifications.length; i++) {
|
|
74
|
+
const notification = store.notifications[i];
|
|
75
|
+
|
|
76
|
+
groups[notification.position || position].push(notification);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return groups;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const styles = $derived(`--notifications-z-index: ${zIndex}; --notifications-container-width: ${rem(containerWidth)};`);
|
|
83
|
+
|
|
84
|
+
const duration = $derived.by(() => {
|
|
85
|
+
const shouldReduceMotion = reducedMotion.current;
|
|
86
|
+
const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;
|
|
87
|
+
return reduceMotion ? 1 : transitionDuration;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const { 'slide-up': slideUp, 'slide-down': slideDown, 'slide-left': slideLeft, 'slide-right': slideRight } = transitions;
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
{#snippet renderGroup(group: NotificationData[], transition: typeof slideLeft | typeof slideRight)}
|
|
94
|
+
{#each group as notification (notification.id)}
|
|
95
|
+
<div animate:notificationStackAnimation class="notification-container" transition:transition={{ duration: duration }}>
|
|
96
|
+
<NotificationContainer class="notification" data={notification} onHide={() => store.hide(notification.id!)} {autoClose} />
|
|
97
|
+
</div>
|
|
98
|
+
{/each}
|
|
99
|
+
{/snippet}
|
|
100
|
+
|
|
101
|
+
<OptionalPortal {withinPortal} {...portalProps}>
|
|
102
|
+
<div class="root" data-position="top-center" style={styles}>
|
|
103
|
+
{@render renderGroup(groupedNotifications['top-center'], slideDown)}
|
|
104
|
+
</div>
|
|
105
|
+
<div class="root" data-position="top-left" style={styles}>
|
|
106
|
+
{@render renderGroup(groupedNotifications['top-left'], slideRight)}
|
|
107
|
+
</div>
|
|
108
|
+
<div class="root" data-position="top-right" style={styles}>
|
|
109
|
+
{@render renderGroup(groupedNotifications['top-right'], slideLeft)}
|
|
110
|
+
</div>
|
|
111
|
+
<div class="root" data-position="bottom-right" style={styles}>
|
|
112
|
+
{@render renderGroup(groupedNotifications['bottom-right'], slideLeft)}
|
|
113
|
+
</div>
|
|
114
|
+
<div class="root" data-position="bottom-left" style={styles}>
|
|
115
|
+
{@render renderGroup(groupedNotifications['bottom-left'], slideRight)}
|
|
116
|
+
</div>
|
|
117
|
+
<div class="root" data-position="bottom-center" style={styles}>
|
|
118
|
+
{@render renderGroup(groupedNotifications['bottom-center'], slideUp)}
|
|
119
|
+
</div>
|
|
120
|
+
</OptionalPortal>
|
|
121
|
+
|
|
122
|
+
<style>.root {
|
|
123
|
+
width: calc(100% - var(--mantine-spacing-md) * 2);
|
|
124
|
+
position: fixed;
|
|
125
|
+
z-index: var(--notifications-z-index);
|
|
126
|
+
max-width: var(--notifications-container-width);
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
gap: var(--mantine-spacing-md);
|
|
130
|
+
}
|
|
131
|
+
.root:where([data-position=top-center]) {
|
|
132
|
+
top: var(--mantine-spacing-md);
|
|
133
|
+
left: 50%;
|
|
134
|
+
transform: translateX(-50%);
|
|
135
|
+
}
|
|
136
|
+
.root:where([data-position=top-left]) {
|
|
137
|
+
top: var(--mantine-spacing-md);
|
|
138
|
+
left: var(--mantine-spacing-md);
|
|
139
|
+
}
|
|
140
|
+
.root:where([data-position=top-right]) {
|
|
141
|
+
top: var(--mantine-spacing-md);
|
|
142
|
+
right: var(--mantine-spacing-md);
|
|
143
|
+
}
|
|
144
|
+
.root:where([data-position=bottom-center]) {
|
|
145
|
+
bottom: var(--mantine-spacing-md);
|
|
146
|
+
left: 50%;
|
|
147
|
+
transform: translateX(-50%);
|
|
148
|
+
}
|
|
149
|
+
.root:where([data-position=bottom-left]) {
|
|
150
|
+
bottom: var(--mantine-spacing-md);
|
|
151
|
+
left: var(--mantine-spacing-md);
|
|
152
|
+
}
|
|
153
|
+
.root:where([data-position=bottom-right]) {
|
|
154
|
+
bottom: var(--mantine-spacing-md);
|
|
155
|
+
right: var(--mantine-spacing-md);
|
|
156
|
+
}</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BasePortalProps } from '../components/Portal/Portal.svelte';
|
|
2
|
+
import type { DivElement } from '../element-types.js';
|
|
3
|
+
import { type CreateNotificationStore, type NotificationPosition } from './NotificationsStore.svelte.js';
|
|
4
|
+
export interface NotificationsProps extends DivElement {
|
|
5
|
+
/** Notifications default position, `'bottom-right'` by default */
|
|
6
|
+
position?: NotificationPosition;
|
|
7
|
+
/** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function, `4000` by default */
|
|
8
|
+
autoClose?: number | false;
|
|
9
|
+
/** Notification transition duration in ms, `250` by default */
|
|
10
|
+
transitionDuration?: number;
|
|
11
|
+
/** Notification width, cannot exceed 100%, `440` by default */
|
|
12
|
+
containerWidth?: number | string;
|
|
13
|
+
/** Notification `max-height`, used for transitions, `200` by default */
|
|
14
|
+
notificationMaxHeight?: number | string;
|
|
15
|
+
/** Maximum number of notifications displayed at a time, other new notifications will be added to queue, `5` by default */
|
|
16
|
+
limit?: number;
|
|
17
|
+
/** Notifications container z-index, `400` by default */
|
|
18
|
+
zIndex?: string | number;
|
|
19
|
+
/** Props passed down to the `Portal` component */
|
|
20
|
+
portalProps?: BasePortalProps;
|
|
21
|
+
/** Store for notifications state, can be used to create multiple instances of notifications system in your application */
|
|
22
|
+
store?: CreateNotificationStore;
|
|
23
|
+
/** Determines whether notifications container should be rendered inside `Portal`, `true` by default */
|
|
24
|
+
withinPortal?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare const Notifications: import("svelte").Component<NotificationsProps, {}, "">;
|
|
27
|
+
type Notifications = ReturnType<typeof Notifications>;
|
|
28
|
+
export default Notifications;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { NotificationProps } from '../components/Notification/Notification.svelte';
|
|
3
|
+
import { type MaybeGetter } from '../context/extract.js';
|
|
4
|
+
export type NotificationPosition = 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center';
|
|
5
|
+
export interface NotificationData extends Omit<NotificationProps, 'onclose'> {
|
|
6
|
+
/** Notification id, can be used to close or update notification */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Position of the notification, if not set, the position is determined based on `position` prop on Notifications component */
|
|
9
|
+
position?: NotificationPosition;
|
|
10
|
+
/** Notification message, required for all notifications */
|
|
11
|
+
message: string | Snippet;
|
|
12
|
+
/** Determines whether notification should be closed automatically,
|
|
13
|
+
* number is auto close timeout in ms, overrides `autoClose` from `Notifications`
|
|
14
|
+
* */
|
|
15
|
+
autoClose?: boolean | number;
|
|
16
|
+
/** Called when notification closes */
|
|
17
|
+
onclose?: (props: NotificationData) => void;
|
|
18
|
+
/** Called when notification opens */
|
|
19
|
+
onopen?: (props: NotificationData) => void;
|
|
20
|
+
}
|
|
21
|
+
interface NotificationStore {
|
|
22
|
+
notifications?: MaybeGetter<NotificationData[]>;
|
|
23
|
+
queue?: MaybeGetter<NotificationData[]>;
|
|
24
|
+
defaultPosition?: MaybeGetter<NotificationPosition>;
|
|
25
|
+
limit?: MaybeGetter<number>;
|
|
26
|
+
}
|
|
27
|
+
interface NotificationShowResult {
|
|
28
|
+
id: string;
|
|
29
|
+
position: NotificationPosition;
|
|
30
|
+
}
|
|
31
|
+
export declare class CreateNotificationStore {
|
|
32
|
+
#private;
|
|
33
|
+
notifications: NotificationData[];
|
|
34
|
+
queue: NotificationData[];
|
|
35
|
+
defaultPosition: "bottom-left" | "bottom-right" | "top-left" | "top-right" | "top-center" | "bottom-center";
|
|
36
|
+
limit: number;
|
|
37
|
+
constructor(props?: NotificationStore);
|
|
38
|
+
show: (notification: NotificationData) => NotificationShowResult;
|
|
39
|
+
hide: (id: string) => string;
|
|
40
|
+
update: (notification: NotificationData) => string | undefined;
|
|
41
|
+
clean: () => void;
|
|
42
|
+
cleanQueue: () => void;
|
|
43
|
+
updateState: (update: (notifications: NotificationData[]) => NotificationData[]) => void;
|
|
44
|
+
}
|
|
45
|
+
export declare const notifications: CreateNotificationStore;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import { extract } from '../context/extract.js';
|
|
3
|
+
function getDistributedNotifications(data, defaultPosition, limit) {
|
|
4
|
+
const queue = [];
|
|
5
|
+
const notifications = [];
|
|
6
|
+
const count = {};
|
|
7
|
+
for (const item of data) {
|
|
8
|
+
const position = item.position || defaultPosition;
|
|
9
|
+
count[position] = count[position] || 0;
|
|
10
|
+
count[position] += 1;
|
|
11
|
+
if (count[position] <= limit) {
|
|
12
|
+
notifications.push(item);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
queue.push(item);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { notifications, queue };
|
|
19
|
+
}
|
|
20
|
+
export class CreateNotificationStore {
|
|
21
|
+
#props;
|
|
22
|
+
notifications = $derived(extract(this.#props.notifications, []));
|
|
23
|
+
queue = $derived(extract(this.#props.queue, []));
|
|
24
|
+
defaultPosition = $derived(extract(this.#props.defaultPosition, 'bottom-right'));
|
|
25
|
+
limit = $derived(extract(this.#props.limit, 5));
|
|
26
|
+
constructor(props = {}) {
|
|
27
|
+
this.#props = props;
|
|
28
|
+
}
|
|
29
|
+
show = (notification) => {
|
|
30
|
+
const id = notification.id || nanoid();
|
|
31
|
+
this.updateState((notifications) => {
|
|
32
|
+
if (notification.id && notifications.some((n) => n.id === notification.id)) {
|
|
33
|
+
return notifications;
|
|
34
|
+
}
|
|
35
|
+
return [...notifications, { ...notification, id }];
|
|
36
|
+
});
|
|
37
|
+
return { id, position: notification.position || this.defaultPosition };
|
|
38
|
+
};
|
|
39
|
+
hide = (id) => {
|
|
40
|
+
this.updateState((notifications) => notifications.filter((notification) => {
|
|
41
|
+
if (notification.id === id) {
|
|
42
|
+
notification.onclose?.(notification);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}));
|
|
47
|
+
return id;
|
|
48
|
+
};
|
|
49
|
+
update = (notification) => {
|
|
50
|
+
this.updateState((notifications) => notifications.map((item) => {
|
|
51
|
+
if (item.id === notification.id) {
|
|
52
|
+
return { ...item, ...notification };
|
|
53
|
+
}
|
|
54
|
+
return item;
|
|
55
|
+
}));
|
|
56
|
+
return notification.id;
|
|
57
|
+
};
|
|
58
|
+
clean = () => {
|
|
59
|
+
this.updateState(() => []);
|
|
60
|
+
};
|
|
61
|
+
cleanQueue = () => {
|
|
62
|
+
this.updateState((notifications) => notifications.slice(0, this.limit));
|
|
63
|
+
};
|
|
64
|
+
updateState = (update) => {
|
|
65
|
+
const notifications = update([...this.notifications, ...this.queue]);
|
|
66
|
+
const updated = getDistributedNotifications(notifications, this.defaultPosition, this.limit);
|
|
67
|
+
this.notifications = updated.notifications;
|
|
68
|
+
this.queue = updated.queue;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export const notifications = new CreateNotificationStore();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAutoClose(autoClose: boolean | number | undefined, notificationAutoClose: boolean | number | undefined): number | boolean | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cubicOut } from 'svelte/easing';
|
|
2
|
+
export function notificationStackAnimation(node, { from, to }) {
|
|
3
|
+
const dx = from.left - to.left;
|
|
4
|
+
const dy = from.top - to.top;
|
|
5
|
+
return {
|
|
6
|
+
delay: 0,
|
|
7
|
+
duration: 200,
|
|
8
|
+
easing: cubicOut,
|
|
9
|
+
css: (t, u) => `transform: translate(${u * dx}px, ${u * dy}px);`,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
{#if icon}
|
|
57
57
|
{@render icon?.()}
|
|
58
58
|
{:else}
|
|
59
|
-
<icon name="tabler:x"
|
|
59
|
+
<icon class="icon" name="tabler:x"></icon>
|
|
60
60
|
{/if}
|
|
61
61
|
</button>
|
|
62
62
|
|
|
@@ -107,4 +107,9 @@
|
|
|
107
107
|
:global(:where([data-mantine-color-scheme="dark"])) .root--subtle:where(:not([data-disabled], :disabled)):active {
|
|
108
108
|
background-color: var(--mantine-color-dark-6);
|
|
109
109
|
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
* :global(.icon) {
|
|
113
|
+
width: var(--cb-icon-size, 70%);
|
|
114
|
+
height: var(--cb-icon-size, 70%);
|
|
110
115
|
}</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Getter, type MaybeGetter } from '../../context/extract.js';
|
|
2
|
+
import type { Middleware } from '@floating-ui/dom';
|
|
3
|
+
import { type MiddlewareData } from '@floating-ui/dom';
|
|
4
|
+
import type { FloatingPosition, FloatingStrategy } from './types.js';
|
|
5
|
+
export interface UpdatePositionProps {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
middlewareData: MiddlewareData;
|
|
9
|
+
}
|
|
10
|
+
interface CreateFloatingProps {
|
|
11
|
+
strategy?: MaybeGetter<FloatingStrategy | undefined>;
|
|
12
|
+
placement?: MaybeGetter<FloatingPosition | undefined>;
|
|
13
|
+
middleware?: MaybeGetter<Middleware[]>;
|
|
14
|
+
onpositionchange?: Getter<((position: FloatingPosition) => void) | undefined>;
|
|
15
|
+
referenceElement: MaybeGetter<HTMLElement | undefined>;
|
|
16
|
+
floatingElement: MaybeGetter<HTMLElement | undefined>;
|
|
17
|
+
onupdate?: Getter<((props: UpdatePositionProps) => void) | undefined>;
|
|
18
|
+
}
|
|
19
|
+
export declare class CreateFloating {
|
|
20
|
+
#private;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
middlewareData: MiddlewareData | undefined;
|
|
24
|
+
constructor(props: CreateFloatingProps);
|
|
25
|
+
updatePosition: () => void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { extract } from '../../context/extract.js';
|
|
2
|
+
import { autoUpdate, computePosition } from '@floating-ui/dom';
|
|
3
|
+
export class CreateFloating {
|
|
4
|
+
#props;
|
|
5
|
+
#strategy = $derived(extract(this.#props.strategy, 'absolute'));
|
|
6
|
+
#placement = $derived(extract(this.#props.placement, 'bottom'));
|
|
7
|
+
#middleware = $derived(extract(this.#props.middleware, []));
|
|
8
|
+
#onpositionchange = $derived(extract(this.#props.onpositionchange));
|
|
9
|
+
#referenceElement = $derived(extract(this.#props.referenceElement));
|
|
10
|
+
#floatingElement = $derived(extract(this.#props.floatingElement));
|
|
11
|
+
#onupdate = $derived(extract(this.#props.onupdate));
|
|
12
|
+
x = $state(0);
|
|
13
|
+
y = $state(0);
|
|
14
|
+
middlewareData = $state(undefined);
|
|
15
|
+
constructor(props) {
|
|
16
|
+
this.#props = props;
|
|
17
|
+
$effect(() => {
|
|
18
|
+
if (!this.#elementsSet())
|
|
19
|
+
return;
|
|
20
|
+
const cleanup = autoUpdate(this.#referenceElement, this.#floatingElement, this.updatePosition);
|
|
21
|
+
return () => cleanup();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
#elementsSet = () => {
|
|
25
|
+
return this.#referenceElement && this.#floatingElement;
|
|
26
|
+
};
|
|
27
|
+
updatePosition = () => {
|
|
28
|
+
if (!this.#elementsSet())
|
|
29
|
+
return;
|
|
30
|
+
console.log({
|
|
31
|
+
strategy: this.#strategy,
|
|
32
|
+
placement: this.#placement,
|
|
33
|
+
middleware: this.#middleware,
|
|
34
|
+
});
|
|
35
|
+
computePosition(this.#referenceElement, this.#floatingElement, {
|
|
36
|
+
strategy: this.#strategy,
|
|
37
|
+
placement: this.#placement,
|
|
38
|
+
middleware: this.#middleware,
|
|
39
|
+
}).then(({ x, y, middlewareData: mW, placement }) => {
|
|
40
|
+
this.x = x;
|
|
41
|
+
this.y = y;
|
|
42
|
+
this.middlewareData = mW;
|
|
43
|
+
this.#onpositionchange?.(placement);
|
|
44
|
+
this.#onupdate?.({ x, y, middlewareData: mW });
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|