Skip to content

Commit

Permalink
feat: 移除defaultProps,替换为默认值和解构赋值默认赋值 (#231)
Browse files Browse the repository at this point in the history
* feat: 移除defaultProps,替换为默认值和解构赋值默认赋值

* feat: prettier code
  • Loading branch information
hsp-sz authored Jun 12, 2024
1 parent c99b386 commit c5141c8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 67 deletions.
40 changes: 19 additions & 21 deletions docs/blocks/administrative-select/administrative-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ const getCascadeData = (list: any[]) => {
}
};

const defaultCascaderProps = {
placeholder: '可选择省/市/县',
expandTrigger: 'hover',
allowClear: true,
changeOnSelect: true,
showSearch: true,
};

export const AdministrativeSelect: React.FC<AdministrativeSelectProps> = ({
enableBoundary,
autoFit,
boundaryLayer,
enableBoundary = true,
autoFit = true,
boundaryLayer = {
shape: 'line',
color: '#ff0000',
size: 2,
style: {
opacity: 0.8,
},
},
value: originValue,
onChange,
...props
Expand Down Expand Up @@ -123,6 +138,7 @@ export const AdministrativeSelect: React.FC<AdministrativeSelectProps> = ({
}
}}
multiple={false}
{...defaultCascaderProps}
{...props}
/>
{enableBoundary && (
Expand All @@ -136,21 +152,3 @@ export const AdministrativeSelect: React.FC<AdministrativeSelectProps> = ({
</>
);
};

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,
},
},
};
31 changes: 15 additions & 16 deletions docs/blocks/draw-modal/DrawModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,23 @@ const DrawModalContent: React.FC<
);
});

const defaultModalProps = {
width: 700,
title: '绘制弹框',
cancelText: '取消',
okText: '提交',
destroyOnClose: true,
}

export const DrawModal: React.FC<DrawModalProps> = ({
className,
larkmapProps,
drawConfig,
locationSearchProps,
drawConfig = {
point: true,
line: true,
polygon: true,
},
locationSearchProps = false,
onOk,
...modalProps
}) => {
Expand All @@ -90,6 +102,7 @@ export const DrawModal: React.FC<DrawModalProps> = ({
onOk={() => {
onOk?.(drawData);
}}
{...defaultModalProps}
{...modalProps}
>
<LarkMap style={{ height: 400 }} {...larkmapProps}>
Expand All @@ -98,17 +111,3 @@ export const DrawModal: React.FC<DrawModalProps> = ({
</Modal>
);
};

DrawModal.defaultProps = {
drawConfig: {
point: true,
line: true,
polygon: true,
},
width: 700,
title: '绘制弹框',
cancelText: '取消',
okText: '提交',
locationSearchProps: false,
destroyOnClose: true,
};
4 changes: 2 additions & 2 deletions src/components/Control/CustomControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getStyleText } from '../../../utils';
import type { CustomControlProps } from './types';

export const CustomControl: React.FC<CustomControlProps> = (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);

Expand All @@ -30,4 +30,4 @@ export const CustomControl: React.FC<CustomControlProps> = (props): React.ReactP
return createPortal(children, containerRef.current);
};

CustomControl.defaultProps = { position: 'topleft' };

7 changes: 1 addition & 6 deletions src/components/Legend/LegendCategories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -39,8 +39,3 @@ export function LegendCategories(props: LegendCategoriesProps) {
}
return <Renders />;
}

LegendCategories.defaultProps = {
geometryType: 'circle',
isStrokeColor: false,
};
4 changes: 0 additions & 4 deletions src/components/Legend/LegendProportion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,3 @@ export const LegendProportion = (props: LegendProportionProp) => {
</div>
);
};

LegendProportion.defaultProps = {
fillColor: '#f9f9f9',
};
7 changes: 1 addition & 6 deletions src/components/Legend/LegendRamp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -120,8 +120,3 @@ export function LegendRamp(props: LegendRampProps) {
</div>
);
}

LegendRamp.defaultProps = {
isContinuous: false,
labelUnit: '',
};
24 changes: 12 additions & 12 deletions src/components/LocationSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocationSearchProps> = ({
searchParams,
showDistrict,
showAddress,
showDistrict = true,
showAddress = true,
onSearchFinish,
onChange,
...selectProps
Expand Down Expand Up @@ -69,6 +78,7 @@ export const LocationSearch: React.FC<LocationSearchProps> = ({
onSearch={onSearch}
onChange={onLocationChange}
clearIcon={() => null}
{...defaultSelectProps}
{...selectProps}
>
{options.map((option) => {
Expand All @@ -89,13 +99,3 @@ export const LocationSearch: React.FC<LocationSearchProps> = ({
</Select>
);
};

LocationSearch.defaultProps = {
placeholder: '请输入要搜索地名',
showSearch: true,
allowClear: true,
filterOption: false,
defaultActiveFirstOption: false,
showAddress: true,
showDistrict: true,
};

0 comments on commit c5141c8

Please sign in to comment.