addBlockFloatingLabel.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import type { Classes } from './utils.ts'
  3. import { clean } from './utils.ts'
  4. /**
  5. * We cannot use absolute positioning for the floating label, because we might need to display
  6. * several rows of information on the screen - so content can depend on the actual label size and not
  7. * overlap.
  8. */
  9. export const addBlockFloatingLabel = (classes: Classes = {}): Classes => {
  10. const {
  11. input = '',
  12. label = '',
  13. outer = '',
  14. wrapper = '',
  15. arrow = '',
  16. } = classes
  17. return {
  18. outer: clean(`
  19. ${outer}
  20. floating-input relative flex flex-col px-2
  21. formkit-invalid:bg-red-dark
  22. formkit-errors:bg-red-dark
  23. focus-within:bg-blue-highlight
  24. `),
  25. wrapper: `${wrapper} relative py-1 flex-1 flex self-start justify-center flex-col`,
  26. inner: 'flex ltr:pr-2 rtl:pl-2 pb-1 relative',
  27. block: 'flex min-h-[3.5rem] cursor-pointer formkit-disabled:cursor-default',
  28. // text-base ensures there is no zoom when you click on the input on iOS
  29. input: clean(`
  30. ${input}
  31. w-full
  32. ltr:pl-2 rtl:pr-2
  33. text-base
  34. bg-transparent
  35. border-none
  36. focus:outline-none
  37. placeholder:text-transparent
  38. pt-6
  39. formkit-label-hidden:pt-4
  40. `),
  41. label: clean(`
  42. ${label}
  43. absolute top-0 ltr:left-0 rtl:right-0
  44. py-4 px-2 h-14
  45. text-base
  46. transition-all duration-100 ease-in-out origin-left
  47. pointer-events-none
  48. formkit-populated:-translate-y-[0.4rem]
  49. formkit-populated:scale-80 formkit-populated:opacity-75
  50. formkit-required:required
  51. formkit-invalid:text-red-bright
  52. `),
  53. arrow: `${arrow} formkit-arrow flex items-center formkit-disabled:opacity-30`,
  54. messages: 'px-2',
  55. suffixIcon: 'text-white fill-current flex justify-center items-center',
  56. }
  57. }