index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. })
  46. initializeFieldLinkClasses({
  47. container: 'formkit-link flex items-center py-2',
  48. base: 'border-white/10 ltr:border-l ltr:pl-1 rtl:border-r rtl:pr-1',
  49. link: 'h-10 w-12',
  50. })
  51. initializeToggleClasses({
  52. track:
  53. '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',
  54. trackOn: '!bg-blue',
  55. knob: 'bg-white shadow-lg ring-0',
  56. })
  57. initializeFieldEditorClasses({
  58. actionBar: {
  59. buttonContainer: 'gap-1 p-2',
  60. tableMenuContainer: 'gap-1 p-2',
  61. leftGradient: {
  62. left: '-0.5rem',
  63. before: {
  64. // Currently mobile supports only dark mode
  65. background: {
  66. light: `linear-gradient(
  67. 270deg,
  68. rgba(255, 255, 255, 0),
  69. #282829)`,
  70. dark: `linear-gradient(
  71. 270deg,
  72. rgba(255, 255, 255, 0),
  73. #282829)`, // :TODO inject tailwind theme colors
  74. },
  75. },
  76. },
  77. rightGradient: {
  78. before: {
  79. // Currently mobile supports only dark mode
  80. background: {
  81. light: `linear-gradient(
  82. 90deg,
  83. rgba(255, 255, 255, 0),
  84. #282829)`,
  85. dark: `linear-gradient(
  86. 90deg,
  87. rgba(255, 255, 255, 0),
  88. #282829`, // :TODO inject tailwind theme colors
  89. },
  90. },
  91. },
  92. shadowGradient: {
  93. before: {
  94. top: 'calc(0px - 30px - 1.5rem)',
  95. height: 'calc(30px + 1.5rem)',
  96. },
  97. },
  98. button: {
  99. 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.
  100. active: 'bg-gray-300',
  101. },
  102. },
  103. input: {
  104. container: 'p-2',
  105. },
  106. })
  107. initializeFieldEditorProps({
  108. actionBar: {
  109. button: {
  110. icon: {
  111. size: 'small',
  112. },
  113. },
  114. },
  115. })
  116. initializeFileClasses({
  117. button: 'disabled:text-blue/60 text-blue p-2.5 w-full',
  118. listContainer: 'max-h-48 px-4 pt-4',
  119. })
  120. }