@eeacms/volto-eea-design-system 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/DEVELOP.md +56 -0
  3. package/README.md +18 -0
  4. package/docker-compose.yml +32 -0
  5. package/locales/de/LC_MESSAGES/volto.po +14 -0
  6. package/locales/en/LC_MESSAGES/volto.po +14 -0
  7. package/locales/it/LC_MESSAGES/volto.po +14 -0
  8. package/locales/ro/LC_MESSAGES/volto.po +14 -0
  9. package/locales/volto.pot +16 -0
  10. package/package.json +1 -1
  11. package/src/helpers/index.js +4 -4
  12. package/src/helpers/useClickOutside.test.js +63 -0
  13. package/src/helpers/useFirstVisited.test.js +54 -0
  14. package/src/ui/Accordion/Accordion.stories.js +72 -25
  15. package/src/ui/Accordion/Accordion.stories.test.js +45 -0
  16. package/src/ui/Banner/Banner.jsx +9 -2
  17. package/src/ui/Banner/Banner.test.jsx +292 -0
  18. package/src/ui/CallToAction/CallToAction.stories.test.jsx +69 -0
  19. package/src/ui/Card/Card.stories.jsx +4 -1
  20. package/src/ui/Card/Card.stories.test.jsx +82 -0
  21. package/src/ui/Card/IconCard/IconCard.stories.test.jsx +64 -0
  22. package/src/ui/Card/RelatedContent/RelatedContent.jsx +1 -1
  23. package/src/ui/Card/RelatedContent/RelatedContent.stories.jsx +2 -2
  24. package/src/ui/Card/RelatedContent/RelatedContent.stories.test.jsx +65 -0
  25. package/src/ui/Confirm/Confirm.stories.test.js +27 -0
  26. package/src/ui/ContextNavigation/ContextNavigation.stories.test.jsx +170 -0
  27. package/src/ui/Divider/Divider.stories.test.jsx +44 -0
  28. package/src/ui/DownloadLabeledIcon/DownloadLabeledIcon.stories.test.jsx +24 -0
  29. package/src/ui/Footer/Description.test.jsx +11 -0
  30. package/src/ui/Footer/Footer.stories.test.js +131 -0
  31. package/src/ui/Footer/Social.test.jsx +11 -0
  32. package/src/ui/Form/Button/Button.stories.test.jsx +55 -0
  33. package/src/ui/Form/Checkbox.stories.test.js +79 -0
  34. package/src/ui/Form/Dropdown.stories.test.js +24 -0
  35. package/src/ui/Form/Radio.stories.test.js +55 -0
  36. package/src/ui/Form/Textarea.stories.test.js +41 -0
  37. package/src/ui/Form/input.stories.test.js +52 -0
  38. package/src/ui/Grid/ComponentGrid.stories.test.js +21 -0
  39. package/src/ui/Header/Header.jsx +4 -0
  40. package/src/ui/Header/Header.stories.js +26 -4
  41. package/src/ui/Header/Header.stories.test.js +158 -0
  42. package/src/ui/Header/Header.test.jsx +293 -0
  43. package/src/ui/Header/HeaderMenuPopUp.js +128 -107
  44. package/src/ui/Header/HeaderSearchPopUp.test.js +113 -0
  45. package/src/ui/Hero/Hero.stories.test.jsx +67 -0
  46. package/src/ui/InpageNavigation/InpageNavigation.stories.test.jsx +10 -0
  47. package/src/ui/InpageNavigation/InpageNavigation.test.jsx +87 -0
  48. package/src/ui/Item/Item.stories.test.js +39 -0
  49. package/src/ui/Item/ItemGroupWithIcons.stories.test.js +119 -0
  50. package/src/ui/Label/Label.stories.test.js +76 -0
  51. package/src/ui/LabeledIconGroup/LabeledIconGroup.stories.test.jsx +19 -0
  52. package/src/ui/LanguageLabeledIcon/LanguageLabeledIcon.jsx +3 -2
  53. package/src/ui/LanguageLabeledIcon/LanguangeLabeledIcon.test.jsx +60 -0
  54. package/src/ui/Loader/Loader.stories.test.jsx +30 -0
  55. package/src/ui/Logo/Logo.stories.test.jsx +81 -0
  56. package/src/ui/Media/Image.stories.test.js +35 -0
  57. package/src/ui/Message/Message.stories.test.js +44 -0
  58. package/src/ui/Modal/Modal.stories.test.js +45 -0
  59. package/src/ui/Popup/Popup.jsx +77 -81
  60. package/src/ui/Popup/Popup.stories.jsx +1 -1
  61. package/src/ui/Popup/Popup.test.jsx +60 -0
  62. package/src/ui/Progress/Progress.stories.test.js +30 -0
  63. package/src/ui/Quote/Testimonial/Testimonial.stories.test.jsx +18 -0
  64. package/src/ui/Statistic/Statistic.stories.test.js +69 -0
  65. package/src/ui/Table/Table.stories.js +8 -0
  66. package/src/ui/Table/Table.stories.test.js +54 -0
  67. package/src/ui/Timeline/Timeline.stories.test.jsx +43 -0
  68. package/src/ui/index.js +21 -41
  69. package/theme/plugins.js +182 -0
  70. package/theme/themes/eea/elements/input.overrides +1 -1
  71. package/theme/themes/eea/extras/banner.less +3 -4
  72. package/theme/themes/eea/extras/custom.overrides +5 -0
  73. package/theme/themes/eea/extras/header.less +3 -22
  74. package/theme/themes/eea/extras/header.variables +1 -1
  75. package/theme/themes/eea/extras/tagList.less +1 -1
  76. package/theme/themes/eea/extras/tagList.variables +1 -1
  77. package/theme/themes/eea/globals/site.variables +3 -3
  78. package/theme/themes/eea/globals/utilities.less +9 -0
  79. package/theme/themes/eea/modules/accordion.overrides +44 -42
  80. package/theme/themes/eea/modules/accordion.variables +4 -4
  81. package/theme/themes/eea/modules/popup.overrides +4 -0
  82. package/theme/themes/eea/views/card.overrides +5 -1
  83. package/theme/themes/eea/views/card.variables +1 -0
  84. package/.i18n.babel.config.js +0 -1
  85. package/src/i18n.js +0 -180
