Skip to content

Commit 07c824d

Browse files
author
Adam Bradley
committed
fix(item): Restructure item editing css for added reusability and organization
1 parent 4e11407 commit 07c824d

File tree

6 files changed

+122
-83
lines changed

6 files changed

+122
-83
lines changed

js/ext/angular/src/directive/ionicList.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ angular.module('ionic.ui.list', ['ngAnimate'])
6363
},
6464

6565
template: '<div class="item item-complex">\
66-
<div class="item-edit" ng-if="deleteClick !== undefined">\
66+
<div class="item-left-edit item-delete" ng-if="deleteClick !== undefined">\
6767
<button class="button button-icon icon" ng-class="deleteIconClass" ng-click="deleteClick()" ion-stop-event="click"></button>\
6868
</div>\
6969
<a class="item-content" ng-href="{{ href }}" ng-transclude></a>\
70-
<div class="item-drag" ng-if="reorderIconClass !== undefined">\
70+
<div class="item-right-edit item-drag" ng-if="reorderIconClass !== undefined">\
7171
<button data-ionic-action="reorder" class="button button-icon icon" ng-class="reorderIconClass"></button>\
7272
</div>\
7373
<div class="item-options" ng-if="itemOptionButtons">\
@@ -114,12 +114,14 @@ angular.module('ionic.ui.list', ['ngAnimate'])
114114

115115
// Set which icons to use for deleting
116116
$scope.deleteIconClass = $scope.deleteIcon || $parentScope.deleteIcon || 'ion-minus-circled';
117+
$element.addClass('item-left-editable');
117118
}
118119
}
119120

120121
// set the reorder Icon Class only if the item or list set can-reorder="true"
121122
if(($attr.canReorder ? $scope.canReorder : $parentScope.canReorder) === "true") {
122123
$scope.reorderIconClass = $scope.reorderIcon || $parentScope.reorderIcon || 'ion-navicon';
124+
$element.addClass('item-right-editable');
123125
}
124126

125127
// Set the option buttons which can be revealed by swiping to the left
@@ -129,6 +131,7 @@ angular.module('ionic.ui.list', ['ngAnimate'])
129131
if(typeof $scope.itemOptionButtons === "undefined") {
130132
$scope.itemOptionButtons = $parentScope.optionButtons();
131133
}
134+
$element.addClass('item-swipeable');
132135
}
133136

134137
}
@@ -202,7 +205,7 @@ angular.module('ionic.ui.list', ['ngAnimate'])
202205
reorderIcon: '@'
203206
},
204207

205-
template: '<div class="list" ng-class="{\'list-editing\': showDelete, \'list-reordering\': showReorder}" ng-transclude></div>',
208+
template: '<div class="list" ng-class="{\'list-left-editing\': showDelete, \'list-right-editing\': showReorder}" ng-transclude></div>',
206209

