nitro-web 0.0.112 → 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.
@@ -309,6 +309,7 @@ export async function getStore(user) {
309
309
 
310
310
  export async function signinAndGetStore(user, isDesktop, getStore) {
311
311
  if (user.loginActive === false) throw 'This user is not available.'
312
+ if (!getStore) throw new Error('Please provide a getStore function')
312
313
  user.desktop = isDesktop
313
314
 
314
315
  const jwt = jsonwebtoken.sign({ _id: user._id }, JWT_SECRET, { expiresIn: '30d' })
@@ -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
 
@@ -14,6 +14,7 @@ export interface TableColumn {
14
14
  /** Use if the value is different from the sortBy */
15
15
  sortByValue?: string
16
16
  align?: 'left' | 'center' | 'right'
17
+ isHidden?: boolean
17
18
  }
18
19
 
19
20
  export type TableRow = {
@@ -83,6 +84,7 @@ export function Table<T extends TableRow>({
83
84
  rowLinesMax: typeof col.rowLinesMax != 'undefined' ? col.rowLinesMax : rowLinesMax,
84
85
  sortByValue: col.sortByValue || col.value,
85
86
  align: col.align || 'left',
87
+ isHidden: col.isHidden ?? false,
86
88
  }))
87
89
  return cols
88
90
  }, [columnsProp])
@@ -139,6 +141,8 @@ export function Table<T extends TableRow>({
139
141
  const sideColorPadding = sideColor && rows.length > 0 ? sideColor.width + 5 : 0
140
142
  const pl = sideColorPadding + (j == 0 ? columnPaddingX : columnGap)
141
143
  const pr = j == columns.length - 1 ? columnPaddingX : columnGap
144
+
145
+ if (col.isHidden) return <Fragment key={j} />
142
146
  return (
143
147
  <div
144
148
  key={j}
@@ -209,6 +213,7 @@ export function Table<T extends TableRow>({
209
213
  return (
210
214
  <div
211
215
  key={`${row._id}-${i}`}
216
+ id={`row-${row._id}-${i}`}
212
217
  onClick={rowOnClick ? () => rowOnClick(row) : undefined}
213
218
  className={twMerge(
214
219
  `table-row relative ${rowOnClick ? 'cursor-pointer' : ''} ${isSelected ? 'is-selected' : ''}`, rowClassName
@@ -219,6 +224,8 @@ export function Table<T extends TableRow>({
219
224
  const sideColor = j == 0 && rowSideColor ? rowSideColor(row) : undefined
220
225
  const pl = j == 0 ? columnPaddingX : columnGap
221
226
  const pr = j == columns.length - 1 ? columnPaddingX : columnGap
227
+
228
+ if (col.isHidden) return <Fragment key={j} />
222
229
  return (
223
230
  <div
224
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.112",
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 🚀",
@@ -1 +1 @@
1
- {"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAmQA,qGAyCC;AAED;;GAKC;AAED,0FAOC;AAED;;;;iBAkDC;AAED,mDAOC;AAED,4CAYC;AAED,kFAiBC;AA5YD;;;;;;;;;;;;;;;;;;EAqBC;AAmED,0DAEC;AAkCD,mDAEC;AAnBD,iDAeC;AA9BD,2DAaC;AAuBD,sEAuBC;AAED,kEAuBC;AAED,sEAqCC;AAED,2DAwBC;AA1ND,4DA+DC"}
1
+ {"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAmQA,qGAyCC;AAED;;GAKC;AAED,0FAQC;AAED;;;;iBAkDC;AAED,mDAOC;AAED,4CAYC;AAED,kFAiBC;AA7YD;;;;;;;;;;;;;;;;;;EAqBC;AAmED,0DAEC;AAkCD,mDAEC;AAnBD,iDAeC;AA9BD,2DAaC;AAuBD,sEAuBC;AAED,kEAuBC;AAED,sEAqCC;AAED,2DAwBC;AA1ND,4DA+DC"}