Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
"[jsonc]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
// Per-language defaults: a user-level [typescript]/[html] default (e.g. Prettier)
// beats the unscoped workspace default above, so pin oxc explicitly per language.
"[typescript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[html]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"[json]": {
"editor.defaultFormatter": "oxc.oxc-vscode"
},
"json.schemaDownload.trustedDomains": {
"https://schemastore.azurewebsites.net/": true,
"https://raw.githubusercontent.com/microsoft/vscode/": true,
Expand Down
6 changes: 3 additions & 3 deletions projects/dragone/ui/breadcrumb/src/breadcrumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { NgpBreadcrumbList, NgpBreadcrumbs } from 'ng-primitives/breadcrumbs';
import { injectDimensions } from 'ng-primitives/internal';

import { createNotifier, toElement } from '@dragone/ui/utils';
import { createNotifier, toNativeElement } from '@dragone/ui/utils';

import { BreadcrumbEllipsis } from './breadcrumb-ellipsis/breadcrumb-ellipsis';
import { BreadcrumbItem } from './breadcrumb-item/breadcrumb-item';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Breadcrumb {
constructor() {
const OVERFLOW_TOLERANCE_PX = 16;
afterRenderEffect(() => {
const listElement = toElement.untracked(this.breadcrumbListElement);
const listElement = toNativeElement.untracked(this.breadcrumbListElement);
const { width: hostWidth } = this.#hostDimensions();

if (!listElement || !hostWidth) return;
Expand All @@ -107,7 +107,7 @@ export class Breadcrumb {
const breadcrumbItems = this.breadcrumbItems();
if (!userExpanded || !breadcrumbItems.length) return;

toElement(breadcrumbItems.at(1))?.querySelector('a')?.focus();
toNativeElement(breadcrumbItems.at(1))?.querySelector('a')?.focus();
});
if (ngDevMode) {
effect(() => {
Expand Down
1 change: 1 addition & 0 deletions projects/dragone/ui/card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
6 changes: 6 additions & 0 deletions projects/dragone/ui/card/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "public-api.ts"
}
}
11 changes: 11 additions & 0 deletions projects/dragone/ui/card/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from './src/card';
export * from './src/card-header/card-header';
export * from './src/card-body/card-body';
export * from './src/card-title/card-title';
export * from './src/card-subtitle/card-subtitle';
export * from './src/card-text/card-text';
export * from './src/card-signature/card-signature';
export * from './src/card-footer/card-footer';
export * from './src/card-image/card-image';
export * from './src/card-tag/card-tag';
export * from './src/card-link/card-link';
24 changes: 24 additions & 0 deletions projects/dragone/ui/card/src/card-body/card-body.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:host {
display: flex;
flex: 1 1 auto;
flex-direction: column;
gap: var(--drgn-space-card-gap);
align-items: flex-start;
min-height: 1px;
padding: var(--drgn-space-card-padding);
}

:host([data-layout='mobile']) {
gap: var(--drgn-space-card-gap-mobile);
padding: var(--drgn-space-card-padding-mobile);
}

/* Portrait mobile keeps a roomier top padding. */
:host([data-type='portrait'][data-layout='mobile']) {
padding-top: var(--drgn-space-card-padding-mobile-top);
}

/* Landscape content is wider. */
:host([data-type='landscape']) {
padding-inline: var(--drgn-space-card-padding-inline-landscape);
}
23 changes: 23 additions & 0 deletions projects/dragone/ui/card/src/card-body/card-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component } from '@angular/core';

import { injectLayoutState } from '@dragone/ui/utils';

import { injectDrgnCardState } from '../card-state';

/**
* Card body: the padded content column of a Card. Padding and gap follow the parent Card `type` and
* `layout` — no inputs needed.
*/
@Component({
selector: 'drgn-card-body',
template: ` <ng-content /> `,
styleUrl: './card-body.css',
host: {
'[attr.data-type]': 'drgnCardState().type()',
'[attr.data-layout]': 'layoutState().layout()'
}
})
export class CardBody {
protected readonly drgnCardState = injectDrgnCardState();
protected readonly layoutState = injectLayoutState();
}
19 changes: 19 additions & 0 deletions projects/dragone/ui/card/src/card-footer/card-footer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
:host {
/* Footer actions must stay clickable above a `CardLink` stretched link. */
position: relative;
z-index: 2;
display: flex;
align-items: center;
gap: 10px;
width: 100%;
}

:host([data-type='landscape']),
:host([data-type='portrait']) {
justify-content: flex-end;
}

:host([data-type='process']) {
justify-content: flex-start;
gap: 12px;
}
30 changes: 30 additions & 0 deletions projects/dragone/ui/card/src/card-footer/card-footer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component } from '@angular/core';

import { injectLayoutState } from '@dragone/ui/utils';

import { injectDrgnCardState } from '../card-state';

/**
* Card footer: the actions row at the bottom of a Card body.
*
* - `portrait`/`landscape`: icon-only actions (e.g. share, bookmark), end-aligned.
* - `process`: a text button plus a single overflow action, start-aligned.
*
* The footer sits above a `CardLink` stretched link (if any), so footer actions stay clickable.
* Icon-only actions that open a menu are menu triggers owned by the consumer (see the `Dropdown`
* Sirio pattern): give them an accessible name plus `aria-haspopup="menu"` and `aria-expanded`
* (`aria-expanded="false"` until the menu opens) once a menu Component is composed in.
*/
@Component({
selector: 'drgn-card-footer',
template: ` <ng-content /> `,
styleUrl: './card-footer.css',
host: {
'[attr.data-type]': 'drgnCardState().type()',
'[attr.data-layout]': 'layoutState().layout()'
}
})
export class CardFooter {
protected readonly drgnCardState = injectDrgnCardState();
protected readonly layoutState = injectLayoutState();
}
32 changes: 32 additions & 0 deletions projects/dragone/ui/card/src/card-header/card-header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
:host {
display: flex;
align-items: center;
gap: 16px;
width: 100%;
overflow: clip;
}

:host([data-type='landscape']),
:host([data-type='portrait']) {
justify-content: space-between;
}

:host([data-type='process']) {
justify-content: flex-start;
}

/* The trailing slot carries the Sirio card date: keep it a short date string. */
::slotted([slot='trailing']) {
margin: 0;
font-family: var(--drgn-typography-font-family-number);
font-size: var(--drgn-typography-size-label-md);
line-height: var(--drgn-typography-line-height-label-md);
font-weight: var(--drgn-typography-weight-regular);
letter-spacing: var(--drgn-typography-letter-spacing-default);
color: var(--drgn-color-text-card-body);
white-space: nowrap;
}

:host-context([data-theme='dark']) ::slotted([slot='trailing']) {
color: var(--drgn-color-text-inverse);
}
32 changes: 32 additions & 0 deletions projects/dragone/ui/card/src/card-header/card-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Component } from '@angular/core';

import { injectLayoutState } from '@dragone/ui/utils';

import { injectDrgnCardState } from '../card-state';

/**
* Card header: the top row of a Card body.
*
* - `portrait`/`landscape`: a category tag (`CardTag`) plus the date, space-between.
* - `process`: a leading icon plus the date.
*
* Compose with `slot="leading"` (tag or icon) and `slot="trailing"` (date) content. The trailing
* slot is styled as the Sirio card date (monospace); project a short date, preferably a `<time
* datetime="...">` element so the date stays machine-readable.
*/
@Component({
selector: 'drgn-card-header',
template: `
<ng-content select="[slot='leading']" />
<ng-content select="[slot='trailing']" />
`,
styleUrl: './card-header.css',
host: {
'[attr.data-type]': 'drgnCardState().type()',
'[attr.data-layout]': 'layoutState().layout()'
}
})
export class CardHeader {
protected readonly drgnCardState = injectDrgnCardState();
protected readonly layoutState = injectLayoutState();
}
34 changes: 34 additions & 0 deletions projects/dragone/ui/card/src/card-image/card-image.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:host {
position: relative;
display: block;
overflow: hidden;
min-height: 220px;
border-radius: var(--drgn-radius-card) var(--drgn-radius-card) 0 0;
width: 100%;
}

:host img {
position: absolute;
top: 0;
left: 0;
height: 100%;
object-fit: cover;
}

/* Side image (landscape): fixed-width column stretching the full card height.
370px matches the Sirio landscape image width. */
:host([data-position='left']),
:host([data-position='right']) {
align-self: stretch;
width: 370px;
max-width: 45%;
min-height: auto;
}

:host([data-position='left']) {
border-radius: var(--drgn-radius-card) 0 0 var(--drgn-radius-card);
}

:host([data-position='right']) {
border-radius: 0 var(--drgn-radius-card) var(--drgn-radius-card) 0;
}
61 changes: 61 additions & 0 deletions projects/dragone/ui/card/src/card-image/card-image.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Component, input, signal } from '@angular/core';
import { render } from '@wismaz/vitest-browser-angular';

import { Card, type CardType } from '../card';
import { CardImage, type CardImagePosition } from './card-image';

@Component({
imports: [Card, CardImage],
template: `
<drgn-card [type]="type()">
<drgn-card-image
data-testid="image"
src="https://example.com/image.png"
alt="A descriptive image"
[position]="position()"
/>
</drgn-card>
`
})
class TestHostCardImage {
type = input<CardType>('portrait');
position = input<CardImagePosition | undefined>();
}

describe(CardImage, () => {
const src = signal('https://example.com/image.png');
const alt = signal('A descriptive image');

it('must render the image with src and alt', async () => {
const { locator } = await render(CardImage, { inputs: { src, alt } });
const img = locator.getByRole('img', { name: 'A descriptive image' });
await expect.element(img).toBeVisible();
await expect.element(img).toHaveAttribute('src', 'https://example.com/image.png');
});

it('must reflect the position on the host', async () => {
const { locator } = await render(CardImage, {
inputs: { src, alt, position: signal('left') }
});
await expect.element(locator).toHaveAttribute('data-position', 'left');
});

it('must default to top outside a landscape card', async () => {
const { locator } = await render(CardImage, { inputs: { src, alt } });
await expect.element(locator).toHaveAttribute('data-position', 'top');
});

it('must default to left inside a landscape card', async () => {
const { locator } = await render(TestHostCardImage, {
inputs: { type: signal('landscape') }
});
await expect.element(locator.getByTestId('image')).toHaveAttribute('data-position', 'left');
});

it('must let an explicit position win over the card type', async () => {
const { locator } = await render(TestHostCardImage, {
inputs: { type: signal('landscape'), position: signal('right') }
});
await expect.element(locator.getByTestId('image')).toHaveAttribute('data-position', 'right');
});
});
39 changes: 39 additions & 0 deletions projects/dragone/ui/card/src/card-image/card-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NgOptimizedImage } from '@angular/common';
import { Component, computed, input } from '@angular/core';

