From 565002bf78b0374b6b9f411df95d5e342f4ce626 Mon Sep 17 00:00:00 2001 From: BeADre Date: Mon, 22 Nov 2021 17:51:00 +0800 Subject: [PATCH] fix(date-picker): css specificity --- .../__snapshots__/index.spec.js.snap | 98 +++++++++---------- .../src/date-picker/date-picker.less | 10 +- .../src/date-picker/src/day-picker-panel.vue | 10 +- .../date-picker/src/month-picker-panel.vue | 10 +- .../src/date-picker/src/panel-header.vue | 23 +---- 5 files changed, 68 insertions(+), 83 deletions(-) diff --git a/packages/varlet-ui/src/date-picker/__tests__/__snapshots__/index.spec.js.snap b/packages/varlet-ui/src/date-picker/__tests__/__snapshots__/index.spec.js.snap index 8166253dfe2..8531fce6cc3 100644 --- a/packages/varlet-ui/src/date-picker/__tests__/__snapshots__/index.spec.js.snap +++ b/packages/varlet-ui/src/date-picker/__tests__/__snapshots__/index.spec.js.snap @@ -14,7 +14,7 @@ exports[`test allowedDates prop 1`] = `
-
@@ -22,7 +22,7 @@ exports[`test allowedDates prop 1`] = `
2021 三月
-
@@ -62,7 +62,7 @@ exports[`test datePicker style and type 1`] = `
-
@@ -70,58 +70,58 @@ exports[`test datePicker style and type 1`] = `
2021
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • @@ -148,7 +148,7 @@ exports[`test datePicker style and type 2`] = `
    -
    @@ -156,7 +156,7 @@ exports[`test datePicker style and type 2`] = `
    2021 五月
    -
    @@ -197,127 +197,127 @@ exports[`test datePicker style and type 2`] = `
    -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • -
  • diff --git a/packages/varlet-ui/src/date-picker/date-picker.less b/packages/varlet-ui/src/date-picker/date-picker.less index bbffb37dca1..c4544f16010 100644 --- a/packages/varlet-ui/src/date-picker/date-picker.less +++ b/packages/varlet-ui/src/date-picker/date-picker.less @@ -192,6 +192,10 @@ width: 100%; max-width: var(--month-picker-item-button-max-width); } + + &__button[var-date-picker-color-cover='true'] { + color: var(--date-picker-main-color); + } } .var-year-picker { @@ -250,10 +254,10 @@ height: var(--day-picker-content-item-button-height); font-size: var(--day-picker-content-item-button-font-size); } - } - &-main__color { - color: var(--date-picker-main-color); + &__button[var-date-picker-color-cover='true'] { + color: var(--date-picker-main-color); + } } &-translatey-enter-from { diff --git a/packages/varlet-ui/src/date-picker/src/day-picker-panel.vue b/packages/varlet-ui/src/date-picker/src/day-picker-panel.vue index 1b383c9c17d..cc99a142a54 100644 --- a/packages/varlet-ui/src/date-picker/src/day-picker-panel.vue +++ b/packages/varlet-ui/src/date-picker/src/day-picker-panel.vue @@ -227,22 +227,22 @@ export default defineComponent({ return true } - const textColorOrClass = (): string => { + const textColorOrCover = (): string => { if (disabled) return '' if (computeOutline()) return color ?? '' if (dayExist()) return '' - return 'var-date-picker-main__color' + return 'var-date-picker-color-cover' } - const isClass = textColorOrClass().startsWith('var-date-picker') + const isCover = textColorOrCover().startsWith('var-date-picker') return { disabled, text: computeText(), outline: computeOutline(), - textColor: isClass ? '' : textColorOrClass(), - class: isClass ? textColorOrClass() : '', + textColor: isCover ? '' : textColorOrCover(), + 'var-date-picker-color-cover': isCover, } } diff --git a/packages/varlet-ui/src/date-picker/src/month-picker-panel.vue b/packages/varlet-ui/src/date-picker/src/month-picker-panel.vue index 64009b0f31a..473773ae8c5 100644 --- a/packages/varlet-ui/src/date-picker/src/month-picker-panel.vue +++ b/packages/varlet-ui/src/date-picker/src/month-picker-panel.vue @@ -169,23 +169,23 @@ export default defineComponent({ return true } - const textColorOrClass = (): string => { + const textColorOrCover = (): string => { if (disabled) return '' if (computeOutline()) return color ?? '' if (monthExist()) return '' - return 'var-date-picker-main__color' + return 'var-date-picker-color-cover' } - const isClass = textColorOrClass().startsWith('var-date-picker') + const isCover = textColorOrCover().startsWith('var-date-picker') return { disabled, outline: computeOutline(), text: computeText(), color: !computeText() ? color : '', - textColor: isClass ? '' : textColorOrClass(), - class: isClass ? textColorOrClass() : '', + textColor: isCover ? '' : textColorOrCover(), + 'var-date-picker-color-cover': isCover, } } diff --git a/packages/varlet-ui/src/date-picker/src/panel-header.vue b/packages/varlet-ui/src/date-picker/src/panel-header.vue index 4735bbbfa44..a8cf31cb46a 100644 --- a/packages/varlet-ui/src/date-picker/src/panel-header.vue +++ b/packages/varlet-ui/src/date-picker/src/panel-header.vue @@ -1,13 +1,6 @@