Skip to content

Commit 582a0fa

Browse files
committed
Add scrollbox pattern variant to accommodate sticky headers
1 parent 663619c commit 582a0fa

File tree

3 files changed

+100
-22
lines changed

3 files changed

+100
-22
lines changed

src/pattern-library/components/patterns/ContainerPatterns.js

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ import Library from '../Library';
44

55
import { IconButton, LabeledButton } from '../../../';
66

7+
function ListElements() {
8+
return (
9+
<>
10+
<li>Alpha</li>
11+
<li>Bravo</li>
12+
<li>Charlie</li>
13+
<li>Delta</li>
14+
<li>Echo</li>
15+
<li>Foxtrot</li>
16+
<li>Golf</li>
17+
<li>Hotel</li>
18+
<li>India</li>
19+
<li>Juliett</li>
20+
<li>Kilo</li>
21+
<li>Lima</li>
22+
<li>Mike</li>
23+
<li>November</li>
24+
<li>Oscar</li>
25+
<li>Papa</li>
26+
<li>Quebec</li>
27+
<li>Romeo</li>
28+
<li>Sierra</li>
29+
<li>Tango</li>
30+
<li>Uniform</li>
31+
<li>Victor</li>
32+
<li>Whiskey</li>
33+
<li>XRay</li>
34+
<li>Yankee</li>
35+
<li>Zulu</li>
36+
</>
37+
);
38+
}
39+
740
export default function ContainerPatterns() {
841
const [showModalExample, setShowModalExample] = useState(false);
942
return (
@@ -231,21 +264,38 @@ export default function ContainerPatterns() {
231264
<code>scrollbox</code>.
232265
</p>
233266
<Library.Demo withSource>
234-
<div className="hyp-scrollbox" style="height: 150px; width:250px">
235-
<ul className="hyp-u-padding hyp-u-vertical-spacing">
236-
<li>Alpha</li>
237-
<li>Bravo</li>
238-
<li>Charlie</li>
239-
<li>Delta</li>
240-
<li>Echo</li>
241-
<li>Foxtrot</li>
242-
<li>Golf</li>
243-
<li>Hotel</li>
244-
<li>India</li>
245-
<li>Juliet</li>
246-
<li>Kilo</li>
247-
<li>Lima</li>
248-
</ul>
267+
<div style="height:250px;width:250px">
268+
<div className="hyp-scrollbox">
269+
<ul className="hyp-u-padding hyp-u-vertical-spacing">
270+
<ListElements />
271+
</ul>
272+
</div>
273+
</div>
274+
</Library.Demo>
275+
</Library.Example>
276+
277+
<Library.Example title="Scrollbox with header offset">
278+
<p>
279+
The <code>scrollbox--with-header</code> pattern offsets the top
280+
scroll-hinting shadow to accommodate one header-like element with a
281+
touch-target height (currently 44px).
282+
</p>
283+
284+
<Library.Demo withSource>
285+
<div style="height:250px;width:250px">
286+
<div className="hyp-scrollbox--with-header">
287+
<div
288+
className="hyp-u-layout-row--center hyp-u-border--bottom hyp-u-bg-color--grey-1"
289+
style="position:sticky;top:0;min-height:44px;"
290+
>
291+
<div>
292+
<strong>NATO Phonetic Alphabet</strong>
293+
</div>
294+
</div>
295+
<ul className="hyp-u-padding hyp-u-vertical-spacing">
296+
<ListElements />
297+
</ul>
298+
</div>
249299
</div>
250300
</Library.Demo>
251301
</Library.Example>

styles/mixins/patterns/_containers.scss

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
$-border-radius: var.$border-radius;
88
$-color-background: var.$color-background;
9+
$-header-height: var.$touch-target-size;
910

1011
/**
1112
* Patterns that are composites of multiple atomic utilities, but
@@ -182,32 +183,55 @@ $-color-background: var.$color-background;
182183
* - Only the bottom scroll-hint shadow appears if content overflows
183184
* - The bottom scroll-hint shadow is always present, even if content is
184185
* fully scrolled
186+
*
187+
* @param {CSSLength} [$shadow-top-position=0] - Top scroll-indicating shadow
188+
* (y) position. Default 0: at top edge of scrollbox. Use case: move
189+
* shadow down to accommodate a sticky header of a known height, such that the
190+
* shadow appears below the header(s).
191+
* @param {CSSLength} [$shadow-bottom-position=100%] - Bottom scroll-indicating
192+
* shadow position relative to scrollbox. Default 100%: flush to bottom.
185193
*/
186-
@mixin scrollbox {
194+
@mixin scrollbox($shadow-top-position: 0, $shadow-bottom-position: 100%) {
187195
overflow: auto;
188196
@include atoms.border;
197+
position: relative;
198+
height: 100%;
199+
width: 100%;
189200

190201
background:
191-
// Shadow covers
192-
linear-gradient($-color-background 30%, rgba(255, 255, 255, 0)),
193-
linear-gradient(rgba(255, 255, 255, 0), $-color-background 70%) 0 100%,
194-
// Shadows
202+
// Top Shadow cover
203+
linear-gradient($-color-background 30%, rgba(255, 255, 255, 0)) 0
204+
$shadow-top-position,
205+
// Bottom shadow cover
206+
linear-gradient(rgba(255, 255, 255, 0), $-color-background 70%) 0
207+
$shadow-bottom-position,
208+
// Top shadow
195209
linear-gradient(
196210
to bottom,
197211
rgba(0, 0, 0, 0.1),
198212
rgba(0, 0, 0, 0.05) 5px,
199213
rgba(255, 255, 255, 0) 70%
200-
),
214+
)
215+
0 $shadow-top-position,
216+
// Bottom shadow
201217
linear-gradient(
202218
to top,
203219
rgba(0, 0, 0, 0.1),
204220
rgba(0, 0, 0, 0.05) 5px,
205221
rgba(255, 255, 255, 0) 70%
206222
)
207-
0 100%;
223+
0 $shadow-bottom-position;
208224
background-repeat: no-repeat;
209225
background-color: $-color-background;
210226
background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px;
211227

212228
background-attachment: local, local, scroll, scroll;
213229
}
230+
231+
/**
232+
* A scrollbox with the top shadow repositioned down by touch-target-size
233+
* to accommodate, e.g., a sticky header at the top of the scrollable content.
234+
*/
235+
@mixin scrollbox--with-header {
236+
@include scrollbox($shadow-top-position: $-header-height);
237+
}

styles/patterns/_containers.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@
3636
.hyp-scrollbox {
3737
@include containers.scrollbox;
3838
}
39+
40+
.hyp-scrollbox--with-header {
41+
@include containers.scrollbox--with-header;
42+
}

0 commit comments

Comments
 (0)