@scottish-government/designsystem-react 0.12.1 → 1.0.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 (490) hide show
  1. package/.storybook/main.ts +6 -6
  2. package/.storybook/sgdsArgTypes.ts +107 -43
  3. package/CHANGELOG.md +49 -0
  4. package/LICENSE.txt +21 -0
  5. package/README.md +3 -0
  6. package/dist/common/AbstractNotificationBanner/AbstractNotificationBanner.d.ts +3 -2
  7. package/dist/common/AbstractNotificationBanner/AbstractNotificationBanner.jsx +8 -7
  8. package/dist/common/AbstractNotificationBanner/types.d.ts +13 -0
  9. package/dist/common/AbstractNotificationBanner/types.js +2 -0
  10. package/dist/common/ActionLink/ActionLink.d.ts +2 -1
  11. package/dist/common/ActionLink/types.d.ts +7 -0
  12. package/dist/common/ActionLink/types.js +2 -0
  13. package/dist/common/ConditionalWrapper/ConditionalWrapper.d.ts +2 -1
  14. package/dist/common/ConditionalWrapper/ConditionalWrapper.jsx +4 -2
  15. package/dist/common/ConditionalWrapper/types.d.ts +4 -0
  16. package/dist/common/ConditionalWrapper/types.js +2 -0
  17. package/dist/common/FileIcon/FileIcon.d.ts +2 -1
  18. package/dist/common/FileIcon/types.d.ts +6 -0
  19. package/dist/common/FileIcon/types.js +2 -0
  20. package/dist/common/HintText/HintText.d.ts +2 -1
  21. package/dist/common/HintText/HintText.jsx +3 -3
  22. package/dist/common/HintText/types.d.ts +4 -0
  23. package/dist/common/HintText/types.js +2 -0
  24. package/dist/common/Icon/Icon.d.ts +2 -1
  25. package/dist/common/Icon/Icon.jsx +3 -2
  26. package/dist/common/Icon/types.d.ts +8 -0
  27. package/dist/common/Icon/types.js +2 -0
  28. package/dist/common/ScreenReaderText/ScreenReaderText.d.ts +1 -1
  29. package/dist/common/WrapperTag/WrapperTag.d.ts +385 -1
  30. package/dist/common/WrapperTag/WrapperTag.jsx +5 -2
  31. package/dist/common/WrapperTag/types.d.ts +3 -0
  32. package/dist/common/WrapperTag/types.js +2 -0
  33. package/dist/components/Accordion/Accordion.d.ts +3 -2
  34. package/dist/components/Accordion/Accordion.jsx +12 -11
  35. package/dist/components/Accordion/types.d.ts +11 -0
  36. package/dist/components/Accordion/types.js +2 -0
  37. package/dist/components/AspectBox/AspectBox.d.ts +2 -1
  38. package/dist/components/AspectBox/AspectBox.jsx +3 -9
  39. package/dist/components/AspectBox/types.d.ts +3 -0
  40. package/dist/components/AspectBox/types.js +2 -0
  41. package/dist/components/BackToTop/BackToTop.d.ts +2 -1
  42. package/dist/components/BackToTop/BackToTop.jsx +4 -3
  43. package/dist/components/BackToTop/types.d.ts +3 -0
  44. package/dist/components/BackToTop/types.js +2 -0
  45. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -2
  46. package/dist/components/Breadcrumbs/Breadcrumbs.jsx +6 -2
  47. package/dist/components/Breadcrumbs/types.d.ts +5 -0
  48. package/dist/components/Breadcrumbs/types.js +2 -0
  49. package/dist/components/Button/Button.d.ts +2 -1
  50. package/dist/components/Button/Button.jsx +4 -3
  51. package/dist/components/Button/ButtonGroup.d.ts +2 -1
  52. package/dist/components/Button/ButtonGroup.jsx +9 -4
  53. package/dist/components/Button/types.d.ts +20 -0
  54. package/dist/components/Button/types.js +2 -0
  55. package/dist/components/Card/Card.d.ts +34 -0
  56. package/dist/components/Card/Card.jsx +118 -0
  57. package/dist/components/Card/index.d.ts +1 -0
  58. package/dist/components/Card/index.js +8 -0
  59. package/dist/components/Card/types.d.ts +26 -0
  60. package/dist/components/Card/types.js +2 -0
  61. package/dist/components/CategoryItem/CategoryItem.d.ts +2 -1
  62. package/dist/components/CategoryItem/CategoryItem.jsx +8 -5
  63. package/dist/components/CategoryItem/types.d.ts +9 -0
  64. package/dist/components/CategoryItem/types.js +2 -0
  65. package/dist/components/CategoryList/CategoryList.d.ts +2 -1
  66. package/dist/components/CategoryList/CategoryList.jsx +3 -2
  67. package/dist/components/CategoryList/types.d.ts +5 -0
  68. package/dist/components/CategoryList/types.js +2 -0
  69. package/dist/components/Checkbox/Checkbox.d.ts +2 -1
  70. package/dist/components/Checkbox/Checkbox.jsx +4 -3
  71. package/dist/components/Checkbox/CheckboxGroup.d.ts +2 -1
  72. package/dist/components/Checkbox/CheckboxGroup.jsx +5 -4
  73. package/dist/components/Checkbox/types.d.ts +7 -0
  74. package/dist/components/Checkbox/types.js +2 -0
  75. package/dist/components/ConfirmationMessage/ConfirmationMessage.d.ts +2 -1
  76. package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +3 -2
  77. package/dist/components/ConfirmationMessage/types.d.ts +6 -0
  78. package/dist/components/ConfirmationMessage/types.js +2 -0
  79. package/dist/components/ContentsNav/ContentsNav.d.ts +3 -2
  80. package/dist/components/ContentsNav/ContentsNav.jsx +7 -5
  81. package/dist/components/ContentsNav/types.d.ts +9 -0
  82. package/dist/components/ContentsNav/types.js +2 -0
  83. package/dist/components/CookieBanner/CookieBanner.d.ts +3 -2
  84. package/dist/components/CookieBanner/CookieBanner.jsx +13 -3
  85. package/dist/components/DatePicker/DatePicker.d.ts +2 -1
  86. package/dist/components/DatePicker/DatePicker.jsx +7 -7
  87. package/dist/components/DatePicker/types.d.ts +18 -0
  88. package/dist/components/DatePicker/types.js +2 -0
  89. package/dist/components/Details/Details.d.ts +2 -1
  90. package/dist/components/Details/Details.jsx +6 -2
  91. package/dist/components/Details/types.d.ts +4 -0
  92. package/dist/components/Details/types.js +2 -0
  93. package/dist/components/ErrorMessage/ErrorMessage.d.ts +2 -1
  94. package/dist/components/ErrorMessage/ErrorMessage.jsx +6 -2
  95. package/dist/components/ErrorMessage/types.d.ts +3 -0
  96. package/dist/components/ErrorMessage/types.js +2 -0
  97. package/dist/components/ErrorSummary/ErrorSummary.d.ts +3 -2
  98. package/dist/components/ErrorSummary/ErrorSummary.jsx +6 -2
  99. package/dist/components/ErrorSummary/types.d.ts +8 -0
  100. package/dist/components/ErrorSummary/types.js +2 -0
  101. package/dist/components/FeatureHeader/FeatureHeader.d.ts +7 -5
  102. package/dist/components/FeatureHeader/FeatureHeader.jsx +87 -50
  103. package/dist/components/FeatureHeader/types.d.ts +12 -0
  104. package/dist/components/FeatureHeader/types.js +2 -0
  105. package/dist/components/FileDownload/FileDownload.d.ts +2 -1
  106. package/dist/components/FileDownload/FileDownload.jsx +4 -3
  107. package/dist/components/FileDownload/types.d.ts +10 -0
  108. package/dist/components/FileDownload/types.js +2 -0
  109. package/dist/components/HideThisPage/HideThisPage.d.ts +2 -1
  110. package/dist/components/HideThisPage/HideThisPage.jsx +5 -4
  111. package/dist/components/HideThisPage/types.d.ts +3 -0
  112. package/dist/components/HideThisPage/types.js +2 -0
  113. package/dist/components/InsetText/InsetText.d.ts +1 -1
  114. package/dist/components/InsetText/InsetText.jsx +6 -2
  115. package/dist/components/NotificationBanner/NotificationBanner.d.ts +3 -2
  116. package/dist/components/NotificationBanner/NotificationBanner.jsx +5 -4
  117. package/dist/components/NotificationPanel/NotificationPanel.d.ts +2 -1
  118. package/dist/components/NotificationPanel/NotificationPanel.jsx +3 -2
  119. package/dist/components/NotificationPanel/types.d.ts +6 -0
  120. package/dist/components/NotificationPanel/types.js +2 -0
  121. package/dist/components/NotificationTag/NotificationTag.d.ts +6 -0
  122. package/dist/components/NotificationTag/NotificationTag.jsx +20 -0
  123. package/dist/components/NotificationTag/index.d.ts +1 -0
  124. package/dist/components/NotificationTag/index.js +8 -0
  125. package/dist/components/NotificationTag/types.d.ts +5 -0
  126. package/dist/components/NotificationTag/types.js +2 -0
  127. package/dist/components/PageHeader/PageHeader.d.ts +2 -1
  128. package/dist/components/PageHeader/PageHeader.jsx +6 -2
  129. package/dist/components/PageHeader/types.d.ts +5 -0
  130. package/dist/components/PageHeader/types.js +2 -0
  131. package/dist/components/PageMetadata/PageMetadata.d.ts +3 -2
  132. package/dist/components/PageMetadata/PageMetadata.jsx +8 -4
  133. package/dist/components/PageMetadata/types.d.ts +6 -0
  134. package/dist/components/PageMetadata/types.js +2 -0
  135. package/dist/components/Pagination/Pagination.d.ts +3 -2
  136. package/dist/components/Pagination/Pagination.jsx +7 -5
  137. package/dist/components/Pagination/types.d.ts +18 -0
  138. package/dist/components/Pagination/types.js +2 -0
  139. package/dist/components/PhaseBanner/PhaseBanner.d.ts +2 -1
  140. package/dist/components/PhaseBanner/PhaseBanner.jsx +3 -2
  141. package/dist/components/PhaseBanner/types.d.ts +3 -0
  142. package/dist/components/PhaseBanner/types.js +2 -0
  143. package/dist/components/Question/Question.d.ts +2 -1
  144. package/dist/components/Question/Question.jsx +4 -3
  145. package/dist/components/Question/types.d.ts +9 -0
  146. package/dist/components/Question/types.js +2 -0
  147. package/dist/components/RadioButton/RadioButton.d.ts +2 -1
  148. package/dist/components/RadioButton/RadioButton.jsx +4 -3
  149. package/dist/components/RadioButton/RadioGroup.d.ts +2 -1
  150. package/dist/components/RadioButton/RadioGroup.jsx +3 -2
  151. package/dist/components/RadioButton/types.d.ts +10 -0
  152. package/dist/components/RadioButton/types.js +2 -0
  153. package/dist/components/SearchFacets/SearchFacets.d.ts +4 -3
  154. package/dist/components/SearchFacets/SearchFacets.jsx +3 -2
  155. package/dist/components/SearchFacets/types.d.ts +12 -0
  156. package/dist/components/SearchFacets/types.js +2 -0
  157. package/dist/components/SearchFilters/SearchFilters.d.ts +5 -4
  158. package/dist/components/SearchFilters/types.d.ts +12 -0
  159. package/dist/components/SearchFilters/types.js +2 -0
  160. package/dist/components/SearchResult/SearchResult.d.ts +8 -11
  161. package/dist/components/SearchResult/SearchResult.jsx +6 -7
  162. package/dist/components/SearchResult/types.d.ts +11 -0
  163. package/dist/components/SearchResult/types.js +2 -0
  164. package/dist/components/SearchSort/SearchSort.d.ts +2 -1
  165. package/dist/components/SearchSort/SearchSort.jsx +3 -2
  166. package/dist/components/SearchSort/types.d.ts +7 -0
  167. package/dist/components/SearchSort/types.js +2 -0
  168. package/dist/components/Select/Select.d.ts +2 -1
  169. package/dist/components/Select/Select.jsx +4 -3
  170. package/dist/components/Select/types.d.ts +6 -0
  171. package/dist/components/Select/types.js +2 -0
  172. package/dist/components/SequentialNavigation/SequentialNavigation.d.ts +4 -3
  173. package/dist/components/SequentialNavigation/SequentialNavigation.jsx +10 -6
  174. package/dist/components/SequentialNavigation/types.d.ts +10 -0
  175. package/dist/components/SequentialNavigation/types.js +2 -0
  176. package/dist/components/SideNavigation/SideNavigation.d.ts +4 -3
  177. package/dist/components/SideNavigation/SideNavigation.jsx +10 -7
  178. package/dist/components/SideNavigation/types.d.ts +13 -0
  179. package/dist/components/SideNavigation/types.js +2 -0
  180. package/dist/components/SiteFooter/SiteFooter.d.ts +6 -5
  181. package/dist/components/SiteFooter/SiteFooter.jsx +4 -3
  182. package/dist/components/SiteFooter/types.d.ts +16 -0
  183. package/dist/components/SiteFooter/types.js +2 -0
  184. package/dist/components/SiteHeader/SiteHeader.d.ts +6 -5
  185. package/dist/components/SiteHeader/SiteHeader.jsx +1 -1
  186. package/dist/components/SiteHeader/types.d.ts +20 -0
  187. package/dist/components/SiteHeader/types.js +2 -0
  188. package/dist/components/SiteNavigation/SiteNavigation.d.ts +3 -2
  189. package/dist/components/SiteNavigation/SiteNavigation.jsx +12 -4
  190. package/dist/components/SiteNavigation/types.d.ts +9 -0
  191. package/dist/components/SiteNavigation/types.js +2 -0
  192. package/dist/components/SiteSearch/SiteSearch.d.ts +2 -1
  193. package/dist/components/SiteSearch/SiteSearch.jsx +12 -11
  194. package/dist/components/SiteSearch/types.d.ts +17 -0
  195. package/dist/components/SiteSearch/types.js +2 -0
  196. package/dist/components/SkipLinks/SkipLinks.d.ts +3 -2
  197. package/dist/components/SkipLinks/SkipLinks.jsx +4 -4
  198. package/dist/components/SkipLinks/types.d.ts +8 -0
  199. package/dist/components/SkipLinks/types.js +2 -0
  200. package/dist/components/SummaryCard/SummaryCard.d.ts +4 -2
  201. package/dist/components/SummaryCard/SummaryCard.jsx +5 -4
  202. package/dist/components/SummaryCard/types.d.ts +5 -0
  203. package/dist/components/SummaryCard/types.js +2 -0
  204. package/dist/components/SummaryList/SummaryList.d.ts +6 -4
  205. package/dist/components/SummaryList/SummaryList.jsx +5 -4
  206. package/dist/components/SummaryList/types.d.ts +6 -0
  207. package/dist/components/SummaryList/types.js +2 -0
  208. package/dist/components/Table/Table.d.ts +2 -1
  209. package/dist/components/Table/Table.jsx +5 -4
  210. package/dist/components/Table/types.d.ts +6 -0
  211. package/dist/components/Table/types.js +2 -0
  212. package/dist/components/Tabs/Tabs.d.ts +3 -2
  213. package/dist/components/Tabs/Tabs.jsx +6 -5
  214. package/dist/components/Tabs/types.d.ts +16 -0
  215. package/dist/components/Tabs/types.js +2 -0
  216. package/dist/components/Tag/Tag.d.ts +2 -1
  217. package/dist/components/Tag/Tag.jsx +7 -3
  218. package/dist/components/Tag/types.d.ts +4 -0
  219. package/dist/components/Tag/types.js +2 -0
  220. package/dist/components/TaskList/TaskList.d.ts +4 -3
  221. package/dist/components/TaskList/TaskList.jsx +11 -8
  222. package/dist/components/TaskList/types.d.ts +17 -0
  223. package/dist/components/TaskList/types.js +2 -0
  224. package/dist/components/TextInput/TextInput.d.ts +2 -1
  225. package/dist/components/TextInput/TextInput.jsx +10 -9
  226. package/dist/components/TextInput/types.d.ts +11 -0
  227. package/dist/components/TextInput/types.js +2 -0
  228. package/dist/components/Textarea/Textarea.d.ts +2 -1
  229. package/dist/components/Textarea/Textarea.jsx +6 -5
  230. package/dist/components/WarningText/WarningText.d.ts +1 -1
  231. package/dist/components/WarningText/WarningText.jsx +6 -2
  232. package/dist/hooks/useTracking/useTracking.js +0 -1
  233. package/eslint.config.mjs +32 -0
  234. package/package.json +12 -5
  235. package/src/common/AbstractNotificationBanner/AbstractNotificationBanner.tsx +13 -10
  236. package/src/common/AbstractNotificationBanner/types.ts +15 -0
  237. package/src/common/ActionLink/ActionLink.tsx +3 -1
  238. package/src/common/ActionLink/types.ts +8 -0
  239. package/src/common/ConditionalWrapper/ConditionalWrapper.tsx +10 -2
  240. package/src/common/ConditionalWrapper/types.ts +4 -0
  241. package/src/common/FileIcon/FileIcon.tsx +2 -1
  242. package/src/common/FileIcon/types.ts +7 -0
  243. package/src/common/HintText/HintText.test.tsx +3 -15
  244. package/src/common/HintText/HintText.tsx +4 -4
  245. package/src/common/HintText/types.ts +4 -0
  246. package/src/common/Icon/Icon.tsx +5 -3
  247. package/src/common/Icon/types.ts +9 -0
  248. package/src/common/ScreenReaderText/ScreenReaderText.tsx +1 -1
  249. package/src/common/WrapperTag/WrapperTag.tsx +5 -3
  250. package/src/common/WrapperTag/types.ts +3 -0
  251. package/src/components/Accordion/Accordion.Item.stories.tsx +1 -5
  252. package/src/components/Accordion/Accordion.stories.tsx +5 -5
  253. package/src/components/Accordion/Accordion.test.tsx +11 -0
  254. package/src/components/Accordion/Accordion.tsx +15 -13
  255. package/src/components/Accordion/types.ts +13 -0
  256. package/src/components/AspectBox/AspectBox.stories.tsx +1 -2
  257. package/src/components/AspectBox/AspectBox.tsx +8 -14
  258. package/src/components/AspectBox/types.ts +3 -0
  259. package/src/components/BackToTop/BackToTop.test.tsx +21 -1
  260. package/src/components/BackToTop/BackToTop.tsx +6 -4
  261. package/src/components/BackToTop/types.ts +3 -0
  262. package/src/components/Breadcrumbs/Breadcrumbs.tsx +7 -4
  263. package/src/components/Breadcrumbs/types.ts +6 -0
  264. package/src/components/Button/Button.tsx +6 -4
  265. package/src/components/Button/ButtonGroup.stories.tsx +22 -0
  266. package/src/components/Button/ButtonGroup.test.tsx +21 -0
  267. package/src/components/Button/ButtonGroup.tsx +9 -4
  268. package/src/components/Button/types.ts +22 -0
  269. package/src/components/Card/Card.stories.tsx +446 -0
  270. package/src/components/Card/Card.test.tsx +282 -0
  271. package/src/components/Card/Card.tsx +208 -0
  272. package/src/components/Card/index.ts +1 -0
  273. package/src/components/Card/types.ts +30 -0
  274. package/src/components/CategoryItem/CategoryItem.tsx +10 -6
  275. package/src/components/CategoryItem/types.ts +10 -0
  276. package/src/components/CategoryList/CategoryList.tsx +7 -4
  277. package/src/components/CategoryList/types.ts +5 -0
  278. package/src/components/Checkbox/Checkbox.stories.tsx +3 -3
  279. package/src/components/Checkbox/Checkbox.test.tsx +30 -0
  280. package/src/components/Checkbox/Checkbox.tsx +8 -7
  281. package/src/components/Checkbox/CheckboxGroup.test.tsx +10 -0
  282. package/src/components/Checkbox/CheckboxGroup.tsx +7 -6
  283. package/src/components/Checkbox/types.ts +9 -0
  284. package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +5 -3
  285. package/src/components/ConfirmationMessage/types.ts +7 -0
  286. package/src/components/ContentsNav/ContentsNav.stories.tsx +5 -1
  287. package/src/components/ContentsNav/ContentsNav.tsx +11 -7
  288. package/src/components/ContentsNav/types.ts +11 -0
  289. package/src/components/CookieBanner/CookieBanner.Buttons.stories.tsx +3 -3
  290. package/src/components/CookieBanner/CookieBanner.stories.tsx +6 -6
  291. package/src/components/CookieBanner/CookieBanner.test.tsx +24 -1
  292. package/src/components/CookieBanner/CookieBanner.tsx +16 -5
  293. package/src/components/DatePicker/DatePicker.test.tsx +52 -19
  294. package/src/components/DatePicker/DatePicker.tsx +8 -8
  295. package/src/components/DatePicker/types.ts +19 -0
  296. package/src/components/Details/Details.stories.tsx +1 -1
  297. package/src/components/Details/Details.tsx +6 -3
  298. package/src/components/Details/types.ts +4 -0
  299. package/src/components/ErrorMessage/ErrorMessage.tsx +6 -3
  300. package/src/components/ErrorMessage/types.ts +3 -0
  301. package/src/components/ErrorSummary/ErrorSummary.test.tsx +1 -1
  302. package/src/components/ErrorSummary/ErrorSummary.tsx +6 -4
  303. package/src/components/ErrorSummary/types.ts +11 -0
  304. package/src/components/FeatureHeader/FeatureHeader.stories.tsx +186 -23
  305. package/src/components/FeatureHeader/FeatureHeader.test.tsx +298 -0
  306. package/src/components/FeatureHeader/FeatureHeader.tsx +83 -58
  307. package/src/components/FeatureHeader/types.ts +13 -0
  308. package/src/components/FileDownload/FileDownload.test.tsx +1 -5
  309. package/src/components/FileDownload/FileDownload.tsx +6 -4
  310. package/src/components/FileDownload/types.ts +11 -0
  311. package/src/components/HideThisPage/HideThisPage.test.tsx +12 -1
  312. package/src/components/HideThisPage/HideThisPage.tsx +7 -5
  313. package/src/components/HideThisPage/types.ts +3 -0
  314. package/src/components/InsetText/InsetText.tsx +5 -3
  315. package/src/components/NotificationBanner/NotificationBanner.stories.tsx +2 -2
  316. package/src/components/NotificationBanner/NotificationBanner.test.tsx +10 -0
  317. package/src/components/NotificationBanner/NotificationBanner.tsx +8 -6
  318. package/src/components/NotificationPanel/NotificationPanel.tsx +5 -3
  319. package/src/components/NotificationPanel/types.ts +7 -0
  320. package/src/components/NotificationTag/NotificationTag.stories.tsx +68 -0
  321. package/src/components/NotificationTag/NotificationTag.test.tsx +70 -0
  322. package/src/components/NotificationTag/NotificationTag.tsx +32 -0
  323. package/src/components/NotificationTag/index.ts +1 -0
  324. package/src/components/NotificationTag/types.ts +5 -0
  325. package/src/components/PageHeader/PageHeader.tsx +6 -3
  326. package/src/components/PageHeader/types.ts +5 -0
  327. package/src/components/PageMetadata/PageMetadata.stories.tsx +1 -1
  328. package/src/components/PageMetadata/PageMetadata.tsx +10 -7
  329. package/src/components/PageMetadata/types.ts +7 -0
  330. package/src/components/Pagination/Pagination.test.tsx +20 -0
  331. package/src/components/Pagination/Pagination.tsx +12 -8
  332. package/src/components/Pagination/types.ts +20 -0
  333. package/src/components/PhaseBanner/PhaseBanner.stories.tsx +1 -4
  334. package/src/components/PhaseBanner/PhaseBanner.tsx +5 -3
  335. package/src/components/PhaseBanner/types.ts +3 -0
  336. package/src/components/Question/Question.tsx +6 -4
  337. package/src/components/Question/types.ts +9 -0
  338. package/src/components/RadioButton/RadioButton.test.tsx +30 -0
  339. package/src/components/RadioButton/RadioButton.tsx +8 -7
  340. package/src/components/RadioButton/RadioGroup.tsx +5 -3
  341. package/src/components/RadioButton/types.ts +12 -0
  342. package/src/components/SearchFacets/SearchFacets.Group.stories.tsx +2 -3
  343. package/src/components/SearchFacets/SearchFacets.stories.tsx +2 -2
  344. package/src/components/SearchFacets/SearchFacets.tsx +10 -8
  345. package/src/components/SearchFacets/types.ts +14 -0
  346. package/src/components/SearchFilters/SearchFilters.Panel.stories.tsx +18 -7
  347. package/src/components/SearchFilters/SearchFilters.stories.tsx +1 -1
  348. package/src/components/SearchFilters/SearchFilters.tsx +4 -3
  349. package/src/components/SearchFilters/types.ts +14 -0
  350. package/src/components/SearchResult/SearchResult.stories.tsx +23 -23
  351. package/src/components/SearchResult/SearchResult.test.tsx +5 -4
  352. package/src/components/SearchResult/SearchResult.tsx +15 -15
  353. package/src/components/SearchResult/types.ts +13 -0
  354. package/src/components/SearchSort/SearchSort.stories.tsx +2 -1
  355. package/src/components/SearchSort/SearchSort.tsx +5 -3
  356. package/src/components/SearchSort/types.ts +7 -0
  357. package/src/components/Select/Select.test.tsx +42 -0
  358. package/src/components/Select/Select.tsx +8 -6
  359. package/src/components/Select/types.ts +7 -0
  360. package/src/components/SequentialNavigation/SequentialNavigation.tsx +13 -10
  361. package/src/components/SequentialNavigation/types.ts +12 -0
  362. package/src/components/SideNavigation/SideNavigation.test.tsx +24 -0
  363. package/src/components/SideNavigation/SideNavigation.tsx +14 -10
  364. package/src/components/SideNavigation/types.ts +16 -0
  365. package/src/components/SiteFooter/SiteFooter.tsx +10 -8
  366. package/src/components/SiteFooter/types.ts +20 -0
  367. package/src/components/SiteHeader/SiteHeader.stories.tsx +4 -3
  368. package/src/components/SiteHeader/SiteHeader.test.tsx +29 -16
  369. package/src/components/SiteHeader/SiteHeader.tsx +10 -9
  370. package/src/components/SiteHeader/types.ts +22 -0
  371. package/src/components/SiteNavigation/SiteNavigation.test.tsx +16 -1
  372. package/src/components/SiteNavigation/SiteNavigation.tsx +13 -6
  373. package/src/components/SiteNavigation/types.ts +11 -0
  374. package/src/components/SiteSearch/SiteSearch.stories.tsx +4 -2
  375. package/src/components/SiteSearch/SiteSearch.test.tsx +22 -0
  376. package/src/components/SiteSearch/SiteSearch.tsx +15 -13
  377. package/src/components/SiteSearch/types.ts +19 -0
  378. package/src/components/SkipLinks/SkipLinks.stories.tsx +3 -3
  379. package/src/components/SkipLinks/SkipLinks.tsx +7 -7
  380. package/src/components/SkipLinks/types.ts +9 -0
  381. package/src/components/SummaryCard/SummaryCard.test.tsx +0 -11
  382. package/src/components/SummaryCard/SummaryCard.tsx +9 -6
  383. package/src/components/SummaryCard/types.ts +6 -0
  384. package/src/components/SummaryList/SummaryList.Item.stories.tsx +5 -5
  385. package/src/components/SummaryList/SummaryList.stories.tsx +1 -1
  386. package/src/components/SummaryList/SummaryList.test.tsx +1 -6
  387. package/src/components/SummaryList/SummaryList.tsx +11 -9
  388. package/src/components/SummaryList/types.ts +7 -0
  389. package/src/components/Table/Table.test.tsx +36 -0
  390. package/src/components/Table/Table.tsx +7 -5
  391. package/src/components/Table/types.ts +6 -0
  392. package/src/components/Tabs/Tabs.Item.stories.tsx +7 -7
  393. package/src/components/Tabs/Tabs.stories.tsx +3 -3
  394. package/src/components/Tabs/Tabs.test.tsx +14 -0
  395. package/src/components/Tabs/Tabs.tsx +12 -9
  396. package/src/components/Tabs/types.ts +19 -0
  397. package/src/components/Tag/Tag.tsx +7 -4
  398. package/src/components/Tag/types.ts +5 -0
  399. package/src/components/TaskList/TaskList.Group.stories.tsx +0 -5
  400. package/src/components/TaskList/TaskList.stories.tsx +0 -1
  401. package/src/components/TaskList/TaskList.tsx +17 -13
  402. package/src/components/TaskList/types.ts +20 -0
  403. package/src/components/TextInput/TextInput.test.tsx +53 -1
  404. package/src/components/TextInput/TextInput.tsx +17 -12
  405. package/src/components/TextInput/types.ts +12 -0
  406. package/src/components/Textarea/Textarea.test.tsx +53 -1
  407. package/src/components/Textarea/Textarea.tsx +10 -8
  408. package/src/components/WarningText/WarningText.tsx +5 -3
  409. package/src/hooks/useTracking/useTracking.test.tsx +5 -7
  410. package/src/hooks/useTracking/useTracking.ts +0 -1
  411. package/src/images/icons/arrow_upward.tsx +10 -10
  412. package/src/images/icons/calendar_today.tsx +10 -10
  413. package/src/images/icons/cancel.tsx +8 -8
  414. package/src/images/icons/check_circle.tsx +10 -10
  415. package/src/images/icons/chevron_left.tsx +10 -10
  416. package/src/images/icons/chevron_right.tsx +10 -10
  417. package/src/images/icons/close.tsx +10 -10
  418. package/src/images/icons/description.tsx +10 -10
  419. package/src/images/icons/double_chevron_left.tsx +8 -8
  420. package/src/images/icons/double_chevron_right.tsx +8 -8
  421. package/src/images/icons/error.tsx +10 -10
  422. package/src/images/icons/expand_less.tsx +10 -10
  423. package/src/images/icons/expand_more.tsx +10 -10
  424. package/src/images/icons/list.tsx +13 -13
  425. package/src/images/icons/menu.tsx +10 -10
  426. package/src/images/icons/priority_high.tsx +11 -11
  427. package/src/images/icons/search.tsx +10 -10
  428. package/src/shared-types.ts +40 -0
  429. package/static/images/illustration.svg +502 -0
  430. package/tsconfig.json +0 -3
  431. package/vite.config.ts +6 -1
  432. package/@types/common/AbstractNotificationBanner.d.ts +0 -17
  433. package/@types/common/ActionLink.d.ts +0 -8
  434. package/@types/common/ConditionalWrapper.d.ts +0 -6
  435. package/@types/common/FileIcon.d.ts +0 -7
  436. package/@types/common/HintText.d.ts +0 -6
  437. package/@types/common/Icon.d.ts +0 -9
  438. package/@types/common/ScreenReaderText.d.ts +0 -4
  439. package/@types/common/WrapperTag.d.ts +0 -5
  440. package/@types/components/Accordion.d.ts +0 -15
  441. package/@types/components/AspectBox.d.ts +0 -5
  442. package/@types/components/BackToTop.d.ts +0 -5
  443. package/@types/components/Breadcrumbs.d.ts +0 -11
  444. package/@types/components/Button.d.ts +0 -17
  445. package/@types/components/ButtonGroup.d.ts +0 -5
  446. package/@types/components/CategoryItem.d.ts +0 -10
  447. package/@types/components/CategoryList.d.ts +0 -7
  448. package/@types/components/Checkbox.d.ts +0 -11
  449. package/@types/components/ConfirmationMessage.d.ts +0 -7
  450. package/@types/components/ContentsNav.d.ts +0 -13
  451. package/@types/components/DatePicker.d.ts +0 -20
  452. package/@types/components/Details.d.ts +0 -6
  453. package/@types/components/ErrorMessage.d.ts +0 -5
  454. package/@types/components/ErrorSummary.d.ts +0 -12
  455. package/@types/components/FileDownload.d.ts +0 -11
  456. package/@types/components/HideThisPage.d.ts +0 -5
  457. package/@types/components/InsetText.d.ts +0 -5
  458. package/@types/components/Metadata.d.ts +0 -11
  459. package/@types/components/NotificationPanel.d.ts +0 -7
  460. package/@types/components/PageHeader.d.ts +0 -7
  461. package/@types/components/Pagination.d.ts +0 -22
  462. package/@types/components/PhaseBanner.d.ts +0 -5
  463. package/@types/components/Question.d.ts +0 -11
  464. package/@types/components/RadioButton.d.ts +0 -14
  465. package/@types/components/SearchFacets.d.ts +0 -18
  466. package/@types/components/SearchFilters.d.ts +0 -14
  467. package/@types/components/SearchResult.d.ts +0 -30
  468. package/@types/components/SearchSort.d.ts +0 -9
  469. package/@types/components/Select.d.ts +0 -7
  470. package/@types/components/SequentialNavigation.d.ts +0 -14
  471. package/@types/components/SideNavigation.d.ts +0 -18
  472. package/@types/components/SiteFooter.d.ts +0 -25
  473. package/@types/components/SiteHeader.d.ts +0 -20
  474. package/@types/components/SiteNavigation.d.ts +0 -13
  475. package/@types/components/SiteSearch.d.ts +0 -14
  476. package/@types/components/SkipLinks.d.ts +0 -13
  477. package/@types/components/SummaryCard.d.ts +0 -6
  478. package/@types/components/SummaryList.d.ts +0 -14
  479. package/@types/components/Table.d.ts +0 -8
  480. package/@types/components/Tabs.d.ts +0 -21
  481. package/@types/components/Tag.d.ts +0 -5
  482. package/@types/components/TaskList.d.ts +0 -22
  483. package/@types/components/TextInput.d.ts +0 -12
  484. package/@types/components/Textarea.d.ts +0 -4
  485. package/@types/components/WarningText.d.ts +0 -5
  486. package/@types/global.d.ts +0 -1
  487. package/@types/sgds.d.ts +0 -49
  488. package/dist/index.d.ts +0 -4
  489. package/dist/index.js +0 -40
  490. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,19 +1,21 @@
