index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { initializeFileClasses } from '#shared/components/Form/fields/FieldFile/initializeFileClasses.ts'
  3. import { initializeToggleClasses } from '#shared/components/Form/fields/FieldToggle/initializeToggleClasses.ts'
  4. import {
  5. initializeFieldEditorClasses,
  6. initializeFieldEditorProps,
  7. } from '#shared/components/Form/initializeFieldEditor.ts'
  8. import { initializeFieldLinkClasses } from '#shared/components/Form/initializeFieldLinkClasses.ts'
  9. import { initializeFormClasses } from '#shared/components/Form/initializeFormClasses.ts'
  10. import { initializeFormGroupClasses } from '#shared/components/Form/initializeFormGroupClasses.ts'
  11. import mainInitializeForm, { getFormPlugins } from '#shared/form/index.ts'
  12. import type {
  13. FormFieldTypeImportModules,
  14. FormThemeExtension,
  15. InitializeAppForm,
  16. } from '#shared/types/form.ts'
  17. import type { ImportGlobEagerOutput } from '#shared/types/utils.ts'
  18. import getCoreClasses from './theme/global/getCoreMobileClasses.ts'
  19. import type { FormKitPlugin } from '@formkit/core'
  20. import type { App } from 'vue'
  21. const pluginModules: ImportGlobEagerOutput<FormKitPlugin> = import.meta.glob(
  22. './plugins/global/*.ts',
  23. { eager: true },
  24. )
  25. export const mobileFormFieldModules: ImportGlobEagerOutput<FormFieldTypeImportModules> =
  26. import.meta.glob('../components/Form/fields/**/index.ts', { eager: true })
  27. const themeExtensionModules: ImportGlobEagerOutput<FormThemeExtension> =
  28. import.meta.glob('./theme/global/extensions/*.ts', { eager: true })
  29. export const initializeForm: InitializeAppForm = (app: App) => {
  30. const plugins = getFormPlugins(pluginModules)
  31. const theme = {
  32. coreClasses: getCoreClasses,
  33. extensions: themeExtensionModules,
  34. }
  35. mainInitializeForm(app, undefined, mobileFormFieldModules, plugins, theme)
  36. }
  37. export const initializeFormFields = () => {
  38. initializeFormClasses({
  39. loading: 'my-4',
  40. })
  41. initializeFormGroupClasses({
  42. container: 'form-group overflow-hidden rounded-xl bg-gray-500',
  43. help: 'text-xs text-gray-100 ltr:pl-3 rtl:pr-3',
  44. dirtyMark: 'form-group-mark-dirty',
  45. bottomMargin: 'mb-4',
  46. })
  47. initializeFieldLinkClasses({
  48. container: 'formkit-link flex items-center py-2',
  49. base: 'border-white/10 ltr:border-l ltr:pl-1 rtl:border-r rtl:pr-1',
  50. link: 'h-10 w-12',
  51. })
  52. initializeToggleClasses({
  53. track:
  54. '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',
  55. trackOn: '!bg-blue',
  56. knob: 'bg-white shadow-lg ring-0',
  57. })
  58. initializeFieldEditorClasses({
  59. actionBar: {
  60. buttonContainer: 'gap-1 p-2',
  61. tableMenuContainer: 'gap-1 p-2',
  62. leftGradient: {
  63. left: '-0.5rem',
  64. before: {
  65. // Currently mobile supports only dark mode
  66. background: {
  67. light: `linear-gradient(
  68. 270deg,
  69. rgba(255, 255, 255, 0),
  70. #282829)`,
  71. dark: `linear-gradient(
  72. 270deg,
  73. rgba(255, 255, 255, 0),
  74. #282829)`, // :TODO inject tailwind theme colors
  75. },
  76. },
  77. },
  78. rightGradient: {
  79. before: {
  80. // Currently mobile supports only dark mode
  81. background: {
  82. light: `linear-gradient(
  83. 90deg,
  84. rgba(255, 255, 255, 0),
  85. #282829)`,
  86. dark: `linear-gradient(
  87. 90deg,
  88. rgba(255, 255, 255, 0),
  89. #282829`, // :TODO inject tailwind theme colors
  90. },
  91. },
  92. },
  93. shadowGradient: {
  94. before: {
  95. top: 'calc(0px - 30px - 1.5rem)',
  96. height: 'calc(30px + 1.5rem)',
  97. },
  98. },
  99. button: {
  100. base: 'rounded bg-black p-2 lg:hover:bg-gray-300', // Should we add a hover class here? It was there in the original code.
  101. active: 'bg-gray-300',
  102. },
  103. },
  104. input: {
  105. container: 'p-2',
  106. },
  107. })
  108. initializeFieldEditorProps({
  109. actionBar: {
  110. button: {
  111. icon: {
  112. size: 'small',
  113. },
  114. },
  115. },
  116. })
  117. initializeFileClasses({
  118. button: 'disabled:text-blue/60 text-blue p-2.5 w-full',
  119. listContainer: 'max-h-48 px-4 pt-4',
  120. })
  121. }