Skip to content
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@
"sort": 11,
"show": true,
"taro": true,
"v15": 2,
"v15": 1,
"author": "dsj",
"dd": true
},
Expand Down
47 changes: 40 additions & 7 deletions src/packages/actionsheet/actionsheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

.nut-actionsheet {
text-align: center;

box-sizing: border-box;
padding: 16px;
width: 100%;
&-bottom {
padding-bottom: 34px;
}
&.nut-popup {
min-height: 10%;
background-color: $actionsheet-background-color;
}

.nut-popup-title {
border-bottom: 1px solid $actionsheet-border-color;
&-bottom-title,
&-top-title {
font-size: 16px;
font-weight: 600;
color: rgb(26, 26, 26);
justify-content: center;
margin-bottom: 16px;
display: flex;
align-items: center;
}
&-top-title {
justify-content: space-between;
}
&-close-icon {
width: 16px;
height: 16px;
}

&-list {
Expand All @@ -23,12 +41,17 @@
&-cancel,
&-item {
display: block;
padding: 10px;
text-align: $actionsheet-item-text-align;
line-height: $actionsheet-item-line-height;
font-size: $font-size-base;
color: $actionsheet-item-color;
cursor: pointer;
&-border {
border-bottom: $actionsheet-item-border-bottom;
/* #ifdef harmony */
border-width: 1px;
/* #endif */
}
&-name {
text-align: $actionsheet-item-text-align;
line-height: $actionsheet-item-line-height;
Expand All @@ -54,9 +77,19 @@
}

&-cancel {
margin-top: 5px;
border-top: 1px solid $actionsheet-border-color;
border: 0.5px solid #c2c4cc;
/* #ifdef harmony */
border-width: 1px;
/* #endif */
border-radius: $actionsheet-border-radius;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
line-height: 40px;
color: rgb(26, 26, 26);
margin-top: 16px;
}

&-safe-area {
Expand Down
17 changes: 12 additions & 5 deletions src/packages/actionsheet/actionsheet.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FunctionComponent } from 'react'
import { View } from '@tarojs/components'
import { Close } from '@nutui/icons-react-taro'
import Popup from '@/packages/popup/index.taro'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
Expand All @@ -12,6 +13,7 @@ const defaultProps = {
options: [],
optionKey: { name: 'name', description: 'description' },
cancelText: '',
position: 'bottom',
onCancel: () => {},
onSelect: () => {},
} as unknown as TaroActionSheetProps
Expand All @@ -31,6 +33,7 @@ export const ActionSheet: FunctionComponent<
visible,
className,
style,
position,
...rest
} = mergeProps(defaultProps, props)

Expand All @@ -54,22 +57,26 @@ export const ActionSheet: FunctionComponent<
{...rest}
round
visible={visible}
position="bottom"
title={title}
position={position}
description={description}
className={classPrefix}
className={`${classPrefix} ${classPrefix}-${position}`}
onClose={() => {
onCancel && onCancel()
onCancel?.()
}}
closeable={position === 'top'}
closeIcon={<Close className={`${classPrefix}-close-icon`} />}
>
<View className={`${className}`} style={style}>
{title && (
<View className={`${classPrefix}-${position}-title`}>{title}</View>
)}
{options.length ? (
<View className={`${classPrefix}-list`}>
{options.map((item, index) => {
const statusClass = `${item.disabled ? `${classPrefix}-item-disabled` : ''} ${item.danger ? `${classPrefix}-item-danger` : ''}`
return (
<View
className={`${classPrefix}-item ${statusClass}`}
className={`${classPrefix}-item ${statusClass} ${index !== options.length - 1 ? `${classPrefix}-item-border` : ''}`}
key={index}
onClick={() => chooseItem(item, index)}
>
Expand Down
17 changes: 12 additions & 5 deletions src/packages/actionsheet/actionsheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FunctionComponent } from 'react'
import { Close } from '@nutui/icons-react'
import Popup from '@/packages/popup/index'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
Expand All @@ -11,6 +12,7 @@
options: [],
optionKey: { name: 'name', description: 'description' },
cancelText: '',
position: 'bottom',
onCancel: () => {},
onSelect: () => {},
} as unknown as WebActionSheetProps
Expand All @@ -30,6 +32,7 @@
visible,
className,
style,
position,
...rest
} = mergeProps(defaultProps, props)

Expand All @@ -53,22 +56,26 @@
{...rest}
round
visible={visible}
position="bottom"
title={title}
position={position}
description={description}
className={classPrefix}
className={`${classPrefix} ${classPrefix}-${position}`}
onClose={() => {
onCancel && onCancel()
onCancel?.()

Check warning on line 63 in src/packages/actionsheet/actionsheet.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/actionsheet/actionsheet.tsx#L63

Added line #L63 was not covered by tests
}}
closeable={position === 'top'}
closeIcon={<Close className={`${classPrefix}-close-icon`} />}
>
<div className={`${className}`} style={style}>
{title && (
<div className={`${classPrefix}-${position}-title`}>{title}</div>
)}
{options.length ? (
<div className={`${classPrefix}-list`}>
{options.map((item, index) => {
const statusClass = `${item.disabled ? `${classPrefix}-item-disabled` : ''} ${item.danger ? `${classPrefix}-item-danger` : ''}`
return (
<div
className={`${classPrefix}-item ${statusClass}`}
className={`${classPrefix}-item ${statusClass} ${index !== options.length - 1 ? `${classPrefix}-item-border` : ''}`}
key={index}
onClick={() => chooseItem(item, index)}
>
Expand Down
4 changes: 3 additions & 1 deletion src/packages/actionsheet/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Demo3 from './demos/taro/demo3'
import Demo4 from './demos/taro/demo4'
import Demo5 from './demos/taro/demo5'
import Demo6 from './demos/taro/demo6'
import Demo7 from './demos/taro/demo7'

const ActionSheetDemo = () => {
const [translated] = useTranslate({
Expand Down Expand Up @@ -45,8 +46,9 @@ const ActionSheetDemo = () => {
<Demo4 />
<View className="h2">{translated.c3a08065}</View>
<Demo5 />
<View className="h2">{translated.c3a08066}</View>
<Demo6 />
<View className="h2">{translated.c3a08066}</View>
<Demo7 />
</ScrollView>
</>
)
Expand Down
4 changes: 3 additions & 1 deletion src/packages/actionsheet/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Demo3 from './demos/h5/demo3'
import Demo4 from './demos/h5/demo4'
import Demo5 from './demos/h5/demo5'
import Demo6 from './demos/h5/demo6'
import Demo7 from './demos/h5/demo7'

const ActionSheetDemo = () => {
const [translated] = useTranslate({
Expand Down Expand Up @@ -41,8 +42,9 @@ const ActionSheetDemo = () => {
<Demo4 />
<h2>{translated.c3a08065}</h2>
<Demo5 />
<h2>{translated.c3a08066}</h2>
<Demo6 />
<h2>{translated.c3a08066}</h2>
<Demo7 />
</div>
</>
)
Expand Down
12 changes: 6 additions & 6 deletions src/packages/actionsheet/demos/h5/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useState } from 'react'
import { ActionSheet, Cell } from '@nutui/nutui-react'

const Demo1 = () => {
const Demo = () => {
const [val, setVal] = useState('')
const [isVisible, setIsVisible] = useState(false)
const options = [
{
name: '权限设置',
name: '分享给朋友',
},
{
name: '重命名',
name: '添加到收藏夹',
},
{
name: '删除',
name: '复制商品链接',
},
]

Expand All @@ -28,13 +28,13 @@ const Demo1 = () => {
<div style={{ marginInlineStart: '10px', color: '#999' }}>{val}</div>
</Cell>
<ActionSheet
title="标题"
visible={isVisible}
options={options}
onSelect={handleSelect}
onCancel={() => setIsVisible(false)}
cancelText="取消"
/>
</>
)
}
export default Demo1
export default Demo
21 changes: 10 additions & 11 deletions src/packages/actionsheet/demos/h5/demo2.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import React, { useState } from 'react'
import { ActionSheet, Cell } from '@nutui/nutui-react'

const Demo2 = () => {
const [isVisible, setIsVisible] = useState(false)
const Demo = () => {
const [val, setVal] = useState('')
const [isVisible, setIsVisible] = useState(false)
const options = [
{
name: '权限设置',
name: '分享给朋友',
},
{
name: '重命名',
},
{
name: '删除',
name: '添加到收藏夹',
},
]

const handleSelect = (item: any) => {
setVal(item.name)
setIsVisible(false)
}

return (
<>
<Cell onClick={() => setIsVisible(!isVisible)}>
<span>展示取消按钮</span>
<span>展示标题</span>
<div style={{ marginInlineStart: '10px', color: '#999' }}>{val}</div>
</Cell>

<ActionSheet
title="标题"
visible={isVisible}
cancelText="取消"
options={options}
onSelect={handleSelect}
onCancel={() => setIsVisible(false)}
cancelText="取消"
/>
</>
)
}
export default Demo2
export default Demo
19 changes: 7 additions & 12 deletions src/packages/actionsheet/demos/h5/demo3.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React, { useState } from 'react'
import { ActionSheet, Cell } from '@nutui/nutui-react'

const Demo3 = () => {
const Demo = () => {
const [isVisible, setIsVisible] = useState(false)
const [val, setVal] = useState('')
const options: Record<string, string>[] = [
const options = [
{
name: '权限设置',
name: '分享给朋友',
},
{
name: '重命名',
},
{
name: '删除',
description: '删除后无法恢复',
name: '添加到收藏夹',
},
]

Expand All @@ -25,19 +21,18 @@ const Demo3 = () => {
return (
<>
<Cell onClick={() => setIsVisible(!isVisible)}>
<span>展示描述信息</span>
<span>顶部弹出</span>
<div style={{ marginInlineStart: '10px', color: '#999' }}>{val}</div>
</Cell>
<ActionSheet
position="top"
visible={isVisible}
title="标题"
description="请选择操作动作"
cancelText="取消"
options={options}
onSelect={handleSelect}
onCancel={() => setIsVisible(false)}
/>
</>
)
}
export default Demo3
export default Demo
4 changes: 2 additions & 2 deletions src/packages/actionsheet/demos/h5/demo4.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'
import { ActionSheet, Cell } from '@nutui/nutui-react'

const Demo4 = () => {
const Demo = () => {
const [isVisible, setIsVisible] = useState(false)
const optionsThree: Record<string, string | boolean>[] = [
{
Expand Down Expand Up @@ -30,4 +30,4 @@ const Demo4 = () => {
</>
)
}
export default Demo4
export default Demo
Loading
Loading