Skip to content

Commit

Permalink
Enhancements to support Bootstrap v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 22, 2021
1 parent 9825762 commit b0740f7
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log: `yii2-widget-datepicker`
====================================

## Version 1.4.8

**Date:** 22-Oct-2021

- Enhancements to support Bootstrap v5.x.

## Version 1.4.7

**Date:** 09-Oct-2018
Expand Down
19 changes: 10 additions & 9 deletions src/DatePicker.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*/

namespace kartik\date;
Expand Down Expand Up @@ -235,7 +235,7 @@ public function run()
*/
protected function initIcon($type, $bs3Icon, $bs4Icon)
{
$css = $this->isBs4() ? "fas fa-{$bs4Icon}" : "glyphicon glyphicon-{$bs3Icon}";
$css = !$this->isBs(3) ? "fas fa-{$bs4Icon}" : "glyphicon glyphicon-{$bs3Icon}";
$icon = $type . 'Icon';
if (!isset($this->$icon)) {
$this->$icon = Html::tag('i', '', ['class' => $css . ' kv-dp-icon']);
Expand Down Expand Up @@ -364,7 +364,7 @@ protected function renderAddon(&$options, $type = 'picker')
if (is_string($options)) {
return $options;
}
$css = $this->isBs4() ? 'input-group-text' : 'input-group-addon';
$css = !$this->isBs(3) ? 'input-group-text' : 'input-group-addon';
Html::addCssClass($options, [$css, "kv-date-{$type}"]);
$iconType = "{$type}Icon";
$icon = ArrayHelper::remove($options, 'label', $this->$iconType);
Expand All @@ -386,7 +386,8 @@ protected function parseMarkup($input)
{
$disabled = $this->disabled ? 'disabled' : '';
$size = isset($this->size) ? "input-{$this->size}" : '';
$isBs4 = $this->isBs4();
$notBs3 = !$this->isBs(3);
$isBs5 = $this->isBs(5);
switch ($this->type) {
case self::TYPE_INPUT:
Html::addCssClass($this->options, [$size, $disabled]);
Expand All @@ -397,7 +398,7 @@ protected function parseMarkup($input)
Html::addCssClass($this->_container, ['input-group', $size, 'date']);
$picker = $this->renderAddon($this->pickerButton);
$remove = $this->renderAddon($this->removeButton, 'remove');
if ($isBs4) {
if ($notBs3 && !$isBs5) {
$css = $this->type === self::TYPE_COMPONENT_APPEND ? 'append' : 'prepend';
$options = ['class' => 'input-group-' . $css];
$picker = Html::tag('div', $picker, $options);
Expand All @@ -416,7 +417,7 @@ protected function parseMarkup($input)
$this->buttonOptions['disabled'] = $this->disabled;
}
if (empty($this->buttonOptions['class'])) {
$this->buttonOptions['class'] = 'btn btn-' . ($isBs4 ? 'secondary' : 'default');
$this->buttonOptions['class'] = 'btn btn-' . ($notBs3 ? 'secondary' : 'default');
}
$button = Html::button($label, $this->buttonOptions);
Html::addCssStyle($this->_container, 'display:block');
Expand Down Expand Up @@ -446,9 +447,9 @@ protected function parseMarkup($input)
Html::activeTextInput($this->model, $this->attribute2, $this->options2) :
Html::textInput($this->name2, $this->value2, $this->options2);
}
$css = $isBs4 ? 'input-group-text' : 'input-group-addon';
$css = $notBs3 ? 'input-group-text' : 'input-group-addon';
$sep = Html::tag('span', $this->separator, ['class' => $css . ' kv-field-separator']);
if ($isBs4) {
if ($notBs3 && !$isBs5) {
$sep = Html::tag('div', $sep, ['class' => 'input-group-append']);
}
$out = strtr($this->layout, [
Expand Down
6 changes: 3 additions & 3 deletions src/DatePickerAsset.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*/

namespace kartik\date;
Expand All @@ -25,7 +25,7 @@ class DatePickerAsset extends AssetBundle
public function init()
{
$this->setSourcePath(__DIR__ . '/assets');
$bsCss = 'bootstrap-datepicker' . ($this->isBs4() ? '4' : '3');
$bsCss = 'bootstrap-datepicker' . ($this->isBs(3) ? '3' : '4');
$this->setupAssets('css', ['css/' . $bsCss, 'css/datepicker-kv']);
$this->setupAssets('js', ['js/bootstrap-datepicker', 'js/datepicker-kv']);
parent::init();
Expand Down
1 change: 0 additions & 1 deletion src/assets/css/bootstrap-datepicker3.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* Licensed under the Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

.datepicker {
border-radius: 4px;
direction: ltr;
Expand Down
5 changes: 2 additions & 3 deletions src/assets/css/bootstrap-datepicker4.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*
* Bootstrap 4.x styling for bootstrap-datepicker
*
* Author: Kartik Visweswaran
* For more Yii related demos visit http://demos.krajee.com
*/

.datepicker {
border-radius: 0.25rem;
direction: ltr;
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/bootstrap-datepicker4.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/css/datepicker-kv.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*
* Custom styling for Datepicker
* Built for Yii Framework 2.0
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/datepicker-kv.min.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*
* Custom styling for Datepicker
* Built for Yii Framework 2.0
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/datepicker-kv.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*
* Extension to bootstrap datepicker to use noconflict approach
* so that the plugin does not conflict with other jquery plugins
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/datepicker-kv.min.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.7
* @version 1.4.8
*
* Extension to bootstrap datepicker to use noconflict approach
* so that the plugin does not conflict with other jquery plugins
Expand Down

0 comments on commit b0740f7

Please sign in to comment.