package/CHANGELOG.md CHANGED
@@ -4,6 +4,78 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [1.17.0](https://github.com/eea/volto-eea-design-system/compare/1.16.0...1.17.0) - 29 August 2023
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat(accordion): improve a11n by providing open close support using space bar on header [David Ichim - [`ac04dbd`](https://github.com/eea/volto-eea-design-system/commit/ac04dbd8fa166a70d535354f6ab631709ee021b3)]
12
+
13
+ #### :bug: Bug Fixes
14
+
15
+ - fix(popup): Fix wrong placement of Popper refs #256765 #384 from eea/popper [ichim-david - [`ee69ca2`](https://github.com/eea/volto-eea-design-system/commit/ee69ca299348509f10ecd954ae4415aaef347104)]
16
+ - fix(sharing): button placement and styling [David Ichim - [`15ecefc`](https://github.com/eea/volto-eea-design-system/commit/15ecefcb4e0a2fcc99d585bf0c913ea515b3f676)]
17
+
18
+ #### :nail_care: Enhancements
19
+
20
+ - change(accordion): removed listitem role from mobile accordion links [David Ichim - [`8b85dac`](https://github.com/eea/volto-eea-design-system/commit/8b85dac5451b10968275c9ed46a0b4cfc0ccd442)]
21
+ - change(mega-menu): mobile accordions now have aria expanded support [David Ichim - [`e0dbb3f`](https://github.com/eea/volto-eea-design-system/commit/e0dbb3f533c9022308527d2d44d32831f66b389f)]
22
+
23
+ #### :house: Internal changes
24
+
25
+ - chore: Remove i18n.js script [Alin Voinea - [`701b82a`](https://github.com/eea/volto-eea-design-system/commit/701b82a67dc97f774c6250d45f159c61b9c7bfec)]
26
+
27
+ #### :hammer_and_wrench: Others
28
+
29
+ - i18n: Add en [Alin Voinea - [`4584295`](https://github.com/eea/volto-eea-design-system/commit/458429530d993c27cfb962ddfe2f376f3568bf01)]
30
+ - Release 1.17.0 [Alin Voinea - [`e3c25ee`](https://github.com/eea/volto-eea-design-system/commit/e3c25eeeca5e863244faae396b5aa915d0702633)]
31
+ - test: add unit tests for DS components - refs #254313 [ana-oprea - [`0c4d4d1`](https://github.com/eea/volto-eea-design-system/commit/0c4d4d118b8e13082c576dc5c2dce6a715f49006)]
32
+ - chrore(mega-menu): mobile accordion accessibility enhancements #385 from eea/accordion-improvements [ichim-david - [`9dd717d`](https://github.com/eea/volto-eea-design-system/commit/9dd717dc4c82a220463da16dba33c9a9d1633c47)]
33
+ - fix popper [Dobricean Ioan Dorian - [`005f2be`](https://github.com/eea/volto-eea-design-system/commit/005f2be705136eebd5f8f4ae4dd5e27d9fbff15d)]
34
+ - fix [Dobricean Ioan Dorian - [`615e67f`](https://github.com/eea/volto-eea-design-system/commit/615e67ff3c9a0fbd6cc7cadbb0c845bf09eec4f0)]
35
+ - remove [Dobricean Ioan Dorian - [`bf3974b`](https://github.com/eea/volto-eea-design-system/commit/bf3974be18225c893fd09814cb2aca9a84ba0ece)]
36
+ - fix popper [Dobricean Ioan Dorian - [`762f199`](https://github.com/eea/volto-eea-design-system/commit/762f199ff5725e7ad1fb788feb4f7b7548d1ee44)]
37
+ - test: Update Makefile and docker-compose to align it with Jenkinsfile [valentinab25 - [`b7eea21`](https://github.com/eea/volto-eea-design-system/commit/b7eea21fd4e71c4f420cd061717166483082dd6e)]
38
+ ### [1.16.0](https://github.com/eea/volto-eea-design-system/compare/1.15.0...1.16.0) - 17 August 2023
39
+
40
+ #### :rocket: New Features
41
+
42
+ - feat(banner): allow Banner.Action to be a link #254325 #378 from eea/banner_link [ichim-david - [`144f71f`](https://github.com/eea/volto-eea-design-system/commit/144f71fdbf24aec8c35ae7cbb93cd719271a4413)]
43
+ - feat(accordion): eea design filtering support and theme refactoring #379 from eea/accordion-filter [ichim-david - [`7e82454`](https://github.com/eea/volto-eea-design-system/commit/7e82454490777a42bc032646483fee59e7236df4)]
44
+
45
+ #### :bug: Bug Fixes
46
+
47
+ - fix: use quanta-toolbar class as trigger #256275 [andreiggr - [`5ede47d`](https://github.com/eea/volto-eea-design-system/commit/5ede47dcc2bd9211ee963c7e881f9ee5663d9d1a)]
48
+ - fix: ensure rule only on quanta-toolbar #256275 [andreiggr - [`4b3e0a4`](https://github.com/eea/volto-eea-design-system/commit/4b3e0a4b6414aac5a9c21686043bc293a194afbd)]
49
+ - fix: teaserGrid controls move only on quanta-toolbar #256275 [andreiggr - [`90c9736`](https://github.com/eea/volto-eea-design-system/commit/90c973679e189587ed3d9afeb5e6a0eb84fa5852)]
50
+ - fix(popup): handle click outside popup area to close the popup [David Ichim - [`a6da52d`](https://github.com/eea/volto-eea-design-system/commit/a6da52d8e03f28fa851b841397e0f896223144b8)]
51
+ - fix(popup): ref error and make sure that all .popup-container .popup get their position fixed [David Ichim - [`4435c1f`](https://github.com/eea/volto-eea-design-system/commit/4435c1fd10f81c9366955567fc1bc6a2c5364ba7)]
52
+ - fix(carousel): lower opacity of arrows when we don't use infinite option [David Ichim - [`b8964c0`](https://github.com/eea/volto-eea-design-system/commit/b8964c0b5637da266c42e3785cfdf3f38babcdae)]
53
+
54
+ #### :nail_care: Enhancements
55
+
56
+ - change(accordion): use real icons for active and inactive panel icons #380 from eea/accordion-filtering [ichim-david - [`bb9e20c`](https://github.com/eea/volto-eea-design-system/commit/bb9e20ca9b68890852baae4f7a06c35db6136286)]
57
+ - change(accordion): simplify change of icon for filter icons [David Ichim - [`a1cb797`](https://github.com/eea/volto-eea-design-system/commit/a1cb797929ddda6513dcc7027f32ebad6992ee14)]
58
+ - change(accordion): make use of css variables for text and background colors [David Ichim - [`a6cddd5`](https://github.com/eea/volto-eea-design-system/commit/a6cddd542abb3d1aba3e985107410a60b697744e)]
59
+ - change(site): use css variable values for inputs for easier customization [David Ichim - [`7a085e2`](https://github.com/eea/volto-eea-design-system/commit/7a085e26496420a503ba5c21b3791e66af96c96c)]
60
+ - change(accordion): use the right selector for accordion panels hovering [dana-cfc4 - [`3b041b2`](https://github.com/eea/volto-eea-design-system/commit/3b041b29a4c871a50844f1054c7c39d3a468a7ae)]
61
+ - change(accordion): use a css variable for icon active and inactive [David Ichim - [`a11bf76`](https://github.com/eea/volto-eea-design-system/commit/a11bf76c8ba5d3f58f330a75e673a0eed7c10c7e)]
62
+ - change(popup): use a functional component for popup component using react-popper [David Ichim - [`3fe2629`](https://github.com/eea/volto-eea-design-system/commit/3fe26294162966d3815d74384f5e53071ad80b26)]
63
+ - change(carousel): modified setting of current dot based on parent li slick-active class [David Ichim - [`4ac957e`](https://github.com/eea/volto-eea-design-system/commit/4ac957ed7fcba588f56ba65f9405ad4e39b568b7)]
64
+
65
+ #### :house: Internal changes
66
+
67
+ - chore(accordion): Improve accordion filter styling -refs#254324 [dana-cfc4 - [`d3ca98e`](https://github.com/eea/volto-eea-design-system/commit/d3ca98e494a4e0a68880dd87ed0f90967c431d50)]
68
+ - chore: Add filter to accordion story -refs #254324 [dana-cfc4 - [`fdc906a`](https://github.com/eea/volto-eea-design-system/commit/fdc906a2e065e250bda198311e4e3b20b0880169)]
69
+
70
+ #### :house: Documentation changes
71
+
72
+ - docs: add links to docusaurus and storybook - refs #253277 [ana-oprea - [`9f7ba84`](https://github.com/eea/volto-eea-design-system/commit/9f7ba848d2e54ea7cd9d9eb92a0171274077e307)]
73
+ - docs: Cleanup Makefile, update DEVELOP documentation, i18n - refs #254894 [valentinab25 - [`df303a5`](https://github.com/eea/volto-eea-design-system/commit/df303a56e90581d6ed554e839343a359727bb166)]
74
+
75
+ #### :hammer_and_wrench: Others
76
+
77
+ - bump package release version [David Ichim - [`fff4264`](https://github.com/eea/volto-eea-design-system/commit/fff4264d5a91fbf2fc5fe52fb2cc530c77ea43b1)]
78
+ - Refs #254325; allow setting a Banner.Action to be a link [Tiberiu Ichim - [`18b00bf`](https://github.com/eea/volto-eea-design-system/commit/18b00bf355d8180d7ed4f43810e95fb6cef0e95c)]
7
79
  ### [1.15.0](https://github.com/eea/volto-eea-design-system/compare/1.14.0...1.15.0) - 26 July 2023
8
80
 
9
81
  #### :rocket: New Features
package/DEVELOP.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  ## Develop
4
4
 
5
+ 1. Make sure you have `docker` and `docker compose` installed and running on your machine:
6
+
7
+ ```Bash
8
+ git clone https://github.com/eea/volto-eea-design-system.git
9
+ cd volto-eea-design-system
10
+ git checkout -b bugfix-123456 develop
11
+ make
12
+ make start
13
+ ```
14
+
15
+ 1. Wait for `Volto started at 0.0.0.0:3000` meesage
16
+
17
+ 1. Go to http://localhost:3000
18
+
19
+ 1. Happy hacking!
20
+
21
+ ```Bash
22
+ cd src/addons/volto-eea-design-system/
23
+ ```
24
+
25
+ ### Or add @eeacms/volto-eea-design-system to your Volto project
26
+
5
27
  Before starting make sure your development environment is properly set. See [Volto Developer Documentation](https://docs.voltocms.com/getting-started/install/)
6
28
 
7
29
  1. Make sure you have installed `yo`, `@plone/generator-volto` and `mrs-developer`
@@ -49,3 +71,37 @@ Before starting make sure your development environment is properly set. See [Vol
49
71
  1. Happy hacking!
50
72
 
51
73
  cd src/addons/volto-eea-design-system/
74
+
75
+ ## Cypress
76
+
77
+ To run cypress locally, first make sure you don't have any Volto/Plone running on ports `8080` and `3000`.
78
+
79
+ You don't have to be in a `clean-volto-project`, you can be in any Volto Frontend
80
+ project where you added `volto-eea-design-system` to `mrs.developer.json`
81
+
82
+ Go to:
83
+
84
+ ```BASH
85
+ cd src/addons/volto-eea-design-system/
86
+ ```
87
+
88
+ Start:
89
+
90
+ ```Bash
91
+ make
92
+ make start
93
+ ```
94
+
95
+ This will build and start with Docker a clean `Plone backend` and `Volto Frontend` with `volto-eea-design-system` block installed.
96
+
97
+ Open Cypress Interface:
98
+
99
+ ```Bash
100
+ make cypress-open
101
+ ```
102
+
103
+ Or run it:
104
+
105
+ ```Bash
106
+ make cypress-run
107
+ ```
package/README.md CHANGED
@@ -27,10 +27,23 @@ This package provides the following features:
27
27
 
28
28
  ## Getting started
29
29
 
30
+ ### Try volto-eea-design-system with Docker
31
+
32
+ git clone https://github.com/eea/volto-eea-design-system.git
33
+ cd volto-eea-design-system
34
+ make
35
+ make start
36
+
37
+ Go to http://localhost:3000
38
+
30
39
  ### Add volto-eea-design-system to your Volto project
31
40
 
32
41
  1. Make sure you have a [Plone backend](https://plone.org/download) up-and-running at http://localhost:8080/Plone
33
42
 
43
+ ```Bash
44
+ docker compose up backend
45
+ ```
46
+
34
47
  1. Start Volto frontend
35
48
 
36
49
  - If you already have a volto project, just update `package.json`:
@@ -76,6 +89,11 @@ Checkout the docs found within the [mockups](https://github.com/eea/volto-eea-de
76
89
 
77
90
  See [RELEASE.md](https://github.com/eea/volto-eea-design-system/blob/master/RELEASE.md).
78
91
 
92
+ ## Docusaurus and Storybook
93
+
94
+ See [Docusaurus](https://eea.github.io/).
95
+ See [Storybook](https://eea.github.io/eea-storybook/).
96
+
79
97
  ## How to contribute
80
98
 
81
99
  See [DEVELOP.md](https://github.com/eea/volto-eea-design-system/blob/develop/DEVELOP.md).
@@ -0,0 +1,32 @@
1
+ version: "3"
2
+ services:
3
+ backend:
4
+ image: eeacms/plone-backend
5
+ ports:
6
+ - "8080:8080"
7
+ environment:
8
+ SITE: "Plone"
9
+ PROFILES: "eea.kitkat:testing"
10
+
11
+ frontend:
12
+ build:
13
+ context: ./
14
+ dockerfile: ./Dockerfile
15
+ args:
16
+ ADDON_NAME: "${ADDON_NAME}"
17
+ ADDON_PATH: "${ADDON_PATH}"
18
+ VOLTO_VERSION: ${VOLTO_VERSION:-16}
19
+ ports:
20
+ - "3000:3000"
21
+ - "3001:3001"
22
+ depends_on:
23
+ - backend
24
+ volumes:
25
+ - ./:/app/src/addons/${ADDON_PATH}
26
+ environment:
27
+ CI: "true"
28
+ NODE_ENV: "development"
29
+ RAZZLE_JEST_CONFIG: "src/addons/${ADDON_PATH}/jest-addon.config.js"
30
+ RAZZLE_INTERNAL_API_PATH: "http://backend:8080/Plone"
31
+ RAZZLE_DEV_PROXY_API_PATH: "http://backend:8080/Plone"
32
+ HOST: "0.0.0.0"
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
@@ -0,0 +1,14 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: \n"
8
+ "Language: \n"
9
+ "Language-Team: \n"
10
+ "Content-Type: \n"
11
+ "Content-Transfer-Encoding: \n"
12
+ "Plural-Forms: \n"
13
+
14
+
package/locales/volto.pot CHANGED
@@ -0,0 +1,16 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Plone\n"
4
+ "POT-Creation-Date: 2023-06-28T10:48:22.678Z\n"
5
+ "Last-Translator: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
6
+ "Language-Team: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
7
+ "MIME-Version: 1.0\n"
8
+ "Content-Type: text/plain; charset=utf-8\n"
9
+ "Content-Transfer-Encoding: 8bit\n"
10
+ "Plural-Forms: nplurals=1; plural=0;\n"
11
+ "Language-Code: en\n"
12
+ "Language-Name: English\n"
13
+ "Preferred-Encodings: utf-8\n"
14
+ "Domain: volto\n"
15
+
16
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-design-system",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "@eeacms/volto-eea-design-system: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -1,4 +1,4 @@
1
- export useClickOutside from './useClickOutside';
2
- export usePrevious from './usePrevious';
3
- export useFirstVisited from './useFirstVisited';
4
- export handleEnterKeyPress from './eventHandlers';
1
+ export { default as useClickOutside } from './useClickOutside';
2
+ export { default as usePrevious } from './usePrevious';
3
+ export { default as useFirstVisited } from './useFirstVisited';
4
+ export { default as handleEnterKeyPress } from './eventHandlers';
@@ -0,0 +1,63 @@
1
+ import { act, renderHook } from '@testing-library/react-hooks';
2
+ import useClickOutside from './useClickOutside';
3
+ import { doesNodeContainClick } from 'semantic-ui-react/dist/commonjs/lib';
4
+
5
+ jest.mock('semantic-ui-react/dist/commonjs/lib', () => ({
6
+ doesNodeContainClick: jest.fn(),
7
+ }));
8
+
9
+ describe('useClickOutside', () => {
10
+ let ref;
11
+ let callback;
12
+
13
+ beforeEach(() => {
14
+ ref = { current: {} };
15
+ callback = jest.fn();
16
+ });
17
+
18
+ it('does not call callback function when clicked inside', () => {
19
+ doesNodeContainClick.mockImplementation(() => true);
20
+
21
+ const { rerender } = renderHook(() =>
22
+ useClickOutside({ targetRefs: [ref], callback }),
23
+ );
24
+
25
+ act(() => {
26
+ document.dispatchEvent(new MouseEvent('mousedown'));
27
+ });
28
+
29
+ rerender();
30
+
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+
34
+ it('calls callback function when clicked outside', () => {
35
+ doesNodeContainClick.mockImplementation(() => false);
36
+
37
+ const { rerender } = renderHook(() =>
38
+ useClickOutside({ targetRefs: [ref], callback }),
39
+ );
40
+
41
+ act(() => {
42
+ document.dispatchEvent(new MouseEvent('mousedown'));
43
+ });
44
+
45
+ rerender();
46
+
47
+ expect(callback).toHaveBeenCalled();
48
+ });
49
+
50
+ it('calls callback function when clicked outside and no refs', () => {
51
+ doesNodeContainClick.mockImplementation(() => false);
52
+
53
+ const { rerender } = renderHook(() => useClickOutside({ callback }));
54
+
55
+ act(() => {
56
+ document.dispatchEvent(new MouseEvent('mousedown'));
57
+ });
58
+
59
+ rerender();
60
+
61
+ expect(callback).toHaveBeenCalled();
62
+ });
63
+ });
@@ -0,0 +1,54 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import useFirstVisited from './useFirstVisited';
3
+
4
+ describe('useFirstVisited', () => {
5
+ let observe;
6
+ let unobserve;
7
+ let callback;
8
+ let disconnect;
9
+
10
+ beforeEach(() => {
11
+ observe = jest.fn();
12
+ unobserve = jest.fn();
13
+ disconnect = jest.fn();
14
+
15
+ window.IntersectionObserver = jest.fn(function (cb) {
16
+ this.observe = observe;
17
+ this.unobserve = unobserve;
18
+ this.disconnect = disconnect;
19
+ callback = cb;
20
+ });
21
+ });
22
+ it('should set intersected to true when element is intersecting', async () => {
23
+ const ref = { current: document.createElement('div') };
24
+ const { result } = renderHook(() => useFirstVisited(ref));
25
+ const entry = { isIntersecting: true };
26
+
27
+ expect(result.current).toBe(false); // Initial state
28
+ callback([entry]);
29
+ expect(result.current).toBe(true);
30
+ });
31
+
32
+ it('should unobserve and disconnect when ref changes or component unmounts', () => {
33
+ const ref = { current: document.createElement('div') };
34
+ const newRef = { current: document.createElement('div') };
35
+ const { unmount, rerender } = renderHook(
36
+ ({ ref }) => useFirstVisited(ref),
37
+ {
38
+ initialProps: { ref },
39
+ },
40
+ );
41
+
42
+ expect(unobserve).not.toHaveBeenCalled();
43
+ expect(disconnect).not.toHaveBeenCalled();
44
+
45
+ rerender({ ref: newRef });
46
+ expect(unobserve).toHaveBeenCalled();
47
+ expect(disconnect).toHaveBeenCalled();
48
+
49
+ unmount();
50
+
51
+ expect(unobserve).toHaveBeenCalledTimes(2);
52
+ expect(disconnect).toHaveBeenCalledTimes(2);
53
+ });
54
+ });
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { Accordion, Icon, Container } from 'semantic-ui-react';
2
+ import { Accordion, Icon, Container, Input } from 'semantic-ui-react';
3
3
 
4
4
  export default {
5
5
  title: 'Components/Accordion',
@@ -30,11 +30,20 @@ export default {
30
30
  type: { summary: 'string' },
31
31
  },
32
32
  },
33
+ enable_filtering: {
34
+ name: 'Enable filtering',
35
+ defaultValue: false,
36
+ table: {
37
+ defaultValue: { summary: false },
38
+ type: { summary: 'boolean' },
39
+ },
40
+ },
33
41
  },
34
42
  };
35
43
 
36
44
  function AccordionContainer({ ...args }) {
37
45
  const [activeIndex, setActiveIndex] = useState([0]);
46
+ const [filterValue, setFilterValue] = useState('');
38
47
 
39
48
  const handleClick = (e, titleProps) => {
40
49
  const { index } = titleProps;
@@ -43,33 +52,70 @@ function AccordionContainer({ ...args }) {
43
52
  setActiveIndex(newIndex);
44
53
  };
45
54
 
55
+ const handleFilteredValueChange = (value) => {
56
+ setFilterValue(value);
57
+ };
58
+
46
59
  return (
47
60
  <Container>
48
61
  <div className="accordion-block">
49
- {args.panels.map((panel, index) => {
50
- return (
51
- <Accordion className={args.variant} key={index}>
52
- <Accordion.Title
53
- index={index}
54
- tabIndex={0}
55
- active={activeIndex === index}
56
- onClick={handleClick}
57
- as={args.title_size === 'no value' ? '' : args.title_size}
58
- onKeyDown={(e) => {
59
- if (e.nativeEvent.keyCode === 13) {
60
- handleClick(e, { index });
61
- }
62
- }}
63
- >
64
- <span>{panel.title}</span>
65
- <Icon className="ri-arrow-down-s-line" />
66
- </Accordion.Title>
67
- <Accordion.Content active={activeIndex === index}>
68
- {panel.content}
69
- </Accordion.Content>
70
- </Accordion>
71
- );
72
- })}
62
+ {args.enable_filtering && (
63
+ <Accordion className={args.variant}>
64
+ <Accordion.Title className={'filter'}>
65
+ <Input
66
+ fluid
67
+ className="input-accordion-title"
68
+ transparent
69
+ placeholder="Type to filter..."
70
+ value={filterValue}
71
+ onChange={(e) => handleFilteredValueChange(e.target.value)}
72
+ />
73
+ <Icon
74
+ className={filterValue ? 'ri-close-line' : 'ri-filter-3-line'}
75
+ onClick={() => handleFilteredValueChange('')}
76
+ />
77
+ </Accordion.Title>
78
+ </Accordion>
79
+ )}
80
+ {args.panels
81
+ .filter(
82
+ (panel) =>
83
+ !args.enable_filtering ||
84
+ filterValue === '' ||
85
+ (filterValue !== '' &&
86
+ panel.title?.toLowerCase().includes(filterValue.toLowerCase())),
87
+ )
88
+ .map((panel, index) => {
89
+ const active = activeIndex === index;
90
+ return (
91
+ <Accordion className={args.variant} key={index}>
92
+ <Accordion.Title
93
+ index={index}
94
+ tabIndex={0}
95
+ active={active}
96
+ role="button"
97
+ aria-expanded={activeIndex === index}
98
+ onClick={handleClick}
99
+ as={args.title_size === 'no value' ? '' : args.title_size}
100
+ onKeyDown={(e) => {
101
+ if (e.keyCode === 13 || e.keyCode === 32) {
102
+ handleClick(e, { index });
103
+ }
104
+ }}
105
+ >
106
+ <span>{panel.title}</span>
107
+ <Icon
108
+ className={
109
+ active ? 'ri-arrow-down-s-line' : 'ri-arrow-up-s-line'
110
+ }
111
+ />
112
+ </Accordion.Title>
113
+ <Accordion.Content active={active}>
114
+ {panel.content}
115
+ </Accordion.Content>
116
+ </Accordion>
117
+ );
118
+ })}
73
119
  </div>
74
120
  </Container>
75
121
  );
@@ -80,6 +126,7 @@ export const Default = Template.bind({});
80
126
  Default.args = {
81
127
  variant: 'secondary',
82
128
  title_size: 'no value',
129
+ enable_filtering: false,
83
130
  panels: [
84
131
  {
85
132
  title: 'Water and marine environment',
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import { Default } from './Accordion.stories';
4
+ import '@testing-library/jest-dom/extend-expect';
5
+
6
+ describe('Default component', () => {
7
+ it('renders correctly and fires keyDown Enter events', () => {
8
+ const { getByText, getAllByText } = render(<Default {...Default.args} />);
9
+
10
+ Default.args.panels.forEach((panel) => {
11
+ expect(getByText(panel.title)).toBeInTheDocument();
12
+ });
13
+
14
+ expect(getAllByText(Default.args.panels[0].content)).toHaveLength(3);
15
+ fireEvent.keyDown(getByText(Default.args.panels[0].title), {
16
+ key: 'Enter',
17
+ code: 'Enter',
18
+ keyCode: 13,
19
+ charCode: 13,
20
+ });
21
+
22
+ fireEvent.keyDown(getByText(Default.args.panels[0].title), {
23
+ key: 'Enter',
24
+ code: 'Enter',
25
+ keyCode: 13,
26
+ charCode: 13,
27
+ });
28
+ });
29
+
30
+ it('renders correctly and fires keyDown A event', () => {
31
+ const { getByText, getAllByText } = render(
32
+ <Default {...Default.args} title_size={'h1'} />,
33
+ );
34
+
35
+ Default.args.panels.forEach((panel) => {
36
+ expect(getByText(panel.title)).toBeInTheDocument();
37
+ });
38
+
39
+ expect(getAllByText(Default.args.panels[0].content)).toHaveLength(3);
40
+ fireEvent.keyDown(getByText(Default.args.panels[0].title), {
41
+ key: 'A',
42
+ code: 'KeyA',
43
+ });
44
+ });
45
+ });
@@ -67,12 +67,19 @@ function Banner({ image, metadata, properties, children, ...rest }) {
67
67
  }
68
68
 
69
69
  Banner.Action = React.forwardRef(function (
70
- { id, title, titleClass, icon, onClick, className, color },
70
+ { id, title, titleClass, icon, onClick, className, color, ...rest },
71
71
  ref,
72
72
  ) {
73
73
  return (
74
74
  <div className="action" ref={ref}>
75
- <Button className={className} basic icon inverted onClick={onClick}>
75
+ <Button
76
+ className={className}
77
+ basic
78
+ icon
79
+ inverted
80
+ onClick={onClick}
81
+ {...rest}
82
+ >
76
83
  <Icon className={icon} color={color}></Icon>
77
84
  <span className={titleClass || 'mobile hidden'}>{title}</span>
78
85
  </Button>