Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paragon
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
paragon
Commits
d54abdd6
Commit
d54abdd6
authored
Dec 15, 2017
by
jaebradley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(as-input): clean up feedback messaging
parent
c20de7c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
35 deletions
+71
-35
src/asInput/index.jsx
+71
-35
No files found.
src/asInput/index.jsx
View file @
d54abdd6
/* eslint-disable react/no-unused-prop-types */
/* eslint-disable react/no-unused-prop-types */
/* eslint-disable react/no-multi-comp */
import
React
from
'react'
;
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
PropTypes
from
'prop-types'
;
import
classNames
from
'classnames'
;
import
classNames
from
'classnames'
;
...
@@ -7,6 +9,58 @@ import FontAwesomeStyles from 'font-awesome/css/font-awesome.min.css';
...
@@ -7,6 +9,58 @@ import FontAwesomeStyles from 'font-awesome/css/font-awesome.min.css';
import
newId
from
'../utils/newId'
;
import
newId
from
'../utils/newId'
;
import
styles
from
'./asInput.scss'
;
import
styles
from
'./asInput.scss'
;
class
FeedbackMessage
extends
React
.
Component
{
getId
()
{
return
`error-
${
this
.
props
.
identifier
}
`
;
}
getWarning
()
{
return
(
<
span
key=
"0"
>
<
span
className=
{
classNames
(
FontAwesomeStyles
.
fa
,
FontAwesomeStyles
[
'fa-exclamation-circle'
],
styles
[
'fa-icon-spacing'
],
)
}
aria
-
hidden
/>
<
span
className=
{
styles
[
'sr-only'
]
}
>
{
this
.
props
.
warningIconDescription
}
</
span
>
</
span
>
);
}
getMessage
()
{
const
errors
=
[];
if
(
this
.
props
.
showWarning
)
{
errors
.
push
(
this
.
getWarning
());
}
errors
.
push
(<
span
key=
"1"
>
{
this
.
props
.
feedback
}
</
span
>);
return
errors
;
}
render
()
{
return
(
<
div
className=
{
classNames
(
styles
[
'form-control-feedback'
],
{
[
styles
[
'invalid-feedback'
]]:
this
.
props
.
showWarning
},
)
}
id=
{
this
.
getId
()
}
key=
"0"
aria
-
live=
"polite"
>
{
this
.
getMessage
()
}
</
div
>
);
}
}
export
const
getDisplayName
=
WrappedComponent
=>
export
const
getDisplayName
=
WrappedComponent
=>
WrappedComponent
.
displayName
||
WrappedComponent
.
name
||
'Component'
;
WrappedComponent
.
displayName
||
WrappedComponent
.
name
||
'Component'
;
...
@@ -62,42 +116,16 @@ const asInput = (WrappedComponent, labelFirst = true) => {
...
@@ -62,42 +116,16 @@ const asInput = (WrappedComponent, labelFirst = true) => {
const
hasDangerTheme
=
this
.
hasDangerTheme
();
const
hasDangerTheme
=
this
.
hasDangerTheme
();
desc
.
error
=
(
const
message
=
(
<
div
<
FeedbackMessage
className=
{
classNames
(
identifier=
{
this
.
state
.
id
}
styles
[
'form-control-feedback'
],
showWarning=
{
hasDangerTheme
}
{
[
styles
[
'invalid-feedback'
]]:
hasDangerTheme
},
warningIconDescription=
{
this
.
state
.
dangerIconDescription
}
)
}
feedback=
{
this
.
state
.
validationMessage
}
id=
{
errorId
}
/>
key=
"0"
aria
-
live=
"polite"
>
{
this
.
state
.
isValid
?
(
<
span
/>
)
:
[
(
hasDangerTheme
&&
<
span
key=
"0"
>
<
span
className=
{
classNames
(
FontAwesomeStyles
.
fa
,
FontAwesomeStyles
[
'fa-exclamation-circle'
],
styles
[
'fa-icon-spacing'
],
)
}
aria
-
hidden
/>
<
span
className=
{
classNames
(
styles
[
'sr-only'
])
}
>
{
this
.
state
.
dangerIconDescription
}
</
span
>
</
span
>
),
<
span
key=
"1"
>
{
this
.
state
.
validationMessage
}
</
span
>,
]
}
</
div
>
);
);
desc
.
error
=
message
;
desc
.
describedBy
=
errorId
;
desc
.
describedBy
=
errorId
;
if
(
this
.
props
.
description
)
{
if
(
this
.
props
.
description
)
{
...
@@ -175,6 +203,14 @@ const asInput = (WrappedComponent, labelFirst = true) => {
...
@@ -175,6 +203,14 @@ const asInput = (WrappedComponent, labelFirst = true) => {
themes
:
[],
themes
:
[],
};
};
FeedbackMessage
.
propTypes
=
{
identifier
:
PropTypes
.
string
.
isRequired
,
warningIconDescription
:
PropTypes
.
string
.
isRequired
,
errorMessage
:
PropTypes
.
string
.
isRequired
,
showWarning
:
PropTypes
.
bool
.
isRequired
,
feedback
:
PropTypes
.
string
.
isRequired
,
};
return
NewComponent
;
return
NewComponent
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment