# Divider

## Introduction

The Divider component draws a line that visually separates content. It is based on Joy UI's Divider component and adds Framer Motion animation support. You can use it to separate list items, card sections, form areas, and more to improve content readability.

```tsx
<Box
    sx={{
      width: 300,
      height: 200,
      p: 3
    }}
  >
    <Typography level="body-md">위 콘텐츠</Typography>
    <Divider
      {...args}
      sx={{
        my: 2
      }}
    />
    <Typography level="body-md">아래 콘텐츠</Typography>
  </Box>
```

| Field       | Description | Default      |
| ----------- | ----------- | ------------ |
| orientation | 구분선의 방향     | "horizontal" |
| inset       | 구분선의 들여쓰기   | —            |
| color       | 구분선의 색상     | —            |

## Usage

```tsx
import { Divider } from '@ceed/cds';

function MyComponent() {
  return (
    <div>
      <p>첫 번째 콘텐츠</p>
      <Divider />
      <p>두 번째 콘텐츠</p>
    </div>
  );
}
```

## Examples

### Basic Usage

The most basic way to use Divider.

```tsx
<Stack spacing={3}>
    <Box>
      <Typography
        level="title-md"
        sx={{
          mb: 2
        }}
      >
        기본 수평 구분선
      </Typography>
      <Typography level="body-sm">첫 번째 콘텐츠</Typography>
      <Divider
        sx={{
          my: 1
        }}
      />
      <Typography level="body-sm">두 번째 콘텐츠</Typography>
    </Box>

    <Box
      sx={{
        display: "flex",
        alignItems: "center",
        height: 60
      }}
    >
      <Typography
        level="title-md"
        sx={{
          mr: 2
        }}
      >
        수직 구분선
      </Typography>
      <Divider orientation="vertical" />
      <Typography
        level="title-md"
        sx={{
          ml: 2
        }}
      >
        다른 섹션
      </Typography>
    </Box>
  </Stack>
```

### Orientations

You can set the direction of the divider.

```tsx
<Stack spacing={4}>
    <Box>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        Horizontal (기본)
      </Typography>
      <Typography level="body-sm">첫 번째 섹션</Typography>
      <Divider
        orientation="horizontal"
        sx={{
          my: 1
        }}
      />
      <Typography level="body-sm">두 번째 섹션</Typography>
    </Box>

    <Box
      sx={{
        display: "flex",
        alignItems: "center",
        height: 80
      }}
    >
      <Typography
        level="title-sm"
        sx={{
          mr: 2
        }}
      >
        Vertical
      </Typography>
      <Divider
        orientation="vertical"
        sx={{
          mx: 2
        }}
      />
      <Typography level="title-sm">수직 구분선은 요소들을 좌우로 구분합니다</Typography>
    </Box>
  </Stack>
```

### Colors

You can apply various colors.

```tsx
<Stack spacing={3}>
    {["primary", "neutral", "danger", "success", "warning"].map((color) => (
      <Box key={color}>
        <Typography
          level="title-sm"
          sx={{
            mb: 1,
            textTransform: "capitalize"
          }}
        >
          {color}
        </Typography>
        <Typography level="body-sm">위 콘텐츠</Typography>
        <Divider
          color={color as any}
          sx={{
            my: 1
          }}
        />
        <Typography level="body-sm">아래 콘텐츠</Typography>
      </Box>
    ))}
  </Stack>
```

### With Text

You can place text in the center of the divider.

```tsx
<Stack spacing={3}>
    <Box>
      <Typography level="body-md">로그인 정보</Typography>
      <Divider
        sx={{
          my: 2
        }}
      >
        또는
      </Divider>
      <Typography level="body-md">소셜 로그인</Typography>
    </Box>

    <Box>
      <Typography level="body-md">개인 정보</Typography>
      <Divider
        sx={{
          my: 2,
          "&::before, &::after": {
            border: "1px solid",
            borderColor: "primary.500"
          }
        }}
      >
        <Typography level="title-sm" color="primary">
          추가 정보
        </Typography>
      </Divider>
      <Typography level="body-md">추가 세부사항</Typography>
    </Box>
  </Stack>
```

### In Cards

You can use it to separate sections inside cards or panels.

