Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(item-sliding): add open method #17964

Merged
merged 26 commits into from May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
205d6cf
feat(item-sliding): add open method
shreeshbhat Apr 5, 2019
f1a163f
fix(item-sliding): update open method transition
shreeshbhat Apr 6, 2019
5845a46
fix(item-sliding): fix lint & remove deprecated webkit
shreeshbhat Apr 6, 2019
fd0b5b9
feat(item-sliding): Add requested changes
shreeshbhat Apr 12, 2019
53384a4
feat(item-sliding): Add delayed open dirty call
shreeshbhat Apr 12, 2019
8d4a1a7
add ability to specify a side when opening, bug fixes
liamdebeasi Apr 15, 2019
4c360b2
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 15, 2019
a2d6b1e
update default side
liamdebeasi Apr 15, 2019
2ce55eb
remove extra querySelector, remove extra transition set
liamdebeasi Apr 16, 2019
1ab8b11
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 16, 2019
d23933a
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 16, 2019
df13796
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 16, 2019
3fc31bb
document open method params
liamdebeasi Apr 16, 2019
79990c7
run build
liamdebeasi Apr 16, 2019
73d74b9
Merge branch 'master' into item-sliding-open
brandyscarney Apr 16, 2019
8f239a4
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 17, 2019
925c777
Merge branch 'master' into item-sliding-open
liamdebeasi Apr 18, 2019
f2edc3b
remove opts dirty usage with open
liamdebeasi Apr 18, 2019
2b04a4d
close other open options when opening new options
liamdebeasi Apr 18, 2019
96c99f2
do not re-open side that is already open
liamdebeasi Apr 18, 2019
476d6ef
update docs
liamdebeasi Apr 18, 2019
7f683a0
fix case where side needs to be inferred
liamdebeasi Apr 18, 2019
b1f651e
update todos
liamdebeasi Apr 18, 2019
f3a1030
fix typo
liamdebeasi Apr 18, 2019
823eac5
Merge branch 'master' into item-sliding-open
liamdebeasi May 7, 2019
3d9d0fe
Merge branch 'master' into item-sliding-open
brandyscarney May 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular/src/directives/proxies.ts
Expand Up @@ -414,7 +414,7 @@ export class IonItemSliding {
proxyOutputs(this, this.el, ['ionDrag']);
}
}
proxyMethods(IonItemSliding, ['getOpenAmount', 'getSlidingRatio', 'close', 'closeOpened']);
proxyMethods(IonItemSliding, ['getOpenAmount', 'getSlidingRatio', 'open', 'close', 'closeOpened']);
proxyInputs(IonItemSliding, ['disabled']);

export declare interface IonLabel extends StencilComponents<'IonLabel'> {}
Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Expand Up @@ -472,6 +472,7 @@ ion-item-sliding,method,close,close() => Promise<void>
ion-item-sliding,method,closeOpened,closeOpened() => Promise<boolean>
ion-item-sliding,method,getOpenAmount,getOpenAmount() => Promise<number>
ion-item-sliding,method,getSlidingRatio,getSlidingRatio() => Promise<number>
ion-item-sliding,method,open,open(side: string | undefined) => Promise<void>
ion-item-sliding,event,ionDrag,void,true

