Skip to content

Commit

Permalink
feat: 支持自定义组件名称,而不是固定的 iconfont
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Jul 31, 2023
1 parent ba7b0c6 commit 3d23446
Show file tree
Hide file tree
Showing 41 changed files with 125 additions and 86 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ npx iconfont-init
"use_rpx": true,
"trim_icon_prefix": "icon",
"default_icon_size": 18,
"design_width": 750
"design_width": 750,
"component_name": "iconfont"
}
```
### 配置参数说明:
Expand Down Expand Up @@ -94,6 +95,9 @@ npx iconfont-init
### default_icon_size
我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入props的方式改变这个size值。

### component_name
生成的组件名称,用于注册小程序的组件,所以该项只有在小程序平台下才会生效。此项能满足一个项目中引入多个 iconfont 组件。


# Step 3
开始生成Taro标准组件
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"@tarojs/taro": "^3.0.8"
},
"dependencies": {
"camelcase": "^6.0.0",
"colors": "^1.4.0",
"decamelize": "^5.0.0",
"fs-extra": "^8.1.0",
"iconfont-parser": "^1.0.0",
"mini-program-iconfont-cli": "0.6.1",
Expand Down
3 changes: 2 additions & 1 deletion scripts/config/iconfont-js.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"design_width": 720,
"save_dir": "./snapshots/iconfont-js",
"trim_icon_prefix": "icon",
"default_icon_size": 14
"default_icon_size": 14,
"component_name": "iconfont"
}
3 changes: 2 additions & 1 deletion scripts/config/iconfont-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"use_rpx": false,
"save_dir": "./snapshots/iconfont-ts",
"trim_icon_prefix": "icon",
"default_icon_size": 20
"default_icon_size": 20,
"component_name": "iconfont"
}
2 changes: 1 addition & 1 deletion snapshots/iconfont-js/helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-disable */
export declare var useGlobalIconFont: () => { iconfont: string };
export declare var useGlobalIconFont: () => { 'iconfont': string };
2 changes: 1 addition & 1 deletion snapshots/iconfont-js/helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
const useGlobalIconFont = () => {
return {
iconfont: `../snapshots/iconfont-js/${process.env.TARO_ENV}/${process.env.TARO_ENV}`,
'iconfont': `../snapshots/iconfont-js/${process.env.TARO_ENV}/${process.env.TARO_ENV}`,
};
};

Expand Down
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.alipay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import React from 'react';
import Taro from '@tarojs/taro';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <iconfont name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ interface Props {
style?: React.CSSProperties;
}

declare const IconFont: FunctionComponent<Props>;
declare const Iconfont: FunctionComponent<Props>;

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.h5.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import React from 'react';
import Taro from '@tarojs/taro';
import Icon from './h5';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <Icon name={name} size={parseFloat(Taro.pxTransform(size, 720))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */

const IconFont = () => {
const Iconfont = () => {
return null;
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.qq.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import React from 'react';
import Taro from '@tarojs/taro';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <iconfont name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.rn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import React from 'react';
import Taro from '@tarojs/taro';
import Icon from './rn';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <Icon name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.swan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import React from 'react';
import Taro from '@tarojs/taro';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <iconfont name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.tt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import React from 'react';
import Taro from '@tarojs/taro';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <iconfont name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-js/index.weapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import React from 'react';
import Taro from '@tarojs/taro';

const IconFont = (props) => {
const Iconfont = (props) => {
const { name, size, color, style } = props;

return <iconfont name={name} size={parseFloat(Taro.pxTransform(size))} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 14,
};

export default IconFont;
export default Iconfont;
2 changes: 1 addition & 1 deletion snapshots/iconfont-ts/helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-disable */
export declare var useGlobalIconFont: () => { iconfont: string };
export declare var useGlobalIconFont: () => { 'iconfont': string };
2 changes: 1 addition & 1 deletion snapshots/iconfont-ts/helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
const useGlobalIconFont = () => {
return {
iconfont: `../snapshots/iconfont-ts/${process.env.TARO_ENV}/${process.env.TARO_ENV}`,
'iconfont': `../snapshots/iconfont-ts/${process.env.TARO_ENV}/${process.env.TARO_ENV}`,
};
};

Expand Down
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.alipay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <iconfont name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.h5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

return <Icon name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.qq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <iconfont name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.rn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <Icon name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.swan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <iconfont name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
4 changes: 2 additions & 2 deletions snapshots/iconfont-ts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface IconProps {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<IconProps> = () => {
const Iconfont: FunctionComponent<IconProps> = () => {
return null;
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.tt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <iconfont name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
6 changes: 3 additions & 3 deletions snapshots/iconfont-ts/index.weapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface Props {
style?: React.CSSProperties;
}

const IconFont: FunctionComponent<Props> = (props) => {
const Iconfont: FunctionComponent<Props> = (props) => {
const { name, size, color, style } = props;

// @ts-ignore
return <iconfont name={name} size={size} color={color} style={style} />;
};

IconFont.defaultProps = {
Iconfont.defaultProps = {
size: 20,
};

export default IconFont;
export default Iconfont;
Loading

0 comments on commit 3d23446

Please sign in to comment.