From c28a26800a8e2df407c2d2c8e73c68d027c07be9 Mon Sep 17 00:00:00 2001 From: JeremyWuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com> Date: Fri, 27 May 2022 17:33:19 +0800 Subject: [PATCH] refactor(components): [date-picker] basic cell (#7924) - Refactor `h` function to `jsx`. - Extract props out of `basic-cell-render` --- .../src/date-picker-com/basic-cell-render.ts | 46 ------------------- .../src/date-picker-com/basic-cell-render.tsx | 32 +++++++++++++ .../date-picker/src/props/basic-cell.ts | 12 +++++ 3 files changed, 44 insertions(+), 46 deletions(-) delete mode 100644 packages/components/date-picker/src/date-picker-com/basic-cell-render.ts create mode 100644 packages/components/date-picker/src/date-picker-com/basic-cell-render.tsx create mode 100644 packages/components/date-picker/src/props/basic-cell.ts diff --git a/packages/components/date-picker/src/date-picker-com/basic-cell-render.ts b/packages/components/date-picker/src/date-picker-com/basic-cell-render.ts deleted file mode 100644 index f495533fbf..0000000000 --- a/packages/components/date-picker/src/date-picker-com/basic-cell-render.ts +++ /dev/null @@ -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(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] - ), - ] - ) - } - }, -}) diff --git a/packages/components/date-picker/src/date-picker-com/basic-cell-render.tsx b/packages/components/date-picker/src/date-picker-com/basic-cell-render.tsx new file mode 100644 index 0000000000..c3f07a4c5d --- /dev/null +++ b/packages/components/date-picker/src/date-picker-com/basic-cell-render.tsx @@ -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 ( +
+ {cell?.text} +
+ ) + } + }, +}) diff --git a/packages/components/date-picker/src/props/basic-cell.ts b/packages/components/date-picker/src/props/basic-cell.ts new file mode 100644 index 0000000000..312fbd1cbe --- /dev/null +++ b/packages/components/date-picker/src/props/basic-cell.ts @@ -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(Object), + }, +} as const) + +export type BasicCellProps = ExtractPropTypes