Skip to content

Commit 652adfa

Browse files
author
Juli Ovechkina
authored
fix: remove background from Overlowscroller (#153)
1 parent 83254e4 commit 652adfa

File tree

6 files changed

+39
-36
lines changed

6 files changed

+39
-36
lines changed

src/components/OverflowScroller/OverflowScroller.scss

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33
$block: '.#{$ns}overflow-scroller';
44

55
#{$block} {
6+
display: flex;
7+
align-items: center;
68
position: relative;
7-
89
overflow-x: hidden;
910

10-
&__wrapper {
11+
&__container {
12+
width: 100%;
1113
position: relative;
1214

13-
transition: left 0.3s;
15+
&_padding {
16+
&-left {
17+
padding-left: $indentSM;
18+
}
19+
&-right {
20+
padding-right: $indentSM;
21+
}
22+
}
23+
}
24+
25+
&__wrapper {
26+
position: relative;
27+
transition: left 0.6s;
1428
}
1529

16-
&__scroller {
30+
&__arrow {
1731
position: absolute;
1832
z-index: 10;
1933
top: 0;
@@ -28,12 +42,6 @@ $block: '.#{$ns}overflow-scroller';
2842
cursor: pointer;
2943

3044
color: var(--yc-color-text-secondary);
31-
background: linear-gradient(
32-
to left,
33-
var(--yc-color-base-background) 70%,
34-
var(--pc-transparent) 100%
35-
)
36-
no-repeat;
3745

3846
&_type_left {
3947
left: 0;

src/components/OverflowScroller/OverflowScroller.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './OverflowScroller.scss';
88

99
const b = block('overflow-scroller');
1010
const TRANSITION_TIME = 300;
11+
const PADDING_SIZE = 24;
1112

1213
type Arrow = 'left' | 'right';
1314

@@ -27,7 +28,7 @@ export default class OverflowScroller extends React.Component<
2728
OverflowScrollerState
2829
> {
2930
state = {
30-
arrows: [],
31+
arrows: [] as Arrow[],
3132
scrollValue: 0,
3233
};
3334
containerRef = createRef<HTMLDivElement>();
@@ -57,16 +58,25 @@ export default class OverflowScroller extends React.Component<
5758
const {className, children} = this.props;
5859
const {arrows, scrollValue} = this.state;
5960
const wrapperStyle = arrows.length ? {left: -scrollValue} : {left: 0};
61+
const paddingLeft = arrows.includes('left');
62+
const paddingRight = arrows.includes('right');
6063

6164
return (
62-
<div className={b(null, className)} ref={this.containerRef}>
63-
<div className={b('wrapper')} style={wrapperStyle} ref={this.wrapperRef}>
64-
{children}
65+
<div
66+
className={b('container', {
67+
'padding-left': paddingLeft,
68+
'padding-right': paddingRight,
69+
})}
70+
>
71+
<div className={b(null, className)} ref={this.containerRef}>
72+
<div className={b('wrapper')} style={wrapperStyle} ref={this.wrapperRef}>
73+
{children}
74+
</div>
6575
</div>
6676
{arrows.map((direction: Arrow) => (
6777
<div
6878
key={direction}
69-
className={b('scroller', {type: direction})}
79+
className={b('arrow', {type: direction})}
7080
onClick={(e: React.MouseEvent) => this.handleScrollClick(e, direction)}
7181
>
7282
<ToggleArrow size={18} type={'horizontal'} iconType="navigation" />
@@ -94,7 +104,7 @@ export default class OverflowScroller extends React.Component<
94104
}, 100);
95105

96106
private handleScrollClick = (e: React.MouseEvent, arrow: Arrow) => {
97-
const {scrollValue} = this.state;
107+
const {scrollValue, arrows} = this.state;
98108
const {onScrollStart} = this.props;
99109

100110
if (
@@ -107,8 +117,11 @@ export default class OverflowScroller extends React.Component<
107117
const wrapperWidth = this.wrapperRef.current.offsetWidth;
108118
const hiddenWidth =
109119
arrow === 'right' ? wrapperWidth - (containerWidth + scrollValue) : scrollValue;
120+
const padding =
121+
arrows.length > 1 && hiddenWidth + PADDING_SIZE > containerWidth ? PADDING_SIZE : 0;
110122
const delta = containerWidth > hiddenWidth ? hiddenWidth : containerWidth;
111-
const newScrollValue = arrow === 'right' ? scrollValue + delta : scrollValue - delta;
123+
const newScrollValue =
124+
arrow === 'right' ? scrollValue + delta + padding : scrollValue - delta - padding;
112125
let newArrows: Arrow[] = ['left', 'right'];
113126

114127
if (newScrollValue + containerWidth >= wrapperWidth) {

src/components/OverflowScroller/__stories__/OverflowScroller.stories.scss

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/components/OverflowScroller/__stories__/OverflowScroller.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import React from 'react';
44
import OverflowScroller, {OverflowScrollerProps} from '../OverflowScroller';
55
import {COMPONENTS} from '../../../demo/constants';
66

7-
import './OverflowScroller.stories.scss';
8-
9-
import data from './data.json';
10-
117
export default {
128
component: OverflowScroller,
139
title: `${COMPONENTS}/OverflowScroller`,
@@ -31,5 +27,3 @@ const DefaultTemplate: Story<OverflowScrollerProps> = (args) => (
3127
);
3228

3329
export const Default = DefaultTemplate.bind({});
34-
35-
Default.args = data.default.content;

src/components/OverflowScroller/__stories__/data.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/navigation/components/Header/Header.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ $block: '.#{$ns}header';
4848
&__navigation {
4949
@include add-specificity(&) {
5050
position: relative;
51-
margin-right: $normalOffset;
5251

5352
flex: 1 0 0;
5453
justify-content: flex-start;
@@ -69,7 +68,7 @@ $block: '.#{$ns}header';
6968
justify-content: space-between;
7069
align-items: center;
7170

72-
margin-right: $indentS;
71+
margin-right: $indentM;
7372
}
7473

7574
&__buttons {

0 commit comments

Comments
 (0)