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(cell): add clickable prop to support click style feedback #2527

Merged
merged 2 commits into from
Aug 27, 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
20 changes: 20 additions & 0 deletions src/packages/cell/cell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@
font-size: $cell-extra-font-size;
color: $cell-extra-color;
}
&:active::before {
opacity: 0.1;
}
&-clickable {
cursor: pointer;
&::before {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
height: 100%;
background-color: $black;
border: inherit;
border-color: $black;
border-radius: inherit;
transform: translate(-50%, -50%);
opacity: 0;
content: ' ';
}
}
}
5 changes: 4 additions & 1 deletion src/packages/cell/cell.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CellProps extends BasicComponent {
extra: ReactNode
radius: string | number
align: 'flex-start' | 'center' | 'flex-end'
clickable: boolean
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}

Expand All @@ -20,6 +21,7 @@ const defaultProps = {
extra: null,
radius: '6px',
align: 'flex-start',
clickable: false,
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {},
} as CellProps

Expand All @@ -39,6 +41,7 @@ export const Cell: FunctionComponent<
align,
className,
style,
clickable,
...rest
} = {
...defaultProps,
Expand All @@ -63,7 +66,7 @@ export const Cell: FunctionComponent<
}
return (
<div
className={classNames(classPrefix, className)}
className={`${classNames(classPrefix, className, clickable ? `${classPrefix}-clickable` : '')}`}
onClick={(event) => handleClick(event)}
style={baseStyle}
{...rest}
Expand Down
5 changes: 4 additions & 1 deletion src/packages/cell/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CellProps extends BasicComponent {
extra: ReactNode
radius: string | number
align: 'flex-start' | 'center' | 'flex-end'
clickable: boolean
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}

Expand All @@ -20,6 +21,7 @@ const defaultProps = {
extra: null,
radius: '6px',
align: 'flex-start',
clickable: false,
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {},
} as CellProps

Expand All @@ -31,6 +33,7 @@ export const Cell: FunctionComponent<
const ctx = useContext(CellGroupContext)
const {
children,
clickable,
onClick,
title,
description,
Expand Down Expand Up @@ -63,7 +66,7 @@ export const Cell: FunctionComponent<
}
return (
<div
className={classNames(classPrefix, className)}
className={`${classNames(classPrefix, className, clickable ? `${classPrefix}-clickable` : '')}`}
onClick={(event) => handleClick(event)}
style={baseStyle}
{...rest}
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/demos/h5/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Demo1 = () => {
<Cell title="我是标题" extra="描述文字" />
<Cell title="我是标题" description="我是描述" extra="描述文字" />
<Cell
clickable
title="点击测试"
onClick={(
event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Demo1 = () => {
<Cell title="我是标题" description="我是描述" extra="描述文字" />
<Cell
title="点击测试"
clickable
onClick={(
event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>
) => testClick(event)}
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The 'divider' property allows you to keep the lower edge from being displayed be
| extra | Extra | `ReactNode` | `-` |
| radius | Corner radius | `string` | `6px` |
| align | Alignment in the vertical direction | `flex-start` \| `center` \| `flex-end` | `flex-start` |
| clickable | click style feedback | `boolean` | `false` |
| onClick | Emitted when cell is clicked | `onClick: (event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void` | `false` |

## Theming
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import { Cell } from '@nutui/nutui-react'
| extra | 右侧描述 | `ReactNode` | `-` |
| radius | 圆角半径 | `string` | `6px` |
| align | 纵轴方向上的对齐方式 | `flex-start` \| `center` \| `flex-end` | `flex-start` |
| clickable | 点击的样式反馈 | `boolean` | `false` |
| onClick | 点击事件 | `onClick: (event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void` | `false` |

## 主题定制
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { Cell } from '@nutui/nutui-react-taro'
| extra | 右侧描述 | `ReactNode` | `-` |
| radius | 圆角半径 | `string` | `6px` |
| align | 纵轴方向上的对齐方式 | `flex-start` \| `center` \| `flex-end` | `flex-start` |
| clickable | 点击的样式反馈 | `boolean` | `false` |
| onClick | 点击事件 | `onClick: (event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void` | `false` |

## 主题定制
Expand Down
1 change: 1 addition & 0 deletions src/packages/cell/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import { Cell } from '@nutui/nutui-react'
| extra | 右側描述 | `ReactNode` | `-` |
| radius | 圓角半徑 | `string` | `6px` |
| align | 縱軸方向上的對齊方式 | `flex-start` \| `center` \| `flex-end` | `flex-start` |
| clickable | 點擊的樣式反饋 | `boolean` | `false` |
| onClick | 點擊事件 | `onClick: (event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void` | `false` |

## 主題定製
Expand Down
Loading