# Chip

## Introduction

The Chip component is a compact UI element used to represent inputs, attributes, and actions. It is commonly used for tags, filters, contacts, categories, and similar items. It can be used with text, icons, or avatars, and provides interactive behaviors such as clicking or deleting.

```tsx
<Chip {...args} />
```

| Field    | Description | Default   |
| -------- | ----------- | --------- |
| children | Chip 내용     | "Chip"    |
| color    | Chip 색상     | "primary" |
| variant  | Chip 스타일 변형 | "solid"   |
| size     | Chip 크기     | "md"      |
| disabled | 비활성화 상태     | —         |

## Usage

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

function MyComponent() {
  return (
    <div>
      <Chip>Basic Chip</Chip>
      <Chip clickable onClick={() => console.log('clicked')}>
        Clickable Chip
      </Chip>
      <Chip endDecorator={<CloseIcon />} onClick={() => console.log('delete')}>
        Deletable Chip
      </Chip>
    </div>
  );
}
```

## Examples

### Basic Usage

Basic Chip usage.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip>Basic Chip</Chip>
    <Chip disabled>Disabled</Chip>
    <Chip onClick={() => alert("Clicked!")}>Clickable</Chip>
  </div>
```

### Colors

You can apply various colors.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip color="primary">Primary</Chip>
    <Chip color="neutral">Neutral</Chip>
    <Chip color="danger">Danger</Chip>
    <Chip color="success">Success</Chip>
    <Chip color="warning">Warning</Chip>
  </div>
```

### Variants

Provides a variety of style variants.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip variant="solid">Solid</Chip>
    <Chip variant="soft">Soft</Chip>
    <Chip variant="outlined">Outlined</Chip>
    <Chip variant="plain">Plain</Chip>
  </div>
```

### Sizes

You can adjust the size.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      alignItems: "center",
      flexWrap: "wrap"
    }}
  >
    <Chip size="sm">Small</Chip>
    <Chip size="md">Medium</Chip>
    <Chip size="lg">Large</Chip>
  </div>
```

### With Icons

Can be used with icons.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip startDecorator={<Add />}>Add Item</Chip>
    <Chip endDecorator={<Close />}>Remove</Chip>
    <Chip startDecorator={<Done />} color="success">
      Completed
    </Chip>
  </div>
```

### With Avatar

Can be used with an avatar to represent a user.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip startDecorator={<Avatar size="sm" src="https://i.pravatar.cc/40?img=1" />}>John Doe</Chip>
    <Chip startDecorator={<Avatar size="sm" src="https://i.pravatar.cc/40?img=2" />}>
      Jane Smith
    </Chip>
  </div>
```

### Deletable

A Chip with delete functionality. Clicking it removes it from the list.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    {chips.map((chip) => (
      <Chip
        key={chip}
        endDecorator={<Close />}
        onClick={() => handleDelete(chip)}
        variant="outlined"
      >
        {chip}
      </Chip>
    ))}
  </div>
```

### Clickable

A clickable Chip that can be used as a filter or tab.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip onClick={() => alert("Filter: All")}>All</Chip>
    <Chip onClick={() => alert("Filter: Active")} color="success">
      Active
    </Chip>
    <Chip onClick={() => alert("Filter: Completed")} color="neutral">
      Completed
    </Chip>
  </div>
```

### Clickable Actions

Can trigger various actions when clicked.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <Chip onClick={() => window.open("#", "_blank")}>Home</Chip>
    <Chip onClick={() => window.open("#", "_blank")} variant="outlined">
      About
    </Chip>
    <Chip onClick={() => window.open("#", "_blank")} variant="soft">
      Contact
    </Chip>
  </div>
```

### States

Can represent various states.

```tsx
<div
    style={{
      display: "flex",
      gap: "1rem",
      flexWrap: "wrap"
    }}
  >
    <div>
      <h4>Normal</h4>
      <div
        style={{
          display: "flex",
          gap: "0.5rem",
          flexWrap: "wrap"
        }}
      >
        <Chip>Default</Chip>
        <Chip onClick={() => {}}>Clickable</Chip>
        <Chip endDecorator={<Close />}>Deletable</Chip>
      </div>
    </div>
    <div>
      <h4>Disabled</h4>
      <div
        style={{
          display: "flex",
          gap: "0.5rem",
          flexWrap: "wrap"
        }}
      >
        <Chip disabled>Default</Chip>
        <Chip disabled onClick={() => {}}>
          Clickable
        </Chip>
        <Chip disabled endDecorator={<Close />}>
          Deletable
        </Chip>
      </div>
    </div>
  </div>
```

## Common Use Cases

### Tags

```tsx
<div style={{ display: 'flex', gap: '0.5rem' }}>
  <Chip variant="outlined">React</Chip>
  <Chip variant="outlined">TypeScript</Chip>
  <Chip variant="outlined">JavaScript</Chip>
</div>
```

### Status Indicators

```tsx
<Chip color="success" startDecorator={<CheckIcon />}>
  Completed
</Chip>
<Chip color="warning" startDecorator={<ClockIcon />}>
  In Progress
</Chip>
```

### Filter Controls

```tsx
<Chip clickable variant={isActive ? 'solid' : 'outlined'} onClick={() => setFilter('all')}>
  All Items
</Chip>
```

### Contact Pills

```tsx
<Chip startDecorator={<Avatar size="sm" />} endDecorator={<CloseIcon />} onDelete={() => removeContact(id)}>
  John Doe
</Chip>
```

## Props and Customization

### Key Props

| Prop             | Type                                                           | Default     | Description                            |
| ---------------- | -------------------------------------------------------------- | ----------- | -------------------------------------- |
| `children`       | `ReactNode`                                                    | -           | Chip content (text, icons)             |
| `variant`        | `'solid' \| 'soft' \| 'outlined' \| 'plain'`                   | `'soft'`    | Visual style                           |
| `size`           | `'sm' \| 'md' \| 'lg'`                                         | `'md'`      | Chip size                              |
| `color`          | `'primary' \| 'neutral' \| 'danger' \| 'success' \| 'warning'` | `'neutral'` | Color scheme                           |
| `disabled`       | `boolean`                                                      | `false`     | Disables the chip                      |
| `onClick`        | `(event: MouseEvent) => void`                                  | -           | Click handler (makes chip interactive) |
| `startDecorator` | `ReactNode`                                                    | -           | Content before the chip text           |
| `endDecorator`   | `ReactNode`                                                    | -           | Content after the chip text            |
| `sx`             | `SxProps`                                                      | -           | Custom styles using the MUI system     |

> **Note**: Chip also accepts all Joy UI Chip props and Framer Motion props.

## Best Practices

1. **Use appropriate sizes**: Choose sizes that fit the content. Keep text concise.

2. **Be consistent**: Use the same variant and color within the same context.

3. **Clear actions**: When using clickable or deletable behavior, provide clear feedback to the user.

4. **Accessibility**: Support keyboard navigation and provide appropriate labels for screen readers.

5. **Appropriate spacing**: Use proper spacing when listing multiple Chips to improve readability.

6. **Semantic color usage**: Use colors with clear meaning, such as green for success and orange for warnings.
