Skip to content

Commit

Permalink
refactor(row): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Sep 21, 2024
1 parent 22824fa commit 8f89826
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
23 changes: 18 additions & 5 deletions packages/varlet-ui/src/col/Col.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ export default defineComponent({
setup(props) {
const span = computed(() => toNumber(props.span))
const offset = computed(() => toNumber(props.offset))
const { row } = useRow()
const padding = computed<ColPadding>(() => {
const [y = 0, x = 0] = row?.average?.value || []
const [y = 0, x = 0] = row?.average.value ?? []
return { left: x, right: x, top: y, bottom: y }
})
const { row, bindRow } = useRow()
call(bindRow, null)
function getSize(mode: string, size: string | number | ColSizeDescriptor | undefined) {
const classes: string[] = []
Expand All @@ -59,9 +62,19 @@ export default defineComponent({
if (isPlainObject(size)) {
const { offset, span } = size
if (Number(span) >= 0) classes.push(n(`--span-${mode}-${span}`))
if (offset) classes.push(n(`--offset-${mode}-${offset}`))
} else if (Number(size) >= 0) {
if (Number(span) >= 0) {
classes.push(n(`--span-${mode}-${span}`))
}
if (offset) {
classes.push(n(`--offset-${mode}-${offset}`))
}
return classes
}
if (Number(size) >= 0) {
classes.push(n(`--span-${mode}-${size}`))
}
Expand Down
6 changes: 3 additions & 3 deletions packages/varlet-ui/src/col/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export type ColSizeDescriptor = {
offset?: number | string
}

export type ColProvider = object

This comment has been minimized.

Copy link
@chenyulun

chenyulun Sep 23, 2024

Contributor

我当时没去掉这个,是因为packages/varlet-ui/src/row/provide.ts里面有导出,现在报错了

import { type ColProvider } from '../col/provide'

保持约定,补回去一个空的类型null?


export function useRow() {
const { parentProvider } = useParent<RowProvider, ColProvider>(ROW_BIND_COL_KEY)
const { index, bindParent, parentProvider } = useParent<RowProvider, null>(ROW_BIND_COL_KEY)

return {
index,
row: parentProvider,
bindRow: bindParent,
}
}
6 changes: 2 additions & 4 deletions packages/varlet-ui/src/row/Row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { defineComponent, computed } from 'vue'
import { props } from './props'
import { isArray, call } from '@varlet/shared'
import { useCols, type RowProvider } from './provide'
import { useCols } from './provide'
import { toPxNum, padStartFlex } from '../utils/elements'
import { createNamespace } from '../utils/components'
Expand All @@ -31,9 +31,7 @@ export default defineComponent({
)
const { bindCols } = useCols()
const rowProvider: RowProvider = { average }
bindCols(rowProvider)
bindCols({ average })
function handleClick(e: Event) {
call(props.onClick, e)
Expand Down
4 changes: 3 additions & 1 deletion packages/varlet-ui/src/row/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export interface RowProvider {
export const ROW_BIND_COL_KEY = Symbol('ROW_BIND_COL_KEY')

export function useCols() {
const { bindChildren } = useChildren<RowProvider, ColProvider>(ROW_BIND_COL_KEY)
const { length, childProviders: cols, bindChildren } = useChildren<RowProvider, ColProvider>(ROW_BIND_COL_KEY)

return {
length,
cols,
bindCols: bindChildren,
}
}

0 comments on commit 8f89826

Please sign in to comment.