mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Fix and update docs.
This commit is contained in:
		
							
								
								
									
										4
									
								
								src/alertContext/AlertContext.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/alertContext/AlertContext.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
It provides alert context to children. `AlertContext` allows using `useAlert` in components.
 | 
			
		||||
 | 
			
		||||
Notice that `<div id="alert-container"/>` should be presented in HTML doc to get it work (In reForis it's already done
 | 
			
		||||
with base Jinja2 templates).
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
Bootstrap alert component.
 | 
			
		||||
 | 
			
		||||
```jsx
 | 
			
		||||
import {useState} from 'react';
 | 
			
		||||
 | 
			
		||||
@@ -7,14 +8,14 @@ function AlertExample(){
 | 
			
		||||
    if (alert)
 | 
			
		||||
        return <Alert 
 | 
			
		||||
            type='warning' 
 | 
			
		||||
            message='Some warning out there!' 
 | 
			
		||||
            onDismiss={()=>setAlert(false)}
 | 
			
		||||
        />;
 | 
			
		||||
        >
 | 
			
		||||
            Some warning out there!        
 | 
			
		||||
        </Alert>;
 | 
			
		||||
    return <button 
 | 
			
		||||
        className='btn btn-secondary' 
 | 
			
		||||
        onClick={()=>setAlert(true)}
 | 
			
		||||
    >Show alert again</button>;
 | 
			
		||||
};
 | 
			
		||||
<AlertExample/>
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,8 @@ FileInput.propTypes = {
 | 
			
		||||
    helpText: PropTypes.string,
 | 
			
		||||
    /** Email value. */
 | 
			
		||||
    value: PropTypes.string,
 | 
			
		||||
    /** Allow selecting multiple files. */
 | 
			
		||||
    multiple: PropTypes.bool,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export function FileInput({ ...props }) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,13 +3,39 @@ Bootstrap component for file input. Includes label and has predefined sizes and
 | 
			
		||||
All additional `props` are passed to the `<input type="file">` HTML component.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import {useState} from 'react';
 | 
			
		||||
import { useState } from 'react';
 | 
			
		||||
 | 
			
		||||
const [files, setFiles] = useState([]);
 | 
			
		||||
 | 
			
		||||
<FileInput
 | 
			
		||||
    files={files}
 | 
			
		||||
    label="Some file"
 | 
			
		||||
    helpText="Will be uploaded"
 | 
			
		||||
    onChange={event =>setFiles(event.target.files)}
 | 
			
		||||
/>
 | 
			
		||||
// Note that files is not an array but FileList.
 | 
			
		||||
const label = files.length === 1 ? files[0].name : "Choose file";
 | 
			
		||||
 | 
			
		||||
<form className="col">
 | 
			
		||||
    <FileInput
 | 
			
		||||
        files={files}
 | 
			
		||||
        label={label}
 | 
			
		||||
        helpText="Will be uploaded"
 | 
			
		||||
        onChange={event=>setFiles(event.target.files)}
 | 
			
		||||
    />
 | 
			
		||||
</form>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### FileInput with multiple files
 | 
			
		||||
```js
 | 
			
		||||
import { useState } from 'react';
 | 
			
		||||
 | 
			
		||||
const [files, setFiles] = useState([]);
 | 
			
		||||
 | 
			
		||||
// Note that files is not an array but FileList.
 | 
			
		||||
const label = files.length > 0 ? Array.from(files).map(file=>file.name).join(", ") : "Choose files";
 | 
			
		||||
 | 
			
		||||
<form className="col">
 | 
			
		||||
    <FileInput
 | 
			
		||||
        files={files}
 | 
			
		||||
        label={label}
 | 
			
		||||
        helpText="Will be uploaded"
 | 
			
		||||
        onChange={event=>setFiles(event.target.files)}
 | 
			
		||||
        multiple
 | 
			
		||||
    />
 | 
			
		||||
</form>
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
@@ -6,8 +6,6 @@ it's required to have an element `<div id={"modal-container"}/>` somewhere on th
 | 
			
		||||
    <div id="modal-container"/>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
I have no idea why example doesn't work here but you can investigate HTML code and Foris project.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import {ModalHeader, ModalBody, ModalFooter} from './Modal';
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/testUtils/mockGlobals.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/testUtils/mockGlobals.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/)
 | 
			
		||||
 *
 | 
			
		||||
 * This is free software, licensed under the GNU General Public License v3.
 | 
			
		||||
 * See /LICENSE for more information.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// Mock babel (gettext)
 | 
			
		||||
global._ = (str) => str;
 | 
			
		||||
global.ngettext = (str) => str;
 | 
			
		||||
global.babel = { format: (str) => str };
 | 
			
		||||
global.ForisTranslations = { locale: "en" };
 | 
			
		||||
@@ -7,18 +7,13 @@
 | 
			
		||||
 | 
			
		||||
import mockAxios from "jest-mock-axios";
 | 
			
		||||
import moment from "moment-timezone";
 | 
			
		||||
import "./mockGlobals";
 | 
			
		||||
 | 
			
		||||
// Setup axios cleanup
 | 
			
		||||
global.afterEach(() => {
 | 
			
		||||
    mockAxios.reset();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Mock babel (gettext)
 | 
			
		||||
global._ = (str) => str;
 | 
			
		||||
global.ngettext = (str) => str;
 | 
			
		||||
global.babel = { format: (str) => str };
 | 
			
		||||
global.ForisTranslations = { locale: "en" };
 | 
			
		||||
 | 
			
		||||
// Mock web sockets
 | 
			
		||||
window.WebSocket = jest.fn();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user