207210
controller: ['$scope', '$attrs', function($scope, $attrs) {
208211
this.scope = $scope;

js/ext/angular/test/directive/ionicList.unit.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('Ionic List', function() {
2525

2626
it('Should init', function() {
2727
var element = compile('<ion-list>' +
28-
'<ion-item></ion-item>' +
29-
'<ion-item></ion-item>' +
28+
'<ion-item></ion-item>' +
29+
'<ion-item></ion-item>' +
3030
'</ion-list>')(scope);
3131

3232
expect(element.children().length).toBe(2);
@@ -37,18 +37,18 @@ describe('Ionic List', function() {
3737
expect(element.hasClass('my-animation')).toBe(true);
3838
});
3939

40-
it('Should add list-editing class', function() {
41-
expect(listElement.hasClass('list-editing')).toBe(false);
40+
it('Should add list-left-editing class because of showDelete', function() {
41+
expect(listElement.hasClass('list-left-editing')).toBe(false);
4242
scope.showDelete = true;
4343
scope.$digest();
44-
expect(listElement.hasClass('list-editing')).toBe(true);
44+
expect(listElement.hasClass('list-left-editing')).toBe(true);
4545
});
4646

47-
it('Should add list-reordering class', function() {
48-
expect(listElement.hasClass('list-reordering')).toBe(false);
47+
it('Should add list-right-editing class because of showReorder', function() {
48+
expect(listElement.hasClass('list-right-editing')).toBe(false);
4949
scope.showReorder = true;
5050
scope.$digest();
51-
expect(listElement.hasClass('list-reordering')).toBe(true);
51+
expect(listElement.hasClass('list-right-editing')).toBe(true);
5252
});
5353

5454
it('Should add item-options-hide class', function() {
@@ -221,7 +221,8 @@ describe('Ionic Item Directive', function () {
221221
$rootScope.$digest();
222222
itemScope = itemElement.isolateScope();
223223
expect(itemScope.deleteClick).not.toBe(undefined);
224-
expect(itemElement.find('.item-edit').length).toBe(1);
224+
expect(itemElement.find('.item-left-edit').length).toBe(1);
225+
expect(itemElement.find('.item-delete').length).toBe(1);
225226
expect(itemScope.deleteIconClass).toBe("test-icon");
226227
}));
227228

@@ -277,7 +278,8 @@ describe('Ionic Item Directive', function () {
277278
$rootScope.$digest();
278279
itemScope = itemElement.isolateScope();
279280
expect(itemScope.deleteClick).not.toBe(undefined);
280-
expect(itemElement.find('.item-edit').length).toBe(1);
281+
expect(itemElement.find('.item-left-edit').length).toBe(1);
282+
expect(itemElement.find('.item-delete').length).toBe(1);
281283

282284
expect(itemScope.deleteIconClass).toBe("test-icon");
283285
}));

js/ext/angular/test/list.html

+9-10
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ <h1 class="title">List Tests</h1>
9595

9696
<ion-content class="has-header">
9797

98-
<div contenteditable="true">
99-
Hello!
100-
101-
Hello!
102-
</div>
103-
10498
<ion-list show-delete="isDeletingItems"
10599
show-reorder="isReorderingItems"
106100
on-refresh-holding="refreshHolding()"
@@ -118,7 +112,7 @@ <h1 class="title">List Tests</h1>
118112
option-buttons="optionButtons1">
119113

120114
<!-- shows that the item directive does not need attributes and can get values from the list attributes -->
121-
<ion-item ion-item="item" ng-href="#" ng-click="itemClick()" class="item-thumbnail-left" ng-repeat="item in items" ng-class="{ active: item.isActive}">
115+
<ion-item ion-item="item" ng-href="#" ng-click="itemClick()" class="item-thumbnail-left" ng-repeat="item in items">
122116
<img ng-src="{{item.face}}">
123117
<h2>{{item.from}}</h2>
124118
<p>{{item.text}}</p>
@@ -198,9 +192,14 @@ <h1>YELLOW {{slideBox.slideIndex}}</h1>
198192

199193
// Build Mock Data
200194
$scope.items = [
201-
{ from: 'Ben', face: 'https://pbs.twimg.com/profile_images/378800000571933189/278e8e1b7871a115b95fc550cd07af40.png', text: 'Did you prepare?' },
202-
{ from: 'Adam', face: 'https://pbs.twimg.com/profile_images/2927292174/25b170ee2e3044fd936ad1319bc4b82d_bigger.jpeg', text: 'Don\'t forget to smile!' },
203-
{ from: 'Tim', face: 'https://pbs.twimg.com/profile_images/378800000290028838/ee3303b02223f25cb0f9b082b55b2eeb.jpeg', text: 'Bring some shirts!', isActive: true }
195+
{ from: 'Ben', face: 'https://pbs.twimg.com/profile_images/378800000571933189/278e8e1b7871a115b95fc550cd07af40.png', text: 'Whoa, whoa, whoa. There’s still plenty of meat on that bone. Now you take this home, throw it in a pot, add some broth, a potato. Baby, you\'ve got a stew going.' },
196+
{ from: 'Adam', face: 'https://pbs.twimg.com/profile_images/2927292174/25b170ee2e3044fd936ad1319bc4b82d_bigger.jpeg', text: 'It Ain\'t Easy Being Cheesy' },
197+
{ from: 'Tim', face: 'https://pbs.twimg.com/profile_images/378800000290028838/ee3303b02223f25cb0f9b082b55b2eeb.jpeg', text: 'Baxter! You know I don\'t speak spanish!' },
198+
{ from: 'Brody', face: 'https://pbs.twimg.com/profile_images/378800000138067018/554c103ebf37c2ba3b923b8deea46b0d.jpeg', text: 'Sounds like some sort of marmalade' },
199+
{ from: 'Peter', face: 'https://pbs.twimg.com/profile_images/378800000238071493/08f76337bdc91b1e1e73a9d55c57a451.jpeg', text: 'A cooked goose for everyone!' },
200+
{ from: 'Max', face: 'https://pbs.twimg.com/profile_images/430001754747305984/qa5DFLgU.jpeg', text: 'Yes my dear man, more beans. oooohh' },
201+
{ from: 'Andy', face: 'https://pbs.twimg.com/profile_images/423294834229522433/BSlEOBYt.jpeg', text: 'I did it all for her' },
202+
{ from: 'Melissa', face: 'https://pbs.twimg.com/profile_images/412451928816111616/VZ3_md1N.jpeg', text: 'I think I want my money back' }
204203
];
205204

206205

scss/_items.scss

+81-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
.item {
77
@include item-style($item-default-bg, $item-default-border, $item-default-text);
8-
@include transition(margin-left 0.2s ease-in-out, margin-right 0.2s ease-in-out, left 0.2s ease-in-out);
98

109
position: relative;
1110
z-index: $z-index-item; // Make sure the borders and stuff don't get hidden by children
@@ -183,18 +182,10 @@ button.item.item-complex {
183182
}
184183
.item-complex .item-content,
185184
.item-radio .item-content {
186-
/**
187-
* The content area of a complex list item. This area can
188-
* Slide left and right and be dragged to support different
189-
* UI interactions.
190-
*/
191-
@include transition(all 0.1s ease-in-out);
192185
position: relative;
193186
z-index: $z-index-item;
194-
195187
padding: $item-padding (($item-padding * 3) - 5) $item-padding $item-padding;
196188
border: none;
197-
198189
background-color: white;
199190
}
200191

@@ -554,30 +545,60 @@ button.item-button-right:after,
554545
// Item Editing
555546
// -------------------------------
556547

557-
.item-reordering {
558-
position: absolute;
559-
z-index: $z-index-item-reordering;
560-
width: 100%;
548+
.item-left-editable .item-content,
549+
.item-right-editable .item-content {
550+
// setup standard transition settings
551+
@include transition-duration( $item-edit-transition-duration );
552+
@include transition-timing-function( $item-edit-transition-function );
553+
@include transition-property( none );
561554
}
562555

563-
.item-placeholder {
564-
opacity: 0.7;
556+
.item-left-editable .item-content {
557+
// set transition property for an item just left editable
558+
-webkit-transition-property: -webkit-transform;
559+
-moz-transition-property: -moz-transform;
560+
transition-property: transform;
565561
}
566562

563+
.item-right-editable .item-content {
564+
// set transition property for an item just right editable
565+
@include transition-property(margin-right);
566+
}
567567

568-
/**
569-
* The left-side edit area of a complex list item. This area shows
570-
* whe the list item is in edit mode.
571-
*/
572-
.item-edit {
573-
@include transition(left 0.2s ease-in-out, opacity 0.2s ease-in-out);
568+
.item-left-editable.item-right-editable .item-content {
569+
// set transition property for an item that's both left/right editable
570+
-webkit-transition-property: -webkit-transform, margin-right;
571+
-moz-transition-property: -moz-transform, margin-right;
572+
transition-property: transform, margin-right;
573+
}
574+
575+
.list-left-editing .item-left-editable .item-content,
576+
.item-left-editing.item-left-editable .item-content {
577+
// actively editing the left side of the item
578+
@include translate3d($item-edit-left-open-width, 0, 0);
579+
}
580+
581+
.list-right-editing .item-right-editable .item-content,
582+
.item-right-editing.item-right-editable .item-content {
583+
// actively editing the right side of the item
584+
margin-right: $item-edit-right-open-width;
585+
}
586+
587+
588+
// Item Left Edit Button
589+
// -------------------------------
590+
591+
.item-left-edit {
592+
@include transition(all $item-edit-transition-function $item-edit-transition-duration);
593+
@include translate3d( $item-delete-icon-left - $item-edit-left-open-width, 0, 0);
574594
position: absolute;
575595
top: 0;
576-
left: 8px;
596+
left: 0;
577597
z-index: $z-index-item-edit;
578-
width: 48px;
598+
width: $item-edit-left-open-width;
579599
height: 100%;
580600
line-height: 100%;
601+
opacity: 0;
581602

582603
.button {
583604
height: 100%;
@@ -589,31 +610,48 @@ button.item-button-right:after,
589610
top: 0;
590611
left: 0;
591612
height: 100%;
592-
color: $assertive;
593-
font-size: 24px;
594613
}
595614
}
615+
}
596616

597-
&.ng-enter {
598-
@include transition(left 0.2s ease-in-out, opacity 0.2s ease-in-out);
599-
left: -48px;
600-
opacity: 0;
601-
}
602-
&.ng-enter-active {
603-
left: 8px;
604-
opacity: 1;
605-
}
606-
&.ng-leave {
607-
@include transition(left 0.2s ease-in-out, opacity 0.2s ease-in-out);
608-
left: 0px;
609-
opacity: 1;
617+
.list-left-editing .item-left-edit {
618+
@include translate3d($item-delete-icon-left, 0, 0);
619+
opacity: 1;
620+
}
621+
622+
623+
// Item Delete
624+
// -------------------------------
625+
626+
.item-delete .button.icon {
627+
color: $item-delete-icon-color;
628+
font-size: $item-delete-icon-size;
629+
630+
&:hover {
631+
opacity: .7;
610632
}
611-
&.ng-leave-active {
612-
left: -48px;
613-
opacity: 0;
633+
}
634+
635+
636+
// Item Reordering
637+
// -------------------------------
638+
639+
.list-reordering {
640+
.item-drag {
641+
z-index: 1;
614642
}
615643
}
616644

645+
.item-reordering {
646+
position: absolute;
647+
z-index: $z-index-item-reordering;
648+
width: 100%;
649+
}
650+
651+
.item-placeholder {
652+
opacity: 0.7;
653+
}
654+
617655
.item-drag {
618656
position: absolute;
619657
top: 0;
@@ -637,6 +675,8 @@ button.item-button-right:after,
637675
}
638676
}
639677
}
678+
679+
640680
/**
641681
* The hidden right-side buttons that can be exposed under a list item
642682
* with dragging.

scss/_list.scss

-19
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,10 @@
1111
padding-left: 0; // reset padding because ul and ol
1212
margin-bottom: 20px;
1313
}
14-
/* If a list is the last item in a container, don't add margin-bottom */
1514
.list:last-child {
1615
margin-bottom: 0px;
1716
}
1817

19-
/**
20-
* List editing styles. These trigger when the entire list goes into
21-
* "edit mode" or reordering list items
22-
*/
23-
.list-editing {
24-
.item-content {
25-
@include translate3d(50px, 0, 0);
26-
}
27-
}
28-
.list-reordering {
29-
.item-content {
30-
margin-right: 50px;
31-
}
32-
.item-drag {
33-
z-index: 1;
34-
}
35-
}
36-
3718

3819
/**
3920
* List Header

scss/_variables.scss

+14
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,20 @@ $item-default-active-bg: #D9D9D9 !default;
361361
$item-default-active-border: $item-light-active-border !default;
362362

363363

364+
// Item Editing
365+
// -------------------------------
366+
367+
$item-edit-transition-duration: 250ms !default;
368+
$item-edit-transition-function: ease-in-out !default;
369+
370+
$item-edit-right-open-width: 50px !default;
371+
$item-edit-left-open-width: 50px !default;
372+
373+
$item-delete-icon-left: 8px !default;
374+
$item-delete-icon-size: 24px !default;
375+
$item-delete-icon-color: $assertive !default;
376+
377+
364378
// Lists
365379
// -------------------------------
366380

0 commit comments

Comments
 (0)