stack.tsx 756 B

12345678910111213141516171819202122
  1. 'use client';
  2. import { type ComponentRenderProps } from '@json-render/react';
  3. export function Stack({ element, children }: ComponentRenderProps) {
  4. const { direction, gap, align } = element.props as { direction?: string | null; gap?: string | null; align?: string | null };
  5. const gaps: Record<string, string> = { none: '0', sm: '8px', md: '16px', lg: '24px' };
  6. const alignments: Record<string, string> = { start: 'flex-start', center: 'center', end: 'flex-end', stretch: 'stretch' };
  7. return (
  8. <div
  9. style={{
  10. display: 'flex',
  11. flexDirection: direction === 'horizontal' ? 'row' : 'column',
  12. gap: gaps[gap || 'md'],
  13. alignItems: alignments[align || 'stretch'],
  14. }}
  15. >
  16. {children}
  17. </div>
  18. );
  19. }