Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
527aed43
Commit
527aed43
authored
Apr 07, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Apr 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `LinkButton` in Excerpt
parent
884fc5ca
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
+34
-25
Excerpt.js
src/sidebar/components/Excerpt.js
+10
-7
Excerpt-test.js
src/sidebar/components/test/Excerpt-test.js
+21
-9
Excerpt.scss
src/styles/sidebar/components/Excerpt.scss
+3
-9
No files found.
src/sidebar/components/Excerpt.js
View file @
527aed43
...
@@ -5,6 +5,8 @@ import observeElementSize from '../util/observe-element-size';
...
@@ -5,6 +5,8 @@ import observeElementSize from '../util/observe-element-size';
import
{
withServices
}
from
'../service-context'
;
import
{
withServices
}
from
'../service-context'
;
import
{
applyTheme
}
from
'../helpers/theme'
;
import
{
applyTheme
}
from
'../helpers/theme'
;
import
{
LinkButton
}
from
'../../shared/components/buttons'
;
/**
/**
* @typedef InlineControlsProps
* @typedef InlineControlsProps
* @prop {boolean} isCollapsed
* @prop {boolean} isCollapsed
...
@@ -23,17 +25,18 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
...
@@ -23,17 +25,18 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
return
(
return
(
<
div
className
=
"Excerpt__inline-controls"
>
<
div
className
=
"Excerpt__inline-controls"
>
<
span
className
=
"Excerpt__toggle-link
"
>
<
div
className
=
"Excerpt__toggle-container
"
>
<
b
utton
<
LinkB
utton
className
=
"
Excerpt__toggle-b
utton"
className
=
"
InlineLinkB
utton"
onClick
=
{()
=>
setCollapsed
(
!
isCollapsed
)}
onClick
=
{()
=>
setCollapsed
(
!
isCollapsed
)}
aria
-
expanded
=
{
!
isCollapsed
}
expanded
=
{
!
isCollapsed
}
aria
-
label
=
"Toggle visibility of full excerpt text"
title
=
"Toggle visibility of full excerpt text"
style
=
{
linkStyle
}
style
=
{
linkStyle
}
variant
=
"dark"
>
>
{
toggleLabel
}
{
toggleLabel
}
<
/
b
utton
>
<
/
LinkB
utton
>
<
/
span
>
<
/
div
>
<
/div
>
<
/div
>
);
);
}
}
...
...
src/sidebar/components/test/Excerpt-test.js
View file @
527aed43
...
@@ -115,36 +115,48 @@ describe('Excerpt', () => {
...
@@ -115,36 +115,48 @@ describe('Excerpt', () => {
});
});
context
(
'when inline controls are enabled'
,
()
=>
{
context
(
'when inline controls are enabled'
,
()
=>
{
const
getToggleButton
=
wrapper
=>
wrapper
.
find
(
'LinkButton[title="Toggle visibility of full excerpt text"]'
);
it
(
'displays inline controls if collapsed'
,
()
=>
{
it
(
'displays inline controls if collapsed'
,
()
=>
{
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
assert
.
isTrue
(
wrapper
.
exists
(
'
.Excerpt__inline-c
ontrols'
));
assert
.
isTrue
(
wrapper
.
exists
(
'
InlineC
ontrols'
));
});
});
it
(
'does not display inline controls if not collapsed'
,
()
=>
{
it
(
'does not display inline controls if not collapsed'
,
()
=>
{
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
SHORT_DIV
);
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
SHORT_DIV
);
assert
.
isFalse
(
wrapper
.
exists
(
'
.Excerpt__inline-c
ontrols'
));
assert
.
isFalse
(
wrapper
.
exists
(
'
InlineC
ontrols'
));
});
});
it
(
'toggles the expanded state when clicked'
,
()
=>
{
it
(
'toggles the expanded state when clicked'
,
()
=>
{
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
button
=
wrapper
.
find
(
'.Excerpt__toggle-button'
);
const
button
=
getToggleButton
(
wrapper
);
assert
.
equal
(
getExcerptHeight
(
wrapper
),
40
);
assert
.
equal
(
getExcerptHeight
(
wrapper
),
40
);
button
.
simulate
(
'click'
);
act
(()
=>
{
button
.
props
().
onClick
();
});
wrapper
.
update
();
assert
.
equal
(
getExcerptHeight
(
wrapper
),
200
);
assert
.
equal
(
getExcerptHeight
(
wrapper
),
200
);
});
});
it
(
"sets button's default state to un-expanded"
,
()
=>
{
it
(
"sets button's default state to un-expanded"
,
()
=>
{
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
button
=
wrapper
.
find
(
'.Excerpt__toggle-button'
);
const
button
=
getToggleButton
(
wrapper
);
assert
.
equal
(
button
.
prop
(
'
aria-
expanded'
),
false
);
assert
.
equal
(
button
.
prop
(
'expanded'
),
false
);
assert
.
equal
(
button
.
text
(),
'More'
);
assert
.
equal
(
button
.
text
(),
'More'
);
});
});
it
(
"changes button's state to expanded when clicked"
,
()
=>
{
it
(
"changes button's state to expanded when clicked"
,
()
=>
{
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
const
wrapper
=
createExcerpt
({
inlineControls
:
true
},
TALL_DIV
);
wrapper
.
find
(
'.Excerpt__toggle-button'
).
simulate
(
'click'
);
let
button
=
getToggleButton
(
wrapper
);
const
button
=
wrapper
.
find
(
'.Excerpt__toggle-button'
);
act
(()
=>
{
assert
.
equal
(
button
.
prop
(
'aria-expanded'
),
true
);
button
.
props
().
onClick
();
});
wrapper
.
update
();
button
=
getToggleButton
(
wrapper
);
assert
.
equal
(
button
.
prop
(
'expanded'
),
true
);
assert
.
equal
(
button
.
text
(),
'Less'
);
assert
.
equal
(
button
.
text
(),
'Less'
);
});
});
});
});
...
...
src/styles/sidebar/components/Excerpt.scss
View file @
527aed43
@use
"../../mixins/buttons"
;
@use
"../../variables"
as
var
;
@use
"../../variables"
as
var
;
// the distance by which the shadow indicating a collapsed
// the distance by which the shadow indicating a collapsed
...
@@ -34,7 +33,9 @@ $expand-duration: 0.15s;
...
@@ -34,7 +33,9 @@ $expand-duration: 0.15s;
bottom
:
0
;
bottom
:
0
;
}
}
.Excerpt__toggle-link
{
// A container for a button with a gradient background; this gives partial
// opacity behind the More/Less button so that it is easier to read
.Excerpt__toggle-container
{
padding-left
:
var
.
$layout-space
;
padding-left
:
var
.
$layout-space
;
// See https://stackoverflow.com/a/56548711/9788954 regarding
// See https://stackoverflow.com/a/56548711/9788954 regarding
// rgba(255, 255, 255, 0) used here instead of `transparent` (for Safari)
// rgba(255, 255, 255, 0) used here instead of `transparent` (for Safari)
...
@@ -45,13 +46,6 @@ $expand-duration: 0.15s;
...
@@ -45,13 +46,6 @@ $expand-duration: 0.15s;
);
);
}
}
// TODO the tap target here is quite small
.Excerpt__toggle-button
{
@include
buttons
.
reset-native-btn-styles
;
background
:
transparent
;
font-style
:
italic
;
}
// a shadow displayed at the bottom of an <excerpt>s with inline controls
// a shadow displayed at the bottom of an <excerpt>s with inline controls
// disabled, which provides a hint that the excerpt is collapsed
// disabled, which provides a hint that the excerpt is collapsed
.Excerpt__shadow
{
.Excerpt__shadow
{
...
...
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