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 28, 2021
1 parent 27847bf commit 680aec2
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 25 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-timepicker`
====================================

## Version 1.0.5

**Date:** 28-Oct-2021

- Enhancements to support Bootstrap v5.x.

## Version 1.0.4

**Date:** 09-Oct-2018
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2018, Kartik Visweswaran
Copyright (c) 2014 - 2021, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
yii2-widget-timepicker
<hr>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DTP3NZQ6G2AYU"
title="Donate via Paypal" target="_blank">
<img src="http://kartik-v.github.io/bootstrap-fileinput-samples/samples/donate.png" alt="Donate"/>
</a>
title="Donate via Paypal" target="_blank"><img height="60" src="https://kartik-v.github.io/bootstrap-fileinput-samples/samples/donate.png" alt="Donate"/></a>
&nbsp; &nbsp; &nbsp;
<a href="https://www.buymeacoffee.com/kartikv" title="Buy me a coffee" ><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="60" alt="kartikv" /></a>
</h1>

<div align="center">

[![Stable Version](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/v/stable)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)
[![Untable Version](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/v/unstable)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)
[![License](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/license)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)
[![Total Downloads](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/downloads)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)
[![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/d/monthly)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)
[![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-widget-timepicker/d/daily)](https://packagist.org/packages/kartik-v/yii2-widget-timepicker)

</div>

The TimePicker widget allows you to easily select a time for a text input using your mouse or keyboards arrow keys. The widget is a wrapper enhancement of the <a href='https://github.com/rendom/bootstrap-3-timepicker' target='_blank'>TimePicker plugin</a> by rendom forked from <a href='https://github.com/jdewit/bootstrap-timepicker' target='_blank'>jdewit's TimePicker</a>. This widget as used here has been specially enhanced for Yii framework 2.0 and Bootstrap 3. With release v1.0.4, the extension has been enhanced to support Bootstrap 4.x version.

> NOTE: This extension is a sub repo split of [yii2-widgets](https://github.com/kartik-v/yii2-widgets). The split has been done since 08-Nov-2014 to allow developers to install this specific widget in isolation if needed. One can also use the extension the previous way with the whole suite of [yii2-widgets](http://demos.krajee.com/widgets).
Expand Down
32 changes: 17 additions & 15 deletions src/TimePicker.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-timepicker
* @version 1.0.4
* @version 1.0.5
*/

namespace kartik\time;
Expand Down Expand Up @@ -43,7 +43,7 @@ class TimePicker extends InputWidget
* - `buttonOptions`: _array_, HTML attributes if the addon is to be displayed like a button. If [[asButton]] is
* `true`, this will default to :
* - `['class' => 'btn btn-default']` for [[bsVersion]] = '3.x' or .
* - `['class' => 'btn btn-secondary']` for [[bsVersion]] = '4.x'
* - `['class' => 'btn btn-secondary']` for [[bsVersion]] = '4.x' and '5.x'
*/
public $addonOptions = [];

Expand Down Expand Up @@ -72,13 +72,13 @@ public function run()
/**
* Initializes icon for time units up and down buttons
* @param string $type whether 'up' or 'down'
* @throws InvalidConfigException
* @throws InvalidConfigException|\Exception
*/
protected function initIcon($type)
{
$prop = $type . 'ArrowStyle';
if (!isset($this->pluginOptions[$prop])) {
$prefix = $this->isBs4() ? 'fas fa-' : 'glyphicon glyphicon-';
$prefix = !$this->isBs(3) ? 'fas fa-' : 'glyphicon glyphicon-';
$this->pluginOptions[$prop] = $prefix . 'chevron-' . $type;
}
}
Expand All @@ -87,23 +87,24 @@ protected function initIcon($type)
* Renders the input
*
* @return string
* @throws InvalidConfigException
* @throws InvalidConfigException|\Exception
*/
protected function renderInput()
{
$isBs4 = $this->isBs4();
$notBs3 = !$this->isBs(3);
$isBs5 = $this->isBs(5);
if (!isset($this->addon)) {
$this->addon = $isBs4 ? '<i class="far fa-clock"></i>' : '<i class="glyphicon glyphicon-time"></i>';
$this->addon = $notBs3 ? '<i class="far fa-clock"></i>' : '<i class="glyphicon glyphicon-time"></i>';
}
Html::addCssClass($this->options, 'form-control');
if (!empty($this->options['disabled'])) {
Html::addCssClass($this->addonOptions, 'disabled-addon');
}
if (ArrayHelper::getValue($this->pluginOptions, 'template', true) === false) {
$css = $isBs4 ? 'bootstrap-timepicker4' : 'bootstrap-timepicker3';
$css = $notBs3 ? 'bootstrap-timepicker4' : 'bootstrap-timepicker3';
Html::addCssClass($this->containerOptions, ['bootstrap-timepicker', $css]);
if (isset($this->size)) {
Html::addCssClass($this->options, ($isBs4 ? 'form-control-' : 'input-') . $this->size);
Html::addCssClass($this->options, ($notBs3 ? 'form-control-' : 'input-') . $this->size);
Html::addCssClass($this->addonOptions, 'inline-addon inline-addon-' . $this->size);
} else {
Html::addCssClass($this->addonOptions, 'inline-addon');
Expand All @@ -115,19 +116,20 @@ protected function renderInput()
$buttonOptions = ArrayHelper::remove($this->addonOptions, 'buttonOptions', []);

if ($asButton) {
$css = $isBs4 ? 'input-group-append' : 'input-group-btn';
$tag = $isBs4 ? 'div' : 'span';
$css = $notBs3 ? 'input-group-append' : 'input-group-btn';
$tag = $notBs3 ? 'div' : 'span';
Html::addCssClass($this->addonOptions, [$css, 'picker']);
$buttonOptions['type'] = 'button';
if (empty($buttonOptions['class'])) {
Html::addCssClass($buttonOptions, 'btn btn-default');
}
$addon = Html::tag($tag, Html::button($this->addon, $buttonOptions), $this->addonOptions);
$button = Html::button($this->addon, $buttonOptions);
$addon = $isBs5 ? $button : Html::tag($tag, $button, $this->addonOptions);
} else {
$css = $isBs4 ? 'input-group-text' : 'input-group-addon';
$css = $notBs3 ? 'input-group-text' : 'input-group-addon';
Html::addCssClass($this->addonOptions, [$css, 'picker']);
$addon = Html::tag('span', $this->addon, $this->addonOptions);
if ($isBs4) {
if ($notBs3 && !$isBs5) {
$addon = Html::tag('div', $addon, ['class' => 'input-group-append']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/TimePickerAsset.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-timepicker
* @version 1.0.4
* @version 1.0.5
*/

namespace kartik\time;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/bootstrap-timepicker.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Timepicker Component for Twitter Bootstrap
*
* Improvements by: Kartik Visweswaran, Krajee.com, 2014 - 2018
* Improvements by: Kartik Visweswaran, Krajee.com, 2014 - 2021
*
* Copyright 2013 Joris de Wit
*
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/bootstrap-timepicker.min.css

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

2 changes: 1 addition & 1 deletion src/assets/js/bootstrap-timepicker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Timepicker Component for Twitter Bootstrap
*
* Improvements by: Kartik Visweswaran, Krajee.com, 2014 - 2018
* Improvements by: Kartik Visweswaran, Krajee.com, 2014 - 2021
*
* Copyright 2013 Joris de Wit
*
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/bootstrap-timepicker.min.js

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

0 comments on commit 680aec2

Please sign in to comment.