@react-ui-org/react-ui 0.47.0 → 0.48.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/lib.development.js +330 -54
- package/dist/lib.js +1 -1
- package/package.json +1 -1
- package/src/lib/components/Alert/README.mdx +4 -2
- package/src/lib/components/Alert/index.js +1 -1
- package/src/lib/components/Badge/README.mdx +1 -1
- package/src/lib/components/Badge/index.js +1 -1
- package/src/lib/components/Button/Button.jsx +31 -31
- package/src/lib/components/Button/README.mdx +4 -2
- package/src/lib/components/Button/index.js +1 -1
- package/src/lib/components/ButtonGroup/ButtonGroup.jsx +2 -1
- package/src/lib/components/ButtonGroup/README.mdx +4 -2
- package/src/lib/components/Card/README.mdx +7 -5
- package/src/lib/components/CheckboxField/CheckboxField.jsx +27 -28
- package/src/lib/components/CheckboxField/README.mdx +1 -1
- package/src/lib/components/CheckboxField/index.js +1 -1
- package/src/lib/components/FileInputField/FileInputField.jsx +27 -27
- package/src/lib/components/FileInputField/README.mdx +1 -1
- package/src/lib/components/FileInputField/index.js +1 -1
- package/src/lib/components/FormLayout/README.mdx +15 -13
- package/src/lib/components/Grid/Grid.jsx +31 -28
- package/src/lib/components/Grid/Grid.scss +10 -15
- package/src/lib/components/Grid/GridSpan.jsx +5 -4
- package/src/lib/components/Grid/README.mdx +34 -36
- package/src/lib/components/Grid/_helpers/generateResponsiveCustomProperties.js +11 -3
- package/src/lib/components/Grid/_settings.scss +18 -0
- package/src/lib/components/Grid/_tools.scss +5 -5
- package/src/lib/components/Modal/Modal.jsx +147 -250
- package/src/lib/components/Modal/Modal.scss +7 -55
- package/src/lib/components/Modal/ModalBody.jsx +64 -0
- package/src/lib/components/Modal/ModalBody.scss +18 -0
- package/src/lib/components/Modal/ModalCloseButton.jsx +61 -0
- package/src/lib/components/Modal/ModalCloseButton.scss +18 -0
- package/src/lib/components/Modal/ModalContent.jsx +43 -0
- package/src/lib/components/Modal/ModalContent.scss +5 -0
- package/src/lib/components/Modal/ModalFooter.jsx +46 -0
- package/src/lib/components/Modal/ModalFooter.scss +35 -0
- package/src/lib/components/Modal/ModalHeader.jsx +48 -0
- package/src/lib/components/Modal/ModalHeader.scss +30 -0
- package/src/lib/components/Modal/ModalTitle.jsx +45 -0
- package/src/lib/components/Modal/ModalTitle.scss +10 -0
- package/src/lib/components/Modal/README.mdx +842 -197
- package/src/lib/components/Modal/_helpers/getJustifyClassName.js +19 -0
- package/src/lib/components/Modal/_helpers/getScrollingClassName.js +11 -0
- package/src/lib/components/Modal/_settings.scss +1 -5
- package/src/lib/components/Modal/_theme.scss +6 -0
- package/src/lib/components/Modal/index.js +7 -1
- package/src/lib/components/Paper/README.mdx +1 -1
- package/src/lib/components/Paper/index.js +1 -1
- package/src/lib/components/Popover/Popover.jsx +24 -24
- package/src/lib/components/Popover/Popover.scss +7 -6
- package/src/lib/components/Popover/PopoverWrapper.jsx +5 -5
- package/src/lib/components/Popover/PopoverWrapper.scss +3 -0
- package/src/lib/components/Popover/README.mdx +13 -11
- package/src/lib/components/Popover/_theme.scss +1 -1
- package/src/lib/components/Radio/README.mdx +1 -1
- package/src/lib/components/Radio/Radio.jsx +37 -27
- package/src/lib/components/Radio/index.js +1 -1
- package/src/lib/components/ScrollView/README.mdx +146 -84
- package/src/lib/components/ScrollView/ScrollView.jsx +104 -113
- package/src/lib/components/ScrollView/ScrollView.scss +18 -16
- package/src/lib/components/ScrollView/index.js +1 -1
- package/src/lib/components/SelectField/README.mdx +66 -2
- package/src/lib/components/SelectField/SelectField.jsx +93 -49
- package/src/lib/components/SelectField/_components/Option/Option.jsx +46 -0
- package/src/lib/components/SelectField/_components/Option/index.js +1 -0
- package/src/lib/components/SelectField/index.js +1 -1
- package/src/lib/components/Table/README.mdx +4 -2
- package/src/lib/components/Table/Table.jsx +1 -1
- package/src/lib/components/Table/index.js +1 -1
- package/src/lib/components/Tabs/README.mdx +5 -3
- package/src/lib/components/Tabs/TabsItem.scss +1 -2
- package/src/lib/components/Text/README.mdx +9 -7
- package/src/lib/components/Text/index.js +1 -1
- package/src/lib/components/TextArea/README.mdx +1 -1
- package/src/lib/components/TextArea/TextArea.jsx +33 -33
- package/src/lib/components/TextArea/index.js +1 -1
- package/src/lib/components/TextField/README.mdx +3 -3
- package/src/lib/components/TextField/TextField.jsx +33 -34
- package/src/lib/components/TextField/index.js +1 -1
- package/src/lib/components/TextLink/README.mdx +1 -1
- package/src/lib/components/TextLink/index.js +1 -1
- package/src/lib/components/Toggle/README.mdx +1 -1
- package/src/lib/components/Toggle/Toggle.jsx +28 -28
- package/src/lib/components/Toggle/index.js +1 -1
- package/src/lib/components/Toolbar/README.mdx +8 -6
- package/src/lib/components/_helpers/transferProps.js +1 -1
- package/src/lib/index.js +24 -16
- package/src/lib/provider/withGlobalProps.jsx +20 -3
- package/src/lib/theme.scss +18 -26
- package/src/lib/translations/en.js +1 -1
- package/src/lib/components/Grid/_theme.scss +0 -11
- package/src/lib/components/ScrollView/_theme.scss +0 -2
- package/src/lib/components/withForwardedRef.jsx +0 -11
@@ -9,18 +9,20 @@ route: /components/scroll-view
|
|
9
9
|
ScrollView makes long content scrollable.
|
10
10
|
|
11
11
|
👉 Please note that HTML is rendered even when no children are provided.
|
12
|
-
This is needed to allow the
|
12
|
+
This is needed to allow the auto-scroll feature to work.
|
13
13
|
|
14
14
|
import {
|
15
15
|
Playground,
|
16
16
|
Props,
|
17
17
|
} from 'docz'
|
18
18
|
import { Placeholder } from '../../../docs/_components/Placeholder/Placeholder'
|
19
|
-
import
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
import {
|
20
|
+
Button,
|
21
|
+
Radio,
|
22
|
+
Toolbar,
|
23
|
+
ToolbarItem,
|
24
|
+
ScrollView,
|
25
|
+
} from '../..'
|
24
26
|
|
25
27
|
## Basic Usage
|
26
28
|
|
@@ -89,9 +91,9 @@ See [API](#api) for all available options.
|
|
89
91
|
to restrict the height of its parent to activate scrolling.
|
90
92
|
|
91
93
|
- While arrow controls are optional in the vertical mode, you should always
|
92
|
-
**enable arrows in the horizontal mode when scrollbar is disabled.**
|
93
|
-
if you don't, users without horizontal-scrolling-enabled devices
|
94
|
-
old-school mouse) might not be able to access your content.
|
94
|
+
**enable arrows in the horizontal mode when the scrollbar is disabled.**
|
95
|
+
Because if you don't, users without horizontal-scrolling-enabled devices
|
96
|
+
(like an old-school mouse) might not be able to access your content.
|
95
97
|
|
96
98
|
- For dynamic content such as chat window or console output, consider using the
|
97
99
|
**auto-scroll feature**. This will ensure the newest content is always
|
@@ -101,13 +103,13 @@ See [API](#api) for all available options.
|
|
101
103
|
area in your app scrollable based on viewport size, please use custom CSS
|
102
104
|
with media queries instead.
|
103
105
|
|
104
|
-
- ScrollView only supports **scrolling in single direction at a time.** It
|
105
|
-
content that
|
106
|
-
scrollbars would be unreachable under scrolling shadows. If you
|
107
|
-
content to be ready for bi-directional scrolling, either consider
|
108
|
-
`overflow: auto` instead of ScrollView, or make your content
|
109
|
-
putting it into ScrollView and make sure its scrollbars
|
110
|
-
scrolling shadows.
|
106
|
+
- ScrollView only supports **scrolling in a single direction at a time.** It
|
107
|
+
crops content that would possibly overflow in the other direction because
|
108
|
+
additional scrollbars would be unreachable under scrolling shadows. If you
|
109
|
+
need your content to be ready for bi-directional scrolling, either consider
|
110
|
+
using just `overflow: auto` instead of ScrollView, or make your content
|
111
|
+
scrollable before putting it into ScrollView and make sure its scrollbars
|
112
|
+
don't collide with scrolling shadows.
|
111
113
|
|
112
114
|
## Arrows
|
113
115
|
|
@@ -168,7 +170,7 @@ horizontal content and you need to make sure it remains accessible on all
|
|
168
170
|
viewport sizes.
|
169
171
|
|
170
172
|
<Playground>
|
171
|
-
<ScrollView direction="horizontal">
|
173
|
+
<ScrollView direction="horizontal" arrows>
|
172
174
|
<Placeholder>
|
173
175
|
<div style={{ whiteSpace: 'nowrap' }}>
|
174
176
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
|
@@ -284,60 +286,20 @@ property defined because it detects changes of these keys.
|
|
284
286
|
It's possible to entirely customize the arrow controls, including the scroll
|
285
287
|
step, and the scrolling shadows.
|
286
288
|
|
287
|
-
### Custom Arrows
|
288
|
-
|
289
|
-
You can pass any HTML element or even custom React component to be used as the
|
290
|
-
arrow control.
|
291
|
-
|
292
|
-
The color of arrows and scrolling shadows can be simply adjusted, too. While the
|
293
|
-
`arrowsColor` accepts
|
294
|
-
[color in any valid CSS format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value),
|
295
|
-
the `shadowColor` is broken down to individual color channels so we can easily
|
296
|
-
derive the transparent version from the value without having to parse it.
|
289
|
+
### Custom Arrows
|
297
290
|
|
298
|
-
|
299
|
-
|
291
|
+
You can pass any HTML element or even a custom React component to be used as the
|
292
|
+
arrow control. Furthermore, you can change the scroll step if you need to scroll
|
293
|
+
by smaller or bigger portions.
|
300
294
|
|
301
295
|
<Playground>
|
302
296
|
<ScrollView
|
303
297
|
arrows
|
304
|
-
arrowsColor="white"
|
305
298
|
arrowsScrollStep={300}
|
306
|
-
customNextArrow={(
|
307
|
-
<span
|
308
|
-
style={{
|
309
|
-
fontSize: '1.5rem',
|
310
|
-
fontWeight: 'bold',
|
311
|
-
position: 'relative',
|
312
|
-
textShadow: '0 0 0.4em black',
|
313
|
-
top: '-0.05em',
|
314
|
-
}}
|
315
|
-
>
|
316
|
-
→
|
317
|
-
</span>
|
318
|
-
)}
|
319
|
-
customPrevArrow={(
|
320
|
-
<span
|
321
|
-
style={{
|
322
|
-
fontSize: '1.5rem',
|
323
|
-
fontWeight: 'bold',
|
324
|
-
position: 'relative',
|
325
|
-
textShadow: '0 0 0.4em black',
|
326
|
-
top: '-0.05em',
|
327
|
-
}}
|
328
|
-
>
|
329
|
-
←
|
330
|
-
</span>
|
331
|
-
)}
|
332
299
|
direction="horizontal"
|
300
|
+
nextArrowElement={(<span class="typography-size-3">➡️</span>)}
|
301
|
+
prevArrowElement={(<span class="typography-size-3">⬅️</span>)}
|
333
302
|
scrollbar={false}
|
334
|
-
shadowColor={{
|
335
|
-
alpha: 0.75,
|
336
|
-
blue: 0,
|
337
|
-
green: 0,
|
338
|
-
red: 0,
|
339
|
-
}}
|
340
|
-
shadowSize="5rem"
|
341
303
|
>
|
342
304
|
<Placeholder>
|
343
305
|
<div style={{ whiteSpace: 'nowrap' }}>
|
@@ -352,36 +314,34 @@ bigger portions.
|
|
352
314
|
</ScrollView>
|
353
315
|
</Playground>
|
354
316
|
|
355
|
-
###
|
317
|
+
### Scrolling Shadows
|
356
318
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
The following example demonstrates exactly the same custom scrolling shadows as
|
361
|
-
we use in the [Modal](/components/modal#scrolling-long-content) component.
|
319
|
+
You can customize the start and end scrolling shadows using `startShadow*` and
|
320
|
+
`endShadow*` properties.
|
362
321
|
|
363
322
|
<Playground>
|
364
323
|
<Placeholder height="200px">
|
365
324
|
<ScrollView
|
366
|
-
|
367
|
-
background: 'radial-gradient('
|
325
|
+
startShadowBackground={'radial-gradient('
|
368
326
|
+ 'farthest-side at center top, '
|
369
327
|
+ 'rgba(0, 0, 0, 0.15) 0%, '
|
370
328
|
+ 'rgba(0, 0, 0, 0.05) 60%, '
|
371
329
|
+ 'rgba(0, 0, 0, 0.02) 85%, '
|
372
330
|
+ 'rgba(0, 0, 0, 0) 100%'
|
373
|
-
+ ')'
|
374
|
-
}
|
375
|
-
|
376
|
-
|
331
|
+
+ ')'
|
332
|
+
}
|
333
|
+
startShadowInitialOffset="-5px"
|
334
|
+
startShadowSize="40px"
|
335
|
+
endShadowBackground={'radial-gradient('
|
377
336
|
+ 'farthest-side at center bottom, '
|
378
337
|
+ 'rgba(0, 0, 0, 0.15) 0%, '
|
379
338
|
+ 'rgba(0, 0, 0, 0.05) 60%, '
|
380
339
|
+ 'rgba(0, 0, 0, 0.02) 85%, '
|
381
340
|
+ 'rgba(0, 0, 0, 0) 100%'
|
382
|
-
+ ')'
|
383
|
-
}
|
384
|
-
|
341
|
+
+ ')'
|
342
|
+
}
|
343
|
+
endShadowInitialOffset="-5px"
|
344
|
+
endShadowSize="40px"
|
385
345
|
>
|
386
346
|
<div>
|
387
347
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
|
@@ -428,13 +388,115 @@ we use in the [Modal](/components/modal#scrolling-long-content) component.
|
|
428
388
|
</Placeholder>
|
429
389
|
</Playground>
|
430
390
|
|
391
|
+
#### Linear Gradients
|
392
|
+
|
393
|
+
For easier CSS definition of [linear gradients] for both vertical and horizontal
|
394
|
+
directions at the same time, there are `--rui-local-start-shadow-direction` and
|
395
|
+
`--rui-local-end-shadow-direction` custom properties that can be used inside
|
396
|
+
`startShadowBackground` and `endShadowBackground` definitions. The value of the
|
397
|
+
custom properties then reacts to the `direction` option:
|
398
|
+
|
399
|
+
| Custom property | Vertical direction | Horizontal direction |
|
400
|
+
|--------------------------------------|--------------------|----------------------|
|
401
|
+
| `--rui-local-start-shadow-direction` | `to bottom` | `to right` |
|
402
|
+
| `--rui-local-end-shadow-direction` | `to top` | `to left` |
|
403
|
+
|
404
|
+
This is useful if you want to create a single definition of linear gradients for
|
405
|
+
scrolling shadows in both directions via
|
406
|
+
[global props](/customize/global-props).
|
407
|
+
|
408
|
+
<Playground>
|
409
|
+
{() => {
|
410
|
+
const START_SHADOW_BACKGROUND = `linear-gradient(
|
411
|
+
var(--rui-local-start-shadow-direction),
|
412
|
+
rgba(0 0 0 / 0.5),
|
413
|
+
rgba(0 0 0 / 0)
|
414
|
+
)`;
|
415
|
+
const END_SHADOW_BACKGROUND = `linear-gradient(
|
416
|
+
var(--rui-local-end-shadow-direction),
|
417
|
+
rgba(0 0 0 / 0.5),
|
418
|
+
rgba(0 0 0 / 0)
|
419
|
+
)`
|
420
|
+
const [direction, setDirection] = React.useState('vertical');
|
421
|
+
return(
|
422
|
+
<>
|
423
|
+
<Radio
|
424
|
+
label="Direction:"
|
425
|
+
onChange={(e) => setDirection(e.target.value)}
|
426
|
+
options={[
|
427
|
+
{
|
428
|
+
label: 'Vertical',
|
429
|
+
value: 'vertical',
|
430
|
+
},
|
431
|
+
{
|
432
|
+
label: 'Horizontal',
|
433
|
+
value: 'horizontal',
|
434
|
+
},
|
435
|
+
]}
|
436
|
+
value={direction}
|
437
|
+
/>
|
438
|
+
<Placeholder height="200px">
|
439
|
+
<ScrollView
|
440
|
+
direction={direction}
|
441
|
+
endShadowBackground={END_SHADOW_BACKGROUND}
|
442
|
+
startShadowBackground={START_SHADOW_BACKGROUND}
|
443
|
+
>
|
444
|
+
<div
|
445
|
+
style={{
|
446
|
+
width: (direction === 'horizontal' ? '3000px' : 'auto'),
|
447
|
+
}}
|
448
|
+
>
|
449
|
+
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
|
450
|
+
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
|
451
|
+
penatibus et magnis dis parturient montes, nascetur ridiculus mus.
|
452
|
+
Donec quam felis, ultricies nec, pellentesque eu, pretium quis,
|
453
|
+
sem. Nulla consequat massa quis enim. Donec pede justo, fringilla
|
454
|
+
vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut,
|
455
|
+
imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede
|
456
|
+
mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum
|
457
|
+
semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula,
|
458
|
+
porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem
|
459
|
+
ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus
|
460
|
+
viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean
|
461
|
+
imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper
|
462
|
+
ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus,
|
463
|
+
tellus eget condimentum rhoncus, sem quam semper libero, sit amet
|
464
|
+
adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus
|
465
|
+
pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt
|
466
|
+
tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam
|
467
|
+
quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis
|
468
|
+
leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis
|
469
|
+
magna. Sed consequat, leo eget bibendum sodales, augue velit
|
470
|
+
cursus nunc. Aenean massa. Cum sociis natoque penatibus et magnis
|
471
|
+
dis parturient montes, nascetur ridiculus mus. Donec quam felis,
|
472
|
+
ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat
|
473
|
+
massa quis enim. Donec pede justo, fringilla vel, aliquet nec,
|
474
|
+
vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
|
475
|
+
venenatis vitae, justo. Nullam dictum felis eu pede mollis
|
476
|
+
pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper
|
477
|
+
nisi. Aenean vulputate eleifend tellus. Aenean leo ligula,
|
478
|
+
porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem
|
479
|
+
ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus
|
480
|
+
viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean
|
481
|
+
imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper
|
482
|
+
ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus,
|
483
|
+
tellus eget condimentum rhoncus, sem quam semper libero, sit amet
|
484
|
+
adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus
|
485
|
+
pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt
|
486
|
+
tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam
|
487
|
+
quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis
|
488
|
+
leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis
|
489
|
+
magna. Sed consequat, leo eget bibendum sodales, augue velit
|
490
|
+
cursus nunc.
|
491
|
+
</div>
|
492
|
+
</ScrollView>
|
493
|
+
</Placeholder>
|
494
|
+
</>
|
495
|
+
)}}
|
496
|
+
</Playground>
|
497
|
+
|
431
498
|
## API
|
432
499
|
|
433
500
|
<Props table of={ScrollView} />
|
434
501
|
|
435
|
-
|
436
|
-
|
437
|
-
| Custom Property | Description |
|
438
|
-
|------------------------------------------------------|--------------------------------------------------------------|
|
439
|
-
| `--rui-ScrollView__arrow__initial-offset` | Initial offset of scrolling arrows (transitioned) |
|
440
|
-
| `--rui-ScrollView__shadow__initial-offset` | Initial offset of scrolling shadows (transitioned) |
|
502
|
+
[linear gradients]: https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient
|
@@ -24,20 +24,26 @@ const EDGE_DETECTION_INACCURACY_PX = 1;
|
|
24
24
|
export const ScrollView = (props) => {
|
25
25
|
const {
|
26
26
|
arrows,
|
27
|
-
arrowsColor,
|
28
27
|
arrowsScrollStep,
|
29
28
|
autoScroll,
|
30
29
|
children,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
customStartShadowStyle,
|
30
|
+
endShadowBackground,
|
31
|
+
endShadowInitialOffset,
|
32
|
+
endShadowSize,
|
35
33
|
id,
|
36
34
|
debounce,
|
37
35
|
direction,
|
36
|
+
nextArrowColor,
|
37
|
+
nextArrowElement,
|
38
|
+
nextArrowInitialOffset,
|
39
|
+
prevArrowColor,
|
40
|
+
prevArrowElement,
|
41
|
+
prevArrowInitialOffset,
|
38
42
|
scrollbar,
|
39
|
-
|
40
|
-
|
43
|
+
shadows,
|
44
|
+
startShadowBackground,
|
45
|
+
startShadowInitialOffset,
|
46
|
+
startShadowSize,
|
41
47
|
} = props;
|
42
48
|
|
43
49
|
const { translations } = useContext(RUIContext);
|
@@ -84,7 +90,7 @@ export const ScrollView = (props) => {
|
|
84
90
|
|
85
91
|
/**
|
86
92
|
* If autoScroll is enabled, it automatically scrolls viewport element to the end of the
|
87
|
-
*
|
93
|
+
* viewport when content is changed. It is performed only when viewport element is
|
88
94
|
* scrolled to the end of the viewport or when viewport element is in any position but
|
89
95
|
* autoScroll triggered by previous change is still in progress.
|
90
96
|
*/
|
@@ -156,43 +162,6 @@ export const ScrollView = (props) => {
|
|
156
162
|
[autoScroll, autoScrollChildrenKeys, autoScrollChildrenLength],
|
157
163
|
);
|
158
164
|
|
159
|
-
const setAlpha = (rgba, alpha) => ({
|
160
|
-
...rgba,
|
161
|
-
alpha,
|
162
|
-
});
|
163
|
-
|
164
|
-
const rgbaToString = (rgba) => (
|
165
|
-
`rgba(${rgba.red}, ${rgba.green}, ${rgba.blue}, ${rgba.alpha})`
|
166
|
-
);
|
167
|
-
|
168
|
-
const inlineStyle = (
|
169
|
-
scrollDirection,
|
170
|
-
customArrowsColor,
|
171
|
-
customShadowColor,
|
172
|
-
customShadowSize,
|
173
|
-
startShadowStyle,
|
174
|
-
endShadowStyle,
|
175
|
-
) => {
|
176
|
-
const shadowStartColor = rgbaToString(customShadowColor);
|
177
|
-
const shadowEndColor = rgbaToString(setAlpha(customShadowColor, 0));
|
178
|
-
|
179
|
-
/* eslint-disable sort-keys */
|
180
|
-
return {
|
181
|
-
'--rui-local-arrow-color': customArrowsColor || 'inherit',
|
182
|
-
'--rui-local-shadow-width': scrollDirection === 'horizontal' ? shadowSize : 'auto',
|
183
|
-
'--rui-local-shadow-height': scrollDirection === 'horizontal' ? 'auto' : shadowSize,
|
184
|
-
'--rui-local-start-shadow-background':
|
185
|
-
startShadowStyle.background
|
186
|
-
|| `linear-gradient(${direction === 'horizontal' ? 'to right' : 'to bottom'}, ${shadowStartColor}, ${shadowEndColor})`,
|
187
|
-
'--rui-local-start-shadow-box-shadow': startShadowStyle.boxShadow || 'none',
|
188
|
-
'--rui-local-end-shadow-background':
|
189
|
-
endShadowStyle.background
|
190
|
-
|| `linear-gradient(${direction === 'horizontal' ? 'to left' : 'to top'}, ${shadowStartColor}, ${shadowEndColor})`,
|
191
|
-
'--rui-local-end-shadow-box-shadow': endShadowStyle.boxShadow || 'none',
|
192
|
-
};
|
193
|
-
/* eslint-enable sort-keys */
|
194
|
-
};
|
195
|
-
|
196
165
|
const arrowHandler = (contentEl, viewportEl, scrollViewDirection, shiftDirection, step) => {
|
197
166
|
const offset = shiftDirection === 'next' ? step : -1 * step;
|
198
167
|
const differenceX = scrollViewDirection === 'horizontal' ? offset : 0;
|
@@ -210,31 +179,39 @@ export const ScrollView = (props) => {
|
|
210
179
|
!scrollbar && styles.hasRootScrollbarDisabled,
|
211
180
|
direction === 'horizontal' ? styles.isRootHorizontal : styles.isRootVertical,
|
212
181
|
)}
|
213
|
-
style={inlineStyle(
|
214
|
-
direction,
|
215
|
-
arrowsColor,
|
216
|
-
shadowColor,
|
217
|
-
shadowSize,
|
218
|
-
customStartShadowStyle,
|
219
|
-
customEndShadowStyle,
|
220
|
-
)}
|
221
182
|
id={id}
|
183
|
+
style={{
|
184
|
+
'--rui-local-end-shadow-background': endShadowBackground,
|
185
|
+
'--rui-local-end-shadow-direction': direction === 'horizontal' ? 'to left' : 'to top',
|
186
|
+
'--rui-local-end-shadow-initial-offset': endShadowInitialOffset,
|
187
|
+
'--rui-local-end-shadow-size': endShadowSize,
|
188
|
+
'--rui-local-next-arrow-color': nextArrowColor,
|
189
|
+
'--rui-local-next-arrow-initial-offset': nextArrowInitialOffset,
|
190
|
+
'--rui-local-prev-arrow-color': prevArrowColor,
|
191
|
+
'--rui-local-prev-arrow-initial-offset': prevArrowInitialOffset,
|
192
|
+
'--rui-local-start-shadow-background': startShadowBackground,
|
193
|
+
'--rui-local-start-shadow-direction': direction === 'horizontal' ? 'to right' : 'to bottom',
|
194
|
+
'--rui-local-start-shadow-initial-offset': startShadowInitialOffset,
|
195
|
+
'--rui-local-start-shadow-size': startShadowSize,
|
196
|
+
}}
|
222
197
|
>
|
223
198
|
<div className={styles.viewport} ref={scrollViewViewportEl}>
|
224
199
|
<div
|
225
200
|
className={styles.content}
|
226
|
-
ref={scrollViewContentEl}
|
227
201
|
id={id && `${id}__content`}
|
202
|
+
ref={scrollViewContentEl}
|
228
203
|
>
|
229
204
|
{children}
|
230
205
|
</div>
|
231
206
|
</div>
|
232
|
-
|
207
|
+
{shadows && (
|
208
|
+
<div className={styles.scrollingShadows} aria-hidden />
|
209
|
+
)}
|
233
210
|
{arrows && (
|
234
211
|
<>
|
235
212
|
<button
|
236
|
-
type="button"
|
237
213
|
className={styles.arrowPrev}
|
214
|
+
id={id && `${id}__arrowPrevButton`}
|
238
215
|
onClick={() => arrowHandler(
|
239
216
|
scrollViewContentEl,
|
240
217
|
scrollViewViewportEl,
|
@@ -243,15 +220,15 @@ export const ScrollView = (props) => {
|
|
243
220
|
arrowsScrollStep,
|
244
221
|
)}
|
245
222
|
title={translations.ScrollView.previous}
|
246
|
-
|
223
|
+
type="button"
|
247
224
|
>
|
248
|
-
{
|
225
|
+
{prevArrowElement || (
|
249
226
|
<span className={styles.arrowIcon} aria-hidden />
|
250
227
|
)}
|
251
228
|
</button>
|
252
229
|
<button
|
253
|
-
type="button"
|
254
230
|
className={styles.arrowNext}
|
231
|
+
id={id && `${id}__arrowNextButton`}
|
255
232
|
onClick={() => arrowHandler(
|
256
233
|
scrollViewContentEl,
|
257
234
|
scrollViewViewportEl,
|
@@ -260,9 +237,9 @@ export const ScrollView = (props) => {
|
|
260
237
|
arrowsScrollStep,
|
261
238
|
)}
|
262
239
|
title={translations.ScrollView.next}
|
263
|
-
|
240
|
+
type="button"
|
264
241
|
>
|
265
|
-
{
|
242
|
+
{nextArrowElement || (
|
266
243
|
<span className={styles.arrowIcon} aria-hidden />
|
267
244
|
)}
|
268
245
|
</button>
|
@@ -274,25 +251,26 @@ export const ScrollView = (props) => {
|
|
274
251
|
|
275
252
|
ScrollView.defaultProps = {
|
276
253
|
arrows: false,
|
277
|
-
arrowsColor: undefined,
|
278
254
|
arrowsScrollStep: 200,
|
279
255
|
autoScroll: 'off',
|
280
256
|
children: null,
|
281
|
-
customEndShadowStyle: {},
|
282
|
-
customNextArrow: null,
|
283
|
-
customPrevArrow: null,
|
284
|
-
customStartShadowStyle: {},
|
285
257
|
debounce: 50,
|
286
258
|
direction: 'vertical',
|
259
|
+
endShadowBackground: 'linear-gradient(var(--rui-local-end-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
260
|
+
endShadowInitialOffset: '-1rem',
|
261
|
+
endShadowSize: '2em',
|
287
262
|
id: undefined,
|
263
|
+
nextArrowColor: undefined,
|
264
|
+
nextArrowElement: null,
|
265
|
+
nextArrowInitialOffset: '-0.5rem',
|
266
|
+
prevArrowColor: undefined,
|
267
|
+
prevArrowElement: null,
|
268
|
+
prevArrowInitialOffset: '-0.5rem',
|
288
269
|
scrollbar: true,
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
red: 255,
|
294
|
-
},
|
295
|
-
shadowSize: '2em',
|
270
|
+
shadows: true,
|
271
|
+
startShadowBackground: 'linear-gradient(var(--rui-local-start-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
272
|
+
startShadowInitialOffset: '-1rem',
|
273
|
+
startShadowSize: '2em',
|
296
274
|
};
|
297
275
|
|
298
276
|
ScrollView.propTypes = {
|
@@ -300,21 +278,17 @@ ScrollView.propTypes = {
|
|
300
278
|
* If `true`, display the arrow controls.
|
301
279
|
*/
|
302
280
|
arrows: PropTypes.bool,
|
303
|
-
/**
|
304
|
-
* Text color of the arrow controls. Accepts any valid CSS color value.
|
305
|
-
*/
|
306
|
-
arrowsColor: PropTypes.string,
|
307
281
|
/**
|
308
282
|
* Portion to scroll by when the arrows are clicked, in px.
|
309
283
|
*/
|
310
284
|
arrowsScrollStep: PropTypes.number,
|
311
285
|
/**
|
312
|
-
*
|
313
|
-
*
|
286
|
+
* The auto-scroll mechanism requires having the `key` prop set for every child present in `children`
|
287
|
+
* because it detects changes of those keys. Without the keys, the auto-scroll will not work.
|
314
288
|
*
|
315
|
-
* Option `always` means
|
316
|
-
* Option `detectEnd` means
|
317
|
-
* and the user scrolled at the end of the viewport at the moment of the change.
|
289
|
+
* Option `always` means the auto-scroll scrolls to the end every time the content changes.
|
290
|
+
* Option `detectEnd` means the auto-scroll scrolls to the end only when the content is changed
|
291
|
+
* and the user has scrolled at the end of the viewport at the moment of the change.
|
318
292
|
*
|
319
293
|
* See https://reactjs.org/docs/lists-and-keys.html#keys
|
320
294
|
*/
|
@@ -324,35 +298,26 @@ ScrollView.propTypes = {
|
|
324
298
|
*/
|
325
299
|
children: PropTypes.node,
|
326
300
|
/**
|
327
|
-
*
|
328
|
-
*/
|
329
|
-
customEndShadowStyle: PropTypes.shape({
|
330
|
-
background: PropTypes.string,
|
331
|
-
boxShadow: PropTypes.string,
|
332
|
-
}),
|
333
|
-
/**
|
334
|
-
* Custom HTML or React Component to replace the default next-arrow control.
|
301
|
+
* Delay in ms before the display of arrows and scrolling shadows is evaluated during interaction.
|
335
302
|
*/
|
336
|
-
|
303
|
+
debounce: PropTypes.number,
|
337
304
|
/**
|
338
|
-
*
|
305
|
+
* Direction of scrolling.
|
339
306
|
*/
|
340
|
-
|
307
|
+
direction: PropTypes.oneOf(['horizontal', 'vertical']),
|
341
308
|
/**
|
342
|
-
* Custom
|
309
|
+
* Custom background of the end scrolling shadow. Can be a CSS gradient or an image `url()`.
|
343
310
|
*/
|
344
|
-
|
345
|
-
background: PropTypes.string,
|
346
|
-
boxShadow: PropTypes.string,
|
347
|
-
}),
|
311
|
+
endShadowBackground: PropTypes.string,
|
348
312
|
/**
|
349
|
-
*
|
313
|
+
* Initial offset of the end scrolling shadow (transitioned). If set, the end scrolling shadow slides in
|
314
|
+
* by this distance.
|
350
315
|
*/
|
351
|
-
|
316
|
+
endShadowInitialOffset: PropTypes.string,
|
352
317
|
/**
|
353
|
-
*
|
318
|
+
* Size of the end scrolling shadow. Accepts any valid CSS length value.
|
354
319
|
*/
|
355
|
-
|
320
|
+
endShadowSize: PropTypes.string,
|
356
321
|
/**
|
357
322
|
* ID of the root HTML element. It also serves as base for nested elements:
|
358
323
|
* * `<ID>__content`
|
@@ -360,25 +325,51 @@ ScrollView.propTypes = {
|
|
360
325
|
* * `<ID>__arrowNextButton`
|
361
326
|
*/
|
362
327
|
id: PropTypes.string,
|
328
|
+
/**
|
329
|
+
* Text color of the end arrow control. Accepts any valid CSS color value.
|
330
|
+
*/
|
331
|
+
nextArrowColor: PropTypes.string,
|
332
|
+
/**
|
333
|
+
* Custom HTML or React Component to replace the default next-arrow control.
|
334
|
+
*/
|
335
|
+
nextArrowElement: PropTypes.node,
|
336
|
+
/**
|
337
|
+
* Initial offset of the end arrow control (transitioned). If set, the next arrow slides in by this distance.
|
338
|
+
*/
|
339
|
+
nextArrowInitialOffset: PropTypes.string,
|
340
|
+
/**
|
341
|
+
* Text color of the start arrow control. Accepts any valid CSS color value.
|
342
|
+
*/
|
343
|
+
prevArrowColor: PropTypes.string,
|
344
|
+
/**
|
345
|
+
* Custom HTML or React Component to replace the default prev-arrow control.
|
346
|
+
*/
|
347
|
+
prevArrowElement: PropTypes.node,
|
348
|
+
/**
|
349
|
+
* Initial offset of the start arrow control (transitioned). If set, the prev arrow slides in by this distance.
|
350
|
+
*/
|
351
|
+
prevArrowInitialOffset: PropTypes.string,
|
363
352
|
/**
|
364
353
|
* If `false`, the system scrollbar will be hidden.
|
365
354
|
*/
|
366
355
|
scrollbar: PropTypes.bool,
|
367
356
|
/**
|
368
|
-
*
|
369
|
-
|
357
|
+
* If `true`, display scrolling shadows.
|
358
|
+
*/
|
359
|
+
shadows: PropTypes.bool,
|
360
|
+
/**
|
361
|
+
* Custom background of the start scrolling shadow. Can be a CSS gradient or an image `url()`.
|
362
|
+
*/
|
363
|
+
startShadowBackground: PropTypes.string,
|
364
|
+
/**
|
365
|
+
* Initial offset of the start scrolling shadow (transitioned). If set, the start scrolling shadow slides in
|
366
|
+
* by this distance.
|
370
367
|
*/
|
371
|
-
|
372
|
-
alpha: PropTypes.number.isRequired,
|
373
|
-
blue: PropTypes.number.isRequired,
|
374
|
-
green: PropTypes.number.isRequired,
|
375
|
-
red: PropTypes.number.isRequired,
|
376
|
-
}),
|
368
|
+
startShadowInitialOffset: PropTypes.string,
|
377
369
|
/**
|
378
|
-
* Size of scrolling
|
379
|
-
* mode.
|
370
|
+
* Size of the start scrolling shadow. Accepts any valid CSS length value.
|
380
371
|
*/
|
381
|
-
|
372
|
+
startShadowSize: PropTypes.string,
|
382
373
|
};
|
383
374
|
|
384
375
|
export const ScrollViewWithGlobalProps = withGlobalProps(ScrollView, 'ScrollView');
|