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
f267af28
Commit
f267af28
authored
Aug 18, 2019
by
Ben Wheeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use media queries to make info message responsive
parent
96a7d01c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
17 deletions
+43
-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/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 @
f267af28
const
bindAll
=
require
(
'
lodash.bindall
'
);
const
PropTypes
=
require
(
'
prop-types
'
);
const
React
=
require
(
'
react
'
);
const
MediaQuery
=
require
(
'
react-responsive
'
).
default
;
const
frameless
=
require
(
'
../../lib/frameless
'
);
require
(
'
./info-button.scss
'
);
...
...
@@ -22,25 +25,38 @@ class InfoButton extends React.Component {
this
.
setState
({
visible
:
true
});
}
render
()
{
const
messageJsx
=
this
.
state
.
visible
&&
(
<
div
className=
"info-button-message"
>
{
this
.
props
.
message
}
</
div
>
);
return
(
<
div
className=
"info-button"
onClick=
{
this
.
handleShowMessage
}
onMouseOut=
{
this
.
handleHideMessage
}
onMouseOver=
{
this
.
handleShowMessage
}
>
{
this
.
state
.
visible
&&
(
<
div
className=
"info-button-message"
>
{
this
.
props
.
message
}
<
React
.
Fragment
>
<
div
className=
"info-button"
onClick=
{
this
.
handleShowMessage
}
onMouseOut=
{
this
.
handleHideMessage
}
onMouseOver=
{
this
.
handleShowMessage
}
>
<
MediaQuery
minWidth=
{
frameless
.
desktop
}
>
{
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
>
</
React
.
Fragment
>
);
}
}
InfoButton
.
propTypes
=
{
message
:
PropTypes
.
string
message
:
PropTypes
.
string
.
isRequired
};
module
.
exports
=
InfoButton
;
src/components/info-button/info-button.scss
View file @
f267af28
...
...
@@ -65,11 +65,12 @@
@media
#{
$intermediate-and-smaller
}
{
.info-button-message
{
position
:
relativ
e
;
position
:
absolut
e
;
transform
:
none
;
margin
:
inherit
;
width
:
100%
;
height
:
inherit
;
/* since we're positioning message relative to info-button's parent,
we need to center this element within its width. */
margin
:
0
calc
((
100%
-
16
.5rem
)
/
2
);;
top
:
.125rem
;
&
:before
{
display
:
none
;
...
...
test/unit/components/info-button.test.jsx
View file @
f267af28
...
...
@@ -11,6 +11,15 @@ describe('InfoButton', () => {
);
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
'
,
()
=>
{
const
component
=
mountWithIntl
(
<
InfoButton
...
...
@@ -26,7 +35,7 @@ describe('InfoButton', () => {
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
);
component
.
find
(
'
div.info-button
'
).
simulate
(
'
mouseOut
'
);
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