Skip to content

Commit

Permalink
refactor: Remove IconSettings context
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorov-xyz committed Aug 16, 2023
1 parent eaff6da commit ec27fd5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/icons-scripts/scripts/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function generateIcons(options) {
* @param {string} dir
*/
function createIndexExports(exportsMap, dir) {
const exported = [`export { IconSettingsProvider } from '@vkontakte/icons-sprite';`];
const exported = [];

const keys = Object.keys(exportsMap);
if (!keys) {
Expand Down
23 changes: 0 additions & 23 deletions packages/icons-sprite/src/IconSettings.tsx

This file was deleted.

31 changes: 10 additions & 21 deletions packages/icons-sprite/src/SvgIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { BrowserSymbol } from './browser-symbol';
import { IconSettingsInterface, IconSettingsContext } from './IconSettings';
import { addSpriteSymbol, useIsomorphicLayoutEffect } from './sprite';
import { warnOnce } from './warnOnce';

Expand All @@ -11,19 +10,6 @@ export interface SvgIconProps extends React.SVGProps<SVGSVGElement> {
title?: string;
}

function iconClass(fragments: string[], { classPrefix, globalClasses }: IconSettingsInterface) {
let res = '';
for (let i = 0; i < fragments.length; i++) {
if (classPrefix) {
res += ' ' + (classPrefix + fragments[i]);
}
if (!classPrefix || globalClasses) {
res += ' ' + fragments[i];
}
}
return res;
}

const SvgIcon = ({
width = 0,
height = 0,
Expand All @@ -39,12 +25,6 @@ const SvgIcon = ({
}: SvgIconProps) => {
const size = Math.max(width, height);

const iconSettings = React.useContext(IconSettingsContext);
const ownClass = iconClass(
['Icon', `Icon--${size}`, `Icon--w-${width}`, `Icon--h-${height}`, `Icon--${id}`],
iconSettings,
);

const style = {
width,
height,
Expand All @@ -56,7 +36,16 @@ const SvgIcon = ({
aria-hidden="true"
display="block"
{...restProps}
className={`${ownClass} ${className}`}
className={[
'vkuiIcon',
`vkuiIcon--${size}`,
`vkuiIcon--w-${width}`,
`vkuiIcon--h-${height}`,
`vkuiIcon--${id}`,
className,
]
.join(' ')
.trim()}
viewBox={viewBox}
width={width}
height={height}
Expand Down
1 change: 0 additions & 1 deletion packages/icons-sprite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { BrowserSprite } from './browser-sprite';
export { BrowserSymbol } from './browser-symbol';
export { makeIcon } from './SvgIcon';
export { IconSettingsProvider } from './IconSettings';

0 comments on commit ec27fd5

Please sign in to comment.