Skip to content

Commit 8a68e27

Browse files
committed
feat: 添加 modal layout 识别
1 parent ddfceb2 commit 8a68e27

File tree

8 files changed

+139
-20
lines changed

8 files changed

+139
-20
lines changed

src/type.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,30 @@ export type GroupLayoutType =
2525
| 'VERTICALLY_CENTER'
2626
| 'RIGHT_TO_LEFT'
2727
| 'LEFT_TO_RIGHT'
28-
| 'TOP_TO_BOTTOM';
28+
| 'TOP_TO_BOTTOM'
29+
| 'NONE';
2930

3031
/**
3132
* 对 symbol 进行自定义处理的方法
3233
*/
3334
export type HandleSymbolFn = (symbol: SymbolMaster) => void;
3435

36+
export interface DefaultSymbolParams {
37+
/**
38+
* symbol 本身的 layout
39+
*/
40+
symbolLayout: GroupLayoutType;
41+
/**
42+
* symbol 内部的图层配置项
43+
*/
44+
layerParams: SymbolAdjustParams[];
45+
}
46+
47+
export enum LayerSelectorMatchMethod {
48+
Equal,
49+
Included,
50+
}
51+
3552
/**
3653
* 对 symbol 的相关配置项调整的参数
3754
*/
@@ -42,6 +59,7 @@ export interface SymbolAdjustParams {
4259
selector: {
4360
type: 'classname' | 'class' | 'name' | 'text' | 'tag';
4461
value: string;
62+
match?: LayerSelectorMatchMethod;
4563
};
4664
/**
4765
* sketch 的调整参数

src/utils/sketchSymbolParams/Modal.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { ResizingConstraint } from '../layout';
2+
import { DefaultSymbolParams, LayerSelectorMatchMethod } from '../../type';
3+
4+
/**
5+
* 默认的 modal 样式
6+
*/
7+
export const defaultModal: DefaultSymbolParams = {
8+
symbolLayout: 'NONE',
9+
layerParams: [
10+
{
11+
// 内容
12+
selector: {
13+
type: 'classname',
14+
value: 'ant-modal-content',
15+
},
16+
resizing: [ResizingConstraint.Top, ResizingConstraint.Bottom],
17+
},
18+
{
19+
// svg
20+
selector: {
21+
type: 'class',
22+
value: 'svg',
23+
},
24+
resizing: [
25+
ResizingConstraint.Height,
26+
ResizingConstraint.Width,
27+
ResizingConstraint.Top,
28+
ResizingConstraint.Right,
29+
],
30+
},
31+
{
32+
// 标题
33+
selector: {
34+
type: 'classname',
35+
value: 'ant-modal-footer',
36+
},
37+
resizing: [
38+
ResizingConstraint.Bottom,
39+
ResizingConstraint.Height,
40+
ResizingConstraint.Width,
41+
],
42+
layout: 'RIGHT_TO_LEFT',
43+
},
44+
{
45+
// Modal 头部
46+
selector: {
47+
type: 'classname',
48+
value: 'ant-modal-header',
49+
},
50+
resizing: [ResizingConstraint.Height, ResizingConstraint.Top],
51+
layout: 'RIGHT_TO_LEFT',
52+
},
53+
{
54+
// Modal 头部
55+
selector: {
56+
type: 'classname',
57+
value: 'ant-modal-header',
58+
match: LayerSelectorMatchMethod.Included,
59+
},
60+
resizing: [ResizingConstraint.Width, ResizingConstraint.Right],
61+
layout: 'RIGHT_TO_LEFT',
62+
},
63+
],
64+
};

src/utils/sketchSymbolParams/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { welcomeHeader } from './WelcomeHeader';
2+
import { defaultModal } from './Modal';
3+
4+
/**
5+
* 模块内部集成的 Symbol 参数列表
6+
*/
7+
export const defaultSymbolParamsList = [welcomeHeader, defaultModal];

tests/docs/case/modal.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Modal 浮层
3+
order: 50
4+
---
5+
6+
## 测试 Modal 浮层
7+
8+
测试浮层的结果
9+
10+
<code src="../demo/Modal.tsx" />

tests/docs/demo/Modal.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.modal-wrapper {
2+
z-index: -10;
3+
}
4+
.modal-body {
5+
z-index: 100 !important;
6+
}
7+
.container {
8+
z-index: 100;
9+
}

tests/docs/demo/Modal.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import React, { FC, useRef } from 'react';
1+
import React, { FC, useEffect } from 'react';
22
import { Modal } from 'antd';
33
import TestLayout from './utils/TestLayout';
4+
import useElements from './utils/useElements';
5+
import './Modal.less';
46

57
/**
68
*
79
*/
810
const ModalPage: FC = () => {
9-
const ref = useRef(null);
11+
const { elements, ref, setElements } = useElements();
12+
13+
useEffect(() => {
14+
const modal = document.getElementsByClassName('ant-modal')?.item(0);
15+
if (modal) {
16+
setElements([modal]);
17+
}
18+
}, [ref.current]);
1019
return (
11-
<TestLayout elements={[]}>
12-
<div ref={ref} id="x-modal" style={{ width: '100%', height: '100%' }}>
13-
<Modal
14-
visible
15-
title="123123"
16-
mask={false}
17-
maskClosable
18-
getContainer={() => document.getElementById('x-modal')!}
19-
>
20-
123
21-
</Modal>
22-
</div>
20+
<TestLayout elements={elements}>
21+
<Modal
22+
visible
23+
title="Modal 测试"
24+
mask={false}
25+
centered
26+
maskClosable
27+
className="modal-body"
28+
wrapClassName="modal-wrapper"
29+
>
30+
123
31+
</Modal>
2332
</TestLayout>
2433
);
2534
};

tests/docs/demo/utils/TestLayout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable import/no-unresolved */
2+
13
import React, { FC, useState } from 'react';
24
import { Button, Row, Col, Card, Divider, Space, message } from 'antd';
35
import ReactJson from 'react-json-view';
@@ -58,7 +60,7 @@ const TestLayout: FC<FooterProps> = ({ elements, children }) => {
5860
<div>
5961
{children}
6062
<Divider dashed />
61-
<Row>
63+
<Row style={{ zIndex: 99999 }}>
6264
<Col span={24}>
6365
<Row justify="space-between">
6466
<Col>

tests/docs/demo/utils/useElements.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useEffect, useRef, useState } from 'react';
22

3-
export default () => {
4-
const ref = useRef(null);
5-
const [elements, setElements] = useState([]);
3+
export default <T = any>() => {
4+
const ref = useRef<T>(null);
5+
const [elements, setElements] = useState<T[]>([]);
66

77
useEffect(() => {
88
if (elements.length === 0 && ref.current) {
99
// @ts-ignore
1010
setElements([ref.current]);
1111
}
1212
});
13-
return { ref, elements };
13+
return { ref, elements, setElements };
1414
};

0 commit comments

Comments
 (0)