@cxxi-lab/hub-ui 0.0.0-stage → 0.1.1

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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/fonts/MerriweatherSans/MerriweatherSans-Bold.woff +0 -0
  3. package/fonts/MerriweatherSans/MerriweatherSans-Bold.woff2 +0 -0
  4. package/fonts/MerriweatherSans/MerriweatherSans-BoldItalic.woff +0 -0
  5. package/fonts/MerriweatherSans/MerriweatherSans-BoldItalic.woff2 +0 -0
  6. package/fonts/MerriweatherSans/MerriweatherSans-ExtraBold.woff +0 -0
  7. package/fonts/MerriweatherSans/MerriweatherSans-ExtraBold.woff2 +0 -0
  8. package/fonts/MerriweatherSans/MerriweatherSans-ExtraBoldItalic.woff +0 -0
  9. package/fonts/MerriweatherSans/MerriweatherSans-ExtraBoldItalic.woff2 +0 -0
  10. package/fonts/MerriweatherSans/MerriweatherSans-Italic.woff +0 -0
  11. package/fonts/MerriweatherSans/MerriweatherSans-Italic.woff2 +0 -0
  12. package/fonts/MerriweatherSans/MerriweatherSans-Light.woff +0 -0
  13. package/fonts/MerriweatherSans/MerriweatherSans-Light.woff2 +0 -0
  14. package/fonts/MerriweatherSans/MerriweatherSans-LightItalic.woff +0 -0
  15. package/fonts/MerriweatherSans/MerriweatherSans-LightItalic.woff2 +0 -0
  16. package/fonts/MerriweatherSans/MerriweatherSans-Medium.woff +0 -0
  17. package/fonts/MerriweatherSans/MerriweatherSans-Medium.woff2 +0 -0
  18. package/fonts/MerriweatherSans/MerriweatherSans-MediumItalic.woff +0 -0
  19. package/fonts/MerriweatherSans/MerriweatherSans-MediumItalic.woff2 +0 -0
  20. package/fonts/MerriweatherSans/MerriweatherSans-Regular.woff +0 -0
  21. package/fonts/MerriweatherSans/MerriweatherSans-Regular.woff2 +0 -0
  22. package/fonts/MerriweatherSans/MerriweatherSans-SemiBold.woff +0 -0
  23. package/fonts/MerriweatherSans/MerriweatherSans-SemiBold.woff2 +0 -0
  24. package/fonts/MerriweatherSans/MerriweatherSans-SemiBoldItalic.woff +0 -0
  25. package/fonts/MerriweatherSans/MerriweatherSans-SemiBoldItalic.woff2 +0 -0
  26. package/fonts/Sofia/Sofia-Regular.woff +0 -0
  27. package/fonts/Sofia/Sofia-Regular.woff2 +0 -0
  28. package/package.json +45 -5
  29. package/src/Brand/Brand.tsx +23 -0
  30. package/src/Brand/Brand.types.ts +6 -0
  31. package/src/Brand/Brand.variants.ts +9 -0
  32. package/src/Brand/HubLogo.tsx +22 -0
  33. package/src/Brand/index.ts +2 -0
  34. package/src/back.ts +52 -0
  35. package/src/buttons/Button/Button.tsx +38 -0
  36. package/src/buttons/Button/Button.types.ts +18 -0
  37. package/src/buttons/Button/Button.variants.ts +36 -0
  38. package/src/buttons/Button/index.ts +2 -0
  39. package/src/buttons/FavButton/FavButton.tsx +29 -0
  40. package/src/buttons/FavButton/FavButton.types.ts +10 -0
  41. package/src/buttons/FavButton/FavButton.variants.ts +12 -0
  42. package/src/buttons/FavButton/index.ts +2 -0
  43. package/src/buttons/IconButton/IconButton.tsx +40 -0
  44. package/src/buttons/IconButton/IconButton.types.ts +23 -0
  45. package/src/buttons/IconButton/IconButton.variants.ts +56 -0
  46. package/src/buttons/IconButton/index.ts +2 -0
  47. package/src/buttons/index.ts +3 -0
  48. package/src/contexts/FormContext.tsx +57 -0
  49. package/src/forms/CheckboxField/Checkbox.tsx +17 -0
  50. package/src/forms/CheckboxField/CheckboxField.tsx +39 -0
  51. package/src/forms/CheckboxField/CheckboxField.types.ts +5 -0
  52. package/src/forms/CheckboxField/CheckboxField.variants.ts +36 -0
  53. package/src/forms/CheckboxField/index.ts +3 -0
  54. package/src/forms/DropdownField/DropdownField.tsx +72 -0
  55. package/src/forms/DropdownField/DropdownField.types.ts +11 -0
  56. package/src/forms/DropdownField/DropdownField.variants.ts +37 -0
  57. package/src/forms/DropdownField/index.ts +2 -0
  58. package/src/forms/Form/Form.tsx +41 -0
  59. package/src/forms/Form/Form.types.ts +11 -0
  60. package/src/forms/Form/Form.variants.ts +8 -0
  61. package/src/forms/Form/index.ts +2 -0
  62. package/src/forms/FormField/FormField.tsx +26 -0
  63. package/src/forms/FormField/FormField.types.ts +10 -0
  64. package/src/forms/FormField/FormField.variants.ts +44 -0
  65. package/src/forms/FormField/index.ts +3 -0
  66. package/src/forms/InputField/InputField.tsx +33 -0
  67. package/src/forms/InputField/InputField.types.ts +14 -0
  68. package/src/forms/InputField/InputField.variants.ts +14 -0
  69. package/src/forms/InputField/index.ts +2 -0
  70. package/src/forms/SpoilerField/SpoilerField.tsx +48 -0
  71. package/src/forms/SpoilerField/SpoilerField.types.ts +8 -0
  72. package/src/forms/SpoilerField/SpoilerField.variants.ts +31 -0
  73. package/src/forms/SpoilerField/index.ts +2 -0
  74. package/src/forms/SwitchField/ChoiceSwitch.tsx +43 -0
  75. package/src/forms/SwitchField/Switch.tsx +18 -0
  76. package/src/forms/SwitchField/SwitchField.tsx +43 -0
  77. package/src/forms/SwitchField/SwitchField.types.ts +5 -0
  78. package/src/forms/SwitchField/SwitchField.variants.ts +62 -0
  79. package/src/forms/SwitchField/index.ts +4 -0
  80. package/src/forms/TagsField/TagsField.tsx +109 -0
  81. package/src/forms/TagsField/TagsField.types.ts +7 -0
  82. package/src/forms/TagsField/TagsField.variants.ts +51 -0
  83. package/src/forms/TagsField/index.ts +2 -0
  84. package/src/forms/TextareaField/TextareaField.tsx +33 -0
  85. package/src/forms/TextareaField/TextareaField.types.ts +9 -0
  86. package/src/forms/TextareaField/TextareaField.variants.ts +14 -0
  87. package/src/forms/TextareaField/index.ts +2 -0
  88. package/src/forms/UploadField/UploadField.tsx +70 -0
  89. package/src/forms/UploadField/UploadField.types.ts +7 -0
  90. package/src/forms/UploadField/UploadField.variants.ts +23 -0
  91. package/src/forms/UploadField/index.ts +2 -0
  92. package/src/forms/index.ts +10 -0
  93. package/src/index.ts +15 -0
  94. package/src/menus/Dropdown/Dropdown.tsx +39 -0
  95. package/src/menus/Dropdown/Dropdown.types.ts +17 -0
  96. package/src/menus/Dropdown/Dropdown.variants.ts +44 -0
  97. package/src/menus/Dropdown/index.ts +2 -0
  98. package/src/menus/index.ts +1 -0
  99. package/src/modals/ConfirmationModal/ConfirmationModal.tsx +44 -0
  100. package/src/modals/ConfirmationModal/ConfirmationModal.types.ts +14 -0
  101. package/src/modals/ConfirmationModal/ConfirmationModal.variants.ts +6 -0
  102. package/src/modals/ConfirmationModal/index.ts +2 -0
  103. package/src/modals/FormModal/FormModal.tsx +46 -0
  104. package/src/modals/FormModal/FormModal.types.ts +14 -0
  105. package/src/modals/FormModal/FormModal.variants.ts +5 -0
  106. package/src/modals/FormModal/index.ts +2 -0
  107. package/src/modals/InfoModal/InfoModal.tsx +21 -0
  108. package/src/modals/InfoModal/InfoModal.types.ts +10 -0
  109. package/src/modals/InfoModal/InfoModal.variants.ts +6 -0
  110. package/src/modals/InfoModal/index.ts +2 -0
  111. package/src/modals/Modal/Modal.tsx +34 -0
  112. package/src/modals/Modal/Modal.types.ts +10 -0
  113. package/src/modals/Modal/Modal.variants.ts +48 -0
  114. package/src/modals/Modal/index.ts +2 -0
  115. package/src/modals/index.ts +4 -0
  116. package/src/navs/BreadCrumb/BreadCrumb.tsx +19 -0
  117. package/src/navs/BreadCrumb/BreadCrumb.types.ts +11 -0
  118. package/src/navs/BreadCrumb/BreadCrumb.variants.ts +7 -0
  119. package/src/navs/BreadCrumb/index.ts +2 -0
  120. package/src/navs/index.ts +1 -0
  121. package/src/tables/Table/Table.tsx +6 -0
  122. package/src/tables/Table/Table.types.ts +6 -0
  123. package/src/tables/Table/Table.variants.ts +5 -0
  124. package/src/tables/Table/index.ts +2 -0
  125. package/src/tables/TableCell/TableCell.tsx +27 -0
  126. package/src/tables/TableCell/TableCell.types.ts +9 -0
  127. package/src/tables/TableCell/TableCell.variants.ts +26 -0
  128. package/src/tables/TableCell/index.ts +2 -0
  129. package/src/tables/TableFootGroup/TableFootGroup.tsx +10 -0
  130. package/src/tables/TableFootGroup/TableFootGroup.variants.ts +6 -0
  131. package/src/tables/TableFootGroup/index.ts +1 -0
  132. package/src/tables/TableHead/TableHead.tsx +22 -0
  133. package/src/tables/TableHead/TableHead.types.ts +9 -0
  134. package/src/tables/TableHead/TableHead.variants.ts +16 -0
  135. package/src/tables/TableHead/index.ts +2 -0
  136. package/src/tables/TableHeadGroup/TableHeadGroup.tsx +10 -0
  137. package/src/tables/TableHeadGroup/TableHeadGroup.variants.ts +6 -0
  138. package/src/tables/TableHeadGroup/index.ts +1 -0
  139. package/src/tables/TableRow/TableRow.tsx +7 -0
  140. package/src/tables/TableRow/TableRow.types.ts +7 -0
  141. package/src/tables/TableRow/TableRow.variants.ts +12 -0
  142. package/src/tables/TableRow/index.ts +2 -0
  143. package/src/tables/TableRowGroup/TableRowGroup.tsx +6 -0
  144. package/src/tables/TableRowGroup/TableRowGroup.variants.ts +5 -0
  145. package/src/tables/TableRowGroup/index.ts +1 -0
  146. package/src/tables/index.ts +7 -0
  147. package/src/utils/index.ts +4 -0
  148. package/src/utils/snakeCase.ts +6 -0
  149. package/src/utils/useClickOutside.ts +16 -0
  150. package/src/utils/useMediaQuery.ts +11 -0
  151. package/src/utils/withLoading.ts +13 -0
  152. package/styles/fonts.css +116 -0
  153. package/styles/theme.css +78 -0
  154. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Louis-Antoine Lumet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
