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
9123797f
Commit
9123797f
authored
Jun 20, 2017
by
Sarah Fischmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified variables, got rid of form tags, added function story
parent
8009d271
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
35 deletions
+32
-35
src/CheckBox.jsx
+19
-28
stories/index.jsx
+13
-7
No files found.
src/CheckBox.jsx
View file @
9123797f
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
{
inputProps
}
from
'./utils/asInput'
;
...
...
@@ -7,33 +6,31 @@ import { inputProps } from './utils/asInput';
class
CheckBox
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
handleClick
=
this
.
handleClick
.
bind
(
this
);
if
(
props
.
checked
===
'true'
)
{
this
.
state
=
{
pressed
:
props
.
checked
,
checked
:
true
,
};
}
else
{
this
.
state
=
{
pressed
:
props
.
checked
,
checked
:
false
,
};
}
}
handleClick
()
{
if
(
this
.
state
.
pressed
===
'true'
)
{
if
(
this
.
state
.
checked
===
true
)
{
this
.
setState
({
pressed
:
'false'
,
checked
:
false
,
});
}
else
{
this
.
setState
({
pressed
:
'true'
,
checked
:
true
,
});
}
if
(
this
.
props
.
fun
)
{
this
.
props
.
fun
();
if
(
this
.
props
.
onChange
)
{
this
.
props
.
onChange
();
}
}
...
...
@@ -42,29 +39,23 @@ class CheckBox extends React.Component {
const
props
=
{
...
this
.
props
};
return
(
<
form
>
<
label
htmlFor=
{
props
.
checkLabel
}
className=
"form-check-label"
>
<
input
name=
{
props
.
name
}
type=
"checkbox"
defaultChecked=
{
this
.
state
.
checked
}
className=
"form-check-input"
aria
-
describedby=
{
props
.
describedby
}
aria
-
checked=
{
this
.
state
.
pressed
}
tabIndex=
"0"
onClick=
{
()
=>
this
.
handleClick
()
}
disabled=
{
props
.
disable
}
/>
{
props
.
checkLabel
}
</
label
>
</
form
>
<
label
htmlFor=
{
props
.
checkLabel
}
>
<
input
name=
{
props
.
name
}
type=
"checkbox"
defaultChecked=
{
this
.
state
.
checked
}
aria
-
describedby=
{
props
.
describedby
}
aria
-
checked=
{
this
.
state
.
checked
}
tabIndex=
"0"
onClick=
{
this
.
handleClick
}
disabled=
{
props
.
disabled
}
/>
{
props
.
label
}
</
label
>
);
}
}
CheckBox
.
propTypes
=
{
...
inputProps
,
checkLabel
:
PropTypes
.
string
.
isRequired
,
};
CheckBox
.
propTypes
=
inputProps
;
export
default
CheckBox
;
stories/index.jsx
View file @
9123797f
...
...
@@ -130,28 +130,34 @@ storiesOf('CheckBox', module)
.
add
(
'basic usage'
,
()
=>
(
<
CheckBox
name=
"checkbox"
label=
"CheckBox"
describedBy=
"checkbox"
checkL
abel=
"check me out!"
l
abel=
"check me out!"
checked=
"false"
/>
))
.
add
(
'disabled'
,
()
=>
(
<
CheckBox
name=
"checkbox"
label=
"CheckBox"
describedBy=
"checkbox"
checkL
abel=
"you cannot check me out"
l
abel=
"you cannot check me out"
checked=
"false"
disable=
"true"
disable
d
=
"true"
/>
))
.
add
(
'default checked'
,
()
=>
(
<
CheckBox
name=
"checkbox"
label=
"CheckBox"
describedBy=
"checkbox"
checkL
abel=
"(un)check me out"
l
abel=
"(un)check me out"
checked=
"true"
/>
))
.
add
(
'call a function'
,
()
=>
(
<
CheckBox
name=
"checkbox"
describedBy=
"checkbox"
label=
"check out the console"
checked=
"false"
onChange=
{
()
=>
console
.
log
(
'the checkbox changed state'
)
}
/>
));
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