
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
ion-cdk-tree-select
Advanced tools
An Angular component that combines the power of Angular CDK Tree and Ionic components to create a customizable, tree-structured selection list. It allows for dynamic icon sizes, font sizes, and style customizations, making it suitable for a wide range of
An Angular component that combines the power of Angular CDK Tree and Ionic components to create a customizable, tree-structured selection list. It allows for dynamic icon sizes, font sizes, and style customizations, making it suitable for a wide range of applications.
@Input
propertiesInstall the package via NPM:
npm install ion-cdk-tree-select
In your app.module.ts
, import IonCdkTreeSelectModule
:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonCdkTreeSelectModule } from 'ion-cdk-tree-select';
import { IonicModule } from '@ionic/angular';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, IonicModule.forRoot(), IonCdkTreeSelectModule],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
In your component template:
<cdk-tree-select
[data]="treeData"
[iconSize]="'large'"
[fontSize]="'16px'"
(selectChangeEvent)="onSelectChange($event)"
></cdk-tree-select>
In your component class:
import { Component } from '@angular/core';
import { TodoItem } from 'ion-cdk-tree-select';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage {
treeData: TodoItem[] = [
{ id: 1, name: 'Furniture' },
{ id: 2, name: 'Tables', parentId: 1 },
// ... more data
];
onSelectChange(selectedItems: TodoItem[]) {
console.log('Selected items:', selectedItems);
}
}
In your component file, import CdkTreeSelectComponent
and necessary Ionic modules:
import { Component } from '@angular/core';
import { CdkTreeSelectComponent, TodoItem } from 'ion-cdk-tree-select';
import {
IonicModule,
IonContent,
IonHeader,
IonToolbar,
IonTitle,
} from '@ionic/angular';
@Component({
selector: 'app-home',
standalone: true,
imports: [
IonicModule,
CdkTreeSelectComponent,
IonContent,
IonHeader,
IonToolbar,
IonTitle,
],
templateUrl: 'home.page.html',
})
export class HomePage {
// Same as before
}
Same as in the NgModule version.
Input | Type | Default | Description |
---|---|---|---|
data | TodoItem[] | [] | The data source for the tree. |
buttonSize | 'default' | 'large' | 'small' | undefined | 'default' | Size of the expand/collapse button. |
buttonColor | string | 'medium' | Color of the expand/collapse button. Accepts any valid Ionic color. |
iconSize | 'small' | 'default' | 'large' | 'default' | Size of the icons used in the expand/collapse button. |
fontSize | string | 'inherit' | Font size of the text labels. Accepts any valid CSS font-size value (e.g., '16px' , '1em' , 'larger' ). |
expandedIconName | string | 'chevron-down' | Icon name to display when a node is expanded. Must be a valid Ionicon name. |
collapsedIconName | string | 'chevron-forward' | Icon name to display when a node is collapsed. Must be a valid Ionicon name. |
nodePadding | string | '40px' | Padding applied to child nodes. |
Output | Type | Description |
---|---|---|
selectChangeEvent | EventEmitter<TodoItem[]> | Emits the list of selected items whenever the selection changes. |
The TodoItem
interface represents each node in the tree.
export interface TodoItem {
id: number;
name: string;
parentId?: number;
selected?: boolean;
expanded?: boolean;
children?: TodoItem[];
}
id
: Unique identifier for the node.name
: Display name of the node.parentId
: id
of the parent node (if any).selected
: Whether the node is selected.expanded
: Whether the node is expanded.children
: Array of child TodoItem
nodes.The component comes with default styles but allows for extensive customization.
You can override styles by using the following methods:
@Input()
PropertiesProperties like fontSize
, iconSize
, and nodePadding
allow you to adjust styles directly.
Example:
<cdk-tree-select
[data]="treeData"
fontSize="14px"
nodePadding="30px"
></cdk-tree-select>
The component uses some CSS variables, which you can override in your global styles or component-specific styles.
Example:
:root {
--tree-node-padding: 50px;
}
As a last resort, you can use deep selectors to override styles:
cdk-tree-select ::ng-deep .tree-node {
background-color: #f9f9f9;
}
Note: Use deep selectors cautiously, as they may affect encapsulation and maintenance.
<cdk-tree-select
[data]="treeData"
(selectChangeEvent)="onSelectChange($event)"
></cdk-tree-select>
<cdk-tree-select
[data]="treeData"
[iconSize]="'large'"
[fontSize]="'18px'"
[expandedIconName]="'caret-down-outline'"
[collapsedIconName]="'caret-forward-outline'"
(selectChangeEvent)="onSelectChange($event)"
></cdk-tree-select>
Note: Ensure the custom icons are registered using addIcons
from ionicons
.
import { addIcons } from 'ionicons';
import { caretDownOutline, caretForwardOutline } from 'ionicons/icons';
addIcons({
'caret-down-outline': caretDownOutline,
'caret-forward-outline': caretForwardOutline,
});
<cdk-tree-select
[data]="treeData"
[nodePadding]="'60px'"
></cdk-tree-select>
Contributions are welcome! Please submit a pull request or open an issue to discuss changes.
Clone the repository and install dependencies:
git clone https://github.com/your-username/ion-cdk-tree-select.git
cd ion-cdk-tree-select
npm install
Run the development server:
npm start
This project is licensed under the MIT License.
FAQs
An Angular component that combines Angular CDK Tree and Ionic components to create a customizable, tree-structured selection list.
We found that ion-cdk-tree-select demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.