1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-25 00:11:36 +01:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Aleksandr Gumroian
14b90bbbd4 Merge branch 'dev' into 'master'
Dev

See merge request turris/reforis/foris-js!251
2024-10-02 14:35:17 +02:00
Aleksandr Gumroian
85b207b1dd Merge branch 'bump-version-640' into 'dev'
Bump v6.4.0

See merge request turris/reforis/foris-js!250
2024-10-02 14:31:57 +02:00
Aleksandr Gumroian
79e61d9507
Bump v6.4.0
* Refactor Alert component to include dismiss animation and timeout
* Refactor ThreeDotsMenu component to include additional props
2024-10-02 14:30:09 +02:00
Aleksandr Gumroian
6795c3941b Merge branch 'add-alert-animation-and-timeout' into 'dev'
Add Alert animation and timeout

See merge request turris/reforis/foris-js!249
2024-10-02 13:48:31 +02:00
Aleksandr Gumroian
969e8e6411
Update Snapshots 2024-10-02 13:16:45 +02:00
Aleksandr Gumroian
0099759279
Fix tests 2024-10-02 13:16:37 +02:00
Aleksandr Gumroian
87c81a2a2d
Refactor Alert component to include dismiss animation and timeout 2024-10-02 13:14:48 +02:00
Aleksandr Gumroian
81b71f8153
Refactor ThreeDotsMenu component to include additional props 2024-10-02 13:14:40 +02:00
7 changed files with 39 additions and 12 deletions

View File

@ -8,6 +8,13 @@ and this project adheres to
## [Unreleased]
## [6.4.0] - 2024-10-02
### Changed
- Refactored Alert component to include dismiss animation and timeout
- Refactored ThreeDotsMenu component to include additional props
## [6.3.0] - 2024-09-27
### Added
@ -398,7 +405,8 @@ and this project adheres to
## [0.0.7] - 2019-09-02
[unreleased]:
https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.3.0...dev
https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.4.0...dev
[6.4.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.3.0...v6.4.0
[6.3.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.2.1...v6.3.0
[6.2.1]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.2.0...v6.2.1
[6.2.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.1.1...v6.2.0

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "foris",
"version": "6.3.0",
"version": "6.4.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "foris",
"version": "6.3.0",
"version": "6.4.0",
"license": "GPL-3.0",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.6.0",

View File

@ -1,6 +1,6 @@
{
"name": "foris",
"version": "6.3.0",
"version": "6.4.0",
"description": "Foris JS library is a set of components and utils for reForis application and plugins.",
"author": "CZ.NIC, z.s.p.o.",
"repository": {

View File

@ -5,7 +5,7 @@
* See /LICENSE for more information.
*/
import React, { useRef } from "react";
import React, { useRef, useEffect, useState } from "react";
import PropTypes from "prop-types";
@ -40,20 +40,36 @@ Alert.defaultProps = {
function Alert({ type, onDismiss, children }) {
const alertRef = useRef();
const [isVisible, setIsVisible] = useState(true);
useFocusTrap(alertRef, !!onDismiss);
useEffect(() => {
if (onDismiss) {
const timeout = setTimeout(() => setIsVisible(false), 7000);
return () => clearTimeout(timeout);
}
}, [onDismiss]);
const handleAnimationEnd = () => {
if (!isVisible && onDismiss) {
onDismiss();
}
};
return (
<div
ref={alertRef}
className={`alert alert-${type} ${
className={`alert alert-${type} ${isVisible ? "alert-fade-in" : "alert-slide-out-top"} ${
onDismiss ? "alert-dismissible" : ""
}`.trim()}
role="alert"
onAnimationEnd={handleAnimationEnd}
>
{onDismiss && (
<button
type="button"
className="btn-close"
onClick={onDismiss}
onClick={() => setIsVisible(false)}
aria-label={_("Close")}
/>
)}

View File

@ -18,9 +18,9 @@ ThreeDotsMenu.propTypes = {
children: PropTypes.arrayOf(PropTypes.node).isRequired,
};
function ThreeDotsMenu({ children }) {
function ThreeDotsMenu({ children, ...props }) {
return (
<div className="dropdown">
<div className="dropdown position-static" {...props}>
<Button
className="btn-sm btn-link text-body"
data-bs-toggle="dropdown"

View File

@ -43,14 +43,17 @@ describe("AlertContext", () => {
expect(componentContainer).toMatchSnapshot();
});
it("should dismiss alert with alert button", () => {
it("should dismiss alert with alert button", async () => {
fireEvent.click(getByText(componentContainer, "Set alert"));
// Alert is present
expect(getByText(componentContainer, "Alert content")).toBeDefined();
fireEvent.click(componentContainer.querySelector(".btn-close"));
// Alert is gone
expect(queryByText(componentContainer, "Alert content")).toBeNull();
await (() =>
expect(
queryByText(componentContainer, "Alert content")
).toBeNull());
});
it("should dismiss alert with external button", () => {

View File

@ -6,7 +6,7 @@ exports[`AlertContext should render alert 1`] = `
id="alert-container"
>
<div
class="alert alert-danger alert-dismissible"
class="alert alert-danger alert-fade-in alert-dismissible"
role="alert"
>
<button