# Quantity Picker
URL: /react/components/quantity-picker
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/quantity-picker.mdx
A component used to increase or decrease quantity in integer units.
사용 가능 버전: @seed-design/react@2.1.0, @seed-design/css@2.3.0
## Preview
```tsx
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerPreview() {
return ;
}
```
## Installation
- npm: npx @seed-design/cli@latest add ui:quantity-picker
- pnpm: pnpm dlx @seed-design/cli@latest add ui:quantity-picker
- yarn: yarn dlx @seed-design/cli@latest add ui:quantity-picker
- bun: bun x @seed-design/cli@latest add ui:quantity-picker
## Props
## Examples
### Layout
사용 가능 버전: @seed-design/react@2.2.0, @seed-design/css@2.4.0
`layout="hug"` maintains the original width to fit the content. If the parent is a Flex layout and you need to fill the remaining space, use `layout="fill"`. In this case, the button sizes on both sides are maintained and only the Value Display area expands.
```tsx
import { HStack, Text, VStack } from "@seed-design/react";
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerLayout() {
return (
Hug (기본)
Fill
);
}
```
### Value Text
Using `getValueText`, you can add units or supplementary descriptions to the displayed quantity.
```tsx
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerValueText() {
return (
`${valueText}개`}
/>
);
}
```
### Controlled
You can control the quantity state externally using `value` and `onValueChange`.
```tsx
import { Text, VStack } from "@seed-design/react";
import { useState } from "react";
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerControlled() {
const [quantity, setQuantity] = useState(2);
return (
현재 수량: {quantity}개
);
}
```
### Removable
When you use `removable`, the Decrement button switches to a Remove button when the value reaches `min`. Handle the removal action in `onRemove`.
```tsx
import { Text, VStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerRemovable() {
const [removed, setRemoved] = useState(false);
if (removed) {
return (
상품을 삭제했습니다.
setRemoved(false)}>
되돌리기
);
}
return (
setRemoved(true)}
/>
최소 수량에서 Decrement 버튼이 Remove 버튼으로 전환됩니다.
);
}
```
### Loading
With `loading`, you can temporarily prevent all actions or specific actions and display a loading indicator.
```tsx
import { HStack, VStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerLoading() {
const [decrementLoading, setDecrementLoading] = useState(false);
const [incrementLoading, setIncrementLoading] = useState(false);
const allLoading = decrementLoading && incrementLoading;
function toggleAllLoading() {
const nextLoading = !allLoading;
setDecrementLoading(nextLoading);
setIncrementLoading(nextLoading);
}
return (
전체
setDecrementLoading((current) => !current)}
>
Decrement
setIncrementLoading((current) => !current)}
>
Increment
);
}
```
### Form
When you pass `name` to `inputProps`, the current quantity is submitted as a hidden input.
```tsx
import { VStack } from "@seed-design/react";
import type { FormEvent } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import { QuantityPicker } from "seed-design/ui/quantity-picker";
export default function QuantityPickerForm() {
function handleSubmit(event: FormEvent) {
event.preventDefault();
const formData = new FormData(event.currentTarget);
window.alert(`제출한 수량: ${formData.get("quantity")}개`);
}
return (
);
}
```
## Accessibility
Provide an `aria-label` or `aria-labelledby` to the Root that describes the purpose of Quantity Picker. If needed, you can change the accessibility name of each action contextually using `decrementAriaLabel`, `incrementAriaLabel`, and `removeAriaLabel`.
Using `getValueText`, you can provide the ValueDisplay number as human-readable text. This value does not affect the raw integer value submitted to the hidden input.