mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Download button
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/bootstrap/DownloadButton.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/bootstrap/DownloadButton.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2019 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.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from "react";
 | 
				
			||||||
 | 
					import PropTypes from "prop-types";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DownloadButton.propTypes = {
 | 
				
			||||||
 | 
					    href: PropTypes.string.isRequired,
 | 
				
			||||||
 | 
					    children: PropTypes.oneOfType([
 | 
				
			||||||
 | 
					        PropTypes.arrayOf(PropTypes.node),
 | 
				
			||||||
 | 
					        PropTypes.node,
 | 
				
			||||||
 | 
					    ]),
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function DownloadButton({ href, children }) {
 | 
				
			||||||
 | 
					    return <a href={href} className="btn btn-primary" download>{children}</a>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										7
									
								
								src/bootstrap/DownloadButton.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/bootstrap/DownloadButton.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					Hyperlink with apperance of a button.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					It has `download` attribute, which prevents closing WebSocket connection on Firefox. See [related issue](https://bugzilla.mozilla.org/show_bug.cgi?id=858538) for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```js
 | 
				
			||||||
 | 
					<DownloadButton href="example.zip">Download</DownloadButton>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/bootstrap/__tests__/DownloadButton.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/bootstrap/__tests__/DownloadButton.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2019 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.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import React from "react";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { render } from "customTestRender";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { DownloadButton } from "../DownloadButton";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe("<DownloadButton />", () => {
 | 
				
			||||||
 | 
					    it("should have download attribute", () => {
 | 
				
			||||||
 | 
					        const { container } = render(<DownloadButton href="http://example.com">Test Button</DownloadButton>);
 | 
				
			||||||
 | 
					        expect(container.firstChild.getAttribute("download")).not.toBeNull();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@@ -15,6 +15,7 @@ export { useAPIPatch } from "api/patch";
 | 
				
			|||||||
export { Alert } from "bootstrap/Alert";
 | 
					export { Alert } from "bootstrap/Alert";
 | 
				
			||||||
export { Button } from "bootstrap/Button";
 | 
					export { Button } from "bootstrap/Button";
 | 
				
			||||||
export { CheckBox } from "bootstrap/CheckBox";
 | 
					export { CheckBox } from "bootstrap/CheckBox";
 | 
				
			||||||
 | 
					export { DownloadButton } from "bootstrap/DownloadButton";
 | 
				
			||||||
export { DataTimeInput } from "bootstrap/DataTimeInput";
 | 
					export { DataTimeInput } from "bootstrap/DataTimeInput";
 | 
				
			||||||
export { EmailInput } from "bootstrap/EmailInput";
 | 
					export { EmailInput } from "bootstrap/EmailInput";
 | 
				
			||||||
export { FileInput } from "bootstrap/FileInput";
 | 
					export { FileInput } from "bootstrap/FileInput";
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user