diff --git a/.vscode/iconConfig.json b/.vscode/iconConfig.json index 4f21c2353..08326c4c9 100644 --- a/.vscode/iconConfig.json +++ b/.vscode/iconConfig.json @@ -1,4 +1,9 @@ [ + { + "name": "packages/amis", + "iconPath": "packages/amis-ui/src/components/icons.tsx", + "iconDir": "packages/amis-ui/src/icons" + }, { "name": "packages/amis-ui", "iconPath": "packages/amis-ui/src/components/icons.tsx", @@ -14,4 +19,4 @@ "iconPath": "packages/amis-editor-core/src/icons/index.tsx", "iconDir": "packages/amis-editor-core/src/icons" } -] +] \ No newline at end of file diff --git a/packages/amis-core/src/utils/icon.tsx b/packages/amis-core/src/utils/icon.tsx index c36d48044..e0a62c4e9 100644 --- a/packages/amis-core/src/utils/icon.tsx +++ b/packages/amis-core/src/utils/icon.tsx @@ -6,18 +6,19 @@ import React from 'react'; import {isObject} from 'lodash'; import {ClassNamesFn} from '../theme'; -export interface IconCheckedSchema { +interface IconCheckedSchema { id: string; name?: string; svg?: string; } -export interface IconCheckedSchemaNew { +interface IconCheckedSchemaNew { type: 'icon'; icon: IconCheckedSchema; } /** + * 废弃,不建议使用 * 判断字符串来生成 i 或 img * @param icon icon 设置 * @param className 内部用的 className diff --git a/packages/amis-editor-core/src/icons/display-block.svg b/packages/amis-editor-core/src/icons/display-block.svg index 850a39f1c..08e615b9b 100644 --- a/packages/amis-editor-core/src/icons/display-block.svg +++ b/packages/amis-editor-core/src/icons/display-block.svg @@ -1 +1,7 @@ - \ No newline at end of file + + + + + diff --git a/packages/amis-editor-core/src/icons/display-flex.svg b/packages/amis-editor-core/src/icons/display-flex.svg index 67d3d97bc..3b28fdb17 100644 --- a/packages/amis-editor-core/src/icons/display-flex.svg +++ b/packages/amis-editor-core/src/icons/display-flex.svg @@ -1 +1,14 @@ - \ No newline at end of file + + + + + + + + + + + + diff --git a/packages/amis-editor-core/src/icons/display-inline-block.svg b/packages/amis-editor-core/src/icons/display-inline-block.svg index 7ecae3423..e31202fb8 100644 --- a/packages/amis-editor-core/src/icons/display-inline-block.svg +++ b/packages/amis-editor-core/src/icons/display-inline-block.svg @@ -1 +1,8 @@ - \ No newline at end of file + + + + + diff --git a/packages/amis-editor-core/src/icons/display-inline.svg b/packages/amis-editor-core/src/icons/display-inline.svg index 2c7b8824e..f9e8e2058 100644 --- a/packages/amis-editor-core/src/icons/display-inline.svg +++ b/packages/amis-editor-core/src/icons/display-inline.svg @@ -1 +1,5 @@ - \ No newline at end of file + + + diff --git a/packages/amis-editor-core/src/icons/fixed.svg b/packages/amis-editor-core/src/icons/fixed.svg index 695f436f7..22c2a61e5 100644 --- a/packages/amis-editor-core/src/icons/fixed.svg +++ b/packages/amis-editor-core/src/icons/fixed.svg @@ -1,5 +1,7 @@ - + diff --git a/packages/amis-editor-core/src/icons/no-fixed.svg b/packages/amis-editor-core/src/icons/no-fixed.svg index 00605b607..a8179f447 100644 --- a/packages/amis-editor-core/src/icons/no-fixed.svg +++ b/packages/amis-editor-core/src/icons/no-fixed.svg @@ -1,5 +1,7 @@ - + diff --git a/packages/amis-editor-core/src/icons/position-bottom.svg b/packages/amis-editor-core/src/icons/position-bottom.svg index 8dcfc002d..9fd5499f8 100644 --- a/packages/amis-editor-core/src/icons/position-bottom.svg +++ b/packages/amis-editor-core/src/icons/position-bottom.svg @@ -1 +1,6 @@ - \ No newline at end of file + + + + diff --git a/packages/amis-editor-core/src/icons/position-left.svg b/packages/amis-editor-core/src/icons/position-left.svg index 9310d23ed..776d06686 100644 --- a/packages/amis-editor-core/src/icons/position-left.svg +++ b/packages/amis-editor-core/src/icons/position-left.svg @@ -1 +1,6 @@ - \ No newline at end of file + + + + diff --git a/packages/amis-editor-core/src/icons/position-right.svg b/packages/amis-editor-core/src/icons/position-right.svg index 847e48cc1..76ef8426b 100644 --- a/packages/amis-editor-core/src/icons/position-right.svg +++ b/packages/amis-editor-core/src/icons/position-right.svg @@ -1 +1,6 @@ - \ No newline at end of file + + + + diff --git a/packages/amis-editor-core/src/icons/position-top.svg b/packages/amis-editor-core/src/icons/position-top.svg index 9310d23ed..776d06686 100644 --- a/packages/amis-editor-core/src/icons/position-top.svg +++ b/packages/amis-editor-core/src/icons/position-top.svg @@ -1 +1,6 @@ - \ No newline at end of file + + + + diff --git a/packages/amis-editor/src/icons/display/aBaseline.svg b/packages/amis-editor/src/icons/display/aBaseline.svg index 21c91f6de..67f9f6999 100644 --- a/packages/amis-editor/src/icons/display/aBaseline.svg +++ b/packages/amis-editor/src/icons/display/aBaseline.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/aCenter.svg b/packages/amis-editor/src/icons/display/aCenter.svg index 04d11bfa6..351e3c2cd 100644 --- a/packages/amis-editor/src/icons/display/aCenter.svg +++ b/packages/amis-editor/src/icons/display/aCenter.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/aFlexEnd.svg b/packages/amis-editor/src/icons/display/aFlexEnd.svg index 8c26bf166..4863c11b3 100644 --- a/packages/amis-editor/src/icons/display/aFlexEnd.svg +++ b/packages/amis-editor/src/icons/display/aFlexEnd.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/aFlexStart.svg b/packages/amis-editor/src/icons/display/aFlexStart.svg index fca3a020b..bb2474923 100644 --- a/packages/amis-editor/src/icons/display/aFlexStart.svg +++ b/packages/amis-editor/src/icons/display/aFlexStart.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/aStretch.svg b/packages/amis-editor/src/icons/display/aStretch.svg index fb5acc86e..86277b084 100644 --- a/packages/amis-editor/src/icons/display/aStretch.svg +++ b/packages/amis-editor/src/icons/display/aStretch.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/block.svg b/packages/amis-editor/src/icons/display/block.svg index 850a39f1c..739cfabd9 100644 --- a/packages/amis-editor/src/icons/display/block.svg +++ b/packages/amis-editor/src/icons/display/block.svg @@ -1 +1,8 @@ - \ No newline at end of file + + + + + diff --git a/packages/amis-editor/src/icons/display/dcolumn.svg b/packages/amis-editor/src/icons/display/dcolumn.svg index 3727f111a..13b4d32b3 100644 --- a/packages/amis-editor/src/icons/display/dcolumn.svg +++ b/packages/amis-editor/src/icons/display/dcolumn.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/packages/amis-editor/src/icons/display/dcolumnReverse.svg b/packages/amis-editor/src/icons/display/dcolumnReverse.svg index 10d6efb81..d5a58201b 100644 --- a/packages/amis-editor/src/icons/display/dcolumnReverse.svg +++ b/packages/amis-editor/src/icons/display/dcolumnReverse.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + diff --git a/packages/amis-editor/src/icons/display/drow.svg b/packages/amis-editor/src/icons/display/drow.svg index 10124f271..0ed5f7da3 100644 --- a/packages/amis-editor/src/icons/display/drow.svg +++ b/packages/amis-editor/src/icons/display/drow.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/packages/amis-editor/src/icons/display/drowReverse.svg b/packages/amis-editor/src/icons/display/drowReverse.svg index 62660edd8..42983b793 100644 --- a/packages/amis-editor/src/icons/display/drowReverse.svg +++ b/packages/amis-editor/src/icons/display/drowReverse.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/packages/amis-editor/src/icons/display/flex.svg b/packages/amis-editor/src/icons/display/flex.svg index 67d3d97bc..35f765c9e 100644 --- a/packages/amis-editor/src/icons/display/flex.svg +++ b/packages/amis-editor/src/icons/display/flex.svg @@ -1 +1,15 @@ - \ No newline at end of file + + + + + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/inline-block.svg b/packages/amis-editor/src/icons/display/inline-block.svg index 7ecae3423..6433d2f4a 100644 --- a/packages/amis-editor/src/icons/display/inline-block.svg +++ b/packages/amis-editor/src/icons/display/inline-block.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + diff --git a/packages/amis-editor/src/icons/display/inline.svg b/packages/amis-editor/src/icons/display/inline.svg index 2c7b8824e..047905b9f 100644 --- a/packages/amis-editor/src/icons/display/inline.svg +++ b/packages/amis-editor/src/icons/display/inline.svg @@ -1 +1,6 @@ - \ No newline at end of file + + + diff --git a/packages/amis-editor/src/icons/display/jCenter.svg b/packages/amis-editor/src/icons/display/jCenter.svg index b0d67d641..358b4b076 100644 --- a/packages/amis-editor/src/icons/display/jCenter.svg +++ b/packages/amis-editor/src/icons/display/jCenter.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/jFlexEnd.svg b/packages/amis-editor/src/icons/display/jFlexEnd.svg index 7a35df44a..ce56a65d1 100644 --- a/packages/amis-editor/src/icons/display/jFlexEnd.svg +++ b/packages/amis-editor/src/icons/display/jFlexEnd.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/jFlexStart.svg b/packages/amis-editor/src/icons/display/jFlexStart.svg index 3c26c9b4f..06912b95c 100644 --- a/packages/amis-editor/src/icons/display/jFlexStart.svg +++ b/packages/amis-editor/src/icons/display/jFlexStart.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/jSpaceAround.svg b/packages/amis-editor/src/icons/display/jSpaceAround.svg index 2eda310d1..ad547c8bc 100644 --- a/packages/amis-editor/src/icons/display/jSpaceAround.svg +++ b/packages/amis-editor/src/icons/display/jSpaceAround.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/icons/display/jSpaceBetween.svg b/packages/amis-editor/src/icons/display/jSpaceBetween.svg index 673ef2a72..c36c250b3 100644 --- a/packages/amis-editor/src/icons/display/jSpaceBetween.svg +++ b/packages/amis-editor/src/icons/display/jSpaceBetween.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + + diff --git a/packages/amis-editor/src/renderer/DataBindingControl.tsx b/packages/amis-editor/src/renderer/DataBindingControl.tsx index 1bbeef1a9..b4f0d42d8 100644 --- a/packages/amis-editor/src/renderer/DataBindingControl.tsx +++ b/packages/amis-editor/src/renderer/DataBindingControl.tsx @@ -10,12 +10,7 @@ import { Checkbox, Spinner } from 'amis'; -import { - FormControlProps, - generateIcon, - Renderer, - RendererProps -} from 'amis-core'; +import {FormControlProps, Renderer, RendererProps} from 'amis-core'; import {debounce, remove} from 'lodash'; import React from 'react'; import {EditorManager, EditorNodeType, autobind} from 'amis-editor-core'; @@ -226,7 +221,11 @@ export class SimpleDataBindingControl extends React.Component< item => item.value || item.label )} expandIcon={ - generateIcon(cx, 'fa fa-chevron-right expandIcon', 'Icon')! + } expandIconPosition="right" // accordion={true} diff --git a/packages/amis-ui/scss/_components.scss b/packages/amis-ui/scss/_components.scss index ef7cab427..eeed4c09a 100644 --- a/packages/amis-ui/scss/_components.scss +++ b/packages/amis-ui/scss/_components.scss @@ -1593,7 +1593,7 @@ --ListControl-item-onActive-color: var( --listSelect-base-active-top-border-color ); - --ListControl-item-onActive-before-bg: var(--colors-brand-4); + --ListControl-item-onActive-before-bg: var(--colors-brand-5); --ListControl-item-color: var(--listSelect-base-default-color); --ListControl-item-onDisabled-color: var(--listSelect-base-disabled-color); --ListControl-item-paddingX: var(--listSelect-base-default-paddingLeft); @@ -3498,7 +3498,7 @@ --Toast--danger-bottom-left-border-radius: var(--borders-radius-3); --Toast--danger-bgColor: var(--colors-neutral-fill-11); --Toast--info-color: var(--colors-neutral-text-2); - --Toast--info-fontSize: var(--fonts-size-6); + --Toast--info-fontSize: var(--fonts-size-7); --Toast--info-fontWeight: var(--fonts-weight-6); --Toast--info-top-border-color: var(--colors-neutral-line-11); --Toast--info-top-border-width: var(--borders-width-2); diff --git a/packages/amis-ui/scss/_properties.scss b/packages/amis-ui/scss/_properties.scss index 06cd1c470..6f21f85e0 100644 --- a/packages/amis-ui/scss/_properties.scss +++ b/packages/amis-ui/scss/_properties.scss @@ -482,7 +482,7 @@ $Table-strip-bg: transparent; --ListControl-item-borderRadius: var(--borders-radius-3); --ListControl-item-color: var(--colors-neutral-text-2); --ListControl-item-onActive-after-borderColor: var(--colors-neutral-line-11); - --ListControl-item-onActive-before-bg: var(--colors-brand-4); + --ListControl-item-onActive-before-bg: var(--colors-brand-5); --ListControl-item-onActive-bg: var(--colors-neutral-fill-11); --ListControl-item-onActive-borderColor: var(--colors-brand-4); --ListControl-item-onActive-color: var(--colors-brand-4); diff --git a/packages/amis-ui/scss/components/_column-toggler.scss b/packages/amis-ui/scss/components/_column-toggler.scss index 0f95c82d4..7da26a45a 100644 --- a/packages/amis-ui/scss/components/_column-toggler.scss +++ b/packages/amis-ui/scss/components/_column-toggler.scss @@ -6,17 +6,17 @@ margin-left: var(--DropDown-caret-marginLeft); display: inline-block; vertical-align: top; - transition: transform var(--animation-duration) ease; > svg { width: px2rem(10px); height: px2rem(10px); - top: 0.125em; + transition: transform var(--animation-duration) ease; + transform: rotate(90deg); } } - &.is-opened &-caret { - transform: rotate(180deg); + &.is-opened &-caret svg { + transform: rotate(270deg); } &.is-actived > .#{$ns}Button { diff --git a/packages/amis-ui/scss/components/_dropdown.scss b/packages/amis-ui/scss/components/_dropdown.scss index ac28cbb34..fd2eaad31 100644 --- a/packages/amis-ui/scss/components/_dropdown.scss +++ b/packages/amis-ui/scss/components/_dropdown.scss @@ -6,17 +6,18 @@ margin-left: var(--DropDown-caret-marginLeft); display: inline-block; vertical-align: top; - transition: transform var(--animation-duration) ease; > svg { width: px2rem(10px); height: px2rem(10px); - top: 0.125em; + top: 0; + transform: rotate(90deg); + transition: transform var(--animation-duration) ease; } } - &.is-opened &-caret { - transform: rotate(180deg); + &.is-opened &-caret svg { + transform: rotate(270deg); } &.is-actived { diff --git a/packages/amis-ui/scss/components/_input-box.scss b/packages/amis-ui/scss/components/_input-box.scss index 6382b290c..fbc0d9776 100644 --- a/packages/amis-ui/scss/components/_input-box.scss +++ b/packages/amis-ui/scss/components/_input-box.scss @@ -58,6 +58,7 @@ margin: 5px; display: flex; color: var(--Form-select-caret-iconColor); + transform: rotate(90deg); &:hover { color: var(--Form-select-caret-onHover-iconColor); } @@ -70,7 +71,7 @@ } &.is-active &-caret { - transform: rotate(180deg); + transform: rotate(270deg); } &.is-mobile { diff --git a/packages/amis-ui/scss/components/_json-schema-editor.scss b/packages/amis-ui/scss/components/_json-schema-editor.scss index 3e4d83959..9c105492c 100644 --- a/packages/amis-ui/scss/components/_json-schema-editor.scss +++ b/packages/amis-ui/scss/components/_json-schema-editor.scss @@ -96,7 +96,7 @@ transition: transform var(--animation-duration); color: var(--icon-color); margin-top: calc((var(--Form-input-height) - var(--Switch-height)) / 2); - + transform: rotate(90deg); > svg { width: 10px; height: 10px; @@ -105,7 +105,7 @@ } &-caret.is-collapsed { - transform: rotate(-90deg); + transform: rotate(0deg); } &-required { diff --git a/packages/amis-ui/scss/components/_json-schema.scss b/packages/amis-ui/scss/components/_json-schema.scss index 2c0349a18..0b7f09de3 100644 --- a/packages/amis-ui/scss/components/_json-schema.scss +++ b/packages/amis-ui/scss/components/_json-schema.scss @@ -79,7 +79,7 @@ transition: transform var(--animation-duration); color: var(--icon-color); margin-top: calc((var(--Form-input-height) - var(--Switch-height)) / 2); - + transform: rotate(90deg); > svg { width: 10px; height: 10px; @@ -88,7 +88,7 @@ } &-caret.is-collapsed { - transform: rotate(-90deg); + transform: rotate(0deg); } &.is-expanded { diff --git a/packages/amis-ui/scss/components/_search-box.scss b/packages/amis-ui/scss/components/_search-box.scss index cd0f3a990..779c26a36 100644 --- a/packages/amis-ui/scss/components/_search-box.scss +++ b/packages/amis-ui/scss/components/_search-box.scss @@ -53,6 +53,9 @@ &-cancelBtn { cursor: pointer; color: var(--SearchBox-search-icon-color); + svg { + top: 1px; + } &:hover { color: var(--icon-onHover-color); @@ -118,6 +121,9 @@ height: 100%; color: var(--SearchBox-enhonce-icon-color); background: var(--SearchBox-hover-color); + svg { + top: 0; + } &:hover { background: var(--button-primary-hover-bg-color); diff --git a/packages/amis-ui/scss/components/_steps.scss b/packages/amis-ui/scss/components/_steps.scss index b1dbc64da..8eb2d9152 100644 --- a/packages/amis-ui/scss/components/_steps.scss +++ b/packages/amis-ui/scss/components/_steps.scss @@ -24,8 +24,8 @@ font-size: var(--Steps-icon-fontsize); text-align: center; .icon { - width: px2rem(9px); - height: px2rem(9px); + width: px2rem(12px); + height: px2rem(12px); position: relative; top: 0; } @@ -388,7 +388,9 @@ .#{$ns}StepsItem.is-clickable { .#{$ns}StepsItem-container { - &ProgressDot, &Icon, &Wrapper { + &ProgressDot, + &Icon, + &Wrapper { cursor: pointer; } } diff --git a/packages/amis-ui/scss/components/_timeline.scss b/packages/amis-ui/scss/components/_timeline.scss index 9b9f4b1da..f91f924ec 100644 --- a/packages/amis-ui/scss/components/_timeline.scss +++ b/packages/amis-ui/scss/components/_timeline.scss @@ -103,10 +103,11 @@ color: var(--Timeline-detail-icon-color); width: var(--TimelineItem-detail-arrow-width); height: var(--TimelineItem-detail-arrow-width); + transition: transform var(--animation-duration); } .#{$ns}TimelineItem-detail-arrow-top { - transform: rotateX(180deg); + transform: rotate(180deg); } .#{$ns}TimelineItem-detail-visible { diff --git a/packages/amis-ui/scss/components/form/_checks.scss b/packages/amis-ui/scss/components/form/_checks.scss index 284eab2af..ac2708375 100644 --- a/packages/amis-ui/scss/components/form/_checks.scss +++ b/packages/amis-ui/scss/components/form/_checks.scss @@ -362,7 +362,9 @@ margin-right: 0; border-radius: calc(var(--Checkbox-borderRadius) * 2); min-width: var(--Checkbox-button-min-width); - + > span { + line-height: var(--Checkbox-button-line-height); + } &:hover:not(:disabled) { color: var(--Checkbox-onHover-color); border-color: var(--Checkbox-onHover-color); diff --git a/packages/amis-ui/scss/components/form/_date.scss b/packages/amis-ui/scss/components/form/_date.scss index 038ef4905..8dbb83150 100644 --- a/packages/amis-ui/scss/components/form/_date.scss +++ b/packages/amis-ui/scss/components/form/_date.scss @@ -487,6 +487,9 @@ padding: 0 8px; border-radius: 2px; } + .#{$ns}QuickWrapper a { + font-size: var(--button-size-sm-fontSize); + } } .#{$ns}CalendarInput { diff --git a/packages/amis-ui/scss/components/form/_list.scss b/packages/amis-ui/scss/components/form/_list.scss index ba52dcf29..25c248c2b 100644 --- a/packages/amis-ui/scss/components/form/_list.scss +++ b/packages/amis-ui/scss/components/form/_list.scss @@ -167,7 +167,7 @@ border-style: solid; border-width: 0 0 px2rem(2px) px2rem(2px); right: px2rem(1px); - bottom: var(--gap-xs); + bottom: px2rem(6px); transform: rotate(-40deg); } } diff --git a/packages/amis-ui/scss/components/form/_nested-select.scss b/packages/amis-ui/scss/components/form/_nested-select.scss index cd5986153..86743da5e 100644 --- a/packages/amis-ui/scss/components/form/_nested-select.scss +++ b/packages/amis-ui/scss/components/form/_nested-select.scss @@ -21,10 +21,11 @@ padding-right: var(--Form-select-icon-rigin); svg { - width: px2rem(12px); - height: px2rem(12px); + width: px2rem(10px); + height: px2rem(10px); fill: var(--Form-input-iconColor); color: var(--default-icon-color); + top: 0; } } diff --git a/packages/amis-ui/src/components/Alert2.tsx b/packages/amis-ui/src/components/Alert2.tsx index a450d5647..79ce8942f 100644 --- a/packages/amis-ui/src/components/Alert2.tsx +++ b/packages/amis-ui/src/components/Alert2.tsx @@ -5,7 +5,6 @@ import React from 'react'; import {ClassNamesFn, themeable} from 'amis-core'; -import {generateIcon, IconCheckedSchema} from 'amis-core'; import {Icon, getIcon} from './icons'; export interface AlertProps { @@ -78,20 +77,8 @@ export class Alert extends React.Component { } = this.props; // 优先使用内置svg,其次使用icon库 - const iconNode = icon ? ( - ['string', 'object'].includes(typeof icon) ? ( - typeof icon === 'object' ? ( - generateIcon(cx, icon as any as IconCheckedSchema, 'icon') - ) : ( - getIcon(icon as string) && - ) - ) : React.isValidElement(icon) ? ( - React.cloneElement(icon as React.ReactElement, { - className: cx(`Alert-icon`, icon.props?.className) - }) - ) : null - ) : showIcon ? ( - + const iconNode = showIcon ? ( + ) : null; return this.state.show ? ( diff --git a/packages/amis-ui/src/components/Avatar.tsx b/packages/amis-ui/src/components/Avatar.tsx index 44ad44de9..5c5501cbc 100644 --- a/packages/amis-ui/src/components/Avatar.tsx +++ b/packages/amis-ui/src/components/Avatar.tsx @@ -1,11 +1,6 @@ import * as React from 'react'; -import { - ClassNamesFn, - themeable, - ThemeProps, - generateIcon, - IconCheckedSchema -} from 'amis-core'; +import {ClassNamesFn, themeable, ThemeProps} from 'amis-core'; +import {Icon, IconCheckedSchema} from './icons'; /** * Avatar 属性 @@ -234,7 +229,7 @@ export class Avatar extends React.Component { ); } else if (['string', 'object'].includes(typeof icon)) { - childrenRender = generateIcon(cx, icon as any); + childrenRender = ; } else if (isIconRender) { childrenRender = icon as any; } else { diff --git a/packages/amis-ui/src/components/Breadcrumb.tsx b/packages/amis-ui/src/components/Breadcrumb.tsx index c54090fc7..ffb7c4770 100644 --- a/packages/amis-ui/src/components/Breadcrumb.tsx +++ b/packages/amis-ui/src/components/Breadcrumb.tsx @@ -8,7 +8,6 @@ import {ClassNamesFn, themeable, ThemeProps} from 'amis-core'; import {RootClose} from 'amis-core'; import {removeHTMLTag} from 'amis-core'; import {Icon} from './icons'; -import {generateIcon} from 'amis-core'; export type ItemPlace = 'start' | 'middle' | 'end'; export type TooltipPositionType = 'top' | 'bottom' | 'left' | 'right'; @@ -60,8 +59,14 @@ export class Breadcrumb extends React.Component { render() { const cx = this.props.classnames; - const {className, style, separatorClassName, items, separator, ...restProps} = - this.props; + const { + className, + style, + separatorClassName, + items, + separator, + ...restProps + } = this.props; const crumbsLength = items?.length; if (!crumbsLength) { @@ -97,7 +102,11 @@ export class Breadcrumb extends React.Component { curr ]); - return
{crumbs}
; + return ( +
+ {crumbs} +
+ ); } } @@ -157,18 +166,28 @@ export class BreadcrumbItem extends React.Component< href={item.href} className={cx('Breadcrumb-item-' + itemType, baseItemClassName)} > - {item.icon - ? generateIcon(cx, item.icon, 'Icon', 'Breadcrumb-icon') - : null} + {item.icon ? ( + + ) : null} {label} ); } return ( - {item.icon - ? generateIcon(cx, item.icon, 'Icon', 'Breadcrumb-icon') - : null} + {item.icon ? ( + + ) : null} {label} ); diff --git a/packages/amis-ui/src/components/Collapse.tsx b/packages/amis-ui/src/components/Collapse.tsx index bdaa9a5d5..9a2507d37 100644 --- a/packages/amis-ui/src/components/Collapse.tsx +++ b/packages/amis-ui/src/components/Collapse.tsx @@ -208,7 +208,7 @@ export class Collapse extends React.Component { diff --git a/packages/amis-ui/src/components/InputBoxWithSuggestion.tsx b/packages/amis-ui/src/components/InputBoxWithSuggestion.tsx index bfb9511ad..86a62bd8c 100644 --- a/packages/amis-ui/src/components/InputBoxWithSuggestion.tsx +++ b/packages/amis-ui/src/components/InputBoxWithSuggestion.tsx @@ -108,7 +108,7 @@ export class InputBoxWithSuggestion extends React.Component - + )} diff --git a/packages/amis-ui/src/components/Link.tsx b/packages/amis-ui/src/components/Link.tsx index 167e9c27c..e8d24ac53 100644 --- a/packages/amis-ui/src/components/Link.tsx +++ b/packages/amis-ui/src/components/Link.tsx @@ -1,7 +1,7 @@ import React from 'react'; import {themeable, ThemeProps} from 'amis-core'; import {autobind} from 'amis-core'; -import {generateIcon} from 'amis-core'; +import {Icon} from './icons'; export interface LinkProps extends ThemeProps, @@ -76,9 +76,11 @@ export class Link extends React.Component { title={title} onClick={this.handleClick} > - {icon ? generateIcon(cx, icon, 'Link-icon') : null} + {icon ? : null} {children} - {rightIcon ? generateIcon(cx, rightIcon, 'Link-icon') : null} + {rightIcon ? ( + + ) : null} ); } diff --git a/packages/amis-ui/src/components/NumberInput.tsx b/packages/amis-ui/src/components/NumberInput.tsx index 928e54500..51c025d71 100644 --- a/packages/amis-ui/src/components/NumberInput.tsx +++ b/packages/amis-ui/src/components/NumberInput.tsx @@ -398,7 +398,7 @@ export class NumberInput extends React.Component { @@ -415,7 +415,7 @@ export class NumberInput extends React.Component { diff --git a/packages/amis-ui/src/components/Spinner.tsx b/packages/amis-ui/src/components/Spinner.tsx index ca90a79f2..cfb325511 100644 --- a/packages/amis-ui/src/components/Spinner.tsx +++ b/packages/amis-ui/src/components/Spinner.tsx @@ -10,7 +10,6 @@ import ReactDOM from 'react-dom'; import {themeable, ThemeProps} from 'amis-core'; import Transition, {ENTERED, ENTERING} from 'react-transition-group/Transition'; import {Icon, hasIcon} from './icons'; -import {generateIcon} from 'amis-core'; import {types} from 'mobx-state-tree'; import {observable, reaction} from 'mobx'; @@ -250,13 +249,7 @@ export class Spinner extends React.Component< )} > {icon ? ( - isCustomIcon ? ( - icon - ) : hasIcon(icon as string) ? ( - - ) : ( - generateIcon(cx, icon as string, 'icon') - ) + ) : null} {tip ? {tip} : ''} diff --git a/packages/amis-ui/src/components/Tabs.tsx b/packages/amis-ui/src/components/Tabs.tsx index 6fcf0677b..1a21c6e92 100644 --- a/packages/amis-ui/src/components/Tabs.tsx +++ b/packages/amis-ui/src/components/Tabs.tsx @@ -9,7 +9,7 @@ import {ClassName, localeable, LocaleProps, Schema} from 'amis-core'; import Transition, {ENTERED, ENTERING} from 'react-transition-group/Transition'; import {themeable, ThemeProps, noop} from 'amis-core'; import {uncontrollable} from 'amis-core'; -import {generateIcon, isObjectShallowModified} from 'amis-core'; +import {isObjectShallowModified} from 'amis-core'; import {autobind, guid} from 'amis-core'; import {Icon} from './icons'; import debounce from 'lodash/debounce'; @@ -611,7 +611,7 @@ export class Tabs extends React.Component { const activeKey = activeKeyProp === undefined && index === 0 ? eventKey : activeKeyProp; - const iconElement = generateIcon(cx, icon, 'Icon'); + const iconElement = ; const link = ( diff --git a/packages/amis-ui/src/components/Tag.tsx b/packages/amis-ui/src/components/Tag.tsx index 6a59af04d..45dfec178 100644 --- a/packages/amis-ui/src/components/Tag.tsx +++ b/packages/amis-ui/src/components/Tag.tsx @@ -5,7 +5,6 @@ import React from 'react'; import {themeable, ThemeProps} from 'amis-core'; import {Icon, getIcon} from './icons'; -import {generateIcon} from 'amis-core'; import {autobind, noop} from 'amis-core'; export interface TagProps extends ThemeProps { @@ -59,18 +58,7 @@ export class Tag extends React.Component { return null; } - const icon = - typeof closeIcon === 'string' ? ( - getIcon(closeIcon) ? ( - - ) : ( - generateIcon(cx, closeIcon, 'Icon') - ) - ) : React.isValidElement(closeIcon) ? ( - closeIcon - ) : ( - - ); + const icon = ; return ( @@ -133,11 +121,7 @@ export class Tag extends React.Component { if (displayMode === 'status') { let iconItem; if (icon) { - if (typeof icon === 'string' && getIcon(icon)) { - iconItem = ; - } else { - iconItem = generateIcon(cx, icon, 'Icon'); - } + iconItem = ; } if (!iconItem) { iconItem = ( diff --git a/packages/amis-ui/src/components/TimelineItem.tsx b/packages/amis-ui/src/components/TimelineItem.tsx index 218fcd4d6..5386b2a2b 100644 --- a/packages/amis-ui/src/components/TimelineItem.tsx +++ b/packages/amis-ui/src/components/TimelineItem.tsx @@ -1,9 +1,9 @@ import React, {ReactNode, useState} from 'react'; import {localeable, LocaleProps} from 'amis-core'; -import {themeable, ThemeProps, generateIcon} from 'amis-core'; +import {themeable, ThemeProps} from 'amis-core'; import {Icon} from './icons'; -import type {IconCheckedSchema} from 'amis-core'; +import type {IconCheckedSchema} from 'amis-ui'; export interface TimelineItemProps { /** @@ -118,11 +118,12 @@ export function TimelineItem(props: TimelineItem) {
{icon ? (
- {typeof icon === 'string' ? ( - - ) : ( - generateIcon(cx, icon as any) - )} +
) : (
} accordion > diff --git a/packages/amis-ui/src/components/formula/Picker.tsx b/packages/amis-ui/src/components/formula/Picker.tsx index 7f488ae52..e88243272 100644 --- a/packages/amis-ui/src/components/formula/Picker.tsx +++ b/packages/amis-ui/src/components/formula/Picker.tsx @@ -13,7 +13,6 @@ import { import { autobind, noop, - generateIcon, themeable, localeable, parse, @@ -363,7 +362,7 @@ export class FormulaPicker extends React.Component< ...rest } = this.props; const {isOpened, value, editorValue, isError} = this.state; - const iconElement = generateIcon(cx, icon, 'Icon'); + const iconElement = ; const mobileUI = useMobileUI && isMobile(); return ( diff --git a/packages/amis-ui/src/components/icons.tsx b/packages/amis-ui/src/components/icons.tsx index 4383baa28..2d5e106d2 100644 --- a/packages/amis-ui/src/components/icons.tsx +++ b/packages/amis-ui/src/components/icons.tsx @@ -4,7 +4,7 @@ * @author fex */ import React, {useState, useEffect, useRef} from 'react'; -import cx from 'classnames'; +import cxClass from 'classnames'; import CloseIcon from '../icons/close.svg'; import CloseSmallIcon from '../icons/close-small.svg'; import StatusCloseIcon from '../icons/status-close.svg'; @@ -101,6 +101,7 @@ import NewEdit from '../icons/new-edit.svg'; import RotateLeft from '../icons/rotate-left.svg'; import RotateRight from '../icons/rotate-right.svg'; import ScaleOrigin from '../icons/scale-origin.svg'; +import {isObject} from 'lodash'; // 兼容原来的用法,后续不直接试用。 @@ -235,24 +236,56 @@ registerIcon('rotate-left', RotateLeft); registerIcon('rotate-right', RotateRight); registerIcon('scale-origin', ScaleOrigin); +export interface IconCheckedSchema { + id: string; + name?: string; + svg?: string; +} + +export interface IconCheckedSchemaNew { + type: 'icon'; + icon: IconCheckedSchema; +} + export function Icon({ icon, className, wrapClassName, classPrefix = '', + classNameProp, iconContent, - ...rest + vendor, + cx: iconCx, + onClick = () => {} }: { icon: string; iconContent?: string; } & React.ComponentProps) { - // jest 运行环境下,把指定的 icon 也输出到 snapshot 中。 - if (typeof jest !== 'undefined') { - rest.icon = icon; + let cx = iconCx || cxClass; + + if (!icon) { + return null; } - const [showCssIcon, setShowCssIcon] = useState(false); + // 直接的icon dom + if (React.isValidElement(icon)) { + return icon; + } + // 获取注册的icon + const Component = getIcon(icon); + if (Component) { + return ( + + ); + } + + // 从css变量中获取icon function refFn(dom: any) { if (dom) { const style = getComputedStyle(dom); @@ -266,41 +299,84 @@ export function Icon({ // 存储svg,不直接用innerHTML是防止渲染后变成的情况 dom.svgHTMLClone = svgHTML; dom.style.display = ''; - setShowCssIcon(true); } - } else { - // 当传入svg为空时,隐藏div,展示原icon - dom.style.display = 'none'; - setShowCssIcon(false); } } } + if (iconContent) { + return ( +
+ ); + } - const Component = getIcon(icon); + // 符合schema的icon + if ( + isObject(icon) && + (icon as IconCheckedSchemaNew).type === 'icon' && + (icon as IconCheckedSchemaNew).icon + ) { + icon = (icon as IconCheckedSchemaNew).icon; + } + + // icon是引用svg的情况 + if ( + isObject(icon) && + typeof (icon as IconCheckedSchema).id === 'string' && + (icon as IconCheckedSchema).id.startsWith('svg-') + ) { + return ( + + + + ); + } + + // icon是链接 const isURLIcon = typeof icon === 'string' && icon?.indexOf('.') !== -1; - const isIconfont = - typeof icon === 'string' && - (~icon?.indexOf('iconfont') || ~icon?.indexOf('fa')); + if (isURLIcon) { + return ( + + ); + } - return Component ? ( - <> - {iconContent ? ( -
- ) : null} - {!showCssIcon ? ( - - ) : null} - - ) : isURLIcon ? ( - - ) : isIconfont ? ( - - ) : ( - 没有 icon {icon} - ); + // icon是普通字符串 + const isIconfont = typeof icon === 'string'; + + let iconPrefix = ''; + if (vendor === 'iconfont') { + iconPrefix = `iconfont icon-${icon}`; + } else if (vendor === 'fa') { + //默认是fontawesome v4,兼容之前配置 + iconPrefix = `${vendor} ${vendor}-${icon}`; + } else { + // 如果vendor为空,则不设置前缀,这样可以支持fontawesome v5、fontawesome v6或者其他框架 + iconPrefix = icon; + } + + if (isIconfont) { + return ( + + ); + } + + // 没有合适的图标 + return 没有 icon {icon}; } export { diff --git a/packages/amis-ui/src/components/json-schema/Array.tsx b/packages/amis-ui/src/components/json-schema/Array.tsx index c9fc130bd..baba3fa87 100644 --- a/packages/amis-ui/src/components/json-schema/Array.tsx +++ b/packages/amis-ui/src/components/json-schema/Array.tsx @@ -150,7 +150,7 @@ export function InputJSONSchemaArray(props: InputJSONSchemaItemProps) { })} onClick={toggleCollapsed} > - +
) : null} diff --git a/packages/amis-ui/src/components/json-schema/Object.tsx b/packages/amis-ui/src/components/json-schema/Object.tsx index bfec03c75..b041eca54 100644 --- a/packages/amis-ui/src/components/json-schema/Object.tsx +++ b/packages/amis-ui/src/components/json-schema/Object.tsx @@ -202,7 +202,7 @@ export function InputJSONSchemaObject(props: InputJSONSchemaItemProps) { })} onClick={toggleCollapsed} > - + ) : null} diff --git a/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap b/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap index f7f93a9b2..7e605002a 100644 --- a/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap +++ b/packages/amis/__tests__/event-action/__snapshots__/dialog.test.tsx.snap @@ -45,10 +45,6 @@ exports[`EventAction:dialog 1`] = ` data-position="left" data-tooltip="关闭" > -