-
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.
Merge pull request #32 from qoretechnologies/feature/navbar
Navbar
- Loading branch information
Showing
11 changed files
with
464 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { | ||
ReqoreHeader, | ||
ReqoreNavbarDivider, | ||
ReqoreNavbarGroup, | ||
ReqoreNavbarItem, | ||
ReqoreUIProvider, | ||
} from '../src'; | ||
|
||
test('Renders Navbar properly', () => { | ||
render( | ||
<ReqoreUIProvider> | ||
<ReqoreHeader> | ||
<ReqoreNavbarGroup> | ||
<ReqoreNavbarItem>Logo</ReqoreNavbarItem> | ||
</ReqoreNavbarGroup> | ||
<ReqoreNavbarGroup position='right'> | ||
<ReqoreNavbarItem>Item</ReqoreNavbarItem> | ||
<ReqoreNavbarDivider /> | ||
<ReqoreNavbarItem>Item 2</ReqoreNavbarItem> | ||
</ReqoreNavbarGroup> | ||
</ReqoreHeader> | ||
</ReqoreUIProvider> | ||
); | ||
|
||
expect(document.querySelectorAll('.reqore-navbar-header').length).toBe(1); | ||
expect(document.querySelectorAll('.reqore-navbar-group').length).toBe(2); | ||
expect(document.querySelectorAll('.reqore-navbar-divider').length).toBe(1); | ||
expect(document.querySelectorAll('.reqore-navbar-item').length).toBe(3); | ||
}); |
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,49 @@ | ||
import React, { forwardRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { IReqoreTheme } from '../../constants/theme'; | ||
import { getReadableColor } from '../../helpers/colors'; | ||
|
||
export interface IReqoreNavbarDividerProps | ||
extends React.HTMLAttributes<HTMLDivElement> { | ||
type?: 'header' | 'footer'; | ||
} | ||
|
||
const StyledNavbarDivider = styled.div<{ | ||
theme: IReqoreTheme; | ||
type?: 'header' | 'footer'; | ||
}>` | ||
position: relative; | ||
width: 20px; | ||
height: 100%; | ||
background-color: inherit; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
&:before { | ||
content: ''; | ||
display: block; | ||
width: 1px; | ||
height: 50%; | ||
background-color: ${({ theme, type }) => | ||
getReadableColor( | ||
theme[type]?.background || theme[type]?.main || theme.main, | ||
undefined, | ||
undefined, | ||
true | ||
)}; | ||
opacity: 0.2; | ||
} | ||
`; | ||
|
||
const ReqoreNavbarDivider = forwardRef( | ||
({ type, ...rest }: IReqoreNavbarDividerProps, ref: any) => ( | ||
<StyledNavbarDivider | ||
type={type} | ||
className={`${rest.className || ''} reqore-navbar-divider`} | ||
ref={ref} | ||
/> | ||
) | ||
); | ||
|
||
export default ReqoreNavbarDivider; |
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,49 @@ | ||
import React, { forwardRef } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { IReqoreTheme } from '../../constants/theme'; | ||
import ReqoreThemeProvider from '../../containers/ThemeProvider'; | ||
|
||
export interface IReqoreNavbarGroupProps | ||
extends React.HTMLAttributes<HTMLDivElement> { | ||
position?: 'right' | 'left'; | ||
type?: 'footer' | 'header'; | ||
children?: any; | ||
} | ||
|
||
export interface IReqoreNavbarGroupStyle extends IReqoreNavbarGroupProps { | ||
theme: IReqoreTheme; | ||
} | ||
|
||
const StyledNavbarGroup = styled.div<IReqoreNavbarGroupStyle>` | ||
${({ position }: IReqoreNavbarGroupStyle) => css` | ||
height: 100%; | ||
float: ${position}; | ||
color: inherit; | ||
background-color: inherit; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`} | ||
`; | ||
|
||
const ReqoreNavbarGroup = forwardRef( | ||
( | ||
{ position = 'left', children, type, ...rest }: IReqoreNavbarGroupProps, | ||
ref: any | ||
) => ( | ||
<ReqoreThemeProvider> | ||
<StyledNavbarGroup | ||
{...rest} | ||
className={`${rest.className || ''} reqore-navbar-group`} | ||
position={position} | ||
ref={ref} | ||
> | ||
{React.Children.map(children, (child) => | ||
React.cloneElement(child, { type }) | ||
)} | ||
</StyledNavbarGroup> | ||
</ReqoreThemeProvider> | ||
) | ||
); | ||
|
||
export default ReqoreNavbarGroup; |
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,72 @@ | ||
import { darken } from 'polished'; | ||
import React, { forwardRef } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { IReqoreTheme } from '../../constants/theme'; | ||
import ReqoreThemeProvider from '../../containers/ThemeProvider'; | ||
import { getMainColor, getReadableColor } from '../../helpers/colors'; | ||
|
||
export interface IReqoreNavbarProps | ||
extends React.HTMLAttributes<HTMLDivElement> { | ||
children?: any; | ||
position?: 'top' | 'bottom'; | ||
type?: 'header' | 'footer'; | ||
} | ||
|
||
export interface IReqoreNavbarStyle extends IReqoreNavbarProps { | ||
theme: IReqoreTheme; | ||
} | ||
|
||
const StyledNavbar = styled.div<IReqoreNavbarStyle>` | ||
${({ theme, type }: IReqoreNavbarStyle) => css` | ||
height: 50px; | ||
width: 100%; | ||
color: ${ | ||
theme[type]?.color || | ||
getReadableColor( | ||
theme[type]?.background || theme[type]?.main || theme.main, | ||
undefined, | ||
undefined, | ||
true | ||
) | ||
}; | ||
background-color: ${ | ||
theme[type]?.background || theme[type]?.main || theme.main | ||
}; | ||
border-${type === 'header' ? 'bottom' : 'top'}: 1px solid ${ | ||
theme[type]?.border || darken(0.1, getMainColor(theme, type)) | ||
}; | ||
`} | ||
`; | ||
|
||
const ReqoreNavbar = forwardRef( | ||
( | ||
{ position = 'top', children, type, ...rest }: IReqoreNavbarProps, | ||
ref: any | ||
) => ( | ||
<ReqoreThemeProvider> | ||
<StyledNavbar | ||
{...rest} | ||
className={`${rest.className || ''} reqore-navbar-${type}`} | ||
position={position} | ||
type={type} | ||
ref={ref} | ||
> | ||
{React.Children.map(children, (child) => | ||
React.cloneElement(child, { type }) | ||
)} | ||
</StyledNavbar> | ||
</ReqoreThemeProvider> | ||
) | ||
); | ||
|
||
export const ReqoreHeader = forwardRef( | ||
(props: IReqoreNavbarProps, ref: any) => ( | ||
<ReqoreNavbar {...props} type='header' ref={ref} /> | ||
) | ||
); | ||
|
||
export const ReqoreFooter = forwardRef( | ||
(props: IReqoreNavbarProps, ref: any) => ( | ||
<ReqoreNavbar {...props} type='footer' ref={ref} /> | ||
) | ||
); |
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,59 @@ | ||
import React, { forwardRef } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { IReqoreTheme } from '../../constants/theme'; | ||
import ReqoreThemeProvider from '../../containers/ThemeProvider'; | ||
import { changeLightness, getMainColor } from '../../helpers/colors'; | ||
|
||
export interface IReqoreNavbarItemProps | ||
extends React.HTMLAttributes<HTMLDivElement> { | ||
children?: any; | ||
interactive?: boolean; | ||
type?: 'header' | 'footer'; | ||
} | ||
|
||
export interface IReqoreNavbarItemStyle extends IReqoreNavbarItemProps { | ||
theme?: IReqoreTheme; | ||
} | ||
|
||
const StyledNavbarItem = styled.div<IReqoreNavbarItemStyle>` | ||
height: 100%; | ||
min-width: 50px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
padding: 10px; | ||
color: inherit; | ||
background-color: inherit; | ||
${({ interactive, theme, type }: IReqoreNavbarItemStyle) => | ||
interactive && | ||
css` | ||
transition: background-color 0.1s linear; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: ${theme[type]?.hoverColor || | ||
changeLightness(getMainColor(theme, type), 0.05)}; | ||
} | ||
`} | ||
`; | ||
|
||
const ReqoreNavbarItem = forwardRef( | ||
( | ||
{ interactive, children, type, ...rest }: IReqoreNavbarItemProps, | ||
ref: any | ||
) => ( | ||
<ReqoreThemeProvider> | ||
<StyledNavbarItem | ||
{...rest} | ||
className={`${rest.className || ''} reqore-navbar-item`} | ||
interactive={interactive} | ||
type={type} | ||
ref={ref} | ||
> | ||
{children} | ||
</StyledNavbarItem> | ||
</ReqoreThemeProvider> | ||
) | ||
); | ||
|
||
export default ReqoreNavbarItem; |
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
Oops, something went wrong.