addAbsoluteFloatingLabel.ts 1.5 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. * Creates classes for a floating input label. Here we don't have a problem, where
  6. * we might need to display several rows of information on the screen, so we can use "absolute".
  7. */
  8. export const addAbsoluteFloatingLabel = (classes: Classes = {}) => {
  9. const {
  10. input = '',
  11. label = '',
  12. outer = '',
  13. wrapper = '',
  14. arrow = '',
  15. } = classes
  16. return {
  17. outer: clean(
  18. `${outer}
  19. absolute-floating-input
  20. relative flex-col flex px-2
  21. formkit-invalid:bg-red-dark
  22. formkit-errors:bg-red-dark
  23. `,
  24. ),
  25. wrapper: `${wrapper} relative flex-1`,
  26. inner: 'flex ltr:pr-2 rtl:pl-2',
  27. block: 'flex',
  28. input: clean(`
  29. ${input}
  30. w-full
  31. h-14
  32. text-sm
  33. bg-transparent
  34. border-none
  35. focus:outline-none
  36. placeholder:text-transparent
  37. focus-within:pt-8
  38. formkit-populated:pt-8
  39. `),
  40. label: clean(`
  41. ${label}
  42. absolute top-0 ltr:left-0 rtl:right-0
  43. py-4 px-2 h-14
  44. text-base
  45. transition-all duration-100 ease-in-out origin-left
  46. pointer-events-none
  47. formkit-populated:-translate-y-3 formkit-populated:translate-x-6
  48. formkit-populated:scale-75 formkit-populated:opacity-75
  49. formkit-required:required
  50. formkit-invalid:text-red-bright
  51. `),
  52. arrow: `${arrow} formkit-arrow flex items-center`,
  53. messages: 'px-2',
  54. }
  55. }