-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new CollapseButton that uses a single section.
- Loading branch information
Showing
3 changed files
with
136 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2022 The Kubeflow Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import CollapseButton from './CollapseButtonSingle'; | ||
|
||
describe('CollapseButtonSingle', () => { | ||
const collapseSectionUpdateSpy = jest.fn(); | ||
|
||
it('Collapes an expanded section when clicked', () => { | ||
render( | ||
<CollapseButton | ||
collapseSection={false} | ||
collapseSectionUpdate={collapseSectionUpdateSpy} | ||
sectionName='testSection' | ||
/>, | ||
); | ||
|
||
fireEvent.click(screen.getByText('testSection')); | ||
expect(collapseSectionUpdateSpy).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('Expands a collapsed section when clicked', () => { | ||
render( | ||
<CollapseButton | ||
collapseSection={true} | ||
collapseSectionUpdate={collapseSectionUpdateSpy} | ||
sectionName='testSection' | ||
/>, | ||
); | ||
|
||
fireEvent.click(screen.getByText('testSection')); | ||
expect(collapseSectionUpdateSpy).toHaveBeenCalledWith(false); | ||
}); | ||
}); |
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,64 @@ | ||
/* | ||
* Copyright 2022 The Kubeflow Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import Button from '@material-ui/core/Button'; | ||
import ExpandedIcon from '@material-ui/icons/ArrowDropUp'; | ||
import { stylesheet, classes } from 'typestyle'; | ||
import { color, fontsize } from '../Css'; | ||
|
||
const css = stylesheet({ | ||
collapseBtn: { | ||
color: color.strong, | ||
fontSize: fontsize.title, | ||
fontWeight: 'bold', | ||
padding: 5, | ||
}, | ||
collapsed: { | ||
transform: 'rotate(180deg)', | ||
}, | ||
icon: { | ||
marginRight: 5, | ||
transition: 'transform 0.3s', | ||
}, | ||
}); | ||
|
||
interface CollapseButtonProps { | ||
collapseSection: boolean; | ||
collapseSectionUpdate: (collapseSection: boolean) => void; | ||
sectionName: string; | ||
} | ||
|
||
function CollapseButton(props: CollapseButtonProps) { | ||
const { collapseSection, collapseSectionUpdate, sectionName } = props; | ||
|
||
return ( | ||
<div> | ||
<Button | ||
onClick={() => { | ||
collapseSectionUpdate(!collapseSection); | ||
}} | ||
title='Expand/Collapse this section' | ||
className={css.collapseBtn} | ||
> | ||
<ExpandedIcon className={classes(css.icon, collapseSection ? css.collapsed : '')} /> | ||
{sectionName} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
export default CollapseButton; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, 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
NIT: It will help usage by using the same name as this file
CollapseButtonSingle
.