@agility/plenum-ui 2.0.0-rc1 → 2.0.0-rc11
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/AnimatedLabelInput/index.d.ts +1 -1
- package/dist/types/stories/organisms/DropdownComponent/DropdownComponent.d.ts +3 -7
- package/dist/types/stories/organisms/EmptySectionPlaceholder/index.d.ts +1 -1
- 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/molecules/tabs/index.tsx +2 -3
- package/stories/organisms/AnimatedLabelInput/AnimatedLabelInput.tsx +3 -3
- package/stories/organisms/AnimatedLabelInput/index.tsx +1 -1
- package/stories/organisms/DropdownComponent/DropdownComponent.tsx +111 -80
- package/stories/organisms/DropdownComponent/dropdownItems.ts +8 -8
- package/stories/organisms/EmptySectionPlaceholder/index.tsx +2 -1
- 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
package/stories/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
INestedInputButtonProps,
|
|
35
35
|
IRadioProps,
|
|
36
36
|
ISelectProps,
|
|
37
|
-
|
|
37
|
+
ITextareaProps,
|
|
38
38
|
IToggleSwitchProps,
|
|
39
39
|
AcceptedInputTypes,
|
|
40
40
|
Checkbox,
|
|
@@ -44,8 +44,11 @@ import {
|
|
|
44
44
|
NestedInputButton,
|
|
45
45
|
Radio,
|
|
46
46
|
Select,
|
|
47
|
-
|
|
48
|
-
ToggleSwitch
|
|
47
|
+
Textarea,
|
|
48
|
+
ToggleSwitch,
|
|
49
|
+
TextInput,
|
|
50
|
+
ITextInputProps,
|
|
51
|
+
ISimpleSelectOptions
|
|
49
52
|
} from "./molecules"
|
|
50
53
|
// Organism Components, props, and type gaurds.
|
|
51
54
|
import {
|
|
@@ -60,7 +63,9 @@ import {
|
|
|
60
63
|
ButtonDropdown,
|
|
61
64
|
Dropdown,
|
|
62
65
|
EmptySectionPlaceholder,
|
|
63
|
-
FormInputWithAddons
|
|
66
|
+
FormInputWithAddons,
|
|
67
|
+
TextInputSelect,
|
|
68
|
+
ITextInputSelectProps
|
|
64
69
|
} from "./organisms"
|
|
65
70
|
|
|
66
71
|
export type {
|
|
@@ -68,6 +73,7 @@ export type {
|
|
|
68
73
|
IBadgeProps,
|
|
69
74
|
IButtonProps,
|
|
70
75
|
ICapsuleProps,
|
|
76
|
+
ITextInputSelectProps,
|
|
71
77
|
IDynamicIconProps,
|
|
72
78
|
IIconWithShadowProps,
|
|
73
79
|
ILoaderProps,
|
|
@@ -79,7 +85,7 @@ export type {
|
|
|
79
85
|
INestedInputButtonProps,
|
|
80
86
|
IRadioProps,
|
|
81
87
|
ISelectProps,
|
|
82
|
-
|
|
88
|
+
ITextareaProps,
|
|
83
89
|
IToggleSwitchProps,
|
|
84
90
|
AcceptedInputTypes,
|
|
85
91
|
IAnimatedLabelInputProps,
|
|
@@ -92,7 +98,9 @@ export type {
|
|
|
92
98
|
UnifiedIconName,
|
|
93
99
|
IconName,
|
|
94
100
|
FAIconName,
|
|
95
|
-
BTNActionType
|
|
101
|
+
BTNActionType,
|
|
102
|
+
ITextInputProps,
|
|
103
|
+
ISimpleSelectOptions
|
|
96
104
|
}
|
|
97
105
|
export {
|
|
98
106
|
Avatar,
|
|
@@ -103,7 +111,7 @@ export {
|
|
|
103
111
|
NestedInputButton,
|
|
104
112
|
Radio,
|
|
105
113
|
Select,
|
|
106
|
-
|
|
114
|
+
Textarea,
|
|
107
115
|
ToggleSwitch,
|
|
108
116
|
AnimatedLabelInput,
|
|
109
117
|
ButtonDropdown,
|
|
@@ -120,5 +128,7 @@ export {
|
|
|
120
128
|
isFAIcon,
|
|
121
129
|
isHeroIcon,
|
|
122
130
|
isTablerIcon,
|
|
123
|
-
isUnifiedIconName
|
|
131
|
+
isUnifiedIconName,
|
|
132
|
+
TextInput,
|
|
133
|
+
TextInputSelect
|
|
124
134
|
}
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
INestedInputButtonProps,
|
|
7
7
|
IRadioProps,
|
|
8
8
|
ISelectProps,
|
|
9
|
-
|
|
9
|
+
ISimpleSelectOptions,
|
|
10
|
+
ITextareaProps,
|
|
10
11
|
IToggleSwitchProps,
|
|
11
12
|
AcceptedInputTypes,
|
|
12
13
|
Checkbox,
|
|
@@ -16,8 +17,10 @@ import {
|
|
|
16
17
|
NestedInputButton,
|
|
17
18
|
Radio,
|
|
18
19
|
Select,
|
|
19
|
-
|
|
20
|
-
ToggleSwitch
|
|
20
|
+
Textarea,
|
|
21
|
+
ToggleSwitch,
|
|
22
|
+
ITextInputProps,
|
|
23
|
+
TextInput
|
|
21
24
|
} from "./inputs"
|
|
22
25
|
|
|
23
26
|
export type {
|
|
@@ -28,8 +31,21 @@ export type {
|
|
|
28
31
|
INestedInputButtonProps,
|
|
29
32
|
IRadioProps,
|
|
30
33
|
ISelectProps,
|
|
31
|
-
|
|
34
|
+
ISimpleSelectOptions,
|
|
35
|
+
ITextareaProps,
|
|
32
36
|
IToggleSwitchProps,
|
|
33
|
-
AcceptedInputTypes
|
|
37
|
+
AcceptedInputTypes,
|
|
38
|
+
ITextInputProps
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
Checkbox,
|
|
42
|
+
Combobox,
|
|
43
|
+
InputField,
|
|
44
|
+
InputLabel,
|
|
45
|
+
NestedInputButton,
|
|
46
|
+
Radio,
|
|
47
|
+
Select,
|
|
48
|
+
Textarea,
|
|
49
|
+
ToggleSwitch,
|
|
50
|
+
TextInput
|
|
34
51
|
}
|
|
35
|
-
export { Checkbox, Combobox, InputField, InputLabel, NestedInputButton, Radio, Select, TextAreaField, ToggleSwitch }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
+
import InputCounter, { IInputCounterProps } from "./InputCounter"
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof InputCounter> = {
|
|
5
|
+
title: "Design System/molecules/inputs/InputCounter",
|
|
6
|
+
component: InputCounter,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
argTypes: {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default meta
|
|
12
|
+
type Story = StoryObj<typeof InputCounter>
|
|
13
|
+
export const DefaultInputCounterStory: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
limit: 100,
|
|
16
|
+
current: 0
|
|
17
|
+
} as IInputCounterProps
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React, { FC } from "react"
|
|
2
|
+
|
|
3
|
+
export interface IInputCounterProps {
|
|
4
|
+
/** Counter limit */
|
|
5
|
+
limit: number | undefined
|
|
6
|
+
/** Counter current number */
|
|
7
|
+
current: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Primary UI component for user interaction */
|
|
11
|
+
const InputCounter: FC<IInputCounterProps> = ({ current = 0, limit }) => {
|
|
12
|
+
return (
|
|
13
|
+
<div className="mt-1 text-center text-sm text-gray-500 flex gap-1">
|
|
14
|
+
<div className="currentCount">{current}</div>
|
|
15
|
+
{(limit || 0) > 0 && (
|
|
16
|
+
<>
|
|
17
|
+
<div>/</div>
|
|
18
|
+
<div className="limitCount">{limit}</div>
|
|
19
|
+
</>
|
|
20
|
+
)}
|
|
21
|
+
</div>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
export default InputCounter
|
|
@@ -13,6 +13,7 @@ export type AcceptedInputTypes =
|
|
|
13
13
|
| "tel"
|
|
14
14
|
| "text"
|
|
15
15
|
| "url"
|
|
16
|
+
| "currency"
|
|
16
17
|
|
|
17
18
|
export interface IInputFieldProps extends React.ComponentPropsWithoutRef<"input"> {
|
|
18
19
|
/** Callback on change */
|
|
@@ -37,7 +38,8 @@ export interface IInputFieldProps extends React.ComponentPropsWithoutRef<"input"
|
|
|
37
38
|
required?: boolean
|
|
38
39
|
/** use input psuedo classes for :valid and :invalid styles. on by default */
|
|
39
40
|
clientSideCheck?: boolean
|
|
40
|
-
/**
|
|
41
|
+
/**ref for input */
|
|
42
|
+
ref?: React.Ref<HTMLInputElement>
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
const InputField: React.FC<IInputFieldProps> = ({
|
|
@@ -54,16 +56,20 @@ const InputField: React.FC<IInputFieldProps> = ({
|
|
|
54
56
|
clientSideCheck = true,
|
|
55
57
|
placeholder,
|
|
56
58
|
className,
|
|
59
|
+
ref,
|
|
57
60
|
...rest
|
|
58
61
|
}) => {
|
|
62
|
+
|
|
59
63
|
return (
|
|
60
64
|
<input
|
|
61
65
|
{...{
|
|
62
66
|
type,
|
|
63
67
|
id,
|
|
68
|
+
ref,
|
|
64
69
|
name,
|
|
65
70
|
value,
|
|
66
71
|
onChange: (e) => {
|
|
72
|
+
console.log(e)
|
|
67
73
|
handleChange(e.target.value)
|
|
68
74
|
},
|
|
69
75
|
autoFocus: isFocused,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
+
import TextInput, { ITextInputProps } from "./TextInput"
|
|
3
|
+
import React from "react"
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof TextInput> = {
|
|
6
|
+
title: "Design System/molecules/inputs/TextInput",
|
|
7
|
+
component: TextInput,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
argTypes: {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default meta
|
|
13
|
+
type Story = StoryObj<typeof TextInput>
|
|
14
|
+
|
|
15
|
+
export const DefaultTextInputStory: Story = {
|
|
16
|
+
args: {
|
|
17
|
+
type: "text",
|
|
18
|
+
label: "Label",
|
|
19
|
+
isFocused: true,
|
|
20
|
+
isError: false,
|
|
21
|
+
id: "id",
|
|
22
|
+
name: "name",
|
|
23
|
+
isRequired: true,
|
|
24
|
+
|
|
25
|
+
isDisabled: false,
|
|
26
|
+
isReadonly: false,
|
|
27
|
+
message: "message",
|
|
28
|
+
isShowCounter: true,
|
|
29
|
+
maxLength: 100,
|
|
30
|
+
placeholder: "placeholder"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useId, useRef, useState } from "react"
|
|
2
|
+
import { default as cn } from "classnames"
|
|
3
|
+
import InputLabel from "../InputLabel"
|
|
4
|
+
import InputField, { AcceptedInputTypes } from "../InputField"
|
|
5
|
+
import InputCounter from "../InputCounter"
|
|
6
|
+
|
|
7
|
+
export interface ITextInputProps {
|
|
8
|
+
/** Input type*/
|
|
9
|
+
type: AcceptedInputTypes
|
|
10
|
+
/** Input ID */
|
|
11
|
+
id?: string
|
|
12
|
+
/** Input Name */
|
|
13
|
+
name?: string
|
|
14
|
+
/** Label for the input */
|
|
15
|
+
label?: string
|
|
16
|
+
/** Force the focus state on the input */
|
|
17
|
+
isFocused?: boolean
|
|
18
|
+
/** Error state */
|
|
19
|
+
isError?: boolean
|
|
20
|
+
/** If field is required */
|
|
21
|
+
isRequired?: boolean
|
|
22
|
+
/** Disabled state */
|
|
23
|
+
isDisabled?: boolean
|
|
24
|
+
/** Readonly state */
|
|
25
|
+
isReadonly?: boolean
|
|
26
|
+
/** Set default value */
|
|
27
|
+
defaultValue?: string
|
|
28
|
+
/** Message shown under the text field */
|
|
29
|
+
message?: string
|
|
30
|
+
/** Input character counter */
|
|
31
|
+
isShowCounter?: boolean
|
|
32
|
+
/** Max length of input character */
|
|
33
|
+
maxLength?: number
|
|
34
|
+
/** Callback on change */
|
|
35
|
+
onChange(value: string): void
|
|
36
|
+
/** input value */
|
|
37
|
+
value: string
|
|
38
|
+
/**Placeholder input text*/
|
|
39
|
+
placeholder?: string
|
|
40
|
+
|
|
41
|
+
className?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const TextInput = (
|
|
45
|
+
{
|
|
46
|
+
label,
|
|
47
|
+
isFocused,
|
|
48
|
+
isError,
|
|
49
|
+
id,
|
|
50
|
+
name,
|
|
51
|
+
isRequired,
|
|
52
|
+
type,
|
|
53
|
+
defaultValue,
|
|
54
|
+
isDisabled,
|
|
55
|
+
isReadonly,
|
|
56
|
+
message,
|
|
57
|
+
isShowCounter,
|
|
58
|
+
maxLength,
|
|
59
|
+
onChange,
|
|
60
|
+
placeholder,
|
|
61
|
+
value: externalValue,
|
|
62
|
+
className,
|
|
63
|
+
...props
|
|
64
|
+
}: ITextInputProps,
|
|
65
|
+
ref: React.Ref<HTMLInputElement>
|
|
66
|
+
) => {
|
|
67
|
+
const uniqueID = useId()
|
|
68
|
+
const [isFocus, setIsFocus] = useState<boolean>(Boolean(isFocused))
|
|
69
|
+
|
|
70
|
+
const [value, setValue] = useState<string>(externalValue || defaultValue || "")
|
|
71
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
//if the external value is updated by the parent component, reset the value in here...
|
|
75
|
+
if (externalValue !== undefined && externalValue !== null) {
|
|
76
|
+
setValue(externalValue)
|
|
77
|
+
}
|
|
78
|
+
}, [externalValue])
|
|
79
|
+
|
|
80
|
+
// set force focus
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const input = inputRef.current
|
|
83
|
+
if (!input || isFocus === undefined || isDisabled) return
|
|
84
|
+
if (isFocus) {
|
|
85
|
+
input.focus()
|
|
86
|
+
} else {
|
|
87
|
+
input.blur()
|
|
88
|
+
}
|
|
89
|
+
}, [isFocus])
|
|
90
|
+
|
|
91
|
+
// set label as active if default value is set
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const input = inputRef.current
|
|
94
|
+
if (!input || defaultValue === undefined || defaultValue === "") return
|
|
95
|
+
}, [defaultValue])
|
|
96
|
+
|
|
97
|
+
const handleInputFocus = () => setIsFocus(true)
|
|
98
|
+
// add other focus effects here
|
|
99
|
+
|
|
100
|
+
const handleInputBlur = () => setIsFocus(false)
|
|
101
|
+
|
|
102
|
+
if (!id) id = `input-${uniqueID}`
|
|
103
|
+
if (!name) name = id
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="relative">
|
|
107
|
+
<InputLabel
|
|
108
|
+
isPlaceholder={true}
|
|
109
|
+
label={label}
|
|
110
|
+
isRequired={isRequired}
|
|
111
|
+
id={id}
|
|
112
|
+
isError={isError}
|
|
113
|
+
isActive={true}
|
|
114
|
+
isDisabled={isDisabled}
|
|
115
|
+
/>
|
|
116
|
+
<InputField
|
|
117
|
+
onFocus={handleInputFocus}
|
|
118
|
+
onBlur={handleInputBlur}
|
|
119
|
+
handleChange={(v) => setValue(v)}
|
|
120
|
+
ref={ref}
|
|
121
|
+
type={type}
|
|
122
|
+
name={name}
|
|
123
|
+
id={id}
|
|
124
|
+
className={cn(
|
|
125
|
+
"w-full rounded border py-2 px-3 text-sm font-normal leading-5",
|
|
126
|
+
{ "border-gray-300": !isFocus && !isError },
|
|
127
|
+
{
|
|
128
|
+
"!border-purple-500 shadow-none outline-purple-500 focus:!ring-purple-500": isFocus && !isError
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"!border-red-500 shadow-none focus:ring-red-500": isError
|
|
132
|
+
},
|
|
133
|
+
className
|
|
134
|
+
)}
|
|
135
|
+
isDisabled={isDisabled}
|
|
136
|
+
isReadonly={isReadonly}
|
|
137
|
+
value={value}
|
|
138
|
+
defaultValue={defaultValue}
|
|
139
|
+
maxLength={maxLength}
|
|
140
|
+
placeholder={placeholder}
|
|
141
|
+
{...props}
|
|
142
|
+
/>
|
|
143
|
+
<div className="flex flex-row space-x-3">
|
|
144
|
+
<div className="grow">
|
|
145
|
+
{message && (
|
|
146
|
+
<span className={cn("mt-1 block text-sm", isError ? "text-red-500" : "text-gray-500")}>
|
|
147
|
+
{message}
|
|
148
|
+
</span>
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
{isShowCounter && (
|
|
152
|
+
<div className="shrink-0">
|
|
153
|
+
<InputCounter current={Number(value?.length)} limit={maxLength} />
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const _TextInput = forwardRef<HTMLInputElement, ITextInputProps>(TextInput)
|
|
162
|
+
export default _TextInput
|
|
@@ -4,8 +4,9 @@ import InputField, { AcceptedInputTypes, IInputFieldProps } from "./InputField"
|
|
|
4
4
|
import InputLabel, { IInputLabelProps } from "./InputLabel"
|
|
5
5
|
import NestedInputButton, { INestedInputButtonProps } from "./NestedInputButton"
|
|
6
6
|
import Radio, { IRadioProps } from "./radio"
|
|
7
|
-
import Select, { ISelectProps } from "./select"
|
|
8
|
-
import
|
|
7
|
+
import Select, { ISelectProps, ISimpleSelectOptions } from "./select"
|
|
8
|
+
import Textarea, { ITextareaProps } from "./textArea"
|
|
9
|
+
import TextInput, { ITextInputProps } from "./TextInput"
|
|
9
10
|
import ToggleSwitch, { IToggleSwitchProps } from "./toggleSwitch"
|
|
10
11
|
|
|
11
12
|
export type {
|
|
@@ -16,9 +17,22 @@ export type {
|
|
|
16
17
|
INestedInputButtonProps,
|
|
17
18
|
IRadioProps,
|
|
18
19
|
ISelectProps,
|
|
19
|
-
|
|
20
|
+
ISimpleSelectOptions,
|
|
21
|
+
ITextareaProps,
|
|
22
|
+
ITextInputProps,
|
|
20
23
|
IToggleSwitchProps,
|
|
21
24
|
AcceptedInputTypes
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
export {
|
|
27
|
+
export {
|
|
28
|
+
Checkbox,
|
|
29
|
+
Combobox,
|
|
30
|
+
InputField,
|
|
31
|
+
InputLabel,
|
|
32
|
+
NestedInputButton,
|
|
33
|
+
Radio,
|
|
34
|
+
Select,
|
|
35
|
+
Textarea,
|
|
36
|
+
ToggleSwitch,
|
|
37
|
+
TextInput
|
|
38
|
+
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
-
import
|
|
3
|
-
const meta: Meta<typeof
|
|
2
|
+
import Textarea from "./TextArea"
|
|
3
|
+
const meta: Meta<typeof Textarea> = {
|
|
4
4
|
title: "Design System/Molecules/Inputs/TextArea",
|
|
5
|
-
component:
|
|
5
|
+
component: Textarea,
|
|
6
6
|
tags: ["autodocs"]
|
|
7
7
|
}
|
|
8
8
|
const dummyText: string = `Checkmate... Life finds a way. Is this my espresso machine? Wh-what is-h-how did you get my espresso machine? You're a very talented young man, with your own clever thoughts and ideas. Do you need a manager? Is this my espresso machine? Wh-what is-h-how did you get my espresso machine?
|
|
9
9
|
|
|
10
10
|
I was part of something special. Just my luck, no ice. You really think you can fly that thing? Must go faster... go, go, go, go, go! God creates dinosaurs. God destroys dinosaurs. God creates Man. Man destroys God. Man creates Dinosaurs. Yeah, but your scientists were so preoccupied with whether or not they could, they didn't stop to think if they should.`
|
|
11
|
-
type Story = StoryObj<typeof
|
|
12
|
-
export const
|
|
11
|
+
type Story = StoryObj<typeof Textarea>
|
|
12
|
+
export const DefaultTextarea: Story = {
|
|
13
13
|
args: {
|
|
14
14
|
id: "appDescription",
|
|
15
15
|
name: "description",
|
|
16
16
|
rows: 12,
|
|
17
|
+
cols: 18,
|
|
18
|
+
label: "Description",
|
|
17
19
|
placeholder: dummyText
|
|
18
20
|
}
|
|
19
21
|
}
|
|
@@ -1,67 +1,128 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useId, useState } from "react"
|
|
1
2
|
import { default as cn } from "classnames"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/** Error condition */
|
|
3
|
+
import InputLabel from "../InputLabel"
|
|
4
|
+
import InputCounter from "../InputCounter"
|
|
5
|
+
export interface ITextareaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange"> {
|
|
6
|
+
/** Input ID */
|
|
7
|
+
id?: string
|
|
8
|
+
/** Input Name */
|
|
9
|
+
name?: string
|
|
10
|
+
/** Label for the input */
|
|
11
|
+
label?: string
|
|
12
|
+
/** Error state */
|
|
13
13
|
isError?: boolean
|
|
14
|
+
/** If field is required */
|
|
15
|
+
isRequired?: boolean
|
|
14
16
|
/** Disabled state */
|
|
15
17
|
isDisabled?: boolean
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
value
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/** Set default value */
|
|
19
|
+
defaultValue?: string
|
|
20
|
+
|
|
21
|
+
value?: string
|
|
22
|
+
|
|
23
|
+
/** Message shown under the text field */
|
|
24
|
+
message?: string
|
|
25
|
+
/** Input character counter */
|
|
26
|
+
isShowCounter?: boolean
|
|
27
|
+
/** Max length of input character */
|
|
28
|
+
maxLength?: number
|
|
29
|
+
/** Callback on change */
|
|
30
|
+
onChange?(value: string): void
|
|
31
|
+
/** Number of rows */
|
|
32
|
+
rows?: number
|
|
33
|
+
/** Number of cols */
|
|
34
|
+
cols?: number
|
|
35
|
+
placeholder?: string
|
|
24
36
|
className?: string
|
|
37
|
+
ref?: React.LegacyRef<HTMLTextAreaElement>
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
|
|
40
|
+
const Textarea: React.FC<ITextareaProps> = ({
|
|
27
41
|
id,
|
|
28
42
|
name,
|
|
29
|
-
|
|
30
|
-
isFocused,
|
|
43
|
+
label,
|
|
31
44
|
isError,
|
|
32
|
-
|
|
45
|
+
isRequired,
|
|
33
46
|
isDisabled,
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
defaultValue,
|
|
48
|
+
message,
|
|
49
|
+
isShowCounter,
|
|
50
|
+
maxLength,
|
|
51
|
+
rows = 12,
|
|
52
|
+
cols = 48,
|
|
53
|
+
onChange,
|
|
54
|
+
value: externalValue,
|
|
36
55
|
placeholder,
|
|
37
56
|
className,
|
|
57
|
+
ref,
|
|
38
58
|
...rest
|
|
39
59
|
}) => {
|
|
60
|
+
const uniqueID = useId()
|
|
61
|
+
const [value, setValue] = useState<string | undefined>(externalValue || defaultValue || "")
|
|
62
|
+
const handleOnchange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
63
|
+
const targetValue = e.currentTarget.value
|
|
64
|
+
typeof onChange === "function" && onChange(targetValue)
|
|
65
|
+
setValue(targetValue)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const discriptionStyles = cn("text-sm mt-1 block", { "text-gray-500": !isError }, { "text-red-500": isError })
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
//if the external value is updated by the parent component, reset the value in here...
|
|
72
|
+
if (externalValue !== undefined && externalValue !== null) {
|
|
73
|
+
setValue(externalValue)
|
|
74
|
+
}
|
|
75
|
+
}, [externalValue])
|
|
76
|
+
|
|
77
|
+
if (!id) id = `ta-${uniqueID}`
|
|
78
|
+
|
|
40
79
|
return (
|
|
41
|
-
<
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
<div>
|
|
81
|
+
{label && (
|
|
82
|
+
<InputLabel
|
|
83
|
+
isPlaceholder
|
|
84
|
+
isActive
|
|
85
|
+
label={label}
|
|
86
|
+
isRequired={isRequired}
|
|
87
|
+
id={id}
|
|
88
|
+
isError={isError}
|
|
89
|
+
isDisabled={isDisabled}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
<div>
|
|
93
|
+
<textarea
|
|
94
|
+
ref={ref}
|
|
95
|
+
maxLength={maxLength}
|
|
96
|
+
onChange={handleOnchange}
|
|
97
|
+
rows={rows}
|
|
98
|
+
name={name}
|
|
99
|
+
id={id}
|
|
100
|
+
cols={cols}
|
|
101
|
+
className={cn(
|
|
102
|
+
"block w-full rounded focus:border-purple-500 focus:ring-purple-500 sm:text-sm",
|
|
103
|
+
{ "border-gray-300 ": !isError },
|
|
104
|
+
{
|
|
105
|
+
"border-red-500 outline-red-500 focus:ring-red-500": isError
|
|
106
|
+
},
|
|
107
|
+
className
|
|
108
|
+
)}
|
|
109
|
+
disabled={isDisabled}
|
|
110
|
+
defaultValue={defaultValue}
|
|
111
|
+
value={value}
|
|
112
|
+
placeholder={placeholder}
|
|
113
|
+
{...rest}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
<div className="flex flex-row space-x-3">
|
|
117
|
+
<div className="grow">{message && <span className={discriptionStyles}>{message}</span>}</div>
|
|
118
|
+
{isShowCounter && (
|
|
119
|
+
<div className="shrink-0">
|
|
120
|
+
<InputCounter current={Number(value?.length)} limit={maxLength} />
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
64
125
|
)
|
|
65
126
|
}
|
|
66
127
|
|
|
67
|
-
export default
|
|
128
|
+
export default Textarea
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type {
|
|
3
|
-
export default
|
|
1
|
+
import TextArea, { ITextareaProps } from "./TextArea"
|
|
2
|
+
export type { ITextareaProps }
|
|
3
|
+
export default TextArea
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { default } from
|
|
3
|
-
export * from './Tabs';
|
|
1
|
+
export * from "./Tabs"
|
|
2
|
+
export { default } from "./Tabs"
|