Skip to content

Commit be7dcd5

Browse files
feat: support rtl (#209)
1 parent 573ec0a commit be7dcd5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

__tests__/functions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ describe('getCss', () => {
162162
duration: ZERO_SEC,
163163
'padding_bottom': 'a',
164164
cssFilter: css => css,
165+
rtl: true,
165166
});
166167
expect(css).toHaveProperty('background-position');
167-
expect(css['background-position']).toBe('left -100% center');
168+
expect(css['background-position']).toBe('right 0 center');
168169
});
169170

170171
it('should get stripe css', () => {

src/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export const SETTINGS_DEFAULTS = {
1212
cssFilter: function(css) {
1313
return css;
1414
},
15+
rtl: false,
1516
};

src/functions.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,31 @@ export const isStatic = options => options.stripe || (ZERO_SEC === options.delay
6161
*/
6262
export const getCss = options => options.cssFilter(options.stripe ? getStripeCss(options) : getMarkerCss(options));
6363

64+
/**
65+
* @param {object} options options
66+
* @returns {string} direction
67+
*/
68+
const getDirection = options => options.rtl ? 'right' : 'left';
69+
70+
/**
71+
* @param {object} options options
72+
* @returns {string} percentage
73+
*/
74+
const getStartPercentage = options => options.rtl ? '0' : '-100%';
75+
76+
/**
77+
* @param {object} options options
78+
* @returns {string} percentage
79+
*/
80+
const getGoalPercentage = options => options.rtl ? '100%' : '0';
81+
6482
/**
6583
* @param {object} options options
6684
* @returns {object} css
6785
*/
6886
const getCommonCss = options => Object.assign({
6987
'display': 'inline',
70-
'background-position': 'left 0 center',
88+
'background-position': `${getDirection(options)} ${getGoalPercentage(options)} center`,
7189
'padding-bottom': options.padding_bottom,
7290
}, options.font_weight ? {
7391
'font-weight': options.font_weight,
@@ -82,7 +100,7 @@ const getMarkerCss = options => Object.assign({}, getCommonCss(options), {
82100
'background-repeat': 'repeat-x',
83101
'background-image': `linear-gradient(to right, rgba(255,255,255,0) 50%, ${options.color} 50%)`,
84102
}, isStatic(options) ? {
85-
'background-position': 'left -100% center',
103+
'background-position': `${getDirection(options)} ${getStartPercentage(options)} center`,
86104
} : {});
87105

88106
/**
@@ -133,7 +151,7 @@ export const stop = target => {
133151
export const onInView = (target, options) => {
134152
target.stop(true, true).css({
135153
transition: `background-position ${options.duration} ${options.function} ${options.delay}`,
136-
'background-position': 'left -100% center',
154+
'background-position': `${getDirection(options)} ${getStartPercentage(options)} center`,
137155
});
138156
if (!options.repeat) {
139157
stop(target);

0 commit comments

Comments
 (0)