Skip to content

Commit aa291fc

Browse files
Hiwsjacobmllr95
andauthored
feat(b-calendar): add nav-button-variant prop (closes #5702) (#5705)
* init * update package.json * Improve `navButtonVariant` prop handling Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
1 parent edc2d35 commit aa291fc

File tree

8 files changed

+79
-14
lines changed

8 files changed

+79
-14
lines changed

src/components/calendar/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,16 @@ default. To specify a different theme color to use for today's date, use the `to
200200

201201
To disable highlighting of today's date altogether, set the `no-highlight-today` prop.
202202

203+
The navigation buttons default to the `'secondary'` theme variant. You can change this via the
204+
`nav-button-variant` prop.
205+
203206
```html
204207
<template>
205-
<b-calendar selected-variant="success" today-variant="info"></b-calendar>
208+
<b-calendar
209+
selected-variant="success"
210+
today-variant="info"
211+
nav-button-variant="primary"
212+
></b-calendar>
206213
</template>
207214

208215
<!-- b-calendar-variants.vue -->

src/components/calendar/calendar.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,17 @@ export const BCalendar = Vue.extend({
123123
selectedVariant: {
124124
// Variant color to use for the selected date
125125
type: String,
126-
default: 'primary'
126+
default: getComponentConfig(NAME, 'selectedVariant')
127127
},
128128
todayVariant: {
129-
// Variant color to use for today's date (defaults to `variant`)
130-
type: String
131-
// default: null
129+
// Variant color to use for today's date (defaults to `selectedVariant`)
130+
type: String,
131+
default: getComponentConfig(NAME, 'todayVariant')
132+
},
133+
navButtonVariant: {
134+
// Variant color to use for the navigation buttons
135+
type: String,
136+
default: getComponentConfig(NAME, 'navButtonVariant')
132137
},
133138
noHighlightToday: {
134139
// Disable highlighting today's date
@@ -355,6 +360,9 @@ export const BCalendar = Vue.extend({
355360
computedTodayVariant() {
356361
return `btn-outline-${this.todayVariant || this.selectedVariant || 'primary'}`
357362
},
363+
computedNavButtonVariant() {
364+
return `btn-outline-${this.navButtonVariant || 'primary'}`
365+
},
358366
isRTL() {
359367
// `true` if the language requested is RTL
360368
const dir = toString(this.direction).toLowerCase()
@@ -889,8 +897,8 @@ export const BCalendar = Vue.extend({
889897
return h(
890898
'button',
891899
{
892-
staticClass: 'btn btn-sm btn-outline-secondary border-0 flex-fill',
893-
class: { disabled: btnDisabled },
900+
staticClass: 'btn btn-sm border-0 flex-fill',
901+
class: [this.computedNavButtonVariant, { disabled: btnDisabled }],
894902
attrs: {
895903
title: label || null,
896904
type: 'button',

src/components/calendar/calendar.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,22 @@ describe('calendar', () => {
339339

340340
wrapper.destroy()
341341
})
342+
343+
it('`nav-button-variant` changes nav button class', async () => {
344+
const wrapper = mount(BCalendar, {
345+
attachTo: createContainer(),
346+
propsData: {
347+
navButtonVariant: 'primary'
348+
}
349+
})
350+
351+
const nav = wrapper.find('.b-calendar-nav')
352+
const buttons = nav.findAll('button')
353+
expect(buttons.length).toBe(5)
354+
expect(buttons.at(0).classes()).toContain('btn-outline-primary')
355+
expect(buttons.at(1).classes()).toContain('btn-outline-primary')
356+
expect(buttons.at(2).classes()).toContain('btn-outline-primary')
357+
expect(buttons.at(3).classes()).toContain('btn-outline-primary')
358+
expect(buttons.at(4).classes()).toContain('btn-outline-primary')
359+
})
342360
})

src/components/calendar/package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@
3434
},
3535
{
3636
"prop": "selectedVariant",
37+
"settings": true,
3738
"description": "Theme color variant to use for the selected date button"
3839
},
3940
{
4041
"prop": "todayVariant",
41-
"description": "Theme color variant to use for highlighting todays date button. Defaults to the `variant` prop"
42+
"settings": true,
43+
"description": "Theme color variant to use for highlighting todays date button. Defaults to the `selectedVariant` prop"
44+
},
45+
{
46+
"prop": "navButtonVariant",
47+
"version": "2.17.0",
48+
"settings": true,
49+
"description": "Theme color variant to use for the navigation buttons"
4250
},
4351
{
4452
"prop": "noHighlightToday",

src/components/form-datepicker/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ default. To specify a different theme color to use for today's date, use the `to
219219

220220
To disable highlighting of today's date altogether, set the `no-highlight-today` prop.
221221

222+
The navigation buttons default to the `'secondary'` theme variant. You can change this via the
223+
`nav-button-variant` prop.
224+
222225
### Control sizing
223226

224227
Fancy a smaller or larger `<b-form-datepicker>` control? Set the `size` prop to `'sm'` for a smaller

src/components/form-datepicker/form-datepicker.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ const propsMixin = {
133133
selectedVariant: {
134134
// Variant color to use for the selected date
135135
type: String,
136-
default: 'primary'
136+
default: () => getConfigFallback('selectedVariant')
137137
},
138138
todayVariant: {
139-
// Variant color to use for today's date (defaults to `variant`)
140-
type: String
141-
// default: null
139+
// Variant color to use for today's date (defaults to `selectedVariant`)
140+
type: String,
141+
default: () => getConfigFallback('todayVariant')
142+
},
143+
navButtonVariant: {
144+
// Variant color to use for the navigation buttons
145+
type: String,
146+
default: () => getConfigFallback('navButtonVariant')
142147
},
143148
noHighlightToday: {
144149
// Disable highlighting today's date
@@ -325,6 +330,7 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
325330
dateDisabledFn: self.dateDisabledFn,
326331
selectedVariant: self.selectedVariant,
327332
todayVariant: self.todayVariant,
333+
navButtonVariant: self.navButtonVariant,
328334
dateInfoFn: self.dateInfoFn,
329335
hideHeader: self.hideHeader,
330336
showDecadeNav: self.showDecadeNav,

src/components/form-datepicker/package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@
4646
},
4747
{
4848
"prop": "selectedVariant",
49+
"settings": true,
4950
"description": "Theme color variant to use for the selected date button"
5051
},
5152
{
5253
"prop": "todayVariant",
53-
"description": "Theme color variant to use for highlighting todays date button. Defaults to the `variant` prop"
54+
"settings": true,
55+
"description": "Theme color variant to use for highlighting todays date button. Defaults to the `selectedVariant` prop"
56+
},
57+
{
58+
"prop": "navButtonVariant",
59+
"version": "2.17.0",
60+
"settings": true,
61+
"description": "Theme color variant to use for the navigation buttons"
5462
},
5563
{
5664
"prop": "noHighlightToday",

src/utils/config-defaults.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ export default deepFreeze({
6464
},
6565
BButtonClose: {
6666
content: '&times;',
67-
// `textVariant` is `null` to inherit the current text color
67+
// `textVariant` is `undefined` to inherit the current text color
6868
textVariant: undefined,
6969
ariaLabel: 'Close'
7070
},
7171
BCalendar: {
72+
selectedVariant: 'primary',
73+
// Defaults to `selectedVariant`
74+
todayVariant: undefined,
75+
navButtonVariant: 'secondary',
7276
// BFormDate will choose these first if not provided in BFormDate section
7377
labelPrevDecade: 'Previous decade',
7478
labelPrevYear: 'Previous year',
@@ -102,6 +106,9 @@ export default deepFreeze({
102106
},
103107
BFormDatepicker: {
104108
// BFormDatepicker will choose from BCalendar first if not provided here
109+
selectedVariant: undefined,
110+
todayVariant: undefined,
111+
navButtonVariant: undefined,
105112
labelPrevDecade: undefined,
106113
labelPrevYear: undefined,
107114
labelPrevMonth: undefined,

0 commit comments

Comments
 (0)