fds-vue-core 9.1.0 → 9.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/components.d.ts +4 -0
- package/dist/components/Blocks/FdsBlockLink/FdsBlockLink.js.map +1 -1
- package/dist/components/Blocks/FdsBlockLink/FdsBlockLink.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/Blocks/FdsBlockLink/FdsBlockLink.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/Buttons/FdsButtonIcon/FdsButtonIcon.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/components/Buttons/FdsButtonIcon/FdsButtonIcon.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/Buttons/FdsButtonIcon/types.d.ts +1 -0
- package/dist/components/FdsSearchSelect/FdsSearchSelect.js.map +1 -1
- package/dist/components/FdsSearchSelect/FdsSearchSelect.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/components/FdsSearchSelect/FdsSearchSelect.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.js.map +1 -1
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/FdsSnackbar/FdsSnackbar.js +6 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.js.map +1 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue.d.ts +7 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue_vue_type_script_setup_true_lang.js +78 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsSnackbar/types.d.ts +16 -0
- package/dist/components/FdsSnackbar/useSnackbar.d.ts +40 -0
- package/dist/components/FdsSnackbar/useSnackbar.js +19 -0
- package/dist/components/FdsSnackbar/useSnackbar.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.js +6 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue.d.ts +8 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js +58 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.js +6 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue.d.ts +20 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue_vue_type_script_setup_true_lang.js +185 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.js +8 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue.d.ts +28 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue_vue_type_script_setup_true_lang.js +81 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/createMessageQueue.d.ts +19 -0
- package/dist/components/FdsToastMessage/createMessageQueue.js +50 -0
- package/dist/components/FdsToastMessage/createMessageQueue.js.map +1 -0
- package/dist/components/FdsToastMessage/getReadingDuration.d.ts +1 -0
- package/dist/components/FdsToastMessage/getReadingDuration.js +11 -0
- package/dist/components/FdsToastMessage/getReadingDuration.js.map +1 -0
- package/dist/components/FdsToastMessage/types.d.ts +20 -0
- package/dist/components/FdsToastMessage/useToastMessage.d.ts +40 -0
- package/dist/components/FdsToastMessage/useToastMessage.js +19 -0
- package/dist/components/FdsToastMessage/useToastMessage.js.map +1 -0
- package/dist/fds-vue-core.css +2 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/lang/en.js +6 -0
- package/dist/lang/en.js.map +1 -1
- package/dist/lang/sv.js +6 -0
- package/dist/lang/sv.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/components/Blocks/FdsBlockLink/FdsBlockLink.vue +1 -1
- package/src/components/Buttons/FdsButtonIcon/types.ts +1 -0
- package/src/components/FdsSearchSelect/FdsSearchSelect.vue +8 -3
- package/src/components/FdsSearchSelectPro/FdsSearchSelectPro.vue +8 -3
- package/src/components/FdsSnackbar/FdsSnackbar.stories.ts +111 -0
- package/src/components/FdsSnackbar/FdsSnackbar.vue +74 -0
- package/src/components/FdsSnackbar/types.ts +21 -0
- package/src/components/FdsSnackbar/useSnackbar.ts +19 -0
- package/src/components/FdsToastMessage/FdsToastMessage.stories.ts +122 -0
- package/src/components/FdsToastMessage/FdsToastMessage.vue +44 -0
- package/src/components/FdsToastMessage/FdsToastMessageCard.vue +173 -0
- package/src/components/FdsToastMessage/FdsToastRegions.vue +114 -0
- package/src/components/FdsToastMessage/createMessageQueue.ts +57 -0
- package/src/components/FdsToastMessage/getReadingDuration.ts +8 -0
- package/src/components/FdsToastMessage/types.ts +31 -0
- package/src/components/FdsToastMessage/useToastMessage.ts +19 -0
- package/src/docs/Start/Start.mdx +3 -1
- package/src/docs/Start/Start.stories.ts +18 -0
- package/src/index.ts +27 -0
- package/src/lang/en.json +6 -0
- package/src/lang/sv.json +6 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { useFdsI18n } from '../../plugin/useFdsI18n'
|
|
4
|
+
import FdsButtonIcon from '../Buttons/FdsButtonIcon/FdsButtonIcon.vue'
|
|
5
|
+
import FdsButtonMinor from '../Buttons/FdsButtonMinor/FdsButtonMinor.vue'
|
|
6
|
+
import FdsIcon from '../FdsIcon/FdsIcon.vue'
|
|
7
|
+
import type { FdsIconName } from '../FdsIcon/types'
|
|
8
|
+
import type { FdsToastMessageType } from './types'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
message: string
|
|
12
|
+
heading?: string
|
|
13
|
+
type: FdsToastMessageType
|
|
14
|
+
duration: number
|
|
15
|
+
closeable: boolean
|
|
16
|
+
actionLabel?: string
|
|
17
|
+
screenReaderHint?: string
|
|
18
|
+
dataTestid?: string
|
|
19
|
+
}>()
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{
|
|
22
|
+
(e: 'close'): void
|
|
23
|
+
(e: 'action'): void
|
|
24
|
+
}>()
|
|
25
|
+
|
|
26
|
+
const { t } = useFdsI18n()
|
|
27
|
+
|
|
28
|
+
const typeStyles: Record<FdsToastMessageType, { card: string; icon: string; action: string; iconName: FdsIconName }> =
|
|
29
|
+
{
|
|
30
|
+
success: { card: 'bg-green-100 inset-ring-green-300', icon: 'fill-green-700', action: '', iconName: 'success' },
|
|
31
|
+
info: { card: 'bg-blue-100 inset-ring-blue-300', icon: 'fill-blue-700', action: '', iconName: 'information' },
|
|
32
|
+
warning: {
|
|
33
|
+
card: 'bg-yellow-200 inset-ring-yellow-300',
|
|
34
|
+
icon: 'fill-yellow-700',
|
|
35
|
+
action:
|
|
36
|
+
'[&_button]:text-gray-900! [&_button]:underline [&_button]:hover:bg-gray-100! [&_button]:active:bg-gray-200!',
|
|
37
|
+
iconName: 'warning',
|
|
38
|
+
},
|
|
39
|
+
error: { card: 'bg-red-100 inset-ring-red-300', icon: 'fill-red-700', action: '', iconName: 'alert' },
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const style = computed(() => typeStyles[props.type])
|
|
43
|
+
|
|
44
|
+
const typeLabel = computed(() => {
|
|
45
|
+
const labels: Record<FdsToastMessageType, string> = {
|
|
46
|
+
success: t('FdsToastMessage.type.success'),
|
|
47
|
+
info: t('FdsToastMessage.type.info'),
|
|
48
|
+
warning: t('FdsToastMessage.type.warning'),
|
|
49
|
+
error: t('FdsToastMessage.type.error'),
|
|
50
|
+
}
|
|
51
|
+
return labels[props.type]
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const isHovered = ref(false)
|
|
55
|
+
const isFocused = ref(false)
|
|
56
|
+
const isSwiping = ref(false)
|
|
57
|
+
const swipeOffset = ref(0)
|
|
58
|
+
let swipeStartX = 0
|
|
59
|
+
let swipeStartTime = 0
|
|
60
|
+
|
|
61
|
+
const isPaused = computed(() => isHovered.value || isFocused.value || isSwiping.value)
|
|
62
|
+
|
|
63
|
+
const cardStyle = computed(() => ({
|
|
64
|
+
transform: swipeOffset.value ? `translateX(${swipeOffset.value}px)` : undefined,
|
|
65
|
+
opacity: swipeOffset.value ? Math.max(0.3, 1 - Math.abs(swipeOffset.value) / 250) : undefined,
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
let remainingTime = props.duration
|
|
69
|
+
let closeTimer: number | undefined
|
|
70
|
+
let timerStartedAt = 0
|
|
71
|
+
|
|
72
|
+
function startCloseTimer() {
|
|
73
|
+
if (props.duration <= 0 || closeTimer !== undefined) return
|
|
74
|
+
timerStartedAt = Date.now()
|
|
75
|
+
closeTimer = window.setTimeout(() => emit('close'), remainingTime)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function pauseCloseTimer() {
|
|
79
|
+
if (closeTimer === undefined) return
|
|
80
|
+
window.clearTimeout(closeTimer)
|
|
81
|
+
closeTimer = undefined
|
|
82
|
+
remainingTime -= Date.now() - timerStartedAt
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
watch(isPaused, (paused) => (paused ? pauseCloseTimer() : startCloseTimer()))
|
|
86
|
+
|
|
87
|
+
onMounted(startCloseTimer)
|
|
88
|
+
|
|
89
|
+
onBeforeUnmount(pauseCloseTimer)
|
|
90
|
+
|
|
91
|
+
function handlePointerDown(event: PointerEvent) {
|
|
92
|
+
if (event.pointerType === 'mouse' || (event.target instanceof Element && event.target.closest('button, a'))) return
|
|
93
|
+
isSwiping.value = true
|
|
94
|
+
swipeStartX = event.clientX
|
|
95
|
+
swipeStartTime = event.timeStamp
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handlePointerMove(event: PointerEvent) {
|
|
99
|
+
if (!isSwiping.value) return
|
|
100
|
+
const distance = event.clientX - swipeStartX
|
|
101
|
+
if (swipeOffset.value === 0 && Math.abs(distance) < 10) return
|
|
102
|
+
swipeOffset.value = distance
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function handlePointerUp(event: PointerEvent) {
|
|
106
|
+
if (!isSwiping.value) return
|
|
107
|
+
isSwiping.value = false
|
|
108
|
+
const distance = Math.abs(swipeOffset.value)
|
|
109
|
+
const speed = distance / Math.max(1, event.timeStamp - swipeStartTime)
|
|
110
|
+
if (distance > 100 || (distance > 30 && speed > 0.5)) {
|
|
111
|
+
emit('close')
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
swipeOffset.value = 0
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function handlePointerCancel() {
|
|
118
|
+
isSwiping.value = false
|
|
119
|
+
swipeOffset.value = 0
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function handleFocusOut(event: FocusEvent) {
|
|
123
|
+
if (event.currentTarget instanceof Element && event.relatedTarget instanceof Node) {
|
|
124
|
+
isFocused.value = event.currentTarget.contains(event.relatedTarget)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
isFocused.value = false
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<div
|
|
133
|
+
:role="type === 'error' ? 'alert' : undefined"
|
|
134
|
+
v-bind="{ 'data-testid': dataTestid }"
|
|
135
|
+
:class="[
|
|
136
|
+
'pointer-events-auto flex items-start gap-3 overflow-hidden rounded-md inset-ring-1 p-4 shadow-lg touch-pan-y',
|
|
137
|
+
style.card,
|
|
138
|
+
isSwiping ? '' : 'transition-[transform,opacity] duration-200 ease-out',
|
|
139
|
+
swipeOffset !== 0 && 'select-none',
|
|
140
|
+
]"
|
|
141
|
+
:style="cardStyle"
|
|
142
|
+
@mouseenter="isHovered = true"
|
|
143
|
+
@mouseleave="isHovered = false"
|
|
144
|
+
@focusin="isFocused = true"
|
|
145
|
+
@focusout="handleFocusOut"
|
|
146
|
+
@keydown.esc="closeable && emit('close')"
|
|
147
|
+
@pointerdown="handlePointerDown"
|
|
148
|
+
@pointermove="handlePointerMove"
|
|
149
|
+
@pointerup="handlePointerUp"
|
|
150
|
+
@pointercancel="handlePointerCancel"
|
|
151
|
+
>
|
|
152
|
+
<div class="h-7 flex items-center shrink-0">
|
|
153
|
+
<FdsIcon :name="style.iconName" :size="24" :class="style.icon" aria-hidden="true" />
|
|
154
|
+
</div>
|
|
155
|
+
<div class="flex-1 min-w-0 flex flex-col py-0.5 break-words">
|
|
156
|
+
<span class="sr-only">{{ typeLabel }}</span>
|
|
157
|
+
<span v-if="heading" class="font-bold">{{ heading }}</span>
|
|
158
|
+
<span>{{ message }}</span>
|
|
159
|
+
<span v-if="screenReaderHint" class="sr-only">{{ screenReaderHint }}</span>
|
|
160
|
+
</div>
|
|
161
|
+
<div v-if="actionLabel" class="flex flex-col justify-center self-center shrink-0">
|
|
162
|
+
<FdsButtonMinor :text="actionLabel" :class="style.action" @click="emit('action')" />
|
|
163
|
+
</div>
|
|
164
|
+
<FdsButtonIcon
|
|
165
|
+
v-if="closeable"
|
|
166
|
+
icon="cross"
|
|
167
|
+
:size="28"
|
|
168
|
+
class="shrink-0 fill-gray-900! hover:bg-gray-100 active:bg-gray-200"
|
|
169
|
+
v-bind="{ 'aria-label': t('FdsToastMessage.close') }"
|
|
170
|
+
@click="emit('close')"
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
</template>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts" generic="Item extends FdsToastMessageItem">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import type { FdsToastMessageItem, FdsToastMessagePosition } from './types'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
items: readonly Item[]
|
|
7
|
+
position: FdsToastMessagePosition
|
|
8
|
+
max: number
|
|
9
|
+
widthClass: string
|
|
10
|
+
}>()
|
|
11
|
+
|
|
12
|
+
defineSlots<{
|
|
13
|
+
item(props: { item: Item }): unknown
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
const regionStyles: Record<FdsToastMessagePosition, { classes: string; enterX: string; enterY: string }> = {
|
|
17
|
+
'top-left': { classes: 'top-0 left-0 flex-col', enterX: '-2rem', enterY: '0' },
|
|
18
|
+
'top-center': { classes: 'top-0 left-1/2 -translate-x-1/2 flex-col', enterX: '0', enterY: '-1rem' },
|
|
19
|
+
'top-right': { classes: 'top-0 right-0 flex-col', enterX: '2rem', enterY: '0' },
|
|
20
|
+
'bottom-left': { classes: 'bottom-0 left-0 flex-col-reverse', enterX: '-2rem', enterY: '0' },
|
|
21
|
+
'bottom-center': { classes: 'bottom-0 left-1/2 -translate-x-1/2 flex-col-reverse', enterX: '0', enterY: '1rem' },
|
|
22
|
+
'bottom-right': { classes: 'bottom-0 right-0 flex-col-reverse', enterX: '2rem', enterY: '0' },
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const regions = computed(() =>
|
|
26
|
+
(Object.keys(regionStyles) as FdsToastMessagePosition[]).map((position) => ({
|
|
27
|
+
position,
|
|
28
|
+
...regionStyles[position],
|
|
29
|
+
items: props.items.filter((item) => (item.position ?? props.position) === position).slice(0, props.max),
|
|
30
|
+
})),
|
|
31
|
+
)
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<Teleport to="body">
|
|
36
|
+
<div
|
|
37
|
+
v-for="region in regions"
|
|
38
|
+
:key="region.position"
|
|
39
|
+
aria-live="polite"
|
|
40
|
+
:class="['fixed z-[100000] flex w-full p-2.5 pointer-events-none', widthClass, region.classes]"
|
|
41
|
+
:style="{
|
|
42
|
+
'--fds-toast-enter-x': region.enterX,
|
|
43
|
+
'--fds-toast-enter-y': region.enterY,
|
|
44
|
+
}"
|
|
45
|
+
>
|
|
46
|
+
<TransitionGroup name="fds-toast">
|
|
47
|
+
<div v-for="item in region.items" :key="item.id" class="fds-toast">
|
|
48
|
+
<div class="min-h-0">
|
|
49
|
+
<div class="py-1.5">
|
|
50
|
+
<slot name="item" :item="item" />
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</TransitionGroup>
|
|
55
|
+
</div>
|
|
56
|
+
</Teleport>
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<style scoped>
|
|
60
|
+
.fds-toast {
|
|
61
|
+
display: grid;
|
|
62
|
+
grid-template-rows: 1fr;
|
|
63
|
+
will-change: transform, opacity;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.fds-toast-enter-active {
|
|
67
|
+
transition:
|
|
68
|
+
opacity 120ms ease-out,
|
|
69
|
+
transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.fds-toast-move {
|
|
73
|
+
transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.fds-toast-leave-active {
|
|
77
|
+
transition:
|
|
78
|
+
opacity 140ms ease-out,
|
|
79
|
+
transform 140ms ease-out,
|
|
80
|
+
grid-template-rows 110ms cubic-bezier(0.4, 0, 0.2, 1) 90ms;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.fds-toast-leave-active > div {
|
|
84
|
+
overflow: hidden;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.fds-toast-enter-from {
|
|
88
|
+
opacity: 0;
|
|
89
|
+
transform: translate(var(--fds-toast-enter-x), var(--fds-toast-enter-y));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.fds-toast-leave-to {
|
|
93
|
+
grid-template-rows: 0fr;
|
|
94
|
+
opacity: 0;
|
|
95
|
+
transform: scale(0.98);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@media (prefers-reduced-motion: reduce) {
|
|
99
|
+
.fds-toast-enter-active,
|
|
100
|
+
.fds-toast-leave-active {
|
|
101
|
+
transition: opacity 150ms linear;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.fds-toast-move {
|
|
105
|
+
transition: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.fds-toast-enter-from,
|
|
109
|
+
.fds-toast-leave-to {
|
|
110
|
+
grid-template-rows: 1fr;
|
|
111
|
+
transform: none;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
</style>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { computed, onBeforeUnmount, onMounted, shallowReadonly, shallowRef } from 'vue'
|
|
2
|
+
import type { FdsToastMessageOptions, FdsToastMessageType } from './types'
|
|
3
|
+
|
|
4
|
+
type ShortcutOptions<Options> = Omit<Options, 'message' | 'type'>
|
|
5
|
+
|
|
6
|
+
type ShortcutArguments<Options> =
|
|
7
|
+
Partial<ShortcutOptions<Options>> extends ShortcutOptions<Options>
|
|
8
|
+
? [options?: ShortcutOptions<Options>]
|
|
9
|
+
: [options: ShortcutOptions<Options>]
|
|
10
|
+
|
|
11
|
+
export function createMessageQueue<Options extends FdsToastMessageOptions>() {
|
|
12
|
+
const items = shallowRef<(Options & { id: number })[]>([])
|
|
13
|
+
const mountedContainers = shallowRef<symbol[]>([])
|
|
14
|
+
let nextId = 0
|
|
15
|
+
|
|
16
|
+
const show = (options: Options): number => {
|
|
17
|
+
nextId += 1
|
|
18
|
+
items.value = [...items.value, { ...options, id: nextId }]
|
|
19
|
+
return nextId
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const dismiss = (id: number) => {
|
|
23
|
+
items.value = items.value.filter((item) => item.id !== id)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const clear = () => {
|
|
27
|
+
items.value = []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const showType =
|
|
31
|
+
(type: FdsToastMessageType) =>
|
|
32
|
+
(message: string, ...[options]: ShortcutArguments<Options>) =>
|
|
33
|
+
show({ ...options, message, type } as Options)
|
|
34
|
+
|
|
35
|
+
const useContainer = () => {
|
|
36
|
+
const containerId = Symbol('FdsMessageContainer')
|
|
37
|
+
onMounted(() => {
|
|
38
|
+
mountedContainers.value = [...mountedContainers.value, containerId]
|
|
39
|
+
})
|
|
40
|
+
onBeforeUnmount(() => {
|
|
41
|
+
mountedContainers.value = mountedContainers.value.filter((id) => id !== containerId)
|
|
42
|
+
})
|
|
43
|
+
return computed(() => mountedContainers.value[0] === containerId)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
items: shallowReadonly(items),
|
|
48
|
+
show,
|
|
49
|
+
dismiss,
|
|
50
|
+
clear,
|
|
51
|
+
success: showType('success'),
|
|
52
|
+
info: showType('info'),
|
|
53
|
+
warning: showType('warning'),
|
|
54
|
+
error: showType('error'),
|
|
55
|
+
useContainer,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const reactionTime = 1000
|
|
2
|
+
const timePerWord = 300
|
|
3
|
+
|
|
4
|
+
export function getReadingDuration(text: string, minimumDuration: number): number {
|
|
5
|
+
if (minimumDuration <= 0) return 0
|
|
6
|
+
const wordCount = text.split(/\s+/).filter(Boolean).length
|
|
7
|
+
return Math.max(minimumDuration, reactionTime + wordCount * timePerWord)
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type FdsToastMessageType = 'warning' | 'info' | 'error' | 'success'
|
|
2
|
+
|
|
3
|
+
export type FdsToastMessagePosition =
|
|
4
|
+
| 'top-left'
|
|
5
|
+
| 'top-center'
|
|
6
|
+
| 'top-right'
|
|
7
|
+
| 'bottom-left'
|
|
8
|
+
| 'bottom-center'
|
|
9
|
+
| 'bottom-right'
|
|
10
|
+
|
|
11
|
+
export interface FdsToastMessageOptions {
|
|
12
|
+
message: string
|
|
13
|
+
heading?: string
|
|
14
|
+
type?: FdsToastMessageType
|
|
15
|
+
duration?: number
|
|
16
|
+
position?: FdsToastMessagePosition
|
|
17
|
+
closeable?: boolean
|
|
18
|
+
dataTestid?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FdsToastMessageItem extends FdsToastMessageOptions {
|
|
22
|
+
id: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type FdsToastMessageShortcutOptions = Omit<FdsToastMessageOptions, 'message' | 'type'>
|
|
26
|
+
|
|
27
|
+
export interface FdsToastMessageProps {
|
|
28
|
+
position?: FdsToastMessagePosition
|
|
29
|
+
duration?: number
|
|
30
|
+
max?: number
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMessageQueue } from './createMessageQueue'
|
|
2
|
+
import type { FdsToastMessageOptions } from './types'
|
|
3
|
+
|
|
4
|
+
const toastQueue = createMessageQueue<FdsToastMessageOptions>()
|
|
5
|
+
|
|
6
|
+
export function useToastMessage() {
|
|
7
|
+
return {
|
|
8
|
+
toasts: toastQueue.items,
|
|
9
|
+
show: toastQueue.show,
|
|
10
|
+
dismiss: toastQueue.dismiss,
|
|
11
|
+
clear: toastQueue.clear,
|
|
12
|
+
success: toastQueue.success,
|
|
13
|
+
info: toastQueue.info,
|
|
14
|
+
warning: toastQueue.warning,
|
|
15
|
+
error: toastQueue.error,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useToastMessageContainer = toastQueue.useContainer
|
package/src/docs/Start/Start.mdx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Meta, Typeset } from '@storybook/addon-docs/blocks'
|
|
1
|
+
import { Meta, Story, Typeset } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as StartStories from './Start.stories'
|
|
2
3
|
// fallow-ignore-file
|
|
3
4
|
|
|
4
5
|
<Meta title="Start" />
|
|
@@ -9,5 +10,6 @@ import { Meta, Typeset } from '@storybook/addon-docs/blocks'
|
|
|
9
10
|
<fds-text type="lead">
|
|
10
11
|
Everything you'll eventually need to build great and accessible solutions for Feelgood.
|
|
11
12
|
</fds-text>
|
|
13
|
+
<Story of={StartStories.AppVersion} />
|
|
12
14
|
</div>
|
|
13
15
|
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
|
+
import { version } from '../../../package.json'
|
|
3
|
+
import FdsAppVersion from '../../components/FdsAppVersion/FdsAppVersion.vue'
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof FdsAppVersion> = {
|
|
6
|
+
title: 'Start/AppVersion',
|
|
7
|
+
component: FdsAppVersion,
|
|
8
|
+
tags: ['!dev'],
|
|
9
|
+
args: {
|
|
10
|
+
name: 'fds-vue-core',
|
|
11
|
+
version,
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj<typeof meta>
|
|
17
|
+
|
|
18
|
+
export const AppVersion: Story = {}
|
package/src/index.ts
CHANGED
|
@@ -25,10 +25,12 @@ import FdsPagination from './components/FdsPagination/FdsPagination.vue'
|
|
|
25
25
|
import FdsPopover from './components/FdsPopover/FdsPopover.vue'
|
|
26
26
|
import FdsSearchSelect from './components/FdsSearchSelect/FdsSearchSelect.vue'
|
|
27
27
|
import FdsSearchSelectPro from './components/FdsSearchSelectPro/FdsSearchSelectPro.vue'
|
|
28
|
+
import FdsSnackbar from './components/FdsSnackbar/FdsSnackbar.vue'
|
|
28
29
|
import FdsSpinner from './components/FdsSpinner/FdsSpinner.vue'
|
|
29
30
|
import FdsSticker from './components/FdsSticker/FdsSticker.vue'
|
|
30
31
|
import FdsTreeView from './components/FdsTreeView/FdsTreeView.vue'
|
|
31
32
|
import FdsTruncatedText from './components/FdsTruncatedText/FdsTruncatedText.vue'
|
|
33
|
+
import FdsToastMessage from './components/FdsToastMessage/FdsToastMessage.vue'
|
|
32
34
|
import FdsWeekCalendar from './components/FdsWeekCalendar/FdsWeekCalendar.vue'
|
|
33
35
|
import FdsWizard from './components/FdsWizard/FdsWizard.vue'
|
|
34
36
|
import FdsBankIdQr from './components/BankId/FdsBankIdQr/FdsBankIdQr.vue'
|
|
@@ -59,6 +61,8 @@ import FdsMeta from './components/Typography/FdsMeta/FdsMeta.vue'
|
|
|
59
61
|
|
|
60
62
|
// Import composables (relative paths)
|
|
61
63
|
import useTreeState from './components/FdsTreeView/useTreeState'
|
|
64
|
+
import { useToastMessage } from './components/FdsToastMessage/useToastMessage'
|
|
65
|
+
import { useSnackbar } from './components/FdsSnackbar/useSnackbar'
|
|
62
66
|
import { useBoldQuery } from './composables/useBoldQuery'
|
|
63
67
|
import { useDevMode } from './composables/useDevMode'
|
|
64
68
|
import { useDevModeEnvironment } from './composables/useDevModeEnvironment'
|
|
@@ -151,6 +155,7 @@ export {
|
|
|
151
155
|
FdsSearchSelect,
|
|
152
156
|
FdsSearchSelectPro,
|
|
153
157
|
FdsSelect,
|
|
158
|
+
FdsSnackbar,
|
|
154
159
|
FdsSpinner,
|
|
155
160
|
FdsSticker,
|
|
156
161
|
FdsSwitch,
|
|
@@ -160,6 +165,7 @@ export {
|
|
|
160
165
|
FdsTabsItem,
|
|
161
166
|
FdsTextarea,
|
|
162
167
|
FdsTreeView,
|
|
168
|
+
FdsToastMessage,
|
|
163
169
|
FdsTruncatedText,
|
|
164
170
|
FdsWeekCalendar,
|
|
165
171
|
FdsWizard,
|
|
@@ -211,6 +217,8 @@ export {
|
|
|
211
217
|
usePreviousLocation,
|
|
212
218
|
useRouteFilters,
|
|
213
219
|
useRouteScrollPositions,
|
|
220
|
+
useSnackbar,
|
|
221
|
+
useToastMessage,
|
|
214
222
|
useTreeState,
|
|
215
223
|
useViewportBreakpoint,
|
|
216
224
|
}
|
|
@@ -270,7 +278,9 @@ const FdsVueCorePlugin: Plugin<[FdsVueCorePluginOptions?]> = {
|
|
|
270
278
|
app.component('FdsPopover', FdsPopover)
|
|
271
279
|
app.component('FdsSearchSelect', FdsSearchSelect)
|
|
272
280
|
app.component('FdsSearchSelectPro', FdsSearchSelectPro)
|
|
281
|
+
app.component('FdsSnackbar', FdsSnackbar)
|
|
273
282
|
app.component('FdsTruncatedText', FdsTruncatedText)
|
|
283
|
+
app.component('FdsToastMessage', FdsToastMessage)
|
|
274
284
|
app.component('FdsWizard', FdsWizard)
|
|
275
285
|
app.component('FdsWeekCalendar', FdsWeekCalendar)
|
|
276
286
|
app.component('FdsError', FdsError)
|
|
@@ -472,6 +482,23 @@ export type {
|
|
|
472
482
|
|
|
473
483
|
export type { FdsSpinnerProps } from './components/FdsSpinner/types'
|
|
474
484
|
|
|
485
|
+
export type {
|
|
486
|
+
FdsToastMessageItem,
|
|
487
|
+
FdsToastMessageOptions,
|
|
488
|
+
FdsToastMessagePosition,
|
|
489
|
+
FdsToastMessageProps,
|
|
490
|
+
FdsToastMessageShortcutOptions,
|
|
491
|
+
FdsToastMessageType,
|
|
492
|
+
} from './components/FdsToastMessage/types'
|
|
493
|
+
|
|
494
|
+
export type {
|
|
495
|
+
FdsSnackbarAction,
|
|
496
|
+
FdsSnackbarItem,
|
|
497
|
+
FdsSnackbarOptions,
|
|
498
|
+
FdsSnackbarProps,
|
|
499
|
+
FdsSnackbarShortcutOptions,
|
|
500
|
+
} from './components/FdsSnackbar/types'
|
|
501
|
+
|
|
475
502
|
export type { FdsStickerProps } from './components/FdsSticker/types'
|
|
476
503
|
|
|
477
504
|
export type { FdsTruncatedTextProps } from './components/FdsTruncatedText/types'
|
package/src/lang/en.json
CHANGED
|
@@ -132,9 +132,15 @@
|
|
|
132
132
|
"FdsSearchSelectPro.loadingMore": "Loading more...",
|
|
133
133
|
"FdsSearchSelectPro.showMore": "Show more",
|
|
134
134
|
"FdsSearchSelectPro.unspecified": "Unspecified",
|
|
135
|
+
"FdsSnackbar.focusHint": "Press Alt+T (Option+T on Mac) to reach the action.",
|
|
135
136
|
"FdsSsn.invalidSsn": "Enter a valid Swedish personal identity number or coordination number",
|
|
136
137
|
"FdsSsn.label": "Personal identity number",
|
|
137
138
|
"FdsTextarea.characters": "characters",
|
|
139
|
+
"FdsToastMessage.close": "Close",
|
|
140
|
+
"FdsToastMessage.type.error": "Error:",
|
|
141
|
+
"FdsToastMessage.type.info": "Information:",
|
|
142
|
+
"FdsToastMessage.type.success": "Success:",
|
|
143
|
+
"FdsToastMessage.type.warning": "Warning:",
|
|
138
144
|
"FdsTreeView.childrenCountPrefix": "(+",
|
|
139
145
|
"FdsTreeView.closePopover": "Close",
|
|
140
146
|
"FdsTreeView.collapseNode": "Collapse {title}",
|
package/src/lang/sv.json
CHANGED
|
@@ -132,9 +132,15 @@
|
|
|
132
132
|
"FdsSearchSelectPro.loadingMore": "Hämtar fler...",
|
|
133
133
|
"FdsSearchSelectPro.showMore": "Visa fler",
|
|
134
134
|
"FdsSearchSelectPro.unspecified": "Ospecificerat",
|
|
135
|
+
"FdsSnackbar.focusHint": "Tryck Alt+T (Option+T på Mac) för att nå åtgärden.",
|
|
135
136
|
"FdsSsn.invalidSsn": "Ange ett giltigt personnummer eller samordningsnummer",
|
|
136
137
|
"FdsSsn.label": "Personnummer",
|
|
137
138
|
"FdsTextarea.characters": "tecken",
|
|
139
|
+
"FdsToastMessage.close": "Stäng",
|
|
140
|
+
"FdsToastMessage.type.error": "Fel:",
|
|
141
|
+
"FdsToastMessage.type.info": "Information:",
|
|
142
|
+
"FdsToastMessage.type.success": "Lyckades:",
|
|
143
|
+
"FdsToastMessage.type.warning": "Varning:",
|
|
138
144
|
"FdsTreeView.childrenCountPrefix": "(+",
|
|
139
145
|
"FdsTreeView.closePopover": "Stäng",
|
|
140
146
|
"FdsTreeView.collapseNode": "Fäll ihop {title}",
|