-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend]Improvements to initial file chooser commit
- Loading branch information
1 parent
8ff802d
commit ec3ea15
Showing
6 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...top/core/src/desktop/js/reactComponents/FileChooser/FileChooserModal/FileChooserModal.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import Modal from 'antd/lib/modal/Modal'; | ||
|
||
interface FileProps { | ||
show: boolean; | ||
onCancel: () => void; | ||
title: string; | ||
okText: string; | ||
} | ||
|
||
const defaultProps = { title: 'Choose a file', okText: 'Select' }; | ||
|
||
const FileChooserModal: React.FC<FileProps> = ({ show, onCancel, title, okText }) => { | ||
const handleOk = () => { | ||
//temporary until the file is selected through the file chooser compoent | ||
onCancel(); | ||
}; | ||
|
||
const handleCancel = () => { | ||
onCancel(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title={title} | ||
open={show} | ||
onOk={handleOk} | ||
onCancel={handleCancel} | ||
okText={okText} | ||
></Modal> | ||
); | ||
}; | ||
|
||
FileChooserModal.defaultProps = defaultProps; | ||
|
||
export default FileChooserModal; |
8 changes: 8 additions & 0 deletions
8
...c/desktop/js/reactComponents/FileChooser/FileChooserWithButton/FileChooserWithButton.scss
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,8 @@ | ||
@use '../../../components/styles/colors' as colors; | ||
|
||
.file-chooser__button { | ||
background-color: colors.$hue-primary-color-dark; | ||
color: white; | ||
margin-left: 40px; | ||
margin-top: 12px; | ||
} |
14 changes: 14 additions & 0 deletions
14
...sktop/js/reactComponents/FileChooser/FileChooserWithButton/FileChooserWithButton.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import React from 'react'; | ||
|
||
import FileChooserWithButton from './FileChooserWithButton'; | ||
|
||
test('Filechooser modal opens on button click', async () => { | ||
const user = userEvent.setup(); | ||
const { queryByText } = render(<FileChooserWithButton title={'File chooser component'} />); | ||
await user.click(screen.getByRole('button', { name: 'File chooser component' })); | ||
expect(queryByText('Choose a file')).toBeInTheDocument(); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...rc/desktop/js/reactComponents/FileChooser/FileChooserWithButton/FileChooserWithButton.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useState } from 'react'; | ||
import { Button } from 'antd'; | ||
|
||
import './FileChooserWithButton.scss'; | ||
import FileChooserModal from '../FileChooserModal/FileChooserModal'; | ||
|
||
interface FileChooserWithButtonProps { | ||
title: string; | ||
} | ||
|
||
const defaultProps = { title: 'File chooser component' }; | ||
|
||
const FileChooserWithButton: React.FC<FileChooserWithButtonProps> = ({ title }): JSX.Element => { | ||
const [show, setShow] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Button className="file-chooser__button" type="primary" onClick={() => setShow(true)}> | ||
{title} | ||
</Button> | ||
|
||
<FileChooserModal | ||
onCancel={() => setShow(false)} | ||
show={show} | ||
title="Choose a file" | ||
okText="Select" | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
FileChooserWithButton.defaultProps = defaultProps; | ||
|
||
export default FileChooserWithButton; |
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