vueless 0.0.503 → 0.0.505
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/package.json +1 -1
- package/plugin-vite.d.ts +43 -11
- package/types.ts +31 -3
- package/ui.button/UButton.vue +101 -240
- package/ui.button/storybook/Docs.mdx +2 -2
- package/ui.button/storybook/{stories.js → stories.ts} +25 -12
- package/ui.button/types.ts +121 -0
- package/ui.button/{useAttrs.js → useAttrs.ts} +6 -3
- package/ui.button-link/ULink.vue +72 -223
- package/ui.button-link/storybook/Docs.mdx +2 -2
- package/ui.button-link/storybook/{stories.js → stories.ts} +30 -17
- package/ui.button-link/types.ts +131 -0
- package/ui.button-link/{useAttrs.js → useAttrs.ts} +15 -3
- package/ui.button-toggle/UToggle.vue +47 -165
- package/ui.button-toggle/storybook/Docs.mdx +2 -2
- package/ui.button-toggle/storybook/{stories.js → stories.ts} +13 -5
- package/ui.button-toggle/types.ts +85 -0
- package/ui.button-toggle/useAttrs.ts +18 -0
- package/ui.button-toggle-item/UToggleItem.vue +59 -110
- package/ui.button-toggle-item/storybook/Docs.mdx +2 -2
- package/ui.button-toggle-item/storybook/{stories.js → stories.ts} +10 -3
- package/ui.button-toggle-item/types.ts +40 -0
- package/ui.button-toggle-item/{useAttrs.js → useAttrs.ts} +16 -4
- package/ui.other-dot/UDot.vue +14 -42
- package/ui.other-dot/storybook/Docs.mdx +2 -2
- package/ui.other-dot/storybook/{stories.js → stories.ts} +13 -5
- package/ui.other-dot/types.ts +46 -0
- package/ui.other-dot/useAttrs.ts +18 -0
- package/ui.text-alert/UAlert.vue +85 -157
- package/ui.text-alert/storybook/Docs.mdx +2 -2
- package/ui.text-alert/storybook/{stories.js → stories.ts} +17 -9
- package/ui.text-alert/types.ts +76 -0
- package/ui.text-alert/useAttrs.ts +18 -0
- package/ui.text-badge/UBadge.vue +1 -0
- package/ui.text-badge/storybook/stories.ts +1 -8
- package/ui.text-badge/types.ts +2 -0
- package/ui.text-badge/useAttrs.ts +1 -3
- package/ui.text-block/UText.vue +1 -0
- package/ui.text-block/storybook/stories.ts +1 -1
- package/ui.text-block/types.ts +2 -0
- package/ui.text-block/useAttrs.ts +1 -1
- package/ui.text-empty/UEmpty.vue +39 -75
- package/ui.text-empty/storybook/Docs.mdx +2 -2
- package/ui.text-empty/storybook/{stories.js → stories.ts} +14 -6
- package/ui.text-empty/types.ts +30 -0
- package/ui.text-empty/useAttrs.ts +18 -0
- package/ui.text-file/UFile.vue +49 -109
- package/ui.text-file/storybook/Docs.mdx +2 -2
- package/ui.text-file/storybook/{stories.js → stories.ts} +10 -3
- package/ui.text-file/types.ts +45 -0
- package/ui.text-file/useAttrs.ts +18 -0
- package/ui.text-files/UFiles.vue +46 -106
- package/ui.text-files/storybook/Docs.mdx +2 -2
- package/ui.text-files/storybook/{stories.js → stories.ts} +10 -3
- package/ui.text-files/types.ts +45 -0
- package/ui.text-files/useAttrs.ts +18 -0
- package/ui.text-header/UHeader.vue +19 -76
- package/ui.text-header/storybook/Docs.mdx +2 -2
- package/ui.text-header/storybook/{stories.js → stories.ts} +13 -5
- package/ui.text-header/types.ts +66 -0
- package/ui.text-header/useAttrs.ts +18 -0
- package/ui.text-money/UMoney.vue +58 -168
- package/ui.text-money/storybook/Docs.mdx +2 -2
- package/ui.text-money/storybook/{stories.js → stories.ts} +13 -5
- package/ui.text-money/types.ts +101 -0
- package/ui.text-money/useAttrs.ts +18 -0
- package/ui.text-money/{utilMoney.js → utilMoney.ts} +1 -1
- package/ui.text-notify/UNotify.vue +89 -116
- package/ui.text-notify/storybook/Docs.mdx +2 -2
- package/ui.text-notify/storybook/{stories.js → stories.ts} +12 -5
- package/ui.text-notify/types.ts +25 -0
- package/ui.text-notify/useAttrs.ts +18 -0
- package/ui.text-notify/utilNotify.ts +140 -0
- package/web-types.json +285 -135
- package/ui.button-toggle/useAttrs.js +0 -15
- package/ui.other-dot/useAttrs.js +0 -15
- package/ui.text-alert/useAttrs.js +0 -15
- package/ui.text-empty/useAttrs.js +0 -15
- package/ui.text-file/useAttrs.js +0 -15
- package/ui.text-files/useAttrs.js +0 -15
- package/ui.text-header/useAttrs.js +0 -15
- package/ui.text-money/useAttrs.js +0 -15
- package/ui.text-notify/useAttrs.js +0 -15
- package/ui.text-notify/utilNotify.js +0 -86
- /package/ui.button/{config.js → config.ts} +0 -0
- /package/ui.button/{constants.js → constants.ts} +0 -0
- /package/ui.button-link/{config.js → config.ts} +0 -0
- /package/ui.button-link/{constants.js → constants.ts} +0 -0
- /package/ui.button-toggle/{config.js → config.ts} +0 -0
- /package/ui.button-toggle/{constants.js → constants.ts} +0 -0
- /package/ui.button-toggle-item/{config.js → config.ts} +0 -0
- /package/ui.button-toggle-item/{constants.js → constants.ts} +0 -0
- /package/ui.other-dot/{config.js → config.ts} +0 -0
- /package/ui.other-dot/{constants.js → constants.ts} +0 -0
- /package/ui.text-alert/{config.js → config.ts} +0 -0
- /package/ui.text-alert/{constants.js → constants.ts} +0 -0
- /package/ui.text-empty/{config.js → config.ts} +0 -0
- /package/ui.text-empty/{constants.js → constants.ts} +0 -0
- /package/ui.text-file/{config.js → config.ts} +0 -0
- /package/ui.text-file/{constants.js → constants.ts} +0 -0
- /package/ui.text-files/{config.js → config.ts} +0 -0
- /package/ui.text-files/{constants.js → constants.ts} +0 -0
- /package/ui.text-header/{config.js → config.ts} +0 -0
- /package/ui.text-header/{constants.js → constants.ts} +0 -0
- /package/ui.text-money/{config.js → config.ts} +0 -0
- /package/ui.text-money/{constants.js → constants.ts} +0 -0
- /package/ui.text-notify/{config.js → config.ts} +0 -0
- /package/ui.text-notify/{constants.js → constants.ts} +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
4
|
+
|
|
5
|
+
export interface UMoneyProps {
|
|
6
|
+
/**
|
|
7
|
+
* Money value.
|
|
8
|
+
*/
|
|
9
|
+
value?: number;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Money size.
|
|
13
|
+
*/
|
|
14
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Money color.
|
|
18
|
+
*/
|
|
19
|
+
color?:
|
|
20
|
+
| "brand"
|
|
21
|
+
| "grayscale"
|
|
22
|
+
| "gray"
|
|
23
|
+
| "red"
|
|
24
|
+
| "orange"
|
|
25
|
+
| "amber"
|
|
26
|
+
| "yellow"
|
|
27
|
+
| "lime"
|
|
28
|
+
| "green"
|
|
29
|
+
| "emerald"
|
|
30
|
+
| "teal"
|
|
31
|
+
| "cyan"
|
|
32
|
+
| "sky"
|
|
33
|
+
| "blue"
|
|
34
|
+
| "indigo"
|
|
35
|
+
| "violet"
|
|
36
|
+
| "purple"
|
|
37
|
+
| "fuchsia"
|
|
38
|
+
| "pink"
|
|
39
|
+
| "rose"
|
|
40
|
+
| "white";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Money currency symbol.
|
|
44
|
+
*/
|
|
45
|
+
symbol?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Money currency symbol align.
|
|
49
|
+
*/
|
|
50
|
+
symbolAlign?: "right" | "left";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Add space between currency symbol and sum.
|
|
54
|
+
*/
|
|
55
|
+
symbolDivided?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Money sign.
|
|
59
|
+
*/
|
|
60
|
+
sign?: "default" | "positive" | "negative";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Minimal number of signs after the decimal separator (fractional part of a number).
|
|
64
|
+
*/
|
|
65
|
+
minFractionDigits?: number;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Maximal number of signs after the decimal separator (fractional part of a number).
|
|
69
|
+
*/
|
|
70
|
+
maxFractionDigits?: number;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A symbol used to separate the integer part from the fractional part of a number.
|
|
74
|
+
*/
|
|
75
|
+
decimalSeparator?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A symbol used to separate the thousand parts of a number.
|
|
79
|
+
*/
|
|
80
|
+
thousandsSeparator?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Money align.
|
|
84
|
+
*/
|
|
85
|
+
align?: "right" | "left";
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Make money planned (add brackets).
|
|
89
|
+
*/
|
|
90
|
+
planned?: boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Component config object.
|
|
94
|
+
*/
|
|
95
|
+
config?: Partial<typeof defaultConfig>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Data-test attribute for automated testing.
|
|
99
|
+
*/
|
|
100
|
+
dataTest?: string;
|
|
101
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import useUI from "../composables/useUI.ts";
|
|
2
|
+
|
|
3
|
+
import defaultConfig from "./config.ts";
|
|
4
|
+
|
|
5
|
+
import type { UseAttrs } from "../types.ts";
|
|
6
|
+
import type { UMoneyProps, Config } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
export function useAttrs(props: UMoneyProps): UseAttrs<Config> {
|
|
9
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
|
|
10
|
+
|
|
11
|
+
const keysAttrs = getKeysAttrs();
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
config,
|
|
15
|
+
...keysAttrs,
|
|
16
|
+
hasSlotContent,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,130 +1,25 @@
|
|
|
1
|
-
<
|
|
2
|
-
<TransitionGroup
|
|
3
|
-
ref="notificationsWrapperRef"
|
|
4
|
-
:style="notifyPositionStyles"
|
|
5
|
-
tag="div"
|
|
6
|
-
v-bind="{ ...config.transitionGroup, ...wrapperAttrs }"
|
|
7
|
-
>
|
|
8
|
-
<div
|
|
9
|
-
v-for="notification in notifications"
|
|
10
|
-
:key="notification.id"
|
|
11
|
-
v-bind="bodyAttrs"
|
|
12
|
-
:class="getNotificationClasses(notification)"
|
|
13
|
-
>
|
|
14
|
-
<UIcon
|
|
15
|
-
v-if="notification.type === NOTIFY_TYPE.success"
|
|
16
|
-
color="green"
|
|
17
|
-
variant="light"
|
|
18
|
-
size="md"
|
|
19
|
-
internal
|
|
20
|
-
:name="config.defaults.successIcon"
|
|
21
|
-
v-bind="successIconAttrs"
|
|
22
|
-
data-test="type-notify"
|
|
23
|
-
/>
|
|
24
|
-
|
|
25
|
-
<UIcon
|
|
26
|
-
v-else-if="notification.type === NOTIFY_TYPE.warning"
|
|
27
|
-
color="orange"
|
|
28
|
-
variant="light"
|
|
29
|
-
size="md"
|
|
30
|
-
internal
|
|
31
|
-
:name="config.defaults.warningIcon"
|
|
32
|
-
v-bind="warningIconAttrs"
|
|
33
|
-
data-test="type-notify"
|
|
34
|
-
/>
|
|
35
|
-
|
|
36
|
-
<UIcon
|
|
37
|
-
v-else-if="notification.type === NOTIFY_TYPE.error"
|
|
38
|
-
data-test="type-notify"
|
|
39
|
-
color="red"
|
|
40
|
-
variant="light"
|
|
41
|
-
size="md"
|
|
42
|
-
internal
|
|
43
|
-
:name="config.defaults.errorIcon"
|
|
44
|
-
v-bind="errorIconAttrs"
|
|
45
|
-
/>
|
|
46
|
-
|
|
47
|
-
<div v-bind="contentAttrs">
|
|
48
|
-
<template v-if="html">
|
|
49
|
-
<span v-bind="labelAttrs" v-html="notification.label" />
|
|
50
|
-
<span
|
|
51
|
-
v-bind="descriptionAttrs"
|
|
52
|
-
v-html="getText(notification.description, notification.type)"
|
|
53
|
-
/>
|
|
54
|
-
</template>
|
|
55
|
-
|
|
56
|
-
<template v-else>
|
|
57
|
-
<span v-bind="labelAttrs" v-text="notification.label" />
|
|
58
|
-
<span
|
|
59
|
-
v-bind="descriptionAttrs"
|
|
60
|
-
v-text="getText(notification.description, notification.type)"
|
|
61
|
-
/>
|
|
62
|
-
</template>
|
|
63
|
-
</div>
|
|
64
|
-
|
|
65
|
-
<UIcon
|
|
66
|
-
color="gray"
|
|
67
|
-
variant="light"
|
|
68
|
-
size="xs"
|
|
69
|
-
internal
|
|
70
|
-
interactive
|
|
71
|
-
:name="config.defaults.closeIcon"
|
|
72
|
-
v-bind="closeIconAttrs"
|
|
73
|
-
@click="onClickClose(notification)"
|
|
74
|
-
/>
|
|
75
|
-
</div>
|
|
76
|
-
</TransitionGroup>
|
|
77
|
-
</template>
|
|
78
|
-
|
|
79
|
-
<script setup>
|
|
1
|
+
<script lang="ts" setup>
|
|
80
2
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
|
81
3
|
import { merge } from "lodash-es";
|
|
82
4
|
|
|
83
5
|
import { cx, getDefault, vuelessConfig } from "../utils/ui.ts";
|
|
84
6
|
import { useLocale } from "../composables/useLocale.ts";
|
|
85
|
-
import useAttrs from "./useAttrs.
|
|
7
|
+
import useAttrs from "./useAttrs.ts";
|
|
86
8
|
|
|
87
|
-
import defaultConfig from "./config.
|
|
88
|
-
import { UNotify, NOTIFY_TYPE, POSITION } from "./constants.
|
|
9
|
+
import defaultConfig from "./config.ts";
|
|
10
|
+
import { UNotify, NOTIFY_TYPE, POSITION } from "./constants.ts";
|
|
89
11
|
|
|
90
12
|
import UIcon from "../ui.image-icon/UIcon.vue";
|
|
91
13
|
|
|
14
|
+
import type { UNotifyProps } from "./types.ts";
|
|
15
|
+
|
|
92
16
|
defineOptions({ inheritAttrs: false });
|
|
93
17
|
|
|
94
|
-
const props = defineProps({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
xPosition: {
|
|
100
|
-
type: String,
|
|
101
|
-
default: getDefault(defaultConfig, UNotify).xPosition,
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* A position on the y-axis.
|
|
106
|
-
* @values top, bottom
|
|
107
|
-
*/
|
|
108
|
-
yPosition: {
|
|
109
|
-
type: String,
|
|
110
|
-
default: getDefault(defaultConfig, UNotify).yPosition,
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Use html to render you own content.
|
|
115
|
-
*/
|
|
116
|
-
html: {
|
|
117
|
-
type: Boolean,
|
|
118
|
-
default: getDefault(defaultConfig, UNotify).html,
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Component config object.
|
|
123
|
-
*/
|
|
124
|
-
config: {
|
|
125
|
-
type: Object,
|
|
126
|
-
default: () => ({}),
|
|
127
|
-
},
|
|
18
|
+
const props = withDefaults(defineProps<UNotifyProps>(), {
|
|
19
|
+
xPosition: getDefault<UNotifyProps>(defaultConfig, UNotify).xPosition,
|
|
20
|
+
yPosition: getDefault<UNotifyProps>(defaultConfig, UNotify).yPosition,
|
|
21
|
+
html: getDefault<UNotifyProps>(defaultConfig, UNotify).html,
|
|
22
|
+
dataTest: "",
|
|
128
23
|
});
|
|
129
24
|
|
|
130
25
|
const {
|
|
@@ -238,3 +133,81 @@ function getNotificationClasses(notification) {
|
|
|
238
133
|
}
|
|
239
134
|
}
|
|
240
135
|
</script>
|
|
136
|
+
|
|
137
|
+
<template>
|
|
138
|
+
<TransitionGroup
|
|
139
|
+
ref="notificationsWrapperRef"
|
|
140
|
+
:style="notifyPositionStyles"
|
|
141
|
+
tag="div"
|
|
142
|
+
v-bind="{ ...config.transitionGroup, ...wrapperAttrs }"
|
|
143
|
+
>
|
|
144
|
+
<div
|
|
145
|
+
v-for="notification in notifications"
|
|
146
|
+
:key="notification.id"
|
|
147
|
+
v-bind="bodyAttrs"
|
|
148
|
+
:class="getNotificationClasses(notification)"
|
|
149
|
+
>
|
|
150
|
+
<UIcon
|
|
151
|
+
v-if="notification.type === NOTIFY_TYPE.success"
|
|
152
|
+
color="green"
|
|
153
|
+
variant="light"
|
|
154
|
+
size="md"
|
|
155
|
+
internal
|
|
156
|
+
:name="config.defaults.successIcon"
|
|
157
|
+
v-bind="successIconAttrs"
|
|
158
|
+
data-test="type-notify"
|
|
159
|
+
/>
|
|
160
|
+
|
|
161
|
+
<UIcon
|
|
162
|
+
v-else-if="notification.type === NOTIFY_TYPE.warning"
|
|
163
|
+
color="orange"
|
|
164
|
+
variant="light"
|
|
165
|
+
size="md"
|
|
166
|
+
internal
|
|
167
|
+
:name="config.defaults.warningIcon"
|
|
168
|
+
v-bind="warningIconAttrs"
|
|
169
|
+
data-test="type-notify"
|
|
170
|
+
/>
|
|
171
|
+
|
|
172
|
+
<UIcon
|
|
173
|
+
v-else-if="notification.type === NOTIFY_TYPE.error"
|
|
174
|
+
data-test="type-notify"
|
|
175
|
+
color="red"
|
|
176
|
+
variant="light"
|
|
177
|
+
size="md"
|
|
178
|
+
internal
|
|
179
|
+
:name="config.defaults.errorIcon"
|
|
180
|
+
v-bind="errorIconAttrs"
|
|
181
|
+
/>
|
|
182
|
+
|
|
183
|
+
<div v-bind="contentAttrs">
|
|
184
|
+
<template v-if="html">
|
|
185
|
+
<span v-bind="labelAttrs" v-html="notification.label" />
|
|
186
|
+
<span
|
|
187
|
+
v-bind="descriptionAttrs"
|
|
188
|
+
v-html="getText(notification.description, notification.type)"
|
|
189
|
+
/>
|
|
190
|
+
</template>
|
|
191
|
+
|
|
192
|
+
<template v-else>
|
|
193
|
+
<span v-bind="labelAttrs" v-text="notification.label" />
|
|
194
|
+
<span
|
|
195
|
+
v-bind="descriptionAttrs"
|
|
196
|
+
v-text="getText(notification.description, notification.type)"
|
|
197
|
+
/>
|
|
198
|
+
</template>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<UIcon
|
|
202
|
+
color="gray"
|
|
203
|
+
variant="light"
|
|
204
|
+
size="xs"
|
|
205
|
+
internal
|
|
206
|
+
interactive
|
|
207
|
+
:name="config.defaults.closeIcon"
|
|
208
|
+
v-bind="closeIconAttrs"
|
|
209
|
+
@click="onClickClose(notification)"
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
</TransitionGroup>
|
|
213
|
+
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source, Markdown } from "@storybook/blocks";
|
|
2
2
|
import { getSource } from "../../utils/storybook.ts";
|
|
3
3
|
|
|
4
|
-
import * as stories from "./stories.
|
|
5
|
-
import defaultConfig from "../config.
|
|
4
|
+
import * as stories from "./stories.ts";
|
|
5
|
+
import defaultConfig from "../config.ts?raw"
|
|
6
6
|
|
|
7
7
|
<Meta of={stories} />
|
|
8
8
|
<Title of={stories} />
|
|
@@ -6,6 +6,13 @@ import UNotify from "../../ui.text-notify/UNotify.vue";
|
|
|
6
6
|
import UButton from "../../ui.button/UButton.vue";
|
|
7
7
|
import UCol from "../../ui.container-col/UCol.vue";
|
|
8
8
|
|
|
9
|
+
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
10
|
+
import type { UNotifyProps } from "../types.ts";
|
|
11
|
+
|
|
12
|
+
interface UNotifyArgs extends UNotifyProps {
|
|
13
|
+
slotTemplate?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
/**
|
|
10
17
|
* The `UNotify` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.text-notify)
|
|
11
18
|
*/
|
|
@@ -23,9 +30,9 @@ export default {
|
|
|
23
30
|
},
|
|
24
31
|
},
|
|
25
32
|
},
|
|
26
|
-
};
|
|
33
|
+
} as Meta;
|
|
27
34
|
|
|
28
|
-
const DefaultTemplate = (args) => ({
|
|
35
|
+
const DefaultTemplate: StoryFn<UNotifyArgs> = (args: UNotifyArgs) => ({
|
|
29
36
|
components: { UNotify, UButton },
|
|
30
37
|
setup() {
|
|
31
38
|
function onClick() {
|
|
@@ -42,16 +49,16 @@ const DefaultTemplate = (args) => ({
|
|
|
42
49
|
},
|
|
43
50
|
template: `
|
|
44
51
|
<UNotify class="m-4" v-bind="args">
|
|
45
|
-
${args.slotTemplate || getSlotsFragment()}
|
|
52
|
+
${args.slotTemplate || getSlotsFragment("")}
|
|
46
53
|
</UNotify>
|
|
47
54
|
<UButton label="Show notify" @click="onClick"/>
|
|
48
55
|
`,
|
|
49
56
|
});
|
|
50
57
|
|
|
51
|
-
const TypesTemplate = (args) => ({
|
|
58
|
+
const TypesTemplate: StoryFn<UNotifyArgs> = (args: UNotifyArgs) => ({
|
|
52
59
|
components: { UNotify, UButton, UCol },
|
|
53
60
|
setup() {
|
|
54
|
-
function onClick(type) {
|
|
61
|
+
function onClick(type: string) {
|
|
55
62
|
if (type === "success") {
|
|
56
63
|
notify({
|
|
57
64
|
type,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import defaultConfig from "./config.ts";
|
|
2
|
+
|
|
3
|
+
export type Config = Partial<typeof defaultConfig>;
|
|
4
|
+
|
|
5
|
+
export interface UNotifyProps {
|
|
6
|
+
/**
|
|
7
|
+
* A position on the x-axis.
|
|
8
|
+
*/
|
|
9
|
+
xPosition?: "left" | "center" | "right";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A position on the y-axis.
|
|
13
|
+
*/
|
|
14
|
+
yPosition?: "top" | "bottom";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Use html to render you own content.
|
|
18
|
+
*/
|
|
19
|
+
html?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Component config object.
|
|
23
|
+
*/
|
|
24
|
+
config?: Partial<typeof defaultConfig>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import useUI from "../composables/useUI.ts";
|
|
2
|
+
|
|
3
|
+
import defaultConfig from "./config.ts";
|
|
4
|
+
|
|
5
|
+
import type { UseAttrs } from "../types.ts";
|
|
6
|
+
import type { UNotifyProps, Config } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
export default function useAttrs(props: UNotifyProps): UseAttrs<Config> {
|
|
9
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
|
|
10
|
+
|
|
11
|
+
const keysAttrs = getKeysAttrs();
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
config,
|
|
15
|
+
...keysAttrs,
|
|
16
|
+
hasSlotContent,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { getRandomId, vuelessConfig } from "../utils/ui.ts";
|
|
2
|
+
import { DELAY_BETWEEN_CLONES, DURATION, LOCAL_STORAGE_ID, NOTIFY_TYPE } from "./constants.ts";
|
|
3
|
+
|
|
4
|
+
interface NotifyConfig {
|
|
5
|
+
type?: (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE];
|
|
6
|
+
label?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
duration?: number;
|
|
9
|
+
ignoreDuplicates?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface NotifyEventDetail {
|
|
13
|
+
type: (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE];
|
|
14
|
+
id: string;
|
|
15
|
+
label: string;
|
|
16
|
+
description: string;
|
|
17
|
+
duration: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface VuelessNotifyConfig {
|
|
21
|
+
duration?: {
|
|
22
|
+
short?: number;
|
|
23
|
+
medium?: number;
|
|
24
|
+
long?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const globalNotifyDuration = (vuelessConfig.component?.UNotify as VuelessNotifyConfig)?.duration;
|
|
29
|
+
const notifyClearAllEvent: Event = new Event("notifyClearAll");
|
|
30
|
+
|
|
31
|
+
let lastMessageTime: Date | undefined = undefined;
|
|
32
|
+
let lastMessage: string | undefined = undefined;
|
|
33
|
+
|
|
34
|
+
export function notify({
|
|
35
|
+
type,
|
|
36
|
+
label = "",
|
|
37
|
+
description = "",
|
|
38
|
+
duration,
|
|
39
|
+
ignoreDuplicates,
|
|
40
|
+
}: NotifyConfig = {}): void {
|
|
41
|
+
const notifyDuration: number = duration || globalNotifyDuration?.short || DURATION.short;
|
|
42
|
+
|
|
43
|
+
const isSameMessage = Boolean(
|
|
44
|
+
lastMessage === description &&
|
|
45
|
+
lastMessageTime &&
|
|
46
|
+
new Date().getTime() - lastMessageTime.getTime() < DELAY_BETWEEN_CLONES,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if ((isSameMessage || !description) && ignoreDuplicates) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
lastMessageTime = new Date();
|
|
54
|
+
lastMessage = description;
|
|
55
|
+
|
|
56
|
+
const eventDetail: NotifyEventDetail = {
|
|
57
|
+
type: type as (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE],
|
|
58
|
+
id: getRandomId(),
|
|
59
|
+
label,
|
|
60
|
+
description,
|
|
61
|
+
duration: notifyDuration,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const notifyStart: CustomEvent<NotifyEventDetail> = new CustomEvent("notifyStart", {
|
|
65
|
+
detail: eventDetail,
|
|
66
|
+
});
|
|
67
|
+
const notifyEnd: CustomEvent<NotifyEventDetail> = new CustomEvent("notifyEnd", {
|
|
68
|
+
detail: eventDetail,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
window.dispatchEvent(notifyStart);
|
|
72
|
+
|
|
73
|
+
setTimeout(() => window.dispatchEvent(notifyEnd), notifyDuration);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function notifySuccess({
|
|
77
|
+
label,
|
|
78
|
+
description,
|
|
79
|
+
duration,
|
|
80
|
+
ignoreDuplicates,
|
|
81
|
+
}: Omit<NotifyConfig, "type"> = {}): void {
|
|
82
|
+
notify({
|
|
83
|
+
label,
|
|
84
|
+
description,
|
|
85
|
+
ignoreDuplicates,
|
|
86
|
+
type: NOTIFY_TYPE.success,
|
|
87
|
+
duration: duration || globalNotifyDuration?.short || DURATION.short,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function notifyWarning({
|
|
92
|
+
label,
|
|
93
|
+
description,
|
|
94
|
+
duration,
|
|
95
|
+
ignoreDuplicates,
|
|
96
|
+
}: Omit<NotifyConfig, "type"> = {}): void {
|
|
97
|
+
notify({
|
|
98
|
+
label,
|
|
99
|
+
description,
|
|
100
|
+
ignoreDuplicates,
|
|
101
|
+
type: NOTIFY_TYPE.warning,
|
|
102
|
+
duration: duration || globalNotifyDuration?.medium || DURATION.medium,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function notifyError({
|
|
107
|
+
label,
|
|
108
|
+
description,
|
|
109
|
+
duration,
|
|
110
|
+
ignoreDuplicates,
|
|
111
|
+
}: Omit<NotifyConfig, "type"> = {}): void {
|
|
112
|
+
notify({
|
|
113
|
+
label,
|
|
114
|
+
description,
|
|
115
|
+
ignoreDuplicates,
|
|
116
|
+
type: NOTIFY_TYPE.error,
|
|
117
|
+
duration: duration || globalNotifyDuration?.long || DURATION.long,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function clearNotifications(): void {
|
|
122
|
+
window.dispatchEvent(notifyClearAllEvent);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function setDelayedNotify(settings: NotifyConfig): void {
|
|
126
|
+
localStorage.setItem(LOCAL_STORAGE_ID, JSON.stringify(settings));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getDelayedNotify(): void {
|
|
130
|
+
const notifyData: NotifyConfig | null = JSON.parse(
|
|
131
|
+
localStorage.getItem(LOCAL_STORAGE_ID) || "null",
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
clearNotifications();
|
|
135
|
+
|
|
136
|
+
if (notifyData) {
|
|
137
|
+
notify(notifyData);
|
|
138
|
+
localStorage.removeItem(LOCAL_STORAGE_ID);
|
|
139
|
+
}
|
|
140
|
+
}
|