```tsx
<Stack direction="row" spacing={3}>
    <Sheet
      variant="outlined"
      sx={{
        p: 3,
        minWidth: 250,
        borderRadius: "md"
      }}
    >
      <Typography
        level="title-lg"
        sx={{
          mb: 2
        }}
      >
        사용자 정보
      </Typography>
      <Typography
        level="body-sm"
        sx={{
          mb: 1
        }}
      >
        이름: 김철수
      </Typography>
      <Typography
        level="body-sm"
        sx={{
          mb: 2
        }}
      >
        이메일: kim@example.com
      </Typography>

      <Divider
        sx={{
          my: 2
        }}
      />

      <Typography
        level="title-md"
        sx={{
          mb: 2
        }}
      >
        통계
      </Typography>
      <Typography
        level="body-sm"
        sx={{
          mb: 1
        }}
      >
        가입일: 2024.01.15
      </Typography>
      <Typography level="body-sm">활동 점수: 1,234</Typography>
    </Sheet>

    <Sheet
      variant="outlined"
      sx={{
        p: 3,
        minWidth: 250,
        borderRadius: "md"
      }}
    >
      <Typography
        level="title-lg"
        sx={{
          mb: 2
        }}
      >
        프로젝트 현황
      </Typography>

      <Box
        sx={{
          display: "flex",
          justifyContent: "space-between",
          mb: 1
        }}
      >
        <Typography level="body-sm">완료</Typography>
        <Typography level="body-sm" color="success">
          12
        </Typography>
      </Box>

      <Divider
        color="neutral"
        sx={{
          my: 1,
          opacity: 0.3
        }}
      />

      <Box
        sx={{
          display: "flex",
          justifyContent: "space-between",
          mb: 1
        }}
      >
        <Typography level="body-sm">진행중</Typography>
        <Typography level="body-sm" color="warning">
          5
        </Typography>
      </Box>

      <Divider
        color="neutral"
        sx={{
          my: 1,
          opacity: 0.3
        }}
      />

      <Box
        sx={{
          display: "flex",
          justifyContent: "space-between"
        }}
      >
        <Typography level="body-sm">대기</Typography>
        <Typography level="body-sm" color="neutral">
          3
        </Typography>
      </Box>
    </Sheet>
  </Stack>
```

### List Separators

You can use it as a separator between list items.

```tsx
<Sheet
    variant="outlined"
    sx={{
      maxWidth: 400,
      borderRadius: "md"
    }}
  >
    <Stack>
      <Box
        sx={{
          p: 2
        }}
      >
        <Typography level="body-md">첫 번째 항목</Typography>
        <Typography level="body-xs" color="neutral">
          첫 번째 항목에 대한 설명입니다.
        </Typography>
      </Box>

      <Divider />

      <Box
        sx={{
          p: 2
        }}
      >
        <Typography level="body-md">두 번째 항목</Typography>
        <Typography level="body-xs" color="neutral">
          두 번째 항목에 대한 설명입니다.
        </Typography>
      </Box>

      <Divider />

      <Box
        sx={{
          p: 2
        }}
      >
        <Typography level="body-md">세 번째 항목</Typography>
        <Typography level="body-xs" color="neutral">
          세 번째 항목에 대한 설명입니다.
        </Typography>
      </Box>
    </Stack>
  </Sheet>
```

### Responsive Orientation

You can change the orientation based on screen size.

```tsx
<Stack spacing={3}>
    <Typography level="title-md">화면 크기에 따라 방향이 바뀌는 구분선</Typography>

    <Box
      sx={{
        display: "flex",
        flexDirection: {
          xs: "column",
          sm: "row"
        },
        alignItems: "center",
        gap: 2,
        p: 3,
        bgcolor: "background.level1",
        borderRadius: "md"
      }}
    >
      <Typography
        level="body-md"
        sx={{
          textAlign: "center"
        }}
      >
        첫 번째 섹션
      </Typography>

      <Divider
        orientation={
          {
            xs: "horizontal",
            sm: "vertical"
          } as any
        }
        sx={{
          width: {
            xs: "100%",
            sm: "auto"
          },
          height: {
            xs: "auto",
            sm: 40
          }
        }}
      />

      <Typography
        level="body-md"
        sx={{
          textAlign: "center"
        }}
      >
        두 번째 섹션
      </Typography>
    </Box>

    <Typography level="body-xs" color="neutral">
      * 화면 크기를 조절하여 구분선 방향 변화를 확인하세요
    </Typography>
  </Stack>
```

### With Motion

You can apply Framer Motion animations.

