@agility/plenum-ui 2.0.0-rc1 → 2.0.0-rc10
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/README.md +1 -1
- package/build.js +8 -0
- package/dist/index.d.ts +1117 -0
- package/dist/index.js +515 -155
- package/dist/index.js.map +4 -4
- package/dist/lib/tailwind.css +63535 -0
- package/dist/types/stories/atoms/buttons/Button/Alternative/Alternative.stories.d.ts +1 -0
- package/dist/types/stories/atoms/buttons/Button/Button.d.ts +6 -4
- package/dist/types/stories/atoms/buttons/Button/Danger/Danger.stories.d.ts +1 -0
- package/dist/types/stories/atoms/buttons/Button/Primary/Primary.stories.d.ts +1 -0
- package/dist/types/stories/atoms/buttons/Button/Secondary/Secondary.stories.d.ts +1 -0
- package/dist/types/stories/index.d.ts +4 -4
- package/dist/types/stories/molecules/index.d.ts +3 -3
- package/dist/types/stories/molecules/inputs/InputCounter/InputCounter.d.ts +10 -0
- package/dist/types/stories/molecules/inputs/InputCounter/index.d.ts +2 -0
- package/dist/types/stories/molecules/inputs/InputField/InputField.d.ts +3 -1
- package/dist/types/stories/molecules/inputs/TextInput/TextInput.d.ts +39 -0
- package/dist/types/stories/molecules/inputs/TextInput/index.d.ts +4 -0
- package/dist/types/stories/molecules/inputs/index.d.ts +5 -4
- package/dist/types/stories/molecules/inputs/select/Select.d.ts +2 -2
- package/dist/types/stories/molecules/inputs/textArea/TextArea.d.ts +30 -21
- package/dist/types/stories/molecules/inputs/textArea/TextArea.stories.d.ts +4 -4
- package/dist/types/stories/molecules/inputs/textArea/index.d.ts +3 -3
- package/dist/types/stories/organisms/AnimatedLabelInput/AnimatedLabelInput.d.ts +2 -2
- package/dist/types/stories/organisms/DropdownComponent/DropdownComponent.d.ts +3 -7
- package/dist/types/stories/organisms/TextInputSelect/InputSelect.d.ts +16 -0
- package/dist/types/stories/organisms/TextInputSelect/TextInputSelect.d.ts +48 -0
- package/dist/types/stories/organisms/TextInputSelect/index.d.ts +3 -0
- package/dist/types/stories/organisms/index.d.ts +3 -2
- package/package.json +4 -3
- package/stories/Introduction.mdx +1 -1
- package/stories/atoms/buttons/Button/Alternative/Alternative.stories.ts +7 -0
- package/stories/atoms/buttons/Button/Button.tsx +25 -2
- package/stories/atoms/buttons/Button/Danger/Danger.stories.ts +7 -0
- package/stories/atoms/buttons/Button/Primary/Primary.stories.ts +7 -0
- package/stories/atoms/buttons/Button/Secondary/Secondary.stories.ts +7 -0
- package/stories/index.ts +18 -8
- package/stories/molecules/index.ts +22 -6
- package/stories/molecules/inputs/InputCounter/InputCounter.stories.tsx +18 -0
- package/stories/molecules/inputs/InputCounter/InputCounter.tsx +24 -0
- package/stories/molecules/inputs/InputCounter/index.tsx +3 -0
- package/stories/molecules/inputs/InputField/InputField.tsx +7 -1
- package/stories/molecules/inputs/TextInput/TextInput.stories.tsx +32 -0
- package/stories/molecules/inputs/TextInput/TextInput.tsx +162 -0
- package/stories/molecules/inputs/TextInput/index.tsx +5 -0
- package/stories/molecules/inputs/index.ts +18 -4
- package/stories/molecules/inputs/select/Select.tsx +1 -1
- package/stories/molecules/inputs/textArea/TextArea.stories.ts +7 -5
- package/stories/molecules/inputs/textArea/TextArea.tsx +110 -49
- package/stories/molecules/inputs/textArea/index.ts +3 -3
- package/stories/organisms/AnimatedLabelInput/AnimatedLabelInput.tsx +3 -3
- package/stories/organisms/DropdownComponent/DropdownComponent.tsx +111 -80
- package/stories/organisms/DropdownComponent/dropdownItems.ts +8 -8
- package/stories/organisms/TextInputSelect/InputSelect.tsx +59 -0
- package/stories/organisms/TextInputSelect/TextInputSelect.stories.tsx +33 -0
- package/stories/organisms/TextInputSelect/TextInputSelect.tsx +186 -0
- package/stories/organisms/TextInputSelect/index.tsx +3 -0
- package/stories/organisms/index.ts +4 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { default as cn } from "classnames"
|
|
3
3
|
import InputField, { IInputFieldProps } from "@/stories/molecules/inputs/InputField"
|
|
4
|
-
import
|
|
4
|
+
import Textarea, { ITextareaProps } from "@/stories/molecules/inputs/textArea/TextArea"
|
|
5
5
|
|
|
6
6
|
interface ILabelProps extends React.ComponentPropsWithoutRef<"label"> {
|
|
7
7
|
display: string
|
|
@@ -12,7 +12,7 @@ export interface IAnimatedLabelInputProps {
|
|
|
12
12
|
containerStyles?: string
|
|
13
13
|
message?: string
|
|
14
14
|
input?: IInputFieldProps
|
|
15
|
-
textarea?:
|
|
15
|
+
textarea?: ITextareaProps
|
|
16
16
|
required?: boolean
|
|
17
17
|
isError?: boolean
|
|
18
18
|
label: ILabelProps
|
|
@@ -31,7 +31,7 @@ const AnimatedLabelInput: React.FC<IAnimatedLabelInputProps> = ({
|
|
|
31
31
|
return (
|
|
32
32
|
<div className={cn("group relative", containerStyles ? containerStyles : "")}>
|
|
33
33
|
{input && <InputField isError={isError} {...input} />}
|
|
34
|
-
{textarea && <
|
|
34
|
+
{textarea && <Textarea isError={isError} {...textarea} />}
|
|
35
35
|
<label
|
|
36
36
|
className={cn(
|
|
37
37
|
"absolute left-1 z-10 ml-[.172rem] inline-block bg-white px-1 text-xs transition-all peer-placeholder-shown:top-2 peer-placeholder-shown:text-sm peer-placeholder-shown:text-gray-600",
|
|
@@ -18,15 +18,11 @@ import {
|
|
|
18
18
|
} from "@floating-ui/react"
|
|
19
19
|
|
|
20
20
|
import { ClassNameWithAutocomplete } from "utils/types"
|
|
21
|
-
import { DynamicIcon, IDynamicIconProps } from "@/stories/atoms/icons"
|
|
21
|
+
import { DynamicIcon, IDynamicIconProps, UnifiedIconName } from "@/stories/atoms/icons"
|
|
22
22
|
|
|
23
23
|
export interface IItemProp extends HTMLAttributes<HTMLButtonElement> {
|
|
24
|
-
icon?:
|
|
25
|
-
|
|
26
|
-
className?: ClassNameWithAutocomplete
|
|
27
|
-
pos?: "trailing" | "leading"
|
|
28
|
-
outline?: boolean
|
|
29
|
-
}
|
|
24
|
+
icon?: IDynamicIconProps | UnifiedIconName
|
|
25
|
+
iconPosition?: "trailing" | "leading"
|
|
30
26
|
label: string
|
|
31
27
|
onClick?(): void
|
|
32
28
|
isEmphasized?: boolean
|
|
@@ -180,80 +176,115 @@ const Dropdown: React.FC<IDropdownProps> = ({
|
|
|
180
176
|
{items.map((itemStack, idx) => {
|
|
181
177
|
return (
|
|
182
178
|
<React.Fragment key={`${idx}-list-${id}`}>
|
|
183
|
-
{itemStack.map(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
179
|
+
{itemStack.map(
|
|
180
|
+
({
|
|
181
|
+
onClick,
|
|
182
|
+
label,
|
|
183
|
+
key,
|
|
184
|
+
isEmphasized,
|
|
185
|
+
icon,
|
|
186
|
+
iconPosition,
|
|
187
|
+
...rest
|
|
188
|
+
}) => {
|
|
189
|
+
const active = activeItem && activeItem === key
|
|
190
|
+
const itemClass = cn(
|
|
191
|
+
itemClassname,
|
|
192
|
+
"group flex cursor-pointer items-center px-4 py-2 text-sm transition-all",
|
|
193
|
+
{
|
|
194
|
+
"text-red-500": isEmphasized
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"text-gray-900": !isEmphasized
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"bg-gray-100 text-gray-900": active
|
|
201
|
+
},
|
|
202
|
+
active ? activeItemClassname : "",
|
|
203
|
+
{
|
|
204
|
+
"bg-gray-100 text-red-500 hover:text-red-500":
|
|
205
|
+
active && isEmphasized
|
|
206
|
+
},
|
|
207
|
+
itemClassname
|
|
208
|
+
)
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
210
|
+
return (
|
|
211
|
+
<li key={key}>
|
|
212
|
+
<button
|
|
213
|
+
{...{
|
|
214
|
+
onClick: () => {
|
|
215
|
+
setActiveItem(key)
|
|
216
|
+
onClick && onClick()
|
|
217
|
+
},
|
|
218
|
+
key,
|
|
219
|
+
className: cn(itemClass, "w-full"),
|
|
220
|
+
...rest
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div className="flex items-center gap-x-4">
|
|
224
|
+
{icon &&
|
|
225
|
+
(iconPosition === "leading" ||
|
|
226
|
+
iconPosition === undefined) &&
|
|
227
|
+
(typeof icon === "string" ? (
|
|
228
|
+
<DynamicIcon
|
|
229
|
+
{...{
|
|
230
|
+
icon: icon,
|
|
231
|
+
className: cn(
|
|
232
|
+
{
|
|
233
|
+
"text-red-500": isEmphasized
|
|
234
|
+
},
|
|
235
|
+
"opacity-60 group"
|
|
236
|
+
)
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
239
|
+
) : (
|
|
240
|
+
<DynamicIcon
|
|
241
|
+
{...{
|
|
242
|
+
...icon,
|
|
243
|
+
className: cn(
|
|
244
|
+
icon.className,
|
|
245
|
+
{
|
|
246
|
+
"text-red-500": isEmphasized
|
|
247
|
+
},
|
|
248
|
+
"opacity-60 group"
|
|
249
|
+
)
|
|
250
|
+
}}
|
|
251
|
+
/>
|
|
252
|
+
))}
|
|
253
|
+
<div className="whitespace-nowrap">{label}</div>
|
|
254
|
+
{icon &&
|
|
255
|
+
iconPosition === "trailing" &&
|
|
256
|
+
(typeof icon === "string" ? (
|
|
257
|
+
<DynamicIcon
|
|
258
|
+
{...{
|
|
259
|
+
icon: icon,
|
|
260
|
+
className: cn(
|
|
261
|
+
{
|
|
262
|
+
"text-red-500": isEmphasized
|
|
263
|
+
},
|
|
264
|
+
"opacity-60 group"
|
|
265
|
+
)
|
|
266
|
+
}}
|
|
267
|
+
/>
|
|
268
|
+
) : (
|
|
269
|
+
<DynamicIcon
|
|
270
|
+
{...{
|
|
271
|
+
...icon,
|
|
272
|
+
className: cn(
|
|
273
|
+
icon.className,
|
|
274
|
+
{
|
|
275
|
+
"text-red-500": isEmphasized
|
|
276
|
+
},
|
|
277
|
+
"opacity-60 group"
|
|
278
|
+
)
|
|
279
|
+
}}
|
|
280
|
+
/>
|
|
281
|
+
))}
|
|
282
|
+
</div>
|
|
283
|
+
</button>
|
|
284
|
+
</li>
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
)}
|
|
257
288
|
</React.Fragment>
|
|
258
289
|
)
|
|
259
290
|
})}
|
|
@@ -42,11 +42,11 @@ export const dropdownDataWithIcons: IItemProp[][] = [
|
|
|
42
42
|
[
|
|
43
43
|
{
|
|
44
44
|
icon: {
|
|
45
|
-
|
|
46
|
-
pos: "leading",
|
|
45
|
+
icon: "IconClipboardCopy",
|
|
47
46
|
className: "h-5 w-5",
|
|
48
47
|
outline: false
|
|
49
48
|
},
|
|
49
|
+
iconPosition: "leading",
|
|
50
50
|
key: "Copy",
|
|
51
51
|
label: "Copy",
|
|
52
52
|
onClick: () => {
|
|
@@ -57,11 +57,11 @@ export const dropdownDataWithIcons: IItemProp[][] = [
|
|
|
57
57
|
[
|
|
58
58
|
{
|
|
59
59
|
icon: {
|
|
60
|
-
|
|
61
|
-
pos: "leading",
|
|
60
|
+
icon: "IconFolderPlus",
|
|
62
61
|
className: "h-5 w-5",
|
|
63
62
|
outline: false
|
|
64
63
|
},
|
|
64
|
+
iconPosition: "leading",
|
|
65
65
|
key: "Add to Batch",
|
|
66
66
|
label: "Add to Batch",
|
|
67
67
|
onClick: () => {
|
|
@@ -70,11 +70,11 @@ export const dropdownDataWithIcons: IItemProp[][] = [
|
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
icon: {
|
|
73
|
-
|
|
74
|
-
pos: "leading",
|
|
73
|
+
icon: "IconEye",
|
|
75
74
|
className: "h-5 w-5",
|
|
76
75
|
outline: false
|
|
77
76
|
},
|
|
77
|
+
iconPosition: "leading",
|
|
78
78
|
key: "View Batch",
|
|
79
79
|
label: "View Batch",
|
|
80
80
|
onClick: () => {
|
|
@@ -85,11 +85,11 @@ export const dropdownDataWithIcons: IItemProp[][] = [
|
|
|
85
85
|
[
|
|
86
86
|
{
|
|
87
87
|
icon: {
|
|
88
|
-
|
|
89
|
-
pos: "leading",
|
|
88
|
+
icon: "IconTrash",
|
|
90
89
|
className: "h-5 w-5",
|
|
91
90
|
outline: false
|
|
92
91
|
},
|
|
92
|
+
iconPosition: "leading",
|
|
93
93
|
key: "Delete",
|
|
94
94
|
label: "Delete",
|
|
95
95
|
onClick: () => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { FC, useState } from "react"
|
|
2
|
+
import { default as cn } from "classnames"
|
|
3
|
+
|
|
4
|
+
export type SelectOptions = {
|
|
5
|
+
label: string
|
|
6
|
+
value: string
|
|
7
|
+
}
|
|
8
|
+
export interface InputSelectProps {
|
|
9
|
+
align: "left" | "right"
|
|
10
|
+
/** Show the CTA without Background color and a border seperator */
|
|
11
|
+
inputOptions: SelectOptions[]
|
|
12
|
+
/** Onclick callback */
|
|
13
|
+
onSelectOption?(value: string): void
|
|
14
|
+
className?: string
|
|
15
|
+
isDisabled?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Comment */
|
|
19
|
+
export const InputSelect: FC<InputSelectProps> = ({
|
|
20
|
+
inputOptions,
|
|
21
|
+
onSelectOption,
|
|
22
|
+
align = "right",
|
|
23
|
+
className,
|
|
24
|
+
isDisabled
|
|
25
|
+
}: InputSelectProps): JSX.Element | null => {
|
|
26
|
+
const [selectedOption, setSelectedOption] = useState<string>(inputOptions[0].value)
|
|
27
|
+
|
|
28
|
+
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
29
|
+
const targetValue = e.target.value
|
|
30
|
+
onSelectOption && onSelectOption(targetValue)
|
|
31
|
+
setSelectedOption(targetValue)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!inputOptions?.length) return null
|
|
35
|
+
return (
|
|
36
|
+
<select
|
|
37
|
+
className={cn(
|
|
38
|
+
"relative z-10 inline-flex items-center space-x-2 border border-gray-300 bg-white px-4 py-2 pr-7 text-sm font-medium",
|
|
39
|
+
"focus:border-purple-500 focus:outline-none focus:ring-1 focus:ring-purple-500",
|
|
40
|
+
align === "right"
|
|
41
|
+
? "-ml-px rounded-r border-l-white text-gray-700"
|
|
42
|
+
: align === "left"
|
|
43
|
+
? "-mr-px rounded-l border-r-white text-gray-500 focus-within:z-10"
|
|
44
|
+
: "",
|
|
45
|
+
!onSelectOption ? "cursor-default" : "",
|
|
46
|
+
className
|
|
47
|
+
)}
|
|
48
|
+
onChange={handleChange}
|
|
49
|
+
value={selectedOption}
|
|
50
|
+
disabled={isDisabled}
|
|
51
|
+
>
|
|
52
|
+
{inputOptions.map((option) => (
|
|
53
|
+
<option key={option.value} value={option.value}>
|
|
54
|
+
{option.label}
|
|
55
|
+
</option>
|
|
56
|
+
))}
|
|
57
|
+
</select>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
+
import TextInputSelect from "."
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof TextInputSelect> = {
|
|
5
|
+
title: "Design System/organisms/TextInputSelect",
|
|
6
|
+
component: TextInputSelect,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
argTypes: {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default meta
|
|
12
|
+
type Story = StoryObj<typeof TextInputSelect>
|
|
13
|
+
export const DefaultTextInputSelectStory: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
isFocused: false,
|
|
16
|
+
isError: false,
|
|
17
|
+
id: "input",
|
|
18
|
+
name: "input",
|
|
19
|
+
defaultValue: "",
|
|
20
|
+
isRequired: false,
|
|
21
|
+
isDisabled: false,
|
|
22
|
+
isShowCounter: false,
|
|
23
|
+
label: "Currency",
|
|
24
|
+
placeholder: "420.69",
|
|
25
|
+
type: "currency",
|
|
26
|
+
inputOptions: [
|
|
27
|
+
{ label: "USD", value: "USD" },
|
|
28
|
+
{ label: "CAD", value: "CAD" },
|
|
29
|
+
{ label: "EUR", value: "EUR" }
|
|
30
|
+
],
|
|
31
|
+
prefix: "$"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import React, { FC, useEffect, useId, useRef, useState } from "react"
|
|
2
|
+
import { default as cn } from "classnames"
|
|
3
|
+
|
|
4
|
+
import { InputSelect } from "./InputSelect"
|
|
5
|
+
import { AcceptedInputTypes, InputField } from "@/stories/molecules"
|
|
6
|
+
import InputCounter from "@/stories/molecules/inputs/InputCounter"
|
|
7
|
+
|
|
8
|
+
export type SelectOptions = {
|
|
9
|
+
label: string
|
|
10
|
+
value: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ITextInputSelectProps {
|
|
14
|
+
/** Input type*/
|
|
15
|
+
type: AcceptedInputTypes
|
|
16
|
+
/** Input ID */
|
|
17
|
+
id?: string
|
|
18
|
+
/** Input Name */
|
|
19
|
+
name?: string
|
|
20
|
+
/** Label for the input */
|
|
21
|
+
label?: string
|
|
22
|
+
/** placeholder for the input */
|
|
23
|
+
placeholder?: string
|
|
24
|
+
/** Force the focus state on the input */
|
|
25
|
+
isFocused?: boolean
|
|
26
|
+
/** Error state */
|
|
27
|
+
isError?: boolean
|
|
28
|
+
/** If field is required */
|
|
29
|
+
isRequired?: boolean
|
|
30
|
+
/** Disabled state */
|
|
31
|
+
isDisabled?: boolean
|
|
32
|
+
/** Set default value */
|
|
33
|
+
defaultValue?: string
|
|
34
|
+
/** Set value */
|
|
35
|
+
value: string
|
|
36
|
+
/** Message shown under the text field */
|
|
37
|
+
message?: string
|
|
38
|
+
/** Input character counter */
|
|
39
|
+
isShowCounter?: boolean
|
|
40
|
+
/** Max length of input character */
|
|
41
|
+
maxLength?: number
|
|
42
|
+
/** Select input location */
|
|
43
|
+
selectLocation?: "left" | "right"
|
|
44
|
+
/** Prefix */
|
|
45
|
+
prefix?: string
|
|
46
|
+
/** List of options to show on the select field */
|
|
47
|
+
inputOptions?: SelectOptions[]
|
|
48
|
+
/** Callback on base input */
|
|
49
|
+
onChange?(value: string): void
|
|
50
|
+
/** Callback on input select field */
|
|
51
|
+
onSelectOption?(value: string): void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const TextInputSelect: FC<ITextInputSelectProps> = ({
|
|
55
|
+
label,
|
|
56
|
+
isFocused,
|
|
57
|
+
isError,
|
|
58
|
+
id,
|
|
59
|
+
name,
|
|
60
|
+
isRequired,
|
|
61
|
+
type,
|
|
62
|
+
defaultValue,
|
|
63
|
+
isDisabled,
|
|
64
|
+
message,
|
|
65
|
+
isShowCounter,
|
|
66
|
+
maxLength,
|
|
67
|
+
placeholder,
|
|
68
|
+
inputOptions,
|
|
69
|
+
selectLocation = "right",
|
|
70
|
+
prefix,
|
|
71
|
+
onChange,
|
|
72
|
+
onSelectOption,
|
|
73
|
+
value: externalValue
|
|
74
|
+
}: ITextInputSelectProps) => {
|
|
75
|
+
const [isFocus, setIsFocus] = useState<boolean>(Boolean(isFocused))
|
|
76
|
+
const [value, setValue] = useState<string>(defaultValue || "")
|
|
77
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
78
|
+
|
|
79
|
+
const uniqueID = useId()
|
|
80
|
+
if (!id) id = `select-${uniqueID}`
|
|
81
|
+
if (!name) name = id
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
setValue(externalValue)
|
|
85
|
+
}, [externalValue])
|
|
86
|
+
|
|
87
|
+
// set force focus
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const input = inputRef.current
|
|
90
|
+
if (!input || isFocus === undefined || isFocused === undefined || isDisabled) return
|
|
91
|
+
if (isFocus || isFocused) {
|
|
92
|
+
input.focus()
|
|
93
|
+
} else {
|
|
94
|
+
input.blur()
|
|
95
|
+
}
|
|
96
|
+
}, [isFocus, isFocused])
|
|
97
|
+
|
|
98
|
+
// set label as active if default value is set
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const input = inputRef.current
|
|
101
|
+
if (!input || defaultValue === undefined || defaultValue === "") return
|
|
102
|
+
}, [defaultValue])
|
|
103
|
+
|
|
104
|
+
const handleInputFocus = (): void => {
|
|
105
|
+
setIsFocus(true)
|
|
106
|
+
// add other focus effects here
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const handleInputBlur = (): void => {
|
|
110
|
+
setIsFocus(false)
|
|
111
|
+
// add other focus effects here
|
|
112
|
+
}
|
|
113
|
+
const labelStyles = cn("block inline-block font-medium transition-all text-sm text-gray-700 mb-1", {
|
|
114
|
+
"text-red-500 bg-white": isError
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const discriptionStyles = cn("text-sm mt-1 block", { "text-gray-500": !isError }, { "text-red-500": isError })
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div>
|
|
121
|
+
{label && (
|
|
122
|
+
<label htmlFor={id} className={labelStyles}>
|
|
123
|
+
{label}
|
|
124
|
+
{isRequired && <span className="text-red-500"> *</span>}
|
|
125
|
+
</label>
|
|
126
|
+
)}
|
|
127
|
+
<div className="flex">
|
|
128
|
+
{inputOptions?.length && selectLocation === "left" && (
|
|
129
|
+
<InputSelect
|
|
130
|
+
inputOptions={inputOptions}
|
|
131
|
+
align="left"
|
|
132
|
+
onSelectOption={onSelectOption}
|
|
133
|
+
className={cn(isError ? "border-red-500" : "")}
|
|
134
|
+
isDisabled={isDisabled}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
<div className="relative flex-grow focus-within:z-20">
|
|
138
|
+
{prefix && (
|
|
139
|
+
<div className="pointer-events-none pr-10 absolute inset-y-0 left-0 flex items-center pl-3">
|
|
140
|
+
<span className="text-gray-500 sm:text-sm">{prefix}</span>
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
<InputField
|
|
144
|
+
onFocus={handleInputFocus}
|
|
145
|
+
onBlur={handleInputBlur}
|
|
146
|
+
handleChange={(v) => onChange && onChange(v)}
|
|
147
|
+
ref={inputRef}
|
|
148
|
+
type={type}
|
|
149
|
+
name={name}
|
|
150
|
+
id={id}
|
|
151
|
+
className={cn(
|
|
152
|
+
"w-full border border-gray-300 py-2 px-3 text-sm font-normal leading-5",
|
|
153
|
+
"focus:border-purple-500 focus:outline-none focus:ring-1 focus:ring-purple-500 sm:text-sm",
|
|
154
|
+
selectLocation === "right" ? `rounded-l` : `rounded-r`,
|
|
155
|
+
isError ? "border-red-500" : "",
|
|
156
|
+
prefix ? `pl-7` : ""
|
|
157
|
+
)}
|
|
158
|
+
isDisabled={isDisabled}
|
|
159
|
+
defaultValue={defaultValue}
|
|
160
|
+
value={value}
|
|
161
|
+
maxLength={maxLength}
|
|
162
|
+
placeholder={placeholder}
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
{inputOptions?.length && selectLocation === "right" && (
|
|
166
|
+
<InputSelect
|
|
167
|
+
inputOptions={inputOptions}
|
|
168
|
+
align={"right"}
|
|
169
|
+
onSelectOption={onSelectOption}
|
|
170
|
+
isDisabled={isDisabled}
|
|
171
|
+
className={cn(isError ? "border-red-500" : "")}
|
|
172
|
+
/>
|
|
173
|
+
)}
|
|
174
|
+
</div>
|
|
175
|
+
<div className="flex flex-row space-x-3">
|
|
176
|
+
<div className="grow">{message && <span className={discriptionStyles}>{message}</span>}</div>
|
|
177
|
+
{isShowCounter && (
|
|
178
|
+
<div className="shrink-0">
|
|
179
|
+
<InputCounter current={Number(value?.length)} limit={maxLength} />
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
export default TextInputSelect
|
|
@@ -3,6 +3,7 @@ import ButtonDropdown, { IButtonDropdownProps } from "./ButtonDropdown"
|
|
|
3
3
|
import Dropdown, { IDropdownClassnames, IDropdownProps, IItemProp } from "./DropdownComponent"
|
|
4
4
|
import EmptySectionPlaceholder, { IEmptySectionPlaceholderProps } from "./EmptySectionPlaceholder"
|
|
5
5
|
import FormInputWithAddons, { IFormInputWithAddonsProps } from "./FormInputWithAddons"
|
|
6
|
+
import TextInputSelect, { ITextInputSelectProps } from "./TextInputSelect"
|
|
6
7
|
|
|
7
8
|
export type {
|
|
8
9
|
IAnimatedLabelInputProps,
|
|
@@ -11,6 +12,7 @@ export type {
|
|
|
11
12
|
IDropdownProps,
|
|
12
13
|
IEmptySectionPlaceholderProps,
|
|
13
14
|
IItemProp,
|
|
14
|
-
IFormInputWithAddonsProps
|
|
15
|
+
IFormInputWithAddonsProps,
|
|
16
|
+
ITextInputSelectProps
|
|
15
17
|
}
|
|
16
|
-
export { AnimatedLabelInput, ButtonDropdown, Dropdown, EmptySectionPlaceholder, FormInputWithAddons }
|
|
18
|
+
export { AnimatedLabelInput, ButtonDropdown, Dropdown, EmptySectionPlaceholder, FormInputWithAddons, TextInputSelect }
|