Skip to content

Commit

Permalink
Merge branch 'element-plus:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
JauSingSing committed Apr 7, 2024
2 parents f740ad8 + 111086c commit 9558010
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/en-US/guide/i18n.md
Expand Up @@ -14,7 +14,7 @@ Element Plus provides global configurations

```typescript
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

app.use(ElementPlus, {
locale: zhCn,
Expand All @@ -37,7 +37,7 @@ for globally configuring locale and other settings.
import { defineComponent } from 'vue'
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
export default defineComponent({
components: {
Expand Down
28 changes: 15 additions & 13 deletions packages/components/button/src/button.vue
Expand Up @@ -3,19 +3,7 @@
:is="tag"
ref="_ref"
v-bind="_props"
:class="[
ns.b(),
ns.m(_type),
ns.m(_size),
ns.is('disabled', _disabled),
ns.is('loading', loading),
ns.is('plain', plain),
ns.is('round', round),
ns.is('circle', circle),
ns.is('text', text),
ns.is('link', link),
ns.is('has-bg', bg),
]"
:class="buttonKls"
:style="buttonStyle"
@click="handleClick"
>
Expand All @@ -39,6 +27,7 @@
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { ElIcon } from '@element-plus/components/icon'
import { useNamespace } from '@element-plus/hooks'
import { useButton } from './use-button'
Expand All @@ -56,6 +45,19 @@ const buttonStyle = useButtonCustomStyle(props)
const ns = useNamespace('button')
const { _ref, _size, _type, _disabled, _props, shouldAddSpace, handleClick } =
useButton(props, emit)
const buttonKls = computed(() => [
ns.b(),
ns.m(_type.value),
ns.m(_size.value),
ns.is('disabled', _disabled.value),
ns.is('loading', props.loading),
ns.is('plain', props.plain),
ns.is('round', props.round),
ns.is('circle', props.circle),
ns.is('text', props.text),
ns.is('link', props.link),
ns.is('has-bg', props.bg),
])
defineExpose({
/** @description button html element */
Expand Down
30 changes: 25 additions & 5 deletions packages/components/table-v2/src/composables/use-row.ts
Expand Up @@ -3,7 +3,7 @@ import { debounce } from 'lodash-unified'
import { isNumber } from '@element-plus/utils'
import { FixedDir } from '../constants'

import type { Ref } from 'vue'
import type { ComponentInternalInstance, Ref, ShallowRef } from 'vue'
import type { TableV2Props } from '../table'
import type {
RowExpandParams,
Expand All @@ -13,6 +13,7 @@ import type {
import type { FixedDirection, KeyType } from '../types'
import type { onRowRenderedParams } from '../grid'
import type { TableGridInstance } from '../table-grid'
import type { UseNamespaceReturn } from '@element-plus/hooks'

type Heights = Record<KeyType, number>
type GridInstanceRef = Ref<TableGridInstance | undefined>
Expand All @@ -21,16 +22,25 @@ type UseRowProps = {
mainTableRef: GridInstanceRef
leftTableRef: GridInstanceRef
rightTableRef: GridInstanceRef
tableInstance: ComponentInternalInstance
ns: UseNamespaceReturn
isScrolling: ShallowRef<boolean>
}

export const useRow = (
props: TableV2Props,
{ mainTableRef, leftTableRef, rightTableRef }: UseRowProps
{
mainTableRef,
leftTableRef,
rightTableRef,
tableInstance,
ns,
isScrolling,
}: UseRowProps
) => {
const vm = getCurrentInstance()!
const { emit } = vm
const isResetting = shallowRef(false)
const hoveringRowKey = shallowRef<KeyType | null>(null)
const expandedRowKeys = ref<KeyType[]>(props.defaultExpandedRowKeys || [])
const lastRenderedRowIndex = ref(-1)
const resetIndex = shallowRef<number | null>(null)
Expand All @@ -50,7 +60,18 @@ export const useRow = (
}

function onRowHovered({ hovered, rowKey }: RowHoverParams) {
hoveringRowKey.value = hovered ? rowKey : null
if (isScrolling.value) {
return
}
const tableRoot = tableInstance!.vnode.el as HTMLElement
const rows = tableRoot.querySelectorAll(`[rowkey=${rowKey as string}]`)
rows.forEach((row) => {
if (hovered) {
row.classList.add(ns.is('hovered'))
} else {
row.classList.remove(ns.is('hovered'))
}
})
}

function onRowExpanded({
Expand Down Expand Up @@ -141,7 +162,6 @@ export const useRow = (
}

return {
hoveringRowKey,
expandedRowKeys,
lastRenderedRowIndex,
isDynamic,
Expand Down
38 changes: 33 additions & 5 deletions packages/components/table-v2/src/renderers/row.tsx
@@ -1,7 +1,11 @@
import { Row } from '../components'
import { tryCall } from '../utils'

import type { FunctionalComponent, UnwrapNestedRefs } from 'vue'
import type {
ComponentInternalInstance,
FunctionalComponent,
UnwrapNestedRefs,
} from 'vue'
import type { UseNamespaceReturn } from '@element-plus/hooks'
import type { UseTableReturn } from '../use-table'
import type { TableV2Props } from '../table'
Expand All @@ -23,13 +27,13 @@ type RowRendererProps = TableGridRowSlotParams &
| 'depthMap'
| 'expandedRowKeys'
| 'hasFixedColumns'
| 'hoveringRowKey'
| 'onRowHovered'
| 'onRowExpanded'
| 'columnsStyles'
>
> & {
ns: UseNamespaceReturn
tableInstance: null | ComponentInternalInstance
}

const RowRenderer: FunctionalComponent<RowRendererProps> = (
Expand All @@ -44,7 +48,6 @@ const RowRenderer: FunctionalComponent<RowRendererProps> = (
expandedRowKeys,
estimatedRowHeight,
hasFixedColumns,
hoveringRowKey,
rowData,
rowIndex,
style,
Expand Down Expand Up @@ -74,7 +77,6 @@ const RowRenderer: FunctionalComponent<RowRendererProps> = (
{
[ns.e(`row-depth-${depth}`)]: canExpand && rowIndex >= 0,
[ns.is('expanded')]: canExpand && expandedRowKeys.includes(_rowKey),
[ns.is('hovered')]: !isScrolling && _rowKey === hoveringRowKey,
[ns.is('fixed')]: !depth && isFixedRow,
[ns.is('customized')]: Boolean(slots.row),
},
Expand All @@ -98,8 +100,34 @@ const RowRenderer: FunctionalComponent<RowRendererProps> = (
style,
}

const handlerMosueEnter = (e: MouseEvent) => {
onRowHover?.({
hovered: true,
rowKey: _rowKey,
event: e,
rowData,
rowIndex,
})
}

const handlerMouseLeave = (e: MouseEvent) => {
onRowHover?.({
hovered: false,
rowKey: _rowKey,
event: e,
rowData,
rowIndex,
})
}

return (
<Row {..._rowProps} onRowHover={onRowHover} onRowExpand={onRowExpanded}>
<Row
{..._rowProps}
onRowExpand={onRowExpanded}
onMouseenter={handlerMosueEnter}
onMouseleave={handlerMouseLeave}
rowkey={_rowKey}
>
{slots}
</Row>
)
Expand Down
3 changes: 0 additions & 3 deletions packages/components/table-v2/src/table-v2.tsx
Expand Up @@ -45,7 +45,6 @@ const TableV2 = defineComponent({
depthMap,
expandedRowKeys,
hasFixedColumns,
hoveringRowKey,
mainTableRef,
leftTableRef,
rightTableRef,
Expand Down Expand Up @@ -104,7 +103,6 @@ const TableV2 = defineComponent({
provide(TableV2InjectionKey, {
ns,
isResetting,
hoveringRowKey,
isScrolling,
})

Expand Down Expand Up @@ -222,7 +220,6 @@ const TableV2 = defineComponent({
expandedRowKeys: unref(expandedRowKeys),
estimatedRowHeight,
hasFixedColumns: unref(hasFixedColumns),
hoveringRowKey: unref(hoveringRowKey),
rowProps,
rowClass,
rowKey,
Expand Down
2 changes: 0 additions & 2 deletions packages/components/table-v2/src/tokens.ts
@@ -1,10 +1,8 @@
import type { InjectionKey, Ref } from 'vue'
import type { UseNamespaceReturn } from '@element-plus/hooks'
import type { KeyType } from './types'

export type TableV2Context = {
isScrolling: Ref<boolean>
hoveringRowKey: Ref<null | KeyType>
isResetting: Ref<boolean>
ns: UseNamespaceReturn
}
Expand Down
25 changes: 19 additions & 6 deletions packages/components/table-v2/src/use-table.ts
@@ -1,5 +1,14 @@
import { computed, ref, shallowRef, toRef, unref, watch } from 'vue'
import {
computed,
getCurrentInstance,
ref,
shallowRef,
toRef,
unref,
watch,
} from 'vue'
import { isArray } from '@element-plus/utils'
import { useNamespace } from '@element-plus/hooks'
import {
useColumns,
useData,
Expand Down Expand Up @@ -43,14 +52,18 @@ function useTable(props: TableV2Props) {
onMaybeEndReached,
})

const ns = useNamespace('table-v2')
const instance = getCurrentInstance()!

// state
const isScrolling = shallowRef(false)

const {
expandedRowKeys,
hoveringRowKey,
lastRenderedRowIndex,
isDynamic,
isResetting,
rowHeights,

resetAfterIndex,
onRowExpanded,
onRowHeightChange,
Expand All @@ -60,6 +73,9 @@ function useTable(props: TableV2Props) {
mainTableRef,
leftTableRef,
rightTableRef,
tableInstance: instance,
ns,
isScrolling,
})

const { data, depthMap } = useData(props, {
Expand Down Expand Up @@ -87,8 +103,6 @@ function useTable(props: TableV2Props) {
fixedColumnsOnLeft,
fixedColumnsOnRight,
})
// state
const isScrolling = shallowRef(false)

// DOM/Component refs
const containerRef = ref()
Expand Down Expand Up @@ -152,7 +166,6 @@ function useTable(props: TableV2Props) {
isDynamic,
isResetting,
isScrolling,
hoveringRowKey,
hasFixedColumns,
// records
columnsStyles,
Expand Down

0 comments on commit 9558010

Please sign in to comment.