ion-item,shadow
Expand Down
4 changes: 4 additions & 0 deletions core/src/components.d.ts
Expand Up @@ -1983,6 +1983,10 @@ export namespace Components {
* Get the ratio of the open amount of the item compared to the width of the options. If the number returned is positive, then the options on the right side are open. If the number returned is negative, then the options on the left side are open. If the absolute value of the number is greater than 1, the item is open more than the width of the options.
*/
'getSlidingRatio': () => Promise<number>;
/**
* Open the sliding item.
*/
'open': (side: string | undefined) => Promise<void>;
}
interface IonItemSlidingAttributes extends StencilHTMLAttributes {
/**
Expand Down
67 changes: 67 additions & 0 deletions core/src/components/item-sliding/item-sliding.tsx
Expand Up @@ -117,6 +117,52 @@ export class ItemSliding implements ComponentInterface {
return Promise.resolve(this.getSlidingRatioSync());
}

/**
* Open the sliding item.
*
* @param side The side of the options to open. If a side is not provided, it will open the first set of options it finds within the item.
*/
// TODO update to work with RTL
@Method()
async open(side: string | undefined) {
if (this.item === null) { return; }

const optionsToOpen = this.getOptions(side);
if (!optionsToOpen) { return; }

/**
* If side is not set, we need to infer the side
* so we know which direction to move the options
*/
if (side === undefined) {
side = (optionsToOpen === this.leftOptions) ? 'start' : 'end';
}

const isStartOpen = this.openAmount < 0;
const isEndOpen = this.openAmount > 0;

/**
* If a side is open and a user tries to
* re-open the same side, we should not do anything
*/
if (isStartOpen && optionsToOpen === this.leftOptions) { return; }
if (isEndOpen && optionsToOpen === this.rightOptions) { return; }

this.closeOpened();

this.state = SlidingState.Enabled;

requestAnimationFrame(() => {
this.calculateOptsWidth();

const width = (side === 'end') ? this.optsWidthRightSide : -this.optsWidthLeftSide;
openSlidingItem = this.el;

this.setOpenAmount(width, false);
this.state = (side === 'end') ? SlidingState.End : SlidingState.Start;
});
}

/**
* Close the sliding item. Items can also be closed from the [List](../../list/List).
*/
Expand All @@ -138,6 +184,22 @@ export class ItemSliding implements ComponentInterface {
return false;
}

/**
* Given a side, attempt to return the ion-item-options element
*
* @param side This side of the options to get. If a side is not provided it will return the first one available
*/
// TODO update to work with RTL
private getOptions(side?: string): HTMLIonItemOptionsElement | undefined {
if (side === undefined) {
return this.leftOptions || this.rightOptions;
} else if (side === 'start') {
return this.leftOptions;
} else {
return this.rightOptions;
}
}

private async updateOptions() {
const options = this.el.querySelectorAll('ion-item-options');

Expand Down Expand Up @@ -244,13 +306,18 @@ export class ItemSliding implements ComponentInterface {
private calculateOptsWidth() {
this.optsWidthRightSide = 0;
if (this.rightOptions) {
this.rightOptions.style.display = 'flex';
this.optsWidthRightSide = this.rightOptions.offsetWidth;
this.rightOptions.style.display = '';
}

this.optsWidthLeftSide = 0;
if (this.leftOptions) {
this.leftOptions.style.display = 'flex';
this.optsWidthLeftSide = this.leftOptions.offsetWidth;
this.leftOptions.style.display = '';
}

this.optsDirty = false;
}

Expand Down
16 changes: 16 additions & 0 deletions core/src/components/item-sliding/readme.md
Expand Up @@ -692,6 +692,22 @@ Type: `Promise<number>`



### `open(side: string | undefined) => Promise<void>`

Open the sliding item.

#### Parameters

| Name | Type | Description |
| ------ | --------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `side` | `string \| undefined` | The side of the options to open. If a side is not provided, it will open the first set of options it finds within the item. |

#### Returns

Type: `Promise<void>`




----------------------------------------------

Expand Down
13 changes: 13 additions & 0 deletions core/src/components/item-sliding/test/basic/index.html
Expand Up @@ -38,6 +38,9 @@
<ion-button expand="block" onclick="toggleSliding()">Toggle sliding</ion-button>
<ion-button expand="block" onclick="toggleDynamicOptions()">Toggle Dynamic Options</ion-button>
<ion-button expand="block" onclick="closeOpened()">Close Opened Items</ion-button>
<ion-button expand="block" onclick="openItem('start')">Open Item Start</ion-button>
<ion-button expand="block" onclick="openItem('end')">Open Item End</ion-button>
<ion-button expand="block" onclick="openItemOneSide()">Open Item with only one side</ion-button>
</div>

<ion-list id="list">
Expand Down Expand Up @@ -405,6 +408,16 @@ <h2>Normal button (no sliding)</h2>
list.closeSlidingItems();
}

function openItem(side) {
var item = document.getElementById('item2');
item.open(side);
}

function openItemOneSide() {
var item = document.getElementById('item1');
item.open();
}

function noclose(item) {
var itemEle = document.getElementById(item);
console.log('no close', itemEle);
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/item-sliding/test/preview/index.html
Expand Up @@ -32,6 +32,7 @@
<ion-button expand="block" onclick="toggleSliding()">Toggle sliding</ion-button>
<ion-button expand="block" onclick="toggleDynamicOptions()">Toggle Dynamic Options</ion-button>
<ion-button expand="block" onclick="closeOpened()">Close Opened Items</ion-button>
<ion-button expand="block" onclick="openItem()">Open Item</ion-button>
</div>

<ion-list id="list">
Expand Down Expand Up @@ -356,6 +357,11 @@ <h2>Normal button (no sliding)</h2>
list.closeSlidingItems();
}

function openItem() {
var item = document.getElementById('item0');
item.open();
}

function noclose(item) {
var itemEle = document.getElementById(item);
console.log('no close', itemEle);
Expand Down