react-frontend-common-components 0.0.79 → 0.0.82

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-frontend-common-components",
3
- "version": "0.0.79",
3
+ "version": "0.0.82",
4
4
  "description": "Reusable frontend library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,6 +1,29 @@
1
+ .placeHolder {
2
+ line-height: normal;
3
+ position: absolute;
4
+ bottom: 50%;
5
+ transform: translateY(50%);
6
+ left: 11px;
7
+ color: #000000;
8
+ z-index: 1 !important;
9
+ }
10
+ .requiredText {
11
+ opacity: 60%;
12
+ color: #686869 !important;
13
+ font-size: 14px;
14
+ font-weight: 500;
15
+ line-height: normal;
16
+ }
17
+ .star {
18
+ color: rgba(255, 40, 25, 1);
19
+ display: inline-block;
20
+ transform: translateX(1.5px);
21
+ }
22
+
1
23
  .appInput {
2
24
  font-size: var(--font-14);
3
25
  font-weight: 500;
26
+ position: relative;
4
27
  .ant-input::placeholder {
5
28
  color: #202123 !important;
6
29
  font-size: 14px;
@@ -51,7 +74,6 @@
51
74
  }
52
75
  }
53
76
  }
54
-
55
77
  .error {
56
78
  color: red;
57
79
  font-size: 0.875rem;
@@ -2,11 +2,13 @@
2
2
 
3
3
  import { Input, InputProps, InputRef } from "antd";
4
4
  import {
5
+ ChangeEvent,
5
6
  ChangeEventHandler,
6
7
  KeyboardEventHandler,
7
8
  MouseEventHandler,
8
9
  useEffect,
9
10
  useRef,
11
+ useState,
10
12
  } from "react";
11
13
  import "./app-input.css";
12
14
 
@@ -29,7 +31,7 @@ interface AppInputProps extends InputProps {
29
31
  errorMessage?: string;
30
32
  suffixIcon?: React.ReactNode;
31
33
  prefixIcon?: React.ReactNode;
32
- required?:boolean;
34
+ required?: boolean;
33
35
  }
34
36
 
35
37
  const AppInput = ({
@@ -55,6 +57,8 @@ const AppInput = ({
55
57
  ...props
56
58
  }: AppInputProps) => {
57
59
  const inputRef = useRef<InputRef>(null);
60
+ const [inputValue, setInputValue] = useState<string>(value || "");
61
+ const [isTyping, setIsTyping] = useState(false);
58
62
 
59
63
  useEffect(() => {
60
64
  if (isAutoFocus && inputRef.current) {
@@ -62,10 +66,32 @@ const AppInput = ({
62
66
  }
63
67
  }, [triggerFocus, isAutoFocus]);
64
68
 
69
+ useEffect(() => {
70
+ if (value !== undefined) {
71
+ setInputValue(value);
72
+ }
73
+ }, [value]);
74
+
65
75
  const placeholder = isOptional ? `${label} (optional)` : label;
66
76
 
77
+ const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
78
+ setInputValue(e.target.value);
79
+ setIsTyping(e.target.value.length > 0);
80
+ handleChange?.(e);
81
+ };
82
+
67
83
  return (
68
84
  <div className={`appInput ${className}`}>
85
+ {/* Show placeholder only if user hasn't started typing */}
86
+ {required && !isTyping && !inputValue && (
87
+ <div className="placeHolder" onClick={() => inputRef.current?.focus()}>
88
+ <label className="requiredText" htmlFor={id}>
89
+ {placeholder}
90
+ </label>
91
+ <span className="star">*</span>
92
+ </div>
93
+ )}
94
+
69
95
  <Input
70
96
  type={type}
71
97
  data-test-id={dataTestId}
@@ -73,12 +99,12 @@ const AppInput = ({
73
99
  disabled={disabled}
74
100
  name={name}
75
101
  className={"input"}
76
- value={value}
77
- onChange={handleChange}
102
+ value={inputValue}
103
+ onChange={handleInputChange}
78
104
  onClick={onClick}
79
105
  defaultValue={defaultValue}
80
106
  onPressEnter={onPressEnter}
81
- placeholder={`${required ? placeholder + " (required)" : placeholder}`}
107
+ placeholder={`${required ? "" : placeholder}`}
82
108
  ref={inputRef}
83
109
  prefix={prefixIcon && prefixIcon}
84
110
  suffix={suffixIcon && suffixIcon}
@@ -1,6 +1,7 @@
1
1
  .appselect {
2
2
  font-weight: 500;
3
3
  font-size: var(--font-14);
4
+ position: relative;
4
5
  *:focus,
5
6
  *:active,
6
7
  *:focus-within {
@@ -31,3 +32,24 @@
31
32
  font-size: 0.875rem;
32
33
  margin-top: 0.25rem;
33
34
  }
35
+
36
+ .placeHolder {
37
+ line-height: normal;
38
+ position: absolute;
39
+ bottom: 50%;
40
+ transform: translateY(50%);
41
+ left: 11px;
42
+ z-index: 1 !important;
43
+ }
44
+ .requiredText {
45
+ opacity: 60%;
46
+ color: #686869 !important;
47
+ font-size: 14px;
48
+ font-weight: 500;
49
+ line-height: normal;
50
+ }
51
+ .star {
52
+ color: rgba(255, 40, 25, 1);
53
+ display: inline-block;
54
+ transform: translateX(1.5px);
55
+ }
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useState, useEffect, useRef } from "react";
2
2
  import { Select, SelectProps } from "antd";
3
3
  import { MouseEventHandler } from "react";
4
4
  import "./app-select.css";
@@ -37,19 +37,58 @@ const AppSelect = ({
37
37
  required,
38
38
  ...props
39
39
  }: AppSelectProps) => {
40
+ const selectRef = useRef<HTMLDivElement>(null);
41
+ const [selectedValue, setSelectedValue] = useState<string | null>(
42
+ value || null
43
+ );
44
+
45
+ useEffect(() => {
46
+ if (value !== undefined) {
47
+ setSelectedValue(value);
48
+ }
49
+ }, [value]);
50
+
51
+ const handleSelectChange = (val: string | string[]) => {
52
+ setSelectedValue(val ? String(val) : null);
53
+ handleChange?.(val);
54
+ };
55
+
40
56
  return (
41
- <div className={`appselect ${className}`}>
57
+ <div className={`appselect ${className}`} ref={selectRef}>
58
+ {/* Show placeholder only when nothing is selected */}
59
+ {required && !selectedValue && (
60
+ <div
61
+ className="placeHolder"
62
+ onClick={() => {
63
+ const selectElement = selectRef.current?.querySelector(
64
+ ".ant-select-selector"
65
+ ) as HTMLElement;
66
+ if (selectElement) {
67
+ selectElement.click();
68
+ setTimeout(() => {
69
+ selectElement.dispatchEvent(
70
+ new MouseEvent("mousedown", { bubbles: true })
71
+ );
72
+ }, 0);
73
+ }
74
+ }}
75
+ >
76
+ <label className="requiredText" htmlFor={props.id}>
77
+ {placeholder}
78
+ </label>
79
+ <span className="star">*</span>
80
+ </div>
81
+ )}
82
+
42
83
  <Select
43
84
  className={"select"}
44
85
  showSearch={showSearch}
45
86
  disabled={disabled}
46
- value={value?.length ? value : null}
47
- placeholder={`${required ? placeholder + " (required)" : placeholder}`}
48
- onChange={(value: string | string[]) =>
49
- handleChange && handleChange(value)
50
- }
51
- filterOption={(input, options) =>
52
- (options?.label || "")
87
+ value={selectedValue || null}
88
+ placeholder={`${required ? "" : placeholder}`}
89
+ onChange={handleSelectChange}
90
+ filterOption={(input, option) =>
91
+ (option?.label || "")
53
92
  .toString()
54
93
  .toLowerCase()
55
94
  .includes(input.toLowerCase())
@@ -81,7 +120,8 @@ const AppSelect = ({
81
120
  value,
82
121
  }))}
83
122
  {...props}
84
- ></Select>
123
+ />
124
+
85
125
  {errorMessage && <div className={"error"}>{errorMessage}</div>}
86
126
  </div>
87
127
  );