```tsx
<Stack spacing={3}>
    <Typography level="title-md">Framer Motion 애니메이션이 적용된 구분선</Typography>

    <Box
      sx={{
        p: 3,
        bgcolor: "background.level1",
        borderRadius: "md"
      }}
    >
      <Typography
        level="body-md"
        sx={{
          mb: 2
        }}
      >
        위 콘텐츠
      </Typography>

      <Divider
        initial={{
          scaleX: 0
        }}
        animate={{
          scaleX: 1
        }}
        transition={{
          duration: 1,
          ease: "easeOut"
        }}
        sx={{
          my: 2,
          transformOrigin: "left"
        }}
      />

      <Typography level="body-md">아래 콘텐츠 (구분선이 애니메이션과 함께 나타남)</Typography>
    </Box>

    <Box
      sx={{
        display: "flex",
        alignItems: "center",
        p: 3,
        bgcolor: "background.level1",
        borderRadius: "md"
      }}
    >
      <Typography
        level="body-md"
        sx={{
          mr: 3
        }}
      >
        좌측 콘텐츠
      </Typography>

      <Divider
        orientation="vertical"
        initial={{
          scaleY: 0
        }}
        animate={{
          scaleY: 1
        }}
        transition={{
          duration: 1,
          delay: 0.5
        }}
        sx={{
          mx: 2,
          height: 40,
          transformOrigin: "top"
        }}
      />

      <Typography
        level="body-md"
        sx={{
          ml: 3
        }}
      >
        우측 콘텐츠
      </Typography>
    </Box>
  </Stack>
```

### Custom Styling

You can customize the divider with CSS styles.

```tsx
<Stack spacing={4}>
    <Box>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        둥근 모서리 구분선
      </Typography>
      <Typography level="body-sm">위 콘텐츠</Typography>
      <Divider
        sx={{
          my: 2,
          borderWidth: 3,
          borderRadius: "6px",
          borderColor: "primary.500"
        }}
      />
      <Typography level="body-sm">아래 콘텐츠</Typography>
    </Box>

    <Box>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        그라데이션 구분선 (Box 사용)
      </Typography>
      <Typography level="body-sm">위 콘텐츠</Typography>
      <Box
        sx={{
          height: 2,
          my: 2,
          background: "linear-gradient(90deg, transparent, #0073e6, transparent)",
          borderRadius: "1px"
        }}
      />
      <Typography level="body-sm">아래 콘텐츠</Typography>
    </Box>

    <Box>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        패턴 구분선 (Box 사용)
      </Typography>
      <Typography level="body-sm">위 콘텐츠</Typography>
      <Box
        sx={{
          height: 3,
          my: 2,
          background: `repeating-linear-gradient(
              90deg,
              #0073e6 0px,
              #0073e6 10px,
              transparent 10px,
              transparent 20px
            )`,
          borderRadius: "1px"
        }}
      />
      <Typography level="body-sm">아래 콘텐츠</Typography>
    </Box>

    <Box>
      <Typography
        level="title-sm"
        sx={{
          mb: 2
        }}
      >
        그림자 효과
      </Typography>
      <Typography level="body-sm">위 콘텐츠</Typography>
      <Divider
        sx={{
          my: 2,
          borderColor: "neutral.500",
          filter: "drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.2))"
        }}
      />
      <Typography level="body-sm">아래 콘텐츠</Typography>
    </Box>
  </Stack>
```

## Key Props

### orientation

Sets the divider orientation.

```tsx
<Divider orientation="horizontal" /> {/* default */}
<Divider orientation="vertical" />

{/* responsive orientation */}
<Divider orientation={{ xs: 'horizontal', sm: 'vertical' }} />
```

### variant

Sets the divider style.

```tsx
<Divider variant="solid" />    {/* default - solid line */}
<Divider variant="plain" />    {/* plain style */}
<Divider variant="soft" />     {/* soft style */}
```

### color

Sets the divider color.

```tsx
<Divider color="neutral" />    {/* default */}
<Divider color="primary" />
<Divider color="danger" />
<Divider color="success" />
<Divider color="warning" />
```

## Common Use Cases

### Navigation Sections

```tsx
<nav>
  <Link href="/home">Home</Link>
  <Link href="/about">About</Link>

  <Divider sx={{ my: 1 }} />

  <Link href="/login">Login</Link>
  <Link href="/signup">Sign Up</Link>
</nav>
```

### Form Sections

```tsx
<form>
  <Stack spacing={2}>
    <Typography level="title-md">개인 정보</Typography>
    <FormControl>
      <FormLabel>이름</FormLabel>
      <Input />
    </FormControl>
    <FormControl>
      <FormLabel>이메일</FormLabel>
      <Input type="email" />
    </FormControl>

    <Divider sx={{ my: 3 }}>추가 정보</Divider>

    <FormControl>
      <FormLabel>회사명</FormLabel>
      <Input />
    </FormControl>
  </Stack>
</form>
```

### Card Content Separation

```tsx
<Card>
  <CardContent>
    <Typography level="title-lg">제품명</Typography>
    <Typography level="body-md">제품 설명...</Typography>

    <Divider sx={{ my: 2 }} />

    <Stack direction="row" justifyContent="space-between">
      <Typography level="title-lg" color="primary">
        ₩99,000
      </Typography>
      <Button>장바구니</Button>
    </Stack>
  </CardContent>
</Card>
```

### List Items

