nitro-web 0.3.6 → 0.3.8

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.
@@ -1,9 +1,20 @@
1
1
 
2
+ /* ---- Calendar (react-day-picker) ----- */
3
+
4
+ .nitro-calendar {
5
+ --rdp-accent-color: rgb(var(--primary-text));
6
+ --rdp-accent-background-color: rgb(var(--primary-text) / 0.08);
7
+ --rdp-today-color: rgb(var(--primary-text));
8
+ }
9
+ .dark .nitro-calendar {
10
+ --rdp-accent-background-color: rgb(var(--primary-text) / 0.25);
11
+ }
12
+
2
13
  /* ---- Tailwind UI Components ---------- */
3
14
 
4
15
  @layer base {
5
16
  .border-bottom-with-space {
6
- @apply relative mb-[6px] after:content-[""] after:absolute after:bottom-[-4px] after:left-0 after:h-[1px] after:w-full after:bg-gray-200;
17
+ @apply relative mb-[6px] after:content-[""] after:absolute after:bottom-[-4px] after:left-0 after:h-[1px] after:w-full after:bg-muted;
7
18
  }
8
19
  }
9
20
 
package/client/index.ts CHANGED
@@ -40,6 +40,7 @@ export { Modal } from '../components/partials/element/modal'
40
40
  export { Pagination, type PaginationProps } from '../components/partials/element/pagination'
41
41
  export { Sidebar, getIsActive, type SidebarProps } from '../components/partials/element/sidebar'
42
42
  export { TimePicker, type TimePickerProps } from '../components/partials/element/timepicker'
43
+ export { ThemeToggle, useTheme, getTheme, type Theme } from '../components/partials/element/theme-toggle'
43
44
  export { Tooltip, type TooltipProps } from '../components/partials/element/tooltip'
44
45
  export { Topbar } from '../components/partials/element/topbar'
45
46
  export { Table, type TableColumn, type TableProps, type TableRow, type TableRowType } from '../components/partials/element/table'
@@ -3,9 +3,9 @@ import { injectedConfig } from 'nitro-web'
3
3
 
