Skip to content

Commit

Permalink
fix(VCol): fix BreakPoints type
Browse files Browse the repository at this point in the history
fix #16604
  • Loading branch information
yuwu9145 committed Mar 5, 2023
1 parent 6cc6070 commit d9631c6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
9 changes: 9 additions & 0 deletions packages/vuetify/dev/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { VCol } from 'vuetify/src/components/VGrid/VCol'
import { VRow } from 'vuetify/src/components/VGrid/VRow'

declare module 'vue' {
export interface GlobalComponents {
VCol: typeof VCol;
VRow: typeof VRow;
}
}
1 change: 1 addition & 0 deletions packages/vuetify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"dev": "cross-env NODE_ENV=development vite",
"dev:ssr": "cross-env NODE_ENV=development VITE_SSR=true vite-ssr",
"dev:prod": "concurrently \"cross-env NODE_ENV=production vite build -w\" \"vite preview\"",
"dev:typecheck": "vue-tsc --noEmit --skipLibCheck --project ./tsconfig.dev.json",
"build": "rimraf lib dist && concurrently \"yarn build:dist\" \"yarn build:lib\" -n \"dist,lib\" --kill-others-on-fail -r && yarn build:types",
"build:dist": "rollup --config build/rollup.config.js",
"build:lib": "cross-env NODE_ENV=lib babel src --out-dir lib --source-maps --extensions \".ts\",\".tsx\",\".snap\" --copy-files --no-copy-ignored --out-file-extension .mjs",
Expand Down
17 changes: 11 additions & 6 deletions packages/vuetify/src/components/VGrid/VCol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import './VGrid.sass'

// Composables
import { makeTagProps } from '@/composables/tag'
import { breakpoints } from '@/composables/breakpoint'

// Utilities
import { capitalize, computed, h } from 'vue'
import { genericComponent } from '@/util'

// Types
import type { Prop, PropType } from 'vue'
import type { BreakPoint } from '@/composables/breakpoint'

const breakpoints = ['sm', 'md', 'lg', 'xl', 'xxl'] as const // no xs
type BreakPointOffset = `offset${Capitalize<BreakPoint>}`
type BreakPointOrder = `order${Capitalize<BreakPoint>}`

const breakpointProps = (() => {
return breakpoints.reduce((props, val) => {
Expand All @@ -20,27 +23,29 @@ const breakpointProps = (() => {
default: false,
}
return props
}, {} as Record<string, Prop<boolean | string | number, false>>)
}, {} as Record<BreakPoint, Prop<boolean | string | number, false>>)
})()

const offsetProps = (() => {
return breakpoints.reduce((props, val) => {
props['offset' + capitalize(val)] = {
const offsetKey = ('offset' + capitalize(val)) as BreakPointOffset
props[offsetKey] = {
type: [String, Number],
default: null,
}
return props
}, {} as Record<string, Prop<string | number, null>>)
}, {} as Record<BreakPointOffset, Prop<string | number, null>>)
})()

const orderProps = (() => {
return breakpoints.reduce((props, val) => {
props['order' + capitalize(val)] = {
const orderKey = ('order' + capitalize(val)) as BreakPointOrder
props[orderKey] = {
type: [String, Number],
default: null,
}
return props
}, {} as Record<string, Prop<string | number, null>>)
}, {} as Record<BreakPointOrder, Prop<string | number, null>>)
})()

const propMap = {
Expand Down
32 changes: 21 additions & 11 deletions packages/vuetify/src/components/VGrid/VRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,57 @@ import './VGrid.sass'

// Composables
import { makeTagProps } from '@/composables/tag'
import { breakpoints } from '@/composables/breakpoint'

// Utilities
import { capitalize, computed, h } from 'vue'
import { genericComponent } from '@/util'

// Types
import type { Prop, PropType } from 'vue'

const breakpoints = ['sm', 'md', 'lg', 'xl', 'xxl'] as const // no xs
import type { BreakPoint } from '@/composables/breakpoint'

const ALIGNMENT = ['start', 'end', 'center'] as const

type BreakPointAlign = `align${Capitalize<BreakPoint>}`
type BreakPointJustify = `justify${Capitalize<BreakPoint>}`
type BreakPointAlignContent = `alignContent${Capitalize<BreakPoint>}`

const SPACE = ['space-between', 'space-around', 'space-evenly'] as const

function makeRowProps <T> (prefix: string, def: () => Prop<T, null>) {
function makeRowProps <
U extends BreakPointAlign | BreakPointJustify | BreakPointAlignContent, T
> (prefix: string, def: () => Prop<T, null>) {
return breakpoints.reduce((props, val) => {
props[prefix + capitalize(val)] = def()
const prefixKey = prefix + capitalize(val) as U
props[prefixKey] = def()
return props
}, {} as Record<string, Prop<T, null>>)
}, {} as Record<U, Prop<T, null>>)
}

const ALIGN_VALUES = [...ALIGNMENT, 'baseline', 'stretch'] as const
type AlignProp = typeof ALIGN_VALUES[number]
const alignValidator = (str: any) => ALIGN_VALUES.includes(str)
const alignProps = makeRowProps('align', () => ({
type: String as PropType<typeof ALIGN_VALUES[number]>,
const alignProps = makeRowProps<BreakPointAlign, AlignProp>('align', () => ({
type: String as PropType<AlignProp>,
default: null,
validator: alignValidator,
}))

const JUSTIFY_VALUES = [...ALIGNMENT, ...SPACE] as const
type JustifyProp = typeof JUSTIFY_VALUES[number]
const justifyValidator = (str: any) => JUSTIFY_VALUES.includes(str)
const justifyProps = makeRowProps('justify', () => ({
type: String as PropType<typeof JUSTIFY_VALUES[number]>,
const justifyProps = makeRowProps<BreakPointJustify, JustifyProp>('justify', () => ({
type: String as PropType<JustifyProp>,
default: null,
validator: justifyValidator,
}))

const ALIGN_CONTENT_VALUES = [...ALIGNMENT, ...SPACE, 'stretch'] as const
type AlignContentProp = typeof ALIGN_CONTENT_VALUES[number]
const alignContentValidator = (str: any) => ALIGN_CONTENT_VALUES.includes(str)
const alignContentProps = makeRowProps('alignContent', () => ({
type: String as PropType<typeof ALIGN_CONTENT_VALUES[number]>,
const alignContentProps = makeRowProps<BreakPointAlignContent, AlignContentProp>('alignContent', () => ({
type: String as PropType<AlignContentProp>,
default: null,
validator: alignContentValidator,
}))
Expand Down
3 changes: 3 additions & 0 deletions packages/vuetify/src/composables/breakpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const breakpoints = ['sm', 'md', 'lg', 'xl', 'xxl'] as const // no xs

export type BreakPoint = 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
8 changes: 7 additions & 1 deletion packages/vuetify/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"src",
"dev",
"cypress"
]
],
"compilerOptions": {
"allowJs": true
},
"vueCompilerOptions": {
"strictTemplates": true
}
}

0 comments on commit d9631c6

Please sign in to comment.