@infonomic/uikit 2.0.0 → 2.1.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 (312) hide show
  1. package/dist/components/card/card.d.ts.map +1 -1
  2. package/package.json +9 -5
  3. package/src/astro.d.ts +43 -0
  4. package/src/astro.js +2 -2
  5. package/src/components/@types/shared.ts +24 -0
  6. package/src/components/accordion/accordion.module.css +60 -0
  7. package/src/components/accordion/accordion.stories.tsx +117 -0
  8. package/src/components/accordion/accordion.tsx +105 -0
  9. package/src/components/animation/fade-in-lift.stories.tsx +81 -0
  10. package/src/components/animation/fade-in-lift.tsx +42 -0
  11. package/src/components/avatar/avatar.module.css +54 -0
  12. package/src/components/avatar/avatar.stories.tsx +28 -0
  13. package/src/components/avatar/avatar.tsx +19 -0
  14. package/src/components/button/@types/button.ts +17 -0
  15. package/src/components/button/button-group.module.css +17 -0
  16. package/src/components/button/button-group.stories.tsx +45 -0
  17. package/src/components/button/button-group.tsx +132 -0
  18. package/src/components/button/button-icon.stories.tsx +145 -0
  19. package/src/components/button/button-intents.stories.tsx +50 -0
  20. package/src/components/button/button-variants.stories.tsx +60 -0
  21. package/src/components/button/button.astro +86 -0
  22. package/src/components/button/button.module.css +533 -0
  23. package/src/components/button/button.tsx +81 -0
  24. package/src/components/button/control-buttons.module.css +144 -0
  25. package/src/components/button/control-buttons.stories.tsx +60 -0
  26. package/src/components/button/control-buttons.tsx +137 -0
  27. package/src/components/button/copy-button.module.css +31 -0
  28. package/src/components/button/copy-button.stories.tsx +50 -0
  29. package/src/components/button/copy-button.tsx +92 -0
  30. package/src/components/button/icon-button.astro +47 -0
  31. package/src/components/button/icon-button.tsx +44 -0
  32. package/src/components/button/index.ts +5 -0
  33. package/src/components/calendar/calendar.module.css +315 -0
  34. package/src/components/calendar/calendar.stories.tsx +139 -0
  35. package/src/components/calendar/calendar.tsx +173 -0
  36. package/src/components/card/card-content.astro +14 -0
  37. package/src/components/card/card-description.astro +14 -0
  38. package/src/components/card/card-footer.astro +14 -0
  39. package/src/components/card/card-header.astro +14 -0
  40. package/src/components/card/card-title.astro +14 -0
  41. package/src/components/card/card.astro +41 -0
  42. package/src/components/card/card.module.css +67 -0
  43. package/src/components/card/card.stories.tsx +61 -0
  44. package/src/components/card/card.tsx +86 -0
  45. package/src/components/container/container.astro +13 -0
  46. package/src/components/container/container.module.css +28 -0
  47. package/src/components/container/container.stories.tsx +42 -0
  48. package/src/components/container/container.tsx +23 -0
  49. package/src/components/dropdown/dropdown.module.css +131 -0
  50. package/src/components/dropdown/dropdown.stories.tsx +103 -0
  51. package/src/components/dropdown/dropdown.tsx +193 -0
  52. package/src/components/hamburger/hamburger.astro +30 -0
  53. package/src/components/hamburger/hamburger.tsx +66 -0
  54. package/src/components/input/@types/checkbox.ts +20 -0
  55. package/src/components/input/@types/input.ts +20 -0
  56. package/src/components/input/checkbox-group.tsx +78 -0
  57. package/src/components/input/checkbox.module.css +267 -0
  58. package/src/components/input/checkbox.stories.tsx +240 -0
  59. package/src/components/input/checkbox.tsx +95 -0
  60. package/src/components/input/error-text.astro +14 -0
  61. package/src/components/input/error-text.module.css +19 -0
  62. package/src/components/input/error-text.tsx +18 -0
  63. package/src/components/input/errors.tsx +37 -0
  64. package/src/components/input/help-text.astro +13 -0
  65. package/src/components/input/help-text.module.css +19 -0
  66. package/src/components/input/help-text.tsx +13 -0
  67. package/src/components/input/index.tsx +8 -0
  68. package/src/components/input/input-adornment.astro +26 -0
  69. package/src/components/input/input-adornment.module.css +18 -0
  70. package/src/components/input/input-adornment.tsx +36 -0
  71. package/src/components/input/input.astro +99 -0
  72. package/src/components/input/input.module.css +310 -0
  73. package/src/components/input/input.stories.tsx +174 -0
  74. package/src/components/input/input.tsx +103 -0
  75. package/src/components/input/label.astro +24 -0
  76. package/src/components/input/label.module.css +28 -0
  77. package/src/components/input/label.tsx +25 -0
  78. package/src/components/input/radio-group.module.css +219 -0
  79. package/src/components/input/radio-group.stories.tsx +73 -0
  80. package/src/components/input/radio-group.tsx +67 -0
  81. package/src/components/input/select.module.css +75 -0
  82. package/src/components/input/select.stories.tsx +34 -0
  83. package/src/components/input/select.tsx +115 -0
  84. package/src/components/input/text-area.module.css +9 -0
  85. package/src/components/input/text-area.stories.tsx +51 -0
  86. package/src/components/input/text-area.tsx +81 -0
  87. package/src/components/input/utils.ts +21 -0
  88. package/src/components/notifications/@types/alert.ts +12 -0
  89. package/src/components/notifications/@types/toast.ts +12 -0
  90. package/src/components/notifications/alert.module.css +114 -0
  91. package/src/components/notifications/alert.stories.tsx +39 -0
  92. package/src/components/notifications/alert.tsx +117 -0
  93. package/src/components/notifications/index.ts +2 -0
  94. package/src/components/notifications/toast.module.css +237 -0
  95. package/src/components/notifications/toast.stories.tsx +42 -0
  96. package/src/components/notifications/toast.tsx +124 -0
  97. package/src/components/overlay/index.stories.tsx +29 -0
  98. package/src/components/overlay/index.ts +2 -0
  99. package/src/components/overlay/overlay.module.css +41 -0
  100. package/src/components/overlay/overlay.tsx +61 -0
  101. package/src/components/pager/@types/index.ts +2 -0
  102. package/src/components/pager/ellipses.tsx +18 -0
  103. package/src/components/pager/event-pager.tsx +18 -0
  104. package/src/components/pager/first-button.tsx +53 -0
  105. package/src/components/pager/hooks/types/usePagination.ts +80 -0
  106. package/src/components/pager/hooks/usePagination.ts +140 -0
  107. package/src/components/pager/icons/first.tsx +33 -0
  108. package/src/components/pager/icons/index.tsx +4 -0
  109. package/src/components/pager/icons/last.tsx +33 -0
  110. package/src/components/pager/icons/next.tsx +20 -0
  111. package/src/components/pager/icons/previous.tsx +20 -0
  112. package/src/components/pager/index.ts +4 -0
  113. package/src/components/pager/last-button.tsx +57 -0
  114. package/src/components/pager/next-button.tsx +55 -0
  115. package/src/components/pager/number-button.tsx +83 -0
  116. package/src/components/pager/pagination.module.css +165 -0
  117. package/src/components/pager/pagination.stories.tsx +190 -0
  118. package/src/components/pager/pagination.tsx +266 -0
  119. package/src/components/pager/previous-button.tsx +51 -0
  120. package/src/components/scroll-area/scroll-area.module.css +80 -0
  121. package/src/components/scroll-area/scroll-area.stories.tsx +33 -0
  122. package/src/components/scroll-area/scroll-area.tsx +22 -0
  123. package/src/components/scroll-to-top/scroll-to-top.tsx +59 -0
  124. package/src/components/section/section.astro +13 -0
  125. package/src/components/section/section.module.css +7 -0
  126. package/src/components/section/section.tsx +23 -0
  127. package/src/components/shimmer/shimmer.module.css +53 -0
  128. package/src/components/shimmer/shimmer.stories.tsx +24 -0
  129. package/src/components/shimmer/shimmer.tsx +70 -0
  130. package/src/components/table/table.module.css +100 -0
  131. package/src/components/table/table.stories.tsx +95 -0
  132. package/src/components/table/table.tsx +165 -0
  133. package/src/components/tabs/tabs.module.css +64 -0
  134. package/src/components/tabs/tabs.stories.tsx +47 -0
  135. package/src/components/tabs/tabs.tsx +75 -0
  136. package/src/components/timeline/timeline.module.css +87 -0
  137. package/src/components/timeline/timeline.stories.tsx +50 -0
  138. package/src/components/timeline/timeline.tsx +177 -0
  139. package/src/components/tooltip/tooltip.module.css +55 -0
  140. package/src/components/tooltip/tooltip.stories.tsx +59 -0
  141. package/src/components/tooltip/tooltip.tsx +51 -0
  142. package/src/declarations.d.ts +4 -0
  143. package/src/hooks/use-media-query.ts +20 -0
  144. package/src/icons/activity-icon.tsx +40 -0
  145. package/src/icons/calendar-icon.tsx +39 -0
  146. package/src/icons/check-icon.tsx +33 -0
  147. package/src/icons/chevron-down-icon.tsx +39 -0
  148. package/src/icons/chevron-left-double-icon.tsx +58 -0
  149. package/src/icons/chevron-left-icon.tsx +58 -0
  150. package/src/icons/chevron-right-double-icon.tsx +58 -0
  151. package/src/icons/chevron-right-icon.tsx +58 -0
  152. package/src/icons/chevrons-up-down.tsx +37 -0
  153. package/src/icons/close-icon.astro +38 -0
  154. package/src/icons/close-icon.tsx +30 -0
  155. package/src/icons/copy-icon.tsx +35 -0
  156. package/src/icons/danger-icon.tsx +18 -0
  157. package/src/icons/dashboard-icon.tsx +41 -0
  158. package/src/icons/delete-icon.tsx +34 -0
  159. package/src/icons/document-icon.tsx +38 -0
  160. package/src/icons/download-icon.tsx +39 -0
  161. package/src/icons/edit-icon.tsx +35 -0
  162. package/src/icons/ellipsis-icon.tsx +38 -0
  163. package/src/icons/email-icon.tsx +33 -0
  164. package/src/icons/external-link-icon.tsx +39 -0
  165. package/src/icons/github-icon.tsx +27 -0
  166. package/src/icons/globe-icon.tsx +50 -0
  167. package/src/icons/google-icon.tsx +44 -0
  168. package/src/icons/gripper-vertical-icon.tsx +43 -0
  169. package/src/icons/history-icon.tsx +32 -0
  170. package/src/icons/home-icon.tsx +34 -0
  171. package/src/icons/icon-element.astro +27 -0
  172. package/src/icons/icon-element.tsx +32 -0
  173. package/src/icons/icon-sprite.tsx +18 -0
  174. package/src/icons/icons.module.css +147 -0
  175. package/src/icons/index.stories.tsx +25 -0
  176. package/src/icons/index.ts +39 -0
  177. package/src/icons/info-icon.tsx +18 -0
  178. package/src/icons/infonomic-icon.tsx +173 -0
  179. package/src/icons/light-icon.astro +36 -0
  180. package/src/icons/light-icon.tsx +29 -0
  181. package/src/icons/location-pin-icon.tsx +36 -0
  182. package/src/icons/moon-icon.astro +38 -0
  183. package/src/icons/moon-icon.tsx +42 -0
  184. package/src/icons/plus-icon.tsx +34 -0
  185. package/src/icons/primary-icon.tsx +22 -0
  186. package/src/icons/refresh-icon.tsx +33 -0
  187. package/src/icons/return-icon.tsx +36 -0
  188. package/src/icons/roles-icon.tsx +34 -0
  189. package/src/icons/search-icon.astro +40 -0
  190. package/src/icons/search-icon.tsx +29 -0
  191. package/src/icons/search-menu-icon.tsx +42 -0
  192. package/src/icons/settings-gear-icon.tsx +36 -0
  193. package/src/icons/settings-sliders-icon.tsx +43 -0
  194. package/src/icons/sign-out-icon.tsx +35 -0
  195. package/src/icons/source/icon-calendar.svg +1 -0
  196. package/src/icons/source/icon-check.svg +4 -0
  197. package/src/icons/source/icon-close.svg +3 -0
  198. package/src/icons/source/icon-coinbase.svg +9 -0
  199. package/src/icons/source/icon-copy.svg +4 -0
  200. package/src/icons/source/icon-document.svg +5 -0
  201. package/src/icons/source/icon-download.svg +4 -0
  202. package/src/icons/source/icon-edit.svg +6 -0
  203. package/src/icons/source/icon-eth-purple.svg +15 -0
  204. package/src/icons/source/icon-etherscan.svg +5 -0
  205. package/src/icons/source/icon-external-link.svg +4 -0
  206. package/src/icons/source/icon-globe.svg +7 -0
  207. package/src/icons/source/icon-gripper-vertical.svg +9 -0
  208. package/src/icons/source/icon-info.svg +4 -0
  209. package/src/icons/source/icon-infonomic.svg +43 -0
  210. package/src/icons/source/icon-ledger.svg +4 -0
  211. package/src/icons/source/icon-light.svg +3 -0
  212. package/src/icons/source/icon-location-pin.svg +8 -0
  213. package/src/icons/source/icon-logout.svg +6 -0
  214. package/src/icons/source/icon-metamask.svg +32 -0
  215. package/src/icons/source/icon-moon.svg +3 -0
  216. package/src/icons/source/icon-plus.svg +4 -0
  217. package/src/icons/source/icon-refresh.svg +4 -0
  218. package/src/icons/source/icon-return.svg +4 -0
  219. package/src/icons/source/icon-search-menu.svg +13 -0
  220. package/src/icons/source/icon-search.svg +3 -0
  221. package/src/icons/source/icon-settings-gear.svg +5 -0
  222. package/src/icons/source/icon-settings.svg +12 -0
  223. package/src/icons/source/icon-wallet.svg +3 -0
  224. package/src/icons/source/icon-walletconnect.svg +4 -0
  225. package/src/icons/source/icon-x.svg +4 -0
  226. package/src/icons/stopwatch-icon.tsx +39 -0
  227. package/src/icons/success-icon.tsx +18 -0
  228. package/src/icons/types/icon.ts +8 -0
  229. package/src/icons/user-icon.tsx +33 -0
  230. package/src/icons/users-icon.tsx +35 -0
  231. package/src/icons/wallet-icon.tsx +29 -0
  232. package/src/icons/warning-icon.tsx +18 -0
  233. package/src/icons/x-icon.tsx +33 -0
  234. package/src/loaders/ellipses.tsx +36 -0
  235. package/src/loaders/loaders.stories.tsx +46 -0
  236. package/src/loaders/ring.tsx +33 -0
  237. package/src/loaders/spinner.tsx +28 -0
  238. package/src/loaders/types/index.ts +6 -0
  239. package/src/react.ts +99 -0
  240. package/src/styles/base/animations.css +143 -0
  241. package/src/styles/base/base.css +5 -0
  242. package/src/styles/base/colors.css +163 -0
  243. package/src/styles/base/colors.stories.tsx +671 -0
  244. package/src/styles/base/reset.css +464 -0
  245. package/src/styles/base/typography.css +25 -0
  246. package/src/styles/base/vars.css +188 -0
  247. package/src/styles/components/card.css +20 -0
  248. package/src/styles/components/checkbox.css +55 -0
  249. package/src/styles/components/components.css +11 -0
  250. package/src/styles/components/directional-button.css +92 -0
  251. package/src/styles/components/dropdown.css +19 -0
  252. package/src/styles/components/fade-in-lift.css +13 -0
  253. package/src/styles/components/hamburger.css +107 -0
  254. package/src/styles/components/icon-element.css +4 -0
  255. package/src/styles/components/list-checkbox.css +60 -0
  256. package/src/styles/components/loaders.css +196 -0
  257. package/src/styles/components/popover.css +15 -0
  258. package/src/styles/components/scroll-to-top.css +89 -0
  259. package/src/styles/components/toast.css +18 -0
  260. package/src/styles/styles.css +6 -0
  261. package/src/styles/theme/autofill.css +58 -0
  262. package/src/styles/theme/scrollers.css +52 -0
  263. package/src/styles/theme/theme.css +130 -0
  264. package/src/styles/theme/theme.stories.tsx +33 -0
  265. package/src/styles/typography/code.stories.tsx +76 -0
  266. package/src/styles/typography/default.stories.tsx +51 -0
  267. package/src/styles/typography/fonts.css +30 -0
  268. package/src/styles/typography/lists.stories.tsx +50 -0
  269. package/src/styles/typography/prose.css +404 -0
  270. package/src/styles/typography/quote.stories.tsx +37 -0
  271. package/src/styles/typography.css +24 -0
  272. package/src/styles/utils/scroll-layout-shift.css +9 -0
  273. package/src/styles/utils/utility-classes.css +1278 -0
  274. package/src/styles/utils/utils.css +2 -0
  275. package/src/theme/theme-provider/index.ts +1 -0
  276. package/src/theme/theme-provider/provider.tsx +44 -0
  277. package/src/utils/capitalize.ts +6 -0
  278. package/src/utils/externalLinkProps.ts +6 -0
  279. package/src/utils/findMatch.ts +7 -0
  280. package/src/utils/getPortalRoot.ts +3 -0
  281. package/src/utils/isTouchDevice.ts +11 -0
  282. package/src/utils/objectsToArray.ts +15 -0
  283. package/src/utils/objectsToString.ts +5 -0
  284. package/src/utils/polymorphic.ts +16 -0
  285. package/src/utils/to-kebab-case.ts +5 -0
  286. package/src/widgets/datepicker/datepicker.module.css +189 -0
  287. package/src/widgets/datepicker/datepicker.stories.tsx +25 -0
  288. package/src/widgets/datepicker/datepicker.tsx +310 -0
  289. package/src/widgets/drawer/drawer-container.tsx +26 -0
  290. package/src/widgets/drawer/drawer-content.tsx +26 -0
  291. package/src/widgets/drawer/drawer-context.tsx +49 -0
  292. package/src/widgets/drawer/drawer-header.tsx +27 -0
  293. package/src/widgets/drawer/drawer-top-actions.tsx +27 -0
  294. package/src/widgets/drawer/drawer-wrapper.tsx +54 -0
  295. package/src/widgets/drawer/drawer.module.css +116 -0
  296. package/src/widgets/drawer/drawer.stories.tsx +224 -0
  297. package/src/widgets/drawer/drawer.tsx +115 -0
  298. package/src/widgets/drawer/motionDomAnimation.ts +4 -0
  299. package/src/widgets/drawer/motionDomMax.ts +4 -0
  300. package/src/widgets/modal/modal-actions.tsx +26 -0
  301. package/src/widgets/modal/modal-container.tsx +26 -0
  302. package/src/widgets/modal/modal-content.tsx +26 -0
  303. package/src/widgets/modal/modal-header.tsx +27 -0
  304. package/src/widgets/modal/modal-wrapper.tsx +50 -0
  305. package/src/widgets/modal/modal.module.css +85 -0
  306. package/src/widgets/modal/modal.stories.tsx +71 -0
  307. package/src/widgets/modal/modal.tsx +110 -0
  308. package/src/widgets/modal/motionDomAnimation.ts +4 -0
  309. package/src/widgets/modal/motionDomMax.ts +4 -0
  310. package/src/widgets/search/index.ts +1 -0
  311. package/src/widgets/search/search.stories.tsx +18 -0
  312. package/src/widgets/search/search.tsx +186 -0
