addLink.ts 826 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useAppName } from '#shared/composables/useAppName.ts'
  3. import type { FormKitNode } from '@formkit/core'
  4. const addLink = (node: FormKitNode) => {
  5. const { props } = node
  6. node.addProps(['link', 'linkIcon'])
  7. // The padding below is specific to mobile field layout only.
  8. if (useAppName() !== 'mobile') return
  9. const toggleLink = (isLink: boolean) => {
  10. if (isLink) {
  11. props.inputClass = `${props.inputClass || ''} ltr:pr-2 rtl:pl-2`
  12. } else if (props.inputClass) {
  13. props.inputClass = props.inputClass.replace('ltr:pr-2 rtl:pl-2', '')
  14. }
  15. }
  16. node.on('created', () => {
  17. toggleLink(!!props.link)
  18. node.on('prop:link', ({ payload }) => {
  19. toggleLink(!!payload)
  20. })
  21. })
  22. }
  23. export default addLink