kahuna-base-react-components 1.1.0 → 1.1.1
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/components/KTextArea/KTextArea.d.ts +1 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/KTextArea/KTextArea.stories.tsx +6 -2
- package/src/components/KTextArea/KTextArea.tsx +21 -6
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -25,9 +25,13 @@ KTextAreaPrimary.args = {
|
|
|
25
25
|
console.log("Enter is clicked and our value is:", event.currentTarget)
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
rows: 4,
|
|
29
28
|
placeholder: "Placeholder...",
|
|
30
|
-
hoverBackground: "white"
|
|
29
|
+
hoverBackground: "white",
|
|
30
|
+
width: 200,
|
|
31
|
+
height: 20,
|
|
32
|
+
leftIcon: TracksIcon,
|
|
33
|
+
activeBackground: "#FFF"
|
|
34
|
+
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export const KTextAreaLeftIcon = Template.bind({})
|
|
@@ -28,6 +28,7 @@ export interface KTextAreaProps {
|
|
|
28
28
|
fontSize?: string
|
|
29
29
|
iconSize?: string
|
|
30
30
|
checked?: boolean
|
|
31
|
+
maxHeight?: number
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const KTextArea: React.FC<KTextAreaProps> = (props) => {
|
|
@@ -58,7 +59,16 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
|
|
|
58
59
|
const border = props.border || "none"
|
|
59
60
|
const fontSize = props.fontSize || "14px"
|
|
60
61
|
const iconSize = props.iconSize || "20px"
|
|
61
|
-
const rows = props.rows ||
|
|
62
|
+
const rows = props.rows || 1
|
|
63
|
+
|
|
64
|
+
const autoResize = props.maxHeight && props.maxHeight !== props.height
|
|
65
|
+
const maxHeight = props.maxHeight || 200
|
|
66
|
+
|
|
67
|
+
const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
68
|
+
const textarea = e.target
|
|
69
|
+
textarea.style.height = "auto"
|
|
70
|
+
textarea.style.height = `${textarea.scrollHeight}px` // Set the height to scrollHeight
|
|
71
|
+
}
|
|
62
72
|
|
|
63
73
|
return (
|
|
64
74
|
<div
|
|
@@ -89,22 +99,27 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
|
|
|
89
99
|
width,
|
|
90
100
|
height,
|
|
91
101
|
accentColor,
|
|
92
|
-
fontSize
|
|
102
|
+
fontSize,
|
|
103
|
+
overflow: autoResize ? "hidden" : "auto",
|
|
104
|
+
minHeight: height,
|
|
105
|
+
resize: autoResize ? "none" : "vertical",
|
|
106
|
+
...(autoResize && { maxHeight })
|
|
93
107
|
}}
|
|
94
|
-
rows={rows}
|
|
95
108
|
value={props.value}
|
|
109
|
+
rows={rows}
|
|
96
110
|
placeholder={props.placeholder || ""}
|
|
97
111
|
disabled={disabled}
|
|
98
112
|
onBlur={(event) => {
|
|
99
|
-
console.log("onBulur", event.target.value)
|
|
100
113
|
if (props.onBlur) props.onBlur(event.target.value)
|
|
101
114
|
}}
|
|
102
115
|
onChange={(event) => {
|
|
103
|
-
|
|
116
|
+
if (autoResize) {
|
|
117
|
+
handleInput(event)
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
props.onChange(event.target.value)
|
|
105
121
|
}}
|
|
106
122
|
onKeyDown={(event) => {
|
|
107
|
-
console.log("OnKeyDown", event)
|
|
108
123
|
if (props.onKeyDown) props.onKeyDown(event)
|
|
109
124
|
}}
|
|
110
125
|
/>
|