index.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 { getCoreDesktopClasses } from './theme/global/getCoreDesktopClasses.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 desktopFormFieldModules: 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: getCoreDesktopClasses,
  33. extensions: themeExtensionModules,
  34. }
  35. const decoratorIcons = {
  36. checkboxDecorator:
  37. '<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" class="w-3 h-3 fill-current"><path d="M10.9696 4.96967C11.2625 4.67678 11.7374 4.67678 12.0303 4.96967C12.3196 5.25897 12.3231 5.72582 12.0409 6.01947L8.04873 11.0097C8.04297 11.0169 8.03682 11.0238 8.03029 11.0303C7.7374 11.3232 7.26253 11.3232 6.96963 11.0303L4.32319 8.38388C4.03029 8.09099 4.03029 7.61612 4.32319 7.32322C4.61608 7.03033 5.09095 7.03033 5.38385 7.32322L7.47737 9.41674L10.9497 4.9921C10.9559 4.98424 10.9626 4.97674 10.9696 4.96967Z" /></svg>',
  38. }
  39. mainInitializeForm(
  40. app,
  41. undefined,
  42. desktopFormFieldModules,
  43. plugins,
  44. theme,
  45. decoratorIcons,
  46. )
  47. }
  48. export const initializeFormFields = () => {
  49. initializeFormClasses({
  50. loading: 'my-9 fill-yellow-300',
  51. })
  52. initializeFieldLinkClasses({
  53. container: 'formkit-link',
  54. base: 'ms-3 mb-2.5',
  55. link: 'hover:rounded-sm hover:outline hover:outline-1 hover:outline-offset-1 hover:outline-blue-600 dark:hover:outline-blue-900',
  56. })
  57. initializeFormGroupClasses({
  58. container: 'form-group grid grid-cols-2 gap-y-2.5 gap-x-3',
  59. help: 'text-xs',
  60. dirtyMark: 'form-group-mark-dirty',
  61. bottomMargin: 'mb-4 last:mb-0',
  62. })
  63. initializeToggleClasses({
  64. track:
  65. 'bg-stone-200 dark:bg-gray-500 ring-1 ring-neutral-100 dark:ring-gray-900 hover:outline hover:outline-1 hover:outline-offset-2 hover:outline-blue-600 dark:hover:outline-blue-900 focus:outline focus:outline-1 focus:outline-offset-2 focus:outline-blue-800 hover:focus:outline-blue-800 dark:hover:focus:outline-blue-800 formkit-invalid:outline formkit-invalid:outline-1 formkit-invalid:outline-offset-2 formkit-invalid:outline-red-500 dark:hover:formkit-invalid:outline-red-500 formkit-errors:outline formkit-errors:outline-1 formkit-errors:outline-offset-2 formkit-errors:outline-red-500 dark:hover:formkit-errors:outline-red-500',
  66. trackOn: '!bg-blue-800',
  67. knob: 'bg-white',
  68. })
  69. initializeFieldEditorClasses({
  70. actionBar: {
  71. buttonContainer:
  72. 'gap-1.5 px-2.5 py-2 focus:outline focus:outline-1 focus:outline-offset-2 rounded-md focus:outline-blue-800',
  73. tableMenuContainer:
  74. 'gap-1.5 px-1.5 py-1.5 focus:outline focus:outline-1 focus:outline-offset-2 rounded-md focus:outline-blue-800',
  75. leftGradient: {
  76. left: '0',
  77. before: {
  78. background: {
  79. light: `linear-gradient(
  80. 270deg,
  81. rgba(0, 0, 0, 0),
  82. #EDF1F2)`,
  83. dark: `linear-gradient(
  84. 270deg,
  85. rgba(255, 255, 255, 0),
  86. #262627`, // :TODO inject tailwind theme colors
  87. },
  88. },
  89. },
  90. rightGradient: {
  91. before: {
  92. background: {
  93. light: `linear-gradient(
  94. 90deg,
  95. rgba(0, 0, 0, 0),
  96. #EDF1F2)`,
  97. dark: `linear-gradient(
  98. 90deg,
  99. rgba(255, 255, 255, 0),
  100. #262627`, // :TODO inject tailwind theme colors
  101. },
  102. },
  103. },
  104. shadowGradient: {
  105. before: {
  106. top: 'calc(0px - 20px - 1.5rem)',
  107. height: 'calc(28px + 1rem)',
  108. },
  109. },
  110. button: {
  111. base: 'bg-green-200 focus:outline focus:outline-1 focus:outline-offset-2 focus:outline-blue-800 transition-color hover:bg-green-300 dark:hover:bg-neutral-950 text-gray-300 dark:bg-gray-600 dark:text-neutral-400 rounded-lg p-1.5',
  112. active: 'bg-green-300 dark:bg-neutral-950', // :TODO adapt if gets adapted in figma
  113. },
  114. },
  115. input: {
  116. container: 'px-2.5 py-2',
  117. },
  118. })
  119. initializeFieldEditorProps({
  120. actionBar: {
  121. visible: true, // show action bar always
  122. button: {
  123. icon: {
  124. size: 'tiny',
  125. },
  126. },
  127. },
  128. })
  129. initializeFileClasses({
  130. button: 'disabled:opacity-60',
  131. divider: 'bg-neutral-100 dark:bg-gray-900',
  132. listContainer: 'max-h-96',
  133. dropZoneContainer: 'bg-blue-200 dark:bg-gray-700',
  134. dropZoneBorder: 'border-blue-800',
  135. })
  136. }