Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
3f150be1
Unverified
Commit
3f150be1
authored
Aug 19, 2019
by
Benjamin Wheeler
Committed by
GitHub
Aug 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3266 from benjiwheeler/join-flow-info-responsive
use media queries to make info message responsive
parents
83bbe404
d8bafccc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
17 deletions
+48
-17
src/components/info-button/info-button.jsx
src/components/info-button/info-button.jsx
+28
-12
src/components/info-button/info-button.scss
src/components/info-button/info-button.scss
+5
-4
test/__mocks__/react-responsive.js
test/__mocks__/react-responsive.js
+5
-0
test/unit/components/info-button.test.jsx
test/unit/components/info-button.test.jsx
+10
-1
No files found.
src/components/info-button/info-button.jsx
View file @
3f150be1
const
bindAll
=
require
(
'
lodash.bindall
'
);
const
bindAll
=
require
(
'
lodash.bindall
'
);
const
PropTypes
=
require
(
'
prop-types
'
);
const
PropTypes
=
require
(
'
prop-types
'
);
const
React
=
require
(
'
react
'
);
const
React
=
require
(
'
react
'
);
const
MediaQuery
=
require
(
'
react-responsive
'
).
default
;
const
frameless
=
require
(
'
../../lib/frameless
'
);
require
(
'
./info-button.scss
'
);
require
(
'
./info-button.scss
'
);
...
@@ -22,25 +25,38 @@ class InfoButton extends React.Component {
...
@@ -22,25 +25,38 @@ class InfoButton extends React.Component {
this
.
setState
({
visible
:
true
});
this
.
setState
({
visible
:
true
});
}
}
render
()
{
render
()
{
const
messageJsx
=
this
.
state
.
visible
&&
(
<
div
className=
"info-button-message"
>
{
this
.
props
.
message
}
</
div
>
);
return
(
return
(
<
div
<
React
.
Fragment
>
className=
"info-button"
<
div
onClick=
{
this
.
handleShowMessage
}
className=
"info-button"
onMouseOut=
{
this
.
handleHideMessage
}
onClick=
{
this
.
handleShowMessage
}
onMouseOver=
{
this
.
handleShowMessage
}
onMouseOut=
{
this
.
handleHideMessage
}
>
onMouseOver=
{
this
.
handleShowMessage
}
{
this
.
state
.
visible
&&
(
>
<
div
className=
"info-button-message"
>
<
MediaQuery
minWidth=
{
frameless
.
desktop
}
>
{
this
.
props
.
message
}
{
messageJsx
}
</
MediaQuery
>
</
div
>
{
/* for small screens, add additional position: relative element,
so info message can position itself relative to the width which
encloses info-button -- rather than relative to info-button itself */
}
<
MediaQuery
maxWidth=
{
frameless
.
desktop
-
1
}
>
<
div
style=
{
{
position
:
'
relative
'
}
}
>
{
messageJsx
}
</
div
>
</
div
>
)
}
</
MediaQuery
>
</
div
>
</
React
.
Fragment
>
);
);
}
}
}
}
InfoButton
.
propTypes
=
{
InfoButton
.
propTypes
=
{
message
:
PropTypes
.
string
message
:
PropTypes
.
string
.
isRequired
};
};
module
.
exports
=
InfoButton
;
module
.
exports
=
InfoButton
;
src/components/info-button/info-button.scss
View file @
3f150be1
...
@@ -65,11 +65,12 @@
...
@@ -65,11 +65,12 @@
@media
#{
$intermediate-and-smaller
}
{
@media
#{
$intermediate-and-smaller
}
{
.info-button-message
{
.info-button-message
{
position
:
relativ
e
;
position
:
absolut
e
;
transform
:
none
;
transform
:
none
;
margin
:
inherit
;
/* since we're positioning message relative to info-button's parent,
width
:
100%
;
we need to center this element within its width. */
height
:
inherit
;
margin
:
0
calc
((
100%
-
16
.5rem
)
/
2
);;
top
:
.125rem
;
&
:before
{
&
:before
{
display
:
none
;
display
:
none
;
...
...
test/__mocks__/react-responsive.js
0 → 100644
View file @
3f150be1
// __mocks__/react-responsive.js
const
MediaQuery
=
({
children
})
=>
children
;
export
default
MediaQuery
;
test/unit/components/info-button.test.jsx
View file @
3f150be1
...
@@ -11,6 +11,15 @@ describe('InfoButton', () => {
...
@@ -11,6 +11,15 @@ describe('InfoButton', () => {
);
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
false
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
false
);
});
});
test
(
'
mouseOver on info button makes info message visible
'
,
()
=>
{
const
component
=
mountWithIntl
(
<
InfoButton
message=
"Here is some info about something!"
/>
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
mouseOver
'
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
true
);
});
test
(
'
clicking on info button makes info message visible
'
,
()
=>
{
test
(
'
clicking on info button makes info message visible
'
,
()
=>
{
const
component
=
mountWithIntl
(
const
component
=
mountWithIntl
(
<
InfoButton
<
InfoButton
...
@@ -26,7 +35,7 @@ describe('InfoButton', () => {
...
@@ -26,7 +35,7 @@ describe('InfoButton', () => {
message=
"Here is some info about something!"
message=
"Here is some info about something!"
/>
/>
);
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
click
'
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
mouseOver
'
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
true
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
true
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
mouseOut
'
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
mouseOut
'
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
false
);
expect
(
component
.
find
(
'
div.info-button-message
'
).
exists
()).
toEqual
(
false
);
...
...
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