Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove inject icons #571

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module.exports = {
});

config.module.rules.push({
test: /\.svg$/,
loader: require.resolve('svg-sprite-loader'),
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: [require.resolve('@svgr/webpack')],
});

return config;
Expand Down
6 changes: 3 additions & 3 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = {
use: ['babel-loader', 'ts-loader'],
},
{
test: /\.svg$/,
exclude: [paths.publicFiles],
loader: 'svg-sprite-loader',
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-02-09 at 11 58 51

@vozbrann could check if it can be helpful for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really in our case. Will require types refactoring.
The only usage of imported icon:
image

},
{
test: /\.css$/,
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,16 @@ Peer dependencies:
To start importing and using components in your project, you need the following:

- Import css of **Panenco UI** from `@panenco/ui/lib/styles.css`. It could be any way of global import of styles into your project. For instance, using `import` in js with a proper loader or using `@import` in your `css`.
- Include Panenco UI icons by importing `@panenco/ui/lib/spritesheet.svg` as a file (to obtain its URL and be able to inject it to DOM asynchronously) and pass it to the `injectIcons` function as shown below.
- Wrap your application with the `ThemeProvider` component from `styled-components` and pass the theme to it.

```javascript
import React from 'react';
import { render } from 'react-dom';
import AppContainers from 'containers';
import { ThemeProvider } from 'styled-components';
import { injectIcons } from '@panenco/ui';
import { theme } from './theme';

import '@panenco/ui/lib/styles.css';
import svgSprite from '!file-loader!@panenco/ui/lib/spritesheet.svg';

injectIcons(svgSprite);

const App = () => (
<ThemeProvider theme={theme}>
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@babel/preset-typescript": "^7.15.0",
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@panenco/rollup-plugin-svg-sprite": "^1.0.3",
"@rollup/plugin-alias": "^4.0.0",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-commonjs": "^24.0.0",
Expand All @@ -73,13 +72,14 @@
"@storybook/react": "^6.5.16",
"@storybook/storybook-deployer": "^2.8.16",
"@storybook/testing-library": "^0.0.13",
"@svgr/rollup": "^6.5.1",
"@svgr/webpack": "5.5.0",
"@types/classnames": "^2.2.10",
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9",
"@types/react-router-dom": "^5.1.8",
"@types/react-select": "^3.0.11",
"@types/styled-components": "^5.1.26",
"@types/svg-sprite-loader": "^3.9.2",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
Expand Down Expand Up @@ -132,9 +132,6 @@
"stylelint-config-idiomatic-order": "^9.0.0",
"stylelint-config-standard": "^29.0.0",
"stylelint-order": "^6.0.0",
"svg-sprite-loader": "^6.0.11",
"svgo": "^3.0.0",
"svgo-loader": "^4.0.0",
"terser-webpack-plugin": "^5.0.0",
"ts-loader": "^9.0.0",
"tsconfig-paths-webpack-plugin": "^4.0.0",
Expand Down
7 changes: 2 additions & 5 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable global-require */
import svgSprite from '@panenco/rollup-plugin-svg-sprite';
import path from 'path';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
Expand All @@ -9,6 +8,7 @@ import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import ttypescript from 'ttypescript';
import svgr from '@svgr/rollup';

import packageJson from './package.json' assert { type: 'json' };
import paths from './config/paths.js';
Expand All @@ -22,6 +22,7 @@ export default {
format: 'esm',
},
plugins: [
svgr(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
Expand All @@ -46,10 +47,6 @@ export default {
}),
commonjs(),
json(),
svgSprite({
outputFolder: paths.outputPath,
spriteFilename: 'spritesheet.svg',
}),
],
external,
};
19 changes: 9 additions & 10 deletions src/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { StyledSVG } from './style';
import { defaultIcons } from './icons';

const sizeToPx = {
sm: '16px',
md: '24px',
lg: '28px',
sm: 16,
md: 24,
lg: 28,
};

export type IconProps<T extends { lg: any; md: any; sm: any }> = {
Expand Down Expand Up @@ -37,21 +37,20 @@ export const withIcons =
{ icon = 'eye', className, strokeWidth = 1.33, onClick, size = 'md', disabled, width, height, ...iconProps },
ref,
): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> => {
const iconToRender = icons[size][icon] || icons.sm[icon] || icons.md[icon] || icons.lg[icon];
const IconToRender = icons[size][icon] || icons.sm[icon] || icons.md[icon] || icons.lg[icon];

return (
<StyledSVG
as={IconToRender}
className={cx(disabled && 'disabled', 'svg', className)}
viewBox={iconToRender.viewBox}
width={width || sizeToPx[size]}
height={height || sizeToPx[size]}
viewBox={`0 0 ${sizeToPx[size]} ${sizeToPx[size]}`}
width={width || `${sizeToPx[size]}px`}
height={height || `${sizeToPx[size]}px`}
strokeWidth={strokeWidth}
onClick={onClick}
ref={ref}
{...iconProps}
>
<use xlinkHref={`#${iconToRender.id}`} />
</StyledSVG>
/>
);
},
);
Expand Down
1 change: 0 additions & 1 deletion src/utils/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './id-generator';
export * from './injectIcons';
export * from './size-to-string';
13 changes: 0 additions & 13 deletions src/utils/helpers/injectIcons.ts

This file was deleted.

Loading