Skip to content

Commit

Permalink
feat: use locale from vuetify as default
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Nov 28, 2024
1 parent bf9b78e commit 05b9e68
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@koumoul/vjsf",
"version": "3.3.4",
"version": "3.4.0",
"description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.",
"scripts": {
"test": "vitest",
Expand Down
6 changes: 4 additions & 2 deletions lib/src/composables/use-vjsf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDefaults } from 'vuetify'
import { useDefaults, useLocale } from 'vuetify'
import { StatefulLayout, produceCompileOptions } from '@json-layout/core'
import { inject, toRaw, shallowRef, computed, ref, watch, useSlots, getCurrentInstance } from 'vue'
import { useElementSize } from '@vueuse/core'
Expand Down Expand Up @@ -104,7 +104,9 @@ export const useVjsf = (schema, modelValue, options, nodeComponents, emit, compi
}
}

const fullOptions = computed(() => getFullOptions(options.value, form, width.value, defaults?.global, slots, { ...nodeComponents }, onDataUpdate, onStatefulLayoutUpdate, onAutofocus))
const locale = useLocale()

const fullOptions = computed(() => getFullOptions(options.value, form, width.value, locale.current.value, defaults?.global, slots, { ...nodeComponents }, onDataUpdate, onStatefulLayoutUpdate, onAutofocus))

// do not use a simple computed here as we want to prevent recompiling the layout when the options are the same
/** @type {import('vue').Ref<import('@json-layout/core').PartialCompileOptions>} */
Expand Down
4 changes: 3 additions & 1 deletion lib/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const defaultOptions = {
* @param {Partial<import("./types.js").VjsfOptions> | null} options
* @param {any} form
* @param {number} width
* @param {string} locale
* @param {Record<string, unknown> | undefined} globalDefaults
* @param {import("vue").Slots} slots
* @param {Record<string, import('vue').Component>} defaultNodeComponents
Expand All @@ -36,7 +37,7 @@ export const defaultOptions = {
* @param {(key: string) => void} onAutofocus
* @returns
*/
export const getFullOptions = (options, form, width, globalDefaults, slots, defaultNodeComponents, onData, onUpdate, onAutofocus) => {
export const getFullOptions = (options, form, width, locale, globalDefaults, slots, defaultNodeComponents, onData, onUpdate, onAutofocus) => {
const components = { ...options?.components }
const nodeComponents = { ...defaultNodeComponents, ...options?.nodeComponents }
if (options?.plugins) {
Expand All @@ -52,6 +53,7 @@ export const getFullOptions = (options, form, width, globalDefaults, slots, defa
...defaultOptions,
readOnly: !!(form && (form.isDisabled.value || form.isReadonly.value)),
density: /** @type {import("./types.js").VjsfOptions['density']} */(globalDefaults?.density),
locale,
...options,
onData,
onUpdate,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05b9e68

Please sign in to comment.