fis-component 0.1.4 → 0.1.6

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.
@@ -12,6 +12,8 @@ export interface InputTextProps extends InputFieldProps, Partial<InputLabelProps
12
12
  onEnter?: (value: string | null) => void;
13
13
  /** Handle onKeyDown action */
14
14
  onKeyDown?: (event: unknown) => void;
15
+ /** Trim whitespace from value on blur */
16
+ isTrimValue?: boolean;
15
17
  }
16
18
  declare const FISInputText: React.ForwardRefExoticComponent<InputTextProps & React.RefAttributes<HTMLInputElement>>;
17
19
  export default FISInputText;
@@ -31,6 +31,7 @@ export interface MenuProps {
31
31
  selectedGroupLabel?: string;
32
32
  maxHeight?: string | number;
33
33
  onPopupScroll?: (e: React.UIEvent<HTMLElement>) => void;
34
+ normalizeTextSearch?: boolean;
34
35
  }
35
36
  export interface MenuState {
36
37
  search: string;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Normalizes a text value by:
3
+ * - Removing all diacritic marks (e.g. Vietnamese accents)
4
+ * - Converting the result to lowercase
5
+ * - Trimming leading and trailing whitespace
6
+ *
7
+ * This is useful for case-insensitive and accent-insensitive text comparisons
8
+ * or searches, especially for languages that use diacritics.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * normalizeText("Công nghệ thông tin"); // "cong nghe thong tin"
13
+ * normalizeText(""); // ""
14
+ * ```
15
+ *
16
+ * @param value - The input text to normalize. If falsy, an empty string is returned.
17
+ * @returns The normalized, accent-stripped, lowercase, and trimmed string.
18
+ */
19
+ export declare const normalizeText: (value: string) => string;
package/dist/esm/index.js CHANGED
@@ -65331,7 +65331,7 @@ function mergeRefs(...refs) {
65331
65331
  }
65332
65332
 
65333
65333
  const FISInputText = forwardRef((props, ref) => {
65334
- const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, ...rest } = props;
65334
+ const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, isTrimValue = true, ...rest } = props;
65335
65335
  // Internal ref to access DOM element for character count
65336
65336
  const internalRef = React__default.useRef(null);
65337
65337
  const [internalValue, setInternalValue] = React__default.useState("");
@@ -65366,7 +65366,22 @@ const FISInputText = forwardRef((props, ref) => {
65366
65366
  }
65367
65367
  }
65368
65368
  }, [onEnter]);
65369
- return (jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(FISInputField, { ...rest, ref: mergeRefs(ref, internalRef), typeSuffix: typeSuffix, sizeInput: sizeInput, iconPrefix: iconPrefix, onKeyPress: handleKeyPress, onChange: handleChange, disabled: disabled, negative: negative, maxLength: maxLength, onClickSuffix: onClickSuffix }), (message || showCount) && (jsxs(DivHintWrapperSC$1, { children: [jsx(SpanHintSC$3, { className: classNames({
65369
+ const handleBlur = React__default.useCallback((event) => {
65370
+ if (!isTrimValue) {
65371
+ rest.onBlur?.(event);
65372
+ return;
65373
+ }
65374
+ const trimmedValue = event.target.value.trim();
65375
+ event.target.value = trimmedValue;
65376
+ if (rest.value === undefined) {
65377
+ setInternalValue(trimmedValue);
65378
+ }
65379
+ else {
65380
+ forceUpdate();
65381
+ }
65382
+ rest.onBlur?.(event);
65383
+ }, [isTrimValue, rest.value, rest.onBlur]);
65384
+ return (jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(FISInputField, { ...rest, ref: mergeRefs(ref, internalRef), typeSuffix: typeSuffix, sizeInput: sizeInput, iconPrefix: iconPrefix, onKeyPress: handleKeyPress, onChange: handleChange, onBlur: handleBlur, disabled: disabled, negative: negative, maxLength: maxLength, onClickSuffix: onClickSuffix }), (message || showCount) && (jsxs(DivHintWrapperSC$1, { children: [jsx(SpanHintSC$3, { className: classNames({
65370
65385
  disabled: disabled,
65371
65386
  negative: negative,
65372
65387
  positive: positive,
@@ -66627,7 +66642,7 @@ const DivWrapperSC$5 = styled.div `
66627
66642
  gap: ${getTheme("com/input/vertical-gap")};
66628
66643
  `;
66629
66644
 
66630
- const FISInputStepper = forwardRef((props) => {
66645
+ const FISInputStepper = forwardRef((props, ref) => {
66631
66646
  const { min, max, step = 1, defaultValue, sizeInput = "md", StartIcon, EndIcon, negative, positive, message, iconLabel, textLabel = "", onClickIconLabel, disabled, readOnly, onChange, ...rest } = props;
66632
66647
  const [count, setCount] = useState(defaultValue !== undefined ? defaultValue : undefined);
66633
66648
  const handleIncrement = () => {
@@ -66659,7 +66674,7 @@ const FISInputStepper = forwardRef((props) => {
66659
66674
  "input-text-lg": sizeInput === "lg",
66660
66675
  }), children: [jsx(FISIconButton, { icon: StartIcon ? StartIcon : jsx(DecreIcon, {}), size: sizeInput === "lg" ? "md" : "sm", variant: "tertiary-invisible", onClick: handleDecrement, disabled: min !== undefined && count !== undefined && count <= min, className: classNames("decrement", {
66661
66676
  "disabled-button": disabled || readOnly,
66662
- }) }), jsx(InputSC$1, { ...rest, disabled: disabled, readOnly: readOnly, type: "number", value: count !== undefined ? count : "", className: classNames({
66677
+ }) }), jsx(InputSC$1, { ...rest, ref: ref, disabled: disabled, readOnly: readOnly, type: "number", value: count !== undefined ? count : "", className: classNames({
66663
66678
  negative: negative,
66664
66679
  "input-text-lg": sizeInput === "lg",
66665
66680
  }), onChange: handleChange }), jsx(FISIconButton, { icon: EndIcon ? EndIcon : jsx(IncreIcon, {}), size: sizeInput === "lg" ? "md" : "sm", variant: "tertiary-invisible", onClick: handleIncrement, disabled: max !== undefined && count !== undefined && count >= max, className: classNames("increment", {
@@ -68528,7 +68543,37 @@ const FISMenuSection = ({ label, withAction = false, actionText, actionLabel = f
68528
68543
  };
68529
68544
  FISMenuSection.displayName = "FISMenuSection";
68530
68545
 
68531
- const FISMenuSelect = ({ placeholder, groups, size = "md", multi = false, selectedValues = [], onChangeSelected, searchValue = "", onSearchChange, loading = false, noData = false, noResult = false, combobox, className, onClickMenu, loadingText = "Data loading...", noDataText = "No data", noResultText = "No result", removeSelectedText = "Remove selected", selectedGroupLabel = "Selected", maxHeight, onPopupScroll, }) => {
68546
+ /**
68547
+ * Normalizes a text value by:
68548
+ * - Removing all diacritic marks (e.g. Vietnamese accents)
68549
+ * - Converting the result to lowercase
68550
+ * - Trimming leading and trailing whitespace
68551
+ *
68552
+ * This is useful for case-insensitive and accent-insensitive text comparisons
68553
+ * or searches, especially for languages that use diacritics.
68554
+ *
68555
+ * @example
68556
+ * ```ts
68557
+ * normalizeText("Công nghệ thông tin"); // "cong nghe thong tin"
68558
+ * normalizeText(""); // ""
68559
+ * ```
68560
+ *
68561
+ * @param value - The input text to normalize. If falsy, an empty string is returned.
68562
+ * @returns The normalized, accent-stripped, lowercase, and trimmed string.
68563
+ */
68564
+ const normalizeText = (value) => {
68565
+ if (!value)
68566
+ return "";
68567
+ return value
68568
+ .normalize("NFD")
68569
+ .replace(/[\u0300-\u036f]/g, "")
68570
+ .replace(/đ/g, "d")
68571
+ .replace(/Đ/g, "D")
68572
+ .toLowerCase()
68573
+ .trim();
68574
+ };
68575
+
68576
+ const FISMenuSelect = ({ placeholder, groups, size = "md", multi = false, selectedValues = [], onChangeSelected, searchValue = "", onSearchChange, loading = false, noData = false, noResult = false, combobox, className, onClickMenu, loadingText = "Data loading...", noDataText = "No data", noResultText = "No result", removeSelectedText = "Remove selected", selectedGroupLabel = "Selected", maxHeight, onPopupScroll, normalizeTextSearch = false, }) => {
68532
68577
  const [localSearch, setLocalSearch] = useState(searchValue);
68533
68578
  const [debouncedSearchValue, setDebouncedSearchValue] = useState(searchValue);
68534
68579
  const debouncedSetSearch = useMemo$1(() => debounce$1((value) => setDebouncedSearchValue(value), 300), []);
@@ -68560,11 +68605,13 @@ const FISMenuSelect = ({ placeholder, groups, size = "md", multi = false, select
68560
68605
  if (search.trim()) {
68561
68606
  filteredItems = filteredItems.map((group) => ({
68562
68607
  ...group,
68563
- items: group.items.filter((item) => item?.label?.toLowerCase()?.includes(search?.toLowerCase())),
68608
+ items: group.items.filter((item) => normalizeTextSearch
68609
+ ? normalizeText(item?.label).includes(normalizeText(search))
68610
+ : item?.label?.toLowerCase()?.includes(search?.toLowerCase())),
68564
68611
  }));
68565
68612
  }
68566
68613
  return filteredItems.filter((group) => group.items.length > 0);
68567
- }, [groups, multi, selectedValues, search]);
68614
+ }, [groups, multi, selectedValues, search, normalizeTextSearch]);
68568
68615
  const selectedItemsGroup = useMemo$1(() => {
68569
68616
  if (!multi)
68570
68617
  return null;