addFloatingTextareaLabel.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { Classes } from '#shared/form/plugins/utils.ts'
  3. import { clean, extendClasses } from '#shared/form/plugins/utils.ts'
  4. /**
  5. * Textarea can be scrolled, so if we use "aboslute" positioning for label,
  6. * it will overlap with textarea content. But we still can't use regular solution,
  7. * becase the label text should be on the same row with the textarea, so we have a trick,
  8. * where we use "h-2", so it overlaps with the content, until the textarea is populated.
  9. */
  10. export const addFloatingTextareaLabel = (classes: Classes = {}) => {
  11. return extendClasses(classes, {
  12. outer: clean(`
  13. floating-textarea relative px-2
  14. `),
  15. wrapper: 'relative',
  16. // text-base ensures there is no zoom when you click on the input on iOS
  17. input: clean(`
  18. w-full
  19. border-none
  20. bg-transparent
  21. text-base
  22. placeholder:text-transparent
  23. focus:outline-none
  24. `),
  25. label: clean(`
  26. formkit-populated:translate-y-0
  27. formkit-populated:text-xs
  28. formkit-populated:opacity-75
  29. flex
  30. h-2
  31. origin-left
  32. translate-y-4
  33. cursor-text
  34. items-end px-2 pt-5 text-base
  35. transition-all duration-100 ease-in-out
  36. `),
  37. })
  38. }