Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
design-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASTRON SDC
design-system
Commits
30bbfda3
Commit
30bbfda3
authored
1 year ago
by
Robbie Luijben
Browse files
Options
Downloads
Plain Diff
feat: add maxlength, readonly, type, and input mode attributes to textinput
parents
16d31b05
028ad20c
No related branches found
No related tags found
1 merge request
!25
Expose additional base input props
Pipeline
#73590
passed
1 year ago
Stage: test
Stage: build
Stage: release
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/TextInput.tsx
+27
-0
27 additions, 0 deletions
src/components/TextInput.tsx
src/components/utils/baseComponents.tsx
+27
-1
27 additions, 1 deletion
src/components/utils/baseComponents.tsx
src/stories/TextInput.stories.tsx
+48
-2
48 additions, 2 deletions
src/stories/TextInput.stories.tsx
with
102 additions
and
3 deletions
src/components/TextInput.tsx
+
27
−
0
View file @
30bbfda3
...
...
@@ -11,6 +11,25 @@ type TextInputProps = {
isInvalid
?:
boolean
;
errorMessage
?:
string
;
isDisabled
?:
boolean
;
isReadOnly
?:
boolean
;
maxLength
?:
number
;
type
?:
|
"
text
"
|
"
search
"
|
"
url
"
|
"
tel
"
|
"
email
"
|
"
password
"
|
(
string
&
NonNullable
<
unknown
>
);
inputMode
?:
|
"
none
"
|
"
text
"
|
"
tel
"
|
"
url
"
|
"
email
"
|
"
numeric
"
|
"
decimal
"
|
"
search
"
;
};
const
TextInput
=
({
...
...
@@ -23,6 +42,10 @@ const TextInput = ({
isInvalid
=
false
,
errorMessage
=
""
,
isDisabled
=
false
,
isReadOnly
=
false
,
maxLength
,
type
=
"
text
"
,
inputMode
=
"
text
"
,
}:
TextInputProps
)
=>
{
return
(
<
BaseInput
...
...
@@ -36,6 +59,10 @@ const TextInput = ({
isInvalid
=
{
isInvalid
}
errorMessage
=
{
errorMessage
}
isDisabled
=
{
isDisabled
}
isReadOnly
=
{
isReadOnly
}
maxLength
=
{
maxLength
}
type
=
{
type
}
inputMode
=
{
inputMode
}
/>
);
};
...
...
This diff is collapsed.
Click to expand it.
src/components/utils/baseComponents.tsx
+
27
−
1
View file @
30bbfda3
...
...
@@ -15,9 +15,28 @@ type BaseInputProps = {
onValueChange
?:
Dispatch
<
SetStateAction
<
string
>>
;
isInvalid
:
boolean
;
errorMessage
:
string
;
maxLength
?:
number
;
type
?:
|
"
text
"
|
"
search
"
|
"
url
"
|
"
tel
"
|
"
email
"
|
"
password
"
|
(
string
&
NonNullable
<
unknown
>
);
// interaction
isRequired
?:
boolean
;
isDisabled
?:
boolean
;
isReadOnly
?:
boolean
;
inputMode
?:
|
"
none
"
|
"
text
"
|
"
tel
"
|
"
url
"
|
"
email
"
|
"
numeric
"
|
"
decimal
"
|
"
search
"
;
};
type
baseInputClassNamesObj
=
{
[
key
in
InputSlots
]:
string
};
...
...
@@ -60,12 +79,15 @@ export const BaseInput = ({
onValueChange
,
isInvalid
,
errorMessage
,
maxLength
,
type
=
"
text
"
,
isRequired
=
false
,
isDisabled
=
false
,
isReadOnly
=
false
,
inputMode
=
"
text
"
,
}:
BaseInputProps
)
=>
{
return
(
<
Input
type
=
"text"
label
=
{
label
}
endContent
=
{
endContent
}
placeholder
=
{
placeholder
}
...
...
@@ -74,8 +96,12 @@ export const BaseInput = ({
onValueChange
=
{
onValueChange
}
isInvalid
=
{
isInvalid
}
errorMessage
=
{
errorMessage
}
maxLength
=
{
maxLength
}
type
=
{
type
}
isRequired
=
{
isRequired
}
isDisabled
=
{
isDisabled
}
isReadOnly
=
{
isReadOnly
}
inputMode
=
{
inputMode
}
// appearance
labelPlacement
=
"outside"
variant
=
"bordered"
...
...
This diff is collapsed.
Click to expand it.
src/stories/TextInput.stories.tsx
+
48
−
2
View file @
30bbfda3
...
...
@@ -9,7 +9,7 @@ const meta = {
export
default
meta
;
export
const
With
Validation
=
()
=>
{
export
const
Custom
Validation
=
()
=>
{
const
[
value
,
setValue
]
=
useState
(
""
);
const
validateEmail
=
(
str
:
string
)
=>
...
...
@@ -47,9 +47,55 @@ export const IsClearable = () => {
export
const
Disabled
=
()
=>
{
return
(
<
TextInput
label
=
"You can't
change this
!"
label
=
"You can't
interact with this component
!"
isDisabled
=
{
true
}
value
=
"*Evil laughter*"
/>
);
};
export
const
ReadOnly
=
()
=>
{
return
(
<
TextInput
label
=
"You can't change this value!"
isReadOnly
=
{
true
}
value
=
"*Neutral laughter*"
/>
);
};
export
const
MaxLength
=
()
=>
{
const
[
value
,
setValue
]
=
useState
(
""
);
return
(
<
TextInput
label
=
"Maximum of 10 characters"
maxLength
=
{
10
}
value
=
{
value
}
onValueChange
=
{
setValue
}
/>
);
};
export
const
PredefinedType
=
()
=>
{
const
[
value
,
setValue
]
=
useState
(
""
);
return
(
<
TextInput
label
=
"This input is rendered as a password type"
type
=
"password"
value
=
{
value
}
onValueChange
=
{
setValue
}
/>
);
};
export
const
PredefinedInputMode
=
()
=>
{
const
[
value
,
setValue
]
=
useState
(
""
);
return
(
<
TextInput
label
=
"This keyboard for this input is shown as a numeric type"
inputMode
=
"numeric"
value
=
{
value
}
onValueChange
=
{
setValue
}
/>
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment