refactor(components): [date-picker] basic cell (#7924)

- Refactor `h` function to `jsx`.
- Extract props out of `basic-cell-render`
This commit is contained in:
JeremyWuuuuu 2022-05-27 17:33:19 +08:00 committed by GitHub
parent 8835ead864
commit c28a26800a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 46 deletions

View File

@ -1,46 +0,0 @@
import { defineComponent, h, inject } from 'vue'
import { buildProps, definePropType } from '@element-plus/utils'
import { ROOT_PICKER_INJECTION_KEY } from '@element-plus/tokens'
import { useNamespace } from '@element-plus/hooks'
import type { DateCell } from '../date-picker.type'
export default defineComponent({
name: 'ElDatePickerCell',
props: buildProps({
cell: {
type: definePropType<DateCell>(Object),
},
}),
setup(props) {
const ns = useNamespace('date-table-cell')
const picker = inject(ROOT_PICKER_INJECTION_KEY)!
return () => {
const cell = props.cell
if (picker.slots.default) {
const list = picker.slots.default(cell).filter((item) => {
return (
item.patchFlag !== -2 && item.type.toString() !== 'Symbol(Comment)'
)
})
if (list.length) {
return list
}
}
return h(
'div',
{
class: ns.b(),
},
[
h(
'span',
{
class: ns.e('text'),
},
[cell?.text]
),
]
)
}
},
})

View File

@ -0,0 +1,32 @@
import { defineComponent, inject } from 'vue'
import { ROOT_PICKER_INJECTION_KEY } from '@element-plus/tokens'
import { useNamespace } from '@element-plus/hooks'
import { basicCellProps } from '../props/basic-cell'
export default defineComponent({
name: 'ElDatePickerCell',
props: basicCellProps,
setup(props) {
const ns = useNamespace('date-table-cell')
const { slots } = inject(ROOT_PICKER_INJECTION_KEY)!
return () => {
const { cell } = props
if (slots.default) {
const list = slots.default(cell).filter((item) => {
return (
item.patchFlag !== -2 && item.type.toString() !== 'Symbol(Comment)'
)
})
if (list.length) {
return list
}
}
return (
<div class={ns.b()}>
<span class={ns.e('text')}>{cell?.text}</span>
</div>
)
}
},
})

View File

@ -0,0 +1,12 @@
import { buildProps, definePropType } from '@element-plus/utils'
import type { ExtractPropTypes } from 'vue'
import type { DateCell } from '../date-picker.type'
export const basicCellProps = buildProps({
cell: {
type: definePropType<DateCell>(Object),
},
} as const)
export type BasicCellProps = ExtractPropTypes<typeof basicCellProps>