@shoplflow/base 0.42.8 → 0.42.9

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/index.cjs CHANGED
@@ -7089,7 +7089,6 @@ var DEFAULT_DEBOUNCE_TIME = 300;
7089
7089
  var SearchBarInput = (_a) => {
7090
7090
  var _b = _a, {
7091
7091
  value,
7092
- defaultValue,
7093
7092
  onChange,
7094
7093
  onClear,
7095
7094
  placeholder,
@@ -7098,10 +7097,10 @@ var SearchBarInput = (_a) => {
7098
7097
  type = "default",
7099
7098
  onSearch,
7100
7099
  debounceTime = type === "default" ? 0 : DEFAULT_DEBOUNCE_TIME,
7101
- icon = /* @__PURE__ */ jsxRuntime.jsx(exports.Icon, { iconSource: ShoplAssets.SearchIcon, color: "neutral350", sizeVar: "S" })
7100
+ icon = /* @__PURE__ */ jsxRuntime.jsx(exports.Icon, { iconSource: ShoplAssets.SearchIcon, color: "neutral350", sizeVar: "S" }),
7101
+ maxLength
7102
7102
  } = _b, rest = __objRest(_b, [
7103
7103
  "value",
7104
- "defaultValue",
7105
7104
  "onChange",
7106
7105
  "onClear",
7107
7106
  "placeholder",
@@ -7110,16 +7109,11 @@ var SearchBarInput = (_a) => {
7110
7109
  "type",
7111
7110
  "onSearch",
7112
7111
  "debounceTime",
7113
- "icon"
7112
+ "icon",
7113
+ "maxLength"
7114
7114
  ]);
7115
7115
  const { useFlexibleWidth, isSelected } = useSearchBarContext();
7116
7116
  const [text, setText] = React3.useState("");
7117
- const convertToString = React3.useCallback((value2) => {
7118
- if (typeof value2 !== "number") {
7119
- return typeof value2 === "string" ? value2 : value2.join("");
7120
- }
7121
- return String(value2);
7122
- }, []);
7123
7117
  const debouncedOnChange = React3.useRef(
7124
7118
  utils.debounce(
7125
7119
  (event) => {
@@ -7134,7 +7128,18 @@ var SearchBarInput = (_a) => {
7134
7128
  )
7135
7129
  ).current;
7136
7130
  const handleOnChange = (event) => {
7137
- debouncedOnChange(event);
7131
+ const newValue = event.target.value;
7132
+ if (maxLength && newValue.length > maxLength) {
7133
+ event.target.value = value === void 0 ? text : String(value);
7134
+ return;
7135
+ }
7136
+ setText(newValue);
7137
+ if (debounceTime === 0 || maxLength && newValue.length === maxLength) {
7138
+ onChange && onChange(event);
7139
+ }
7140
+ if (type === "real-time") {
7141
+ debouncedOnChange(event);
7142
+ }
7138
7143
  };
7139
7144
  const handleOnClear = React3.useCallback(() => {
7140
7145
  setText("");
@@ -7157,19 +7162,6 @@ var SearchBarInput = (_a) => {
7157
7162
  if (useFlexibleWidth && !isSelected) {
7158
7163
  _placeholder = flexiblePlaceholder;
7159
7164
  }
7160
- const getInitialValue = React3.useCallback(() => {
7161
- if (value !== void 0) {
7162
- return convertToString(value);
7163
- }
7164
- if (defaultValue !== void 0) {
7165
- return convertToString(defaultValue);
7166
- }
7167
- return "";
7168
- }, [convertToString, defaultValue, value]);
7169
- React3.useEffect(() => {
7170
- const initialValue = getInitialValue();
7171
- setText(initialValue);
7172
- }, [getInitialValue]);
7173
7165
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7174
7166
  type === "default" && /* @__PURE__ */ jsxRuntime.jsx(exports.IconButton, { styleVar: "GHOST", sizeVar: "S", onClick: handleIconClick, "aria-label": "\uAC80\uC0C9", children: /* @__PURE__ */ jsxRuntime.jsx(exports.Icon, { iconSource: ShoplAssets.SearchIcon, color: text ? "neutral700" : "neutral350", sizeVar: "S" }) }),
7175
7167
  type === "real-time" && icon,
@@ -7179,7 +7171,7 @@ var SearchBarInput = (_a) => {
7179
7171
  placeholder: _placeholder,
7180
7172
  onChange: handleOnChange,
7181
7173
  onKeyDown: handleKeyDown,
7182
- value: text,
7174
+ value: value === void 0 ? text : value,
7183
7175
  onClear: handleOnClear,
7184
7176
  width: "100%",
7185
7177
  disabled,
package/dist/index.d.cts CHANGED
@@ -1683,6 +1683,8 @@ interface SearchBarInputProps {
1683
1683
  onSearch?: (value: string) => void;
1684
1684
  /** 디바운스 시간 (ms) */
1685
1685
  debounceTime?: number;
1686
+ /** 최대 길이 */
1687
+ maxLength?: number;
1686
1688
  }
1687
1689
  /** 검색바 props */
1688
1690
  declare type SearchBarProps = SearchBarBaseProps;
package/dist/index.d.ts CHANGED
@@ -1683,6 +1683,8 @@ interface SearchBarInputProps {
1683
1683
  onSearch?: (value: string) => void;
1684
1684
  /** 디바운스 시간 (ms) */
1685
1685
  debounceTime?: number;
1686
+ /** 최대 길이 */
1687
+ maxLength?: number;
1686
1688
  }
1687
1689
  /** 검색바 props */
1688
1690
  declare type SearchBarProps = SearchBarBaseProps;
package/dist/index.js CHANGED
@@ -7062,7 +7062,6 @@ var DEFAULT_DEBOUNCE_TIME = 300;
7062
7062
  var SearchBarInput = (_a) => {
7063
7063
  var _b = _a, {
7064
7064
  value,
7065
- defaultValue,
7066
7065
  onChange,
7067
7066
  onClear,
7068
7067
  placeholder,
@@ -7071,10 +7070,10 @@ var SearchBarInput = (_a) => {
7071
7070
  type = "default",
7072
7071
  onSearch,
7073
7072
  debounceTime = type === "default" ? 0 : DEFAULT_DEBOUNCE_TIME,
7074
- icon = /* @__PURE__ */ jsx(Icon_default, { iconSource: SearchIcon, color: "neutral350", sizeVar: "S" })
7073
+ icon = /* @__PURE__ */ jsx(Icon_default, { iconSource: SearchIcon, color: "neutral350", sizeVar: "S" }),
7074
+ maxLength
7075
7075
  } = _b, rest = __objRest(_b, [
7076
7076
  "value",
7077
- "defaultValue",
7078
7077
  "onChange",
7079
7078
  "onClear",
7080
7079
  "placeholder",
@@ -7083,16 +7082,11 @@ var SearchBarInput = (_a) => {
7083
7082
  "type",
7084
7083
  "onSearch",
7085
7084
  "debounceTime",
7086
- "icon"
7085
+ "icon",
7086
+ "maxLength"
7087
7087
  ]);
7088
7088
  const { useFlexibleWidth, isSelected } = useSearchBarContext();
7089
7089
  const [text, setText] = useState("");
7090
- const convertToString = useCallback((value2) => {
7091
- if (typeof value2 !== "number") {
7092
- return typeof value2 === "string" ? value2 : value2.join("");
7093
- }
7094
- return String(value2);
7095
- }, []);
7096
7090
  const debouncedOnChange = useRef(
7097
7091
  debounce(
7098
7092
  (event) => {
@@ -7107,7 +7101,18 @@ var SearchBarInput = (_a) => {
7107
7101
  )
7108
7102
  ).current;
7109
7103
  const handleOnChange = (event) => {
7110
- debouncedOnChange(event);
7104
+ const newValue = event.target.value;
7105
+ if (maxLength && newValue.length > maxLength) {
7106
+ event.target.value = value === void 0 ? text : String(value);
7107
+ return;
7108
+ }
7109
+ setText(newValue);
7110
+ if (debounceTime === 0 || maxLength && newValue.length === maxLength) {
7111
+ onChange && onChange(event);
7112
+ }
7113
+ if (type === "real-time") {
7114
+ debouncedOnChange(event);
7115
+ }
7111
7116
  };
7112
7117
  const handleOnClear = useCallback(() => {
7113
7118
  setText("");
@@ -7130,19 +7135,6 @@ var SearchBarInput = (_a) => {
7130
7135
  if (useFlexibleWidth && !isSelected) {
7131
7136
  _placeholder = flexiblePlaceholder;
7132
7137
  }
7133
- const getInitialValue = useCallback(() => {
7134
- if (value !== void 0) {
7135
- return convertToString(value);
7136
- }
7137
- if (defaultValue !== void 0) {
7138
- return convertToString(defaultValue);
7139
- }
7140
- return "";
7141
- }, [convertToString, defaultValue, value]);
7142
- useEffect(() => {
7143
- const initialValue = getInitialValue();
7144
- setText(initialValue);
7145
- }, [getInitialValue]);
7146
7138
  return /* @__PURE__ */ jsxs(Fragment, { children: [
7147
7139
  type === "default" && /* @__PURE__ */ jsx(IconButton_default, { styleVar: "GHOST", sizeVar: "S", onClick: handleIconClick, "aria-label": "\uAC80\uC0C9", children: /* @__PURE__ */ jsx(Icon_default, { iconSource: SearchIcon, color: text ? "neutral700" : "neutral350", sizeVar: "S" }) }),
7148
7140
  type === "real-time" && icon,
@@ -7152,7 +7144,7 @@ var SearchBarInput = (_a) => {
7152
7144
  placeholder: _placeholder,
7153
7145
  onChange: handleOnChange,
7154
7146
  onKeyDown: handleKeyDown,
7155
- value: text,
7147
+ value: value === void 0 ? text : value,
7156
7148
  onClear: handleOnClear,
7157
7149
  width: "100%",
7158
7150
  disabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoplflow/base",
3
- "version": "0.42.8",
3
+ "version": "0.42.9",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -91,8 +91,8 @@
91
91
  "react-dom": "^18.2.0",
92
92
  "simplebar-react": "^3.2.6",
93
93
  "@shoplflow/hada-assets": "^0.1.7",
94
- "@shoplflow/utils": "^0.7.0",
95
- "@shoplflow/shopl-assets": "^0.12.22"
94
+ "@shoplflow/shopl-assets": "^0.12.22",
95
+ "@shoplflow/utils": "^0.7.0"
96
96
  },
97
97
  "scripts": {
98
98
  "type-check": "tsc --noEmit",