nitro-web 0.0.145 → 0.0.147
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/client/index.ts +5 -5
- package/components/partials/element/calendar.tsx +63 -40
- package/components/partials/element/filters.tsx +98 -69
- package/components/partials/element/timepicker.tsx +119 -0
- package/components/partials/form/field-color.tsx +27 -19
- package/components/partials/form/field-currency.tsx +108 -102
- package/components/partials/form/field-date.tsx +167 -93
- package/components/partials/form/field.tsx +16 -29
- package/components/partials/styleguide.tsx +94 -40
- package/package.json +3 -4
- package/types/util.d.ts +3 -8
- package/types/util.d.ts.map +1 -1
- package/util.js +9 -24
- package/components/partials/form/field-time.tsx +0 -214
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
// fill-current tw class for lucide icons (https://github.com/lucide-icons/lucide/discussions/458)
|
|
3
3
|
import { css } from 'twin.macro'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { type FieldColorProps, FieldColor } from './field-color'
|
|
5
|
+
import { type FieldCurrencyProps, FieldCurrency } from './field-currency'
|
|
6
|
+
import { type FieldDateProps, FieldDate } from './field-date'
|
|
6
7
|
import { twMerge, getErrorFromState, deepFind } from 'nitro-web/util'
|
|
7
8
|
import { Errors, type Error } from 'nitro-web/types'
|
|
8
9
|
import { MailIcon, CalendarIcon, FunnelIcon, SearchIcon, EyeIcon, EyeOffIcon, ClockIcon } from 'lucide-react'
|
|
9
10
|
import { memo } from 'react'
|
|
10
11
|
|
|
11
|
-
type FieldType = 'text' | 'number' | 'password' | 'email' | 'filter' | 'search' | 'textarea' | 'currency' | 'date' | 'color'
|
|
12
|
+
type FieldType = 'text' | 'number' | 'password' | 'email' | 'filter' | 'search' | 'textarea' | 'currency' | 'date' | 'color'
|
|
12
13
|
type InputProps = React.InputHTMLAttributes<HTMLInputElement>
|
|
13
14
|
type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
14
15
|
type FieldExtraProps = {
|
|
@@ -41,8 +42,6 @@ export type FieldProps = (
|
|
|
41
42
|
| ({ type: 'currency' } & FieldCurrencyProps & FieldExtraProps)
|
|
42
43
|
| ({ type: 'color' } & FieldColorProps & FieldExtraProps)
|
|
43
44
|
| ({ type: 'date' } & FieldDateProps & FieldExtraProps)
|
|
44
|
-
| ({ type: 'time' } & FieldTimeProps & FieldExtraProps)
|
|
45
|
-
// | ({ type: 'time2' } & FieldTimeProps2 & FieldExtraProps)
|
|
46
45
|
)
|
|
47
46
|
type IsFieldCachedProps = {
|
|
48
47
|
name: string
|
|
@@ -57,7 +56,7 @@ export const Field = memo(FieldBase, (prev, next) => {
|
|
|
57
56
|
|
|
58
57
|
function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProps) {
|
|
59
58
|
// `type` must be kept as props.type for TS to be happy and follow the conditions below
|
|
60
|
-
let value!:
|
|
59
|
+
let value!: any
|
|
61
60
|
let Icon!: React.ReactNode
|
|
62
61
|
const error = getErrorFromState(state, errorTitle || props.name)
|
|
63
62
|
const type = props.type
|
|
@@ -74,10 +73,10 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
74
73
|
})
|
|
75
74
|
|
|
76
75
|
// Value: Input is always controlled if state is passed in
|
|
77
|
-
if (typeof props.value !== 'undefined') value = props.value
|
|
76
|
+
if (typeof props.value !== 'undefined') value = props.value
|
|
78
77
|
else if (typeof state == 'object') {
|
|
79
|
-
const v = deepFind(state, props.name)
|
|
80
|
-
value = v
|
|
78
|
+
const v = deepFind(state, props.name) ?? ''
|
|
79
|
+
value = v
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
// Icon
|
|
@@ -96,10 +95,10 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
96
95
|
Icon = <IconWrapper iconPos={iconPos} icon={icon || <SearchIcon />} className="size-[14px] size-input-icon" />
|
|
97
96
|
} else if (type == 'color') {
|
|
98
97
|
Icon = <IconWrapper iconPos={iconPos} icon={icon || <ColorSvg hex={value}/>} className="size-[17px]" />
|
|
98
|
+
} else if (type == 'date' && props.mode == 'time') {
|
|
99
|
+
Icon = <IconWrapper iconPos={iconPos} icon={icon || <ClockIcon />} className="size-[14px] size-input-icon" />
|
|
99
100
|
} else if (type == 'date') {
|
|
100
101
|
Icon = <IconWrapper iconPos={iconPos} icon={icon || <CalendarIcon />} className="size-[14px] size-input-icon" />
|
|
101
|
-
} else if (type == 'time') {
|
|
102
|
-
Icon = <IconWrapper iconPos={iconPos} icon={icon || <ClockIcon />} className="size-[14px] size-input-icon" />
|
|
103
102
|
} else if (icon) {
|
|
104
103
|
Icon = <IconWrapper iconPos={iconPos} icon={icon} className="size-[14px] size-input-icon" />
|
|
105
104
|
}
|
|
@@ -121,44 +120,32 @@ function FieldBase({ state, icon, iconPos: ip, errorTitle, ...props }: FieldProp
|
|
|
121
120
|
{Icon}<textarea {...props} {...commonProps} />
|
|
122
121
|
</FieldContainer>
|
|
123
122
|
)
|
|
124
|
-
} else if (type == 'currency') {
|
|
125
|
-
return (
|
|
126
|
-
<FieldContainer error={error} className={props.className}>
|
|
127
|
-
{Icon}<FieldCurrency {...props} {...commonProps} />
|
|
128
|
-
</FieldContainer>
|
|
129
|
-
)
|
|
130
123
|
} else if (type == 'color') {
|
|
131
124
|
return (
|
|
132
125
|
<FieldContainer error={error} className={props.className}>
|
|
133
126
|
<FieldColor {...props} {...commonProps} Icon={Icon} />
|
|
134
127
|
</FieldContainer>
|
|
135
128
|
)
|
|
136
|
-
} else if (type == '
|
|
129
|
+
} else if (type == 'currency') {
|
|
137
130
|
return (
|
|
138
131
|
<FieldContainer error={error} className={props.className}>
|
|
139
|
-
<
|
|
132
|
+
{Icon}<FieldCurrency {...props} {...commonProps} />
|
|
140
133
|
</FieldContainer>
|
|
141
134
|
)
|
|
142
|
-
} else if (type == '
|
|
135
|
+
} else if (type == 'date') {
|
|
143
136
|
return (
|
|
144
137
|
<FieldContainer error={error} className={props.className}>
|
|
145
|
-
<
|
|
138
|
+
<FieldDate {...props} {...commonProps} Icon={Icon} />
|
|
146
139
|
</FieldContainer>
|
|
147
140
|
)
|
|
148
|
-
}
|
|
149
|
-
// else if (type == 'time2') {
|
|
150
|
-
// return (
|
|
151
|
-
// <FieldContainer error={error} className={props.className}>
|
|
152
|
-
// <FieldTime2 {...props} {...commonProps} Icon={Icon} />
|
|
153
|
-
// </FieldContainer>
|
|
154
|
-
// )
|
|
155
|
-
// }
|
|
141
|
+
}
|
|
156
142
|
}
|
|
157
143
|
|
|
158
144
|
function FieldContainer({ children, className, error }: { children: React.ReactNode, className?: string, error?: Error }) {
|
|
159
145
|
return (
|
|
160
146
|
<div
|
|
161
147
|
css={style}
|
|
148
|
+
// todo: add (mt-2.5 mb-6 mt-input-before mb-input-after) as export? fieldSpacing?
|
|
162
149
|
className={twMerge('(mt-2.5 mb-6 mt-input-before mb-input-after) grid grid-cols-1 nitro-field', className || '')}
|
|
163
150
|
>
|
|
164
151
|
{children}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Drop, Dropdown, Field, Select, Button as ButtonNitro, Checkbox, GithubLink, Modal, Calendar, injectedConfig,
|
|
3
|
-
Filters, FiltersHandleType, FilterType, Table, TableColumn,
|
|
2
|
+
Drop, Dropdown, Field, Select, Button as ButtonNitro, Checkbox, GithubLink, Modal, Calendar, injectedConfig, TimePicker,
|
|
3
|
+
Filters, FiltersHandleType, FilterType, Table, TableColumn, usePushChangesToPath,
|
|
4
4
|
} from 'nitro-web'
|
|
5
5
|
import { date, getCountryOptions, getCurrencyOptions, onChange, ucFirst } from 'nitro-web/util'
|
|
6
6
|
import { Check, EllipsisVerticalIcon, FileEditIcon } from 'lucide-react'
|
|
@@ -35,6 +35,7 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
35
35
|
const [, setStore] = useTracked()
|
|
36
36
|
const [customerSearch, setCustomerSearch] = useState('')
|
|
37
37
|
const [showModal1, setShowModal1] = useState(false)
|
|
38
|
+
|
|
38
39
|
// Tip: handy when developing or updating components, you can hide/show the groups you want to see
|
|
39
40
|
const groups = [
|
|
40
41
|
'Links',
|
|
@@ -45,32 +46,65 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
45
46
|
'Selects',
|
|
46
47
|
'Inputs',
|
|
47
48
|
'Date Inputs',
|
|
48
|
-
'File Inputs & Calendar',
|
|
49
|
+
'File Inputs & Calendar & Time',
|
|
49
50
|
'Tables',
|
|
50
51
|
'Modals',
|
|
51
52
|
'Custom Components',
|
|
52
53
|
]
|
|
53
|
-
const [state, setState] = useState(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
const [state, setState] = useState(() => getState())
|
|
55
|
+
|
|
56
|
+
function getState(useOldValues?: boolean) {
|
|
57
|
+
return !useOldValues ? {
|
|
58
|
+
address: '',
|
|
59
|
+
amount: 100,
|
|
60
|
+
brandColor: '#F3CA5F',
|
|
61
|
+
colorsMulti: ['blue', 'green'],
|
|
62
|
+
country: 'nz',
|
|
63
|
+
currency: 'nzd',
|
|
64
|
+
date: Date.now(),
|
|
65
|
+
'date-range': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 33],
|
|
66
|
+
'date-multiple': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 2],
|
|
67
|
+
'date-time': Date.now(),//////
|
|
68
|
+
time: Date.now(),
|
|
69
|
+
'calendar-single': Date.now(),
|
|
70
|
+
'calendar-range': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 8],
|
|
71
|
+
firstName: 'Bruce',
|
|
72
|
+
tableFilter: '',
|
|
73
|
+
errors: [
|
|
74
|
+
{ title: 'address', detail: 'Address is required' },
|
|
75
|
+
],
|
|
76
|
+
} : {
|
|
77
|
+
address: '',
|
|
78
|
+
amount: 200,
|
|
79
|
+
brandColor: '#8656ED',
|
|
80
|
+
colorsMulti: ['blue'],
|
|
81
|
+
country: 'au',
|
|
82
|
+
currency: 'btc',
|
|
83
|
+
date: Date.now() + 1000 * 60 * 60 * 24 * 1.2,
|
|
84
|
+
'date-range': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 5.2],
|
|
85
|
+
'date-multiple': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 3.2],
|
|
86
|
+
'date-time': Date.now() + 1000 * 60 * 60 * 24 * 2.2,
|
|
87
|
+
time: Date.now() + 1000 * 60 * 60 * 1.2,
|
|
88
|
+
'calendar-single': Date.now(),
|
|
89
|
+
'calendar-range': [Date.now(), Date.now() + 1000 * 60 * 60 * 24 * 3.2],
|
|
90
|
+
firstName: 'John',
|
|
91
|
+
tableFilter: '',
|
|
92
|
+
errors: [
|
|
93
|
+
{ title: 'address', detail: 'Address is required' },
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function indirectlyChangeTheState() {
|
|
99
|
+
// Change the state indirectly to test the inputs reactivity
|
|
100
|
+
setState((s: typeof state) => {
|
|
101
|
+
if (s.firstName == 'Bruce') return getState(true)
|
|
102
|
+
else return getState(false)
|
|
103
|
+
})
|
|
104
|
+
}
|
|
71
105
|
|
|
72
106
|
const [filterState, setFilterState] = useState({})
|
|
73
|
-
const
|
|
107
|
+
const pushChangesToPath = usePushChangesToPath(filterState)
|
|
74
108
|
const filters = useMemo(() => {
|
|
75
109
|
const filters: FilterType[] = [
|
|
76
110
|
{
|
|
@@ -200,7 +234,7 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
200
234
|
<h1 class="h1">{injectedConfig.isDemo ? 'Design System' : 'Style Guide'}</h1>
|
|
201
235
|
<p class="mb-3">
|
|
202
236
|
Components are styled using
|
|
203
|
-
<a href="https://v3.tailwindcss.com/docs/configuration" class="underline" target="_blank" rel="noreferrer">TailwindCSS</a>.
|
|
237
|
+
<a href="https://v3.tailwindcss.com/docs/configuration" class="underline" target="_blank" rel="noreferrer">TailwindCSS</a>. {injectedConfig.isDemo && <><a href="#" class="underline" onClick={indirectlyChangeTheState}>Click here</a> to indirectly change the state</>}
|
|
204
238
|
</p>
|
|
205
239
|
</div>
|
|
206
240
|
|
|
@@ -248,8 +282,7 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
248
282
|
<h2 class="h3">Filters</h2>
|
|
249
283
|
<div class="flex flex-wrap gap-x-6 gap-y-4 mb-6">
|
|
250
284
|
{/* Filter dropdown */}
|
|
251
|
-
<Filters
|
|
252
|
-
ref={filtersRef}
|
|
285
|
+
<Filters
|
|
253
286
|
filters={filters}
|
|
254
287
|
state={filterState}
|
|
255
288
|
setState={setFilterState}
|
|
@@ -263,10 +296,10 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
263
296
|
name="search"
|
|
264
297
|
id="search2"
|
|
265
298
|
iconPos="left"
|
|
266
|
-
state={filterState}
|
|
299
|
+
state={filterState}
|
|
267
300
|
onChange={(e) => {
|
|
268
|
-
onChange(e, setFilterState)
|
|
269
|
-
|
|
301
|
+
onChange(e, setFilterState) // update the filter state first
|
|
302
|
+
pushChangesToPath()
|
|
270
303
|
}}
|
|
271
304
|
placeholder="Linked search bar..."
|
|
272
305
|
/>
|
|
@@ -464,7 +497,7 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
464
497
|
<div>
|
|
465
498
|
<label for="amount">Amount ({state.amount})</label>
|
|
466
499
|
<Field
|
|
467
|
-
name="amount" type="currency" state={state} currency={state.currency || 'nzd'}
|
|
500
|
+
name="amount" type="currency" state={state} currency={state.currency || 'nzd'}
|
|
468
501
|
// Example of using a custom format and currencies, e.g.
|
|
469
502
|
format={'¤#,##0.00'}
|
|
470
503
|
currencies={currencies}
|
|
@@ -480,9 +513,13 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
480
513
|
<div class="grid grid-cols-1 gap-x-6 sm:grid-cols-3">
|
|
481
514
|
<div>
|
|
482
515
|
<label for="date">Date with time</label>
|
|
483
|
-
<Field name="date-time" type="date" mode="single" showTime={true} state={state} onChange={(e) => onChange(e, setState)}
|
|
516
|
+
<Field name="date-time" type="date" mode="single" showTime={true} state={state} onChange={(e) => onChange(e, setState)}
|
|
517
|
+
// Testing timezone support:
|
|
518
|
+
// tz="Pacific/Honolulu"
|
|
519
|
+
// DropdownProps={{ menuIsOpen: true }}
|
|
520
|
+
/>
|
|
484
521
|
</div>
|
|
485
|
-
|
|
522
|
+
<div>
|
|
486
523
|
<label for="date-range">Date range (with prefix & disabled days)</label>
|
|
487
524
|
<Field
|
|
488
525
|
name="date-range"
|
|
@@ -498,32 +535,49 @@ export function Styleguide({ className, elements, children, currencies }: Styleg
|
|
|
498
535
|
</div>
|
|
499
536
|
<div>
|
|
500
537
|
<label for="date">Date multi-select (right aligned)</label>
|
|
501
|
-
<Field name="date" type="date" mode="multiple" state={state} onChange={(e) => onChange(e, setState)} dir="bottom-right" />
|
|
538
|
+
<Field name="date-multiple" type="date" mode="multiple" state={state} onChange={(e) => onChange(e, setState)} dir="bottom-right" />
|
|
502
539
|
</div>
|
|
503
540
|
<div>
|
|
504
541
|
<label for="time">Time</label>
|
|
505
|
-
<Field name="time" type="time" state={state} onChange={(e) => onChange(e, setState)}
|
|
542
|
+
<Field name="time" type="date" mode="time" state={state} onChange={(e) => onChange(e, setState)}
|
|
543
|
+
// Testing timezone support:
|
|
544
|
+
// tz="Pacific/Honolulu"
|
|
545
|
+
/>
|
|
506
546
|
</div>
|
|
507
547
|
</div>
|
|
508
548
|
</div>
|
|
509
549
|
)}
|
|
510
550
|
|
|
511
|
-
{groups.includes('File Inputs & Calendar') && (
|
|
551
|
+
{groups.includes('File Inputs & Calendar & Time') && (
|
|
512
552
|
<div>
|
|
513
|
-
<h2 class="h3">File Inputs & Calendar</h2>
|
|
553
|
+
<h2 class="h3">File Inputs & Calendar & Time</h2>
|
|
514
554
|
<div class="grid grid-cols-3 gap-x-6">
|
|
515
555
|
<div>
|
|
516
556
|
<label for="avatar">Avatar</label>
|
|
517
557
|
<Drop class="is-small" name="avatar" state={state} onChange={(e) => onChange(e, setState)} awsUrl={injectedConfig.awsUrl} />
|
|
518
558
|
</div>
|
|
519
559
|
<div>
|
|
520
|
-
<label for="calendar">
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
560
|
+
<label for="calendar">
|
|
561
|
+
Calendar
|
|
562
|
+
{/* {' ' + new Date(state['calendar-single'] || '')?.toLocaleString('en-US', { timeZone: 'Pacific/Honolulu' })} */}
|
|
563
|
+
</label>
|
|
564
|
+
<Calendar mode="range" value={state['calendar-range']} numberOfMonths={1}
|
|
565
|
+
onChange={(value) => onChange({ target: { name: 'calendar-range', value: value } }, setState)}
|
|
566
|
+
// Testing timezone support:
|
|
567
|
+
// tz="Pacific/Honolulu"
|
|
568
|
+
// preserveTime={true}
|
|
525
569
|
/>
|
|
526
570
|
</div>
|
|
571
|
+
<div>
|
|
572
|
+
<label for="time">TimePicker</label>
|
|
573
|
+
<div className="mt-2.5 mb-6 mt-input-before mb-input-after pt-2">
|
|
574
|
+
<TimePicker value={state.time} className="min-h-[150]"
|
|
575
|
+
onChange={(value) => onChange({ target: { name: 'time', value: value }}, setState)}
|
|
576
|
+
// Testing timezone support:
|
|
577
|
+
// tz="Pacific/Honolulu"
|
|
578
|
+
/>
|
|
579
|
+
</div>
|
|
580
|
+
</div>
|
|
527
581
|
</div>
|
|
528
582
|
</div>
|
|
529
583
|
)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.147",
|
|
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 🚀",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"types": "tsc util.js ./server/index.js --declaration --declarationMap --allowJs --emitDeclarationOnly --jsx react-jsx --esModuleInterop --skipLibCheck --outDir types && cd ../webpack && npm run types -w . && cd ../core"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@date-fns/tz": "^1.4.1",
|
|
32
33
|
"@hokify/axios": "^0.19.1",
|
|
33
34
|
"axios": "^1.9.0",
|
|
34
35
|
"axios-retry": "^3.3.1",
|
|
35
36
|
"bcrypt": "^5.0.0",
|
|
36
37
|
"body-parser": "^1.19.0",
|
|
37
38
|
"compression": "^1.7.4",
|
|
38
|
-
"date-fns": "^
|
|
39
|
-
"dateformat": "^5.0.3",
|
|
39
|
+
"date-fns": "^4.1.0",
|
|
40
40
|
"dotenv": "^14.3.2",
|
|
41
41
|
"express": "^4.17.1",
|
|
42
42
|
"express-fileupload": "^1.1.6",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"tailwind-merge": "^2.6.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/dateformat": "^5.0.3",
|
|
57
56
|
"@typescript-eslint/eslint-plugin": "^8.18.1"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
package/types/util.d.ts
CHANGED
|
@@ -111,17 +111,12 @@ export function currency(cents: number, decimals?: number, decimalsMinimum?: num
|
|
|
111
111
|
export function currencyToCents(currency: string): string;
|
|
112
112
|
/**
|
|
113
113
|
* Returns a formatted date string
|
|
114
|
-
* @param {number|Date} [date] -
|
|
115
|
-
* @param {string} [
|
|
114
|
+
* @param {number|Date} [date] - timestamp or date
|
|
115
|
+
* @param {string} [pattern] - e.g. "dd mmmm yy" (https://date-fns.org/v4.1.0/docs/format#)
|
|
116
116
|
* @param {string} [timezone] - convert a UTC date to a particular timezone.
|
|
117
117
|
* @returns {string}
|
|
118
|
-
*
|
|
119
|
-
* Note on the timezone conversion:
|
|
120
|
-
* Timezone conversion relies on parsing the toLocaleString result, e.g. 4/10/2012, 5:10:30 PM.
|
|
121
|
-
* A older browser may not accept en-US formatted date string to its Date constructor, and it may
|
|
122
|
-
* return unexpected result (it may ignore daylight saving).
|
|
123
118
|
*/
|
|
124
|
-
export function date(date?: number | Date,
|
|
119
|
+
export function date(date?: number | Date, pattern?: string, timezone?: string): string;
|
|
125
120
|
/**
|
|
126
121
|
* @template {(...args: any[]) => any} T
|
|
127
122
|
* Creates a debounced function that delays invoking `func` until after `wait`
|
package/types/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../util.js"],"names":[],"mappings":"AA2CA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BC;AAED;;;;;;;;;GASG;AACH,yBARa,sBAAsB,CAoBlC;AAED;;;;;GAKG;AACH,8BAJW,MAAM,cACN;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACrB,MAAM,CAKlB;AAED;;;;;;GAMG;AACH,+BALW,MAAM,oBACN,OAAO,gBACP,OAAO,GACL,MAAM,CAelB;AAED;;;;;GAKG;AACH,sCAJW,MAAM,wBACN,OAAO,GACL,MAAM,CAMlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;GAIG;AACH,iCAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;GAMG;AACH,gCALW,MAAM,aACN,MAAM,oBACN,MAAM,GACJ,MAAM,CAUlB;AAED;;;;GAIG;AACH,0CAHW,MAAM,GACJ,MAAM,CAMlB;AAED
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../util.js"],"names":[],"mappings":"AA2CA;;GAEG;A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AAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;yBACjC;IAAE,MAAM,EAAE,MAAM;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE;8BACrC;IAAE,QAAQ,EAAE;QAAE,IAAI,EAAE;YAAE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE"}
|
package/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _axios from 'axios'
|
|
2
2
|
import axiosRetry from 'axios-retry'
|
|
3
|
-
import
|
|
3
|
+
import { format } from 'date-fns'
|
|
4
4
|
import { loadStripe } from '@stripe/stripe-js/pure.js' // pure removes ping
|
|
5
5
|
import { twMerge as _twMerge, twJoin, createTailwindMerge, getDefaultConfig } from 'tailwind-merge'
|
|
6
6
|
|
|
@@ -194,31 +194,16 @@ export function currencyToCents (currency) {
|
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* Returns a formatted date string
|
|
197
|
-
* @param {number|Date} [date] -
|
|
198
|
-
* @param {string} [
|
|
197
|
+
* @param {number|Date} [date] - timestamp or date
|
|
198
|
+
* @param {string} [pattern] - e.g. "dd mmmm yy" (https://date-fns.org/v4.1.0/docs/format#)
|
|
199
199
|
* @param {string} [timezone] - convert a UTC date to a particular timezone.
|
|
200
200
|
* @returns {string}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export function date (date, format, timezone) {
|
|
208
|
-
if (!date) return 'Date?'
|
|
209
|
-
|
|
210
|
-
// Get the milliseconds
|
|
211
|
-
let milliseconds = 0
|
|
212
|
-
if (typeof date === 'number') {
|
|
213
|
-
if (date < 9999999999) milliseconds = date * 1000
|
|
214
|
-
else milliseconds = date
|
|
215
|
-
} else if (isDate(date)) {
|
|
216
|
-
milliseconds = date.getTime()
|
|
217
|
-
}
|
|
218
|
-
if (timezone) {
|
|
219
|
-
milliseconds = new Date(new Date(milliseconds).toLocaleString('en-US', { timeZone: timezone })).getTime()
|
|
220
|
-
}
|
|
221
|
-
return dateformat(milliseconds, format || 'dS mmmm')
|
|
201
|
+
*/
|
|
202
|
+
export function date (date, pattern, timezone) {
|
|
203
|
+
if (!date) return ''
|
|
204
|
+
const timestamp = typeof date === 'number' ? date : isDate(date) ? date?.getTime() : 0
|
|
205
|
+
const timestampInTz = timezone ? new Date(new Date(timestamp).toLocaleString('en-US', { timeZone: timezone })).getTime() : timestamp
|
|
206
|
+
return format(timestampInTz, pattern ?? 'do MMMM')
|
|
222
207
|
}
|
|
223
208
|
|
|
224
209
|
/**
|