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

fix(core/tree-item): replace with tree-item custom properties #66

Merged
merged 5 commits into from
Oct 18, 2022
Merged
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
30 changes: 28 additions & 2 deletions packages/angular-test-app/src/preview-examples/tree-custom.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
*/

import { Component } from '@angular/core';
import { TreeModel } from '@siemens/ix';
import { TreeContext, TreeModel } from '@siemens/ix';

type TreeData = {
name: string;
@@ -28,7 +28,19 @@ type TreeData = {
`,
],
template: `<div class="example">
<ix-tree root="root" [model]="model" [renderItem]="treeItem"></ix-tree>
<ix-button
id="expand"
ghost
style="margin-bottom: 2rem"
(click)="expandAndSelect()"
>Expand Tree</ix-button
>
<ix-tree
root="root"
[model]="model"
[context]="context"
[renderItem]="treeItem"
></ix-tree>
<ng-template #treeItem let-item>
<div class="d-flex align-items-center">
<ix-icon [name]="item.icon" size="16" class="me-2"></ix-icon>
@@ -38,6 +50,7 @@ type TreeData = {
</div>`,
})
export class TreeCustom {
context: TreeContext = {};
model: TreeModel<TreeData> = {
root: {
id: 'root',
@@ -76,4 +89,17 @@ export class TreeCustom {
children: [],
},
};

expandAndSelect() {
this.context = {
sample: {
isExpanded: true,
isSelected: false,
},
'sample-child-2': {
isSelected: true,
isExpanded: false,
},
};
}
}
32 changes: 16 additions & 16 deletions packages/angular/src/tree/tree.ts
Original file line number Diff line number Diff line change
@@ -8,22 +8,22 @@
*/

import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EmbeddedViewRef,
EventEmitter,
Input,
NgZone,
OnDestroy,
TemplateRef
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EmbeddedViewRef,
EventEmitter,
Input,
NgZone,
OnDestroy,
TemplateRef,
} from '@angular/core';
import type {
Components,
TreeContext as ICwTreeTreeContext,
TreeContext,
UpdateCallback
Components,
TreeContext as ICwTreeTreeContext,
TreeContext,
UpdateCallback,
} from '@siemens/ix';
import { Subscription } from 'rxjs';
import { ProxyCmp, proxyOutputs } from './../angular-component-lib/utils';
@@ -95,7 +95,7 @@ export class IxTree implements OnDestroy {
) => {
const treeItem = document.createElement('ix-tree-item');
treeItem.hasChildren = itemData.hasChildren;
treeItem.context = context as any;
treeItem.context = context[itemData.id];

const embeddedView = templateRef.createEmbeddedView({
$implicit: itemData.data,
@@ -105,7 +105,7 @@ export class IxTree implements OnDestroy {
embeddedView.detectChanges();

update((itemData, context) => {
treeItem.context = context as any;
treeItem.context = context[itemData.id];
treeItem.hasChildren = itemData.hasChildren;

embeddedView.context = {
16 changes: 13 additions & 3 deletions packages/core/src/components/tree-item/tree-item.scss
Original file line number Diff line number Diff line change
@@ -24,17 +24,27 @@
&:not(.disabled):not(:disabled):not(.selected) {
&.hover,
&:hover {
background-color: var(--theme-ghost-hover);
background-color: var(--theme-tree-item--background--hover);
}

&.active,
&:active {
background-color: var(--theme-ghost-pressed);
background-color: var(--theme-tree-item--background--active);
}
}

&.selected {
background-color: var(--theme-ghost-selected);
background-color: var(--theme-tree-item--background--selected);

&.hover,
&:hover {
background-color: var(--theme-tree-item--background--selected-hover);
}

&.active,
&:active {
background-color: var(--theme-tree-item--background--selected-active);
}
}

.tree-node-container {
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ SPDX-License-Identifier: MIT
*/

import { Component } from '@angular/core';
import { TreeModel } from '@siemens/ix';
import { TreeContext, TreeModel } from '@siemens/ix';

type TreeData = {
name: string;
@@ -36,7 +36,19 @@ type TreeData = {
`,
],
template: `<div class="example">
<ix-tree root="root" [model]="model" [renderItem]="treeItem"></ix-tree>
<ix-button
id="expand"
ghost
style="margin-bottom: 2rem"
(click)="expandAndSelect()"
>Expand Tree</ix-button
>
<ix-tree
root="root"
[model]="model"
[context]="context"
[renderItem]="treeItem"
></ix-tree>
<ng-template #treeItem let-item>
<div class="d-flex align-items-center">
<ix-icon [name]="item.icon" size="16" class="me-2"></ix-icon>
@@ -46,6 +58,7 @@ type TreeData = {
</div>`,
})
export class TreeCustom {
context: TreeContext = {};
model: TreeModel<TreeData> = {
root: {
id: 'root',
@@ -84,5 +97,18 @@ export class TreeCustom {
children: [],
},
};

expandAndSelect() {
this.context = {
sample: {
isExpanded: true,
isSelected: false,
},
'sample-child-2': {
isSelected: true,
isExpanded: false,
},
};
}
}
```
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ SPDX-License-Identifier: MIT
* LICENSE file in the root directory of this source tree.
*/

import { TreeModel } from '@siemens/ix';
import { IxIcon, IxTree } from '@siemens/ix-react';
import { TreeContext, TreeModel } from '@siemens/ix';
import { IxButton, IxIcon, IxTree } from '@siemens/ix-react';
import React, { useState } from 'react';

type TreeData = {
@@ -25,6 +25,7 @@ type TreeData = {
};

export const TreeCustom: React.FC = () => {
const [context, setContext] = useState<TreeContext>();
const [model] = useState<TreeModel<TreeData>>({
root: {
id: 'root',
@@ -63,6 +64,20 @@ export const TreeCustom: React.FC = () => {
children: [],
},
});

function expandAndSelect() {
setContext({
sample: {
isExpanded: true,
isSelected: false,
},
'sample-child-2': {
isSelected: true,
isExpanded: false,
},
});
}

return (
<div
style={{
@@ -72,9 +87,20 @@ export const TreeCustom: React.FC = () => {
height: '40rem',
}}
>
<IxButton
onClick={expandAndSelect}
ghost
style={{ marginBottom: '2rem' }}
>
Expand Tree
</IxButton>
<IxTree
root="root"
model={model}
context={context}
onContextChange={({ detail }) => {
setContext(detail);
}}
renderItem={(data: TreeData) => (
<div className="d-flex align-items-center">
<IxIcon name={data.icon} size="16" className="me-2" /> {data.name}
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ SPDX-License-Identifier: MIT
```html

<div style="height: 8rem; width: 100%">
<ix-button id="expand" ghost style="margin-bottom: 2rem"
>Expand Tree</ix-button
>
<ix-tree root="root" id="tree"></ix-tree>
</div>

@@ -16,10 +19,24 @@ SPDX-License-Identifier: MIT
await window.customElements.whenDefined('ix-tree');
const tree = document.getElementById('tree');

const expandButton = document.getElementById('expand');
expandButton.addEventListener('click', () => {
tree.context = {
sample: {
isExpanded: true,
isSelected: false,
},
'sample-child-2': {
isSelected: true,
isExpanded: false,
},
};
});

tree.renderItem = (index, item, dataList, context, update) => {
const el = document.createElement('ix-tree-item');
el.hasChildren = item.hasChildren;
el.context = context;
el.context = context[item.id];

const div = document.createElement('div');
div.style.display = 'flex';
1 change: 1 addition & 0 deletions packages/html-test-app/package.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"start": "vite",
"build": "vite build",
"preview": "vite preview"
},
19 changes: 18 additions & 1 deletion packages/html-test-app/src/preview-examples/tree-custom.html
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@
<!-- Preview code -->

<div style="height: 8rem; width: 100%">
<ix-button id="expand" ghost style="margin-bottom: 2rem"
>Expand Tree</ix-button
>
<ix-tree root="root" id="tree"></ix-tree>
</div>

@@ -21,10 +24,24 @@
await window.customElements.whenDefined('ix-tree');
const tree = document.getElementById('tree');

const expandButton = document.getElementById('expand');
expandButton.addEventListener('click', () => {
tree.context = {
sample: {
isExpanded: true,
isSelected: false,
},
'sample-child-2': {
isSelected: true,
isExpanded: false,
},
};
});

tree.renderItem = (index, item, dataList, context, update) => {
const el = document.createElement('ix-tree-item');
el.hasChildren = item.hasChildren;
el.context = context;
el.context = context[item.id];

const div = document.createElement('div');
div.style.display = 'flex';
Loading