nitro-web 0.3.16 → 0.3.18
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.
- package/.eslintrc.json +1 -0
- package/components/partials/element/dropdown.tsx +9 -3
- package/components/partials/element/filters.tsx +12 -4
- package/components/partials/element/table.tsx +4 -2
- package/components/partials/form/checkbox.tsx +1 -1
- package/components/partials/form/select.tsx +3 -3
- package/package.json +1 -1
- package/tailwind.js +7 -2
package/.eslintrc.json
CHANGED
|
@@ -192,8 +192,12 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
192
192
|
e.stopPropagation()
|
|
193
193
|
// Cancel parent <a> row navigation, unless a link INSIDE the menu was clicked
|
|
194
194
|
// (closest() doesn't stop at the ul, so check the matched link is contained within it)
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
// Only when there is a parent link, and never for form controls, whose default click toggles e.g. a checkbox
|
|
196
|
+
const target = e.target as HTMLElement
|
|
197
|
+
const link = target.closest('a[href]')
|
|
198
|
+
const hasParentLink = !!e.currentTarget.parentElement?.closest('a[href]')
|
|
199
|
+
const isControl = !!target.closest('input, label, select, textarea')
|
|
200
|
+
if (hasParentLink && !isControl && (!link || !e.currentTarget.contains(link))) e.preventDefault()
|
|
197
201
|
}}
|
|
198
202
|
style={{
|
|
199
203
|
minWidth: minWidth,
|
|
@@ -201,7 +205,9 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
201
205
|
...(maxHeight ? { overflow: 'auto' } : {}),
|
|
202
206
|
}}
|
|
203
207
|
class={twMerge(
|
|
204
|
-
|
|
208
|
+
// cursor-default: the menu shouldn't inherit the pointer from a clickable row it happens to sit in
|
|
209
|
+
`${menuStyle} ${ready ? 'is-ready' : ''} absolute invisible opacity-0 select-none outline-none cursor-default `
|
|
210
|
+
+ `min-w-full z-[1] ${menuClassName||''}`
|
|
205
211
|
)}
|
|
206
212
|
>
|
|
207
213
|
{menuContent}
|
|
@@ -56,6 +56,13 @@ export function Filters({
|
|
|
56
56
|
const [state, setState] = [stateProp || stateDefault, setStateProp || setStateDefault]
|
|
57
57
|
const count = useMemo(() => Object.keys(state).filter((k) => state[k] && filters?.some((f) => f.name === k)).length, [state, filters])
|
|
58
58
|
const pushChangesToPath = usePushChangesToPath(state)
|
|
59
|
+
const flushRef = useRef(false)
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// Only typing is debounced, everything else flushes here (not in the handler, the new state is only available after render)
|
|
63
|
+
if (flushRef.current) pushChangesToPath.flush()
|
|
64
|
+
flushRef.current = false
|
|
65
|
+
}, [state])
|
|
59
66
|
|
|
60
67
|
const Elements = {
|
|
61
68
|
Button: elements?.Button || Button,
|
|
@@ -84,16 +91,17 @@ export function Filters({
|
|
|
84
91
|
onAfterChange()
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
async function onInputChange(e: {target: {name: string, value: unknown}}) {
|
|
94
|
+
async function onInputChange(e: {target: {name: string, value: unknown}}, isTyping: boolean) {
|
|
88
95
|
// console.log('onInputChange', e.target.name, e.target.value)
|
|
89
96
|
// the state is flattened for the query string, so here we se full paths as the key names e.g. 'job.location': '10')
|
|
90
97
|
setState((s) => ({ ...s, [e.target.name]: e.target.value as unknown }))
|
|
91
|
-
onAfterChange()
|
|
98
|
+
onAfterChange(isTyping)
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
function onAfterChange() {
|
|
101
|
+
function onAfterChange(isTyping = false) {
|
|
95
102
|
setLastUpdated(Date.now())
|
|
96
103
|
pushChangesToPath()
|
|
104
|
+
flushRef.current = !isTyping
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
function getBasisWidth(width: 'full' | 'half' | 'third' | 'quarter' | 'fifth') {
|
|
@@ -160,7 +168,7 @@ export function Filters({
|
|
|
160
168
|
{
|
|
161
169
|
filters?.map(({label, width='full', rowClassName, ...filter}, i) => {
|
|
162
170
|
// `filter.name` is a full path e.g. 'job.location', not just the key `location`
|
|
163
|
-
const common = { className: '!mb-0', onChange: onInputChange
|
|
171
|
+
const common = { className: '!mb-0', onChange: (e: {target: {name: string, value: unknown}}) => onInputChange(e, filter.type !== 'select') }
|
|
164
172
|
return (
|
|
165
173
|
<div key={i} class={twMerge(getBasisWidth(width), rowClassName || '')}>
|
|
166
174
|
<div class="flex justify-between">
|
|
@@ -37,7 +37,7 @@ export type TableProps<T> = {
|
|
|
37
37
|
rowLinesMax?: number
|
|
38
38
|
rowSideColor?: (row: T|undefined, type: TableRowType) => { className: string, width: number }
|
|
39
39
|
rowGap?: number
|
|
40
|
-
rowOnClick?: (row: T) => void
|
|
40
|
+
rowOnClick?: (row: T, e: React.MouseEvent) => void // the event lets a caller tell a field click from a row click
|
|
41
41
|
rowSelectable?: (row: T) => boolean // rows returning false get no checkbox and are skipped by select all
|
|
42
42
|
rowLink?: (row: T) => string
|
|
43
43
|
columnGap?: number
|
|
@@ -260,7 +260,9 @@ export function Table<T extends TableRow>({
|
|
|
260
260
|
rowsToRender.map((row: T, i: number) => {
|
|
261
261
|
const isSelected = selectedRowIds.includes(row._id || '')
|
|
262
262
|
const Element = (rowLink ? Link : 'div') as React.ElementType
|
|
263
|
-
const extraProps = rowLink
|
|
263
|
+
const extraProps = rowLink
|
|
264
|
+
? { to: rowLink(row) }
|
|
265
|
+
: { onClick: rowOnClick ? (e: React.MouseEvent) => rowOnClick(row, e) : undefined }
|
|
264
266
|
return (
|
|
265
267
|
<Element
|
|
266
268
|
{...extraProps}
|
|
@@ -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-input-border bg-
|
|
78
|
+
`${type === 'radio' ? 'rounded-full' : 'rounded'} appearance-none border border-input-border bg-checkbox-bg forced-colors:appearance-auto disabled:border-input-border disabled:bg-input-disabled-bg disabled:checked:bg-input-disabled-bg 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
|
|
@@ -343,7 +343,7 @@ function SelectBase<IsMulti extends boolean = false>({
|
|
|
343
343
|
},
|
|
344
344
|
} : {})}
|
|
345
345
|
/>
|
|
346
|
-
{error && <div class="mt-1.5 text-xs text-danger-foreground">{error.detail}</div>}
|
|
346
|
+
{error && <div class="mt-1.5 text-xs text-danger-foreground nitro-error">{error.detail}</div>}
|
|
347
347
|
</div>
|
|
348
348
|
)
|
|
349
349
|
}
|
|
@@ -563,10 +563,10 @@ const selectClassNames = {
|
|
|
563
563
|
disabled: 'text-input-disabled',
|
|
564
564
|
},
|
|
565
565
|
// Icon indicators
|
|
566
|
-
clearIndicator: 'text-muted-foreground p-1 rounded-md hover:bg-
|
|
566
|
+
clearIndicator: 'text-muted-foreground p-1 rounded-md hover:bg-danger/10 hover:text-danger-foreground ml-[-0.8em]',
|
|
567
567
|
dropdownIndicator: 'p-1 hover:bg-accent 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-
|
|
569
|
+
indicatorSeparator: 'py-0.5 before:content-[""] before:block before:bg-input-separator before:w-px before:h-full',
|
|
570
570
|
// Dropdown menu
|
|
571
571
|
menu: 'mt-1.5 border border-dropdown-ul-border bg-surface rounded-md text-input-base overflow-hidden shadow-dropdown-ul',
|
|
572
572
|
groupHeading: 'ml-3 mt-2 mb-1 text-muted-foreground text-input-base',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
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 🚀",
|
package/tailwind.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import plugin from 'tailwindcss/plugin'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Nitro theme plugin. Every key in light/dark becomes a CSS variable (:root / .dark) and a tailwind colour,
|
|
4
|
+
* Nitro theme plugin. Every key in light/dark becomes a CSS variable (:root and .light / .dark) and a tailwind colour,
|
|
5
5
|
* e.g. 'surface' -> --surface, bg-surface, text-surface/50. Anything omitted uses the defaults below, and you
|
|
6
6
|
* can add your own keys.
|
|
7
7
|
* plugins: [nitroTheme({ dark: { 'primary-text': '#818cf8' } })]
|
|
@@ -19,7 +19,9 @@ export const themeDefaults = {
|
|
|
19
19
|
'input-placeholder': '#9ca3af', // gray-400
|
|
20
20
|
'input-disabled': '#9ca3af',
|
|
21
21
|
'input-bg': '#ffffff',
|
|
22
|
+
'input-separator': '#f3f4f6', // select divider before the arrow (gray-100)
|
|
22
23
|
'input-disabled-bg': '#f3f4f6', // gray-100
|
|
24
|
+
'checkbox-bg': '#ffffff',
|
|
23
25
|
'overlay': '#6b7280', // used with opacity, e.g. bg-overlay/70
|
|
24
26
|
'primary-text': undefined, // primary used as text, defaults to colors.primary
|
|
25
27
|
'initials': ['#067306', '#aa33ff', '#ff54af', '#f44336', '#c03c3c', '#5451e0', '#d88c1b'], // <Initials /> palette
|
|
@@ -36,7 +38,9 @@ export const themeDefaults = {
|
|
|
36
38
|
'input-placeholder': '#71717a', // zinc-500
|
|
37
39
|
'input-disabled': '#71717a',
|
|
38
40
|
'input-bg': '#1c1c1f',
|
|
41
|
+
'input-separator': '#303035',
|
|
39
42
|
'input-disabled-bg': '#27272a',
|
|
43
|
+
'checkbox-bg': '#1c1c1f',
|
|
40
44
|
'overlay': '#000000',
|
|
41
45
|
'primary-text': undefined,
|
|
42
46
|
'initials': ['#4ade80', '#c084fc', '#f472b6', '#f87171', '#fb923c', '#818cf8', '#facc15'],
|
|
@@ -74,7 +78,8 @@ export default function nitroTheme(options = {}) {
|
|
|
74
78
|
}
|
|
75
79
|
return out
|
|
76
80
|
}
|
|
77
|
-
|
|
81
|
+
// .light lets a light area sit inside a dark one, e.g. a white menu in a dark row
|
|
82
|
+
addBase({ ':root, .light': vars('light'), '.dark': vars('dark') })
|
|
78
83
|
}, {
|
|
79
84
|
theme: { extend: { colors } },
|
|
80
85
|
})
|