```tsx
<Stack>
  {items.map((item, index) => (
    <React.Fragment key={item.id}>
      <Box sx={{ p: 2 }}>
        <Typography level="title-sm">{item.title}</Typography>
        <Typography level="body-sm">{item.description}</Typography>
      </Box>
      {index < items.length - 1 && <Divider />}
    </React.Fragment>
  ))}
</Stack>
```

### Dashboard Sections

```tsx
<Sheet variant="outlined" sx={{ p: 3 }}>
  <Typography level="title-lg">대시보드</Typography>

  <Divider sx={{ my: 2 }} />

  <Grid container spacing={2}>
    <Grid item xs={12} sm={6}>
      <StatCard title="사용자" value="1,234" />
    </Grid>
    <Grid item xs={12} sm={6}>
      <StatCard title="매출" value="₩5.6M" />
    </Grid>
  </Grid>

  <Divider sx={{ my: 2 }} />

  <Typography level="title-md">최근 활동</Typography>
  {/* activity list */}
</Sheet>
```

### Modal Content

```tsx
<Modal open={open}>
  <Sheet variant="outlined" sx={{ p: 4, borderRadius: 'md' }}>
    <Typography level="title-lg">설정</Typography>

    <Divider sx={{ my: 2 }} />

    <Stack spacing={2}>
      <FormControl>
        <FormLabel>알림 설정</FormLabel>
        <Switch />
      </FormControl>

      <FormControl>
        <FormLabel>테마 설정</FormLabel>
        <Select defaultValue="light">
          <Option value="light">Light</Option>
          <Option value="dark">Dark</Option>
        </Select>
      </FormControl>
    </Stack>

    <Divider sx={{ my: 3 }} />

    <Stack direction="row" spacing={2} justifyContent="flex-end">
      <Button variant="outlined" onClick={handleClose}>
        취소
      </Button>
      <Button onClick={handleSave}>저장</Button>
    </Stack>
  </Sheet>
</Modal>
```

## Props and Customization

### Key Props

| Prop          | Type                         | Default        | Description                                            |
| ------------- | ---------------------------- | -------------- | ------------------------------------------------------ |
| `children`    | `ReactNode`                  | -              | Optional content rendered in the center of the divider |
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Divider direction                                      |
| `component`   | `ElementType`                | `'hr'`         | Root element type                                      |
| `sx`          | `SxProps`                    | -              | Custom styles                                          |

> **Note**: Divider also accepts all Joy UI Divider props.

## Best Practices

1. **Use appropriate spacing**: Leave enough space above and below the divider so content is clearly separated.

2. **Separate content meaningfully**: Group logically related content together and use dividers to split sections.

3. **Avoid overuse**: Too many dividers can make the interface feel cluttered.

4. **Using vertical dividers**: When using a vertical divider, explicitly define the height of the parent container.

5. **Consider responsive behavior**: On mobile, a vertical divider may need to switch to horizontal.

6. **Keep colors consistent**: Use consistent divider colors and styles throughout the project.

7. **Consider accessibility**:
   - Dividers are purely visual separators, so screen readers typically ignore them
   - If a semantic separation is needed, use appropriate HTML sectioning elements as well

## Responsive Behavior

Divider supports responsive values for all props:

```tsx
<Divider
  orientation={{ xs: 'horizontal', md: 'vertical' }}
  sx={{
    width: { xs: '100%', md: 'auto' },
    height: { xs: 'auto', md: 50 },
    my: { xs: 2, md: 0 },
    mx: { xs: 0, md: 2 },
  }}
/>
```

## Motion Support

Divider supports Framer Motion:

```tsx
<Divider
  initial={{ scaleX: 0 }}
  animate={{ scaleX: 1 }}
  transition={{ duration: 0.5 }}
  sx={{ transformOrigin: 'left' }}
/>

<Divider
  orientation="vertical"
  initial={{ scaleY: 0 }}
  animate={{ scaleY: 1 }}
  whileHover={{ scaleY: 1.1 }}
  transition={{ duration: 0.3 }}
/>
```

## When to Use Divider

### ✅ Good Use Cases

- **Separate list items**: When you need to clearly divide items in a long list
- **Separate form sections**: When grouping related fields into sections
- **Separate content inside cards**: When distinguishing different kinds of information within a card
- **Navigation menus**: When visually separating menu groups
- **Dashboard sections**: When dividing widgets or sections in a dashboard

### ❌ Cases Where It May Not Be Appropriate

- **When simple spacing is enough**: Avoid using dividers excessively
- **When other separators already exist**: If content is already separated by color, background, borders, or similar cues, a divider may be unnecessary
- **For very short content**: A divider can feel excessive for content that is only one or two lines long

Divider is a useful tool for clarifying content structure and improving readability. When used appropriately, it helps create interfaces that make information easier to understand.
