Skip to content
This repository was archived by the owner on Jul 3, 2022. It is now read-only.

Commit 3793d8d

Browse files
author
Khaled Shaaban
committed
Merge pull request #2 from kshaaban-/icons-to-items
Added support for including icons in the generation ion-items. Closed #1
2 parents c0539eb + 9fdb88c commit 3793d8d

File tree

6 files changed

+48
-17
lines changed

6 files changed

+48
-17
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ I couldn't find an existing plugin to handle duration inputs, but this was large
3939
4. You may use it immediately in your templates with the default configuration:
4040
4141
```html
42-
<ionic-durationpicker idp-label="Mile Run Duration" idp-output="mileRunDuration">
42+
<ionic-durationpicker idp-label="Mile Run Duration" idp-label-icon="ion-clock" idp-output="mileRunDuration">
4343
</ionic-durationpicker>
4444
```
45-
`idp-label` is the string that labels the generated `ion-item`. And the variable you pass into `idp-output` will be used to store the duration input in seconds format. You may also use it to initialize a duration from an integer representing a number of seconds. Be wary though, currently there are no checks against what's already in that variable.
45+
`idp-label` is the string that labels the generated `ion-item`. If you would like to include an ionicon in your ion-item, then you can pass the icon name into `idp-label-icon`. And the variable you pass into `idp-output` will be used to store the duration input in seconds format. You may also use it to initialize a duration from an integer representing a number of seconds. Be wary though, currently there are no checks against what's already in that variable.
4646
4747
For example, if your `$scope.mileRunDuration` had a value of `527`, then the above snippet will result with:
4848
@@ -79,8 +79,8 @@ I couldn't find an existing plugin to handle duration inputs, but this was large
7979
Then pass it into the plugin's directive:
8080
8181
```html
82-
<ionic-durationpicker idp-label="Mile Run Duration" idp-config="mileRunConfig"
83-
idp-output="mileRunDuration">
82+
<ionic-durationpicker idp-label="Mile Run Duration" idp-label-icon="ion-clock"
83+
idp-config="mileRunConfig" idp-output="mileRunDuration">
8484
</ionic-durationpicker>
8585
```
8686
@@ -97,7 +97,7 @@ You can configure the plugin by passing an object containing any of the followin
9797
9898
Property | Type (_Default Value_) | Description
9999
:--------------:|:-------------------------------------------:|-------------------------------------------
100-
rtl | Boolean (_false_) | For Right-to-left languages, flips the button to the left and pulls the label to the right in the generated `ion-item`.
100+
rtl | Boolean (_false_) | For Right-to-left languages, flips the button to the left and pulls the label to the right along with the icon in the generated `ion-item`.
101101
inputButtonType | String (_'button-outline button-positive'_) | CSS class(es) for the button that shows the popup.
102102
format | String (_'MM:SS'_) | Duration Format. **Default value is currently the _only_ supported format.**
103103
secondsStep | Number (_1_) | Amount to increment/decrement seconds by on popup control arrow clicks.

dist/ionic-durationpicker.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
cacheTemplates.$inject = ["$templateCache"];
88

99
function cacheTemplates($templateCache) {
10-
$templateCache.put("idp-item.html","<ion-item ng-class=getItemDirectionClasses()>{{idpLabel}} <button class=button ng-class=getInputButtonType() ng-click=showPopup()>{{prettyFormatDuration()}}</button></ion-item>");
10+
$templateCache.put("idp-item.html","<ion-item ng-class=getItemClasses()><i ng-if=idpLabelIcon class=\"icon {{idpLabelIcon}}\"></i> {{idpLabel}} <button class=button ng-class=getInputButtonType() ng-click=showPopup()>{{prettyFormatDuration()}}</button></ion-item>");
1111

1212
$templateCache.put("popup-minutes-seconds.html","<div class=row><span class=\"idp-control col col-offset-20 col-25\"><button type=button class=\"button button-clear button-small idp-control-arrow\" ng-click=\"increment(\'minutes\')\" on-hold=\"updateOnHold(\'minutes\', \'increment\')\" on-release=releaseHold()><i class=\"icon ion-chevron-up\"></i></button><div ng-bind=popupDuration.minutes class=idp-unit-box></div><button type=button class=\"button button-clear button-small idp-control-arrow\" ng-click=\"decrement(\'minutes\')\" on-hold=\"updateOnHold(\'minutes\', \'decrement\')\" on-release=releaseHold()><i class=\"icon ion-chevron-down\"></i></button></span> <label class=\"col col-10 idp-unit-separator\">:</label> <span class=\"idp-control col col-25\"><button type=button class=\"button button-clear button-small idp-control-arrow\" ng-click=\"increment(\'seconds\')\" on-hold=\"updateOnHold(\'seconds\', \'increment\')\" on-release=releaseHold()><i class=\"icon ion-chevron-up\"></i></button><div ng-bind=popupDuration.seconds class=idp-unit-box></div><button type=button class=\"button button-clear button-small idp-control-arrow\" ng-click=\"decrement(\'seconds\')\" on-hold=\"updateOnHold(\'seconds\', \'decrement\')\" on-release=releaseHold()><i class=\"icon ion-chevron-down\"></i></button></span></div>");
1313
}
@@ -38,6 +38,7 @@
3838
scope: {
3939
idpConfig: '=',
4040
idpLabel: '@',
41+
idpLabelIcon: '@',
4142
idpOutput: '='
4243
},
4344
link: linkFunc
@@ -55,6 +56,9 @@
5556
if (typeof scope.idpLabel === 'undefined' || scope.idpLabel === null) {
5657
scope.idpLabel = 'Duration';
5758
}
59+
if (typeof scope.idpLabelIcon === 'undefined' || scope.idpLabel === null) {
60+
scope.idpLabelIcon = false;
61+
}
5862
if (typeof scope.idpOutput === 'undefined' || scope.idpOutput === null) {
5963
scope.idpOutput = 0;
6064
}
@@ -77,7 +81,7 @@
7781
};
7882

