Skip to content

Commit

Permalink
✨(VDPickerCustomInput): Allows to use an icon slot
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieustan committed Nov 16, 2020
1 parent 8978544 commit 694f6b9
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/vue-datepicker.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-datepicker.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-datepicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-datepicker.umd.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions doc-src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="./favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<script defer src="https://use.fontawesome.com/releases/v5.15.1/js/solid.js" integrity="sha384-oKbh94nlFq571cjny1jaIBlQwzTJW4KYExGYjslYSoG/J/w68zUI+KHPRveXB6EY" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.15.1/js/fontawesome.js" integrity="sha384-v0OPwyxrMWxEgAVlmUqvjeEr48Eh/SOZ2DRtVYJCx1ZNDfWBfNMWUjwUwBCJgfO4" crossorigin="anonymous"></script>
<title>vue-datepicker</title>
</head>
<body>
Expand Down
5 changes: 5 additions & 0 deletions doc-src/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ export default {
Try to keep cursor on a day`,
filename: 'daySlot',
},
slotInputIcon: {
title: '# Custom input-icon slot',
description: `Allows to change icon appaearance`,
filename: 'slot-input-icon',
},
// -- Misc
birthdayPicker: {
title: 'Birthday picker',
Expand Down
15 changes: 15 additions & 0 deletions doc-src/src/examples/slot-input-icon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<VueDatePicker v-model="date">
<template #input-icon>
<i class="fa fa-calendar-week" />
</template>
</VueDatePicker>
</template>

<script>
export default {
data: () => ({
date: new Date(),
}),
};
</script>
31 changes: 22 additions & 9 deletions src/components/VDPicker/VDPickerCustomInput/VDPickerCustomInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ import colorable from '../../../mixins/colorable';
// Components
import VDIcon from '../../VDIcon';

export default {
// Helpers
import mixins from '../../../utils/mixins';

const baseMixins = mixins(
colorable,
);

export default baseMixins.extend({
name: 'VDPickerCustomInput',
mixins: [colorable],
inject: ['VDPicker'],
props: {
clearable: { type: Boolean },
closeOnClickOutside: { type: Boolean, default: true },
Expand Down Expand Up @@ -54,15 +61,21 @@ export default {
// Generate Template
// ------------------------------
genCalendarIcon () {
const icon = this.$createElement(VDIcon, {
props: {
disabled: this.disabled,
},
}, ['calendarAlt']);
let children = [];

if (this.VDPicker.$slots['input-icon']) {
children.push(this.VDPicker.$slots['input-icon']);
} else {
children.push(this.$createElement(VDIcon, {
props: {
disabled: this.disabled,
},
}, ['calendarAlt']));
}

const iconWrapper = this.$createElement('div', {
staticClass: 'vd-picker__input-icon__wrapper',
}, [icon]);
}, children);

return this.$createElement('div', {
staticClass: 'vd-picker__input-icon',
Expand Down Expand Up @@ -133,4 +146,4 @@ export default {
this.clearable && this.genClearIcon(),
]);
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pointer-events: none;

input,
.vd-icon.vd-icon--disabled {
.vd-picker__input-icon__wrapper {
opacity: .38;
}
}
Expand Down
28 changes: 27 additions & 1 deletion tests/unit/components/VDPicker/VDPickerCustomInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vue from 'vue';
import dayjs from 'dayjs';
import { mount } from '@vue/test-utils';
import VDPickerCustomInput from '@/components/VDPicker/VDPickerCustomInput';
Expand All @@ -6,12 +7,21 @@ jest.useFakeTimers();

describe('VDPickerCustomInput', () => {
let mountComponent;
let vm = new Vue();

const dummyDate = dayjs(new Date([2019, 5, 16]));
const defaultVDPickerProvider = { $scopedSlots: {}, $slots: {} };

beforeEach(() => {
mountComponent = ({ props = {} } = {}) =>
mountComponent = ({
props = {},
provide = {
VDPicker: defaultVDPickerProvider,
},
} = {}) =>
mount(VDPickerCustomInput, {
propsData: props,
provide,
});
});

Expand Down Expand Up @@ -101,5 +111,21 @@ describe('VDPickerCustomInput', () => {
expect(wrapper.emitted().clearDate).toBeTruthy();
});

it('should have an input-icon slot', () => {
const VDPickerProviderWithIcon = {
$scopedSlots: {},
$slots: {
'input-icon': vm.$createElement('div', { staticClass: 'icon-slot' }),
},
};
const wrapper = mountComponent({
provide: {
VDPicker: VDPickerProviderWithIcon,
},
});

expect(wrapper.find('.icon-slot').exists()).toBeTruthy();
});

});
});

0 comments on commit 694f6b9

Please sign in to comment.