nitro-web 0.0.195 → 0.0.196
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.
|
@@ -29,6 +29,8 @@ type FieldExtraProps = {
|
|
|
29
29
|
placeholder?: string
|
|
30
30
|
/** title used to find related error messages */
|
|
31
31
|
errorTitle?: string|RegExp
|
|
32
|
+
/** class names to override the default class names */
|
|
33
|
+
inputClassName?: string
|
|
32
34
|
}
|
|
33
35
|
type IconWrapperProps = {
|
|
34
36
|
iconPos: 'left' | 'right'
|
|
@@ -54,7 +56,7 @@ export const Field = memo(FieldBase, (prev, next) => {
|
|
|
54
56
|
return isFieldCached(prev, next)
|
|
55
57
|
})
|
|
56
58
|
|
|
57
|
-
function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProps) {
|
|
59
|
+
function FieldBase({ state, icon, iconPos: ip, errorTitle, inputClassName, ...props }: FieldProps) {
|
|
58
60
|
// `type` must be kept as props.type for TS to be happy and follow the conditions below
|
|
59
61
|
let value!: any
|
|
60
62
|
let Icon!: React.ReactNode
|
|
@@ -104,8 +106,9 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// Classname
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
+
const inputClasses = getInputClasses({ error, Icon, iconPos, type })
|
|
110
|
+
const inputClassName2 = inputClassName ? twMerge(inputClasses, inputClassName) : inputClasses.replaceAll(/\(|\)/g, '')
|
|
111
|
+
const commonProps = { id: id, value: value, className: inputClassName2 }
|
|
109
112
|
|
|
110
113
|
// Type has to be referenced as props.type for TS to be happy
|
|
111
114
|
if (!type || type == 'text' || type == 'number' || type == 'password' || type == 'email' || type == 'filter' || type == 'search') {
|
|
@@ -160,9 +163,11 @@ function getInputClasses({ error, Icon, iconPos, type }: { error?: Error, Icon?:
|
|
|
160
163
|
const py = 'py-[9px] py-input-y'
|
|
161
164
|
return (
|
|
162
165
|
'block col-start-1 row-start-1 w-full rounded-md bg-white disabled:bg-input-disabled-bg text-input-base outline outline-1 -outline-offset-1 ' +
|
|
163
|
-
'placeholder:text-input-placeholder focus:outline focus:outline-2 focus:-outline-offset-2 ' +
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
'placeholder:text-input-placeholder focus:outline focus:outline-2 focus:-outline-offset-2 (' +
|
|
167
|
+
`${py} ${px} ` +
|
|
168
|
+
(iconPos == 'right' && Icon ? 'pr-[32px] pr-input-x-icon pl-input-x ' : '') +
|
|
169
|
+
(iconPos == 'left' && Icon ? 'pl-[32px] pl-input-x-icon pr-input-x ' : 'px-input-x ') +
|
|
170
|
+
')' +
|
|
166
171
|
(iconPos == 'left' && Icon && type == 'color' ? 'indent-[5px] ' : '') +
|
|
167
172
|
(error
|
|
168
173
|
? 'text-danger-foreground outline-danger focus:outline-danger '
|
|
@@ -3,7 +3,7 @@ import { css } from 'twin.macro'
|
|
|
3
3
|
import { memo, useMemo, Fragment } from 'react'
|
|
4
4
|
import ReactSelect, {
|
|
5
5
|
components, ControlProps, createFilter, OptionProps, SingleValueProps, ClearIndicatorProps,
|
|
6
|
-
DropdownIndicatorProps, MultiValueRemoveProps, ClassNamesConfig,
|
|
6
|
+
DropdownIndicatorProps, MultiValueRemoveProps, // ClassNamesConfig,
|
|
7
7
|
ValueContainerProps,
|
|
8
8
|
} from 'react-select'
|
|
9
9
|
import { CheckCircleIcon } from '@heroicons/react/20/solid'
|
|
@@ -14,7 +14,6 @@ import { Errors } from 'nitro-web/types'
|
|
|
14
14
|
|
|
15
15
|
const filterFn = createFilter()
|
|
16
16
|
|
|
17
|
-
type NitroClassNamesConfig = ClassNamesConfig & { flag?: () => string }
|
|
18
17
|
type GetSelectClassName = {
|
|
19
18
|
name: string
|
|
20
19
|
isFocused?: boolean
|
|
@@ -308,7 +307,7 @@ const selectClassNames = {
|
|
|
308
307
|
error: 'outline-danger',
|
|
309
308
|
disabled: 'cursor-not-allowed bg-input-disabled-bg',
|
|
310
309
|
},
|
|
311
|
-
valueContainer: 'gap-1 py-[9px] px-[12px] py-input-y px-input-x', // dont twMerge (input-x is optional)
|
|
310
|
+
valueContainer: 'gap-1 (py-[9px] px-[12px] py-input-y px-input-x)', // dont twMerge (input-x is optional)
|
|
312
311
|
// Input container objects
|
|
313
312
|
input: {
|
|
314
313
|
base: 'text-input',
|
|
@@ -341,28 +340,29 @@ const selectClassNames = {
|
|
|
341
340
|
flag: 'align-middle text-[1.2em] leading-[1em] mr-1.5 flex-shrink-0',
|
|
342
341
|
} as const
|
|
343
342
|
|
|
344
|
-
type ClassNames =
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
343
|
+
type ClassNames = {
|
|
344
|
+
// Input container
|
|
345
|
+
control?: { base?: string, focus?: string, error?: string, disabled?: string }
|
|
346
|
+
valueContainer?: string
|
|
347
|
+
// Input container objects
|
|
348
|
+
input?: { base?: string, error?: string, disabled?: string }
|
|
349
|
+
multiValue?: string
|
|
350
|
+
multiValueLabel?: string
|
|
351
|
+
multiValueRemove?: string
|
|
352
|
+
placeholder?: string
|
|
353
|
+
singleValue?: { base?: string, error?: string, disabled?: string }
|
|
354
|
+
// Icon indicators
|
|
355
|
+
clearIndicator?: string
|
|
356
|
+
dropdownIndicator?: string
|
|
357
|
+
indicatorsContainer?: string
|
|
358
|
+
indicatorSeparator?: string
|
|
359
|
+
// Dropdown menu
|
|
360
|
+
menu?: string
|
|
361
|
+
groupHeading?: string
|
|
362
|
+
noOptionsMessage?: string
|
|
363
|
+
option?: { base?: string, hover?: string, selected?: string }
|
|
364
|
+
// Nitro specific
|
|
365
|
+
flag?: string
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
export function getSelectClassName({ name, isFocused, isSelected, isDisabled, hasError, usePrefixes, classNames }: GetSelectClassName) {
|
|
@@ -370,7 +370,9 @@ export function getSelectClassName({ name, isFocused, isSelected, isDisabled, ha
|
|
|
370
370
|
// @ts-expect-error
|
|
371
371
|
const obj = classNames?.[name] || selectClassNames[name]
|
|
372
372
|
let output = obj?.base
|
|
373
|
-
|
|
373
|
+
|
|
374
|
+
if (typeof obj == 'string' && obj.includes('(')) return obj.replaceAll(/\(|\)/g, '') // no modifiers & still has group wrappers
|
|
375
|
+
else if (typeof obj == 'string') return obj // no modifiers
|
|
374
376
|
|
|
375
377
|
if (usePrefixes) {
|
|
376
378
|
if (obj.focus) output += ' ' + obj.focus.split(' ').map((part: string) => `focus:${part}`).join(' ')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.196",
|
|
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 🚀",
|