forked from vmware-archive/clarity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core:navigation): mvp cds-navigation
- this is vertical axis only - custom expand/collapse icons for root navigation and navigation groups - navigation groups - arrow and home and end key navigation - adds mdx and demos to core storybook Signed-off-by: Matt Hippely <mhippely@vmware.com>
- Loading branch information
1 parent
29218a4
commit a80cfc5
Showing
36 changed files
with
3,901 additions
and
703 deletions.
There are no files selected for viewing
This file contains 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 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
23 changes: 23 additions & 0 deletions
23
packages/core/src/internal/motion/animations/cds-navigation-group-open.ts
This file contains 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,23 @@ | ||
/* | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
import { TargetedAnimation } from '../interfaces.js'; | ||
|
||
export const AnimationNavigationGroupOpenName = 'cds-navigation-group-open'; | ||
export const AnimationNavigationGroupOpenConfig: TargetedAnimation[] = [ | ||
{ | ||
target: '.navigation-group-items', | ||
animation: [ | ||
{ opacity: 0, height: '0' }, | ||
{ opacity: 1, height: 'from:cds-navigation-group' }, | ||
], | ||
options: { | ||
duration: '--animation-duration', | ||
easing: '--animation-easing', | ||
fill: 'forwards', | ||
}, | ||
}, | ||
]; |
20 changes: 20 additions & 0 deletions
20
packages/core/src/internal/motion/animations/cds-navigation-open.ts
This file contains 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,20 @@ | ||
/* | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
import { TargetedAnimation } from '../interfaces.js'; | ||
|
||
export const AnimationNavigationOpenName = 'cds-navigation-open'; | ||
export const AnimationNavigationOpenConfig: TargetedAnimation[] = [ | ||
{ | ||
target: 'cds-navigation', | ||
animation: [{ width: 'var(--collapsed-width)' }, { width: 'var(--expanded-width)' }], | ||
options: { | ||
duration: '--animation-duration', | ||
easing: '--animation-easing', | ||
fill: 'forwards', | ||
}, | ||
}, | ||
]; |
This file contains 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 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 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 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,12 @@ | ||
{ | ||
"extends": "../../tsconfig.lib.json", | ||
"compilerOptions": { | ||
"composite": true | ||
}, | ||
"references": [ | ||
{ "path": "../button/entrypoint.tsconfig.json" }, | ||
{ "path": "../divider/entrypoint.tsconfig.json" }, | ||
{ "path": "../internal/entrypoint.tsconfig.json" }, | ||
{ "path": "../icon/entrypoint.tsconfig.json" } | ||
] | ||
} |
This file contains 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,10 @@ | ||
/* | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
export * from './navigation.element.js'; | ||
export * from './navigation-group.element.js'; | ||
export * from './navigation-start.element.js'; | ||
export * from './navigation-item.element.js'; |
13 changes: 13 additions & 0 deletions
13
packages/core/src/navigation/interfaces/navigation.interfaces.ts
This file contains 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,13 @@ | ||
/* | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
export interface FocusableItem { | ||
id: string; | ||
hasFocus: boolean; | ||
focusElement: HTMLElement; | ||
} | ||
|
||
export type NavigationFocusState = true | false; |
48 changes: 48 additions & 0 deletions
48
packages/core/src/navigation/navigation-group.element.scss
This file contains 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,48 @@ | ||
/*! | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
@import './../styles/tokens/generated/index'; | ||
|
||
:host { | ||
--animation-duration: #{$cds-global-animation-duration-secondary}; | ||
--animation-easing: #{$cds-global-animation-easing-primary}; | ||
--background: inherit; | ||
} | ||
|
||
.navigation-group-items { | ||
height: 0; | ||
overflow-y: hidden; | ||
} | ||
|
||
:host([cds-motion='off']) { | ||
.navigation-group-items { | ||
height: 0; | ||
} | ||
} | ||
|
||
:host([cds-motion='off'][expanded]) { | ||
.navigation-group-items { | ||
height: auto; | ||
} | ||
} | ||
|
||
:host([cds-motion][_cds-animation-status='ready']:not([cds-motion='off'])) { | ||
.navigation-group-items { | ||
height: 0; | ||
} | ||
} | ||
|
||
:host([cds-motion][expanded][_cds-animation-status='ready']:not([cds-motion='off'])) { | ||
.navigation-group-items { | ||
height: auto !important; | ||
transform: none; | ||
} | ||
} | ||
|
||
.group-items-container, | ||
.group-items-wrapper { | ||
width: 100%; | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/core/src/navigation/navigation-group.element.spec.ts
This file contains 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,84 @@ | ||
/* | ||
* Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
import { html } from 'lit'; | ||
import { createTestElement, componentIsStable, removeTestElement } from '@cds/core/test'; | ||
import { CdsNavigationGroup, CdsNavigationStart } from '@cds/core/navigation'; | ||
import '@cds/core/navigation/register.js'; | ||
import Spy = jasmine.Spy; | ||
|
||
describe('cds-navigation-group', () => { | ||
let component: CdsNavigationGroup; | ||
let element: HTMLElement; | ||
let click: MouseEvent; | ||
|
||
beforeEach(async () => { | ||
element = await createTestElement(html` | ||
<cds-navigation-group> | ||
<cds-navigation-start id="start">Group nav start</cds-navigation-start> | ||
<cds-navigation-item>group nav item</cds-navigation-item> | ||
</cds-navigation-group> | ||
`); | ||
component = element.querySelector<CdsNavigationGroup>('cds-navigation-group'); | ||
click = new MouseEvent('click'); | ||
}); | ||
|
||
afterEach(() => { | ||
removeTestElement(element); | ||
}); | ||
|
||
it('should create a navigation group component', async () => { | ||
await componentIsStable(component); | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('expands and collapses', async () => { | ||
await componentIsStable(component); | ||
const items = component.shadowRoot.querySelector('.navigation-group-items'); | ||
expect(items.getAttribute('aria-expanded')).toBe('false'); | ||
component.expanded = true; | ||
await componentIsStable(component); | ||
expect(items.getAttribute('aria-expanded')).toBe('true'); | ||
}); | ||
|
||
it('emits the expandedChange event', async () => { | ||
await componentIsStable(component); | ||
let count = 0; | ||
const expandedSpy: Spy = jasmine.createSpy('expandedChange').and.callFake(() => { | ||
count++; | ||
}); | ||
component.addEventListener('expandedChange', expandedSpy); | ||
const startEle = component.querySelector<CdsNavigationStart>('cds-navigation-start'); | ||
startEle.dispatchEvent(click); | ||
await componentIsStable(component); | ||
expect(count).toBe(1); | ||
}); | ||
|
||
it('has accessible navigationGroupId', async () => { | ||
await componentIsStable(component); | ||
expect(component.navigationGroupId).toBeTruthy(); | ||
const itemWrapper = component.shadowRoot.querySelector('.group-items-wrapper'); | ||
expect(itemWrapper.getAttribute('aria-labelledby')).toBe(component.navigationGroupId); | ||
}); | ||
|
||
it('can be active', async () => { | ||
await componentIsStable(component); | ||
component.setAttribute('active', ''); | ||
await componentIsStable(component); | ||
expect(component.active).toBe(true); | ||
}); | ||
|
||
it('syncs expandedState down to children items', async () => { | ||
await componentIsStable(component); | ||
const startEle = component.querySelector<CdsNavigationStart>('cds-navigation-start'); | ||
expect(startEle.navigationGroupId).toBe(component.navigationGroupId); | ||
expect(startEle.isGroupStart).toBe(true); | ||
expect(startEle.expanded).toBe(component.expanded); | ||
component.setAttribute('expanded', ''); | ||
await componentIsStable(component); | ||
expect(startEle.expanded).toBe(component.expanded); | ||
}); | ||
}); |
Oops, something went wrong.