From 3ad339565f0874c664d6b4c5c72fd1e1e4290148 Mon Sep 17 00:00:00 2001 From: nthoen Date: Fri, 16 Feb 2018 14:05:09 -0500 Subject: [PATCH] feat(pfBootstrapDatePicker): Initial Implementation --- Gruntfile.js | 5 + misc/ng-docs.css | 3 + .../bootstrap-datepicker.component.js | 38 ++++++ src/datepicker/datepicker.html | 14 ++ src/datepicker/datepicker.less | 120 ++++++++++++++++++ src/datepicker/datepicker.module.js | 9 ++ .../examples/bootstrap.datepicker.js | 50 ++++++++ src/patternfly.module.js | 1 + styles/angular-patternfly.less | 1 + test/datepicker/bootstrap-datepicker.spec.js | 78 ++++++++++++ 10 files changed, 319 insertions(+) create mode 100644 src/datepicker/bootstrap-datepicker.component.js create mode 100644 src/datepicker/datepicker.html create mode 100644 src/datepicker/datepicker.less create mode 100644 src/datepicker/datepicker.module.js create mode 100644 src/datepicker/examples/bootstrap.datepicker.js create mode 100644 test/datepicker/bootstrap-datepicker.spec.js diff --git a/Gruntfile.js b/Gruntfile.js index a164625fb..e2a380e4b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -453,6 +453,11 @@ module.exports = function (grunt) { cwd: 'src/', src: ['pagination/**/*.html'], dest: 'templates/pagination.js' + }, + 'patternfly.datepicker' : { + cwd: 'src/', + src: ['datepicker/**/*.html'], + dest: 'templates/datepicker.js' } }, // ng-annotate tries to make the code safe for minification automatically diff --git a/misc/ng-docs.css b/misc/ng-docs.css index 1053d7457..fd4378dcd 100644 --- a/misc/ng-docs.css +++ b/misc/ng-docs.css @@ -375,4 +375,7 @@ ul.events > li > h3 { background-color: #cc0000; } +.type-hint-date { + background:#582fc0; +} diff --git a/src/datepicker/bootstrap-datepicker.component.js b/src/datepicker/bootstrap-datepicker.component.js new file mode 100644 index 000000000..9134d5805 --- /dev/null +++ b/src/datepicker/bootstrap-datepicker.component.js @@ -0,0 +1,38 @@ +angular.module('patternfly.datepicker').component('pfBootstrapDatepicker', { + bindings: { + date: '<', + format: '@?', + dateOptions: ' + + + + +

