addLink.ts 825 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormKitNode } from '@formkit/core'
  3. import { useAppName } from '#shared/composables/useAppName.ts'
  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