Skip to content

Commit

Permalink
fix(tree): Center toggle icon with flex and not after (#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoOleksiyenko authored Dec 2, 2024
1 parent 798fc66 commit 06ef4c8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 27 deletions.
6 changes: 4 additions & 2 deletions angular/bootstrap/src/components/tree/tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class TreeItemToggleDirective {
template: `
<ng-template auTreeItemToggle #toggle let-directives="directives" let-item="item">
@if (item.children.length > 0) {
<button [auUse]="[directives.itemToggleDirective, {item}]"></button>
<button [auUse]="[directives.itemToggleDirective, {item}]">
<span class="au-tree-expand-icon-svg"></span>
</button>
} @else {
<span class="au-tree-expand-icon-placeholder"></span>
}
Expand Down Expand Up @@ -260,7 +262,7 @@ export class TreeComponent extends BaseWidgetDirective<TreeWidget> {
* () => {}
* ```
*/
@Output('auExpandToggle') expandToggle = new EventEmitter<TreeItem>();
@Output('auExpandToggle') expandToggle = new EventEmitter<NormalizedTreeItem>();

/**
* Slot to change the default tree item content
Expand Down
4 changes: 2 additions & 2 deletions core-bootstrap/src/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ $au-tree-expand-icon-background-color: transparent !default;
$au-tree-expand-icon-background-color-hover: var(--#{$prefix}blue-100, #cfe2ff) !default;
$au-tree-expand-icon-width: 2.25rem;
$au-tree-expand-icon-height: 2.25rem;
$au-tree-expand-icon-color-default: #0d6efd !default;
$au-tree-expand-icon-color: #0d6efd !default;
$au-tree-expand-icon-color-hover: #052c65 !default;
$au-tree-expand-icon-default: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 10 10"><path d="M3 1 L7 5 L3 9" stroke="#{$au-tree-expand-icon-color-default}" stroke-width="1" fill="none"/></svg>') !default;
$au-tree-expand-icon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 10 10"><path d="M3 1 L7 5 L3 9" stroke="#{$au-tree-expand-icon-color}" stroke-width="1" fill="none"/></svg>') !default;
$au-tree-expand-icon-hover: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 10 10"><path d="M3 1 L7 5 L3 9" stroke="#{$au-tree-expand-icon-color-hover}" stroke-width="1" fill="none"/></svg>') !default;
// scss-docs-end tree-vars
29 changes: 14 additions & 15 deletions core-bootstrap/src/scss/tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
--#{variables.$prefix}tree-expand-icon-background-color-hover: #{variables.$au-tree-expand-icon-background-color-hover};
--#{variables.$prefix}tree-expand-icon-width: #{variables.$au-tree-expand-icon-width};
--#{variables.$prefix}tree-expand-icon-height: #{variables.$au-tree-expand-icon-height};
--#{variables.$prefix}tree-expand-icon-default: #{functions.escape-svg(variables.$au-tree-expand-icon-default)};
--#{variables.$prefix}tree-expand-icon: #{functions.escape-svg(variables.$au-tree-expand-icon)};
--#{variables.$prefix}tree-expand-icon-hover: #{functions.escape-svg(variables.$au-tree-expand-icon-hover)};
// scss-docs-end tree-css-vars

Expand Down Expand Up @@ -44,33 +44,32 @@
}

.au-tree-expand-icon {
position: relative;
width: var(--#{variables.$prefix}tree-expand-icon-width);
height: var(--#{variables.$prefix}tree-expand-icon-height);
border-radius: var(--#{variables.$prefix}tree-expand-icon-border-radius);
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
padding-inline: 0;
margin-inline-end: var(--#{variables.$prefix}tree-expand-icon-margin-inline-end);
background-color: var(--#{variables.$prefix}tree-expand-icon-background-color);
cursor: pointer;

&:hover {
--#{variables.$prefix}tree-expand-icon-default: var(--#{variables.$prefix}tree-expand-icon-hover);
--#{variables.$prefix}tree-expand-icon: var(--#{variables.$prefix}tree-expand-icon-hover);
--#{variables.$prefix}tree-expand-icon-background-color: var(--#{variables.$prefix}tree-expand-icon-background-color-hover);
}
}

.au-tree-expand-icon::after {
position: absolute;
content: var(--#{variables.$prefix}tree-expand-icon-default);
transition: transform 0.3s;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.au-tree-expand-icon-svg {
content: var(--#{variables.$prefix}tree-expand-icon);
transition: transform 0.3s;
}

/* Expanded state */
.au-tree-expand-icon-expanded::after {
transform: translate(-55%, -50%) rotate(90deg);
&.au-tree-expand-icon-expanded {
.au-tree-expand-icon-svg {
transform: rotate(90deg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
class="au-tree-expand-icon au-tree-expand-icon-expanded"
tabindex="0"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1"
</span>
<ul
Expand All @@ -39,7 +43,11 @@
class="au-tree-expand-icon"
tabindex="-1"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1.1"
</span>
</li>
Expand All @@ -56,7 +64,11 @@
class="au-tree-expand-icon"
tabindex="-1"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1.2"
</span>
</li>
Expand Down
18 changes: 15 additions & 3 deletions e2e/ssr.ssr-e2e-spec.ts-snapshots/ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,11 @@ <h2>
class="au-tree-expand-icon au-tree-expand-icon-expanded"
tabindex="0"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1"
</span>
<ul
Expand All @@ -528,7 +532,11 @@ <h2>
class="au-tree-expand-icon"
tabindex="-1"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1.1"
</span>
</li>
Expand All @@ -545,7 +553,11 @@ <h2>
class="au-tree-expand-icon"
tabindex="-1"
type="button"
/>
>
<span
class="au-tree-expand-icon-svg"
/>
</button>
"Node 1.2"
</span>
</li>
Expand Down
6 changes: 5 additions & 1 deletion react/bootstrap/src/components/tree/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {createTree} from './tree.gen';
import classNames from 'classnames';

const ToggleButtonDisplay = ({directive, item}: {directive: TreeDirectives['itemToggleDirective']; item: NormalizedTreeItem}) => {
return <button {...useDirective(directive, {item})}></button>;
return (
<button {...useDirective(directive, {item})}>
<span className="au-tree-expand-icon-svg"></span>
</button>
);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

{#if item.children.length > 0}
<!-- svelte-ignore a11y_consider_explicit_label -->
<button use:directives.itemToggleDirective={{item: item}}></button>
<button use:directives.itemToggleDirective={{item: item}}>
<span class="au-tree-expand-icon-svg"></span>
</button>
{:else}
<span class="au-tree-expand-icon-placeholder"></span>
{/if}

0 comments on commit 06ef4c8

Please sign in to comment.