From 9e5d1f8d8f9363869c2fbe0928473c99993f6c65 Mon Sep 17 00:00:00 2001 From: hsp-sz Date: Wed, 12 Jun 2024 14:15:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4defaultProps?= =?UTF-8?q?=EF=BC=8C=E6=9B=BF=E6=8D=A2=E4=B8=BA=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E5=92=8C=E8=A7=A3=E6=9E=84=E8=B5=8B=E5=80=BC=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrative-select.tsx | 40 +++++++++---------- docs/blocks/draw-modal/DrawModal.tsx | 31 +++++++------- .../Control/CustomControl/index.tsx | 4 +- .../Legend/LegendCategories/index.tsx | 7 +--- .../Legend/LegendProportion/index.tsx | 4 -- src/components/Legend/LegendRamp/index.tsx | 7 +--- src/components/LocationSearch/index.tsx | 24 +++++------ 7 files changed, 50 insertions(+), 67 deletions(-) diff --git a/docs/blocks/administrative-select/administrative-select.tsx b/docs/blocks/administrative-select/administrative-select.tsx index 10c7fae3..329ed391 100644 --- a/docs/blocks/administrative-select/administrative-select.tsx +++ b/docs/blocks/administrative-select/administrative-select.tsx @@ -47,10 +47,25 @@ const getCascadeData = (list: any[]) => { } }; +const defaultCascaderProps = { + placeholder: '可选择省/市/县', + expandTrigger: 'hover', + allowClear: true, + changeOnSelect: true, + showSearch: true, +}; + export const AdministrativeSelect: React.FC = ({ - enableBoundary, - autoFit, - boundaryLayer, + enableBoundary = true, + autoFit = true, + boundaryLayer = { + shape: 'line', + color: '#ff0000', + size: 2, + style: { + opacity: 0.8, + }, + }, value: originValue, onChange, ...props @@ -123,6 +138,7 @@ export const AdministrativeSelect: React.FC = ({ } }} multiple={false} + {...defaultCascaderProps} {...props} /> {enableBoundary && ( @@ -136,21 +152,3 @@ export const AdministrativeSelect: React.FC = ({ ); }; - -AdministrativeSelect.defaultProps = { - placeholder: '可选择省/市/县', - expandTrigger: 'hover', - allowClear: true, - changeOnSelect: true, - enableBoundary: true, - autoFit: true, - showSearch: true, - boundaryLayer: { - shape: 'line', - color: '#ff0000', - size: 2, - style: { - opacity: 0.8, - }, - }, -}; diff --git a/docs/blocks/draw-modal/DrawModal.tsx b/docs/blocks/draw-modal/DrawModal.tsx index 88e7e4c4..555efc42 100644 --- a/docs/blocks/draw-modal/DrawModal.tsx +++ b/docs/blocks/draw-modal/DrawModal.tsx @@ -63,11 +63,23 @@ const DrawModalContent: React.FC< ); }); +const defaultModalProps = { + width: 700, + title: '绘制弹框', + cancelText: '取消', + okText: '提交', + destroyOnClose: true, +} + export const DrawModal: React.FC = ({ className, larkmapProps, - drawConfig, - locationSearchProps, + drawConfig = { + point: true, + line: true, + polygon: true, + }, + locationSearchProps = false, onOk, ...modalProps }) => { @@ -90,6 +102,7 @@ export const DrawModal: React.FC = ({ onOk={() => { onOk?.(drawData); }} + {...defaultModalProps} {...modalProps} > @@ -98,17 +111,3 @@ export const DrawModal: React.FC = ({ ); }; - -DrawModal.defaultProps = { - drawConfig: { - point: true, - line: true, - polygon: true, - }, - width: 700, - title: '绘制弹框', - cancelText: '取消', - okText: '提交', - locationSearchProps: false, - destroyOnClose: true, -}; diff --git a/src/components/Control/CustomControl/index.tsx b/src/components/Control/CustomControl/index.tsx index 62950d64..75774171 100644 --- a/src/components/Control/CustomControl/index.tsx +++ b/src/components/Control/CustomControl/index.tsx @@ -7,7 +7,7 @@ import { getStyleText } from '../../../utils'; import type { CustomControlProps } from './types'; export const CustomControl: React.FC = (props): React.ReactPortal => { - const { className, style, children, position, name } = props; + const { className, style, children, position = 'topleft', name } = props; const containerRef = useRef(document.createElement('div')); const styleText = getStyleText(style); @@ -30,4 +30,4 @@ export const CustomControl: React.FC = (props): React.ReactP return createPortal(children, containerRef.current); }; -CustomControl.defaultProps = { position: 'topleft' }; + diff --git a/src/components/Legend/LegendCategories/index.tsx b/src/components/Legend/LegendCategories/index.tsx index 422f478d..c772fde8 100644 --- a/src/components/Legend/LegendCategories/index.tsx +++ b/src/components/Legend/LegendCategories/index.tsx @@ -7,7 +7,7 @@ import type { LegendCategoriesProps } from './types'; export const CLS_PREFIX = 'larkmap-legend-category'; export function LegendCategories(props: LegendCategoriesProps) { - const { labels, colors, geometryType = 'circle', isStrokeColor, style, className: cls_name } = props; + const { labels, colors, geometryType = 'circle', isStrokeColor = false, style, className: cls_name } = props; function getColor(item: string) { return isStrokeColor ? { border: `2px solid ${item}` } : { background: item }; @@ -39,8 +39,3 @@ export function LegendCategories(props: LegendCategoriesProps) { } return ; } - -LegendCategories.defaultProps = { - geometryType: 'circle', - isStrokeColor: false, -}; diff --git a/src/components/Legend/LegendProportion/index.tsx b/src/components/Legend/LegendProportion/index.tsx index efef0e72..6aae4bbf 100644 --- a/src/components/Legend/LegendProportion/index.tsx +++ b/src/components/Legend/LegendProportion/index.tsx @@ -82,7 +82,3 @@ export const LegendProportion = (props: LegendProportionProp) => { ); }; - -LegendProportion.defaultProps = { - fillColor: '#f9f9f9', -}; diff --git a/src/components/Legend/LegendRamp/index.tsx b/src/components/Legend/LegendRamp/index.tsx index 60b9cefe..706892d0 100644 --- a/src/components/Legend/LegendRamp/index.tsx +++ b/src/components/Legend/LegendRamp/index.tsx @@ -104,7 +104,7 @@ function DisContinuous({ } export function LegendRamp(props: LegendRampProps) { - const { isContinuous, labels, colors, labelUnit, className: cls, style } = props; + const { isContinuous = false, labels, colors, labelUnit='', className: cls, style } = props; // const [min, max] = getMinMax(labels); // const isError = Number.isNaN(min) || Number.isNaN(max); @@ -120,8 +120,3 @@ export function LegendRamp(props: LegendRampProps) { ); } - -LegendRamp.defaultProps = { - isContinuous: false, - labelUnit: '', -}; diff --git a/src/components/LocationSearch/index.tsx b/src/components/LocationSearch/index.tsx index ba275cb7..88959a95 100644 --- a/src/components/LocationSearch/index.tsx +++ b/src/components/LocationSearch/index.tsx @@ -9,10 +9,19 @@ import type { LocationSearchOption, LocationSearchProps } from './types'; const { Option } = Select; +const defaultSelectProps = { + placeholder: '请输入要搜索地名', + showSearch: true, + allowClear: true, + filterOption: false, + defaultActiveFirstOption: false, +}; + + export const LocationSearch: React.FC = ({ searchParams, - showDistrict, - showAddress, + showDistrict = true, + showAddress = true, onSearchFinish, onChange, ...selectProps @@ -69,6 +78,7 @@ export const LocationSearch: React.FC = ({ onSearch={onSearch} onChange={onLocationChange} clearIcon={() => null} + {...defaultSelectProps} {...selectProps} > {options.map((option) => { @@ -89,13 +99,3 @@ export const LocationSearch: React.FC = ({ ); }; - -LocationSearch.defaultProps = { - placeholder: '请输入要搜索地名', - showSearch: true, - allowClear: true, - filterOption: false, - defaultActiveFirstOption: false, - showAddress: true, - showDistrict: true, -}; From c0bc1b2b489f862b88c2bc15883edb3239e2f6c0 Mon Sep 17 00:00:00 2001 From: hsp-sz Date: Wed, 12 Jun 2024 14:27:10 +0800 Subject: [PATCH 2/2] feat: prettier code --- src/components/Legend/LegendRamp/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Legend/LegendRamp/index.tsx b/src/components/Legend/LegendRamp/index.tsx index 706892d0..186df1dc 100644 --- a/src/components/Legend/LegendRamp/index.tsx +++ b/src/components/Legend/LegendRamp/index.tsx @@ -104,7 +104,7 @@ function DisContinuous({ } export function LegendRamp(props: LegendRampProps) { - const { isContinuous = false, labels, colors, labelUnit='', className: cls, style } = props; + const { isContinuous = false, labels, colors, labelUnit = '', className: cls, style } = props; // const [min, max] = getMinMax(labels); // const isError = Number.isNaN(min) || Number.isNaN(max);