-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tab component * add tabs component to the library * comments * comments * add callback * fix the boxes * chnages * add tabs dialog * add tabs to a dialog * reworked the dialog * organize component props * edit component * clean up * clean up * adjust the theme * spacing clean up * add array of call backs * clean up * adjustments * add tab fixture and add scrollable prop the dialog * correct a typo * address the comments * address comments * Fixes and simplifications. * Restore DialogActions to TabbedDialog. Enhance asserts * Fixup title * Add TabbedDialog.test.jsx * tsc fixups. --------- Co-authored-by: OlegMoshkovich <oleg.mosh@gmail.com>
- Loading branch information
1 parent
363b80d
commit 6508463
Showing
14 changed files
with
309 additions
and
11 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 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 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
import React from 'react' | ||
import FixtureContext from '../FixtureContext' | ||
import debug from '../utils/debug' | ||
import TabbedDialog from './TabbedDialog' | ||
|
||
|
||
const loremIpsum = (size) => `Lorem ipsum dolor sit amet, consectetur adipiscing elit, | ||
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. `.repeat(size) | ||
|
||
|
||
export default ( | ||
<FixtureContext> | ||
<TabbedDialog | ||
tabLabels={['Explore', 'Open', 'Save']} | ||
headerLabels={['Explore Sample Projects', 'Open Project', 'Save Project']} | ||
contentComponents={[ | ||
(<p key='1'>{loremIpsum(3)}</p>), | ||
(<p key='2'>{loremIpsum(2)}</p>), | ||
(<p key='3'>{loremIpsum(4)}</p>), | ||
]} | ||
actionCbs={[ | ||
() => debug().log('clicked 1'), | ||
() => debug().log('clicked 2'), | ||
() => debug().log('clicked 3'), | ||
]} | ||
isDialogDisplayed={true} | ||
setIsDialogDisplayed={() => debug().log('setIsDialogDisplayed')} | ||
/> | ||
</FixtureContext> | ||
) |
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,66 @@ | ||
import React, {useState} from 'react' | ||
import MuiDialog from '@mui/material/Dialog' | ||
import DialogActions from '@mui/material/DialogActions' | ||
import DialogContent from '@mui/material/DialogContent' | ||
import DialogTitle from '@mui/material/DialogTitle' | ||
import {assertDefined, assertArraysEqualLength} from '../utils/assert' | ||
import {CloseButton, RectangularButton} from './Buttons' | ||
import Tabs from './Tabs' | ||
|
||
|
||
/** | ||
* A Dialog with tabs to page between associated contents. | ||
* | ||
* @property {Array<string>} tabLabels Tab names | ||
* @property {Array<string>} headerLabels Short messages describing the current operation | ||
* @property {Array<React.Element>} contentComponents Components coresponding to the tabs | ||
* @property {Array<React.Element>} actionCbs Callbacks for each component's ok button | ||
* @property {boolean} isDialogDisplayed React var | ||
* @property {Function} setIsDialogDisplayed React setter | ||
* @property {boolean} [isTabsScrollable] Activate if the number of tabs is larger than 5 | ||
* @property {React.ReactElement} [icon] Leading icon above header description | ||
* @property {string} [actionButtonLabels] Labels for action ok buttons | ||
* @return {React.Component} | ||
*/ | ||
export default function TabbedDialog({ | ||
tabLabels, | ||
headerLabels, | ||
contentComponents, | ||
actionCbs, | ||
isDialogDisplayed, | ||
setIsDialogDisplayed, | ||
isTabsScrollable = false, | ||
icon, | ||
actionButtonLabels, | ||
}) { | ||
assertDefined(tabLabels, headerLabels, contentComponents, actionCbs, isDialogDisplayed, setIsDialogDisplayed) | ||
assertArraysEqualLength(tabLabels, headerLabels, contentComponents, actionCbs) | ||
const close = () => setIsDialogDisplayed(false) | ||
const [currentTab, setCurrentTab] = useState(0) | ||
return ( | ||
<MuiDialog | ||
maxWidth={'xs'} | ||
open={isDialogDisplayed} | ||
onClose={close} | ||
PaperProps={{variant: 'control'}} | ||
> | ||
<CloseButton onClick={close}/> | ||
<DialogTitle> | ||
{icon && <>{icon}<br/></>} | ||
{headerLabels[currentTab]} | ||
</DialogTitle> | ||
<DialogContent> | ||
<Tabs tabLabels={tabLabels} actionCb={setCurrentTab} isScrollable={isTabsScrollable}/> | ||
</DialogContent> | ||
<DialogContent> | ||
{contentComponents[currentTab]} | ||
</DialogContent> | ||
<DialogActions> | ||
<RectangularButton | ||
title={actionButtonLabels ? actionButtonLabels[currentTab] : 'Ok'} | ||
onClick={actionCbs[currentTab]} | ||
/> | ||
</DialogActions> | ||
</MuiDialog> | ||
) | ||
} |
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,43 @@ | ||
import React from 'react' | ||
import {render, screen, fireEvent} from '@testing-library/react' | ||
import TabbedDialog from './TabbedDialog' | ||
|
||
|
||
describe('TabbedDialog', () => { | ||
it('', () => { | ||
const cb1 = jest.fn() | ||
const cb2 = jest.fn() | ||
const cb3 = jest.fn() | ||
render( | ||
<TabbedDialog | ||
tabLabels={['Explore', 'Open', 'Save']} | ||
headerLabels={['Explore Sample Projects', 'Open Project', 'Save Project']} | ||
contentComponents={[ | ||
(<p key='1'>{'A content'}</p>), | ||
(<p key='2'>{'B content'}</p>), | ||
(<p key='3'>{'C content'}</p>), | ||
]} | ||
actionCbs={[cb1, cb2, cb3]} | ||
actionButtonLabels={['A OK', 'B OK', 'C OK']} | ||
isDialogDisplayed={true} | ||
setIsDialogDisplayed={jest.fn()} | ||
/>) | ||
|
||
fireEvent.click(screen.getByText('A OK')) | ||
expect(cb1.mock.calls.length).toBe(1) | ||
expect(cb2.mock.calls.length).toBe(0) | ||
expect(cb3.mock.calls.length).toBe(0) | ||
|
||
fireEvent.click(screen.getByText('Open')) | ||
fireEvent.click(screen.getByText('B OK')) | ||
expect(cb1.mock.calls.length).toBe(1) | ||
expect(cb2.mock.calls.length).toBe(1) | ||
expect(cb3.mock.calls.length).toBe(0) | ||
|
||
fireEvent.click(screen.getByText('Save')) | ||
fireEvent.click(screen.getByText('C OK')) | ||
expect(cb1.mock.calls.length).toBe(1) | ||
expect(cb2.mock.calls.length).toBe(1) | ||
expect(cb3.mock.calls.length).toBe(1) | ||
}) | ||
}) |
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,14 @@ | ||
import React from 'react' | ||
import Tabs from './Tabs' | ||
import FixtureContext from '../FixtureContext' | ||
import debug from '../utils/debug' | ||
|
||
|
||
export default ( | ||
<FixtureContext> | ||
<Tabs | ||
tabLabels={['Explore', 'Open', 'Save']} | ||
actionCb={() => debug().log('Clicked')} | ||
/> | ||
</FixtureContext> | ||
) |
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,25 @@ | ||
import React, {useState} from 'react' | ||
import MuiTabs from '@mui/material/Tabs' | ||
import Tab from '@mui/material/Tab' | ||
import {assertDefined} from '../utils/assert' | ||
|
||
|
||
/** | ||
* @property {Array<string>} tabLabels Names of each tab | ||
* @property {Function} actionCb callBack fired when the tabs is selected, returns currect tab number | ||
* @property {boolean} [isScrollable] Enable scrolling for many (> 5) tabs | ||
* @return {React.Component} | ||
*/ | ||
export default function Tabs({tabLabels, actionCb, isScrollable = false}) { | ||
assertDefined(tabLabels, actionCb) | ||
const [value, setValue] = useState(0) | ||
const handleChange = (event, newValue) => { | ||
setValue(newValue) | ||
actionCb(newValue) | ||
} | ||
return ( | ||
<MuiTabs value={value} onChange={handleChange} centered variant={isScrollable ? 'scrollable' : 'fullWidth'}> | ||
{tabLabels.map((tab) => <Tab key={tab} label={tab}/>)} | ||
</MuiTabs> | ||
) | ||
} |
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 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.