Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 移除defaultProps,替换为默认值和解构赋值默认赋值 #231

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 All @@ -17,7 +17,7 @@
return (
<div className={classnames(CLS_PREFIX, cls_name)} style={style}>
{labels.map((item, index) => (
<div className={`${CLS_PREFIX}__content`} key={`${item}__${color[index]}__${index}`}>

Check warning on line 20 in src/components/Legend/LegendCategories/index.tsx

View workflow job for this annotation

GitHub Actions / lint (16.x)

Do not use Array index in keys
<div
className={classnames(`${CLS_PREFIX}__content__shape`, {
[`${CLS_PREFIX}__content__${geometryType}`]: geometryType,
Expand All @@ -39,8 +39,3 @@
}
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 @@ -6,7 +6,7 @@

export const CLS_PREFIX = 'larkmap-legend-ramp';

const getMinMax = (labels: (string | number)[]) => {

Check warning on line 9 in src/components/Legend/LegendRamp/index.tsx

View workflow job for this annotation

GitHub Actions / lint (16.x)

'getMinMax' is assigned a value but never used
let max = labels[labels.length - 1];
let min = labels[0];

Expand Down Expand Up @@ -104,7 +104,7 @@
}

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 @@
</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,
};
Loading