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

Feature/ionic4 #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions accordion/accordion.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<ion-card>
<ion-card-header (click)="toggleAccordion()">
<ion-list>
<ion-item color="primary">
<button ion-button clear small icon-only item-right>
<ion-icon color="light" [name]="icon"></ion-icon>
</button>
<ion-item lines="none">
<ion-button fill="clear" size="small" slot="end">
<ion-icon color="dark" slot="icon-only" [name]="icon"></ion-icon>
</ion-button>
{{ title }}
</ion-item>
</ion-list>
</ion-card-header>
<ion-card-content #cc>
<ng-content></ng-content>
</ion-card-content>
</ion-card>
</ion-card>
19 changes: 8 additions & 11 deletions accordion/accordion.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
accordion {

.card-header{
background-color: map-get($colors, primary);
color: #fff;
}
.card-content {
padding: 0px 16px;
max-height: 0px;
}
}
.card-header {
background-color: map-get($colors, primary);
color: #fff;
}
.card-content {
padding: 0px 16px;
max-height: 0px;
}
44 changes: 20 additions & 24 deletions accordion/accordion.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
import { Component, ViewChild, OnInit, Renderer, Input } from '@angular/core';
import { Component, ViewChild, OnInit, Renderer, Input } from "@angular/core";

/**
* Generated class for the AccordionComponent component.
*
* See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
* for more info on Angular Components.
*/
@Component({
selector: 'accordion',
templateUrl: 'accordion.html'
selector: "accordion",
templateUrl: "./accordion.component.html",
styleUrls: ["./accordion.component.scss"]
})
export class AccordionComponent implements OnInit {

accordionExapanded = false;
@ViewChild("cc") cardContent: any;
@Input('title') title: string;
@Input("title") title: string;

icon: string = "arrow-forward";

constructor(public renderer: Renderer) {

}
constructor(public renderer: Renderer) {}

ngOnInit() {
console.log(this.cardContent.nativeElement);
this.renderer.setElementStyle(this.cardContent.nativeElement, "webkitTransition", "max-height 500ms, padding 500ms");
this.cardContent.el.transition = "max-height 500ms, padding 500ms";
this.renderer.setElementStyle(
this.cardContent.el,
"webkitTransition",
"max-height 500ms, padding 500ms"
);
}

toggleAccordion() {
if (this.accordionExapanded) {
this.renderer.setElementStyle(this.cardContent.nativeElement, "max-height", "0px");
this.renderer.setElementStyle(this.cardContent.nativeElement, "padding", "0px 16px");

this.renderer.setElementStyle(this.cardContent.el, "max-height", "0px");
this.renderer.setElementStyle(this.cardContent.el, "padding", "0px 16px");
} else {
this.renderer.setElementStyle(this.cardContent.nativeElement, "max-height", "500px");
this.renderer.setElementStyle(this.cardContent.nativeElement, "padding", "13px 16px");

this.renderer.setElementStyle(this.cardContent.el, "max-height", "500px");
this.renderer.setElementStyle(
this.cardContent.el,
"padding",
"13px 16px"
);
}

this.accordionExapanded = !this.accordionExapanded;
this.icon = this.icon == "arrow-forward" ? "arrow-down" : "arrow-forward";

}

}
17 changes: 13 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
### Accordion Component for Ionic 3 Apps
### Accordion Component for Ionic 4

![Image Preview](https://image.prntscr.com/image/1QwOijlhRZGnkAFb1QxEmQ.png)
![Image Preview](https://image.prntscr.com/image/lVyVb5BmTCyXd5l0q4w49Q.png)

`<accordion title="Your Title"> Your Content Here </accordion>`
## Usage
To use this component, clone it in its components folder and then generate a file called `components.module.ts` in the root folder. Remaining a structure like the following

Simple and easy to use.
![Image](https://image.prntscr.com/image/6tl5OGfrRWSocjTqftW2oQ.png)

Now in your file `components.module.ts` you must import and export your component. Your file should look like this

![Image](https://image.prntscr.com/image/2jIrcUIlTkamvp8KoC1uEQ.png)

On the page that you want to use the component, you must now import its component module in the `your-page.module.ts` file inside the ` imports: [] ` After having done this you can invoke the component in the following way:

`<accordion title="Your Title"> Your Content Here </accordion>`