-
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
Open
edlu77
wants to merge
11
commits into
main
Choose a base branch
from
navigation-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+314
−0
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4791156
feat(design-system): add navigation category button toggle component
edlu77 c94a7ed
Merge remote-tracking branch 'origin/main' into navigation-button
edlu77 7769f1b
feat(design-system): add navigation category toggle
edlu77 58acfef
fix(design-system): fix icon class name
edlu77 9f758f2
fix(design-system): update focus behavior
edlu77 c6ae450
refactor(design-system): split navigation category toggle button into…
edlu77 2e08375
test(design-system): fix test
edlu77 74d7903
refactor(design-system): tweaks
edlu77 957673c
Merge remote-tracking branch 'origin/main' into navigation-button
edlu77 5a19700
test(design-system): test tweak
edlu77 2fc1ad4
fix(design-system): fix navigation-toggle entry point export path
nx-cloud[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
libs/design-system/buttons/navigation-category-toggle/ng-package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "lib": { | ||
| "cssUrl": "inline", | ||
| "entryFile": "src/index.ts", | ||
| "styleIncludePaths": ["../../src/sass"] | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
libs/design-system/buttons/navigation-category-toggle/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { NavigationCategoryToggle } from './lib/navigation-category-toggle'; |
18 changes: 18 additions & 0 deletions
18
.../design-system/buttons/navigation-category-toggle/src/lib/navigation-category-toggle.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <button | ||
| matButton | ||
| angTrackClick | ||
| class="ang-navigation-category-toggle-button" | ||
| target="_blank" | ||
| disableRipple | ||
| [angAnyLink]="link()" | ||
| (click)="toggled.set(!toggled())" | ||
| > | ||
| <span class="ang-navigation-category-toggle-text"><ng-content /></span> | ||
| @if (!link()) { | ||
| <mat-icon | ||
| iconPositionEnd | ||
| class="ang-navigation-category-toggle-icon" | ||
| [fontIcon]="toggled() ? 'expand_less' : 'expand_more'" | ||
| /> | ||
| } | ||
| </button> |
46 changes: 46 additions & 0 deletions
46
.../design-system/buttons/navigation-category-toggle/src/lib/navigation-category-toggle.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| @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-category-toggle-button { | ||
| &:focus-visible { | ||
| outline: solid 0.125rem token-utils.slot(focus-outline-color, $config); | ||
| } | ||
|
|
||
| .ang-navigation-category-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-category-toggle-icon { | ||
| height: 1.25rem; | ||
| width: 1.25rem; | ||
| font-size: 1.25rem; | ||
| } | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...sign-system/buttons/navigation-category-toggle/src/lib/navigation-category-toggle.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { render, screen } from '@testing-library/angular'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { NavigationCategoryToggle } from './navigation-category-toggle'; | ||
|
|
||
| describe('NavigationCategoryToggle', () => { | ||
| async function setup(link: string | null = null) { | ||
| const user = userEvent.setup(); | ||
| const rendered = await render( | ||
| `<ang-navigation-category-toggle [link]="link">Category</ang-navigation-category-toggle>`, | ||
| { | ||
| imports: [NavigationCategoryToggle], | ||
| componentProperties: { | ||
| link, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| user, | ||
| ...rendered, | ||
| }; | ||
| } | ||
|
|
||
| it('toggles state when clicked', async () => { | ||
| const { user } = await setup(); | ||
| const toggle = screen.getByText('Category').closest('.ang-navigation-category-toggle-button'); | ||
|
|
||
| expect(toggle).toBeTruthy(); | ||
|
|
||
| const icon = toggle?.querySelector('.ang-navigation-category-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'); | ||
| }); | ||
|
|
||
| it('hides the toggle icon when a link is provided', async () => { | ||
| await setup('/products'); | ||
|
|
||
| const toggle = screen.getByRole('button', { name: 'Category' }); | ||
|
|
||
| expect(toggle).toBeTruthy(); | ||
| expect(toggle).toHaveAttribute('tabindex', '0'); | ||
| expect(toggle).not.toHaveAttribute('href'); | ||
| expect(toggle.querySelector('.ang-navigation-category-toggle-icon')).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
28 changes: 28 additions & 0 deletions
28
...n-system/buttons/navigation-category-toggle/src/lib/navigation-category-toggle.stories.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Meta, StoryObj } from '@storybook/angular'; | ||
| import { NavigationCategoryToggle } from './navigation-category-toggle'; | ||
|
|
||
| const meta: Meta<NavigationCategoryToggle> = { | ||
| component: NavigationCategoryToggle, | ||
| title: 'Design System/Buttons/Navigation Category 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-category-toggle [link]="link">Label</ang-navigation-category-toggle>`, | ||
| }), | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<NavigationCategoryToggle>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const AsLink: Story = { | ||
| args: { | ||
| link: 'https://example.com', | ||
| }, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
libs/design-system/buttons/navigation-category-toggle/src/lib/navigation-category-toggle.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { ChangeDetectionStrategy, Component, input, model } from '@angular/core'; | ||
| import { MatButtonModule } from '@angular/material/button'; | ||
| import { MatIconModule } from '@angular/material/icon'; | ||
| import { TrackClick } from '@atlasng/analytics'; | ||
| import { AnyLink, AnyLinkCommand } from '@atlasng/common'; | ||
|
|
||
| @Component({ | ||
| selector: 'ang-navigation-category-toggle', | ||
| imports: [MatButtonModule, MatIconModule, AnyLink, TrackClick], | ||
| templateUrl: './navigation-category-toggle.html', | ||
| styleUrl: './navigation-category-toggle.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class NavigationCategoryToggle { | ||
| /** The link to navigate to (hides toggle icon if provided) */ | ||
| readonly link = input<AnyLinkCommand | null>(null); | ||
| /** Whether to show the toggle icon */ | ||
| readonly toggled = model<boolean>(false); | ||
| } |
19 changes: 19 additions & 0 deletions
19
libs/design-system/buttons/navigation-category-toggle/src/lib/tokens.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @use 'internal/token-utils'; | ||
|
|
||
| $config: ( | ||
| namespace: 'navigation-category-toggle', | ||
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Update