7983
scope.showPopup = _showPopup;
80-
scope.getItemDirectionClasses = _getItemDirectionClasses;
84+
scope.getItemClasses = _getItemClasses;
8185
scope.getInputButtonType = _getInputButtonType;
8286
scope.increment = _increment;
8387
scope.decrement = _decrement;
@@ -159,12 +163,23 @@
159163
});
160164
}
161165

162-
function _getItemDirectionClasses() {
166+
function _getItemClasses() {
167+
var itemClasses = '';
168+
169+
// Don't forget a white-space after each appended class
163170
if (config.rtl) {
164-
return 'idp-dir-rtl item-button-left';
171+
itemClasses += 'idp-dir-rtl item-button-left ';
165172
} else {
166-
return 'item-button-right';
173+
itemClasses += 'item-button-right ';
167174
}
175+
176+
if (scope.idpLabelIcon && config.rtl) {
177+
itemClasses += 'item-icon-right ';
178+
} else if (scope.idpLabelIcon) {
179+
itemClasses += 'item-icon-left ';
180+
}
181+
182+
return itemClasses;
168183
}
169184

170185
function _getInputButtonType() {

dist/ionic-durationpicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
scope: {
1515
idpConfig: '=',
1616
idpLabel: '@',
17+
idpLabelIcon: '@',
1718
idpOutput: '='
1819
},
1920
link: linkFunc
@@ -31,6 +32,9 @@
3132
if (typeof scope.idpLabel === 'undefined' || scope.idpLabel === null) {
3233
scope.idpLabel = 'Duration';
3334
}
35+
if (typeof scope.idpLabelIcon === 'undefined' || scope.idpLabel === null) {
36+
scope.idpLabelIcon = false;
37+
}
3438
if (typeof scope.idpOutput === 'undefined' || scope.idpOutput === null) {
3539
scope.idpOutput = 0;
3640
}
@@ -53,7 +57,7 @@
5357
};
5458

5559
scope.showPopup = _showPopup;
56-
scope.getItemDirectionClasses = _getItemDirectionClasses;
60+
scope.getItemClasses = _getItemClasses;
5761
scope.getInputButtonType = _getInputButtonType;
5862
scope.increment = _increment;
5963
scope.decrement = _decrement;
@@ -135,12 +139,23 @@
135139
});
136140
}
137141

138-
function _getItemDirectionClasses() {
142+
function _getItemClasses() {
143+
var itemClasses = '';
144+
145+
// Don't forget a white-space after each appended class
139146
if (config.rtl) {
140-
return 'idp-dir-rtl item-button-left';
147+
itemClasses += 'idp-dir-rtl item-button-left ';
141148
} else {
142-
return 'item-button-right';
149+
itemClasses += 'item-button-right ';
143150
}
151+
152+
if (scope.idpLabelIcon && config.rtl) {
153+
itemClasses += 'item-icon-right ';
154+
} else if (scope.idpLabelIcon) {
155+
itemClasses += 'item-icon-left ';
156+
}
157+
158+
return itemClasses;
144159
}
145160

146161
function _getInputButtonType() {

0 commit comments

Comments
 (0)