-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-react): Introduce
NavigationItem
subcomponent #DS-1411
- Loading branch information
Showing
7 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
packages/web-react/src/components/Navigation/NavigationItem.tsx
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
17 changes: 15 additions & 2 deletions
17
packages/web-react/src/components/Navigation/__tests__/NavigationItem.test.tsx
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
18 changes: 18 additions & 0 deletions
18
packages/web-react/src/components/Navigation/__tests__/useNavigationItemStyleProps.test.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,18 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useNavigationItemStyleProps } from '../useNavigationItemStyleProps'; | ||
|
||
describe('useNavigationItemStyleProps', () => { | ||
it('should return defaults', () => { | ||
const props = {}; | ||
const { result } = renderHook(() => useNavigationItemStyleProps(props)); | ||
|
||
expect(result.current.classProps).toBe('NavigationItem'); | ||
}); | ||
|
||
it('should return stretchChildren class', () => { | ||
const props = { isStretchingChildren: true }; | ||
const { result } = renderHook(() => useNavigationItemStyleProps(props)); | ||
|
||
expect(result.current.classProps).toBe('NavigationItem NavigationItem--stretchChildren'); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/web-react/src/components/Navigation/useNavigationItemStyleProps.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 @@ | ||
import classNames from 'classnames'; | ||
import { useClassNamePrefix } from '../../hooks'; | ||
import { SpiritNavigationItemProps } from '../../types'; | ||
|
||
export interface NavigationItemStyles { | ||
classProps: string; | ||
props: SpiritNavigationItemProps; | ||
} | ||
|
||
export const useNavigationItemStyleProps = (props: SpiritNavigationItemProps): NavigationItemStyles => { | ||
const { isStretchingChildren, ...restProps } = props; | ||
const itemClass = useClassNamePrefix('NavigationItem'); | ||
const itemIsStretchingChildrenClass = `${itemClass}--stretchChildren`; | ||
|
||
const className = classNames(itemClass, { | ||
[itemIsStretchingChildrenClass]: isStretchingChildren, | ||
}); | ||
|
||
return { | ||
classProps: className, | ||
props: restProps, | ||
}; | ||
}; |
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