@tide-design/components 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Input/Input.d.ts +8 -4
- package/dist/Input/Input.js +2 -2
- package/dist/NumberFormatInput/NumberFormatInput.d.ts +35 -0
- package/dist/NumberFormatInput/NumberFormatInput.js +70 -0
- package/dist/NumberFormatInput/components/MaskModeInput.js +22 -0
- package/dist/NumberFormatInput/components/NumericModeInput.js +16 -0
- package/dist/NumberFormatInput/hooks/useNumberCompositionGuard.js +21 -0
- package/dist/NumberFormatInput/index.d.ts +3 -0
- package/dist/NumberFormatInput/libs/formatNumber.d.ts +6 -0
- package/dist/NumberFormatInput/libs/formatNumber.js +17 -0
- package/dist/NumberFormatInput/libs/maskFormat.js +39 -0
- package/dist/NumberFormatInput/libs/numericFormat.js +47 -0
- package/dist/NumberFormatInput/types.d.ts +39 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -1
- package/package.json +4 -3
package/dist/Input/Input.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { InputSize } from "../_internal/constants/inputClass.js";
|
|
2
|
-
import { ComponentProps, ReactElement } from "react";
|
|
2
|
+
import { ComponentProps, HTMLInputTypeAttribute, ReactElement } from "react";
|
|
3
|
+
type NamedInputType<T = HTMLInputTypeAttribute> = T extends unknown ? string extends T ? never : T : never;
|
|
3
4
|
export interface InputOwnProps {
|
|
5
|
+
/** 네이티브 `type`. 기본값 `text`. 숫자는 `NumberFormatInput`을 쓴다(`number`는 받지 않는다). */
|
|
6
|
+
type?: Exclude<NamedInputType, "number">;
|
|
4
7
|
/** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Button과 높이가 같다. 기본값은 `md`다. */
|
|
5
8
|
size?: InputSize;
|
|
6
9
|
/**
|
|
@@ -12,7 +15,8 @@ export interface InputOwnProps {
|
|
|
12
15
|
export interface InputProps extends InputOwnProps, Omit<ComponentProps<"input">, keyof InputOwnProps> {}
|
|
13
16
|
/**
|
|
14
17
|
* 한 줄 텍스트를 입력하는 네이티브 `<input>`. `type`(`email`, `password`, `date` 등)을 그대로 받는다.
|
|
15
|
-
* Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
16
|
-
* Tide props: `size`, `invalid` ({@link InputOwnProps}). 나머지는 `<input>` 속성.
|
|
18
|
+
* 숫자는 `NumberFormatInput`을 쓴다. Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
19
|
+
* Tide props: `type`, `size`, `invalid` ({@link InputOwnProps}). 나머지는 `<input>` 속성.
|
|
17
20
|
*/
|
|
18
|
-
export declare function Input({ size, invalid, id, disabled, required, className, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: InputProps): ReactElement;
|
|
21
|
+
export declare function Input({ size, invalid, id, disabled, required, className, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }: InputProps): ReactElement;
|
|
22
|
+
export {};
|
package/dist/Input/Input.js
CHANGED
|
@@ -8,8 +8,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
8
8
|
// src/Input/Input.tsx
|
|
9
9
|
/**
|
|
10
10
|
* 한 줄 텍스트를 입력하는 네이티브 `<input>`. `type`(`email`, `password`, `date` 등)을 그대로 받는다.
|
|
11
|
-
* Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
12
|
-
* Tide props: `size`, `invalid` ({@link InputOwnProps}). 나머지는 `<input>` 속성.
|
|
11
|
+
* 숫자는 `NumberFormatInput`을 쓴다. Field 안에 두면 label, 설명, 오류 메시지가 자동으로 연결된다.
|
|
12
|
+
* Tide props: `type`, `size`, `invalid` ({@link InputOwnProps}). 나머지는 `<input>` 속성.
|
|
13
13
|
*/
|
|
14
14
|
function Input({ size = "md", invalid, id, disabled, required, className, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...props }) {
|
|
15
15
|
const control = useFieldControl({
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InputSize } from "../_internal/constants/inputClass.js";
|
|
2
|
+
import { MaskFormatOptions, NumericFormatOptions, WithoutNumericOptions } from "./types.js";
|
|
3
|
+
import { ComponentProps, ReactElement } from "react";
|
|
4
|
+
export interface NumberFormatInputOwnProps extends NumericFormatOptions {
|
|
5
|
+
/** 패턴 모드 틀. `#` 자리에 숫자가 들어간다(`"###-####-####"`). 주면 숫자 모드 옵션은 받지 않는다. */
|
|
6
|
+
mask?: MaskFormatOptions["mask"];
|
|
7
|
+
/**
|
|
8
|
+
* 값(제어). 빈 칸은 `null`. 패턴 모드는 앞자리 0을 지키도록 숫자 문자열(`"01012345678"`)도 받는다.
|
|
9
|
+
*/
|
|
10
|
+
value?: number | string | null;
|
|
11
|
+
/** 처음 값(비제어). `value`와 같은 형태다. */
|
|
12
|
+
defaultValue?: number | string | null;
|
|
13
|
+
/**
|
|
14
|
+
* 사용자가 값을 바꾸면 부른다. `value`는 숫자(빈 칸 `null`), `formattedValue`는 화면 글자,
|
|
15
|
+
* `digits`는 숫자만 남긴 문자열이다. 앞자리 0·큰 자릿수(전화·카드번호)는 `digits`를 쓴다.
|
|
16
|
+
*/
|
|
17
|
+
onValueChange?: (value: number | null, formattedValue: string, digits: string) => void;
|
|
18
|
+
/** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Input과 같다. 기본값은 `md`다. */
|
|
19
|
+
size?: InputSize;
|
|
20
|
+
/** 오류 상태. `aria-invalid="true"`와 `data-invalid`가 붙는다. Field 값보다 여기 준 값이 이긴다. */
|
|
21
|
+
invalid?: boolean;
|
|
22
|
+
}
|
|
23
|
+
type NumberFormatInputModeProps = {
|
|
24
|
+
mask?: undefined;
|
|
25
|
+
value?: number | null;
|
|
26
|
+
defaultValue?: number | null;
|
|
27
|
+
} | (Required<Pick<MaskFormatOptions, "mask">> & WithoutNumericOptions);
|
|
28
|
+
export type NumberFormatInputProps = NumberFormatInputModeProps & NumberFormatInputOwnProps & Omit<ComponentProps<"input">, keyof NumberFormatInputOwnProps | "type" | "pattern" | "children" | "dangerouslySetInnerHTML">;
|
|
29
|
+
/**
|
|
30
|
+
* 칠 때 바로 포맷하는 숫자 입력. 천 단위 구분자·prefix·suffix·소수 자릿수(숫자 모드)와
|
|
31
|
+
* `mask` 틀(패턴 모드)을 다룬다. `<input type="text">`이고 Field 안에서 label·설명·오류가 연결된다.
|
|
32
|
+
* Tide props: `mask`, `value`, `defaultValue`, `onValueChange`, `size`, `invalid`, `prefix`, `suffix`, `decimalPlaces`, `fixedDecimalPlaces`, `allowNegative`, `groupStyle`, `groupSeparator`, `decimalSeparator`, `locale` ({@link NumberFormatInputOwnProps}). 나머지는 `<input>` 속성.
|
|
33
|
+
*/
|
|
34
|
+
export declare function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onCompositionStart, onInput, ...props }: NumberFormatInputProps): ReactElement;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Input } from "../Input/Input.js";
|
|
4
|
+
import { MaskModeInput } from "./components/MaskModeInput.js";
|
|
5
|
+
import { NumericModeInput } from "./components/NumericModeInput.js";
|
|
6
|
+
import { useNumberCompositionGuard } from "./hooks/useNumberCompositionGuard.js";
|
|
7
|
+
import { maskDigits } from "./libs/maskFormat.js";
|
|
8
|
+
import { toNumericString } from "./libs/numericFormat.js";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
import { useRef } from "react";
|
|
11
|
+
|
|
12
|
+
// src/NumberFormatInput/NumberFormatInput.tsx
|
|
13
|
+
/**
|
|
14
|
+
* 칠 때 바로 포맷하는 숫자 입력. 천 단위 구분자·prefix·suffix·소수 자릿수(숫자 모드)와
|
|
15
|
+
* `mask` 틀(패턴 모드)을 다룬다. `<input type="text">`이고 Field 안에서 label·설명·오류가 연결된다.
|
|
16
|
+
* Tide props: `mask`, `value`, `defaultValue`, `onValueChange`, `size`, `invalid`, `prefix`, `suffix`, `decimalPlaces`, `fixedDecimalPlaces`, `allowNegative`, `groupStyle`, `groupSeparator`, `decimalSeparator`, `locale` ({@link NumberFormatInputOwnProps}). 나머지는 `<input>` 속성.
|
|
17
|
+
*/
|
|
18
|
+
function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onCompositionStart, onInput, ...props }) {
|
|
19
|
+
const compositionGuard = useNumberCompositionGuard({
|
|
20
|
+
onCompositionStart,
|
|
21
|
+
onInput
|
|
22
|
+
});
|
|
23
|
+
const lastEmitted = useRef(null);
|
|
24
|
+
const toDigits = (input) => {
|
|
25
|
+
if (typeof input === "number") return mask === void 0 ? toNumericString(input, decimalPlaces) : String(input);
|
|
26
|
+
return mask === void 0 ? input : maskDigits(input);
|
|
27
|
+
};
|
|
28
|
+
const libraryValue = value === void 0 ? void 0 : lastEmitted.current && Object.is(value, lastEmitted.current.value) ? lastEmitted.current.digits : value === null ? "" : toDigits(value);
|
|
29
|
+
const handleValueChange = (values, { source }) => {
|
|
30
|
+
if (source !== "event") return;
|
|
31
|
+
const next = mask === void 0 ? values.floatValue ?? null : values.value === "" ? null : Number(values.value);
|
|
32
|
+
lastEmitted.current = {
|
|
33
|
+
value: next,
|
|
34
|
+
digits: values.value
|
|
35
|
+
};
|
|
36
|
+
onValueChange?.(next, values.formattedValue, values.value);
|
|
37
|
+
};
|
|
38
|
+
const shared = {
|
|
39
|
+
...props,
|
|
40
|
+
...compositionGuard,
|
|
41
|
+
type: "text",
|
|
42
|
+
inputMode: inputMode ?? (mask !== void 0 || decimalPlaces === 0 ? "numeric" : allowNegative ? void 0 : "decimal"),
|
|
43
|
+
customInput: Input,
|
|
44
|
+
getInputRef: ref,
|
|
45
|
+
value: libraryValue,
|
|
46
|
+
defaultValue: defaultValue === void 0 || defaultValue === null ? defaultValue : toDigits(defaultValue),
|
|
47
|
+
valueIsNumericString: true,
|
|
48
|
+
onValueChange: handleValueChange
|
|
49
|
+
};
|
|
50
|
+
if (mask !== void 0) return /* @__PURE__ */ jsx(MaskModeInput, {
|
|
51
|
+
...shared,
|
|
52
|
+
mask
|
|
53
|
+
});
|
|
54
|
+
return /* @__PURE__ */ jsx(NumericModeInput, {
|
|
55
|
+
...shared,
|
|
56
|
+
options: {
|
|
57
|
+
prefix,
|
|
58
|
+
suffix,
|
|
59
|
+
decimalPlaces,
|
|
60
|
+
fixedDecimalPlaces,
|
|
61
|
+
allowNegative,
|
|
62
|
+
groupStyle,
|
|
63
|
+
groupSeparator,
|
|
64
|
+
decimalSeparator,
|
|
65
|
+
locale
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { NumberFormatInput };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { applyMask, maskDigits, maxMaskDigits, sortMasks } from "../libs/maskFormat.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { NumberFormatBase } from "react-number-format";
|
|
6
|
+
|
|
7
|
+
// src/NumberFormatInput/components/MaskModeInput.tsx
|
|
8
|
+
function MaskModeInput({ mask, ...props }) {
|
|
9
|
+
const masks = sortMasks(mask);
|
|
10
|
+
const maxDigits = maxMaskDigits(masks);
|
|
11
|
+
return /* @__PURE__ */ jsx(NumberFormatBase, {
|
|
12
|
+
...props,
|
|
13
|
+
format: (digits) => applyMask(digits, masks),
|
|
14
|
+
removeFormatting: (text, change) => {
|
|
15
|
+
const digits = maskDigits(text);
|
|
16
|
+
if (digits.length > maxDigits && change) return maskDigits(change.lastValue);
|
|
17
|
+
return digits.slice(0, maxDigits);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { MaskModeInput };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { toLibraryNumericOptions } from "../libs/numericFormat.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { NumberFormatBase, useNumericFormat } from "react-number-format";
|
|
6
|
+
|
|
7
|
+
// src/NumberFormatInput/components/NumericModeInput.tsx
|
|
8
|
+
function NumericModeInput({ options, ...props }) {
|
|
9
|
+
const baseProps = useNumericFormat({
|
|
10
|
+
...props,
|
|
11
|
+
...toLibraryNumericOptions(options)
|
|
12
|
+
});
|
|
13
|
+
return /* @__PURE__ */ jsx(NumberFormatBase, { ...baseProps });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { NumericModeInput };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
|
|
5
|
+
// src/NumberFormatInput/hooks/useNumberCompositionGuard.ts
|
|
6
|
+
/** IME 조합 중인 글자를 지워 조합 직전 값으로 되돌린다. 넘긴 처리기는 되돌린 뒤 부른다. */
|
|
7
|
+
function useNumberCompositionGuard({ onCompositionStart, onInput }) {
|
|
8
|
+
const valueBeforeComposition = useRef("");
|
|
9
|
+
return {
|
|
10
|
+
onCompositionStart: (event) => {
|
|
11
|
+
valueBeforeComposition.current = event.currentTarget.value;
|
|
12
|
+
onCompositionStart?.(event);
|
|
13
|
+
},
|
|
14
|
+
onInput: (event) => {
|
|
15
|
+
if (event.nativeEvent.isComposing) event.currentTarget.value = valueBeforeComposition.current;
|
|
16
|
+
onInput?.(event);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { useNumberCompositionGuard };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NumberFormatOptions } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* 값을 `NumberFormatInput`과 같은 옵션으로 포맷한 글자. 표·카드의 금액처럼 보여 주기만 할 때 쓴다.
|
|
4
|
+
* 숫자 문자열(`digits`)도 받는다. `null`·`undefined`·`NaN`은 빈 문자열이다.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatNumber(value: number | string | null | undefined, options?: NumberFormatOptions): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { applyMask, maskDigits, sortMasks } from "./maskFormat.js";
|
|
2
|
+
import { toLibraryNumericOptions, toNumericString } from "./numericFormat.js";
|
|
3
|
+
import { numericFormatter } from "react-number-format";
|
|
4
|
+
|
|
5
|
+
// src/NumberFormatInput/libs/formatNumber.ts
|
|
6
|
+
/**
|
|
7
|
+
* 값을 `NumberFormatInput`과 같은 옵션으로 포맷한 글자. 표·카드의 금액처럼 보여 주기만 할 때 쓴다.
|
|
8
|
+
* 숫자 문자열(`digits`)도 받는다. `null`·`undefined`·`NaN`은 빈 문자열이다.
|
|
9
|
+
*/
|
|
10
|
+
function formatNumber(value, options = {}) {
|
|
11
|
+
if (value === null || value === void 0 || Number.isNaN(value)) return "";
|
|
12
|
+
if (options.mask !== void 0) return applyMask(maskDigits(String(value)), sortMasks(options.mask));
|
|
13
|
+
const numStr = typeof value === "number" ? toNumericString(value, options.decimalPlaces) : value;
|
|
14
|
+
return numericFormatter(numStr, toLibraryNumericOptions(options));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { formatNumber };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/NumberFormatInput/libs/maskFormat.ts
|
|
2
|
+
const slotChar = "#";
|
|
3
|
+
function slotCount(mask) {
|
|
4
|
+
return mask.split(slotChar).length - 1;
|
|
5
|
+
}
|
|
6
|
+
/** 자릿수가 적은 틀부터 늘어놓는다. */
|
|
7
|
+
function sortMasks(mask) {
|
|
8
|
+
return [...typeof mask === "string" ? [mask] : mask].sort((a, b) => slotCount(a) - slotCount(b));
|
|
9
|
+
}
|
|
10
|
+
/** 틀이 받을 수 있는 최대 자릿수 */
|
|
11
|
+
function maxMaskDigits(masks) {
|
|
12
|
+
return Math.max(0, ...masks.map(slotCount));
|
|
13
|
+
}
|
|
14
|
+
/** 숫자가 아닌 글자를 뺀다. 전각 숫자(`1`)는 반각으로 바꾼다. */
|
|
15
|
+
function maskDigits(text) {
|
|
16
|
+
return text.replace(/[0-9]/g, (char) => String.fromCharCode(char.charCodeAt(0) - 65248)).replace(/\D/g, "");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `sortMasks` 결과로 숫자를 틀에 채운다. 비어 있는 자리 앞의 고정 글자는 쓰지 않는다.
|
|
20
|
+
* 그래야 지울 때 caret이 고정 글자에 걸리지 않는다.
|
|
21
|
+
*/
|
|
22
|
+
function applyMask(digits, masks) {
|
|
23
|
+
const mask = masks.find((candidate) => slotCount(candidate) >= digits.length) ?? masks.at(-1);
|
|
24
|
+
if (!mask || digits === "") return "";
|
|
25
|
+
let result = "";
|
|
26
|
+
let index = 0;
|
|
27
|
+
for (const char of mask) if (char === slotChar) {
|
|
28
|
+
const digit = digits[index];
|
|
29
|
+
if (digit === void 0) break;
|
|
30
|
+
result += digit;
|
|
31
|
+
index += 1;
|
|
32
|
+
} else {
|
|
33
|
+
if (index >= digits.length && index < slotCount(mask)) break;
|
|
34
|
+
result += char;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { applyMask, maskDigits, maxMaskDigits, sortMasks };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/NumberFormatInput/libs/numericFormat.ts
|
|
2
|
+
function localeSeparators(locale) {
|
|
3
|
+
if (locale === void 0) return {
|
|
4
|
+
group: ",",
|
|
5
|
+
decimal: "."
|
|
6
|
+
};
|
|
7
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(1234567.5);
|
|
8
|
+
return {
|
|
9
|
+
group: parts.find((part) => part.type === "group")?.value ?? ",",
|
|
10
|
+
decimal: parts.find((part) => part.type === "decimal")?.value ?? "."
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Tide 옵션을 react-number-format 옵션으로 바꾼다. */
|
|
14
|
+
function toLibraryNumericOptions(options) {
|
|
15
|
+
const separators = localeSeparators(options.locale);
|
|
16
|
+
const groupSeparator = options.groupSeparator ?? separators.group;
|
|
17
|
+
const decimalSeparator = options.decimalSeparator ?? separators.decimal;
|
|
18
|
+
const groupStyle = options.groupStyle ?? "thousand";
|
|
19
|
+
return {
|
|
20
|
+
prefix: options.prefix,
|
|
21
|
+
suffix: options.suffix,
|
|
22
|
+
decimalScale: options.decimalPlaces,
|
|
23
|
+
fixedDecimalScale: options.fixedDecimalPlaces ?? false,
|
|
24
|
+
allowNegative: options.allowNegative ?? false,
|
|
25
|
+
thousandSeparator: groupStyle === "none" ? false : groupSeparator,
|
|
26
|
+
thousandsGroupStyle: groupStyle,
|
|
27
|
+
decimalSeparator,
|
|
28
|
+
allowedDecimalSeparators: [decimalSeparator, "."].filter((char) => char !== groupSeparator)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 숫자를 지수 표기 없는 숫자 문자열로 바꾼다. `decimalPlaces`가 있으면 그 자릿수로 반올림한다.
|
|
33
|
+
* 입력 칸과 `formatNumber`가 함께 써서 반올림 결과를 맞춘다.
|
|
34
|
+
*/
|
|
35
|
+
function toNumericString(value, decimalPlaces) {
|
|
36
|
+
if (decimalPlaces === void 0) {
|
|
37
|
+
const plain = String(value);
|
|
38
|
+
if (!/e/i.test(plain)) return plain;
|
|
39
|
+
}
|
|
40
|
+
return new Intl.NumberFormat("en-US", {
|
|
41
|
+
useGrouping: false,
|
|
42
|
+
maximumFractionDigits: decimalPlaces ?? 20,
|
|
43
|
+
signDisplay: "negative"
|
|
44
|
+
}).format(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { toLibraryNumericOptions, toNumericString };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "../Input/Input.js";
|
|
2
|
+
import "react-number-format";
|
|
3
|
+
/** 숫자를 몇 자리씩 묶는지. `thousand` 1,234,567 · `wan` 123,4567(만 단위) · `none` 묶지 않음. */
|
|
4
|
+
export type NumberGroupStyle = "thousand" | "wan" | "none";
|
|
5
|
+
/** 숫자 모드 포맷 옵션. `NumberFormatInput`과 `formatNumber`가 같은 옵션으로 같은 글자를 만든다. */
|
|
6
|
+
export interface NumericFormatOptions {
|
|
7
|
+
/** 숫자 앞에 붙는 글자(예: `"₩"`). 값이 있을 때만 보인다. */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
/** 숫자 뒤에 붙는 글자(예: `"원"`, `"%"`). 값이 있을 때만 보인다. */
|
|
10
|
+
suffix?: string;
|
|
11
|
+
/** 소수 최대 자릿수. `0`이면 소수점을 받지 않는다. 기본값은 제한 없음. */
|
|
12
|
+
decimalPlaces?: number;
|
|
13
|
+
/** `decimalPlaces`만큼 소수 자리를 늘 채운다(`1` → `1.00`). 입력 칸은 blur 때 채운다. 기본값 `false`. */
|
|
14
|
+
fixedDecimalPlaces?: boolean;
|
|
15
|
+
/** 음수(`-`)를 받는다. 기본값 `false`. */
|
|
16
|
+
allowNegative?: boolean;
|
|
17
|
+
/** 자릿수 묶음 방식. 기본값 `thousand`. */
|
|
18
|
+
groupStyle?: NumberGroupStyle;
|
|
19
|
+
/** 묶음 구분자. 기본값은 `locale`의 구분자, `locale`이 없으면 `","`. */
|
|
20
|
+
groupSeparator?: string;
|
|
21
|
+
/** 소수점 글자. 기본값은 `locale`의 소수점, `locale`이 없으면 `"."`. */
|
|
22
|
+
decimalSeparator?: string;
|
|
23
|
+
/** 구분자 기본값을 가져올 BCP 47 locale(예: `"de-DE"`). 묶음 방식은 바꾸지 않는다. */
|
|
24
|
+
locale?: string;
|
|
25
|
+
}
|
|
26
|
+
/** 패턴 모드 포맷 옵션 */
|
|
27
|
+
export interface MaskFormatOptions {
|
|
28
|
+
/**
|
|
29
|
+
* 숫자를 채울 틀. `#` 자리에 숫자가 들어간다(예: `"###-####-####"`). 틀의 고정 글자에 숫자를 쓰지 않는다.
|
|
30
|
+
* 배열이면 입력한 자릿수에 맞는 가장 짧은 틀을 고른다.
|
|
31
|
+
*/
|
|
32
|
+
mask: string | readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/** 패턴 모드에서 숫자 모드 옵션을 막는다. */
|
|
35
|
+
export type WithoutNumericOptions = { [K in keyof NumericFormatOptions]?: undefined; };
|
|
36
|
+
/** `formatNumber` 옵션. `mask`가 있으면 패턴 모드, 없으면 숫자 모드다. */
|
|
37
|
+
export type NumberFormatOptions = (NumericFormatOptions & {
|
|
38
|
+
mask?: undefined;
|
|
39
|
+
}) | (MaskFormatOptions & WithoutNumericOptions);
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ import "./Input/index.js";
|
|
|
15
15
|
import { Input, InputOwnProps, InputProps } from "./Input/Input.js";
|
|
16
16
|
import "./Textarea/index.js";
|
|
17
17
|
import { Textarea, TextareaOwnProps, TextareaProps } from "./Textarea/Textarea.js";
|
|
18
|
+
import "./NumberFormatInput/index.js";
|
|
19
|
+
import { formatNumber } from "./NumberFormatInput/libs/formatNumber.js";
|
|
20
|
+
import { NumberFormatInput, NumberFormatInputOwnProps, NumberFormatInputProps } from "./NumberFormatInput/NumberFormatInput.js";
|
|
21
|
+
import { MaskFormatOptions, NumberFormatOptions, NumberGroupStyle, NumericFormatOptions } from "./NumberFormatInput/types.js";
|
|
18
22
|
import "./Checkbox/index.js";
|
|
19
23
|
import { Checkbox, CheckboxOwnProps, CheckboxProps, CheckboxShape } from "./Checkbox/Checkbox.js";
|
|
20
24
|
import "./CheckboxGroup/index.js";
|
|
@@ -117,4 +121,4 @@ import { TooltipTrigger, TooltipTriggerOwnProps, TooltipTriggerProps } from "./T
|
|
|
117
121
|
import { TooltipPlacement } from "./Tooltip/types.js";
|
|
118
122
|
import { TooltipContent, TooltipContentOwnProps, TooltipContentProps } from "./Tooltip/components/TooltipContent.js";
|
|
119
123
|
import { Color, ColorFamilyName, ColorFamilyRegistry, FillVariant, Role, RoleRegistry, Size } from "./types.js";
|
|
120
|
-
export { Accordion, type AccordionHeadingLevel, AccordionItem, type AccordionItemOwnProps, type AccordionItemProps, type AccordionOwnProps, AccordionPanel, type AccordionPanelOwnProps, type AccordionPanelProps, type AccordionProps, AccordionTrigger, type AccordionTriggerOwnProps, type AccordionTriggerProps, Alert, AlertDialog, type AlertDialogProps, type AlertOwnProps, type AlertProps, Avatar, type AvatarOwnProps, type AvatarProps, Badge, type BadgeOwnProps, type BadgeProps, Breadcrumb, BreadcrumbCurrent, type BreadcrumbCurrentProps, BreadcrumbItem, type BreadcrumbItemProps, BreadcrumbLink, type BreadcrumbLinkOwnProps, type BreadcrumbLinkProps, type BreadcrumbOwnProps, type BreadcrumbProps, Button, type ButtonOwnProps, type ButtonProps, Card, type CardOwnProps, type CardProps, Checkbox, CheckboxGroup, type CheckboxGroupOwnProps, type CheckboxGroupProps, type CheckboxOwnProps, type CheckboxProps, type CheckboxShape, type ChoiceOrientation, type Color, type ColorFamilyName, type ColorFamilyRegistry, Combobox, ComboboxItem, type ComboboxItemOwnProps, type ComboboxItemProps, type ComboboxOwnProps, type ComboboxProps, ComboboxSection, type ComboboxSectionProps, Dialog, DialogClose, type DialogCloseOwnProps, type DialogCloseProps, DialogContent, type DialogContentOwnProps, type DialogContentProps, DialogDescription, type DialogDescriptionProps, DialogFooter, type DialogFooterProps, DialogHeader, type DialogHeaderAlign, type DialogHeaderOwnProps, type DialogHeaderProps, type DialogProps, type DialogSize, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerOwnProps, type DialogTriggerProps, Field, type FieldOwnProps, type FieldProps, type FillVariant, IconButton, type IconButtonOwnProps, type IconButtonProps, Input, type InputOwnProps, type InputProps, Link, type LinkOwnProps, type LinkProps, Menu, MenuContent, type MenuContentOwnProps, type MenuContentProps, MenuItem, type MenuItemOwnProps, type MenuItemProps, type MenuPlacement, type MenuProps, MenuSection, type MenuSectionProps, MenuTrigger, type MenuTriggerOwnProps, type MenuTriggerProps, Pagination, PaginationEllipsis, type PaginationEllipsisOwnProps, type PaginationEllipsisProps, PaginationItem, type PaginationItemProps, PaginationLink, type PaginationLinkOwnProps, type PaginationLinkProps, PaginationNext, type PaginationNextOwnProps, type PaginationNextProps, type PaginationOwnProps, PaginationPrevious, type PaginationPreviousOwnProps, type PaginationPreviousProps, type PaginationProps, Popover, PopoverContent, type PopoverContentOwnProps, type PopoverContentProps, type PopoverPlacement, type PopoverProps, PopoverTrigger, type PopoverTriggerOwnProps, type PopoverTriggerProps, Progress, type ProgressOwnProps, type ProgressProps, Radio, RadioGroup, type RadioGroupOwnProps, type RadioGroupProps, type RadioOwnProps, type RadioProps, type Role, type RoleRegistry, Select, SelectItem, type SelectItemOwnProps, type SelectItemProps, type SelectOwnProps, type SelectProps, SelectSection, type SelectSectionProps, Separator, type SeparatorOwnProps, type SeparatorProps, type Size, Skeleton, type SkeletonOwnProps, type SkeletonProps, Spinner, type SpinnerOwnProps, type SpinnerProps, Switch, type SwitchOwnProps, type SwitchProps, Tab, TabList, type TabListOwnProps, type TabListProps, type TabOwnProps, TabPanel, type TabPanelOwnProps, type TabPanelProps, type TabProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellOwnProps, type TableHeaderCellProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsActivationMode, type TabsOrientation, type TabsOwnProps, type TabsProps, type TabsShape, Tag, TagGroup, type TagGroupOwnProps, type TagGroupProps, type TagOwnProps, type TagProps, Textarea, type TextareaOwnProps, type TextareaProps, type ToastAction, type ToastOptions, ToastQueue, type ToastQueueOptions, ToastRegion, type ToastRegionOwnProps, type ToastRegionProps, Tooltip, TooltipContent, type TooltipContentOwnProps, type TooltipContentProps, type TooltipPlacement, type TooltipProps, TooltipTrigger, type TooltipTriggerOwnProps, type TooltipTriggerProps, VisuallyHidden, type VisuallyHiddenProps, cn };
|
|
124
|
+
export { Accordion, type AccordionHeadingLevel, AccordionItem, type AccordionItemOwnProps, type AccordionItemProps, type AccordionOwnProps, AccordionPanel, type AccordionPanelOwnProps, type AccordionPanelProps, type AccordionProps, AccordionTrigger, type AccordionTriggerOwnProps, type AccordionTriggerProps, Alert, AlertDialog, type AlertDialogProps, type AlertOwnProps, type AlertProps, Avatar, type AvatarOwnProps, type AvatarProps, Badge, type BadgeOwnProps, type BadgeProps, Breadcrumb, BreadcrumbCurrent, type BreadcrumbCurrentProps, BreadcrumbItem, type BreadcrumbItemProps, BreadcrumbLink, type BreadcrumbLinkOwnProps, type BreadcrumbLinkProps, type BreadcrumbOwnProps, type BreadcrumbProps, Button, type ButtonOwnProps, type ButtonProps, Card, type CardOwnProps, type CardProps, Checkbox, CheckboxGroup, type CheckboxGroupOwnProps, type CheckboxGroupProps, type CheckboxOwnProps, type CheckboxProps, type CheckboxShape, type ChoiceOrientation, type Color, type ColorFamilyName, type ColorFamilyRegistry, Combobox, ComboboxItem, type ComboboxItemOwnProps, type ComboboxItemProps, type ComboboxOwnProps, type ComboboxProps, ComboboxSection, type ComboboxSectionProps, Dialog, DialogClose, type DialogCloseOwnProps, type DialogCloseProps, DialogContent, type DialogContentOwnProps, type DialogContentProps, DialogDescription, type DialogDescriptionProps, DialogFooter, type DialogFooterProps, DialogHeader, type DialogHeaderAlign, type DialogHeaderOwnProps, type DialogHeaderProps, type DialogProps, type DialogSize, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerOwnProps, type DialogTriggerProps, Field, type FieldOwnProps, type FieldProps, type FillVariant, IconButton, type IconButtonOwnProps, type IconButtonProps, Input, type InputOwnProps, type InputProps, Link, type LinkOwnProps, type LinkProps, type MaskFormatOptions, Menu, MenuContent, type MenuContentOwnProps, type MenuContentProps, MenuItem, type MenuItemOwnProps, type MenuItemProps, type MenuPlacement, type MenuProps, MenuSection, type MenuSectionProps, MenuTrigger, type MenuTriggerOwnProps, type MenuTriggerProps, NumberFormatInput, type NumberFormatInputOwnProps, type NumberFormatInputProps, type NumberFormatOptions, type NumberGroupStyle, type NumericFormatOptions, Pagination, PaginationEllipsis, type PaginationEllipsisOwnProps, type PaginationEllipsisProps, PaginationItem, type PaginationItemProps, PaginationLink, type PaginationLinkOwnProps, type PaginationLinkProps, PaginationNext, type PaginationNextOwnProps, type PaginationNextProps, type PaginationOwnProps, PaginationPrevious, type PaginationPreviousOwnProps, type PaginationPreviousProps, type PaginationProps, Popover, PopoverContent, type PopoverContentOwnProps, type PopoverContentProps, type PopoverPlacement, type PopoverProps, PopoverTrigger, type PopoverTriggerOwnProps, type PopoverTriggerProps, Progress, type ProgressOwnProps, type ProgressProps, Radio, RadioGroup, type RadioGroupOwnProps, type RadioGroupProps, type RadioOwnProps, type RadioProps, type Role, type RoleRegistry, Select, SelectItem, type SelectItemOwnProps, type SelectItemProps, type SelectOwnProps, type SelectProps, SelectSection, type SelectSectionProps, Separator, type SeparatorOwnProps, type SeparatorProps, type Size, Skeleton, type SkeletonOwnProps, type SkeletonProps, Spinner, type SpinnerOwnProps, type SpinnerProps, Switch, type SwitchOwnProps, type SwitchProps, Tab, TabList, type TabListOwnProps, type TabListProps, type TabOwnProps, TabPanel, type TabPanelOwnProps, type TabPanelProps, type TabProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellOwnProps, type TableHeaderCellProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsActivationMode, type TabsOrientation, type TabsOwnProps, type TabsProps, type TabsShape, Tag, TagGroup, type TagGroupOwnProps, type TagGroupProps, type TagOwnProps, type TagProps, Textarea, type TextareaOwnProps, type TextareaProps, type ToastAction, type ToastOptions, ToastQueue, type ToastQueueOptions, ToastRegion, type ToastRegionOwnProps, type ToastRegionProps, Tooltip, TooltipContent, type TooltipContentOwnProps, type TooltipContentProps, type TooltipPlacement, type TooltipProps, TooltipTrigger, type TooltipTriggerOwnProps, type TooltipTriggerProps, VisuallyHidden, type VisuallyHiddenProps, cn, formatNumber };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ import { Link } from "./Link/Link.js";
|
|
|
7
7
|
import { Field } from "./Field/Field.js";
|
|
8
8
|
import { Input } from "./Input/Input.js";
|
|
9
9
|
import { Textarea } from "./Textarea/Textarea.js";
|
|
10
|
+
import { NumberFormatInput } from "./NumberFormatInput/NumberFormatInput.js";
|
|
11
|
+
import { formatNumber } from "./NumberFormatInput/libs/formatNumber.js";
|
|
10
12
|
import { Checkbox } from "./Checkbox/Checkbox.js";
|
|
11
13
|
import { CheckboxGroup } from "./CheckboxGroup/CheckboxGroup.js";
|
|
12
14
|
import { Radio } from "./Radio/Radio.js";
|
|
@@ -74,4 +76,4 @@ import { Tooltip } from "./Tooltip/Tooltip.js";
|
|
|
74
76
|
import { TooltipContent } from "./Tooltip/components/TooltipContent.js";
|
|
75
77
|
import { TooltipTrigger } from "./Tooltip/components/TooltipTrigger.js";
|
|
76
78
|
|
|
77
|
-
export { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, Alert, AlertDialog, Avatar, Badge, Breadcrumb, BreadcrumbCurrent, BreadcrumbItem, BreadcrumbLink, Button, Card, Checkbox, CheckboxGroup, Combobox, ComboboxItem, ComboboxSection, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Field, IconButton, Input, Link, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, Pagination, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioGroup, Select, SelectItem, SelectSection, Separator, Skeleton, Spinner, Switch, Tab, TabList, TabPanel, Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, Tabs, Tag, TagGroup, Textarea, ToastQueue, ToastRegion, Tooltip, TooltipContent, TooltipTrigger, VisuallyHidden, cn };
|
|
79
|
+
export { Accordion, AccordionItem, AccordionPanel, AccordionTrigger, Alert, AlertDialog, Avatar, Badge, Breadcrumb, BreadcrumbCurrent, BreadcrumbItem, BreadcrumbLink, Button, Card, Checkbox, CheckboxGroup, Combobox, ComboboxItem, ComboboxSection, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Field, IconButton, Input, Link, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, NumberFormatInput, Pagination, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioGroup, Select, SelectItem, SelectSection, Separator, Skeleton, Spinner, Switch, Tab, TabList, TabPanel, Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, Tabs, Tag, TagGroup, Textarea, ToastQueue, ToastRegion, Tooltip, TooltipContent, TooltipTrigger, VisuallyHidden, cn, formatNumber };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tide-design/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Tide 디자인 시스템의 React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"./styles.css": "./dist/styles.css"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tide-design/foundation": "0.
|
|
38
|
-
"@tide-design/icons": "0.
|
|
37
|
+
"@tide-design/foundation": "0.21.0",
|
|
38
|
+
"@tide-design/icons": "0.21.0",
|
|
39
39
|
"clsx": "^2.1.1",
|
|
40
40
|
"react-aria": "^3.53.1",
|
|
41
|
+
"react-number-format": "^5.4.5",
|
|
41
42
|
"react-stately": "^3.51.0",
|
|
42
43
|
"tailwind-merge": "^3.7.0"
|
|
43
44
|
},
|