diff --git a/src/datepicker/datepicker.less b/src/datepicker/datepicker.less new file mode 100644 index 000000000..41cf7c64f --- /dev/null +++ b/src/datepicker/datepicker.less @@ -0,0 +1,120 @@ +.uib-datepicker-popup { + padding: 4px; + + *:focus { + outline: none; + } + + button { + background: @color-pf-white; + border: none; + box-shadow: none; + } + + th { + height: 30px; + } + + .uib-title { + font-size: 14px; + font-weight: 500; + padding: 5px; + + strong { + font-weight: normal; + } + } + + .uib-left { + height: 30px; + + .glyphicon { + display: none; + } + + &::before { + content: "\00AB"; + } + } + + .uib-right { + height: 30px; + + .glyphicon { + display: none; + } + + &::before { + content: "\00BB"; + } + } + + .uib-day { + + button.btn.btn-default { + height: 30px; + width: 30px; + + &:hover { + background: @color-pf-blue-50; + } + + &.active { + background: @color-pf-blue-400; + border-color: @color-pf-blue-600; + color: @color-pf-white; + box-shadow: none; + padding: 0; + + .text-info { // this is today's date + color: @color-pf-white; + } + } + + &:not(.active){ + .text-info { // this is today's date + color: @color-pf-black-800; + background: @color-pf-gold-200; + height: 30px; + width: 30px; + padding: 7px; + display: inline-block; + margin: -1px -7px -2px -7px; + + &:hover { + background: @color-pf-blue-50; + } + } + } + } + + } + + .uib-button-bar { + padding: 0; + + .btn-group { + width: 100%; + + .uib-clear { + display: none; + } + + .uib-datepicker-current { + color: @color-pf-black; + width: 100%; + font-size: 14px; + font-weight: 500; + height: 30px; + + &:hover { + background: @color-pf-blue-50; + } + } + } + + .uib-close { + display: none; + } + } +} diff --git a/src/datepicker/datepicker.module.js b/src/datepicker/datepicker.module.js new file mode 100644 index 000000000..5acf23322 --- /dev/null +++ b/src/datepicker/datepicker.module.js @@ -0,0 +1,9 @@ +/** + * @name patternfly datepicker + * + * @description + * Datepicker module for patternfly. + * + */ +angular.module('patternfly.datepicker', ['ui.bootstrap']); + diff --git a/src/datepicker/examples/bootstrap.datepicker.js b/src/datepicker/examples/bootstrap.datepicker.js new file mode 100644 index 000000000..c5501167a --- /dev/null +++ b/src/datepicker/examples/bootstrap.datepicker.js @@ -0,0 +1,50 @@ +/** + * @ngdoc directive + * @name patternfly.datepicker.componenet:pfBootstrapDatepicker + * @element pf-bootstrap-datepicker + * + * @param {date} date Must be a Javascript Date - to be displayed in the input. Can be left empty. + * @param {string} format Optional date format for displayed dates ('MM/dd/yyyy' by default). + * @param {boolean} isOpen Optional boolean for determining whether or not to have the datepicker default to open (false by default). + * @param {string} popupPlacement Optional configuration string used to position the popup datepicker relative to the input element. See {@link https://angular-ui.github.io/bootstrap/#datepickerPopup Angular UI Datepicker Popup}. + * @param {object} dateOptions Optional uib-datepicker configuration object. See {@link https://angular-ui.github.io/bootstrap/#datepicker Angular UI Datepicker}. + * + * @description + * A wrapper for the Angular UI {@link http://angular-ui.github.io/bootstrap/#!#datepickerPopup datepicker}. + * + * @example + + + +
+ + + + +
+
+ + + angular.module('patternfly.datepicker').controller('DemoBootstrapDatepicker', function( $scope ) { + + // first datepicker + $scope.date = new Date("Jan 1, 2000"); + + // second datepicker + $scope.format1 = "MM/dd/yy"; + $scope.dateOptions = { + showWeeks : true + }; + $scope.isOpen = true; + $scope.popupPlacement = "bottom-left"; + }); + + +
+ */ diff --git a/src/patternfly.module.js b/src/patternfly.module.js index bc07448e3..ebc20f54a 100644 --- a/src/patternfly.module.js +++ b/src/patternfly.module.js @@ -7,6 +7,7 @@ angular.module('patternfly', [ 'patternfly.autofocus', 'patternfly.card', + 'patternfly.datepicker', 'patternfly.filters', 'patternfly.form', 'patternfly.modals', diff --git a/styles/angular-patternfly.less b/styles/angular-patternfly.less index b0908f0a3..443216afa 100644 --- a/styles/angular-patternfly.less +++ b/styles/angular-patternfly.less @@ -14,4 +14,5 @@ @import "../src/canvas-view/canvas/canvas.less"; @import "../src/canvas-view/canvas-editor/canvas-editor.less"; @import "../src/pagination/pagination.less"; +@import "../src/datepicker/datepicker.less"; diff --git a/test/datepicker/bootstrap-datepicker.spec.js b/test/datepicker/bootstrap-datepicker.spec.js new file mode 100644 index 000000000..1a77e098d --- /dev/null +++ b/test/datepicker/bootstrap-datepicker.spec.js @@ -0,0 +1,78 @@ +describe('Component: pfBootstrapDatepicker', function () { + var $scope; + var $compile; + var element; + + // load the controller's module + beforeEach(function () { + module('patternfly.datepicker', 'datepicker/datepicker.html'); + }); + + beforeEach(inject(function (_$compile_, _$rootScope_) { + $compile = _$compile_; + $scope = _$rootScope_; + })); + + var compileHTML = function (markup, scope) { + element = angular.element(markup); + $compile(element)(scope); + + scope.$digest(); + }; + + beforeEach(function () { + $scope.date = new Date("Jan 1, 2000"); + $scope.format = "MMM dd, yyyy"; + $scope.dateOptions = { + showWeeks : true + }; + + var htmlTmp = ''; + + compileHTML(htmlTmp, $scope); + }); + + it('should display the date in the correct format', function () { + var input = element.find('input.datepicker')[0]; + expect(input.value).toBe("Jan 01, 2000"); + }); + + it('should open datepicker when button clicked', function () { + var button = element.find('button.datepicker')[0], + datepicker; + + datepicker = element.find('ul.uib-datepicker-popup'); + expect(datepicker.length).toBe(0); + + eventFire(button, 'click'); + + datepicker = element.find('ul.uib-datepicker-popup'); + expect(datepicker.length).toBe(1); + }); + + it('should not display week numbers by default on datepicker', function () { + var button = element.find('button.datepicker')[0], + week; + + eventFire(button, 'click'); + week = $(element.find('.uib-weeks')[0]); + expect($("td", week).length).toBe(7); + + }); + + it('should display week numbers if dateOptions is modified', function () { + + // rebuild the element with the dateOptions included + var htmlTmp = ''; + compileHTML(htmlTmp, $scope); + + // check each uib-weeks row in the datepicker has the week number + the seven days + var button = element.find('button.datepicker')[0], + week; + eventFire(button, 'click'); + week = $(element.find('.uib-weeks')[0]); + expect($("td", week).length).toBe(8); + + }); + +});