index.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { initializeToggleClasses } from '#shared/components/Form/fields/FieldToggle/initializeToggleClasses.ts'
  3. import { initializeFieldLinkClasses } from '#shared/components/Form/initializeFieldLinkClasses.ts'
  4. import { initializeFormClasses } from '#shared/components/Form/initializeFormClasses.ts'
  5. import { initializeFormGroupClasses } from '#shared/components/Form/initializeFormGroupClasses.ts'
  6. import mainInitializeForm, { getFormPlugins } from '#shared/form/index.ts'
  7. import type {
  8. FormFieldTypeImportModules,
  9. FormThemeExtension,
  10. InitializeAppForm,
  11. } from '#shared/types/form.ts'
  12. import type { ImportGlobEagerOutput } from '#shared/types/utils.ts'
  13. import getCoreClasses from './theme/global/getCoreMobileClasses.ts'
  14. import type { FormKitPlugin } from '@formkit/core'
  15. import type { App } from 'vue'
  16. const pluginModules: ImportGlobEagerOutput<FormKitPlugin> = import.meta.glob(
  17. './plugins/global/*.ts',
  18. { eager: true },
  19. )
  20. export const mobileFormFieldModules: ImportGlobEagerOutput<FormFieldTypeImportModules> =
  21. import.meta.glob('../components/Form/fields/**/index.ts', { eager: true })
  22. const themeExtensionModules: ImportGlobEagerOutput<FormThemeExtension> =
  23. import.meta.glob('./theme/global/extensions/*.ts', { eager: true })
  24. export const initializeForm: InitializeAppForm = (app: App) => {
  25. const plugins = getFormPlugins(pluginModules)
  26. const theme = {
  27. coreClasses: getCoreClasses,
  28. extensions: themeExtensionModules,
  29. }
  30. mainInitializeForm(app, undefined, mobileFormFieldModules, plugins, theme)
  31. }
  32. export const initializeFormFields = () => {
  33. initializeFormClasses({
  34. loading: 'my-4',
  35. })
  36. initializeFormGroupClasses({
  37. container: 'form-group overflow-hidden rounded-xl bg-gray-500',
  38. help: 'text-xs text-gray-100 ltr:pl-3 rtl:pr-3',
  39. dirtyMark: 'form-group-mark-dirty',
  40. })
  41. initializeFieldLinkClasses({
  42. container: 'formkit-link flex items-center py-2',
  43. base: 'border-white/10 ltr:border-l ltr:pl-1 rtl:border-r rtl:pr-1',
  44. link: 'h-10 w-12',
  45. })
  46. initializeToggleClasses({
  47. track:
  48. 'bg-gray-300 border border-transparent focus-within:ring-1 focus-within:ring-white focus-within:ring-opacity-75 focus:outline-none formkit-invalid:border-solid formkit-invalid:border-red',
  49. trackOn: '!bg-blue',
  50. knob: 'bg-white shadow-lg ring-0',
  51. })
  52. }