mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 01:11:25 +08:00
refactor(components): [date-picker] basic cell (#7924)
- Refactor `h` function to `jsx`. - Extract props out of `basic-cell-render`
This commit is contained in:
parent
8835ead864
commit
c28a26800a
@ -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]
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
@ -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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
12
packages/components/date-picker/src/props/basic-cell.ts
Normal file
12
packages/components/date-picker/src/props/basic-cell.ts
Normal 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>
|
Loading…
Reference in New Issue
Block a user