addFloatingTextareaLabel.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import type { Classes } from './utils'
  3. import { clean } from './utils'
  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. const {
  12. input = '',
  13. label = '',
  14. inner = '',
  15. outer = '',
  16. wrapper = '',
  17. } = classes
  18. return {
  19. outer: clean(`
  20. ${outer}
  21. floating-textarea relative px-2
  22. formkit-invalid:bg-red-dark
  23. formkit-errors:bg-red-dark
  24. `),
  25. wrapper: `${wrapper} relative`,
  26. inner,
  27. input: clean(`
  28. ${input}
  29. w-full
  30. text-sm
  31. bg-transparent
  32. border-none
  33. focus:outline-none
  34. placeholder:text-transparent
  35. min-h-[100px]
  36. `),
  37. label: clean(`
  38. ${label}
  39. flex
  40. items-end
  41. px-2
  42. pt-5
  43. h-2
  44. translate-y-4
  45. text-base
  46. cursor-text
  47. transition-all duration-100 ease-in-out origin-left
  48. formkit-populated:translate-y-0
  49. formkit-populated:text-xs formkit-populated:opacity-75
  50. formkit-required:required
  51. formkit-invalid:text-red-bright
  52. `),
  53. messages: 'px-2',
  54. }
  55. }