-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(window): convert to TypeScript and export types
- Loading branch information
Showing
11 changed files
with
172 additions
and
160 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
This file was deleted.
Oops, something went wrong.
4 changes: 1 addition & 3 deletions
4
src/WindowContent/WindowContent.spec.js → src/WindowContent/WindowContent.spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { forwardRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { CommonStyledProps } from '../types'; | ||
|
||
type WindowContentProps = { | ||
children?: React.ReactNode; | ||
} & React.HTMLAttributes<HTMLDivElement> & | ||
CommonStyledProps; | ||
|
||
const StyledWindowContent = styled.div` | ||
padding: 16px; | ||
`; | ||
|
||
const WindowContent = forwardRef<HTMLDivElement, WindowContentProps>( | ||
function WindowContent({ children, ...otherProps }, ref) { | ||
return ( | ||
<StyledWindowContent ref={ref} {...otherProps}> | ||
{children} | ||
</StyledWindowContent> | ||
); | ||
} | ||
); | ||
|
||
export { WindowContent, WindowContentProps }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import { renderWithTheme, theme } from '../../test/utils'; | ||
|
||
import { WindowHeader } from './WindowHeader'; | ||
|
||
describe('<WindowHeader />', () => { | ||
it('renders WindowHeader', () => { | ||
const { container } = renderWithTheme(<WindowHeader />); | ||
const windowHeader = container.firstChild; | ||
|
||
expect(windowHeader).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders children', () => { | ||
const textContent = 'Hi there!'; | ||
const { getByText } = renderWithTheme( | ||
<WindowHeader> | ||
<span>{textContent}</span> | ||
</WindowHeader> | ||
); | ||
expect(getByText(textContent)).toBeInTheDocument(); | ||
}); | ||
|
||
describe('prop: active', () => { | ||
it('displays active header by default', () => { | ||
const { container } = renderWithTheme(<WindowHeader />); | ||
const windowHeader = container.firstChild as HTMLDivElement; | ||
|
||
expect(windowHeader).toHaveStyleRule('color', theme.headerText); | ||
expect(windowHeader).toHaveStyleRule( | ||
'background', | ||
theme.headerBackground | ||
); | ||
}); | ||
|
||
it('displays active header when set to true', () => { | ||
const { container } = renderWithTheme(<WindowHeader active />); | ||
const windowHeader = container.firstChild as HTMLDivElement; | ||
|
||
expect(windowHeader).toHaveStyleRule('color', theme.headerText); | ||
expect(windowHeader).toHaveStyleRule( | ||
'background', | ||
theme.headerBackground | ||
); | ||
}); | ||
|
||
it('renders non-active header when set to false', () => { | ||
const { container } = renderWithTheme(<WindowHeader active={false} />); | ||
const windowHeader = container.firstChild; | ||
|
||
expect(windowHeader).toHaveStyleRule('color', theme.headerNotActiveText); | ||
expect(windowHeader).toHaveStyleRule( | ||
'background', | ||
theme.headerNotActiveBackground | ||
); | ||
}); | ||
}); | ||
}); |
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 { StyledButton } from '../Button/Button'; | ||
import { CommonStyledProps } from '../types'; | ||
|
||
type WindowHeaderProps = { | ||
children?: React.ReactNode; | ||
active?: boolean; | ||
} & React.HTMLAttributes<HTMLDivElement> & | ||
CommonStyledProps; | ||
|
||
const StyledWindowHeader = styled.div<Pick<WindowHeaderProps, 'active'>>` | ||
height: 33px; | ||
line-height: 33px; | ||
padding-left: 0.25rem; | ||
padding-right: 3px; | ||
font-weight: bold; | ||
border: 2px solid ${({ theme }) => theme.material}; | ||
${({ active }) => | ||
active === false | ||
? css` | ||
background: ${({ theme }) => theme.headerNotActiveBackground}; | ||
color: ${({ theme }) => theme.headerNotActiveText}; | ||
` | ||
: css` | ||
background: ${({ theme }) => theme.headerBackground}; | ||
color: ${({ theme }) => theme.headerText}; | ||
`} | ||
${StyledButton} { | ||
padding-left: 0; | ||
padding-right: 0; | ||
height: 27px; | ||
width: 31px; | ||
} | ||
`; | ||
|
||
// TODO - should we add some aria label indicating if window is currently active? | ||
const WindowHeader = forwardRef<HTMLDivElement, WindowHeaderProps>( | ||
function WindowHeader({ active = true, children, ...otherProps }, ref) { | ||
return ( | ||
<StyledWindowHeader active={active} ref={ref} {...otherProps}> | ||
{children} | ||
</StyledWindowHeader> | ||
); | ||
} | ||
); | ||
|
||
export { WindowHeader, WindowHeaderProps }; |
Oops, something went wrong.