Skip to content

Commit

Permalink
feat: enhance ngx-dev-toolbar with new card components and layout imp…
Browse files Browse the repository at this point in the history
…rovements

- Introduced new card components: DevToolbarCardComponent and DevToolbarClickableCardComponent for better UI representation.
- Added link button component (DevToolbarLinkButtonComponent) for external links with icons.
- Updated home tool layout to include clickable cards for exporting and importing settings.
- Enhanced styling for various components to improve visual consistency and user experience.
- Updated project configuration to include new assets and styles for better organization.
  • Loading branch information
alfredoperez committed Jan 20, 2025
1 parent 282d931 commit 409ea9c
Show file tree
Hide file tree
Showing 12 changed files with 16,984 additions and 42 deletions.
6 changes: 3 additions & 3 deletions apps/ngx-dev-toolbar-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
{
"glob": "**/*",
"input": "apps/ngx-dev-toolbar-demo/public"
}
},
"apps/ngx-dev-toolbar-demo/src/assets"
],
"styles": ["apps/ngx-dev-toolbar-demo/src/styles.scss"],
"scripts": [],
"assets": ["apps/ngx-dev-toolbar-demo/src/assets"]
"scripts": []
},
"configurations": {
"production": {
Expand Down
18 changes: 18 additions & 0 deletions libs/ngx-dev-toolbar/src/components/card/card.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.card {
background: var(--ndt-bg-primary);
border-radius: var(--ndt-border-radius-large);
padding: var(--ndt-spacing-md);
cursor: pointer;
transition: var(--ndt-transition-default);
border: 1px solid var(--ndt-border-subtle);
position: relative;
flex: 1;
height: 120px;
display: flex;

&:hover {
background: var(--ndt-hover-bg);
border-color: var(--ndt-primary);
box-shadow: 0 0 0 1px rgba(var(--ndt-primary-rgb), 0.3);
}
}
30 changes: 30 additions & 0 deletions libs/ngx-dev-toolbar/src/components/card/card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, signal } from '@angular/core';

@Component({
selector: 'ndt-card',
standalone: true,
template: `
<div
class="card"
role="button"
tabindex="0"
(click)="onClick()"
(keydown.enter)="onClick()"
(keydown.space)="onClick()"
[class.card--hover]="isHovered()"
(mouseenter)="isHovered.set(true)"
(mouseleave)="isHovered.set(false)"
>
<ng-content></ng-content>
</div>
`,
styleUrls: ['./card.component.scss'],
})
export class DevToolbarCardComponent {
readonly click = signal<void>(undefined);
protected readonly isHovered = signal(false);

onClick(): void {
this.click.set();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.clickable-card {
display: flex;
flex-direction: column;
gap: var(--ndt-spacing-sm);
height: 100%;

&__icon {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: var(--ndt-border-radius-medium);
background: var(--ndt-hover-bg);
color: var(--ndt-text-primary);
}

&__content {
display: flex;
flex-direction: column;
gap: var(--ndt-spacing-xs);
}

&__title {
color: var(--ndt-text-primary);
font-size: var(--ndt-font-size-sm);
font-weight: 500;
}

&__subtitle {
color: var(--ndt-text-muted);
font-size: var(--ndt-font-size-xs);
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, input, signal } from '@angular/core';
import { DevToolbarCardComponent } from '../card/card.component';
import { DevToolbarIconComponent } from '../icons/icon.component';
import { IconName } from '../icons/icon.models';

@Component({
selector: 'ndt-clickable-card',
standalone: true,
imports: [DevToolbarCardComponent, DevToolbarIconComponent],
template: `
<ndt-card (clicked)="onClick()">
<div class="clickable-card">
<div class="clickable-card__icon">
<ndt-icon [name]="icon()" />
</div>
<div class="clickable-card__content">
<div class="clickable-card__title">{{ title() }}</div>
<div class="clickable-card__subtitle">{{ subtitle() }}</div>
</div>
</div>
</ndt-card>
`,
styleUrls: ['./clickable-card.component.scss'],
})
export class DevToolbarClickableCardComponent {
readonly icon = input.required<IconName>();
readonly title = input.required<string>();
readonly subtitle = input.required<string>();
readonly clicked = signal<void>(undefined);

onClick(): void {
this.clicked.set();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.link-button {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--ndt-spacing-xs);
text-decoration: none;
color: var(--ndt-text-muted);
transition: var(--ndt-transition-default);
min-width: 80px;

&:hover {
color: var(--ndt-text-primary);

.link-button__icon {
outline: 2px solid var(--ndt-primary);
outline-offset: 2px;
box-shadow: 0 0 8px var(--ndt-primary);
}
}

&__icon {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: var(--ndt-border-radius-medium);
background: var(--ndt-hover-bg);
transition: all 0.2s ease-in-out;
}

&__text {
font-size: var(--ndt-font-size-xs);
text-align: center;
white-space: nowrap;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, input } from '@angular/core';
import { DevToolbarIconComponent } from '../icons/icon.component';
import { IconName } from '../icons/icon.models';

@Component({
selector: 'ndt-link-button',
standalone: true,
imports: [DevToolbarIconComponent],
template: `
<a
[href]="url()"
target="_blank"
rel="noopener noreferrer"
class="link-button"
>
<div class="link-button__icon">
<ndt-icon [name]="icon()" />
</div>
<span class="link-button__text">
<ng-content></ng-content>
</span>
</a>
`,
styleUrls: ['./link-button.component.scss'],
})
export class DevToolbarLinkButtonComponent {
readonly url = input.required<string>();
readonly icon = input.required<IconName>();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { animate, style, transition, trigger } from '@angular/animations';
import { CdkConnectedOverlay, OverlayModule } from '@angular/cdk/overlay';
import {
ChangeDetectionStrategy,
Expand Down Expand Up @@ -35,7 +36,7 @@ import { DevToolbarWindowOptions } from './toolbar-tool.models';
(keydown.space)="onOpen()"
tabindex="0"
>
<div [attr.data-tooltip]="title()">
<div #buttonContainer [attr.data-tooltip]="title()">
@if (icon()) {
<ndt-tool-button [title]="title()" [toolId]="options().id">
<ndt-icon [name]="icon()" />
Expand All @@ -56,7 +57,7 @@ import { DevToolbarWindowOptions } from './toolbar-tool.models';
[cdkConnectedOverlayHeight]="height()"
cdkConnectedOverlay
>
<ndt-window [config]="options()" (close)="onClose()">
<ndt-window [@slideAnimation] [config]="options()" (close)="onClose()">
<ng-content />
</ndt-window>
</ng-template>
Expand All @@ -65,10 +66,40 @@ import { DevToolbarWindowOptions } from './toolbar-tool.models';
`,
styleUrl: './toolbar-tool.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('slideAnimation', [
transition(':enter', [
style({
transform: 'translateY(20px)',
opacity: 0,
}),
animate(
'400ms cubic-bezier(0.4, 0, 0.2, 1)',
style({
transform: 'translateY(0)',
opacity: 1,
})
),
]),
transition(':leave', [
style({
transform: 'translateY(0)',
opacity: 1,
}),
animate(
'400ms cubic-bezier(0.4, 0, 0.2, 1)',
style({
transform: 'translateY(20px)',
opacity: 0,
})
),
]),
]),
],
})
export class DevToolbarToolComponent {
state = inject(DevToolbarStateService);
@ViewChild('trigger') trigger!: ElementRef;
@ViewChild('buttonContainer') buttonContainer!: ElementRef;

@ContentChild(DevToolbarToolButtonComponent)
buttonComponent!: DevToolbarToolButtonComponent;
Expand Down Expand Up @@ -106,15 +137,21 @@ export class DevToolbarToolComponent {
return 400;
}
});
positions = computed(() => [
{
originX: 'center' as const,
originY: 'center' as const,
overlayX: 'center' as const,
overlayY: 'center' as const,
offsetY: -(Math.ceil(this.height() / 2) + 36),
},
]);
positions = computed(() => {
const triggerXPosition = this.getButtonContainerXPosition();
const windowCenter = window.innerWidth / 2;
const offsetX = windowCenter - triggerXPosition - 22;
return [
{
originX: 'center' as const,
originY: 'center' as const,
overlayX: 'center' as const,
overlayY: 'center' as const,
offsetY: -(Math.ceil(this.height() / 2) + 36),
offsetX,
},
];
});

onOpen(): void {
this.state.setActiveTool(this.options().id);
Expand All @@ -123,4 +160,10 @@ export class DevToolbarToolComponent {
onClose(): void {
this.state.setActiveTool(null);
}

getButtonContainerXPosition(): number {
const buttonContainerRect =
this.buttonContainer?.nativeElement?.getBoundingClientRect();
return buttonContainerRect?.left ?? 0;
}
}
56 changes: 30 additions & 26 deletions libs/ngx-dev-toolbar/src/tools/home-tool/home-tool.component.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
@use '../../styles' as *;

.settings {
padding: var(--ndt-spacing-md);
display: flex;
flex-direction: column;
justify-content: space-between;
min-height: 100%;
}

.instruction {
display: flex;
justify-content: space-between;
align-items: center;
align-items: flex-start;
gap: var(--ndt-spacing-md);
padding-block: var(--ndt-spacing-md);
border-bottom: 1px solid var(--ndt-border-subtle);

&__label {
display: flex;
Expand All @@ -26,36 +31,35 @@
font-size: var(--ndt-font-size-xs);
}
}

&__control {
flex: 1;
}
}

.theme {
display: flex;
gap: var(--ndt-spacing-xs);
justify-content: flex-end;
}

&__button {
display: flex;
align-items: center;
justify-content: center;
padding: var(--ndt-spacing-xs);
border-radius: var(--ndt-border-radius-small);
border: 1px solid var(--ndt-border-subtle);
background: var(--ndt-bg-primary);
color: var(--ndt-text-primary);
cursor: pointer;
transition: var(--ndt-transition-default);

&:hover {
background: var(--ndt-hover-bg);
}

&--active {
background: var(--ndt-primary);
color: var(--ndt-text-on-primary);
border-color: var(--ndt-primary);
.settings-actions {
display: flex;
gap: var(--ndt-spacing-md);
padding-block: var(--ndt-spacing-md);

&:hover {
background: var(--ndt-primary);
}
}
> * {
width: 50%;
min-width: 0;
}
}

.footer-links {
border-top: 1px solid var(--ndt-border-subtle);
padding-top: 1em;
display: flex;
flex-direction: row;
justify-content: space-between;
gap: var(--ndt-spacing-lg);
// padding-block: var(--ndt-spacing-md);
}
Loading

0 comments on commit 409ea9c

Please sign in to comment.