-
Notifications
You must be signed in to change notification settings - Fork 1
/
formkit.config.ts
87 lines (81 loc) · 2.76 KB
/
formkit.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { rootClasses } from './formkit.theme';
import { de } from '@formkit/i18n';
import { createAutoAnimatePlugin, createFloatingLabelsPlugin } from '@formkit/addons';
import '@formkit/addons/css/floatingLabels';
export const defaultPlugins = {
autoAnimate: createAutoAnimatePlugin(
{
duration: 250,
easing: 'ease-in-out',
},
{
global: ['outer', 'inner'],
form: ['form'],
repeater: ['items'],
},
),
floatingLabels: createFloatingLabelsPlugin({
useAsDefault: true,
}),
};
export default {
iconLoader: (iconName: string) => {
const getIcon = async (iconkey: string) => {
if (!iconkey) {
return undefined;
}
try {
const iconsImport = import.meta.glob('assets/icons/**/**.svg', {
query: '?raw',
import: 'default',
eager: false,
});
const iconsImportElement = iconsImport[`/assets/icons/${iconkey}.svg`];
if (!iconsImportElement) {
return undefined;
}
return (await iconsImportElement()) ?? undefined;
} catch {
return undefined;
}
};
return getIcon(iconName)
.then(async icon => {
if (icon) {
// returns the icon from our repository
return icon;
} else {
// returns the icon from fontawesome as fallback (or undefined if not found)
return fetch(
`https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/svgs/solid/${iconName}.svg`,
)
.then(async r => {
const icon = await r.text();
if (icon.startsWith('<svg')) {
// returns the icon from fontawesome
return icon;
} else {
// returns undefined if the icon is not found in either the local repository or the CDN
return undefined;
}
})
.catch(e => {
console.error(e);
return undefined;
});
}
})
.catch(e => {
console.error(e);
return undefined;
});
},
locales: { de },
config: {
rootClasses,
},
plugins: Object.values(defaultPlugins),
props: {
decoratorIcon: 'check',
},
};