kahuna-base-react-components 1.1.1 → 1.1.3

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
@@ -124,6 +124,7 @@ interface KTextAreaProps {
124
124
  iconSize?: string;
125
125
  checked?: boolean;
126
126
  maxHeight?: number;
127
+ clearTextOnPressedEnter?: boolean;
127
128
  }
128
129
  declare const KTextArea: React.FC<KTextAreaProps>;
129
130
 
@@ -178,6 +179,7 @@ declare const KSlider: React.FC<KSliderProps>;
178
179
  interface KSelectDateProps {
179
180
  value: Date | undefined;
180
181
  onChange: (date: Date | undefined) => void;
182
+ minimumDate?: Date;
181
183
  }
182
184
  declare const KSelectDate: React.FC<KSelectDateProps>;
183
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -14,7 +14,7 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
14
14
 
15
15
  const [selectedDate, setSelectedDate] = useState<Date | undefined>(undefined)
16
16
  useEffect(() => {
17
- console.log("selectedDate: ", selectedDate)
17
+ // console.log("selectedDate: ", selectedDate)
18
18
  }, [selectedDate])
19
19
 
20
20
  return (
@@ -22,14 +22,14 @@ const KSelectDateWrapper: React.FC<KSelectDateProps> = (args) => {
22
22
  {...args}
23
23
  value={selectedDate}
24
24
  onChange={(date) => {
25
- console.log("date: ", date)
25
+ // console.log("date: ", date)
26
26
  if (date) {
27
27
  setSelectedDate(date)
28
- console.log("updating is completed: ", date)
29
- console.log("updating is completed date.toISOString(): ", date?.toISOString())
28
+ // console.log("updating is completed: ", date)
29
+ // console.log("updating is completed date.toISOString(): ", date?.toISOString())
30
30
  } else {
31
31
  setSelectedDate(undefined)
32
- console.log("Deleting is completed")
32
+ // console.log("Deleting is completed")
33
33
  }
34
34
  }}
35
35
  />
@@ -41,6 +41,7 @@ const Template: StoryFn<typeof KSelectDateWrapper> = (args) => <KSelectDateWrapp
41
41
  export const KSelectDatePrimary = Template.bind({})
42
42
  KSelectDatePrimary.args = {
43
43
  value: undefined,
44
+ minimumDate: new Date(new Date().getTime() + 14 * 24 * 60 * 60 * 1000),
44
45
  onChange: (value) => {
45
46
  if (value) {
46
47
  console.log("value is updated using this value:", value)
@@ -16,6 +16,7 @@ import KSpan from "../KSpan"
16
16
  export interface KSelectDateProps {
17
17
  value: Date | undefined
18
18
  onChange: (date: Date | undefined) => void
19
+ minimumDate?: Date
19
20
  }
20
21
  interface MonthSelectorType {
21
22
  monthName: string
@@ -107,6 +108,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
107
108
  nextLabel={<img src={RightIcon} />}
108
109
  formatShortWeekday={formatShortWeekday}
109
110
  formatMonthYear={formatMonthYear}
111
+ minDate={props.minimumDate || undefined}
110
112
  />
111
113
  <div className="h-19 w-[350px] bg-[#FFF] flex flex-row gap-4 py-4 justify-center border-[1px] border-[#E7E7E7] border-t-0 rounded-b-[10px]">
112
114
  <KButton
@@ -173,7 +175,7 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
173
175
  }
174
176
  }}
175
177
  background={inMonth ? "#111" : "#FFF"}
176
- textColor={inMonth? "#FFF" : "#111"}
178
+ textColor={inMonth ? "#FFF" : "#111"}
177
179
  borderRadius={999}
178
180
  padding="8px 16px"
179
181
  height="34px"
@@ -183,13 +185,23 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
183
185
  }
184
186
 
185
187
  const daySelector = (text: string, date: Date) => {
188
+ const dateNotAllowed = props.minimumDate && date < props.minimumDate
186
189
  return (
187
190
  <div
188
191
  key={`${text}-${date}`}
189
- className={`w-[85px] h-[104px] flex flex-col justify-between py-3 px-2.5 rounded-[10px] ${
190
- date.getTime() === value?.getTime() ? "bg-[#F8FEA3]" : "bg-[#F5F5F5]"
191
- } cursor-pointer`}
192
+ className={`w-[85px] h-[104px] flex flex-col justify-between py-3 px-2.5 rounded-[10px] cursor-pointer`}
193
+ style={{
194
+ background: dateNotAllowed
195
+ ? "rgb(170, 170, 170, 0.7)"
196
+ : date.getTime() === value?.getTime()
197
+ ? "#F8FEA3"
198
+ : "#F5F5F5"
199
+ }}
192
200
  onClick={() => {
201
+ if (dateNotAllowed) {
202
+ return
203
+ }
204
+
193
205
  if (date.getTime() === value?.getTime()) {
194
206
  setValue(undefined)
195
207
  } else {
@@ -228,6 +240,8 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
228
240
  useEffect(() => {
229
241
  if (value) {
230
242
  setDummyDate(value)
243
+ } else if (props.minimumDate) {
244
+ setDummyDate(props.minimumDate)
231
245
  }
232
246
  props.onChange(value)
233
247
  }, [value])
@@ -235,14 +249,19 @@ const KSelectDate: React.FC<KSelectDateProps> = (props) => {
235
249
  useEffect(() => {
236
250
  const today = new Date()
237
251
  if (!props.value) {
238
- getNextMonths(today)
239
- getWeekDays(today)
252
+ getNextMonths(props.minimumDate || today)
253
+ getWeekDays(props.minimumDate || today)
240
254
  }
241
255
  }, [])
242
-
256
+
243
257
  useEffect(() => {
244
- getNextMonths(dummyDate)
245
- getWeekDays(dummyDate)
258
+ if (dummyDate && props.minimumDate && dummyDate < props.minimumDate) {
259
+ getNextMonths(props.minimumDate)
260
+ getWeekDays(props.minimumDate)
261
+ } else {
262
+ getNextMonths(dummyDate)
263
+ getWeekDays(dummyDate)
264
+ }
246
265
  }, [dummyDate])
247
266
 
248
267
  return (
@@ -24,14 +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
31
  placeholder: "Placeholder...",
29
32
  hoverBackground: "white",
30
33
  width: 200,
31
34
  height: 20,
32
35
  leftIcon: TracksIcon,
33
- activeBackground: "#FFF"
34
-
36
+ activeBackground: "#FFF",
37
+ maxHeight: 200,
38
+ clearTextOnPressedEnter: true
35
39
  }
36
40
 
37
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 {
@@ -29,12 +29,15 @@ export interface KTextAreaProps {
29
29
  iconSize?: string
30
30
  checked?: boolean
31
31
  maxHeight?: number
32
+ clearTextOnPressedEnter?: boolean
32
33
  }
33
34
 
34
35
  const KTextArea: React.FC<KTextAreaProps> = (props) => {
35
36
  const [background, setBackground] = useState("#F5F5F5")
36
37
  const [hover, setHover] = useState(false)
37
38
 
39
+ const textAreaRef = useRef<HTMLTextAreaElement>(null)
40
+
38
41
  useEffect(() => {
39
42
  const emptyBackground = props.background || "#F5F5F5"
40
43
  const activeBackground = props.activeBackground || "#FFF"
@@ -63,11 +66,14 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
63
66
 
64
67
  const autoResize = props.maxHeight && props.maxHeight !== props.height
65
68
  const maxHeight = props.maxHeight || 200
69
+ const clearTextOnPressedEnter = props.clearTextOnPressedEnter || false
66
70
 
67
71
  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
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
+ }
71
77
  }
72
78
 
73
79
  return (
@@ -93,6 +99,7 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
93
99
  )}
94
100
 
95
101
  <textarea
102
+ ref={textAreaRef}
96
103
  className={"k-input"}
97
104
  style={{
98
105
  background: hover ? hoverBackground : background,
@@ -121,6 +128,20 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
121
128
  }}
122
129
  onKeyDown={(event) => {
123
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
+ }
124
145
  }}
125
146
  />
126
147