import { injectDrgnCardState } from '../card-state';

export type CardImagePosition = 'top' | 'left' | 'right';

/**
* Card image. When `position` is omitted it follows the parent Card `type` (`landscape` renders the
* image on the left, anything else on top), so consumers composing a `landscape` Card usually need
* no `position` at all.
*/
@Component({
selector: 'drgn-card-image',
imports: [NgOptimizedImage],
template: ` <img fill [ngSrc]="src()" [alt]="alt()" /> `,
styleUrl: './card-image.css',
host: {
'[attr.data-position]': 'resolvedPosition()'
}
})
export class CardImage {
/** The image source URL. */
readonly src = input.required<string>();
/** The accessible alternative text for the image. */
readonly alt = input.required<string>();
/**
* The image position within the card. When omitted it follows the parent Card type.
*
* @default parent Card type (`'left'` for `landscape`, `'top'` otherwise)
*/
readonly position = input<CardImagePosition>();

// No ng-primitives image primitive exists, so `NgOptimizedImage` is used directly.
private readonly drgnCardState = injectDrgnCardState({ optional: true });
protected readonly resolvedPosition = computed<CardImagePosition>(
() => this.position() ?? (this.drgnCardState?.()?.type() === 'landscape' ? 'left' : 'top')
);
}
13 changes: 13 additions & 0 deletions projects/dragone/ui/card/src/card-link/card-link.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:host {
position: absolute;
inset: 0;
z-index: 1;
cursor: pointer;
border-radius: var(--drgn-radius-card);
}

/* Full-card anchor: the parent Card clips overflow, so the focus ring renders inset. */
:host:focus-visible {
outline: 3px solid var(--drgn-color-focus-ring-interactive);
outline-offset: -3px;
}
Loading
Loading