Skip to content

Commit

Permalink
refactor(form-item-gi): clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Sep 15, 2021
1 parent c11edb2 commit c1e2946
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/form/src/FormItemGridItem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { h, ref, defineComponent, getCurrentInstance } from 'vue'
import { h, ref, defineComponent } from 'vue'
import NGridItem, {
gridItemProps,
GridItemVNodeProps
gridItemPropKeys
} from '../../grid/src/GridItem'
import { keep, keysOf } from '../../_utils'
import type { ExtractPublicPropTypes } from '../../_utils'
Expand All @@ -22,7 +22,7 @@ export default defineComponent({
name: 'FormItemGridItem',
alias: ['FormItemGi'],
props: formItemGiProps,
setup (props) {
setup () {
const formItemInstRef = ref<FormItemInst | null>(null)
const validate: FormItemInst['validate'] = ((...args: any[]) => {
const { value } = formItemInstRef
Expand All @@ -42,10 +42,7 @@ export default defineComponent({
}
},
render () {
const self = getCurrentInstance()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const gridItemProps = self!.vnode.props as GridItemVNodeProps
return h(NGridItem, gridItemProps, {
return h(NGridItem, keep(this.$.vnode.props || {}, gridItemPropKeys), {
default: () => {
const itemProps = keep(this.$props, formItemPropKeys)
return h(
Expand Down
9 changes: 3 additions & 6 deletions src/grid/src/GridItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
h,
defineComponent,
CSSProperties,
inject,
renderSlot,
getCurrentInstance,
Expand All @@ -14,7 +13,7 @@ import type { ExtractPublicPropTypes } from '../../_utils'

export const defaultSpan = 1

export interface GridItemVNodeProps {
interface GridItemVNodeProps {
privateOffset?: number
privateSpan?: number
privateColStart?: number
Expand Down Expand Up @@ -50,7 +49,7 @@ export default defineComponent({
name: 'GridItem',
alias: ['Gi'],
props: gridItemProps,
setup (props) {
setup () {
const {
xGapRef,
itemStyleRef,
Expand Down Expand Up @@ -86,9 +85,7 @@ export default defineComponent({
},
render () {
return (
<div
style={[this.itemStyle, this.deriveStyle()] as unknown as CSSProperties}
>
<div style={[this.itemStyle as any, this.deriveStyle()]}>
{renderSlot(this.$slots, 'default', { overflow: this.overflow })}
</div>
)
Expand Down

0 comments on commit c1e2946

Please sign in to comment.