kahuna-base-react-components 0.2.20 → 0.2.21

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.
@@ -0,0 +1,32 @@
1
+ import React, { KeyboardEvent } from "react";
2
+ import "../../main.css";
3
+ export interface KTextAreaProps {
4
+ value: string;
5
+ onChange: (value: string) => void;
6
+ rows?: number;
7
+ onBlur?: (value: string) => void;
8
+ onKeyDown?: (event: KeyboardEvent) => void;
9
+ width?: number;
10
+ height?: number;
11
+ leftIcon?: string;
12
+ rightIcon?: string;
13
+ background?: string;
14
+ activeBackground?: string;
15
+ borderRadius?: number;
16
+ disabled?: boolean;
17
+ placeholder?: string;
18
+ shadowDisabled?: boolean;
19
+ leftIconClick?: () => void;
20
+ rightIconClick?: () => void;
21
+ accentColor?: string;
22
+ hoverBackground?: string;
23
+ padding?: string;
24
+ gap?: string;
25
+ border?: string;
26
+ boxShadow?: string;
27
+ fontSize?: string;
28
+ iconSize?: string;
29
+ checked?: boolean;
30
+ }
31
+ declare const KTextArea: React.FC<KTextAreaProps>;
32
+ export default KTextArea;
@@ -0,0 +1 @@
1
+ export { default } from './KTextArea';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -0,0 +1,65 @@
1
+ import { Meta, StoryFn } from "@storybook/react"
2
+ import KTextArea from "./KTextArea"
3
+ // @ts-ignore
4
+ import TracksIcon from "../../assets/tracks.svg"
5
+ import { KeyboardEvent } from "react"
6
+
7
+ export default {
8
+ title: "ReactComponentLibrary/KTextArea",
9
+ component: KTextArea,
10
+ parameters: {
11
+ layout: "centered"
12
+ }
13
+ } as Meta<typeof KTextArea>
14
+
15
+ const Template: StoryFn<typeof KTextArea> = (args) => <KTextArea {...args} />
16
+
17
+
18
+ export const KTextAreaPrimary = Template.bind({})
19
+ KTextAreaPrimary.args = {
20
+ onChange: (value: string) => {
21
+ console.log("value:", value)
22
+ },
23
+ onKeyDown: (event: KeyboardEvent) => {
24
+ if (event.key === "Enter") {
25
+ console.log("Enter is clicked and our value is:", event.currentTarget)
26
+ }
27
+ },
28
+ rows: 4,
29
+ placeholder: "Placeholder...",
30
+ hoverBackground: "white"
31
+ }
32
+
33
+ export const KTextAreaLeftIcon = Template.bind({})
34
+ KTextAreaLeftIcon.args = {
35
+ onChange: (value: string) => {},
36
+ placeholder: "Placeholder...",
37
+ leftIcon: TracksIcon,
38
+ leftIconClick: () => {
39
+ alert("left icon clicked")
40
+ }
41
+ }
42
+
43
+ export const KTextAreaRightIcon = Template.bind({})
44
+ KTextAreaRightIcon.args = {
45
+ onChange: (value: string) => {},
46
+ placeholder: "Placeholder...",
47
+ rightIcon: TracksIcon,
48
+ rightIconClick: () => {
49
+ alert("right icon clicked")
50
+ }
51
+ }
52
+
53
+ export const KTextAreaLeftRightIcon = Template.bind({})
54
+ KTextAreaLeftRightIcon.args = {
55
+ onChange: (value: string) => {},
56
+ placeholder: "Placeholder...",
57
+ leftIcon: TracksIcon,
58
+ rightIcon: TracksIcon,
59
+ leftIconClick: () => {
60
+ alert("left icon clicked")
61
+ },
62
+ rightIconClick: () => {
63
+ alert("right icon clicked")
64
+ }
65
+ }
@@ -0,0 +1,130 @@
1
+ import React, { useEffect, useState, KeyboardEvent } from "react"
2
+ import "../../main.css"
3
+
4
+ export interface KTextAreaProps {
5
+ value: string
6
+ onChange: (value: string) => void
7
+ rows?: number
8
+ onBlur?: (value: string) => void
9
+ onKeyDown?: (event: KeyboardEvent) => void
10
+ width?: number
11
+ height?: number
12
+ leftIcon?: string
13
+ rightIcon?: string
14
+ background?: string
15
+ activeBackground?: string
16
+ borderRadius?: number
17
+ disabled?: boolean
18
+ placeholder?: string
19
+ shadowDisabled?: boolean
20
+ leftIconClick?: () => void
21
+ rightIconClick?: () => void
22
+ accentColor?: string
23
+ hoverBackground?: string
24
+ padding?: string
25
+ gap?: string
26
+ border?: string
27
+ boxShadow?: string
28
+ fontSize?: string
29
+ iconSize?: string
30
+ checked?: boolean
31
+ }
32
+
33
+ const KTextArea: React.FC<KTextAreaProps> = (props) => {
34
+ const [background, setBackground] = useState("#F5F5F5")
35
+ const [hover, setHover] = useState(false)
36
+
37
+ useEffect(() => {
38
+ const emptyBackground = props.background || "#F5F5F5"
39
+ const activeBackground = props.activeBackground || "#FFF"
40
+
41
+ const background = props.value ? activeBackground : emptyBackground
42
+ setBackground(background)
43
+ }, [props.value])
44
+
45
+ const width = props.width || "100%"
46
+ const height = props.height || 60
47
+ const borderRadius = props.borderRadius || 10
48
+ const boxShadow = props.shadowDisabled
49
+ ? ""
50
+ : props.boxShadow
51
+ ? props.boxShadow
52
+ : "0 0 0 1px rgba(17, 17, 17, 0.04), 0 1px 1px 0 rgba(17, 17, 17, 0.04)"
53
+ const accentColor = props.accentColor || ""
54
+ const disabled = props.disabled || false
55
+ const hoverBackground = props.hoverBackground || background
56
+ const padding = props.padding || "8px"
57
+ const gap = props.gap || "12px"
58
+ const border = props.border || "none"
59
+ const fontSize = props.fontSize || "14px"
60
+ const iconSize = props.iconSize || "20px"
61
+ const rows = props.rows || 2
62
+
63
+ return (
64
+ <div
65
+ onMouseEnter={() => setHover(true)}
66
+ onMouseLeave={() => setHover(false)}
67
+ className={"k-input-container"}
68
+ style={{ background: hover ? hoverBackground : background, borderRadius, boxShadow, padding, gap, border }}
69
+ >
70
+ {props.leftIcon && (
71
+ <img
72
+ src={props.leftIcon}
73
+ style={{
74
+ width: iconSize,
75
+ height: iconSize
76
+ }}
77
+ alt={"l-icon"}
78
+ className={props.leftIconClick && "cursor-pointer"}
79
+ onClick={() => {
80
+ if (props.leftIconClick) props.leftIconClick()
81
+ }}
82
+ />
83
+ )}
84
+
85
+ <textarea
86
+ className={"k-input"}
87
+ style={{
88
+ background: hover ? hoverBackground : background,
89
+ width,
90
+ height,
91
+ accentColor,
92
+ fontSize
93
+ }}
94
+ rows={rows}
95
+ value={props.value}
96
+ placeholder={props.placeholder || ""}
97
+ disabled={disabled}
98
+ onBlur={(event) => {
99
+ console.log("onBulur", event.target.value)
100
+ if (props.onBlur) props.onBlur(event.target.value)
101
+ }}
102
+ onChange={(event) => {
103
+ console.log("OnChange", event.target.value)
104
+ props.onChange(event.target.value)
105
+ }}
106
+ onKeyDown={(event) => {
107
+ console.log("OnKeyDown", event)
108
+ if (props.onKeyDown) props.onKeyDown(event)
109
+ }}
110
+ />
111
+
112
+ {props.rightIcon && (
113
+ <img
114
+ src={props.rightIcon}
115
+ style={{
116
+ width: iconSize,
117
+ height: iconSize
118
+ }}
119
+ alt={"r-icon"}
120
+ className={props.rightIconClick && "cursor-pointer"}
121
+ onClick={() => {
122
+ if (props.rightIconClick) props.rightIconClick()
123
+ }}
124
+ />
125
+ )}
126
+ </div>
127
+ )
128
+ }
129
+
130
+ export default KTextArea
@@ -0,0 +1 @@
1
+ export {default} from './KTextArea';