nitro-web 0.0.113 → 0.0.114
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.
|
@@ -17,6 +17,8 @@ type DropdownProps = {
|
|
|
17
17
|
isSelected?: boolean,
|
|
18
18
|
icon?: React.ReactNode,
|
|
19
19
|
iconLeft?: React.ReactNode,
|
|
20
|
+
/** Prevent the dropdown from closing when the option is clicked */
|
|
21
|
+
preventCloseOnClick?: boolean,
|
|
20
22
|
className?: string
|
|
21
23
|
}[]
|
|
22
24
|
/** Whether the dropdown is hoverable **/
|
|
@@ -25,6 +27,7 @@ type DropdownProps = {
|
|
|
25
27
|
menuContent?: React.ReactNode
|
|
26
28
|
menuClassName?: string
|
|
27
29
|
menuOptionClassName?: string
|
|
30
|
+
/** force open the menu */
|
|
28
31
|
menuIsOpen?: boolean
|
|
29
32
|
menuToggles?: boolean
|
|
30
33
|
/** The minimum width of the menu **/
|
|
@@ -137,9 +140,9 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
137
140
|
if (!isHoverable && !menuIsOpen && ((menuToggles || e.key) || !isActive)) setIsActive(!isActive)
|
|
138
141
|
}
|
|
139
142
|
|
|
140
|
-
function onClick(option: { onClick?: Function }, e: React.MouseEvent) {
|
|
143
|
+
function onClick(option: { onClick?: Function, preventCloseOnClick?: boolean }, e: React.MouseEvent) {
|
|
141
144
|
if (option.onClick) option.onClick(e)
|
|
142
|
-
if (!menuIsOpen) setIsActive(!isActive)
|
|
145
|
+
if (!menuIsOpen && !option?.preventCloseOnClick) setIsActive(!isActive)
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSX, useState, useCallback } from 'react'
|
|
1
|
+
import { JSX, useState, useCallback, Fragment } from 'react'
|
|
2
2
|
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
|
3
3
|
import { Checkbox, queryObject, queryString, twMerge } from 'nitro-web'
|
|
4
4
|
|
|
@@ -142,7 +142,7 @@ export function Table<T extends TableRow>({
|
|
|
142
142
|
const pl = sideColorPadding + (j == 0 ? columnPaddingX : columnGap)
|
|
143
143
|
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
144
144
|
|
|
145
|
-
if(col.isHidden) return
|
|
145
|
+
if (col.isHidden) return <Fragment key={j} />
|
|
146
146
|
return (
|
|
147
147
|
<div
|
|
148
148
|
key={j}
|
|
@@ -213,6 +213,7 @@ export function Table<T extends TableRow>({
|
|
|
213
213
|
return (
|
|
214
214
|
<div
|
|
215
215
|
key={`${row._id}-${i}`}
|
|
216
|
+
id={`row-${row._id}-${i}`}
|
|
216
217
|
onClick={rowOnClick ? () => rowOnClick(row) : undefined}
|
|
217
218
|
className={twMerge(
|
|
218
219
|
`table-row relative ${rowOnClick ? 'cursor-pointer' : ''} ${isSelected ? 'is-selected' : ''}`, rowClassName
|
|
@@ -224,7 +225,7 @@ export function Table<T extends TableRow>({
|
|
|
224
225
|
const pl = j == 0 ? columnPaddingX : columnGap
|
|
225
226
|
const pr = j == columns.length - 1 ? columnPaddingX : columnGap
|
|
226
227
|
|
|
227
|
-
if(col.isHidden) return
|
|
228
|
+
if (col.isHidden) return <Fragment key={j} />
|
|
228
229
|
return (
|
|
229
230
|
<div
|
|
230
231
|
key={j}
|
|
@@ -7,7 +7,7 @@ import { Errors, type Error } from 'nitro-web/types'
|
|
|
7
7
|
import { MailIcon, CalendarIcon, FunnelIcon, SearchIcon, EyeIcon, EyeOffIcon } from 'lucide-react'
|
|
8
8
|
import { memo } from 'react'
|
|
9
9
|
|
|
10
|
-
type FieldType = 'text' | 'password' | 'email' | 'filter' | 'search' | 'textarea' | 'currency' | 'date' | 'color'
|
|
10
|
+
type FieldType = 'text' | 'number' | 'password' | 'email' | 'filter' | 'search' | 'textarea' | 'currency' | 'date' | 'color'
|
|
11
11
|
type InputProps = React.InputHTMLAttributes<HTMLInputElement>
|
|
12
12
|
type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
13
13
|
type FieldExtraProps = {
|
|
@@ -35,7 +35,7 @@ type IconWrapperProps = {
|
|
|
35
35
|
}
|
|
36
36
|
// Discriminated union (https://stackoverflow.com/a/77351290/1900648)
|
|
37
37
|
export type FieldProps = (
|
|
38
|
-
| ({ type?: 'text' | 'password' | 'email' | 'filter' | 'search' } & InputProps & FieldExtraProps)
|
|
38
|
+
| ({ type?: 'text' | 'number' | 'password' | 'email' | 'filter' | 'search' } & InputProps & FieldExtraProps)
|
|
39
39
|
| ({ type: 'textarea' } & TextareaProps & FieldExtraProps)
|
|
40
40
|
| ({ type: 'currency' } & FieldCurrencyProps & FieldExtraProps)
|
|
41
41
|
| ({ type: 'color' } & FieldColorProps & FieldExtraProps)
|
|
@@ -67,7 +67,7 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
67
67
|
|
|
68
68
|
// Input type
|
|
69
69
|
const [inputType, setInputType] = useState(() => { // eslint-disable-line
|
|
70
|
-
return type == 'password' ? 'password' : (type == 'textarea' ? 'textarea' : 'text')
|
|
70
|
+
return type == 'password' ? 'password' : (type == 'textarea' ? 'textarea' : (type == 'number' ? 'number' : 'text'))
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
// Value: Input is always controlled if state is passed in
|
|
@@ -76,7 +76,7 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
76
76
|
const v = deepFind(state, props.name) as string | undefined
|
|
77
77
|
value = v ?? ''
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
// Icon
|
|
81
81
|
if (type == 'password') {
|
|
82
82
|
Icon = <IconWrapper
|
|
@@ -104,7 +104,7 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
104
104
|
const commonProps = { id: id, value: value, className: inputClassName }
|
|
105
105
|
|
|
106
106
|
// Type has to be referenced as props.type for TS to be happy
|
|
107
|
-
if (!type || type == 'text' || type == 'password' || type == 'email' || type == 'filter' || type == 'search') {
|
|
107
|
+
if (!type || type == 'text' || type == 'number' || type == 'password' || type == 'email' || type == 'filter' || type == 'search') {
|
|
108
108
|
return (
|
|
109
109
|
<FieldContainer error={error} className={props.className}>
|
|
110
110
|
{Icon}<input {...props} {...commonProps} type={inputType} />
|
|
@@ -412,6 +412,10 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
412
412
|
</div>
|
|
413
413
|
<Field name="password" type="password"/>
|
|
414
414
|
</div>
|
|
415
|
+
<div>
|
|
416
|
+
<label for="search3number">Number</label>
|
|
417
|
+
<Field name="number" id="search3number" type="number" placeholder="Number..." />
|
|
418
|
+
</div>
|
|
415
419
|
<div>
|
|
416
420
|
<label for="search3">Search</label>
|
|
417
421
|
<Field name="search" id="search3" type="search" placeholder="Search..." />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.114",
|
|
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 🚀",
|