From 000494e0a480f55a7a20369dbdddb4d161988912 Mon Sep 17 00:00:00 2001 From: Dan Popescu Date: Tue, 22 Feb 2022 01:01:27 +0200 Subject: [PATCH] feat(QStep): simplify rules to apply *-color and *-icon props and document the rules #12547, #15259 --- docs/src/examples/QStepper/HeaderClass.vue | 26 ++- docs/src/pages/vue-components/stepper.md | 19 +- .../pages/components/stepper-icons-colors.vue | 204 ++++++++++++++++++ ui/src/components/stepper/QStep.json | 2 +- ui/src/components/stepper/StepHeader.js | 68 +++--- 5 files changed, 274 insertions(+), 45 deletions(-) create mode 100644 ui/dev/src/pages/components/stepper-icons-colors.vue diff --git a/docs/src/examples/QStepper/HeaderClass.vue b/docs/src/examples/QStepper/HeaderClass.vue index 838f2916d0cf..aa2d6b2e9a54 100644 --- a/docs/src/examples/QStepper/HeaderClass.vue +++ b/docs/src/examples/QStepper/HeaderClass.vue @@ -4,7 +4,7 @@ v-model="step" ref="stepper" color="primary" - header-class="text-bold" + header-class="stepper-example__header--emphasized" animated > For each ad campaign that you create, you can control how much you're willing to spend on clicks and conversions, which networks and geographical locations you want @@ -57,6 +58,29 @@ + + diff --git a/ui/src/components/stepper/QStep.json b/ui/src/components/stepper/QStep.json index 86249a859691..d32cf75997b8 100644 --- a/ui/src/components/stepper/QStep.json +++ b/ui/src/components/stepper/QStep.json @@ -40,7 +40,7 @@ "prefix": { "type": [ "String", "Number" ], - "desc": "Step's prefix (max 2 characters) which replaces the icon if step does not has error, is being edited or is marked as done", + "desc": "Step's prefix (max 2 characters) which replaces the icon if the step is not currently active and it isn't marked with error or as 'done', or if the specific icon for the state is 'none'", "examples": [ "1", "2", "A", "B" ], diff --git a/ui/src/components/stepper/StepHeader.js b/ui/src/components/stepper/StepHeader.js index f22c163628d4..3547d30b8a57 100644 --- a/ui/src/components/stepper/StepHeader.js +++ b/ui/src/components/stepper/StepHeader.js @@ -22,15 +22,15 @@ export default Vue.extend({ }, computed: { - isActive () { - return this.stepper.value === this.step.name - }, - isDisable () { const opt = this.step.disable return opt === true || opt === '' }, + isActive () { + return this.isDisable !== true && this.stepper.value === this.step.name + }, + isError () { const opt = this.step.error return opt === true || opt === '' @@ -38,7 +38,7 @@ export default Vue.extend({ isDone () { const opt = this.step.done - return this.isDisable === false && (opt === true || opt === '') + return opt === true || opt === '' }, headerNav () { @@ -52,58 +52,40 @@ export default Vue.extend({ }, hasPrefix () { - return this.step.prefix && - (this.isActive === false || this.stepper.activeIcon === 'none') && - (this.isError === false || this.stepper.errorIcon === 'none') && - (this.isDone === false || this.stepper.doneIcon === 'none') + return this.step.prefix && this.icon === void 0 }, icon () { - const defaultIcon = this.step.icon || this.stepper.inactiveIcon + let icon if (this.isActive === true) { - const icon = this.step.activeIcon || this.stepper.activeIcon - return icon === 'none' - ? defaultIcon - : icon || this.$q.iconSet.stepper.active + icon = this.__getProp('activeIcon', this.$q.iconSet.stepper.active) } - - if (this.isError === true) { - const icon = this.step.errorIcon || this.stepper.errorIcon - return icon === 'none' - ? defaultIcon - : icon || this.$q.iconSet.stepper.error + else if (this.isError === true) { + icon = this.__getProp('errorIcon', this.$q.iconSet.stepper.error) } - - if (this.isDisable === false && this.isDone === true) { - const icon = this.step.doneIcon || this.stepper.doneIcon - return icon === 'none' - ? defaultIcon - : icon || this.$q.iconSet.stepper.done + else if (this.isDone === true) { + icon = this.__getProp('doneIcon', this.$q.iconSet.stepper.done) + } + else { + icon = this.step.icon || this.stepper.inactiveIcon } - return defaultIcon + return icon === 'none' ? void 0 : icon }, color () { - const errorColor = this.isError === true - ? this.step.errorColor || this.stepper.errorColor - : void 0 + if (this.isError === true) { + return this.__getProp('errorColor') + } if (this.isActive === true) { - const color = this.step.activeColor || this.stepper.activeColor || this.step.color - return color !== void 0 - ? color - : errorColor - } - if (errorColor !== void 0) { - return errorColor - } - if (this.isDisable === false && this.isDone === true) { - return this.step.doneColor || this.stepper.doneColor || this.step.color || this.stepper.inactiveColor + return this.__getProp('activeColor') } - return this.step.color || this.stepper.inactiveColor + return this.isDisable === false && this.isDone === true + ? this.__getProp('doneColor') + : this.step.color || this.stepper.inactiveColor }, classes () { @@ -129,6 +111,10 @@ export default Vue.extend({ if (e.keyCode === 13 && this.isActive === false) { this.stepper.goTo(this.step.name) } + }, + + __getProp (prop, fallback) { + return this.step[prop] || this.stepper[prop] || fallback } },