4
4
  export function Dashboard() {
5
5
  const [store] = useTracked()
6
- const textColor = store.apiAvailable ? 'text-green-700' : injectedConfig.isStatic ? 'text-gray-700' : 'text-pink-700'
7
- const fillColor = store.apiAvailable ? 'fill-green-500' : injectedConfig.isStatic ? 'fill-gray-500' : 'fill-pink-500'
8
- const bgColor = store.apiAvailable ? 'bg-green-100' : injectedConfig.isStatic ? 'bg-[#eeeeee]' : 'bg-pink-100'
6
+ const textColor = store.apiAvailable ? 'text-green-700' : injectedConfig.isStatic ? 'text-foreground' : 'text-pink-700'
7
+ const fillColor = store.apiAvailable ? 'fill-green-500' : injectedConfig.isStatic ? 'fill-muted-foreground' : 'fill-pink-500'
8
+ const bgColor = store.apiAvailable ? 'bg-green-100' : injectedConfig.isStatic ? 'bg-muted' : 'bg-pink-100'
9
9
 
10
10
  return (
11
11
  <div css={style}>
@@ -13,7 +13,7 @@ export function Dashboard() {
13
13
  <p className="mb-4">
14
14
  Welcome to Nitro, a modular React/Express base project, styled using Tailwind 🚀.
15
15
  </p>
16
- <p className="text-gray-700">
16
+ <p className="text-foreground">
17
17
  <span className={`inline-flex items-center gap-x-1.5 rounded-md ${bgColor} px-1.5 py-0.5 text-xs font-medium ${textColor}`}>
18
18
  <svg viewBox="0 0 6 6" aria-hidden="true" className={`size-1.5 ${fillColor}`}>
19
19
  <circle r={3} cx={3} cy={3} />
@@ -43,10 +43,10 @@ export function Button({
43
43
  const colors = {
44
44
  'primary': 'bg-primary hover:bg-primary-hover ring-transparent text-white [&>.spinner]:border-white',
45
45
  'secondary': 'bg-secondary hover:bg-secondary-hover ring-transparent text-white [&>.spinner]:border-white',
46
- 'black': 'bg-black hover:bg-gray-800 ring-transparent text-white [&>.spinner]:border-white',
47
- 'dark': 'bg-gray-800 hover:bg-gray-700 ring-transparent text-white [&>.spinner]:border-white',
48
- 'white': 'bg-white hover:bg-gray-50 ring-gray-300 text-gray-900 [&>.spinner]:border-black', // maybe change to text-foreground
49
- 'clear': 'hover:bg-gray-50 ring-gray-300 hover:text-foreground [&>.spinner]:border-foreground !shadow-none',
46
+ 'black': 'bg-foreground hover:bg-foreground/90 ring-transparent text-background [&>.spinner]:border-background',
47
+ 'dark': 'bg-foreground/90 hover:bg-foreground/80 ring-transparent text-background [&>.spinner]:border-background',
48
+ 'white': 'bg-surface hover:bg-muted ring-input-border text-foreground [&>.spinner]:border-foreground',
49
+ 'clear': 'hover:bg-muted ring-input-border hover:text-foreground [&>.spinner]:border-foreground !shadow-none',
50
50
  'danger': 'bg-danger hover:bg-danger-hover ring-transparent text-white [&>.spinner]:border-white',
51
51
  'warning': 'bg-warning hover:bg-warning-hover ring-transparent text-white [&>.spinner]:border-white',
52
52
  'info': 'bg-info hover:bg-info-hover ring-transparent text-white [&>.spinner]:border-white',
@@ -101,7 +101,7 @@ export function Spinner({ className, absoluteCenter }: { className?: string, abs
101
101
  const absoluteCenterClass = absoluteCenter ? 'absolute top-[50%] left-[50%] ml-[-0.5rem] mt-[-0.5rem]' : ''
102
102
  return (
103
103
  <span
104
- className={twMerge(`spinner border-black border-2 inline-block size-[1em] rounded-full animate-spin ${absoluteCenterClass} ${className||''} !border-t-transparent `)}
104
+ className={twMerge(`spinner border-foreground border-2 inline-block size-[1em] rounded-full animate-spin ${absoluteCenterClass} ${className||''} !border-t-transparent `)}
105
105
  />
106
106
  )
107
107
  }
@@ -116,7 +116,7 @@ export function Calendar({ value, numberOfMonths, month: monthProp, className, p
116
116
  caption_label: `${d.caption_label} z-auto`,
117
117
  button_previous: `${d.button_previous} size-8`,// [&:hover>svg]:fill-input-border-focus`,
118
118
  button_next: `${d.button_next} size-8`,// [&:hover>svg]:fill-input-border-focus`,
119
- chevron: `${d.chevron} fill-black size-[18px]`,
119
+ chevron: `${d.chevron} fill-foreground size-[18px]`,
120
120
 
121
121
  // Days
122
122
  weekday: `${d.weekday} text-[11px] font-bold uppercase`,
@@ -124,7 +124,7 @@ export function Calendar({ value, numberOfMonths, month: monthProp, className, p
124
124
  day_button: `${d.day_button} ${dayButtonClassName}`,
125
125
 
126
126
  // States
127
- focused: `${d.focused} [&>button]:bg-gray-200 [&>button]:border-gray-200`,
127
+ focused: `${d.focused} [&>button]:bg-muted [&>button]:border-border`,
128
128
  range_start: `${d.range_start} [&>button]:!bg-input-border-focus [&>button]:!border-input-border-focus`,
129
129
  range_end: `${d.range_end} [&>button]:!bg-input-border-focus [&>button]:!border-input-border-focus`,
130
130
  selected: `${d.selected} font-normal `
@@ -217,7 +217,7 @@ export const Dropdown = forwardRef(function Dropdown({
217
217
  { !!option.iconLeft && option.iconLeft }
218
218
  <span class="flex-auto">{option.label}</span>
219
219
  { !!option.icon && option.icon }
220
- { option.isSelected && <CheckCircleIcon className="size-[22px] text-primary -my-1 -mx-0.5" /> }
220
+ { option.isSelected && <CheckCircleIcon className="size-[22px] text-primary-text -my-1 -mx-0.5" /> }
221
221
  </li>
222
222
  )
223
223
  })
@@ -69,7 +69,7 @@ export function ConfirmModal({
69
69
  >
70
70
  <div className="text-center">
71
71
  <h3 className={twMerge('h3 text-[18px] mb-2.5', titleClassName)}>{cached.current.title}</h3>
72
- {cached.current.subtitle && <p className={twMerge('h5 text-gray-500 mb-0', subtitleClassName)}>{cached.current.subtitle}</p>}
72
+ {cached.current.subtitle && <p className={twMerge('h5 text-muted-foreground mb-0', subtitleClassName)}>{cached.current.subtitle}</p>}
73
73
  </div>
74
74
  {cached.current.children}
75
75
  <div className="self-stretch flex mt-1.5">
@@ -134,7 +134,7 @@ export function FormModal({
134
134
  <h3 className="h3 text-[15.5px] mb-0 pb-0">{cached.current.title}</h3>
135
135
  </div>
136
136
  {cached.current.subtitle && (
137
- <p className={twMerge('h5 text-gray-500 mb-0 text-left', subtitleClassName)}>{cached.current.subtitle}</p>
137
+ <p className={twMerge('h5 text-muted-foreground mb-0 text-left', subtitleClassName)}>{cached.current.subtitle}</p>
138
138
  )}
139
139
  </Fragment>
140
140
  )}
@@ -147,7 +147,7 @@ export function FormModal({
147
147
  </div>
148
148
  )}
149
149
  {cached.current.footerNote && (
150
- <div className="-mt-1 text-xs text-gray-500 flex items-center justify-center gap-1.5">{cached.current.footerNote}</div>
150
+ <div className="-mt-1 text-xs text-muted-foreground flex items-center justify-center gap-1.5">{cached.current.footerNote}</div>
151
151
  )}
152
152
  </Modal>
153
153
  )
@@ -86,10 +86,10 @@ export function ImageDrop({ awsUrl, className, id, name, onChange, state, inheri
86
86
  )}
87
87
  {!url && !inheritedUrl && (
88
88
  <div class="flex flex-col items-center gap-2.5 pointer-events-none">
89
- <ImageIcon size={30} strokeWidth={1.25} class="text-grey-2 transition-colors group-hover:text-primary" />
89
+ <ImageIcon size={30} strokeWidth={1.25} class="text-grey-2 transition-colors group-hover:text-primary-text" />
90
90
  <div>
91
91
  Drag and drop your image here, or
92
- <span class="text-primary font-medium"> select a file</span>
92
+ <span class="text-primary-text font-medium"> select a file</span>
93
93
  </div>
94
94
  </div>
95
95
  )}
@@ -30,7 +30,7 @@ export function Initials({ initials, color, colorBg, colors, opacityBg, size, is
30
30
  if ((colorFgClass || colorBgClass) && (!color || !colorBg)) {
31
31
  throw new Error('When using className colors, `color` and `colorBg` params are required')
32
32
  }
33
- // Check if hex colors were passed, otherwise use the color by letter
33
+ // Check if hex colors were passed, otherwise use the themed color by letter
34
34
  const colorFgHex = colorFgClass ? undefined : (color || getColorByLetter(initials, colors))
35
35
  const colorBgHex = colorBgClass ? undefined : (colorBg || colorFgHex)
36
36
 
@@ -42,7 +42,7 @@ export function Initials({ initials, color, colorBg, colors, opacityBg, size, is
42
42
  className={twMerge(
43
43
  (
44
44
  'nitro-initials flex-shrink-0 inline-flex items-center justify-center font-bold text-[11px] size-[24px] relative rounded-md ' +
45
- `overflow-hidden ring-1 ring-inset ring-[#00000012] ${colorFgClass}`
45
+ `overflow-hidden ring-1 ring-inset ring-foreground/10 ${colorFgClass}`
46
46
  ),
47
47
  sizeClasses(size || 'normal'),
48
48
  isRound && 'rounded-full',
@@ -59,8 +59,9 @@ export function Initials({ initials, color, colorBg, colors, opacityBg, size, is
59
59
  )
60
60
  }
61
61
 
62
+ // Default palette lives in nitro-web/client/css/theme.css (--initials-1..7) so it can differ per theme
62
63
  export function getColorByLetter(letter: string, colors?: string[]) {
63
- const colors2 = colors || ['#067306', '#AA33FF', '#FF54AF', '#F44336', '#c03c3c', '#5451e0', '#d88c1b']
64
+ const colors2 = colors || [1, 2, 3, 4, 5, 6, 7].map(i => `rgb(var(--initials-${i}))`)
64
65
  const charIndex = letter.toLowerCase().charCodeAt(0) - 97
65
66
  const charIndexLimited = (charIndex < 0 || charIndex > 25) ? 25 : charIndex
66
67
  const index = Math.round(charIndexLimited / 25 * (colors2.length-1))
@@ -15,7 +15,7 @@ export function LoadingWithDots({ message='Loading', className, classNameDots }:
15
15
  export function LoadingOverlay({ message='Loading', className }: { message?: string, className?: string }) {
16
16
  return (
17
17
  <div
18
- className={twMerge('absolute inset-0 bg-white bg-opacity-75 flex items-center justify-center z-10 text-sm [&>span]:bg-white', className)}
18
+ className={twMerge('absolute inset-0 bg-surface bg-opacity-75 flex items-center justify-center z-10 text-sm [&>span]:bg-surface', className)}
19
19
  >
20
20
  <span className="inline-block flex items-center justify-center gap-3 p-2">
21
21
  <Spinner />{message}
@@ -189,7 +189,7 @@ export function Message({ className, classNameWrapper, icons: iconsProp, positio
189
189
  <div className="flex flex-col items-center space-y-4">
190
190
  {messageObject && (
191
191
  <div className={twMerge(
192
- 'overflow-hidden translate-y-[0.5rem] opacity-0 pointer-events-auto max-w-[350px] rounded-md bg-white shadow-lg ring-1 ring-black/5 transition text-sm font-medium text-gray-900',
192
+ 'overflow-hidden translate-y-[0.5rem] opacity-0 pointer-events-auto max-w-[350px] rounded-md bg-surface shadow-lg ring-1 ring-border transition text-sm font-medium text-foreground',
193
193
  positionArr[1],
194
194
  (visible ? 'translate-x-0 translate-y-0 sm:translate-x-0 sm:translate-y-0 opacity-100' : 'pointer-events-none'),
195
195
  className
@@ -210,8 +210,8 @@ export function Message({ className, classNameWrapper, icons: iconsProp, positio
210
210
  <button
211
211
  type="button"
212
212
  onClick={hide}
213
- className="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2
214
- focus:ring-indigo-500 focus:ring-offset-2"
213
+ className="inline-flex rounded-md bg-surface text-muted-foreground hover:text-muted-foreground focus:outline-none focus:ring-2
214
+ focus:ring-primary focus:ring-offset-2"
215
215
  >
216
216
  <span className="sr-only">Close</span>
217
217
  <X aria-hidden="true" size={19} />
@@ -70,13 +70,13 @@ export function Modal({
70
70
  onClick={(e) => e.stopPropagation()}
71
71
  class={`${twMerge(`fixed top-0 w-[100vw] h-[100vh] z-[200] ${stateObj.root} ${rootClassName||''}`)} nitro-modal`}
72
72
  >
73
- <div class={`${twMerge('!absolute inset-0 box-content bg-gray-500/70 transition-opacity')} ${stateObj.bg}`}></div>
73
+ <div class={`${twMerge('!absolute inset-0 box-content bg-overlay/70 transition-opacity')} ${stateObj.bg}`}></div>
74
74
  <div class={`${twMerge('relative h-[100vh] overflow-y-auto transition-[opacity,transform]')} ${stateObj.container}`}>
75
75
  <div class="flex items-center justify-center min-h-full" onMouseDown={onClick}>
76
76
  <div
77
77
  ref={containerEl}
78
78
  style={{ maxWidth: maxWidth || '550px', minHeight: minHeight }}
79
- class={`${twMerge('relative w-full mx-6 mt-4 mb-8 bg-white rounded-lg shadow-lg p-9', className)}`}
79
+ class={`${twMerge('relative w-full mx-6 mt-4 mb-8 bg-surface rounded-lg shadow-lg p-9', className)}`}
80
80
  >
81
81
  <div
82
82
  class={twMerge(`absolute top-0 right-0 p-3 m-1 cursor-pointer ${xClassName||''}`)}
@@ -4,11 +4,13 @@ import avatarImg from 'nitro-web/client/imgs/avatar.jpg'
4
4
  import { injectedConfig } from 'nitro-web'
5
5
  import React from 'react'
6
6
  import { House, LogOut, Menu, Paintbrush, Users, XIcon } from 'lucide-react'
7
+ import { ThemeToggle } from './theme-toggle'
7
8
 
8
9
  const sidebarWidth = 'w-80'
9
10
 
10
11
  export type SidebarProps = {
11
12
  Logo?: React.FC<{ width?: string, height?: string }>;
13
+ themeToggle?: boolean; // defaults to true
12
14
  menu?: { name: string; to: string; toMatcher?: ToMatcher; Icon: React.FC<{ className?: string }> }[]
13
15
  links?: { name: string; to: string; toMatcher?: ToMatcher; initial: string }[]
14
16
  }
@@ -19,7 +21,7 @@ function classNames(...classes: string[]) {
19
21
  return classes.filter(Boolean).join(' ')
20
22
  }
21
23
 
22
- export function Sidebar({ Logo, menu, links }: SidebarProps) {
24
+ export function Sidebar({ Logo, menu, links, themeToggle }: SidebarProps) {
23
25
  const [sidebarOpen, setSidebarOpen] = useState(false)
24
26
  return (
25
27
  <React.Fragment>
@@ -41,14 +43,14 @@ export function Sidebar({ Logo, menu, links }: SidebarProps) {
41
43
  <XIcon aria-hidden="true" strokeWidth={1.5} size={24} className="text-white" />
42
44
  </button>
43
45
  </div>
44
- <SidebarContents Logo={Logo} menu={menu} links={links} />
46
+ <SidebarContents Logo={Logo} menu={menu} links={links} themeToggle={themeToggle} />
45
47
  </div>
46
48
 
47
49
  {/* mobile backdrop */}
48
50
  <div
49
51
  css={style}
50
52
  onClick={() => setSidebarOpen(false)}
51
- className={'fixed w-full z-[49] inset-0 bg-gray-900/70 ease-linear lg:hidden ' +
53
+ className={'fixed w-full z-[49] inset-0 bg-overlay/70 ease-linear lg:hidden ' +
52
54
  (
53
55
  sidebarOpen
54
56
  ? 'left-0 opacity-100 sidebar-transition '
@@ -58,13 +60,14 @@ export function Sidebar({ Logo, menu, links }: SidebarProps) {
58
60
  />
59
61
 
60
62
  {/* mobile sidebar topbar */}
61
- <div className="sticky top-0 z-40 flex items-center gap-x-6 bg-white px-4 py-4 shadow-sm sm:px-6 lg:hidden">
62
- <button type="button" onClick={() => setSidebarOpen(true)} className="-m-2.5 p-2.5 text-gray-700 lg:hidden">
63
+ <div className="sticky top-0 z-40 flex items-center gap-x-6 bg-surface px-4 py-4 shadow-sm sm:px-6 lg:hidden">
64
+ <button type="button" onClick={() => setSidebarOpen(true)} className="-m-2.5 p-2.5 text-foreground lg:hidden">
63
65
  <Menu aria-hidden="true" className="size-6" />
64
66
  </button>
65
- <div className="flex-1 text-sm/6 font-semibold text-gray-900">Dashboard</div>
67
+ <div className="flex-1 text-sm/6 font-semibold text-foreground">Dashboard</div>
68
+ {themeToggle !== false && <ThemeToggle />}
66
69
  <Link to="#">
67
- <img alt="" src={avatarImg} className="size-8 rounded-full bg-gray-50" />
70
+ <img alt="" src={avatarImg} className="size-8 rounded-full bg-muted" />
68
71
  </Link>
69
72
  </div>
70
73
 
@@ -73,7 +76,7 @@ export function Sidebar({ Logo, menu, links }: SidebarProps) {
73
76
  )
74
77
  }
75
78
 
76
- function SidebarContents ({ Logo, menu, links }: SidebarProps) {
79
+ function SidebarContents ({ Logo, menu, links, themeToggle }: SidebarProps) {
77
80
  const location = useLocation()
78
81
  const [store] = useTracked()
79
82
  const user = store.user
@@ -93,13 +96,16 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
93
96
 
94
97
  // Sidebar component, swap this element with another sidebar if you like
95
98
  return (
96
- <div className="flex grow flex-col gap-y-8 overflow-y-auto bg-white py-5 px-10 lg:border-r lg:border-gray-200">
99
+ <div className="flex grow flex-col gap-y-8 overflow-y-auto bg-surface py-5 px-10 lg:border-r lg:border-border">
97
100
  {Logo && (
98
101
  <div className="flex h-16 shrink-0 items-center gap-2 justify-between">
99
102
  <Link to="/">
100
103
  <Logo width="70" height={undefined} />
101
104
  </Link>
102
- <span className="text-[9px] text-gray-900 font-semibold mt-4">{injectedConfig.version}</span>
105
+ <div className="flex items-center gap-1 mt-4">
106
+ <span className="text-[9px] text-foreground font-semibold">{injectedConfig.version}</span>
107
+ {themeToggle !== false && <ThemeToggle size={13} className="p-1 -mr-1" />}
108
+ </div>
103
109
  </div>
104
110
  )}
105
111
  <nav className="flex flex-1 flex-col">
@@ -112,15 +118,15 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
112
118
  to={item.to}
113
119
  className={classNames(
114
120
  isActive(item)
115
- ? 'bg-gray-50 text-indigo-600'
116
- : 'text-gray-700 hover:bg-gray-50 hover:text-indigo-600',
121
+ ? 'bg-muted text-primary-text'
122
+ : 'text-foreground/80 hover:bg-muted hover:text-primary-text',
117
123
  'group flex gap-x-3 items-center rounded-md p-2 text-md/6 font-semibold'
118
124
  )}
119
125
  >
120
126
  { item.Icon &&
121
127
  <item.Icon
122
128
  className={classNames(
123
- isActive(item) ? 'text-indigo-600' : 'text-gray-400 group-hover:text-indigo-600',
129
+ isActive(item) ? 'text-primary-text' : 'text-muted-foreground/70 group-hover:text-primary-text',
124
130
  'size-5 shrink-0'
125
131
  )}
126
132
  />
@@ -132,7 +138,7 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
132
138
  </ul>
133
139
  </li>
134
140
  <li>
135
- <div className="text-xs/6 font-semibold text-gray-400">Other Links</div>
141
+ <div className="text-xs/6 font-semibold text-muted-foreground/70">Other Links</div>
136
142
  <ul role="list" className="-mx-2 mt-2 space-y-1">
137
143
  {_links.map((team) => (
138
144
  <li key={team.name}>
@@ -140,17 +146,17 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
140
146
  to={team.to}
141
147
  className={classNames(
142
148
  isActive(team)
143
- ? 'bg-gray-50 text-indigo-600'
144
- : 'text-gray-700 hover:bg-gray-50 hover:text-indigo-600',
149
+ ? 'bg-muted text-primary-text'
150
+ : 'text-foreground/80 hover:bg-muted hover:text-primary-text',
145
151
  'group flex gap-x-3 rounded-md p-2 text-md/6 font-semibold'
146
152
  )}
147
153
  >
148
154
  <span
149
155
  className={classNames(
150
156
  isActive(team)
151
- ? 'border-indigo-600 text-indigo-600'
152
- : 'border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600',
153
- 'flex size-6 shrink-0 items-center justify-center rounded-lg border bg-white text-[0.625rem] font-medium'
157
+ ? 'border-primary-text text-primary-text'
158
+ : 'border-border text-muted-foreground/70 group-hover:border-primary-text group-hover:text-primary-text',
159
+ 'flex size-6 shrink-0 items-center justify-center rounded-lg border bg-surface text-[0.625rem] font-medium'
154
160
  )}
155
161
  >
156
162
  {team.initial}
@@ -165,9 +171,9 @@ function SidebarContents ({ Logo, menu, links }: SidebarProps) {
165
171
  <li className="-mx-6 mt-auto hidden lg:block">
166
172
  <Link
167
173
  to="#"
168
- className="flex items-center gap-x-4 px-6 py-3 text-sm/6 font-semibold text-gray-900 hover:bg-gray-50"
174
+ className="flex items-center gap-x-4 px-6 py-3 text-sm/6 font-semibold text-foreground hover:bg-muted"
169
175
  >
170
- <img alt="" src={avatarImg} className="size-8 rounded-full bg-gray-50" />
176
+ <img alt="" src={avatarImg} className="size-8 rounded-full bg-muted" />
171
177
  <span aria-hidden="true" class="truncate1 flex-1">{user?.name || 'Guest'}</span>
172
178
  </Link>
173
179
  </li>
@@ -282,7 +282,7 @@ export function Table<T extends TableRow>({
282
282
  columnClassName,
283
283
  columnClassNameFn ? columnClassNameFn(col, row, i) : '',
284
284
  col.className,
285
- isSelected ? `bg-gray-50 ${columnSelectedClassName||''}` : ''
285
+ isSelected ? `bg-muted ${columnSelectedClassName||''}` : ''
286
286
  )}
287
287
  >
288
288
  <div
@@ -326,13 +326,13 @@ export function Table<T extends TableRow>({
326
326
  {
327
327
  // Show "no records" or "loading" text in the first column
328
328
  j == 0 && (!row._id || isLoading) &&
329
- <div className={'absolute top-0 h-full flex items-center justify-center gap-3 text-sm text-gray-500'}>
329
+ <div className={'absolute top-0 h-full flex items-center justify-center gap-3 text-sm text-muted-foreground'}>
330
330
  {
331
331
  (!row._id && !isLoading) ? (
332
332
  'No records found.'
333
333
  ) : (!row._id && isLoading && showLoadingInline === true) ? (
334
334
  <Fragment>
335
- <Spinner className="border-gray-500" />
335
+ <Spinner className="border-muted-foreground" />
336
336
  <LoadingWithDots message={loadingMessage} />
337
337
  </Fragment>
338
338
  ) : (!row._id && isLoading && showLoadingInline) ? (
@@ -0,0 +1,37 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { Moon, Sun } from 'lucide-react'
3
+ import { twMerge } from 'nitro-web'
4
+
5
+ export type Theme = 'light' | 'dark'
6
+
7
+ // Theme already applied by the index.html script, else saved, else the OS preference
8
+ export function getTheme(): Theme {
9
+ if (document.documentElement.classList.contains('dark')) return 'dark'
10
+ const saved = localStorage.getItem('theme') as Theme | null
11
+ return saved || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
12
+ }
13
+
14
+ // Applies the theme to <html> and persists it
15
+ export function useTheme() {
16
+ const [theme, setTheme] = useState<Theme>(getTheme)
17
+ useEffect(() => {
18
+ document.documentElement.classList.toggle('dark', theme == 'dark')
19
+ localStorage.setItem('theme', theme)
20
+ }, [theme])
21
+ const toggle = () => setTheme(theme == 'dark' ? 'light' : 'dark')
22
+ return { theme, setTheme, toggle }
23
+ }
24
+
25
+ export function ThemeToggle({ className, size=18 }: { className?: string, size?: number }) {
26
+ const { theme, toggle } = useTheme()
27
+ return (
28
+ <button
29
+ type="button"
30
+ onClick={toggle}
31
+ title="Toggle theme"
32
+ class={twMerge('p-2 rounded-md text-muted-foreground hover:bg-muted hover:text-foreground', className)}
33
+ >
34
+ {theme == 'dark' ? <Sun size={size} /> : <Moon size={size} />}
35
+ </button>
36
+ )
37
+ }
@@ -117,7 +117,7 @@ export function TimePicker({ value, onChange, className, tz, referenceTimestamp
117
117
  <div
118
118
  key={i}
119
119
  ref={refs[type]}
120
- className="w-[60px] relative overflow-hidden hover:overflow-y-auto border-l border-gray-100 sm-scrollbar first:border-l-0"
120
+ className="w-[60px] relative overflow-hidden hover:overflow-y-auto border-l border-border sm-scrollbar first:border-l-0"
121
121
  >
122
122
  <div className="w-[60px] absolute flex flex-col items-center py-2">
123
123
  {/* using absolute since the scrollbar takes up space */}
@@ -133,7 +133,7 @@ export function TimePicker({ value, onChange, className, tz, referenceTimestamp
133
133
  <button
134
134
  key={item}
135
135
  className={
136
- `${dayButtonClassName} rounded-full flex justify-center items-center group-hover:bg-gray-100 `
136
+ `${dayButtonClassName} rounded-full flex justify-center items-center group-hover:bg-muted `
137
137
  + (item === currentValue ? '!bg-input-border-focus text-white' : '')
138
138
  }
139
139
  >
@@ -118,7 +118,7 @@ export function Tooltip({
118
118
  <DefaultIcon
119
119
  size={14}
120
120
  tabIndex={0}
121
- className={twMerge('cursor-help outline-none', pinned ? 'text-primary' : 'text-[#9A9A9A]', iconClassName)}
121
+ className={twMerge('cursor-help outline-none', pinned ? 'text-primary-text' : 'text-[#9A9A9A]', iconClassName)}
122
122
  onClick={() => setPinned(p => !p)}
123
123
  />
124
124
  )}
@@ -128,7 +128,7 @@ export function Tooltip({
128
128
  role="tooltip"
129
129
  style={{ maxWidth, ...gap }}
130
130
  className={twMerge(
131
- 'absolute z-50 w-max px-4 py-3 rounded-lg bg-black text-white text-xs font-medium shadow-md',
131
+ 'absolute z-50 w-max px-4 py-3 rounded-lg bg-foreground text-background text-xs font-medium shadow-md',
132
132
  // interactive when pinned or hoverable so links/text/hover work, else click-through
133
133
  pinned || contentHoverable ? 'pointer-events-auto' : 'pointer-events-none',
134
134
  pos[actualSide],
@@ -75,7 +75,7 @@ export function Checkbox({
75
75
  checked={value}
76
76
  className={
77
77
  twMerge(
78
- `${type === 'radio' ? 'rounded-full' : 'rounded'} appearance-none border border-gray-300 bg-white forced-colors:appearance-auto disabled:border-gray-300 disabled:bg-gray-100 disabled:checked:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 ` +
78
+ `${type === 'radio' ? 'rounded-full' : 'rounded'} appearance-none border border-input-border bg-input-bg forced-colors:appearance-auto disabled:border-input-border disabled:bg-muted disabled:checked:bg-muted focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 ` +
79
79
  // Variable-selected theme colors (was .*-blue-600)
80
80
  'checked:border-variable-selected checked:bg-variable-selected indeterminate:border-variable-selected indeterminate:bg-variable-selected focus-visible:outline-variable-selected ' +
81
81
  // Dark mode not used yet... dark:focus-visible:outline-blue-800
@@ -131,7 +131,7 @@ export function Checkbox({
131
131
  style={{ width: toggleWidth, height: toggleHeight }}
132
132
  className={
133
133
  twMerge(
134
- 'block bg-gray-200 rounded-full transition-colors peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 p-2 ' +
134
+ 'block bg-muted rounded-full transition-colors peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 p-2 ' +
135
135
  // Variable-selected theme colors (was .*-blue-600)
136
136
  'peer-checked:bg-variable-selected peer-focus-visible:outline-variable-selected ' +
137
137
  labelClassName
@@ -141,7 +141,7 @@ export function Checkbox({
141
141
  <span
142
142
  style={{ width: toggleAfterSize, height: toggleAfterSize }}
143
143
  className={
144
- 'absolute top-[2px] start-[2px] bg-white border-gray-300 border rounded-full transition-all group-has-[:checked]:border-white group-has-[:checked]:translate-x-full '
144
+ 'absolute top-[2px] start-[2px] bg-white border-input-border border rounded-full transition-all group-has-[:checked]:border-white group-has-[:checked]:translate-x-full '
145
145
  }
146
146
  />
147
147
  </div>
@@ -151,8 +151,8 @@ export function Checkbox({
151
151
  </div>
152
152
  {text &&
153
153
  <div className="text-[length:inherit] leading-[inherit] select-none">
154
- <span className="text-gray-900">{text}</span>
155
- <span className="ml-2 text-gray-500">{subtext}</span>
154
+ <span className="text-foreground">{text}</span>
155
+ <span className="ml-2 text-muted-foreground">{subtext}</span>
156
156
  </div>
157
157
  }
158
158
  </label>
@@ -1,4 +1,5 @@
1
1
  // @ts-nocheck
2
+ import { Fragment } from 'react'
2
3
  import { deepFind, s3Image, getErrorFromState } from 'nitro-web/util'
3
4
  import { DropHandler } from 'nitro-web'
4
5
  import noImage from 'nitro-web/client/imgs/no-image.svg'
@@ -110,17 +111,17 @@ export function Drop({ awsUrl, className, id, name, onChange, multiple, state, e
110
111
  >
111
112
  {
112
113
  !value &&
113
- <>
114
+ <Fragment>
114
115
  {/* {todo upload svg here} */}
115
116
  <div>
116
117
  Drag and drop your file here&nbsp;
117
- <label class="weight-500 inline-block text-sm text-primary" for={inputId}>or select a file</label>
118
+ <label class="weight-500 inline-block text-sm text-primary-text" for={inputId}>or select a file</label>
118
119
  </div>
119
- </>
120
+ </Fragment>
120
121
  }
121
122
  {
122
123
  !!value &&
123
- <>
124
+ <Fragment>
124
125
  {
125
126
  urls.map((url, i) => (
126
127
  <div key={i} class="flex align-items-center gap-1">
@@ -130,9 +131,9 @@ export function Drop({ awsUrl, className, id, name, onChange, multiple, state, e
130
131
  }
131
132
  <div>
132
133
  Your file has been added successfully.&nbsp;
133
- <Link to="#" class="text-primary" onClick={tryAgain}>Use another file?</Link>
134
+ <Link to="#" class="text-primary-text" onClick={tryAgain}>Use another file?</Link>
134
135
  </div>
135
- </>
136
+ </Fragment>
136
137
  }
137
138
  </DropHandler>
138
139
  {error && <div class="form-error mt-0-5">{error.detail}</div>}
@@ -135,7 +135,7 @@ export function FieldCurrency({
135
135
  type="text"
136
136
  />
137
137
  <span
138
- class={`absolute top-0 bottom-0 inline-flex items-center select-none text-gray-500 text-input-base ${inputValue !== null && settings.prefix == '$' ? 'text-foreground' : ''}`}
138
+ class={`absolute top-0 bottom-0 inline-flex items-center select-none text-muted-foreground text-input-base ${inputValue !== null && settings.prefix == '$' ? 'text-foreground' : ''}`}
139
139
  style={{ left: `${inputPaddingLeft}px` }}
140
140
  >
141
141
  {settings.prefix}
@@ -217,7 +217,7 @@ export function FieldDate({
217
217
  // useffect in the timepicker will use the previous `value`
218
218
  value={getStringValue(props.value, props.defaultValue)}
219
219
  onChange={onChange<Timestamp>}
220
- className={`border-l border-gray-100 ${props.mode == 'single' ? 'min-h-[0]' : ''}`}
220
+ className={`border-l border-border ${props.mode == 'single' ? 'min-h-[0]' : ''}`}
221
221
  referenceTimestamp={referenceTimestamp}
222
222
  tz={tz}
223
223
  // _data={{ name: props.name }}
@@ -226,7 +226,7 @@ export function FieldDate({
226
226
  </div>
227
227
  {
228
228
  props.mode == 'time' &&
229
- <div className="flex justify-between p-2 border-t border-gray-100">
229
+ <div className="flex justify-between p-2 border-t border-border">
230
230
  <Button color="secondary" size="xs" onClick={() => onNowClick()}>Now</Button>
231
231
  <Button color="primary" size="xs" onClick={() => dropdownRef.current?.setIsActive(false)}>Done</Button>
232
232
  </div>
@@ -182,7 +182,7 @@ function getInputClasses({ error, Icon, iconPos, type }: { error?: Error, Icon?:
182
182
  const px = 'px-[12px]'
183
183
  const py = 'py-[9px] py-input-y'
184
184
  return (
185
- 'block col-start-1 row-start-1 w-full rounded-md bg-white disabled:cursor-not-allowed disabled:bg-input-disabled-bg text-input-base outline outline-1 -outline-offset-1 ' +
185
+ 'block col-start-1 row-start-1 w-full rounded-md bg-input-bg disabled:cursor-not-allowed disabled:bg-input-disabled-bg text-input-base outline outline-1 -outline-offset-1 ' +
186
186
  'placeholder:text-input-placeholder focus:outline focus:outline-2 focus:-outline-offset-2 (' +
187
187
  `${py} ${px} ` +
188
188
  (iconPos == 'right' && Icon ? 'pr-[32px] pr-input-x-icon pl-input-x ' : '') +
@@ -196,7 +196,7 @@ function getInputClasses({ error, Icon, iconPos, type }: { error?: Error, Icon?:
196
196
  (type == 'file'
197
197
  ? 'file:inline-flex file:shrink-0 file:cursor-pointer file:items-center file:justify-center ' +
198
198
  'file:rounded file:border-0 file:bg-transparent file:py-[0.1em] file:my-[-0.1em] file:px-[0.4em] file:ml-[-0.4em] file:mr-[0.7em] file:text-input-base file:font-medium file:text-input ' +
199
- 'file:outline-none file:bg-gray-100 hover:file:bg-gray-200 '
199
+ 'file:outline-none file:bg-muted hover:file:bg-border '
200
200
  : ''
201
201
  ) +
202
202
  'nitro-input'
@@ -449,7 +449,7 @@ function LimitedValueContainer({ chips, rest, maxLines, ...props }:
449
449
  <div ref={lastRow} class="w-full min-w-0 flex flex-nowrap items-center gap-1 overflow-hidden [&>*]:shrink-0">
450
450
  {chips.slice(split.upper, split.upper + split.last)}
451
451
  {hidden > 0 && (
452
- <span class="self-stretch flex items-center rounded bg-gray-100 text-gray-500 text-xs px-1.5 whitespace-nowrap">
452
+ <span class="self-stretch flex items-center rounded bg-muted text-muted-foreground text-xs px-1.5 whitespace-nowrap">
453
453
  +{hidden}
454
454
  </span>
455
455
  )}
@@ -491,7 +491,7 @@ function Option(props: OptionProps) {
491
491
  return (
492
492
  <components.Option className={data.className} {...props}>
493
493
  <span class="flex-auto min-w-0">{data.flag && <span className={flagClassName}>{data.flag}</span>}{data.IconLeft}{props.label}</span>
494
- {props.isSelected && <CheckCircleIcon className="flex-shrink-0 size-[22px] text-primary -my-1 -mx-0.5" />}
494
+ {props.isSelected && <CheckCircleIcon className="flex-shrink-0 size-[22px] text-primary-text -my-1 -mx-0.5" />}
495
495
  </components.Option>
496
496
  )
497
497
  }
@@ -541,7 +541,7 @@ const selectClassNames = {
541
541
  // Based off https://www.jussivirtanen.fi/writing/styling-react-select-with-tailwind
542
542
  // Input container
543
543
  control: {
544
- base: 'rounded-md bg-white hover:cursor-pointer text-input-base outline outline-1 -outline-offset-1 '
544
+ base: 'rounded-md bg-input-bg hover:cursor-pointer text-input-base outline outline-1 -outline-offset-1 '
545
545
  + '!min-h-0 outline-input-border',
546
546
  focus: 'outline-2 -outline-offset-2 outline-input-border-focus',
547
547
  error: 'outline-danger',
@@ -555,7 +555,7 @@ const selectClassNames = {
555
555
  },
556
556
  multiValue: 'bg-primary text-white rounded items-center pl-2 pr-1.5 gap-1.5',
557
557
  multiValueLabel: 'text-xs',
558
- multiValueRemove: 'border border-black/10 bg-clip-content bg-white rounded-md text-foreground hover:bg-red-50',
558
+ multiValueRemove: 'border border-border bg-clip-content bg-surface rounded-md text-foreground hover:bg-red-50',
559
559
  placeholder: 'text-input-placeholder truncate',
560
560
  singleValue: {
561
561
  base: 'text-input !overflow-visible min-w-0 flex items-center',
@@ -563,18 +563,18 @@ const selectClassNames = {
563
563
  disabled: 'text-input-disabled',
564
564
  },
565
565
  // Icon indicators
566
- clearIndicator: 'text-gray-500 p-1 rounded-md hover:bg-red-50 hover:text-danger-foreground ml-[-0.8em]',
567
- dropdownIndicator: 'p-1 hover:bg-gray-100 text-gray-500 rounded-md hover:text-black',
566
+ clearIndicator: 'text-muted-foreground p-1 rounded-md hover:bg-red-50 hover:text-danger-foreground ml-[-0.8em]',
567
+ dropdownIndicator: 'p-1 hover:bg-muted text-muted-foreground rounded-md hover:text-foreground',
568
568
  indicatorsContainer: 'p-1 pl-0 pr-2 gap-1 relative', // relative so the hitbox goes over the control
569
- indicatorSeparator: 'py-0.5 before:content-[""] before:block before:bg-gray-100 before:w-px before:h-full',
569
+ indicatorSeparator: 'py-0.5 before:content-[""] before:block before:bg-muted before:w-px before:h-full',
570
570
  // Dropdown menu
571
- menu: 'mt-1.5 border border-dropdown-ul-border bg-white rounded-md text-input-base overflow-hidden shadow-dropdown-ul',
572
- groupHeading: 'ml-3 mt-2 mb-1 text-gray-500 text-input-base',
573
- noOptionsMessage: 'm-1 text-gray-500 p-2 bg-gray-50 border border-dashed border-gray-200 rounded-sm',
571
+ menu: 'mt-1.5 border border-dropdown-ul-border bg-surface rounded-md text-input-base overflow-hidden shadow-dropdown-ul',
572
+ groupHeading: 'ml-3 mt-2 mb-1 text-muted-foreground text-input-base',
573
+ noOptionsMessage: 'm-1 text-muted-foreground p-2 bg-muted border border-dashed border-border rounded-sm',
574
574
  option: {
575
575
  base: 'relative px-3 py-2 !flex items-center gap-2 cursor-default',
576
- hover: 'bg-gray-50',
577
- selected: '!bg-gray-100 text-dropdown-selected-foreground',
576
+ hover: 'bg-muted',
577
+ selected: '!bg-muted text-dropdown-selected-foreground',
578
578
  },
579
579
  // Nitro specific
580
580
  flag: 'align-middle text-[1.2em] leading-[1em] mr-1.5 flex-shrink-0',
@@ -13,6 +13,7 @@ const allGroups = [
13
13
  'Links',
14
14
  'Dropdowns',
15
15
  'Filters',
16
+ 'Theme',
16
17
  'Button Colors & Sizes',
17
18
  'Button Icons',
18
19
  'Loading Elements',
@@ -340,6 +341,22 @@ export function Styleguide({ className, elements, children, currencies, groups }
340
341
  </div>
341
342
  )}
342
343
 
344
+ {visibleGroups.includes('Theme') && (
345
+ <div>
346
+ <h2 class="h3">Theme</h2>
347
+ <div class="flex flex-wrap gap-2 mb-6">
348
+ {['background', 'foreground', 'surface', 'muted', 'muted-foreground', 'border', 'input-bg', 'overlay'].map(token => (
349
+ <div
350
+ key={token}
351
+ class={`w-28 h-8 rounded-md border flex items-center px-2 text-xs bg-${token} ${token.match(/foreground|overlay/) ? 'text-background' : ''}`}
352
+ >
353
+ {token}
354
+ </div>
355
+ ))}
356
+ </div>
357
+ </div>
358
+ )}
359
+
343
360
  {visibleGroups.includes('Button Colors & Sizes') && (
344
361
  <div>
345
362
  <h2 class="h3">Button Colors & Sizes</h2>
@@ -831,9 +848,9 @@ export function Styleguide({ className, elements, children, currencies, groups }
831
848
 
832
849
  checkboxClassName="rounded-[2px] shadow-none"
833
850
  columnClassName="border-t-1 first:rounded-l-xl last:rounded-r-xl"
834
- columnHeaderClassName="text-gray-500 text-2xs uppercase border-none"
835
- columnSelectedClassName="bg-gray-50 border-indigo-300"
836
- rowClassName="[&:hover>div]:bg-gray-50"
851
+ columnHeaderClassName="text-muted-foreground text-2xs uppercase border-none"
852
+ columnSelectedClassName="bg-muted border-primary"
853
+ rowClassName="[&:hover>div]:bg-muted"
837
854
  tableClassName="rounded-3px"
838
855
  />
839
856
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-web",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "repository": "github:boycce/nitro-web",
5
5
  "homepage": "https://boycce.github.io/nitro-web/",
6
6
  "description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
@@ -18,6 +18,7 @@
18
18
  "./types": "./types.ts",
19
19
  "./.eslintrc.json": "./.eslintrc.json",
20
20
  "./tsconfig.json": "./tsconfig.json",
21
+ "./tailwind": "./tailwind.js",
21
22
  "./util": {
22
23
  "import": "./util.js",
23
24
  "types": "./types/util.d.ts"
package/tailwind.js ADDED
@@ -0,0 +1,75 @@
1
+ import plugin from 'tailwindcss/plugin'
2
+
3
+ /**
4
+ * Nitro theme plugin. Every key in light/dark becomes a CSS variable (:root / .dark) and a tailwind colour,
5
+ * e.g. 'surface' -> --surface, bg-surface, text-surface/50. Anything omitted uses the defaults below, and you
6
+ * can add your own keys.
7
+ * plugins: [nitroTheme({ dark: { 'primary-text': '#818cf8' } })]
8
+ */
9
+ export const themeDefaults = {
10
+ light: {
11
+ 'background': '#fdfdfd',
12
+ 'foreground': '#111827', // gray-900
13
+ 'surface': '#ffffff', // cards, sidebar, dropdowns, modals
14
+ 'muted': '#f9fafb', // hover rows, selected options (gray-50)
15
+ 'muted-foreground': '#6b7280', // gray-500
16
+ 'border': '#e5e7eb', // lines, gray-200
17
+ 'input-border': '#d1d5db', // gray-300
18
+ 'input-bg': '#ffffff',
19
+ 'input-disabled-bg': '#f3f4f6', // gray-100
20
+ 'overlay': '#6b7280', // used with opacity, e.g. bg-overlay/70
21
+ 'primary-text': undefined, // primary used as text, defaults to colors.primary
22
+ 'initials': ['#067306', '#aa33ff', '#ff54af', '#f44336', '#c03c3c', '#5451e0', '#d88c1b'], // <Initials /> palette
23
+ },
24
+ dark: {
25
+ 'background': '#09090b', // zinc-950
26
+ 'foreground': '#fafafa', // zinc-50
27
+ 'surface': '#18181b', // zinc-900
28
+ 'muted': '#27272a', // zinc-800
29
+ 'muted-foreground': '#a1a1aa', // zinc-400
30
+ 'border': '#3a3a40',
31
+ 'input-border': '#3a3a40',
32
+ 'input-bg': '#1c1c1f',
33
+ 'input-disabled-bg': '#27272a',
34
+ 'overlay': '#000000',
35
+ 'primary-text': undefined,
36
+ 'initials': ['#4ade80', '#c084fc', '#f472b6', '#f87171', '#fb923c', '#818cf8', '#facc15'],
37
+ },
38
+ }
39
+
40
+ // '#rgb' | '#rrggbb' | 'rgb(r, g, b)' -> 'r g b'
41
+ function channels(color) {
42
+ const hex = color.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)?.[1]
43
+ if (hex) {
44
+ const full = hex.length == 3 ? hex.split('').map(c => c + c).join('') : hex
45
+ return full.match(/../g).map(h => parseInt(h, 16)).join(' ')
46
+ }
47
+ const rgb = color.match(/\d+/g)
48
+ if (rgb?.length >= 3) return rgb.slice(0, 3).join(' ')
49
+ throw new Error(`nitroTheme: unsupported colour '${color}', use hex or rgb()`)
50
+ }
51
+
52
+ // Colour token that reads its variable, with tailwind opacity support
53
+ export const v = (name) => `rgb(var(--${name}) / <alpha-value>)`
54
+
55
+ export default function nitroTheme(options = {}) {
56
+ const keys = new Set([...Object.keys(themeDefaults.light), ...Object.keys(options.light || {}), ...Object.keys(options.dark || {})])
57
+ keys.delete('initials')
58
+ const colors = Object.fromEntries([...keys].map(key => [key, v(key)]))
59
+
60
+ return plugin(({ addBase, theme }) => {
61
+ const vars = (mode) => {
62
+ const t = { ...themeDefaults[mode], ...(options[mode] || {}) }
63
+ const out = { 'color-scheme': mode }
64
+ for (const [key, value] of Object.entries(t)) {
65
+ if (key == 'initials') value.forEach((c, i) => out[`--initials-${i + 1}`] = channels(c))
66
+ else if (key == 'primary-text') out['--primary-text'] = channels(value || theme('colors.primary'))
67
+ else out[`--${key}`] = channels(value)
68
+ }
69
+ return out
70
+ }
71
+ addBase({ ':root': vars('light'), '.dark': vars('dark') })
72
+ }, {
73
+ theme: { extend: { colors } },
74
+ })
75
+ }