-
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.
fixup! Feat(web-react): Introduce
NavigationItem
subcomponent #DS-1411
- Loading branch information
Showing
12 changed files
with
75 additions
and
117 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
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
4 changes: 1 addition & 3 deletions
4
packages/web-react/src/components/Navigation/__tests__/Navigation.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
4 changes: 1 addition & 3 deletions
4
packages/web-react/src/components/Navigation/__tests__/NavigationAction.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
26 changes: 0 additions & 26 deletions
26
packages/web-react/src/components/Navigation/__tests__/useNavigationActionStyleProps.test.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
packages/web-react/src/components/Navigation/__tests__/useNavigationItemStyleProps.test.ts
This file was deleted.
Oops, something went wrong.
26 changes: 25 additions & 1 deletion
26
packages/web-react/src/components/Navigation/__tests__/useNavigationStyleProps.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 |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { SpiritNavigationActionProps } from '../../../types'; | ||
import { useNavigationStyleProps } from '../useNavigationStyleProps'; | ||
|
||
describe('useNavigationStyleProps', () => { | ||
it('should return defaults', () => { | ||
const { result } = renderHook(() => useNavigationStyleProps()); | ||
|
||
expect(result.current.classProps).toBe('Navigation'); | ||
expect(result.current.classProps.root).toBe('Navigation'); | ||
expect(result.current.classProps.action).toBe('NavigationAction'); | ||
expect(result.current.classProps.item).toBe('NavigationItem'); | ||
}); | ||
|
||
it('should return disabled class', () => { | ||
const props: SpiritNavigationActionProps = { isDisabled: true }; | ||
const { result } = renderHook(() => useNavigationStyleProps(props)); | ||
|
||
expect(result.current.classProps.action).toBe('NavigationAction NavigationAction--disabled'); | ||
}); | ||
|
||
it('should return selected class', () => { | ||
const props = { isSelected: true }; | ||
const { result } = renderHook(() => useNavigationStyleProps(props)); | ||
|
||
expect(result.current.classProps.action).toBe('NavigationAction NavigationAction--selected'); | ||
}); | ||
|
||
it('should return stretchChildren class', () => { | ||
const props = { isStretchingChildren: true }; | ||
const { result } = renderHook(() => useNavigationStyleProps(props)); | ||
|
||
expect(result.current.classProps.item).toBe('NavigationItem NavigationItem--stretchChildren'); | ||
}); | ||
}); |
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
31 changes: 0 additions & 31 deletions
31
packages/web-react/src/components/Navigation/useNavigationActionStyleProps.ts
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
packages/web-react/src/components/Navigation/useNavigationItemStyleProps.ts
This file was deleted.
Oops, something went wrong.
45 changes: 41 additions & 4 deletions
45
packages/web-react/src/components/Navigation/useNavigationStyleProps.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 |
---|---|---|
@@ -1,13 +1,50 @@ | ||
import classNames from 'classnames'; | ||
import { ElementType } from 'react'; | ||
import { useClassNamePrefix } from '../../hooks'; | ||
import { SpiritNavigationActionProps, SpiritNavigationItemProps } from '../../types'; | ||
|
||
export interface NavigationStyles { | ||
classProps: string; | ||
export interface UseNavigationStyleProps { | ||
isDisabled?: boolean; | ||
isSelected?: boolean; | ||
isStretchingChildren?: boolean; | ||
} | ||
|
||
export const useNavigationStyleProps = (): NavigationStyles => { | ||
export interface UseNavigationStyleReturn<E extends ElementType = 'a'> { | ||
classProps: { | ||
root: string; | ||
action: string; | ||
item: string; | ||
}; | ||
props: SpiritNavigationItemProps | SpiritNavigationActionProps<E>; | ||
} | ||
|
||
export const useNavigationStyleProps = <E extends ElementType = 'a'>({ | ||
isDisabled = false, | ||
isSelected = false, | ||
isStretchingChildren = false, | ||
...restProps | ||
}: UseNavigationStyleProps = {}): UseNavigationStyleReturn<E> => { | ||
const navigationClass = useClassNamePrefix('Navigation'); | ||
const navigationActionClass = useClassNamePrefix('NavigationAction'); | ||
const navigationItemClass = useClassNamePrefix('NavigationItem'); | ||
|
||
const navigationActionDisabledClass = `${navigationActionClass}--disabled`; | ||
const navigationActionSelectedClass = `${navigationActionClass}--selected`; | ||
const navigationItemStretchingClass = `${navigationItemClass}--stretchChildren`; | ||
|
||
const classProps = { | ||
root: navigationClass, | ||
action: classNames(navigationActionClass, { | ||
[navigationActionDisabledClass]: isDisabled, | ||
[navigationActionSelectedClass]: isSelected, | ||
}), | ||
item: classNames(navigationItemClass, { | ||
[navigationItemStretchingClass]: isStretchingChildren, | ||
}), | ||
}; | ||
|
||
return { | ||
classProps: navigationClass, | ||
classProps, | ||
props: restProps, | ||
}; | ||
}; |