FormSection.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Children } from 'react'
  2. import { cn } from 'ui'
  3. export const FormSection = ({
  4. children,
  5. id,
  6. header,
  7. disabled,
  8. className,
  9. }: {
  10. children: React.ReactNode
  11. id?: string
  12. header?: React.ReactNode
  13. disabled?: boolean
  14. visible?: boolean
  15. className?: string
  16. }) => {
  17. const classes = [
  18. 'grid grid-cols-12 gap-6 px-card py-4 md:py-8',
  19. `${disabled ? ' opacity-30' : ' opacity-100'}`,
  20. `${className}`,
  21. ]
  22. return (
  23. <div id={id} className={classes.join(' ')}>
  24. {header}
  25. {children}
  26. </div>
  27. )
  28. }
  29. export const FormSectionLabel = ({
  30. children,
  31. className = '',
  32. description,
  33. }: {
  34. children: React.ReactNode | string
  35. className?: string
  36. description?: React.ReactNode
  37. }) => {
  38. if (description !== undefined) {
  39. return (
  40. <div className={cn('flex flex-col space-y-2 col-span-12 lg:col-span-5', className)}>
  41. <label className="text-foreground text-sm">{children}</label>
  42. {description}
  43. </div>
  44. )
  45. } else {
  46. return (
  47. <label className={`text-foreground col-span-12 text-sm lg:col-span-5 ${className}`}>
  48. {children}
  49. </label>
  50. )
  51. }
  52. }
  53. const Shimmer = () => (
  54. <div className="flex w-full flex-col gap-2">
  55. <div className="shimmering-loader h-2 w-1/3 rounded-sm"></div>
  56. <div className="flex flex-col justify-between space-y-2">
  57. <div className="shimmering-loader h-[34px] w-2/3 rounded-sm" />
  58. </div>
  59. </div>
  60. )
  61. export const FormSectionContent = ({
  62. children,
  63. loading = true,
  64. loaders,
  65. fullWidth,
  66. className,
  67. }: {
  68. children: React.ReactNode | string
  69. loading?: boolean
  70. loaders?: number
  71. fullWidth?: boolean
  72. className?: string
  73. }) => {
  74. return (
  75. <div
  76. className={`
  77. relative col-span-12 flex flex-col gap-6 @lg:col-span-7
  78. ${fullWidth && 'col-span-12!'}
  79. ${className}
  80. `}
  81. >
  82. {loading
  83. ? !!loaders
  84. ? new Array(loaders).fill(0).map((_, idx) => <Shimmer key={idx} />)
  85. : Children.map(children, (_, idx) => <Shimmer key={idx} />)
  86. : children}
  87. </div>
  88. )
  89. }