Skip to content

Commit 71ccf9f

Browse files
authored
Merge pull request #552 from nullptr-z/dev
fix(Preview): 示例预览组件将节点挂在到div下
2 parents 2f88270 + 6957d03 commit 71ccf9f

File tree

7 files changed

+80
-57
lines changed

7 files changed

+80
-57
lines changed

packages/core/src/DragDrawer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DragDrawer 拖曳抽屉
22
---
33

4-
![](https://user-images.githubusercontent.com/66067296/143187302-bee614b4-7799-49d1-9cab-470ad8228372.gif)
4+
<img src="https://user-images.githubusercontent.com/66067296/143187302-bee614b4-7799-49d1-9cab-470ad8228372.gif" style="width:300px;height:620px"/>
55

66
可自定义拖曳抽屉高度。
77

packages/core/src/Empty/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Empty 空状态
33

44
空状态时的展示占位图。
55

6-
![](https://user-images.githubusercontent.com/66067296/137707848-8603fc59-3904-437d-9908-53cd621a1a0e.png)
6+
<img src="https://user-images.githubusercontent.com/66067296/137707848-8603fc59-3904-437d-9908-53cd621a1a0e.png" style="width:300px;height:620px"/>
77

88
### 基础示例
99

10-
<!--DemoStart-->
10+
<!--DemoStart-->
1111
```js
1212
import { Empty } from '@uiw/react-native';
1313

@@ -24,7 +24,7 @@ export default Demo
2424

2525
### 自定义文字
2626

27-
<!--DemoStart-->
27+
<!--DemoStart-->
2828
```js
2929
import { Empty } from '@uiw/react-native';
3030

@@ -41,7 +41,7 @@ export default Demo
4141

4242
### 替换默认图标
4343

44-
<!--DemoStart-->
44+
<!--DemoStart-->
4545
```js
4646
import { Empty } from '@uiw/react-native';
4747

@@ -82,7 +82,7 @@ export default Demo
8282

8383
### 自定义图标尺寸
8484

85-
<!--DemoStart-->
85+
<!--DemoStart-->
8686
```js
8787
import { Empty } from '@uiw/react-native';
8888

@@ -99,7 +99,7 @@ export default Demo
9999

100100
### 自定义文字样式
101101

102-
<!--DemoStart-->
102+
<!--DemoStart-->
103103
```js
104104
import { Empty } from '@uiw/react-native';
105105

@@ -116,7 +116,7 @@ export default Demo
116116

117117
### 提示更多内容
118118

119-
<!--DemoStart-->
119+
<!--DemoStart-->
120120
```js
121121
import { Empty } from '@uiw/react-native';
122122
import {View, Text } from 'react-native';

packages/core/src/Form/comps/label.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Label = ({ v }: { v: Partial<FormItemsProps> }) => {
1616

1717
const styles = StyleSheet.create({
1818
label: {
19-
width: 110,
19+
width: 'auto',
2020
fontSize: 16,
2121
color: '#434343',
2222
fontWeight: '500',

packages/core/src/Form/styles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StyleSheet } from 'react-native';
22

33
const styles = StyleSheet.create({
44
warpper: {
5-
backgroundColor: '#fff',
5+
backgroundColor: '#fff5',
66
},
77
form_items_container: {
88
flex: 1,

packages/core/src/SpeedDial/README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,48 @@ SpeedDial 悬浮标记组件按下时,浮动动作按钮可以以快速显示
1111
### 基础示例
1212

1313
```jsx mdx:preview&background=#bebebe29
14-
import React, { Fragment } from 'react';
14+
import React, { Fragment, useEffect, useRef, useState } from 'react';
1515
import { SpeedDial, Icon } from '@uiw/react-native';
1616
import { View, Text, Dimensions } from 'react-native';
1717

18+
const bodyHeight = window.screen.height
19+
1820
function Demo() {
21+
const refs = useRef()
22+
const [position, usePosition]= useState(0)
23+
useEffect(() => {
24+
const parent= refs.current.getBoundingClientRect();
25+
console.log('parent: ', parent);
26+
usePosition(parent.y)
27+
},[refs.current])
28+
1929
return (
20-
<View style={{ height: 180, background: '#ddd' }}>
30+
<div ref={refs} style={{ height: 200 }}>
2131
<SpeedDial
2232
onOpen={()=>console.log('onOpen2')}
2333
onClose={()=>console.log('onClose')}
24-
bottom={750}
34+
bottom={bodyHeight-position}
2535
children={[
2636
{
2737
icon: 'plus',
2838
title: <Text>Add</Text>,
2939
onPress:()=>console.log('Add')
3040
},
3141
{
32-
icon: <Icon name='star-on' color="#fff" size={18} />,
42+
icon: <Icon name='star-on' size={18} />,
3343
title: 'Star'
3444
},
3545
{
36-
icon: <Icon name='mail' color="#fff" size={18} />,
46+
icon: <Icon name='mail' size={18} />,
3747
title: 'Mail'
3848
},
3949
{
40-
icon: <Icon name='share' color="#fff" size={18} />,
50+
icon: <Icon name='share' size={18} />,
4151
title: 'Share'
4252
}
4353
]}
4454
/>
45-
</View>
55+
</div>
4656
);
4757
}
4858
export default Demo
@@ -51,39 +61,47 @@ export default Demo
5161
### 设置动画时间
5262

5363
```jsx mdx:preview&background=#bebebe29
54-
import React, { Fragment } from 'react';
64+
import React, { Fragment, useEffect, useRef, useState } from 'react';
5565
import { SpeedDial, Icon } from '@uiw/react-native';
5666
import { View, Text, Dimensions } from 'react-native';
5767

68+
const bodyHeight = window.screen.height
5869
function Demo() {
70+
const refs = useRef()
71+
const [position, usePosition]= useState(0)
72+
useEffect(() => {
73+
const parent= refs.current.getBoundingClientRect();
74+
usePosition(parent.y)
75+
},[refs.current])
76+
5977
return (
60-
<View style={{ height: 180, background: '#ddd' }}>
78+
<div ref={refs} style={{ height: 200 }}>
6179
<SpeedDial
6280
transitionDuration={2000}
6381
onOpen={()=>console.log('onOpen')}
6482
onClose={()=>console.log('onClose')}
65-
bottom={750}
83+
bottom={bodyHeight-(position/2)}
6684
children={[
6785
{
6886
icon: 'plus',
6987
title: <Text>Add</Text>,
7088
onPress:()=>console.log('Add')
7189
},
7290
{
73-
icon: <Icon name='star-on' color="#fff" size={18} />,
91+
icon: <Icon name='star-on' size={18} />,
7492
title: 'Star'
7593
},
7694
{
77-
icon: <Icon name='mail' color="#fff" size={18} />,
95+
icon: <Icon name='mail' size={18} />,
7896
title: 'Mail'
7997
},
8098
{
81-
icon: <Icon name='share' color="#fff" size={18} />,
99+
icon: <Icon name='share' size={18} />,
82100
title: 'Share'
83101
}
84102
]}
85103
/>
86-
</View>
104+
</div>
87105
);
88106
}
89107
export default Demo

packages/core/src/SwipeAction/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SwipeAction 滑动操作组件。
22
---
33
结合手势操作,从屏幕一侧唤出操作。
44

5-
![](https://user-images.githubusercontent.com/57083007/146733663-6c83fca4-72df-424d-8364-47533f57ece6.gif)
5+
<img src="https://user-images.githubusercontent.com/57083007/146733663-6c83fca4-72df-424d-8364-47533f57ece6.gif" style="width:300px;height:620px"/>
66

77
### 基础示例
88

website/src/component/Preview/index.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ const getBooleanValue = (param, field, defaultValue) => {
3434
};
3535

3636
const Preview = ({ path, ...mdData }) => {
37-
const Preview = CodeLayout.Preview;
38-
const Code = CodeLayout.Code;
39-
const Toolbar = CodeLayout.Toolbar;
4037
const $dom = useRef(null);
4138
return (
4239
<Wrapper ref={$dom}>
@@ -46,41 +43,49 @@ const Preview = ({ path, ...mdData }) => {
4643
// transformImageUri={transformImageUri}
4744
source={mdData.source}
4845
rehypeRewrite={(node, index, parent) => {
49-
if (node.type === 'element' && parent && parent.type === 'root' && /h(1|2|3|4|5|6)/.test(node.tagName)) {
50-
const child = node.children && node.children[0];
51-
if (child && child.properties && child.properties.ariaHidden === 'true') {
52-
child.children = [];
46+
if (node.type === 'element' && node.tagName === 'pre' && node.children[0].data?.meta) {
47+
const meta = node.children[0].data?.meta;
48+
if (isMeta(meta)) {
49+
node.tagName = 'div';
50+
if (!node.properties) {
51+
node.properties = {};
52+
}
53+
node.properties['data-md'] = meta;
54+
node.properties['data-meta'] = 'preview';
5355
}
5456
}
5557
}}
5658
components={{
57-
code: ({ inline, node, ...props }) => {
58-
const { 'data-meta': meta, ...rest } = props;
59-
if (inline || !isMeta(meta)) {
60-
return <code {...props} />;
61-
}
62-
const line = node.position?.start.line;
63-
const metaId = getMetaId(meta) || String(line);
64-
const Child = mdData.components[`${metaId}`];
65-
if (metaId && typeof Child === 'function') {
66-
const code = mdData.data[metaId].value || '';
67-
const param = getURLParameters(meta);
68-
return (
69-
<CodeLayout
70-
disableCheckered={getBooleanValue(param, 'disableCheckered', true)}
71-
bordered={getBooleanValue(param, 'bordered', true)}
72-
>
73-
<Preview>
59+
div: ({ node, ...props }) => {
60+
const { 'data-meta': meta, 'data-md': metaData } = props;
61+
if (meta === 'preview') {
62+
const line = node.position?.start.line;
63+
const metaId = getMetaId(meta) || String(line);
64+
const Child = mdData.components[`${metaId}`];
65+
if (metaId && typeof Child === 'function') {
66+
const code = mdData.data[metaId].value || '';
67+
const param = getURLParameters(metaData);
68+
return (
69+
<CodeLayout
70+
disableCheckered={getBooleanValue(param, 'disableCheckered', true)}
71+
disableToolbar={getBooleanValue(param, 'disableToolbar', false)}
72+
disableCode={getBooleanValue(param, 'disableCode', false)}
73+
disablePreview={getBooleanValue(param, 'disablePreview', false)}
74+
bordered={getBooleanValue(param, 'bordered', true)}
75+
copied={getBooleanValue(param, 'copied', true)}
76+
background={param.background}
77+
toolbar={param.title || '示例'}
78+
codeProps={{ style: { padding: 0 } }}
79+
style={{ padding: 0 }}
80+
code={<pre {...props} />}
81+
text={code}
82+
>
7483
<Child />
75-
</Preview>
76-
<Toolbar text={code} copied={getBooleanValue(param, 'copied', true)}>
77-
{param.title || '示例'}
78-
</Toolbar>
79-
<Code>{code}</Code>
80-
</CodeLayout>
81-
);
84+
</CodeLayout>
85+
);
86+
}
8287
}
83-
return <code {...rest} />;
88+
return <div {...props} />;
8489
},
8590
}}
8691
/>

0 commit comments

Comments
 (0)