1
1
  import React, { Children, useId } from 'react';
2
-
3
2
  import ActionLink from '../../common/ActionLink';
4
3
  import ConditionalWrapper from '../../common/ConditionalWrapper';
4
+ import { SummaryListItemProps, SummaryListProps } from './types';
5
+ import { ActionLinkProps } from '@/src/common/ActionLink/types';
6
+ import clsx from 'clsx';
5
7
 
6
8
  const Item = ({
7
9
  children,
8
10
  title
9
- }: SGDS.Component.SummaryList.Item) => {
10
- let values: any[] = [];
11
- let actions: any[] = [];
11
+ }: SummaryListItemProps) => {
12
+ const values: React.ReactElement[] = [];
13
+ const actions: React.ReactElement[] = [];
12
14
 
13
15
  const describedById = useId();
14
16
 
15
17
  Children.forEach(children, (child: React.ReactNode) => {
16
- const thisChild = child as React.ReactElement<SGDS.Common.ActionLink>;
18
+ const thisChild = child as React.ReactElement<ActionLinkProps>;
17
19
  if (thisChild && thisChild.type === Value) {
18
20
  values.push(thisChild);
19
21
  } else if (thisChild && thisChild.type === ActionLink) {
@@ -64,7 +66,7 @@ const Item = ({
64
66
 
65
67
  const Value = ({
66
68
  children
67
- }: SGDS.Component.SummaryList.Answer) => {
69
+ }: React.AllHTMLAttributes<HTMLElement>) => {
68
70
  return (
69
71
  <q className="ds_summary-list__answer">{children}</q>
70
72
  );
@@ -75,14 +77,14 @@ const SummaryList = ({
75
77
  className,
76
78
  isBorderless,
77
79
  ...props
78
- }: SGDS.Component.SummaryList) => {
80
+ }: SummaryListProps) => {
79
81
  return (
80
82
  <ol
81
- className={[
83
+ className={clsx([
82
84
  'ds_summary-list',
83
85
  isBorderless && 'ds_summary-list--no-border',
84
86
  className
85
- ].join(' ')}
87
+ ])}
86
88
  {...props}
87
89
  >
88
90
  {children}
@@ -0,0 +1,7 @@
1
+ export interface SummaryListItemProps extends React.LiHTMLAttributes<HTMLLIElement> {
2
+ title: string;
3
+ }
4
+
5
+ export interface SummaryListProps extends React.OlHTMLAttributes<HTMLOListElement> {
6
+ isBorderless?: boolean;
7
+ }
@@ -58,6 +58,42 @@ test('table with smallscreen behaviour', () => {
58
58
  expect(table.nodeName).toEqual('TABLE');
59
59
  });
60
60
 
61
+ test('instantiating/initialising DS component script: smallscreen', () => {
62
+ render(
63
+ <Table smallscreen="scrolling">
64
+ <caption>Public holidays in 2020</caption>
65
+ <thead>
66
+ <tr>
67
+ <th scope="col">Date</th>
68
+ <th scope="col">Day</th>
69
+ <th scope="col">Holiday</th>
70
+ </tr>
71
+ </thead>
72
+ <tbody>
73
+ <tr>
74
+ <td>10 April</td>
75
+ <td>Friday</td>
76
+ <td>Good Friday</td>
77
+ </tr>
78
+ </tbody>
79
+ </Table>
80
+ );
81
+
82
+ const table = screen.getByRole('table');
83
+ expect(table).toHaveClass('js-initialised');
84
+ expect(table).toHaveClass('js-instantiated');
85
+ });
86
+
87
+ test('instantiating/initialising DS component script: not smallscreen', () => {
88
+ render(
89
+ <Table />
90
+ );
91
+
92
+ const table = screen.getByRole('table');
93
+ expect(table).not.toHaveClass('js-initialised');
94
+ expect(table).not.toHaveClass('js-instantiated');
95
+ });
96
+
61
97
  test('passing additional props', () => {
62
98
  render(
63
99
  <Table data-test="foo"/>
@@ -1,27 +1,29 @@
1
1
  import { useEffect, useRef } from 'react';
2
- // @ts-ignore
3
2
  import DSTable from '@scottish-government/design-system/src/components/table/table';
3
+ import { TableProps } from './types';
4
+ import clsx from 'clsx';
4
5
 
5
6
  const Table = ({
6
7
  children,
7
8
  className,
8
9
  smallscreen,
9
10
  ...props
10
- }: SGDS.Component.Table) => {
11
+ }: TableProps) => {
11
12
  const ref = useRef(null);
12
13
 
13
14
  useEffect(() => {
15
+ /* istanbul ignore else */
14
16
  if (ref.current) {
15
- new DSTable().init();
17
+ new DSTable(ref.current).init();
16
18
  }
17
19
  }, [ref]);
18
20
 
19
21
  return (
20
22
  <table
21
- className={[
23
+ className={clsx([
22
24
  'ds_table',
23
25
  className
24
- ].join(' ')}
26
+ ])}
25
27
  data-smallscreen={smallscreen}
26
28
  ref={ref}
27
29
  {...props}
@@ -0,0 +1,6 @@
1
+ type SmallScreen = 'scrolling' | 'boxes';
2
+
3
+ export interface TableProps extends React.AllHTMLAttributes<HTMLTableElement> {
4
+ className?: string;
5
+ smallscreen?: SmallScreen;
6
+ }
@@ -17,15 +17,15 @@ const meta = {
17
17
  children: argTypes.children()
18
18
  },
19
19
  args: {
20
- baseId: 'my-tabs',
21
20
  children: [
22
- <h3>Search for training courses and funding</h3>,
23
- <p>A wide range of training courses for your employees are available.</p>,
24
- <p>Opportunities include distance learning, short courses and vocational training.</p>,
25
- <p><a href="#">Visit My World of Work to search for training courses</a>.</p>,
26
- <p>You can also <a href="#">search for training courses, and funding towards training</a>.</p>
21
+ <h3 key="1">Search for training courses and funding</h3>,
22
+ <p key="2">A wide range of training courses for your employees are available.</p>,
23
+ <p key="3">Opportunities include distance learning, short courses and vocational training.</p>,
24
+ <p key="4"><a href="#">Visit My World of Work to search for training courses</a>.</p>,
25
+ <p key="5">You can also <a href="#">search for training courses, and funding towards training</a>.</p>
27
26
  ],
28
- tabLabel: 'Courses and funding'
27
+ tabLabel: 'Courses and funding',
28
+ id: 'my-tab'
29
29
  }
30
30
  } satisfies Meta<typeof Tabs.Item>;
31
31
 
@@ -35,14 +35,14 @@ const meta = {
35
35
  args: {
36
36
  baseId: 'my-tabs',
37
37
  children: [
38
- <Tabs.Item key="foo" tabLabel="Courses and funding">
38
+ <Tabs.Item id="foo" key="foo" tabLabel="Courses and funding">
39
39
  <h3>Search for training courses and funding</h3>
40
40
  <p>A wide range of training courses for your employees are available.</p>
41
41
  <p>Opportunities include distance learning, short courses and vocational training.</p>
42
42
  <p><a href="#">Visit My World of Work to search for training courses</a>.</p>
43
43
  <p>You can also <a href="#">search for training courses, and funding towards training</a>.</p>
44
44
  </Tabs.Item>,
45
- <Tabs.Item key="bar" tabLabel="Choosing apprenticeships">
45
+ <Tabs.Item id="bar" key="bar" tabLabel="Choosing apprenticeships">
46
46
  <h3>Choosing an apprenticeship for your business</h3>
47
47
  <p>Apprenticeships can help you address skills gaps in your business. The government provides help with the cost of training an apprentice.</p>
48
48
  <p>There are 3 different types of apprenticeship:</p>
@@ -53,7 +53,7 @@ const meta = {
53
53
  </ul>
54
54
  <p>You can find more information on the <a href="#">apprenticeships.scot</a> website.</p>
55
55
  </Tabs.Item>,
56
- <Tabs.Item key="baz" tabLabel="Extra skills support">
56
+ <Tabs.Item id="baz" key="baz" tabLabel="Extra skills support">
57
57
  <h3>Extra skills support</h3>
58
58
  <p>The <a href="#">Skills for Growth</a> service can offer skills advice to businesses with fewer than 250 employees.</p>
59
59
  <p>Businesses of any size can get skills advice by completing a <a href="#">skills support request form</a>.</p>
@@ -187,6 +187,20 @@ test('with manual activation', () => {
187
187
  expect(tabContainer).toHaveClass('ds_tabs--manual');
188
188
  });
189
189
 
190
+ test('instantiating/initialising DS component script', () => {
191
+ render(
192
+ <Tabs data-testid="tabcontainer" data-test="foo">
193
+ <Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
194
+ <div data-testid="tabpanel1content">Content one</div>
195
+ </Tabs.Item>
196
+ </Tabs>
197
+ );
198
+
199
+ const tabContainer = screen.getByTestId('tabcontainer');
200
+ expect(tabContainer).toHaveClass('js-initialised');
201
+ expect(tabContainer).toHaveClass('js-instantiated');
202
+ });
203
+
190
204
  test('passing additional props to tab container', () => {
191
205
  render(
192
206
  <Tabs data-testid="tabcontainer" data-test="foo">
@@ -1,7 +1,8 @@
1
1
  import React, { Children, useEffect, useRef, useId } from 'react';
2
2
  import WrapperTag from '../../common/WrapperTag';
3
- // @ts-ignore
4
3
  import DSTabs from '@scottish-government/design-system/src/components/tabs/tabs';
4
+ import { TabListItemProps, TabsItemProps, TabsProps } from './types';
5
+ import clsx from 'clsx';
5
6
 
6
7
  const TabItem = ({
7
8
  isBorderless,
@@ -10,14 +11,15 @@ const TabItem = ({
10
11
  id,
11
12
  tabLabel,
12
13
  ...props
13
- }: SGDS.Component.Tabs.Item) => {
14
+ }: TabsItemProps) => {
14
15
  return (
15
16
  <div
16
- className={[
17
+ className={clsx([
17
18
  'ds_tabs__content',
18
19
  !isBorderless && 'ds_tabs__content--bordered',
19
20
  className
20
- ].join(' ')}
21
+ ])}
22
+ data-label={tabLabel}
21
23
  id={id}
22
24
  {...props}
23
25
  >
@@ -29,7 +31,7 @@ const TabItem = ({
29
31
  const TabListItem = ({
30
32
  children,
31
33
  href
32
- }: SGDS.Component.Tabs.TabListItem) => {
34
+ }: TabListItemProps) => {
33
35
  return (
34
36
  <li className="ds_tabs__tab">
35
37
  <a className="ds_tabs__tab-link" href={href}>{children}</a>
@@ -46,19 +48,20 @@ const Tabs = ({
46
48
  isManual = false,
47
49
  title = 'Contents',
48
50
  ...props
49
- }: SGDS.Component.Tabs) => {
51
+ }: TabsProps) => {
50
52
  const ref = useRef(null);
51
53
 
52
54
  const headingId = `${baseId}-heading`;
53
55
 
54
56
  useEffect(() => {
57
+ /* istanbul ignore else */
55
58
  if (ref.current) {
56
59
  new DSTabs(ref.current).init();
57
60
  }
58
61
  }, [ref]);
59
62
 
60
63
  const processedItems = Children.map(children, child => {
61
- const thisChild = child as React.ReactElement<SGDS.Component.Tabs.Item>;
64
+ const thisChild = child as React.ReactElement<TabsItemProps>;
62
65
 
63
66
  if (thisChild && thisChild.type === TabItem) {
64
67
  return React.cloneElement(thisChild, {
@@ -76,11 +79,11 @@ const Tabs = ({
76
79
 
77
80
  return (
78
81
  <div
79
- className={[
82
+ className={clsx([
80
83
  'ds_tabs',
81
84
  isManual && 'ds_tabs--manual',
82
85
  className
83
- ].join(' ')}
86
+ ])}
84
87
  ref={ref}
85
88
  {...props}
86
89
  >
@@ -0,0 +1,19 @@
1
+ import { HeadingLevel } from '../../shared-types';
2
+
3
+ export interface TabsItemProps extends React.AllHTMLAttributes<HTMLElement> {
4
+ isBorderless?: boolean;
5
+ id: string;
6
+ tabLabel: string;
7
+ }
8
+
9
+ export interface TabListItemProps extends React.AllHTMLAttributes<HTMLLIElement> {
10
+ href: string;
11
+ }
12
+
13
+ export interface TabsProps extends React.AllHTMLAttributes<HTMLElement> {
14
+ baseId: string;
15
+ isBorderless?: boolean;
16
+ headingLevel?: HeadingLevel;
17
+ isManual?: boolean;
18
+ title: string;
19
+ }
@@ -1,16 +1,19 @@
1
+ import { TagProps } from "./types";
2
+ import clsx from 'clsx';
3
+
1
4
  const Tag = ({
2
5
  children,
3
6
  className,
4
7
  colour,
5
8
  ...props
6
- }: SGDS.Component.Tag) => {
9
+ }: TagProps) => {
7
10
  return (
8
11
  <span
9
- className={[
12
+ className={clsx([
10
13
  'ds_tag',
11
14
  className,
12
- colour && `ds_tag--${colour}`,
13
- ].join(' ')}
15
+ colour && `ds_tag--${colour}`
16
+ ])}
14
17
  {...props}
15
18
  >
16
19
  {children}
@@ -0,0 +1,5 @@
1
+ import { TagColour } from '../../shared-types';
2
+
3
+ export interface TagProps extends React.AllHTMLAttributes<HTMLElement> {
4
+ colour?: TagColour;
5
+ }
@@ -16,11 +16,6 @@ const meta = {
16
16
  )
17
17
  ],
18
18
  argTypes: {
19
- headingId: {
20
- description: 'ID of the task list\'s heading element',
21
- type: 'string'
22
- },
23
- linkComponent: argTypes.linkComponent(),
24
19
  title: {
25
20
  description: 'The title of the task list',
26
21
  type: {
@@ -11,7 +11,6 @@ const meta = {
11
11
  description: 'ID of the task list\'s heading element',
12
12
  type: 'string'
13
13
  },
14
- linkComponent: argTypes.linkComponent(),
15
14
  title: {
16
15
  description: 'The title of the task list',
17
16
  type: {
@@ -3,6 +3,8 @@ import ConditionalWrapper from '../../common/ConditionalWrapper';
3
3
  import HintText from '../../common/HintText';
4
4
  import ScreenReaderText from '../../common/ScreenReaderText';
5
5
  import Tag from '../Tag';
6
+ import { TaskListGroupProps, TaskListItemProps, TaskListProps } from './types';
7
+ import clsx from 'clsx';
6
8
 
7
9
  const TaskItem = ({
8
10
  children,
@@ -15,7 +17,7 @@ const TaskItem = ({
15
17
  tagColour = 'grey',
16
18
  title,
17
19
  ...props
18
- }: SGDS.Component.TaskList.Item) => {
20
+ }: TaskListItemProps) => {
19
21
  if (isComplete) {
20
22
  tagColour = 'green';
21
23
  statusText = statusText || 'Completed'
@@ -24,19 +26,21 @@ const TaskItem = ({
24
26
  const LINK_CLASS = 'ds_task-list__task-link';
25
27
 
26
28
  function getLinkElement(children: React.ReactNode) {
29
+ let linkElement;
27
30
  if (linkComponent) {
28
- return linkComponent({ className: LINK_CLASS, href, children });
29
- } else if (href) {
30
- return <a href={href} className={LINK_CLASS}>{children}</a>;
31
+ linkElement = linkComponent({ className: LINK_CLASS, href, children });
32
+ } else {
33
+ linkElement = <a href={href} className={LINK_CLASS}>{children}</a>;
31
34
  }
35
+ return linkElement as React.JSX.Element;
32
36
  }
33
37
 
34
38
  return (
35
39
  <li
36
- className={[
40
+ className={clsx([
37
41
  'ds_task-list__task',
38
42
  className
39
- ].join(' ')}
43
+ ])}
40
44
  id={id}
41
45
  {...props}
42
46
  >
@@ -77,13 +81,13 @@ const TaskGroup = ({
77
81
  intro,
78
82
  title,
79
83
  ...props
80
- }: SGDS.Component.TaskList.Group) => {
84
+ }: TaskListGroupProps) => {
81
85
  return (
82
86
  <li
83
- className={[
87
+ className={clsx([
84
88
  'ds_task-list-group__section',
85
89
  className
86
- ].join(' ')}
90
+ ])}
87
91
  {...props}
88
92
  >
89
93
  <h2 className="ds_task-list-heading">{title}</h2>
@@ -101,12 +105,12 @@ const TaskList = ({
101
105
  headingId = 'task-list',
102
106
  title,
103
107
  ...props
104
- }: SGDS.Component.TaskList) => {
108
+ }: TaskListProps) => {
105
109
  let taskCount = 0;
106
- let incompleteTaskIds: string[] = [];
110
+ const incompleteTaskIds: string[] = [];
107
111
  let completedTasksCount = 0;
108
112
 
109
- function processChild(item: any) {
113
+ function processChild(item: React.JSX.Element) {
110
114
  if (item.type.displayName === 'TaskList.Item') {
111
115
  taskCount = taskCount + 1;
112
116
 
@@ -131,7 +135,7 @@ const TaskList = ({
131
135
  }
132
136
 
133
137
  Children.forEach(children, child => {
134
- processChild(child);
138
+ processChild(child as React.JSX.Element);
135
139
  });
136
140
 
137
141
  return (
@@ -0,0 +1,20 @@
1
+ import { LinkComponent, TagColour } from '../../shared-types';
2
+
3
+ export interface TaskListGroupProps extends React.AllHTMLAttributes<HTMLElement> {
4
+ intro?: string;
5
+ title: string;
6
+ }
7
+
8
+ export interface TaskListItemProps extends React.AllHTMLAttributes<HTMLElement> {
9
+ href?: string;
10
+ id?: string;
11
+ isComplete?: boolean;
12
+ linkComponent?: LinkComponent;
13
+ statusText?: string;
14
+ tagColour?: TagColour;
15
+ title: string;
16
+ }
17
+
18
+ export interface TaskListProps extends React.AllHTMLAttributes<HTMLElement> {
19
+ headingId?: string;
20
+ }
@@ -58,7 +58,6 @@ test('text input with character count', () => {
58
58
  const textInput = screen.getByRole('textbox');
59
59
  const textInputWrapper = textInput.parentElement;
60
60
 
61
- expect(textInputWrapper).toHaveAttribute('data-maxlength', MAX_LENGTH.toString());
62
61
  expect(textInputWrapper).toHaveAttribute('data-module', 'ds-character-count');
63
62
  });
64
63
 
@@ -232,6 +231,44 @@ test('text input with change function', () => {
232
231
  expect(ONCHANGE_FUNCTION).toHaveBeenCalled();
233
232
  });
234
233
 
234
+ test('text input with onBlur that is not a function', () => {
235
+ render(
236
+ <TextInput
237
+ id={INPUT_ID}
238
+ label={LABEL_TEXT}
239
+ // @ts-expect-error onBlur is not a function
240
+ onBlur='foo'
241
+ />
242
+ );
243
+
244
+ const textInput = screen.getByRole('textbox');
245
+
246
+ fireEvent.blur(textInput);
247
+
248
+ // todo: assertion
249
+ // success indicated by no errors thrown
250
+ // error would be thrown on an untestable thread
251
+ });
252
+
253
+ test('text input with onChange that is not a function', () => {
254
+ render(
255
+ <TextInput
256
+ id={INPUT_ID}
257
+ label={LABEL_TEXT}
258
+ // @ts-expect-error onChange is not a function
259
+ onChange='foo'
260
+ />
261
+ );
262
+
263
+ const textInput = screen.getByRole('textbox');
264
+
265
+ fireEvent.change(textInput, {target: {value: 'foo'}});
266
+
267
+ // todo: assertion
268
+ // success indicated by no errors thrown
269
+ // error would be thrown on an untestable thread
270
+ });
271
+
235
272
  test('text input with placeholder text', () => {
236
273
  const PLACEHOLDER_TEXT = 'foo';
237
274
 
@@ -299,6 +336,21 @@ test('text input with error message', () => {
299
336
  expect(errorMessageElement).toHaveClass('ds_question__error-message');
300
337
  });
301
338
 
339
+ test('instantiating/initialising DS component script', () => {
340
+ render(
341
+ <TextInput
342
+ id={INPUT_ID}
343
+ label={LABEL_TEXT}
344
+ maxlength={200}
345
+ />
346
+ );
347
+
348
+ const textInput = screen.getByRole('textbox');
349
+ const textInputContainer = textInput.parentElement;
350
+ expect(textInputContainer).toHaveClass('js-initialised');
351
+ expect(textInputContainer).toHaveClass('js-instantiated');
352
+ });
353
+
302
354
  test('passing additional props', () => {
303
355
  render(
304
356
  <TextInput
@@ -1,15 +1,15 @@
1
1
  import { useEffect, useRef } from 'react';
2
- // @ts-ignore
3
- import DSCharacterCount from '@scottish-government/design-system/src/forms/character-count/character-count';
2
+ import DSCharacterCount from '@scottish-government/design-system/src/components/character-count/character-count';
4
3
  import Button from '../Button';
5
4
  import ConditionalWrapper from '../../common/ConditionalWrapper';
6
5
  import ErrorMessage from '../ErrorMessage';
7
6
  import HintText from '../../common/HintText';
7
+ import { TextInputProps } from './types';
8
+ import clsx from 'clsx';
8
9
 
9
10
  const TextInput = ({
10
11
  buttonIcon,
11
12
  buttonText,
12
- children,
13
13
  className,
14
14
  countThreshold,
15
15
  width,
@@ -29,29 +29,34 @@ const TextInput = ({
29
29
  type = 'text',
30
30
  value,
31
31
  ...props
32
- }: SGDS.Component.TextInput) => {
32
+ }: TextInputProps) => {
33
33
  const errorMessageId = `error-message-${id}`;
34
34
  const hintTextId = `hint-text-${id}`;
35
35
  const ref = useRef(null);
36
- const inputWrapperClasses = `${hasButton ? 'ds_input__wrapper ds_input__wrapper--has-icon' : ''} ${isCurrency ? 'ds_currency-wrapper' : ''}`;
36
+ const inputWrapperClasses = clsx(
37
+ hasButton && 'ds_input__wrapper',
38
+ hasButton && 'ds_input__wrapper--has-icon',
39
+ isCurrency && 'ds_currency-wrapper'
40
+ );
37
41
  const describedbys: string[] = [];
38
42
 
39
43
  if (hintText) { describedbys.push(hintTextId) };
40
44
  if (errorMessage) { describedbys.push(errorMessageId) };
41
45
 
42
46
  useEffect(() => {
47
+ /* istanbul ignore else */
43
48
  if (ref.current) {
44
49
  new DSCharacterCount(ref.current).init();
45
50
  }
46
51
  }, [ref]);
47
52
 
48
- function handleBlur(event: React.FocusEvent) {
53
+ function handleBlur(event: React.FocusEvent<HTMLInputElement>) {
49
54
  if (typeof onBlur === 'function') {
50
55
  onBlur(event);
51
56
  }
52
57
  }
53
58
 
54
- function handleChange(event: React.ChangeEvent) {
59
+ function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
55
60
  if (typeof onChange === 'function') {
56
61
  onChange(event);
57
62
  }
@@ -63,7 +68,7 @@ const TextInput = ({
63
68
  wrapper={(children: React.JSX.Element) => <div ref={ref} data-threshold={countThreshold} data-module="ds-character-count">{children}</div>}
64
69
  >
65
70
  <label className="ds_label" htmlFor={id}>{label}</label>
66
- {hintText && <HintText id={hintTextId} text={hintText} />}
71
+ {hintText && <HintText id={hintTextId}>{hintText}</HintText>}
67
72
  {errorMessage && <ErrorMessage id={errorMessageId}>{errorMessage}</ErrorMessage>}
68
73
  <ConditionalWrapper
69
74
  condition={hasButton || typeof isCurrency !== 'undefined' && isCurrency}
@@ -72,12 +77,12 @@ const TextInput = ({
72
77
  <input
73
78
  aria-describedby={describedbys.join(' ')}
74
79
  aria-invalid={hasError}
75
- className={[
80
+ className={clsx([
76
81
  'ds_input',
77
82
  className,
78
- hasError ? 'ds_input--error' : '',
79
- width ? `ds_input--${width}` : '',
80
- ].join(' ')}
83
+ hasError && 'ds_input--error',
84
+ width && `ds_input--${width}`,
85
+ ])}
81
86
  defaultValue={value}
82
87
  id={id}
83
88
  maxLength={maxlength}
@@ -0,0 +1,12 @@
1
+ import { IconName, InputWidth, TextInputBase } from '../../shared-types';
2
+
3
+ export interface TextInputProps extends TextInputBase<HTMLInputElement> {
4
+ buttonIcon?: IconName;
5
+ buttonText?: string;
6
+ className?: string;
7
+ currencySymbol?: string;
8
+ hasButton?: boolean;
9
+ isCurrency?: boolean;
10
+ type?: string;
11
+ width?: InputWidth;
12
+ }