Icon 图标

如果项目中使用的是 1.x 版本的基础组件(@alifd/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @icedesign/base@latest -S

API

图标

参数说明类型默认值
prefix样式类名的品牌前缀String'next-'
className自定义类名String-
style自定义内联样式Object-
type指定显示哪种图标String-
size指定图标大小可选值:'xxs', 'xs', 'small', 'medium', 'large', 'xl', 'xxl', 'xxxl'Enum'medium'

代码示例

基本

展示图标基本使用方法。

Icon 图标 - 图1

查看源码在线预览

  1. import { Icon } from "@icedesign/base";
  2. ReactDOM.render(<Icon type="atm" />, mountNode);

尺寸

ICON的尺寸包括:xxsxssmallmediumlargexlxxlxxxl

Icon 图标 - 图2

查看源码在线预览

  1. import { Icon } from "@icedesign/base";
  2. const sizes = ["xxs", "xs", "small", "medium", "large", "xl", "xxl", "xxxl"];
  3. ReactDOM.render(
  4. <ul className="icon-sizes">
  5. {sizes.map((size, index) => (
  6. <li key={index}>
  7. <Icon type="smile" size={size} />
  8. <span>{size}</span>
  9. </li>
  10. ))}
  11. </ul>,
  12. mountNode
  13. );
  1. .icon-sizes {
  2. margin: 0;
  3. padding: 0;
  4. list-style: none;
  5. }
  6. .icon-sizes li {
  7. display: inline-block;
  8. width: 80px;
  9. height: 80px;
  10. }
  11. .icon-sizes i {
  12. display: block;
  13. margin: 12px auto 0 auto;
  14. text-align: center;
  15. }
  16. .icon-sizes span {
  17. display: block;
  18. margin-top: 10px;
  19. text-align: center;
  20. }

自定义样式

图标字体本质上还是文字,可以使用 style 和 className 设置图标的大小和颜色。

Icon 图标 - 图3

查看源码在线预览

  1. import { Icon } from "@icedesign/base";
  2. ReactDOM.render(
  3. <div>
  4. <div className="icon-style-demo">
  5. <Icon type="success" style={{ color: "#1DC11D", marginRight: "10px" }} />
  6. 这是一个成功的消息
  7. </div>
  8. <div className="icon-style-demo">
  9. <Icon type="warning" style={{ color: "#FFA003", marginRight: "10px" }} />
  10. 这是一个警告的消息
  11. </div>
  12. <div className="icon-style-demo">
  13. <Icon type="error" style={{ color: "#FF3333", marginRight: "10px" }} />
  14. 这是一个失败的消息
  15. </div>
  16. </div>,
  17. mountNode
  18. );
  1. .icon-style-demo {
  2. margin-bottom: 10px;
  3. color: #333;
  4. }

图标列表

点击图标复制代码。

Icon 图标 - 图4

查看源码在线预览

  1. import { Icon, Feedback } from "@icedesign/base";
  2. import CopyToClipboard from "react-copy-to-clipboard";
  3. const types = [
  4. "all",
  5. "cart",
  6. "comments",
  7. "cry",
  8. "email",
  9. "favorite",
  10. "folder",
  11. "form",
  12. "help",
  13. "refresh",
  14. "set",
  15. "training",
  16. "account",
  17. "atm",
  18. "clock",
  19. "attachment",
  20. "3column",
  21. "4column",
  22. "discount",
  23. "service",
  24. "print",
  25. "box",
  26. "process",
  27. "bags",
  28. "electronics",
  29. "gifts",
  30. "lights",
  31. "auto",
  32. "browse",
  33. "atm-away",
  34. "scanning",
  35. "compare",
  36. "filter",
  37. "pin",
  38. "history",
  39. "similar-product",
  40. "link",
  41. "cut",
  42. "table",
  43. "nav-list",
  44. "image-text",
  45. "text",
  46. "move",
  47. "subtract",
  48. "dollar",
  49. "office",
  50. "operation",
  51. "download",
  52. "map",
  53. "bad",
  54. "good",
  55. "skip",
  56. "play",
  57. "stop",
  58. "compass",
  59. "security",
  60. "share",
  61. "store",
  62. "phone",
  63. "ellipsis",
  64. "email-filling",
  65. "favorites-filling",
  66. "account-filling",
  67. "credit-level",
  68. "credit-level-filling",
  69. "mobile-phone",
  70. "smile",
  71. "personal-center",
  72. "arrow-up-filling",
  73. "arrow-right",
  74. "arrow-left",
  75. "arrow-down",
  76. "arrow-up",
  77. "add",
  78. "minus",
  79. "delete-filling",
  80. "edit",
  81. "error",
  82. "select",
  83. "ashbin",
  84. "calendar",
  85. "time",
  86. "success",
  87. "warning",
  88. "search",
  89. "display",
  90. "category",
  91. "prompt",
  92. "arrow-down-filling",
  93. "sorting",
  94. "ascending",
  95. "descending",
  96. "success-filling",
  97. "picture",
  98. "close",
  99. "semi-select",
  100. "tag-subscript",
  101. "survey",
  102. "loading",
  103. "arrow-double-left",
  104. "arrow-double-right"
  105. ];
  106. let customTypes = [];
  107. // 此处代码仅用于 fusion dev 展示自定义组件用
  108. if (window.customIcons) {
  109. customTypes = window.customIcons;
  110. }
  111. const handleCopy = () => Feedback.toast.success("Copied!");
  112. ReactDOM.render(
  113. <div>
  114. <div className="icon-list-title">点击图标复制代码到剪贴板</div>
  115. <ul className="icon-list">
  116. {types.map((type, index) => (
  117. <CopyToClipboard
  118. key={index}
  119. text={`<Icon type="${type}" />`}
  120. onCopy={handleCopy}
  121. >
  122. <li>
  123. <Icon type={type} size="xl" />
  124. <span>{type}</span>
  125. </li>
  126. </CopyToClipboard>
  127. ))}
  128. </ul>
  129. {customTypes.length ? (
  130. <div>
  131. <div className="icon-list-custom-title">自定义图标</div>
  132. <ul className="icon-list">
  133. {customTypes.map((type, index) => (
  134. <CopyToClipboard
  135. key={index}
  136. text={`<Icon type="${type}" />`}
  137. onCopy={handleCopy}
  138. >
  139. <li>
  140. <Icon type={type} size="xl" />
  141. <span>{type}</span>
  142. </li>
  143. </CopyToClipboard>
  144. ))}
  145. </ul>
  146. </div>
  147. ) : null}
  148. </div>,
  149. mountNode
  150. );
  1. .icon-list-title {
  2. margin-bottom: 20px;
  3. font-size: 24px;
  4. color: #333;
  5. }
  6. .icon-list {
  7. margin: 0;
  8. padding: 0;
  9. list-style: none;
  10. }
  11. .icon-list li {
  12. display: inline-block;
  13. width: 160px;
  14. height: 80px;
  15. color: #333;
  16. cursor: pointer;
  17. }
  18. .icon-list li:hover {
  19. background-color: #f7f7f7;
  20. }
  21. .icon-list i {
  22. display: block;
  23. margin: 12px auto 0 auto;
  24. text-align: center;
  25. }
  26. .icon-list span {
  27. display: block;
  28. margin-top: 10px;
  29. text-align: center;
  30. }
  31. .icon-list-custom-title {
  32. margin: 20px 0 20px 10px;
  33. font-size: 20px;
  34. color: #333;
  35. }

相关区块

Icon 图标 - 图5

暂无相关区块