From 82e31d4dcf2e84f07268b3ef9cb28833a18e639b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 4 Mar 2024 10:18:28 +0100 Subject: [PATCH] refs #6911 feat: setDefaults --- quasar.config.js | 3 ++- src/boot/setDefaults.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/boot/setDefaults.js diff --git a/quasar.config.js b/quasar.config.js index 755e96bd3..3e98e3618 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -29,7 +29,8 @@ module.exports = configure(function (/* ctx */) { // app boot file (/src/boot) // --> boot files are part of "main.js" // https://v2.quasar.dev/quasar-cli/boot-files - boot: ['i18n', 'axios', 'vnDate', 'validations'], + // + boot: ['i18n', 'axios', 'vnDate','quasar','setDefaults', 'validations'], // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css css: ['app.scss'], diff --git a/src/boot/setDefaults.js b/src/boot/setDefaults.js new file mode 100644 index 000000000..d54baa63e --- /dev/null +++ b/src/boot/setDefaults.js @@ -0,0 +1,41 @@ +import { QInput, QSelect } from "quasar"; +import { QTable} from "quasar"; +const setDefault = (component, key, value) => { + const prop = component.props[key]; + switch (typeof prop) { + case "object": + prop.default = value; + break; + case "function": + component.props[key] = { + type: prop, + default: value + }; + break; + case "undefined": + throw new Error("unknown prop: " + key); + default: + throw new Error("unhandled type: " + typeof prop); + } + }; + +QInput.props.outlined = { + type: QInput.props.outlined, + default: true +}; +QInput.props.dense = { + type: QInput.props.dense, + default: true +}; +QInput.props.stackLabel = { + type: QInput.props.stackLabel, + default: true +}; + +setDefault(QInput, "outlined", false); +setDefault(QTable, "gridHeader", true); +setDefault(QTable, "color", 'red-8'); +setDefault(QTable, "pagination", { rowsPerPage: 25 }); +setDefault(QTable, "rowKey", 'id'); +setDefault(QSelect,'optionValue','id'); +setDefault(QSelect,'optionLabel','name');