-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LG-4620: ChartCard
and Header
components
#2550
Changes from 23 commits
e690783
3758bbd
ead54a1
9887996
69750a4
b11645e
2e4ca63
4ebe6c5
3427bc1
ff8d20a
215c193
8a977d7
eac05d0
91efd2a
7df0a8a
01715bc
fb116ec
2a4b3cc
46525bd
44ff882
82d60a6
2715b66
34d098f
9aa3101
ce8968a
51fc083
e0b9ce1
a61d79d
fd0bb1f
78c8b34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@lg-charts/core': minor | ||
--- | ||
|
||
Adds both `Header` and `ChartCard` components. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
import { css } from '@leafygreen-ui/emotion'; | ||
import { Theme } from '@leafygreen-ui/lib'; | ||
import { | ||
borderRadius, | ||
color, | ||
InteractionState, | ||
Variant, | ||
} from '@leafygreen-ui/tokens'; | ||
|
||
export const chartStyles = css` | ||
grid-row: 2; | ||
export const chartContainerStyles = css` | ||
display: grid; | ||
grid-template-areas: | ||
'chartHeader' | ||
shaneeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'chart'; | ||
width: 100%; | ||
`; | ||
|
||
export const getWrapperStyles = (theme: Theme) => css` | ||
export const chartStyles = css` | ||
display: block; | ||
grid-area: chart; | ||
height: 280px; | ||
width: 100%; | ||
border: 1px solid | ||
${color[theme].border[Variant.Disabled][InteractionState.Default]}; | ||
border-radius: ${borderRadius[200]}px; | ||
display: grid; | ||
grid-template-rows: auto 1fr; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { axe } from 'jest-axe'; | ||
|
||
import { ChartCard } from './ChartCard'; | ||
import { ChartCardProps } from './ChartCard.types'; | ||
|
||
const defaultContentText = 'shenanigans'; | ||
|
||
const defaultProps = { | ||
title: 'test', | ||
headerContent: <div>{defaultContentText}</div>, | ||
children: 'Chartchartchartchartchart', | ||
}; | ||
|
||
const renderChartCard = (props?: Partial<ChartCardProps>) => | ||
render(<ChartCard {...defaultProps} {...props} />); | ||
|
||
const clickToggleButton = () => { | ||
userEvent.click(screen.getByLabelText('Toggle button')); | ||
shaneeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
describe('@lg-charts/core/src/ChartCard/ChartCard', () => { | ||
test('does not have basic accessibility issues', async () => { | ||
const { container } = renderChartCard(); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
test('should display title value', () => { | ||
renderChartCard(); | ||
expect(screen.getByText(defaultProps.title)).toBeInTheDocument(); | ||
}); | ||
|
||
test('render component passed to headerContent', () => { | ||
renderChartCard(); | ||
expect(screen.getByText(defaultContentText)).toBeInTheDocument(); | ||
}); | ||
|
||
test('should call onToggleButtonClick when button is clicked', () => { | ||
const onToggleButtonClick = jest.fn(); | ||
renderChartCard({ onToggleButtonClick }); | ||
clickToggleButton(); | ||
expect(onToggleButtonClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('content is visible by default', () => { | ||
renderChartCard(); | ||
expect(screen.getByText(defaultProps.children)).toBeVisible(); | ||
}); | ||
|
||
test('content is not visible to accessible devices after click', () => { | ||
renderChartCard(); | ||
clickToggleButton(); | ||
expect(screen.getByTestId('chart-card-children')).toHaveAttribute( | ||
'aria-hidden', | ||
'true', | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { css } from '@leafygreen-ui/emotion'; | ||
import { Theme } from '@leafygreen-ui/lib'; | ||
import { | ||
borderRadius, | ||
color, | ||
InteractionState, | ||
spacing, | ||
transitionDuration, | ||
Variant, | ||
} from '@leafygreen-ui/tokens'; | ||
|
||
export const getContainerStyles = ( | ||
theme: Theme, | ||
height?: number, | ||
headerHeight?: number, | ||
) => css` | ||
border: 1px solid | ||
${color[theme].border[Variant.Disabled][InteractionState.Default]}; | ||
border-radius: ${borderRadius[200]}px; | ||
overflow: hidden; | ||
width: 100%; | ||
|
||
/** | ||
* Height adjustments are being made on the entire container instead of just | ||
* a wrapper around the children because a bottom border is set on the container and header. | ||
* By shrinking the container height we prevent a conflict between the container border | ||
* and the header border when collapsed. By making the container height 1px shorter on collapse | ||
* we just cutoff the header border entirely. | ||
*/ | ||
/* Accounts for 1px border */ | ||
max-height: ${headerHeight ? headerHeight + 1 + 'px' : 'auto'}; | ||
transition: max-height ${transitionDuration.slower}ms ease-in-out; | ||
&.open { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious: why do you prefer using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually not a preference, just not used to having |
||
max-height: ${height ? height + 'px' : 'auto'}; | ||
shaneeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
`; | ||
|
||
export const getHeaderStyles = (theme: Theme) => css` | ||
width: 100%; | ||
padding: ${spacing[150]}px ${spacing[300]}px; | ||
display: grid; | ||
grid-template-columns: auto 1fr; | ||
border-bottom: 1px solid | ||
${color[theme].border[Variant.Disabled][InteractionState.Default]}; | ||
`; | ||
|
||
export const toggleButtonStyles = css` | ||
margin-right: ${spacing[100]}px; | ||
`; | ||
|
||
export const toggleIconStyles = css` | ||
transform: rotate(-90deg); | ||
transition: transform ${transitionDuration.slower}ms ease-in-out; | ||
|
||
&.open { | ||
transform: rotate(0deg); | ||
} | ||
`; | ||
|
||
export const leftInnerContainerStyles = css` | ||
display: flex; | ||
align-items: center; | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some drive-by style changes in the README, mostly to use backticks on some code that wasn't previously formatted