Skip to content

Commit

Permalink
fix(review): rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
inomdzhon committed Aug 10, 2022
1 parent dd63966 commit fa2556e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
20 changes: 10 additions & 10 deletions packages/icons-scripts/scripts/reactify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ function pxToEm(pxSize, baseSize) {
}

const reactify = (symbol, componentName) => {
const defaultWidth = Number(symbol.viewBox.split(' ')[2]);
const defaultHeight = Number(symbol.viewBox.split(' ')[3]);
const viewBoxWidth = Number(symbol.viewBox.split(' ')[2]);
const viewBoxHeight = Number(symbol.viewBox.split(' ')[3]);

const baseSize = Math.max(defaultWidth, defaultHeight);
const relativeWidth = pxToEm(defaultWidth, baseSize);
const relativeHeight = pxToEm(defaultHeight, baseSize);
const fontSize = Math.max(viewBoxWidth, viewBoxHeight);
const fontSizeWidth = pxToEm(viewBoxWidth, fontSize);
const fontSizeHeight = pxToEm(viewBoxHeight, fontSize);

return `import { HTMLAttributes, RefCallback, RefObject } from 'react';
import { makeIcon } from '../SvgIcon';
Expand All @@ -28,11 +28,11 @@ export default makeIcon<${componentName}Props>(
'${componentName}',
'${symbol.id}',
'${symbol.viewBox}',
${defaultWidth},
${defaultHeight},
'${relativeWidth}',
'${relativeHeight}',
${baseSize},
${viewBoxWidth},
${viewBoxHeight},
${fontSize},
'${fontSizeWidth}',
'${fontSizeHeight}',
'${symbol.render()}'
);
`;
Expand Down
54 changes: 27 additions & 27 deletions packages/icons-scripts/src/SvgIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface SvgIconProps extends React.HTMLAttributes<HTMLDivElement> {
}

interface SvgIconInternalProps extends SvgIconProps {
defaultWidth: number;
defaultHeight: number;
relativeWidth: string;
relativeHeight: string;
viewBoxWidth: number;
viewBoxHeight: number;
fontSizeWidth: string;
fontSizeHeight: string;
}

const svgStyle = { display: 'block' };
Expand All @@ -47,10 +47,10 @@ const SvgIcon: React.FC<SvgIconInternalProps> = ({
/**
* Внутренние параметры (скрыты от пользователя)
*/
defaultWidth,
defaultHeight,
relativeWidth,
relativeHeight,
viewBoxWidth,
viewBoxHeight,
fontSizeWidth,
fontSizeHeight,

/**
* Пользовательские параметры.
Expand All @@ -72,13 +72,13 @@ const SvgIcon: React.FC<SvgIconInternalProps> = ({
}) => {
const iconSettings = React.useContext(IconSettingsContext);

const classNameWidth = widthProp || defaultWidth;
const classNameHeight = heightProp || defaultHeight;
const classNameWidth = widthProp || viewBoxWidth;
const classNameHeight = heightProp || viewBoxHeight;
const classNameSize = Math.max(classNameWidth, classNameHeight);
const ownClass = iconClass(['Icon', `Icon--${classNameSize}`, `Icon--w-${classNameWidth}`, `Icon--h-${classNameHeight}`, `Icon--${id}`], iconSettings);

const width = widthProp || relativeWidth;
const height = heightProp || relativeHeight;
const width = widthProp || fontSizeWidth;
const height = heightProp || fontSizeHeight;

return (
<Component
Expand Down Expand Up @@ -106,39 +106,39 @@ const SvgIcon: React.FC<SvgIconInternalProps> = ({
export function makeIcon<Props extends SvgIconProps = SvgIconProps>(
componentName: string,
id: string,
defaultViewBox: string,
defaultWidth: number,
defaultHeight: number,
relativeWidth: string,
relativeHeight: string,
defaultFontSize: number,
viewBox: string,
viewBoxWidth: number,
viewBoxHeight: number,
fontSize: number,
fontSizeWidth: string,
fontSizeHeight: string,
content: string,
): React.FC<Props> {
let isMounted = false;
function mountIcon() {
if (!isMounted) {
addSpriteSymbol(new BrowserSymbol({ id, viewBox: defaultViewBox, content }));
addSpriteSymbol(new BrowserSymbol({ id, viewBox: viewBox, content }));
isMounted = true;
}
}

const Icon: React.FC<Props> = ({
viewBox = defaultViewBox,
fontSize = defaultFontSize,
viewBox: viewBoxProp = viewBox,
fontSize: fontSizeProp = fontSize,
...restProps
}) => {
useIsomorphicLayoutEffect(mountIcon, []);

return (
<SvgIcon
{...restProps}
viewBox={viewBoxProp}
fontSize={fontSizeProp}
id={id}
viewBox={viewBox}
defaultWidth={defaultWidth}
defaultHeight={defaultHeight}
relativeWidth={relativeWidth}
relativeHeight={relativeHeight}
fontSize={fontSize}
viewBoxWidth={viewBoxWidth}
viewBoxHeight={viewBoxHeight}
fontSizeWidth={fontSizeWidth}
fontSizeHeight={fontSizeHeight}
/>
)
};
Expand Down

0 comments on commit fa2556e

Please sign in to comment.