Skip to content

Commit b370cb4

Browse files
authored
Merge pull request #6 from EOS-uiux-Solutions/dev
[React Package] - Addition of Flip prop
2 parents 6ae5c7f + dbeb1ab commit b370cb4

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

gulpfile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export default series(
4343
copy({
4444
from: ['utils/helper.ts'],
4545
toDir: 'src/'
46+
}),
47+
48+
copy({
49+
from: ['utils/flipFunction.ts'],
50+
toDir: 'src/'
4651
})
4752
)
4853
)

scripts/iconScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function generateIconComponents ({ type, from }: IconGenerateScript) {
2626
}
2727

2828
// eslint-disable-next-line no-template-curly-in-string
29-
const propString = 'svg transform={`rotate(${rotate})`} fill={color} width={size} height={size}'
29+
const propString = 'svg transform={`rotate(${rotate}) translate(${translateX}, ${translateY}) scale(${scaleX}, ${scaleY})`} fill={color} width={size} height={size}'
3030
data = data.replace('svg', propString)
3131

3232
const render = componentTemplate({ fileName, data })

template/iconComponent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ function componentTemplate ({ fileName, data }:TemplateProps) {
66
77
import * as React from 'react';
88
import { IconProps, valuesMap } from '../helper';
9+
import { flipFunction } from '../flipFunction';
910
10-
function Eos${fileName}({size = "m", color = "black", rotate = 0}: IconProps) {
11+
function Eos${fileName}({size = "m", color = "black", rotate = 0, horizontalFlip = false, verticalFlip = false}: IconProps) {
1112
const sizeString: string = size.toString()
1213
if(Object.keys(valuesMap).includes(sizeString)) {
1314
size = valuesMap[size]
1415
}
16+
const { scaleX, scaleY, translateX, translateY } = flipFunction({horizontalFlip,verticalFlip})
1517
return (
1618
${data}
1719
);

utils/flipFunction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { FlipProps } from './helper'
2+
3+
export function flipFunction ({ horizontalFlip, verticalFlip }: FlipProps) {
4+
let translateX = 0
5+
let translateY = 0
6+
let scaleX = 1
7+
let scaleY = 1
8+
9+
if (horizontalFlip) {
10+
scaleX = -1
11+
translateX = 24
12+
}
13+
14+
if (verticalFlip) {
15+
scaleY = -1
16+
translateY = 24
17+
}
18+
19+
return { scaleX, scaleY, translateX, translateY }
20+
}

utils/helper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export interface IconProps {
22
size?: string | number,
33
color?: string,
4-
rotate?: string | number
4+
rotate?: string | number,
5+
horizontalFlip?: boolean,
6+
verticalFlip?: boolean
57
}
68

79
export interface ValueMap {
@@ -21,3 +23,8 @@ export const valuesMap: ValueMap = {
2123
xxl: 48,
2224
xxxl: 64
2325
}
26+
27+
export interface FlipProps {
28+
horizontalFlip: boolean;
29+
verticalFlip: boolean;
30+
}

0 commit comments

Comments
 (0)