simple-accordian 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/fesm2022/accordian.mjs +46 -0
- package/fesm2022/accordian.mjs.map +1 -0
- package/package.json +33 -0
- package/types/accordian.d.ts +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Accordian
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.1.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build accordian
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/accordian
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { Input, Component } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
class Accordian {
|
|
6
|
+
//for the inputs of the accordian component
|
|
7
|
+
items = []; // Array of accordion items
|
|
8
|
+
multiple = false; // Allow multiple sections to be open simultaneously
|
|
9
|
+
//function to toggle the accordian items
|
|
10
|
+
toggle(index) {
|
|
11
|
+
const clicked = this.items[index];
|
|
12
|
+
if (clicked.disabled)
|
|
13
|
+
return;
|
|
14
|
+
this.items = this.items.map((item, i) => {
|
|
15
|
+
if (this.multiple) {
|
|
16
|
+
return i === index
|
|
17
|
+
? { ...item, open: !item.open }
|
|
18
|
+
: item;
|
|
19
|
+
}
|
|
20
|
+
return i === index
|
|
21
|
+
? { ...item, open: !item.open }
|
|
22
|
+
: { ...item, open: false };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: Accordian, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
26
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.0", type: Accordian, isStandalone: true, selector: "simple-accordian", inputs: { items: "items", multiple: "multiple" }, ngImport: i0, template: "<div class=\"accordion\">\r\n @for (item of items; track $index; let i = $index) {\r\n <div class=\"accordion-item\">\r\n <button\r\n class=\"accordion-header\"\r\n (click)=\"toggle(i)\"\r\n [class.active]=\"item.open\"\r\n [disabled]=\"item.disabled\">\r\n\r\n <span>{{ item.title }}</span>\r\n <span class=\"icon\">{{ item.open ? '\u2212' : '+' }}</span>\r\n </button>\r\n\r\n <div class=\"accordion-body\" [class.open]=\"item.open\">\r\n <div class=\"accordion-content\">\r\n {{ item.content }}\r\n </div>\r\n </div>\r\n </div>\r\n }\r\n</div>\r\n", styles: [":host{display:block;width:100%;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Helvetica Neue,sans-serif}.accordion{width:100%;border-radius:12px;overflow:hidden;border:1px solid #e5e7eb;background:#fff}.accordion-item{border-bottom:1px solid #e5e7eb}.accordion-item:last-child{border-bottom:none}.accordion-header{width:100%;background:transparent;border:none;outline:none;cursor:pointer;display:flex;align-items:center;justify-content:space-between;padding:16px 18px;font-size:15px;font-weight:600;color:#111827;transition:background .2s ease,color .2s ease}.accordion-header:hover{background:#f9fafb}.accordion-header.active{background:#f3f4f6}.accordion-header:disabled{cursor:not-allowed;color:#9ca3af;background:#fafafa}.icon{font-size:20px;font-weight:400;line-height:1;transition:transform .25s ease}.accordion-header.active .icon{transform:rotate(180deg)}.accordion-body{max-height:0;overflow:hidden;transition:max-height .3s ease}.accordion-body.open{max-height:500px}.accordion-content{padding:14px 18px 18px;font-size:14px;line-height:1.6;color:#374151;background:#fff}.accordion-body.open .accordion-content{animation:fadeIn .2s ease-in}@keyframes fadeIn{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }] });
|
|
27
|
+
}
|
|
28
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: Accordian, decorators: [{
|
|
29
|
+
type: Component,
|
|
30
|
+
args: [{ selector: 'simple-accordian', standalone: true, imports: [CommonModule], template: "<div class=\"accordion\">\r\n @for (item of items; track $index; let i = $index) {\r\n <div class=\"accordion-item\">\r\n <button\r\n class=\"accordion-header\"\r\n (click)=\"toggle(i)\"\r\n [class.active]=\"item.open\"\r\n [disabled]=\"item.disabled\">\r\n\r\n <span>{{ item.title }}</span>\r\n <span class=\"icon\">{{ item.open ? '\u2212' : '+' }}</span>\r\n </button>\r\n\r\n <div class=\"accordion-body\" [class.open]=\"item.open\">\r\n <div class=\"accordion-content\">\r\n {{ item.content }}\r\n </div>\r\n </div>\r\n </div>\r\n }\r\n</div>\r\n", styles: [":host{display:block;width:100%;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Helvetica Neue,sans-serif}.accordion{width:100%;border-radius:12px;overflow:hidden;border:1px solid #e5e7eb;background:#fff}.accordion-item{border-bottom:1px solid #e5e7eb}.accordion-item:last-child{border-bottom:none}.accordion-header{width:100%;background:transparent;border:none;outline:none;cursor:pointer;display:flex;align-items:center;justify-content:space-between;padding:16px 18px;font-size:15px;font-weight:600;color:#111827;transition:background .2s ease,color .2s ease}.accordion-header:hover{background:#f9fafb}.accordion-header.active{background:#f3f4f6}.accordion-header:disabled{cursor:not-allowed;color:#9ca3af;background:#fafafa}.icon{font-size:20px;font-weight:400;line-height:1;transition:transform .25s ease}.accordion-header.active .icon{transform:rotate(180deg)}.accordion-body{max-height:0;overflow:hidden;transition:max-height .3s ease}.accordion-body.open{max-height:500px}.accordion-content{padding:14px 18px 18px;font-size:14px;line-height:1.6;color:#374151;background:#fff}.accordion-body.open .accordion-content{animation:fadeIn .2s ease-in}@keyframes fadeIn{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}\n"] }]
|
|
31
|
+
}], propDecorators: { items: [{
|
|
32
|
+
type: Input
|
|
33
|
+
}], multiple: [{
|
|
34
|
+
type: Input
|
|
35
|
+
}] } });
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* Public API Surface of accordian
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generated bundle index. Do not edit.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
export { Accordian };
|
|
46
|
+
//# sourceMappingURL=accordian.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accordian.mjs","sources":["../../../projects/accordian/src/lib/accordian/accordian.ts","../../../projects/accordian/src/lib/accordian/accordian.html","../../../projects/accordian/src/public-api.ts","../../../projects/accordian/src/accordian.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\r\nimport { Component, Input } from '@angular/core';\r\n\r\nexport interface AccordionItemInterface {\r\n title: string;\r\n content: string;\r\n open?: boolean;\r\n disabled?: boolean;\r\n}\r\n\r\n@Component({\r\n selector: 'simple-accordian',\r\n standalone: true,\r\n imports: [CommonModule],\r\n templateUrl: './accordian.html',\r\n styleUrls: ['./accordian.css']\r\n})\r\nexport class Accordian {\r\n\r\n //for the inputs of the accordian component\r\n @Input() items: AccordionItemInterface[] = []; // Array of accordion items\r\n @Input() multiple = false; // Allow multiple sections to be open simultaneously\r\n\r\n //function to toggle the accordian items\r\n toggle(index: number) {\r\n const clicked = this.items[index];\r\n if (clicked.disabled) return;\r\n\r\n this.items = this.items.map((item, i) => {\r\n if (this.multiple) {\r\n return i === index\r\n ? { ...item, open: !item.open }\r\n : item;\r\n }\r\n\r\n return i === index\r\n ? { ...item, open: !item.open }\r\n : { ...item, open: false };\r\n });\r\n }\r\n}\r\n","<div class=\"accordion\">\r\n @for (item of items; track $index; let i = $index) {\r\n <div class=\"accordion-item\">\r\n <button\r\n class=\"accordion-header\"\r\n (click)=\"toggle(i)\"\r\n [class.active]=\"item.open\"\r\n [disabled]=\"item.disabled\">\r\n\r\n <span>{{ item.title }}</span>\r\n <span class=\"icon\">{{ item.open ? '−' : '+' }}</span>\r\n </button>\r\n\r\n <div class=\"accordion-body\" [class.open]=\"item.open\">\r\n <div class=\"accordion-content\">\r\n {{ item.content }}\r\n </div>\r\n </div>\r\n </div>\r\n }\r\n</div>\r\n","/*\r\n * Public API Surface of accordian\r\n */\r\n\r\nexport * from './lib/accordian/accordian';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAiBa,SAAS,CAAA;;AAGX,IAAA,KAAK,GAA6B,EAAE,CAAC;AACrC,IAAA,QAAQ,GAAG,KAAK,CAAC;;AAG1B,IAAA,MAAM,CAAC,KAAa,EAAA;QAClB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;QACjC,IAAI,OAAO,CAAC,QAAQ;YAAE;AAEtB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAI;AACtC,YAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACjB,OAAO,CAAC,KAAK;sBACT,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI;sBAC3B,IAAI;YACV;YAEA,OAAO,CAAC,KAAK;kBACT,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI;kBAC3B,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE;AAC9B,QAAA,CAAC,CAAC;IACJ;uGAtBW,SAAS,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;2FAAT,SAAS,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,kBAAA,EAAA,MAAA,EAAA,EAAA,KAAA,EAAA,OAAA,EAAA,QAAA,EAAA,UAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,ECjBtB,qoBAqBA,EAAA,MAAA,EAAA,CAAA,ixCAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,UAAA,EAAA,IAAA,EDRY,YAAY,EAAA,CAAA,EAAA,CAAA;;2FAIX,SAAS,EAAA,UAAA,EAAA,CAAA;kBAPrB,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,kBAAkB,EAAA,UAAA,EAChB,IAAI,EAAA,OAAA,EACP,CAAC,YAAY,CAAC,EAAA,QAAA,EAAA,qoBAAA,EAAA,MAAA,EAAA,CAAA,ixCAAA,CAAA,EAAA;;sBAOtB;;sBACA;;;AErBH;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "simple-accordian",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^21.1.0",
|
|
6
|
+
"@angular/core": "^21.1.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"module": "fesm2022/accordian.mjs",
|
|
13
|
+
"typings": "types/accordian.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./types/accordian.d.ts",
|
|
20
|
+
"default": "./fesm2022/accordian.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"description": "a simple, mobile responsive accordian component to use by just passing the item's array and the property multiple to maintain whether single or multiple components can be open at the same time",
|
|
24
|
+
"main": "index.js",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"accordian"
|
|
30
|
+
],
|
|
31
|
+
"author": "Debdip",
|
|
32
|
+
"license": "ISC"
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
|
|
3
|
+
interface AccordionItemInterface {
|
|
4
|
+
title: string;
|
|
5
|
+
content: string;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare class Accordian {
|
|
10
|
+
items: AccordionItemInterface[];
|
|
11
|
+
multiple: boolean;
|
|
12
|
+
toggle(index: number): void;
|
|
13
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Accordian, never>;
|
|
14
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<Accordian, "simple-accordian", never, { "items": { "alias": "items"; "required": false; }; "multiple": { "alias": "multiple"; "required": false; }; }, {}, never, never, true, never>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { Accordian };
|
|
18
|
+
export type { AccordionItemInterface };
|