@campxdev/shared 0.3.4 → 0.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,22 +1,40 @@
1
- import { createContext, useState } from 'react'
1
+ import {createContext, ReactNode, useState} from 'react'
2
2
  import PopupConfirm from './PopupConfirm'
3
3
 
4
- export const ConfirmContext = createContext(null)
4
+ interface ConfirmContextProps {
5
+ confirm: {
6
+ prompt: ReactNode
7
+ isOpen: boolean
8
+ proceed: () => void
9
+ cancel: () => void
10
+ }
11
+ setConfirm: any
12
+ }
13
+
14
+ export const ConfirmContext = createContext<ConfirmContextProps>({
15
+ confirm: {
16
+ cancel: () => {},
17
+ proceed: () => {},
18
+ prompt: 'Are you sure?',
19
+ isOpen: false,
20
+ },
21
+ setConfirm: () => {},
22
+ })
5
23
 
6
- const ConfirmContextProvider = ({ children }) => {
7
- const [confirm, setConfirm] = useState({
8
- prompt: '',
9
- isOpen: false,
10
- proceed: null,
11
- cancel: null,
12
- })
24
+ const ConfirmContextProvider = ({children}) => {
25
+ const [confirm, setConfirm] = useState({
26
+ prompt: '',
27
+ isOpen: false,
28
+ proceed: null,
29
+ cancel: null,
30
+ })
13
31
 
14
- return (
15
- <ConfirmContext.Provider value={[confirm, setConfirm]}>
16
- {children}
17
- <PopupConfirm />
18
- </ConfirmContext.Provider>
19
- )
32
+ return (
33
+ <ConfirmContext.Provider value={{confirm, setConfirm}}>
34
+ {children}
35
+ <PopupConfirm />
36
+ </ConfirmContext.Provider>
37
+ )
20
38
  }
21
39
 
22
40
  export default ConfirmContextProvider
@@ -1,47 +1,47 @@
1
- import { useContext, useEffect, useState } from 'react'
2
- import { ConfirmContext } from './ConfirmContextProvider'
1
+ import {ReactNode, useContext, useEffect, useState} from 'react'
2
+ import {ConfirmContext} from './ConfirmContextProvider'
3
3
 
4
4
  export default function useConfirm(): {
5
- isConfirmed: (prompt?: string) => Promise<boolean>
6
- prompt?: ''
7
- isOpen?: false
8
- proceed?: null
9
- cancel?: null
5
+ isConfirmed: (prompt?: string) => Promise<boolean>
6
+ prompt?: ReactNode
7
+ isOpen?: boolean
8
+ proceed?: () => void
9
+ cancel?: () => void
10
10
  } {
11
- const [confirm, setConfirm] = useContext(ConfirmContext)
12
- const [needsCleanup, setNeedsCleanup] = useState(false)
11
+ const {confirm, setConfirm} = useContext(ConfirmContext)
12
+ const [needsCleanup, setNeedsCleanup] = useState(false)
13
13
 
14
- const isConfirmed = (prompt) => {
15
- setNeedsCleanup(true)
16
- const promise = new Promise((resolve, reject) => {
17
- setConfirm({
18
- prompt,
19
- isOpen: true,
20
- proceed: resolve,
21
- cancel: reject,
22
- })
23
- })
24
- return promise.then(
25
- () => {
26
- setConfirm({ ...confirm, isOpen: false })
27
- return true
28
- },
29
- () => {
30
- setConfirm({ ...confirm, isOpen: false })
31
- return false
32
- },
33
- )
34
- }
14
+ const isConfirmed = (prompt) => {
15
+ setNeedsCleanup(true)
16
+ const promise = new Promise((resolve, reject) => {
17
+ setConfirm({
18
+ prompt,
19
+ isOpen: true,
20
+ proceed: resolve,
21
+ cancel: reject,
22
+ })
23
+ })
24
+ return promise.then(
25
+ () => {
26
+ setConfirm({...confirm, isOpen: false})
27
+ return true
28
+ },
29
+ () => {
30
+ setConfirm({...confirm, isOpen: false})
31
+ return false
32
+ }
33
+ )
34
+ }
35
35
 
36
- useEffect(() => {
37
- return () => {
38
- if (confirm.cancel && needsCleanup) {
39
- confirm.cancel()
40
- }
41
- }
42
- }, [confirm, needsCleanup])
43
- return {
44
- ...confirm,
45
- isConfirmed,
46
- }
36
+ useEffect(() => {
37
+ return () => {
38
+ if (confirm.cancel && needsCleanup) {
39
+ confirm.cancel()
40
+ }
41
+ }
42
+ }, [confirm, needsCleanup])
43
+ return {
44
+ ...confirm,
45
+ isConfirmed,
46
+ }
47
47
  }
@@ -1,6 +1,7 @@
1
- export { default as getUrlParams } from './getUrlParams'
2
- export { default as arrayPadEnd } from './arrayPadEnd'
3
- export { default as romanize } from './romanize'
1
+ export {default as getUrlParams} from './getUrlParams'
2
+ export {default as arrayPadEnd} from './arrayPadEnd'
3
+ export {default as romanize} from './romanize'
4
4
 
5
- export { default as withRouteWrapper } from './withRouteWrapper'
6
- export { default as withSuspense } from './withSuspense'
5
+ export {default as withRouteWrapper} from './withRouteWrapper'
6
+ export {default as withSuspense} from './withSuspense'
7
+ export {default as withLocalization} from './withLocalization'
@@ -0,0 +1,11 @@
1
+ import {LocalizationProvider} from '@mui/x-date-pickers'
2
+ import {AdapterMoment} from '@mui/x-date-pickers/AdapterMoment'
3
+ import {ReactNode} from 'react'
4
+
5
+ export default function withLocalization(component: ReactNode) {
6
+ return (
7
+ <LocalizationProvider dateAdapter={AdapterMoment}>
8
+ {component}
9
+ </LocalizationProvider>
10
+ )
11
+ }