|
| 1 | +--- |
| 2 | +nav: Contributing |
| 3 | +group: |
| 4 | + title: Others |
| 5 | + order: 3 |
| 6 | +--- |
| 7 | + |
| 8 | +# How to Contribute Icons |
| 9 | + |
| 10 | +The crypto industry is evolving rapidly with new projects and standards emerging all the time. We welcome community contributions of icons to better support these projects. |
| 11 | + |
| 12 | +## Add icon files |
| 13 | + |
| 14 | +The `packages/icons` directory corresponds to the `@ant-design/web3-icons` package, and new icons should be added in this directory, specifically: |
| 15 | + |
| 16 | +<Tree> |
| 17 | + <ul> |
| 18 | + <li> |
| 19 | + src |
| 20 | + <ul> |
| 21 | + <li> |
| 22 | + components |
| 23 | + <ul> |
| 24 | + <li>YOUR-ICON.tsx<small>Add icon components</small></li> |
| 25 | + </ul> |
| 26 | + </li> |
| 27 | + <li> |
| 28 | + svgs |
| 29 | + <ul> |
| 30 | + <li>YOUR-ICON.svg<small>Add icon svg</small></li> |
| 31 | + </ul> |
| 32 | + </li> |
| 33 | + </ul> |
| 34 | + </li> |
| 35 | + <li>index.ts<small>export it</small></li> |
| 36 | + </ul> |
| 37 | +</Tree> |
| 38 | + |
| 39 | +## Add icon svg |
| 40 | + |
| 41 | +Add new svg in `svgs` folder, file name should be the same as icon name, and use the [kebab-case](https://developer.mozilla.org/en-US/docs/Glossary/Kebab_case) style for file name. |
| 42 | + |
| 43 | +If you need to use `id` or `classname` in svg, you need to add the prefix `ant-web3-icon-`. This is to prevent `svgo` from simplifying it, which causes the type to not be found. In svg, try to use the inline way to write styles, such as `fill: fff` for colors. |
| 44 | + |
| 45 | +Good writing: |
| 46 | + |
| 47 | +```svg |
| 48 | +<path |
| 49 | + style="fill:#020041;" |
| 50 | + d="M1494.8,856.4c171.5,289.1,336.4,582.2,505.2,873c-168.6,0.6-337.1-1-505.6,0C1493.8,1438.3,1492.9,1147.3,1494.8,856.4" |
| 51 | +/> |
| 52 | +``` |
| 53 | + |
| 54 | +There may be problems with the writing: |
| 55 | + |
| 56 | +```svg |
| 57 | +<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="color"> |
| 58 | + <stop stop-color="#FF8B8B" offset="0%"></stop> |
| 59 | + <stop stop-color="#FF1717" offset="100%"></stop> |
| 60 | +</linearGradient> |
| 61 | +``` |
| 62 | + |
| 63 | +```svg |
| 64 | +<path |
| 65 | + fill:url(#color) |
| 66 | + d="M1494.8,856.4c171.5,289.1,336.4,582.2,505.2,873c-168.6,0.6-337.1-1-505.6,0C1493.8,1438.3,1492.9,1147.3,1494.8,856.4" |
| 67 | +/> |
| 68 | +``` |
| 69 | + |
| 70 | +In these examples, the ids are used as the match, which causes style conflicts or loss when multiple identical svgs appear at the same time. |
| 71 | + |
| 72 | +## Complete the icon react component |
| 73 | + |
| 74 | +In the `components` directory, refer to the following template to complete the component. There are two parts that need to be changed: |
| 75 | + |
| 76 | +1. Icon component name |
| 77 | +2. Svg introduction name |
| 78 | + |
| 79 | +```tsx | pure |
| 80 | +import * as React from 'react'; |
| 81 | +import AntdIcon from '@ant-design/icons'; |
| 82 | +import { type IconBaseProps } from '@ant-design/icons/lib/components/Icon'; |
| 83 | +import { ConfigProvider } from 'antd'; |
| 84 | +import classnames from 'classnames'; |
| 85 | + |
| 86 | +import SVGComponent from '../svgs/aave-circle-colorful.svg'; |
| 87 | + |
| 88 | +export const AAVECircleColorful = React.forwardRef<HTMLSpanElement, IconBaseProps>((props, ref) => { |
| 89 | + const { getPrefixCls } = React.useContext(ConfigProvider.ConfigContext); |
| 90 | + const prefixCls = getPrefixCls('web3-icon-aave-circle-colorful'); |
| 91 | + return ( |
| 92 | + <AntdIcon |
| 93 | + {...props} |
| 94 | + className={classnames(prefixCls, props.className)} |
| 95 | + ref={ref} |
| 96 | + component={SVGComponent} |
| 97 | + /> |
| 98 | + ); |
| 99 | +}); |
| 100 | +AAVECircleColorful.displayName = 'AAVECircleColorful'; |
| 101 | +``` |
| 102 | + |
| 103 | +## Naming specification |
| 104 | + |
| 105 | +There are four types through the display form of icon: |
| 106 | + |
| 107 | +- circle colorful |
| 108 | +- colorful |
| 109 | +- circle filled |
| 110 | +- filled |
| 111 | + |
| 112 | +The naming specification is: `{project name}-{type name}`, such as `aave-circle-colorful`. Using the correct naming specification will be automatically classified in the document. |
| 113 | + |
| 114 | +Based on the functions of the corresponding projects of icons, the following diversions are made: |
| 115 | + |
| 116 | +- Chain Icons |
| 117 | +- Token Icons |
| 118 | +- Tool Icons |
| 119 | + |
| 120 | +If you need to make a special declaration, you can change it in the `.dumi/theme/builtins/IconSearch/fields.ts` file, otherwise it will be classified as the default classification. |
| 121 | + |
| 122 | +## Test and verify |
| 123 | + |
| 124 | +Export the newly added icon in `src/index.ts`, and then verify whether the icon is displayed correctly in the local debugging environment. |
0 commit comments