- "name": "@cxxi-lab/hub-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@cxxi-lab/hub-ui",
3
+ "version": "0.1.1",
4
+ "description": "hub's design system: React components, design tokens and fonts.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": [
8
+ "*.css"
9
+ ],
10
+ "exports": {
11
+ ".": "./src/index.ts",
12
+ "./theme.css": "./styles/theme.css",
13
+ "./fonts.css": "./styles/fonts.css",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "styles",
19
+ "fonts",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/cxxi-lab/hub-ui.git"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "tailwind-merge": "^3.6.0",
34
+ "tailwind-variants": "^3.2.2"
35
+ },
36
+ "peerDependencies": {
37
+ "@fortawesome/fontawesome-svg-core": "^7.2.0",
38
+ "@fortawesome/free-solid-svg-icons": "^7.2.0",
39
+ "@fortawesome/react-fontawesome": "^3.3.1",
40
+ "react": "^19.2.4",
41
+ "react-dom": "^19.2.4",
42
+ "react-router": "^7.18.3",
43
+ "tailwind-scrollbar": "^4.0.2",
44
+ "tailwindcss": "^4.3.0"
45
+ }
46
+ }
@@ -0,0 +1,23 @@
1
+ import { Link } from 'react-router'
2
+ import { HubLogo } from './HubLogo'
3
+ import { type BrandProps } from './Brand.types'
4
+ import { styles } from './Brand.variants'
5
+
6
+ export function Brand({ to, onClick }: BrandProps) {
7
+ const content = (
8
+ <>
9
+ <HubLogo className={styles.icon()} />
10
+ <span className={styles.text()}>hub</span>
11
+ </>
12
+ )
13
+
14
+ if (to) {
15
+ return (
16
+ <Link to={to} onClick={onClick} className={`${styles.wrap()} cursor-pointer`}>
17
+ {content}
18
+ </Link>
19
+ )
20
+ }
21
+
22
+ return <div className={styles.wrap()}>{content}</div>
23
+ }
@@ -0,0 +1,6 @@
1
+ import type { MouseEvent } from 'react'
2
+
3
+ export interface BrandProps {
4
+ to?: string
5
+ onClick?: (e: MouseEvent<HTMLAnchorElement>) => void
6
+ }
@@ -0,0 +1,9 @@
1
+ import { tv } from 'tailwind-variants'
2
+
3
+ export const styles = {
4
+ wrap: tv({
5
+ base: 'inline-flex items-center gap-1 px-1 text-2xl font-["Sofia"] select-none outline-none'
6
+ }),
7
+ icon: tv({ base: 'size-6' }),
8
+ text: tv({ base: 'brand-gradient font-bold mx-1 lowercase' })
9
+ }
@@ -0,0 +1,22 @@
1
+ import { useId } from 'react'
2
+
3
+ /** The hub mark (inline: the package needs no SVG loader in its consumers' bundler). */
4
+ export function HubLogo({ className }: { className?: string }) {
5
+ const gradient = `hub-logo-${useId()}`
6
+ return (
7
+ <svg className={className} width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
8
+ <path
9
+ fillRule="evenodd"
10
+ clipRule="evenodd"
11
+ d="M32 100.641C32 68.391 54.1651 41.3515 84 34.1102V1.28125C36.3772 8.98855 0 50.5392 0 100.641C0 150.742 36.3772 192.293 84 200V167.171C54.1651 159.93 32 132.89 32 100.641ZM200 100.641C200 150.742 163.623 192.293 116 200V167.171C145.835 159.93 168 132.89 168 100.641C168 68.391 145.835 41.3515 116 34.1102V1.28125C163.623 8.98855 200 50.5392 200 100.641Z"
12
+ fill={`url(#${gradient})`}
13
+ />
14
+ <defs>
15
+ <linearGradient id={gradient} x1="157.5" y1="33.0763" x2="44.7421" y2="148.561" gradientUnits="userSpaceOnUse">
16
+ <stop offset="0.0509862" stopColor="oklch(77.48% 0.11579287893479469 256.78266516146084)" />
17
+ <stop offset="1" stopColor="oklch(69.57% 0.16115444413200178 257.18469838826445)" />
18
+ </linearGradient>
19
+ </defs>
20
+ </svg>
21
+ )
22
+ }
@@ -0,0 +1,2 @@
1
+ export { Brand } from './Brand'
2
+ export * from './Brand.types'
package/src/back.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ /**
4
+ * The phone's back button (Android): it closes what is open on top (a menu, a modal, the module
5
+ * drawer…), most recent first; with nothing open, it goes back a page; on the home page, the app
6
+ * goes to the background. The host wires handleBack() to its back button (the app: window.hubBack,
7
+ * called by the Android shell, which does the last part itself when it answers false).
8
+ */
9
+
10
+ const handlers: Array<{ close: () => void }> = []
11
+ const depthListeners = new Set<(depth: number) => void>()
12
+ const changed = () => depthListeners.forEach(l => l(handlers.length))
13
+
14
+ /** How many things the back button would close, now and on each change (a hubby's frame tells its host). */
15
+ export function onBackDepth(listener: (depth: number) => void): () => void {
16
+ depthListeners.add(listener)
17
+ listener(handlers.length)
18
+ return () => { depthListeners.delete(listener) }
19
+ }
20
+
21
+ /** While `open`, the back button closes this (onClose). */
22
+ export function useBackHandler(open: boolean, onClose: () => void): void {
23
+ const latest = useRef(onClose)
24
+ latest.current = onClose
25
+ useEffect(() => {
26
+ if (!open) return
27
+ const entry = { close: () => latest.current() }
28
+ handlers.push(entry)
29
+ changed()
30
+ return () => {
31
+ const at = handlers.indexOf(entry)
32
+ if (at >= 0) handlers.splice(at, 1)
33
+ changed()
34
+ }
35
+ }, [open])
36
+ }
37
+
38
+ /** The back button: true when handled here (something closed, or a page back). */
39
+ export function handleBack(): boolean {
40
+ const top = handlers.pop()
41
+ if (top) {
42
+ changed()
43
+ top.close()
44
+ return true
45
+ }
46
+ const at = window.location.hash.replace(/^#/, '') || '/'
47
+ if (at !== '/' && window.history.length > 1) {
48
+ window.history.back()
49
+ return true
50
+ }
51
+ return false
52
+ }
@@ -0,0 +1,38 @@
1
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
2
+ import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
3
+ import { twMerge } from 'tailwind-merge'
4
+ import { type ButtonProps } from './Button.types'
5
+ import { styles } from './Button.variants'
6
+
7
+ export function Button({
8
+ label,
9
+ children,
10
+ icon,
11
+ onClick,
12
+ className,
13
+ color,
14
+ isDisabled = false,
15
+ isLoading = false,
16
+ type = 'button',
17
+ ...rest
18
+ }: ButtonProps) {
19
+ const classList = twMerge(styles.button({ disabled: isDisabled, color }), className)
20
+
21
+ return (
22
+ <button
23
+ type={type}
24
+ className={classList}
25
+ onClick={onClick}
26
+ disabled={isDisabled || isLoading}
27
+ {...rest}
28
+ >
29
+ {isLoading
30
+ ? <FontAwesomeIcon icon={faCircleNotch} className="animate-spin" />
31
+ : <>
32
+ {icon && <FontAwesomeIcon icon={icon} />}
33
+ {label ?? children}
34
+ </>
35
+ }
36
+ </button>
37
+ )
38
+ }
@@ -0,0 +1,18 @@
1
+ import { type IconDefinition } from '@fortawesome/fontawesome-svg-core'
2
+ import { type MouseEventHandler, type ReactNode } from 'react'
3
+
4
+ export type ButtonColor = 'primary' | 'secondary' | 'danger'
5
+
6
+ export interface ButtonProps {
7
+ label?: ReactNode
8
+ children?: ReactNode
9
+ icon?: IconDefinition
10
+ color?: ButtonColor
11
+ isDisabled?: boolean
12
+ isLoading?: boolean
13
+ className?: string
14
+ onClick?: MouseEventHandler<HTMLButtonElement>
15
+ type?: 'button' | 'submit' | 'reset'
16
+ title?: string
17
+ 'aria-label'?: string
18
+ }
@@ -0,0 +1,36 @@
1
+ import { tv } from 'tailwind-variants'
2
+
3
+ export const styles = {
4
+ button: tv({
5
+ base: [
6
+ 'inline-flex',
7
+ 'items-center',
8
+ 'justify-center',
9
+ 'gap-2',
10
+ 'px-4',
11
+ 'h-9',
12
+ 'rounded',
13
+ 'text-sm',
14
+ 'font-semibold',
15
+ 'leading-none',
16
+ // a label on one line, the button never squeezed by its neighbours (a narrow header)
17
+ 'whitespace-nowrap',
18
+ 'shrink-0',
19
+ 'cursor-pointer',
20
+ 'transition'
21
+ ],
22
+ variants: {
23
+ color: {
24
+ primary: 'bg-primary-500 text-steel-950 hover:bg-primary-300',
25
+ secondary: 'bg-steel-800 text-steel-100 hover:bg-steel-700 hover:text-white',
26
+ danger: 'bg-red-500 text-steel-950 hover:bg-red-300'
27
+ },
28
+ disabled: {
29
+ true: 'opacity-25 pointer-events-none'
30
+ }
31
+ },
32
+ defaultVariants: {
33
+ color: 'primary'
34
+ }
35
+ })
36
+ }
@@ -0,0 +1,2 @@
1
+ export { Button } from './Button'
2
+ export * from './Button.types'
@@ -0,0 +1,29 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { faStar } from '@fortawesome/free-solid-svg-icons'
3
+ import { IconButton } from '../IconButton'
4
+ import { type FavButtonProps } from './FavButton.types'
5
+ import { styles } from './FavButton.variants'
6
+
7
+ export function FavButton({ initialState = false, onClick, size, className, ...rest }: FavButtonProps) {
8
+ const [favorite, setFavorite] = useState(initialState)
9
+
10
+ useEffect(() => setFavorite(initialState), [initialState])
11
+
12
+ const handleClick = () => {
13
+ const next = !favorite
14
+ setFavorite(next)
15
+ onClick?.(next)
16
+ }
17
+
18
+ return (
19
+ <IconButton
20
+ icon={faStar}
21
+ color="secondary"
22
+ shape="square"
23
+ size={size}
24
+ onClick={handleClick}
25
+ className={[styles.button({ favorite }), className].filter(Boolean).join(' ')}
26
+ {...rest}
27
+ />
28
+ )
29
+ }
@@ -0,0 +1,10 @@
1
+ import { type IconButtonSize } from '../IconButton/IconButton.types'
2
+
3
+ export interface FavButtonProps {
4
+ initialState?: boolean
5
+ onClick?: (next: boolean) => void
6
+ size?: IconButtonSize
7
+ className?: string
8
+ title?: string
9
+ 'aria-label'?: string
10
+ }
@@ -0,0 +1,12 @@
1
+ import { tv } from 'tailwind-variants'
2
+
3
+ export const styles = {
4
+ button: tv({
5
+ variants: {
6
+ favorite: {
7
+ true: 'text-primary-500!',
8
+ false: 'text-steel-800!'
9
+ }
10
+ }
11
+ })
12
+ }
@@ -0,0 +1,2 @@
1
+ export { FavButton } from './FavButton'
2
+ export * from './FavButton.types'
@@ -0,0 +1,40 @@
1
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
2
+ import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
3
+ import { twMerge } from 'tailwind-merge'
4
+ import { type IconButtonProps } from './IconButton.types'
5
+ import { styles } from './IconButton.variants'
6
+
7
+ export function IconButton({
8
+ icon,
9
+ onClick,
10
+ className,
11
+ active = false,
12
+ highlighted = false,
13
+ isDisabled = false,
14
+ isLoading = false,
15
+ color,
16
+ shape,
17
+ size,
18
+ type = 'button',
19
+ ...rest
20
+ }: IconButtonProps) {
21
+ const classList = twMerge(
22
+ styles.button({ active, highlighted, disabled: isDisabled, color, shape, size }),
23
+ className
24
+ )
25
+
26
+ return (
27
+ <button
28
+ type={type}
29
+ className={classList}
30
+ onClick={onClick}
31
+ disabled={isDisabled || isLoading}
32
+ {...rest}
33
+ >
34
+ <FontAwesomeIcon
35
+ icon={isLoading ? faCircleNotch : icon}
36
+ className={styles.icon({ loading: isLoading })}
37
+ />
38
+ </button>
39
+ )
40
+ }
@@ -0,0 +1,23 @@
1
+ import { type IconDefinition } from '@fortawesome/fontawesome-svg-core'
2
+ import { type MouseEventHandler } from 'react'
3
+
4
+ export type IconButtonColor = 'primary' | 'secondary' | 'danger' | 'dark'
5
+ export type IconButtonShape = 'square' | 'circle'
6
+ export type IconButtonSize = 'xxs' | 'xs' | 'sm' | 'md' | 'xl'
7
+
8
+ export interface IconButtonProps {
9
+ icon: IconDefinition
10
+ onClick?: MouseEventHandler<HTMLButtonElement>
11
+ className?: string
12
+ active?: boolean
13
+ highlighted?: boolean
14
+ isDisabled?: boolean
15
+ isLoading?: boolean
16
+ color?: IconButtonColor
17
+ shape?: IconButtonShape
18
+ size?: IconButtonSize
19
+ type?: 'button' | 'submit' | 'reset'
20
+ title?: string
21
+ 'aria-label'?: string
22
+ 'aria-expanded'?: boolean
23
+ }
@@ -0,0 +1,56 @@
1
+ import { tv } from 'tailwind-variants'
2
+
3
+ export const styles = {
4
+ button: tv({
5
+ base: [
6
+ 'inline-flex',
7
+ 'justify-center',
8
+ 'items-center',
9
+ 'aspect-square',
10
+ 'font-semibold',
11
+ 'leading-none',
12
+ 'cursor-pointer',
13
+ 'transition'
14
+ ],
15
+ variants: {
16
+ color: {
17
+ primary: 'text-steel-950 bg-primary-500 hover:bg-primary-300',
18
+ secondary: 'text-steel-300 hover:bg-steel-700 hover:text-white',
19
+ danger: 'text-steel-950 bg-red-500 hover:bg-red-300',
20
+ dark: 'text-steel-300 bg-steel-800 hover:bg-steel-700 hover:text-white'
21
+ },
22
+ active: {
23
+ true: 'bg-primary-700! text-primary-300!'
24
+ },
25
+ highlighted: {
26
+ true: 'text-primary-300!'
27
+ },
28
+ shape: {
29
+ square: 'rounded',
30
+ circle: 'rounded-full'
31
+ },
32
+ size: {
33
+ xxs: 'size-4 text-[11px]',
34
+ xs: 'size-6 text-xs',
35
+ sm: 'size-7 text-sm',
36
+ md: 'size-9 text-base',
37
+ xl: 'size-10 text-lg'
38
+ },
39
+ disabled: {
40
+ true: 'opacity-25 pointer-events-none'
41
+ }
42
+ },
43
+ defaultVariants: {
44
+ color: 'dark',
45
+ shape: 'circle',
46
+ size: 'md'
47
+ }
48
+ }),
49
+ icon: tv({
50
+ variants: {
51
+ loading: {
52
+ true: 'animate-spin'
53
+ }
54
+ }
55
+ })
56
+ }
@@ -0,0 +1,2 @@
1
+ export { IconButton } from './IconButton'
2
+ export * from './IconButton.types'
@@ -0,0 +1,3 @@
1
+ export * from './Button'
2
+ export * from './IconButton'
3
+ export * from './FavButton'
@@ -0,0 +1,57 @@
1
+ import { createContext, useContext, useState, type ReactNode } from 'react'
2
+
3
+ export type FormData = Record<string, unknown>
4
+ export type FormErrors = Record<string, string | null>
5
+
6
+ export interface FormContextValue {
7
+ data: FormData
8
+ errors: FormErrors
9
+ setField: (field: string, value: unknown) => void
10
+ setError: (field: string, message: string | null) => void
11
+ clearError: (field: string) => void
12
+ reset: () => void
13
+ }
14
+
15
+ interface FormContextProviderProps {
16
+ children: ReactNode
17
+ initialData?: FormData
18
+ }
19
+
20
+ const FormContext = createContext<FormContextValue | undefined>(undefined)
21
+
22
+ export function FormContextProvider({ children, initialData = {} }: FormContextProviderProps) {
23
+ const [data, setData] = useState<FormData>(initialData)
24
+ const [errors, setErrors] = useState<FormErrors>({})
25
+
26
+ const setField = (field: string, value: unknown) => {
27
+ setData(prev => ({ ...prev, [field]: value }))
28
+ setErrors(prev => ({ ...prev, [field]: null }))
29
+ }
30
+
31
+ const setError = (field: string, message: string | null) => {
32
+ setErrors(prev => ({ ...prev, [field]: message }))
33
+ }
34
+
35
+ const clearError = (field: string) => {
36
+ setErrors(prev => ({ ...prev, [field]: null }))
37
+ }
38
+
39
+ const reset = () => {
40
+ setData(initialData)
41
+ setErrors({})
42
+ }
43
+
44
+ return (
45
+ <FormContext.Provider value={{ data, errors, setField, setError, clearError, reset }}>
46
+ {children}
47
+ </FormContext.Provider>
48
+ )
49
+ }
50
+
51
+ export function useFormContext(): FormContextValue {
52
+ const context = useContext(FormContext)
53
+ if (!context) {
54
+ throw new Error('useFormContext must be used within a FormContextProvider')
55
+ }
56
+ return context
57
+ }
@@ -0,0 +1,17 @@
1
+ import { type ReactNode } from 'react'
2
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
+ import { faCheck } from '@fortawesome/free-solid-svg-icons'
4
+ import { styles } from './CheckboxField.variants'
5
+
6
+ /** The CheckboxField box on its own, outside a form: controlled by `checked`, its label beside it. */
7
+ export function Checkbox({ checked, label, onChange }: { checked: boolean, label: ReactNode, onChange: (checked: boolean) => void }) {
8
+ return (
9
+ <label className="inline-flex items-center gap-2 cursor-pointer select-none">
10
+ <input type="checkbox" className="sr-only" checked={checked} onChange={e => onChange(e.target.checked)} />
11
+ <span aria-hidden className={styles.check({ checked })}>
12
+ <FontAwesomeIcon icon={faCheck} />
13
+ </span>
14
+ <span className="inline-flex items-center gap-2 text-sm text-steel-100">{label}</span>
15
+ </label>
16
+ )
17
+ }