Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vuetify-nuxt-module/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LocaleOptions, RtlOptions, VuetifyOptions } from 'vuetify'

export type DateAdapter = 'vuetify' | 'date-fns' | 'moment' | 'luxon' | 'dayjs' | 'js-joda' | 'date-fns-jalali' | 'jalaali' | 'hijri' | 'custom'
export type DateAdapter = 'vuetify' | 'string' | 'date-fns' | 'moment' | 'luxon' | 'dayjs' | 'js-joda' | 'date-fns-jalali' | 'jalaali' | 'hijri' | 'custom'

/**
* Date configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function dateConfiguration() {
`
}

if (ctx.dateAdapter === 'string' && !ctx.vuetifyGte('3.9.0')) {
throw new Error('[vuetify-nuxt-module] The "string" date adapter requires Vuetify 3.9.0 or newer.')
}

const { adapter: _adapter, ...newDateOptions } = ctx.vuetifyOptions.date ?? {}

let dateFnsLocale: string | undefined
Expand Down Expand Up @@ -71,6 +75,10 @@ export function dateConfiguration() {
return `options.adapter = new Adapter({ locale: ${dateFnsLocale} })`
}

if (ctx.dateAdapter === 'string') {
return 'options.adapter = StringDateAdapter'
}

return 'options.adapter = Adapter'
}

Expand All @@ -83,6 +91,10 @@ export function dateConfiguration() {
return 'import { VuetifyDateAdapter } from \'vuetify/labs/date/adapters/vuetify\''
}

if (ctx.dateAdapter === 'string') {
return 'import { StringDateAdapter } from \'vuetify/date/adapters/string\''
}

const imports = [`import Adapter from '@date-io/${ctx.dateAdapter}'`]
if (ctx.dateAdapter === 'date-fns') {
imports.push(`import { ${dateFnsLocale} } from 'date-fns/locale'`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,25 @@ describe('vuetifyDateConfigurationPlugin date-fns locale', () => {
expect(ctx.logger.warn).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('(unset)'))
})
})

describe('vuetifyDateConfigurationPlugin string adapter', () => {
it('imports and configures Vuetify StringDateAdapter', async () => {
const ctx = makeCtx('en')
ctx.dateAdapter = 'string'
ctx.vuetifyOptions.date.adapter = 'string'

const code = await loadModule(ctx)

expect(code).toContain('import { StringDateAdapter } from \'vuetify/date/adapters/string\'')
expect(code).toContain('options.adapter = StringDateAdapter')
})

it('rejects Vuetify versions without StringDateAdapter', async () => {
const ctx = makeCtx('en')
ctx.dateAdapter = 'string'
ctx.vuetifyOptions.date.adapter = 'string'
ctx.vuetifyGte = (version: string) => version !== '3.9.0'

await expect(loadModule(ctx)).rejects.toThrow('requires Vuetify 3.9.0 or newer')
})
})