Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"lib": {
"entryFile": "src/index.ts",
"styleIncludePaths": ["../../../internal/scss"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SectionLink } from './lib/section-link';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@if (anchor()) {
<span class="link-container">
<a mat-icon-button class="link" aria-label="Link to this heading" [attr.href]="`#${anchor()}`">
<mat-icon class="icon">link</mat-icon>
</a>
</span>
}

<div class="content">
<ng-content />
</div>

@if (underlined()) {
<mat-divider />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@use 'sass:map';
@use 'token-utils';

$level-configs: (
1: (
font: var(token-utils.sys-token(display-medium)),
link-offset: 7px,
margin: 0.5rem,
),
2: (
font: var(token-utils.sys-token(display-small)),
link-offset: 2px,
margin: 0.375rem,
),
3: (
font: var(token-utils.sys-token(headline-large)),
link-offset: 0,
margin: 0.5rem,
),
4: (
font: var(token-utils.sys-token(headline-medium)),
link-offset: -2px,
margin: 0.25rem,
),
5: (
font: var(token-utils.sys-token(headline-small)),
link-offset: -5px,
margin: 0.25rem,
),
6: (
font: var(token-utils.sys-token(title-large)),
link-offset: -6px,
margin: 0.25rem,
),
);

$color-config: (
divider-color: var(token-utils.sys-token(outline)),
text-color: var(token-utils.sys-token(on-background)),
);

:host {
display: block;
margin: 0;

.link-container {
display: inline-block;
vertical-align: top;
height: 0;
line-height: 1;

.link {
position: relative;
margin-left: calc(-2.5rem - 5px);

.icon {
visibility: hidden;
}

&:focus-visible .icon {
visibility: visible;
}
}
}

.content {
display: inline-block;
color: map.get($color-config, text-color);
}

&:hover .link-container .link .icon {
visibility: visible;
}

mat-divider {
border-color: map.get($color-config, divider-color);
}

@media (max-width: 639.9999px) {
.link-container {
display: none;
}
}

@each $level, $config in $level-configs {
&h#{$level} {
font: map.get($config, font);

.link-container .link {
top: map.get($config, link-offset);
}

mat-divider {
margin-top: map.get($config, margin);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SectionLink } from './section-link';

describe('SectionLink', () => {
let component: SectionLink;
let fixture: ComponentFixture<SectionLink>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SectionLink],
}).compileComponents();

fixture = TestBed.createComponent(SectionLink);
component = fixture.componentInstance;
await fixture.whenStable();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Meta, StoryObj } from '@storybook/angular';
import { SectionLink } from './section-link';

interface ExtraArgs {
level: number;
content: string;
}

function clampLevel(level: number): number {
level = Math.max(level, 1);
level = Math.min(level, 6);
return level;
}

const meta: Meta<SectionLink & ExtraArgs> = {
component: SectionLink,
title: 'Design System/Content Templates/Section Link',
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/design/BCEJn9KCIbBJ5MzqnojKQp/AtlasNG-Components?node-id=2355-1046',
},
},
args: {
level: 1,
anchor: 'anchor',
underlined: false,
},
render: (args) => ({
props: args,
styles: ['[ang-section-link] { margin: 0 2rem; }'],
template: `<h${clampLevel(args.level)} ang-section-link anchor="${args.anchor}" underlined="${args.underlined}">
${args.content}
</h${clampLevel(args.level)}>`,
}),
};

export default meta;
type Story = StoryObj<SectionLink & ExtraArgs>;

export const Default: Story = {
render: (args) => ({
props: args,
styles: ['[ang-section-link] { margin: 0 2rem; }'],
template: `<h${clampLevel(args.level)} ang-section-link anchor="${args.anchor}" underlined="${args.underlined}">
Heading ${clampLevel(args.level)}
</h${clampLevel(args.level)}>`,
}),
};

export const LongText: Story = {
args: {
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris.',
},
};

export const Underlined: Story = {
args: {
content: 'Underlined Section Link',
underlined: true,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { booleanAttribute, ChangeDetectionStrategy, Component, input } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';

@Component({
selector:
// eslint-disable-next-line @angular-eslint/component-selector
`h1[ang-section-link], h2[ang-section-link], h3[ang-section-link],
h4[ang-section-link], h5[ang-section-link], h6[ang-section-link]`,
imports: [MatDividerModule, MatIconModule, MatButtonModule],
templateUrl: './section-link.html',
styleUrl: './section-link.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SectionLink {
/** Anchor for href */
readonly anchor = input<string>();

/** Whether to display the underline */
readonly underlined = input(false, { transform: booleanAttribute });
}
5 changes: 4 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@
"preVersionCommand": "npx nx run-many -t build --projects=tag:library",
"manifestRootsToUpdate": [
"{projectRoot}",
{ "path": "{workspaceRoot}/dist/{projectRoot}", "preserveLocalDependencyProtocols": false }
{
"path": "{workspaceRoot}/dist/{projectRoot}",
"preserveLocalDependencyProtocols": false
}
],
"currentVersionResolver": "git-tag",
"fallbackCurrentVersionResolver": "disk"
Expand Down
Loading