-
Notifications
You must be signed in to change notification settings - Fork 0
Navigation button #65
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
4791156
c94a7ed
7769f1b
58acfef
9f758f2
c6ae450
2e08375
74d7903
957673c
5a19700
2fc1ad4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "lib": { | ||
| "cssUrl": "inline", | ||
| "entryFile": "src/index.ts", | ||
| "styleIncludePaths": ["../../src/sass"] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { Navigation } from './lib/navigation'; | ||
| export { NavigationToggle } from './lib/navigation-toggle/navigation-toggle'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <button matButton angTrackClick class="ang-navigation-toggle-button" disableRipple> | ||
| <span class="ang-navigation-toggle-text"><ng-content /></span> | ||
|
|
||
| <mat-icon | ||
| iconPositionEnd | ||
| class="ang-navigation-toggle-icon" | ||
| [fontIcon]="selected() ? 'expand_less' : 'expand_more'" | ||
| /> | ||
| </button> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| @use '@angular/material' as mat; | ||
| @use 'internal/token-utils'; | ||
| @use '../tokens' as *; | ||
|
|
||
| :host { | ||
| display: block; | ||
|
|
||
| @include mat.button-overrides( | ||
| ( | ||
| text-container-height: 3rem, | ||
| text-label-text-color: token-utils.slot(label-color, $config), | ||
| text-icon-spacing: 0.125rem, | ||
| text-label-text-font: token-utils.slot(label-font, $config), | ||
| text-label-text-size: token-utils.slot(label-font-size, $config), | ||
| text-label-text-tracking: token-utils.slot(label-letter-spacing, $config), | ||
| text-label-text-weight: token-utils.slot(label-font-weight, $config), | ||
| text-with-icon-horizontal-padding: 0.75rem, | ||
| text-state-layer-color: transparent, | ||
| ) | ||
| ); | ||
|
|
||
| @include mat.icon-overrides( | ||
| ( | ||
| color: token-utils.slot(icon-color, $config), | ||
| ) | ||
| ); | ||
|
|
||
| .ang-navigation-toggle-button { | ||
| &:focus-visible { | ||
| outline: solid 0.125rem token-utils.slot(focus-outline-color, $config); | ||
| } | ||
|
|
||
| :is(&.selected, &:hover, &:active, &:focus) { | ||
| .ang-navigation-toggle-text { | ||
| text-decoration: underline; | ||
| text-underline-offset: 0.25rem; | ||
| text-decoration-thickness: 0.125rem; | ||
| text-decoration-color: token-utils.slot(underline-color, $config); | ||
| } | ||
| } | ||
|
|
||
| .ang-navigation-toggle-icon { | ||
| height: 1.25rem; | ||
| width: 1.25rem; | ||
| font-size: 1.25rem; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { render, screen } from '@testing-library/angular'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { NavigationToggle } from './navigation-toggle'; | ||
|
|
||
| describe('NavigationToggle', () => { | ||
| async function setup(link: string | null = null) { | ||
| const user = userEvent.setup(); | ||
| const rendered = await render(`<ang-navigation-toggle>Category</ang-navigation-toggle>`, { | ||
| imports: [NavigationToggle], | ||
| componentProperties: { | ||
| link, | ||
| }, | ||
| }); | ||
|
|
||
| return { | ||
| user, | ||
| ...rendered, | ||
| }; | ||
| } | ||
|
|
||
| it('toggles state when clicked', async () => { | ||
| const { user } = await setup(); | ||
| const toggle = screen.getByText('Category').closest('.ang-navigation-toggle-button'); | ||
|
|
||
| expect(toggle).toBeTruthy(); | ||
|
|
||
| const icon = toggle?.querySelector('.ang-navigation-toggle-icon'); | ||
|
|
||
| expect(icon).toHaveAttribute('data-mat-icon-name', 'expand_more'); | ||
|
|
||
| await user.click(toggle as Element); | ||
| expect(icon).toHaveAttribute('data-mat-icon-name', 'expand_less'); | ||
|
|
||
| await user.click(toggle as Element); | ||
| expect(icon).toHaveAttribute('data-mat-icon-name', 'expand_more'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Meta, StoryObj } from '@storybook/angular'; | ||
| import { NavigationToggle } from './navigation-toggle'; | ||
|
|
||
| const meta: Meta<NavigationToggle> = { | ||
| component: NavigationToggle, | ||
| title: 'Design System/Buttons/Navigation/Navigation Toggle', | ||
| parameters: { | ||
| design: { | ||
| type: 'figma', | ||
| url: 'https://www.figma.com/design/BCEJn9KCIbBJ5MzqnojKQp/AtlasNG-Components?node-id=2101-11132', | ||
| }, | ||
| }, | ||
| render: (args) => ({ | ||
| props: args, | ||
| template: `<ang-navigation-toggle>Label</ang-navigation-toggle>`, | ||
| }), | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<NavigationToggle>; | ||
|
|
||
| export const Default: Story = {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { ChangeDetectionStrategy, Component, model } from '@angular/core'; | ||
| import { MatButtonModule } from '@angular/material/button'; | ||
| import { MatIconModule } from '@angular/material/icon'; | ||
| import { TrackClick } from '@atlasng/analytics'; | ||
|
|
||
| @Component({ | ||
| selector: 'ang-navigation-toggle', | ||
| imports: [MatButtonModule, MatIconModule, TrackClick], | ||
| templateUrl: './navigation-toggle.html', | ||
| styleUrl: './navigation-toggle.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| host: { | ||
| '[attr.selected]': 'selected()', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to a class, i.e. |
||
| '(click)': 'selected.set(!selected())', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer using the |
||
| }, | ||
| }) | ||
| export class NavigationToggle { | ||
| /** Whether the button is currently selected */ | ||
| readonly selected = model<boolean>(false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <button matButton angTrackClick class="ang-navigation-button" target="_blank" disableRipple [angAnyLink]="link()"> | ||
| <span class="ang-navigation-text"><ng-content /></span> | ||
| </button> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @use '@angular/material' as mat; | ||
| @use 'internal/token-utils'; | ||
| @use './tokens' as *; | ||
|
|
||
| :host { | ||
| display: block; | ||
|
|
||
| @include mat.button-overrides( | ||
| ( | ||
| text-container-height: 3rem, | ||
| text-label-text-color: token-utils.slot(label-color, $config), | ||
| text-icon-spacing: 0.125rem, | ||
| text-label-text-font: token-utils.slot(label-font, $config), | ||
| text-label-text-size: token-utils.slot(label-font-size, $config), | ||
| text-label-text-tracking: token-utils.slot(label-letter-spacing, $config), | ||
| text-label-text-weight: token-utils.slot(label-font-weight, $config), | ||
| text-with-icon-horizontal-padding: 0.75rem, | ||
| text-state-layer-color: transparent, | ||
| ) | ||
| ); | ||
|
|
||
| .ang-navigation-button { | ||
| &:focus-visible { | ||
| outline: solid 0.125rem token-utils.slot(focus-outline-color, $config); | ||
| } | ||
|
|
||
| :is(&:hover, &:active, &:focus) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| .ang-navigation-text { | ||
| text-decoration: underline; | ||
| text-underline-offset: 0.25rem; | ||
| text-decoration-thickness: 0.125rem; | ||
| text-decoration-color: token-utils.slot(underline-color, $config); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { render, screen } from '@testing-library/angular'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { Navigation } from './navigation'; | ||
|
|
||
| describe('Navigation', () => { | ||
| async function setup(link: string | null = null) { | ||
| const user = userEvent.setup(); | ||
|
|
||
| await render(`<ang-navigation [link]="link">Go to Docs</ang-navigation>`, { | ||
| imports: [Navigation], | ||
| componentProperties: { | ||
| link, | ||
| }, | ||
| }); | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Go to Docs' }); | ||
|
|
||
| return { | ||
| user, | ||
| button, | ||
| }; | ||
| } | ||
|
|
||
| it('renders projected content inside the navigation button', async () => { | ||
| const { button } = await setup(); | ||
|
|
||
| expect(button).toBeInTheDocument(); | ||
| expect(button).toHaveTextContent('Go to Docs'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Meta, StoryObj } from '@storybook/angular'; | ||
| import { Navigation } from './navigation'; | ||
|
|
||
| const meta: Meta<Navigation> = { | ||
| component: Navigation, | ||
| title: 'Design System/Buttons/Navigation', | ||
| parameters: { | ||
| design: { | ||
| type: 'figma', | ||
| url: 'https://www.figma.com/design/BCEJn9KCIbBJ5MzqnojKQp/AtlasNG-Components?node-id=7493-48830', | ||
| }, | ||
| }, | ||
| args: { | ||
| link: 'https://example.com', | ||
| }, | ||
| render: (args) => ({ | ||
| props: args, | ||
| template: `<ang-navigation [link]="link">Label</ang-navigation>`, | ||
| }), | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<Navigation>; | ||
|
|
||
| export const Default: Story = {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { ChangeDetectionStrategy, Component, input } from '@angular/core'; | ||
| import { MatButtonModule } from '@angular/material/button'; | ||
| import { TrackClick } from '@atlasng/analytics'; | ||
| import { AnyLink, AnyLinkCommand } from '@atlasng/common'; | ||
|
|
||
| @Component({ | ||
| selector: 'ang-navigation', | ||
| imports: [MatButtonModule, AnyLink, TrackClick], | ||
| templateUrl: './navigation.html', | ||
| styleUrl: './navigation.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class Navigation { | ||
| /** The link to navigate to */ | ||
| readonly link = input<AnyLinkCommand | null>(null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove null, |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @use 'internal/token-utils'; | ||
|
|
||
| $config: ( | ||
| namespace: 'navigation', | ||
| tokens: ( | ||
| label-color: token-utils.sys-token(on-surface), | ||
| icon-color: token-utils.sys-token(on-surface-variant), | ||
| underline-color: token-utils.sys-token(primary), | ||
| focus-outline-color: token-utils.sys-token(on-surface), | ||
| label-font: token-utils.sys-token(title-medium-font), | ||
| label-font-size: token-utils.sys-token(title-medium-size), | ||
| label-letter-spacing: token-utils.sys-token(title-medium-tracking), | ||
| label-font-weight: token-utils.sys-token(title-medium-weight), | ||
| ), | ||
| ); | ||
|
|
||
| @mixin overrides($overrides) { | ||
| @include token-utils.apply-overrides($overrides, $config); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,9 @@ | |
| "@atlasng/core": ["./libs/core/src/index.ts"], | ||
| "@atlasng/design-system": ["./libs/design-system/src/index.ts"], | ||
| "@atlasng/design-system/buttons/help": ["./libs/design-system/buttons/help/src/index.ts"], | ||
| "@atlasng/design-system/buttons/navigation-category-toggle": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update |
||
| "./libs/design-system/buttons/navigation-category-toggle/src/index.ts" | ||
| ], | ||
| "@atlasng/design-system/buttons/social-media": ["./libs/design-system/buttons/social-media/src/index.ts"], | ||
| "@atlasng/design-system/indicators/end-of-results": [ | ||
| "./libs/design-system/indicators/end-of-results/src/index.ts" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
focus-visibleinstead offocus