kahuna-base-react-components 1.1.0 → 1.1.2

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/types.d.ts CHANGED
@@ -123,6 +123,8 @@ interface KTextAreaProps {
123
123
  fontSize?: string;
124
124
  iconSize?: string;
125
125
  checked?: boolean;
126
+ maxHeight?: number;
127
+ clearTextOnPressedEnter?: boolean;
126
128
  }
127
129
  declare const KTextArea: React.FC<KTextAreaProps>;
128
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -24,10 +24,18 @@ KTextAreaPrimary.args = {
24
24
  if (event.key === "Enter") {
25
25
  console.log("Enter is clicked and our value is:", event.currentTarget)
26
26
  }
27
+ if (event.key === "Enter" && event.shiftKey) {
28
+ console.log("Enter and shift is clicked ")
29
+ }
27
30
  },
28
- rows: 4,
29
31
  placeholder: "Placeholder...",
30
- hoverBackground: "white"
32
+ hoverBackground: "white",
33
+ width: 200,
34
+ height: 20,
35
+ leftIcon: TracksIcon,
36
+ activeBackground: "#FFF",
37
+ maxHeight: 200,
38
+ clearTextOnPressedEnter: true
31
39
  }
32
40
 
33
41
  export const KTextAreaLeftIcon = Template.bind({})
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, KeyboardEvent } from "react"
1
+ import React, { useEffect, useState, KeyboardEvent, useRef } from "react"
2
2
  import "../../main.css"
3
3
 
4
4
  export interface KTextAreaProps {
@@ -28,12 +28,16 @@ export interface KTextAreaProps {
28
28
  fontSize?: string
29
29
  iconSize?: string
30
30
  checked?: boolean
31
+ maxHeight?: number
32
+ clearTextOnPressedEnter?: boolean
31
33
  }
32
34
 
33
35
  const KTextArea: React.FC<KTextAreaProps> = (props) => {
34
36
  const [background, setBackground] = useState("#F5F5F5")
35
37
  const [hover, setHover] = useState(false)
36
38
 
39
+ const textAreaRef = useRef<HTMLTextAreaElement>(null)
40
+
37
41
  useEffect(() => {
38
42
  const emptyBackground = props.background || "#F5F5F5"
39
43
  const activeBackground = props.activeBackground || "#FFF"
@@ -58,7 +62,19 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
58
62
  const border = props.border || "none"
59
63
  const fontSize = props.fontSize || "14px"
60
64
  const iconSize = props.iconSize || "20px"
61
- const rows = props.rows || 2
65
+ const rows = props.rows || 1
66
+
67
+ const autoResize = props.maxHeight && props.maxHeight !== props.height
68
+ const maxHeight = props.maxHeight || 200
69
+ const clearTextOnPressedEnter = props.clearTextOnPressedEnter || false
70
+
71
+ const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
72
+ if (textAreaRef.current) {
73
+ const textarea = textAreaRef.current
74
+ textarea.style.height = "auto"
75
+ textarea.style.height = `${textarea.scrollHeight}px` // Set the height to scrollHeight
76
+ }
77
+ }
62
78
 
63
79
  return (
64
80
  <div
@@ -83,29 +99,49 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
83
99
  )}
84
100
 
85
101
  <textarea
102
+ ref={textAreaRef}
86
103
  className={"k-input"}
87
104
  style={{
88
105
  background: hover ? hoverBackground : background,
89
106
  width,
90
107
  height,
91
108
  accentColor,
92
- fontSize
109
+ fontSize,
110
+ overflow: autoResize ? "hidden" : "auto",
111
+ minHeight: height,
112
+ resize: autoResize ? "none" : "vertical",
113
+ ...(autoResize && { maxHeight })
93
114
  }}
94
- rows={rows}
95
115
  value={props.value}
116
+ rows={rows}
96
117
  placeholder={props.placeholder || ""}
97
118
  disabled={disabled}
98
119
  onBlur={(event) => {
99
- console.log("onBulur", event.target.value)
100
120
  if (props.onBlur) props.onBlur(event.target.value)
101
121
  }}
102
122
  onChange={(event) => {
103
- console.log("OnChange", event.target.value)
123
+ if (autoResize) {
124
+ handleInput(event)
125
+ }
126
+
104
127
  props.onChange(event.target.value)
105
128
  }}
106
129
  onKeyDown={(event) => {
107
- console.log("OnKeyDown", event)
108
130
  if (props.onKeyDown) props.onKeyDown(event)
131
+
132
+ if (event.key === "Enter") {
133
+ if (event.shiftKey) {
134
+ return
135
+ } else if (textAreaRef.current && clearTextOnPressedEnter) {
136
+ event.preventDefault()
137
+ const textAreaComponent = textAreaRef.current
138
+ textAreaComponent.style.height = "auto"
139
+ textAreaComponent.style.height = `${height}px`
140
+ textAreaComponent.value = ""
141
+ } else {
142
+ event.preventDefault()
143
+ }
144
+ }
109
145
  }}
110
146
  />
111
147