@@ -0,0 +1,26 @@
1
+ 'use client'
2
+ import type * as React from 'react'
3
+
4
+ import cx from 'classnames'
5
+
6
+ import styles from './modal.module.css'
7
+
8
+ type ModalContentIntrinsicProps = React.JSX.IntrinsicElements['div']
9
+ export interface ModalContentProps extends ModalContentIntrinsicProps {
10
+ className?: string
11
+ }
12
+
13
+ export const ModalContent = function ModalContent({
14
+ ref,
15
+ children,
16
+ className,
17
+ ...rest
18
+ }: ModalContentProps & {
19
+ ref?: React.RefObject<HTMLDivElement>
20
+ }) {
21
+ return (
22
+ <div ref={ref} {...rest} className={cx(styles['modal-content'], className)}>
23
+ {children}
24
+ </div>
25
+ )
26
+ }
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ import type * as React from 'react'
3
+
4
+ import cx from 'classnames'
5
+
6
+ import styles from './modal.module.css'
7
+
8
+ type ModalHeaderIntrinsicProps = React.JSX.IntrinsicElements['div']
9
+ export interface ModalHeaderProps extends ModalHeaderIntrinsicProps {
10
+ className?: string
11
+ }
12
+
13
+ export const ModalHeader = function ModalHeader({
14
+ ref,
15
+ children,
16
+ className,
17
+ ...rest
18
+ }: ModalHeaderProps & {
19
+ ref?: React.RefObject<HTMLDivElement>
20
+ }) {
21
+ const classes = cx(styles['modal-header'], 'prose', className)
22
+ return (
23
+ <div style={{ overflowWrap: 'anywhere' }} ref={ref} {...rest} className={classes}>
24
+ {children}
25
+ </div>
26
+ )
27
+ }
@@ -0,0 +1,50 @@
1
+ 'use client'
2
+ /* eslint-disable @typescript-eslint/consistent-type-imports */
3
+ import type React from 'react'
4
+ import { useEffect } from 'react'
5
+
6
+ import { useFocusTrap } from '@mantine/hooks'
7
+ import { m } from 'motion/react'
8
+
9
+ import type { HTMLMotionProps } from 'motion/react'
10
+
11
+ import styles from './modal.module.css'
12
+
13
+ export interface ModalWrapperProps extends HTMLMotionProps<'div'> {
14
+ children: React.ReactNode
15
+ onEscapeKey?: (e: any) => void
16
+ }
17
+
18
+ export function ModalWrapper({
19
+ children,
20
+ onEscapeKey,
21
+ ...rest
22
+ }: ModalWrapperProps): React.JSX.Element {
23
+ const focusTrapRef = useFocusTrap()
24
+
25
+ useEffect(() => {
26
+ const handleKeyDown = (event: KeyboardEvent) => {
27
+ if (event.key === 'Escape' && onEscapeKey) {
28
+ onEscapeKey(event)
29
+ }
30
+ }
31
+
32
+ document.addEventListener('keydown', handleKeyDown)
33
+ return () => {
34
+ document.removeEventListener('keydown', handleKeyDown)
35
+ }
36
+ }, [onEscapeKey])
37
+
38
+ return (
39
+ <m.div
40
+ ref={focusTrapRef}
41
+ {...rest}
42
+ className={styles['modal-wrapper']}
43
+ initial={{ opacity: 0 }}
44
+ animate={{ opacity: 1 }}
45
+ exit={{ opacity: 0 }}
46
+ >
47
+ {children}
48
+ </m.div>
49
+ )
50
+ }
@@ -0,0 +1,85 @@
1
+ @layer infonomic-base, infonomic-utilities, infonomic-theme, infonomic-components;
2
+
3
+ @layer infonomic-components {
4
+ .modal-wrapper {
5
+ position: fixed;
6
+ display: flex;
7
+ flex-direction: column;
8
+ justify-content: center;
9
+ align-items: center;
10
+ top: 0;
11
+ left: 0;
12
+ right: 0;
13
+ bottom: 0;
14
+ z-index: 30;
15
+ opacity: 1;
16
+ }
17
+
18
+ .modal-container {
19
+ position: absolute;
20
+ display: flex;
21
+ flex-direction: column;
22
+ box-shadow: var(--shadow-md);
23
+ border-radius: var(--border-radius-md);
24
+ z-index: 20;
25
+ min-height: 300px;
26
+ max-height: 88vh;
27
+ width: 100%;
28
+ bottom: 0;
29
+ background-color: var(--canvas-25);
30
+ border: 1px solid var(--border-color);
31
+ margin-left: var(--spacing-2);
32
+ margin-right: var(--spacing-2);
33
+ }
34
+
35
+ .modal-container:is(:global(.dark) *) {
36
+ background: var(--canvas-800);
37
+ }
38
+
39
+ @media screen and (min-width: 640px) {
40
+ .modal-container {
41
+ max-height: calc(100vh - 24px);
42
+ min-height: auto;
43
+ bottom: auto;
44
+ width: auto;
45
+ }
46
+ }
47
+
48
+ .modal-header {
49
+ display: flex;
50
+ align-items: center;
51
+ justify-content: space-between;
52
+ gap: var(--gap-3);
53
+ padding-left: var(--spacing-6);
54
+ padding-right: var(--spacing-6);
55
+ padding-top: var(--spacing-5);
56
+ max-width: 100%;
57
+ }
58
+
59
+ .modal-header h2,
60
+ .modal-header h3 {
61
+ margin: 0;
62
+ }
63
+
64
+ .modal-content {
65
+ display: flex;
66
+ flex: 1;
67
+ flex-direction: column;
68
+ gap: var(--gap-3);
69
+ padding-left: var(--spacing-6);
70
+ padding-right: var(--spacing-6);
71
+ padding-bottom: var(--spacing-3);
72
+ max-width: 100%;
73
+ }
74
+
75
+ .modal-actions {
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: flex-end;
79
+ gap: var(--gap-3);
80
+ padding-top: var(--spacing-2);
81
+ padding-bottom: var(--spacing-5);
82
+ padding-left: var(--spacing-6);
83
+ padding-right: var(--spacing-6);
84
+ }
85
+ }
@@ -0,0 +1,71 @@
1
+ // biome-ignore lint/style/useImportType: <explanation>
2
+ import React from 'react'
3
+
4
+ import { Button } from '../../components/button/button.js'
5
+ import { IconButton } from '../../components/button/icon-button.js'
6
+ import { CloseIcon } from '../../icons/close-icon.js'
7
+
8
+ import { Modal, useModal } from './modal.js'
9
+
10
+ export default {
11
+ title: 'Widgets/Modal',
12
+ component: Modal,
13
+ argTypes: {},
14
+ }
15
+
16
+ export const Default = (): React.JSX.Element => {
17
+ const { onDismiss, onOpen, isOpen, setIsOpen } = useModal()
18
+
19
+ const whiteIcon = `
20
+ .white-icon {
21
+ fill: white;
22
+ }
23
+ `
24
+
25
+ return (
26
+ <>
27
+ <style>{whiteIcon}</style>
28
+ <Button
29
+ onClick={() => {
30
+ setIsOpen(true)
31
+ }}
32
+ >
33
+ Open Modal
34
+ </Button>
35
+ <Modal isOpen={isOpen} onDismiss={onDismiss} closeOnOverlayClick={true}>
36
+ <Modal.Container style={{ maxWidth: '600px' }}>
37
+ <Modal.Header>
38
+ <h2>Modal Header</h2>
39
+ <IconButton
40
+ arial-label="Close"
41
+ size="sm"
42
+ onClick={() => {
43
+ setIsOpen(false)
44
+ }}
45
+ >
46
+ <CloseIcon width="16px" height="16px" svgClassName="white-icon" />
47
+ </IconButton>
48
+ </Modal.Header>
49
+ <Modal.Content>
50
+ <p style={{ paddingTop: '1rem' }}>
51
+ Modal content with some text here that should run a little longer. And longer here.
52
+ And the current theme is.
53
+ </p>
54
+ </Modal.Content>
55
+ <Modal.Actions>
56
+ <Button
57
+ size="sm"
58
+ intent="noeffect"
59
+ onClick={() => {
60
+ setIsOpen(false)
61
+ }}
62
+ data-autofocus
63
+ >
64
+ Close
65
+ </Button>
66
+ </Modal.Actions>
67
+ </Modal.Container>
68
+ </Modal>
69
+ </>
70
+ )
71
+ }
@@ -0,0 +1,110 @@
1
+ 'use client'
2
+ /* eslint-disable @typescript-eslint/consistent-type-imports */
3
+ import type React from 'react'
4
+ import { createContext, useCallback, useState } from 'react'
5
+ import { createPortal } from 'react-dom'
6
+
7
+ import { AnimatePresence, type FeatureBundle, LazyMotion } from 'motion/react'
8
+
9
+ import { Overlay } from '../../components/overlay'
10
+ import { useMediaQuery } from '../../hooks/use-media-query'
11
+ import { getPortalRoot } from '../../utils/getPortalRoot'
12
+
13
+ import { ModalActions } from './modal-actions'
14
+ import { ModalContainer } from './modal-container'
15
+ import { ModalContent } from './modal-content'
16
+ import { ModalHeader } from './modal-header'
17
+ import { ModalWrapper } from './modal-wrapper'
18
+
19
+ const DomMax: () => Promise<FeatureBundle> = async () =>
20
+ await import('./motionDomMax').then((mod) => mod.default)
21
+ const DomAnimation: () => Promise<FeatureBundle> = async () =>
22
+ await import('./motionDomAnimation').then((mod) => mod.default)
23
+
24
+ export interface ModalProps {
25
+ isOpen?: boolean
26
+ onDismiss?: () => void
27
+ closeOnOverlayClick?: boolean
28
+ children?: React.ReactNode
29
+ }
30
+
31
+ export const ModalContext = createContext<{
32
+ onDismiss?: () => void
33
+ }>({})
34
+
35
+ export type UseModalProps = ReturnType<typeof useModal>
36
+
37
+ export function useModal(): {
38
+ onDismiss: () => void
39
+ onOpen: () => void
40
+ isOpen: boolean
41
+ setIsOpen: React.Dispatch<React.SetStateAction<boolean>>
42
+ } {
43
+ const [isOpen, setIsOpen] = useState(false)
44
+
45
+ const onDismiss = useCallback(() => {
46
+ setIsOpen(false)
47
+ }, [])
48
+
49
+ const onOpen = useCallback(() => {
50
+ setIsOpen(true)
51
+ }, [])
52
+
53
+ return {
54
+ onDismiss,
55
+ onOpen,
56
+ isOpen,
57
+ setIsOpen,
58
+ }
59
+ }
60
+
61
+ function Modal({
62
+ isOpen,
63
+ onDismiss,
64
+ closeOnOverlayClick,
65
+ children,
66
+ ...rest
67
+ }: ModalProps): React.ReactPortal | null {
68
+ const isMobile = useMediaQuery('(max-width: 768px)') ?? false
69
+
70
+ const handleOverlayDismiss = (e: any): void => {
71
+ e.stopPropagation()
72
+ e.preventDefault()
73
+ if (closeOnOverlayClick === true) {
74
+ onDismiss?.()
75
+ }
76
+ }
77
+
78
+ const portal = getPortalRoot()
79
+
80
+ if (portal === false) return null
81
+
82
+ return createPortal(
83
+ <ModalContext.Provider value={{ onDismiss }}>
84
+ <LazyMotion features={isMobile ? DomMax : DomAnimation}>
85
+ <AnimatePresence>
86
+ {isOpen === true && (
87
+ <ModalWrapper
88
+ transition={{ duration: 0.2 }}
89
+ onEscapeKey={handleOverlayDismiss}
90
+ {...rest}
91
+ >
92
+ <Overlay onClick={handleOverlayDismiss} isUnmounting={!(isOpen ?? false)} />
93
+ {children}
94
+ </ModalWrapper>
95
+ )}
96
+ </AnimatePresence>
97
+ </LazyMotion>
98
+ </ModalContext.Provider>,
99
+ portal
100
+ )
101
+ }
102
+
103
+ Modal.displayName = 'Modal'
104
+
105
+ Modal.Container = ModalContainer
106
+ Modal.Header = ModalHeader
107
+ Modal.Content = ModalContent
108
+ Modal.Actions = ModalActions
109
+
110
+ export { Modal }
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ import { domAnimation } from 'motion/react'
3
+
4
+ export default domAnimation
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ import { domMax } from 'motion/react'
3
+
4
+ export default domMax
@@ -0,0 +1 @@
1
+ export * from './search.js'
@@ -0,0 +1,18 @@
1
+ // biome-ignore lint/style/useImportType: <explanation>
2
+ import React from 'react'
3
+
4
+ import { Search } from './search.js'
5
+
6
+ export default {
7
+ title: 'Widgets/Search',
8
+ component: Search,
9
+ argTypes: {},
10
+ }
11
+
12
+ export const Default = (): React.JSX.Element => {
13
+ return (
14
+ <div style={{ maxWidth: '600px', margin: '0 auto' }}>
15
+ <Search variant="underlined" />
16
+ </div>
17
+ )
18
+ }
@@ -0,0 +1,186 @@
1
+ 'use client'
2
+
3
+ import type React from 'react'
4
+ import { useEffect, useRef, useState } from 'react'
5
+
6
+ import { IconButton } from '../../components/button/index.js'
7
+ import { Input, InputAdornment } from '../../components/input'
8
+ import type { ClassName, Intent, Size, Variant } from '../../components/input/@types/input.js'
9
+ import { CloseIcon, SearchIcon } from '../../icons'
10
+
11
+ export interface SearchProps extends React.InputHTMLAttributes<HTMLInputElement> {
12
+ variant?: Variant
13
+ inputSize?: Size
14
+ inputClassName?: ClassName
15
+ intent?: Intent
16
+ className?: ClassName
17
+ ariaLabelForSearch?: string
18
+ ariaLabelForClear?: string
19
+ onClear?: () => void
20
+ onEnter?: (value: string) => void
21
+ onSearch?: (value: string) => void
22
+ validatorFn?: (value: string) => {
23
+ valid: boolean
24
+ value: any
25
+ }
26
+ placeHolderText?: string
27
+ }
28
+
29
+ function fallbackSearchHandler(value: string): void {
30
+ // Implement a fallback querystring search handler
31
+ // but.... this will cause a page reload so not ideal
32
+ // for React and therefore should rarely be called.
33
+ const url = new URL(window.location.href)
34
+ const params = new URLSearchParams(url.search)
35
+ if (value.length > 0) {
36
+ params.set('query', value)
37
+ } else {
38
+ params.delete('query')
39
+ }
40
+ window.location.search = params.toString()
41
+ }
42
+
43
+ export function Search({
44
+ variant,
45
+ inputSize,
46
+ inputClassName,
47
+ intent,
48
+ className,
49
+ onClear,
50
+ onEnter,
51
+ onSearch,
52
+ validatorFn,
53
+ placeHolderText = 'Search',
54
+ ariaLabelForSearch = 'search',
55
+ ariaLabelForClear = 'clear',
56
+ ...rest
57
+ }: SearchProps): React.JSX.Element {
58
+ const [search, setSearch] = useState<null | string>(null)
59
+ const inputRef = useRef<HTMLInputElement>(null)
60
+
61
+ const handleClear = (): void => {
62
+ setSearch(null)
63
+ if (onClear != null) {
64
+ onClear()
65
+ } else {
66
+ fallbackSearchHandler('')
67
+ }
68
+ if (inputRef?.current != null) {
69
+ inputRef.current.value = ''
70
+ }
71
+ }
72
+
73
+ const handleKeyDown = (event: { key: string }): void => {
74
+ if (event.key === 'Enter') {
75
+ if (search != null && search.length > 0) {
76
+ if (validatorFn != null) {
77
+ const result = validatorFn(search)
78
+ if (result.valid) {
79
+ if (onSearch != null) {
80
+ onSearch(search)
81
+ } else {
82
+ fallbackSearchHandler(search)
83
+ }
84
+ }
85
+ } else {
86
+ if (onSearch != null) {
87
+ onSearch(search)
88
+ } else {
89
+ fallbackSearchHandler(search)
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ const handleSearch = (): void => {
97
+ if (search != null && search.length > 0) {
98
+ if (validatorFn != null) {
99
+ const result = validatorFn(search)
100
+ if (result.valid) {
101
+ if (onSearch != null) {
102
+ onSearch(search)
103
+ } else {
104
+ fallbackSearchHandler(search)
105
+ }
106
+ }
107
+ } else {
108
+ if (onSearch != null) {
109
+ onSearch(search)
110
+ } else {
111
+ fallbackSearchHandler(search)
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
118
+ setSearch(event.target.value)
119
+ }
120
+
121
+ useEffect(() => {
122
+ const searchParams = new URLSearchParams(window.location.search)
123
+ const currentSearch = searchParams.get('query')
124
+ if (currentSearch != null && search == null) {
125
+ setSearch(currentSearch)
126
+ }
127
+ })
128
+
129
+ return (
130
+ <div className={className}>
131
+ <Input
132
+ variant={variant}
133
+ intent={intent}
134
+ inputSize={inputSize}
135
+ ref={inputRef}
136
+ className={inputClassName}
137
+ onKeyDown={handleKeyDown}
138
+ onChange={handleChange}
139
+ onClick={(e) => {
140
+ e.preventDefault()
141
+ e.stopPropagation()
142
+ }}
143
+ id="search"
144
+ defaultValue={search ?? ''}
145
+ name="search"
146
+ placeHolder={placeHolderText}
147
+ disabled={false}
148
+ error={false}
149
+ startAdornment={
150
+ <InputAdornment position="start">
151
+ <IconButton
152
+ role="button"
153
+ intent="noeffect"
154
+ variant="text"
155
+ ripple={false}
156
+ arial-label={ariaLabelForSearch}
157
+ size="xs"
158
+ onClick={() => {
159
+ handleSearch()
160
+ }}
161
+ >
162
+ <SearchIcon width="20px" height="20px" />
163
+ </IconButton>
164
+ </InputAdornment>
165
+ }
166
+ endAdornment={
167
+ <InputAdornment position="end">
168
+ <IconButton
169
+ role="button"
170
+ intent="noeffect"
171
+ variant="text"
172
+ arial-label={ariaLabelForClear}
173
+ size="xs"
174
+ onClick={() => {
175
+ handleClear()
176
+ }}
177
+ >
178
+ <CloseIcon width="16px" height="16px" />
179
+ </IconButton>
180
+ </InputAdornment>
181
+ }
182
+ {...rest}
183
+ />
184
+ </div>
185
+ )
186
+ }