Skip to content

Commit dfaff53

Browse files
authored
feat: ✨ grid-item添加hover-class (#994)
1 parent 0f693f9 commit dfaff53

6 files changed

Lines changed: 50 additions & 16 deletions

File tree

docs/component/grid.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
`icon``wd-icon` 标签中的 `name` 属性。
1010

1111
```html
12-
<wd-grid>
12+
<wd-grid clickable>
1313
<wd-grid-item icon="picture" text="文字" />
1414
<wd-grid-item icon="picture" text="文字" />
1515
<wd-grid-item icon="picture" text="文字" />
@@ -221,14 +221,15 @@
221221

222222
## Grid Attributes
223223

224-
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
225-
| --------- | ------------------------------ | ------- | ------ | ------- | -------- |
226-
| column | 列数 | number | - | - | - |
227-
| border | 是否显示边框 | boolean | - | false | - |
228-
| gutter | 格子之间的间距,默认单位为`px` | number | - | - | - |
229-
| square | 是否将格子固定为正方形 | boolean | - | false | - |
230-
| clickable | 是否开启格子点击反馈 | boolean | - | false | - |
231-
| bg-color | 背景颜色设置 | string | - | #ffffff | - |
224+
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
225+
| ----------- | ------------------------------ | ------- | ------ | ---------------------------- | ---------------- |
226+
| column | 列数 | number | - | - | - |
227+
| border | 是否显示边框 | boolean | - | false | - |
228+
| gutter | 格子之间的间距,默认单位为`px` | number | - | - | - |
229+
| square | 是否将格子固定为正方形 | boolean | - | false | - |
230+
| clickable | 是否开启格子点击反馈 | boolean | - | false | - |
231+
| bg-color | 背景颜色设置 | string | - | #ffffff | - |
232+
| hover-class | 指定grid-item按下去的样式类 | string | - | wd-grid-item__content--hover | $LOWEST_VERSION$ |
232233

233234
## GridItem Attributes
234235

@@ -246,12 +247,12 @@
246247
| use-icon-slot | 是否开启 `GridItem` icon 插槽 | boolean | - | false | - |
247248
| use-text-slot | 是否开启 `GridItem` text 内容插槽 | boolean | - | false | - |
248249
| icon-size | 图标大小 | string | - | 26px | - |
249-
| badge-props | 自定义徽标的属性,传入的对象会被透传给 [Badge 组件的 props](/component/badge#attributes) | BadgeProps | - | - | 0.1.50 |
250+
| badge-props | 自定义徽标的属性,传入的对象会被透传给 [Badge 组件的 props](/component/badge#attributes) | BadgeProps | - | - | 0.1.50 |
250251

251252
## GridItem Events
252253

253-
| 方法名 | 说明 | 参数 | 返回值 | 最低版本 |
254-
| -------------- | -------------- | ----- | ------ | -------- |
254+
| 方法名 | 说明 | 参数 | 返回值 | 最低版本 |
255+
| --------- | -------------- | ----- | ------ | -------- |
255256
| itemclick | 点击(跳转)事件 | event | - | - |
256257

257258
## Grid Slot

src/pages/grid/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<wd-toast />
55
<view class="grid">
66
<demo-block title="基本用法" transparent>
7-
<wd-grid>
7+
<wd-grid clickable>
88
<wd-grid-item icon="picture" text="文字" />
99
<wd-grid-item icon="picture" text="文字" />
1010
<wd-grid-item icon="picture" text="文字" />

src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ $-grid-item-fs: var(--wot-grid-item-fs, 12px) !default; // 字号
684684
$-grid-item-bg: var(--wot-grid-item-bg, $-color-white) !default; // 字号
685685
$-grid-item-padding: var(--wot-grid-item-padding, 14px 0px) !default; // 内容的 padding
686686
$-grid-item-border-color: var(--wot-grid-item-border-color, $-color-border-light) !default; // 边框颜色
687+
$-grid-item-hover-bg: var(--wot-grid-item-hover-bg, $-color-gray-3) !default; // hover背景色
688+
$-grid-item-hover-bg-dark: var(--wot-grid-item-hover-bg-dark, $-color-gray-7) !default; // 暗黑模式hover背景色
687689

688690
/* statustip */
689691
$-statustip-fs: var(--wot-statustip-fs, $-fs-content) !default; // 字号

src/uni_modules/wot-design-uni/components/wd-grid-item/index.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
@include e(content) {
2525
background-color: $-dark-background2;
26+
27+
@include m(hover) {
28+
background-color: $-grid-item-hover-bg-dark !important;
29+
}
2630
}
2731
}
2832
}
@@ -129,6 +133,10 @@
129133
box-sizing: border-box;
130134
}
131135
}
136+
137+
@include m(hover) {
138+
background-color: $-grid-item-hover-bg !important;
139+
}
132140
}
133141

134142
@include e(text) {

src/uni_modules/wot-design-uni/components/wd-grid-item/wd-grid-item.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<view :class="`wd-grid-item ${border && !gutter ? itemClass : ''} ${customClass}`" @click="click" :style="`${style};${customStyle}`">
3-
<view :class="`wd-grid-item__content ${square ? 'is-square' : ''} ${border && gutter > 0 ? 'is-round' : ''}`" :style="gutterContentStyle">
3+
<view
4+
:class="`wd-grid-item__content ${square ? 'is-square' : ''} ${border && gutter > 0 ? 'is-round' : ''}`"
5+
:style="gutterContentStyle"
6+
:hover-class="hoverClass"
7+
>
48
<slot v-if="useSlot" />
59
<block v-else>
610
<view :style="'width:' + iconSize + '; height: ' + iconSize" class="wd-grid-item__wrapper">
@@ -154,6 +158,13 @@ function setiIemClass(classes: string) {
154158
itemClass.value = classes
155159
}
156160
161+
const hoverClass = computed(() => {
162+
if (grid?.props.clickable) {
163+
return grid.props.hoverClass ? grid.props.hoverClass : 'wd-grid-item__content--hover'
164+
}
165+
return 'none'
166+
})
167+
157168
defineExpose({
158169
setiIemClass,
159170
itemClass,

src/uni_modules/wot-design-uni/components/wd-grid/types.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ import { type ExtractPropTypes, type InjectionKey } from 'vue'
1111
import { baseProps, makeBooleanProp, makeStringProp } from '../common/props'
1212

1313
export type GridProvide = {
14-
props: { clickable?: boolean; square?: boolean; column?: number; border?: boolean; bgColor?: string; gutter?: number }
14+
props: {
15+
clickable?: boolean
16+
square?: boolean
17+
column?: number
18+
border?: boolean
19+
bgColor?: string
20+
gutter?: number
21+
hoverClass?: string
22+
}
1523
}
1624

1725
export const GRID_KEY: InjectionKey<GridProvide> = Symbol('wd-grid')
@@ -41,7 +49,11 @@ export const gridProps = {
4149
/**
4250
* 格子之间的间距,默认单位为px
4351
*/
44-
gutter: Number
52+
gutter: Number,
53+
/**
54+
* 自定义内容区域hover-class
55+
*/
56+
hoverClass: String
4557
}
4658

4759
export type GridProps = ExtractPropTypes<typeof gridProps>

0 commit comments

Comments
 (0)