@driveflux/ui 1.0.14 → 1.1.1

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.
Files changed (97) hide show
  1. package/dist/bottom-sheet/BottomSheetProvider.d.ts +4 -0
  2. package/dist/bottom-sheet/BottomSheetProvider.d.ts.map +1 -0
  3. package/dist/bottom-sheet/BottomSheetProvider.js +190 -0
  4. package/dist/bottom-sheet/context.d.ts +15 -0
  5. package/dist/bottom-sheet/context.d.ts.map +1 -0
  6. package/dist/bottom-sheet/context.js +6 -0
  7. package/dist/bottom-sheet/index.d.ts +4 -0
  8. package/dist/bottom-sheet/index.d.ts.map +1 -0
  9. package/dist/bottom-sheet/index.js +3 -0
  10. package/dist/bottom-sheet/use-bottom-sheet.d.ts +6 -0
  11. package/dist/bottom-sheet/use-bottom-sheet.d.ts.map +1 -0
  12. package/dist/bottom-sheet/use-bottom-sheet.js +5 -0
  13. package/dist/bottom-sheet/utils.d.ts +2 -0
  14. package/dist/bottom-sheet/utils.d.ts.map +1 -0
  15. package/dist/bottom-sheet/utils.js +15 -0
  16. package/dist/chakra.d.ts.map +1 -1
  17. package/dist/chakra.js +1 -0
  18. package/dist/modal/ModalProvider.d.ts.map +1 -1
  19. package/dist/modal/ModalProvider.js +1 -4
  20. package/dist/modal/components/EnhancedModalCustomWrapper.d.ts.map +1 -1
  21. package/dist/modal/components/EnhancedModalFooter.d.ts +2 -2
  22. package/dist/modal/components/EnhancedModalFooter.d.ts.map +1 -1
  23. package/dist/modal/components/MinimalModalContent.d.ts.map +1 -1
  24. package/dist/modal/components/StandardModalContent.d.ts.map +1 -1
  25. package/dist/modal/context.d.ts.map +1 -1
  26. package/dist/modal/use-enhanced-modal.d.ts.map +1 -1
  27. package/dist/theme/colors.d.ts.map +1 -1
  28. package/dist/theme/colors.js +36 -36
  29. package/dist/toast/index.d.ts.map +1 -1
  30. package/dist/toast/use-toast-result.d.ts +2 -2
  31. package/dist/toast/use-toast-result.d.ts.map +1 -1
  32. package/dist/toast/use-toast-result.js +2 -2
  33. package/dist/translations.d.ts.map +1 -1
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils/accessors.d.ts.map +1 -1
  36. package/dist/utils/react.d.ts.map +1 -1
  37. package/package.json +44 -43
  38. package/.eslintrc.json +0 -3
  39. package/.swcrc +0 -14
  40. package/.turbo/turbo-build.log +0 -11
  41. package/CHANGELOG.md +0 -159
  42. package/dist/cjs/chakra.js +0 -18
  43. package/dist/cjs/index.js +0 -20
  44. package/dist/cjs/modal/ModalProvider.js +0 -255
  45. package/dist/cjs/modal/components/EnhancedModalCustomWrapper.js +0 -139
  46. package/dist/cjs/modal/components/EnhancedModalFooter.js +0 -163
  47. package/dist/cjs/modal/components/MinimalModalContent.js +0 -94
  48. package/dist/cjs/modal/components/StandardModalContent.js +0 -359
  49. package/dist/cjs/modal/context.js +0 -20
  50. package/dist/cjs/modal/index.js +0 -48
  51. package/dist/cjs/modal/use-enhanced-modal.js +0 -15
  52. package/dist/cjs/package.json +0 -3
  53. package/dist/cjs/theme/colors.js +0 -147
  54. package/dist/cjs/theme/index.js +0 -18
  55. package/dist/cjs/toast/index.js +0 -19
  56. package/dist/cjs/toast/use-toast-result.js +0 -210
  57. package/dist/cjs/translations.js +0 -42
  58. package/dist/cjs/types.js +0 -4
  59. package/dist/cjs/utils/accessors.js +0 -65
  60. package/dist/cjs/utils/index.js +0 -19
  61. package/dist/cjs/utils/react.js +0 -56
  62. package/dist/index.d.ts +0 -2
  63. package/dist/index.d.ts.map +0 -1
  64. package/dist/index.js +0 -3
  65. package/index.cjs +0 -1
  66. package/index.d.ts +0 -1
  67. package/modal.cjs +0 -1
  68. package/modal.d.ts +0 -1
  69. package/src/chakra.ts +0 -2
  70. package/src/index.ts +0 -4
  71. package/src/modal/ModalProvider.tsx +0 -143
  72. package/src/modal/components/EnhancedModalCustomWrapper.tsx +0 -39
  73. package/src/modal/components/EnhancedModalFooter.tsx +0 -51
  74. package/src/modal/components/MinimalModalContent.tsx +0 -24
  75. package/src/modal/components/StandardModalContent.tsx +0 -65
  76. package/src/modal/context.tsx +0 -81
  77. package/src/modal/index.ts +0 -7
  78. package/src/modal/use-enhanced-modal.ts +0 -7
  79. package/src/theme/colors.ts +0 -179
  80. package/src/theme/index.ts +0 -1
  81. package/src/toast/index.ts +0 -3
  82. package/src/toast/use-toast-result.tsx +0 -168
  83. package/src/translations.ts +0 -25
  84. package/src/types.ts +0 -22
  85. package/src/utils/accessors.ts +0 -64
  86. package/src/utils/index.ts +0 -2
  87. package/src/utils/react.ts +0 -35
  88. package/theme.cjs +0 -1
  89. package/theme.d.ts +0 -1
  90. package/toast.cjs +0 -1
  91. package/toast.d.ts +0 -1
  92. package/translations.cjs +0 -1
  93. package/translations.d.ts +0 -1
  94. package/tsconfig.json +0 -14
  95. package/tsconfig.tsbuildinfo +0 -1
  96. package/utils.cjs +0 -1
  97. package/utils.d.ts +0 -1
@@ -1,24 +0,0 @@
1
- import { Fragment, type FC } from 'react'
2
- import { Box, ModalBody, ModalCloseButton, ModalHeader } from '../../chakra.js'
3
- import { isReactNode } from '../../utils/react.js'
4
- import type { ModalContentConfig, ModalControlProps } from '../context.js'
5
-
6
- type Props = {
7
- controls: ModalControlProps
8
- modalContentConfig: Extract<ModalContentConfig, { type: 'minimal' }>
9
- }
10
-
11
- const MinimalModalContent: FC<Props> = ({ controls: { open, close }, modalContentConfig, ...props }) => {
12
- const Content = modalContentConfig.content
13
-
14
- const Wrapper = modalContentConfig.noModalBody ? Fragment : ModalBody
15
- return (
16
- <>
17
- {modalContentConfig.title ? <ModalHeader>{modalContentConfig.title}</ModalHeader> : <Box h={'32px'} />}
18
- <ModalCloseButton />
19
- <Wrapper>{isReactNode(Content) ? Content : <Content close={close} open={open} {...props} />}</Wrapper>
20
- </>
21
- )
22
- }
23
-
24
- export default MinimalModalContent
@@ -1,65 +0,0 @@
1
- import { useCallback, useState, type FC } from 'react'
2
- import {
3
- Button,
4
- HStack,
5
- ModalBody,
6
- ModalCloseButton,
7
- ModalFooter,
8
- ModalHeader
9
- } from '../../chakra.js'
10
- import { translations } from '../../translations.js'
11
- import { isReactNode } from '../../utils/react.js'
12
- import type { ModalContentConfig, ModalControlProps } from '../context.js'
13
- import { useEnhancedModal } from '../use-enhanced-modal.js'
14
-
15
- type Props = {
16
- controls: ModalControlProps
17
- modalContentConfig: Extract<ModalContentConfig, { type: 'standard' }>
18
- }
19
-
20
- const StandardModalContent: FC<Props> = ({ controls: { open, close }, modalContentConfig, ...props }) => {
21
- const Content = modalContentConfig.content
22
- const [isSaving, setIsSaving] = useState(false)
23
- const { modalState } = useEnhancedModal()
24
-
25
- const handleOK = useCallback(async () => {
26
- setIsSaving(true)
27
-
28
- if (modalContentConfig.onOk) {
29
- try {
30
- await modalContentConfig.onOk(modalState)
31
- } finally {
32
- setIsSaving(false)
33
- }
34
- }
35
- close()
36
- }, [modalContentConfig.onOk, close, modalState])
37
-
38
- const handleCancel = useCallback(async () => {
39
- if (modalContentConfig.onCancel) {
40
- await modalContentConfig.onCancel()
41
- }
42
- close()
43
- }, [modalContentConfig.onCancel, close])
44
-
45
- return (
46
- <>
47
- <ModalHeader>{modalContentConfig.title}</ModalHeader>
48
- <ModalCloseButton />
49
- <ModalBody>
50
- {isReactNode(Content) ? Content : <Content open={open} close={close} {...props} />}
51
- </ModalBody>
52
- <ModalFooter>
53
- <HStack w={'full'} spacing={'6'}>
54
- <Button isDisabled={isSaving} w={'full'} variant={'outline'} onClick={handleCancel}>{modalContentConfig.cancelText || translations.close}</Button>
55
- <Button isDisabled={modalContentConfig.isOkDisabled} isLoading={isSaving || modalContentConfig.isOkLoading} w={'full'} variant={'solid'} onClick={handleOK} colorScheme={modalContentConfig.okColorScheme}>
56
- {modalContentConfig.okText || translations.ok}
57
- </Button>
58
- </HStack>
59
- </ModalFooter>
60
- </>
61
- )
62
-
63
- }
64
-
65
- export default StandardModalContent
@@ -1,81 +0,0 @@
1
- import { createContext, type Dispatch, type FC, type ReactNode, type SetStateAction } from 'react'
2
- import type { UnionToIntersection } from 'type-fest'
3
- import type { ModalProps } from '../chakra.js'
4
-
5
- export type ModalControlProps = {
6
- open: () => void
7
- close: () => void
8
- }
9
-
10
- export type StandardModaContentConfig<MS = any> = {
11
- type: 'standard'
12
- title?: string
13
- okText?: string
14
- okColorScheme?: string
15
- onOk?: (modalState: MS) => void | Promise<void>
16
- isOkDisabled?: boolean
17
- isOkLoading?: boolean
18
- cancelText?: string
19
- onCancel?: () => void | Promise<void>
20
- }
21
-
22
- export type CustomModalContentConfig = {
23
- type: 'custom'
24
- }
25
-
26
- export type MinimalModalContentConfig = {
27
- type: 'minimal'
28
- title?: string
29
- noModalBody?: boolean
30
- }
31
-
32
- type CleanupModalContentConfig<T> = {
33
- [K in keyof T as Exclude<K, 'type'>]: T[K]
34
- };
35
-
36
- type ModalContentConfigUnion<MS = any> = StandardModaContentConfig<MS> | CustomModalContentConfig | MinimalModalContentConfig
37
- type ModalContentConfigIntersection<MS = any> = UnionToIntersection<CleanupModalContentConfig<ModalContentConfigUnion<MS>>>
38
-
39
- export type ModalContentConfig<P extends object = {}, MS = any> = {
40
- contentProps?: P
41
- initialModalState?: MS
42
- content: FC<Partial<ModalControlProps> & Omit<P, keyof ModalControlProps>> | ReactNode
43
- size?: ModalProps['size']
44
- } & ModalContentConfigUnion<MS>
45
-
46
- export type ModalOptions = {
47
- onClose?: () => void
48
- }
49
-
50
- export interface ModalOpenOptions<ExtraProps extends object = {}, MS = any> extends ModalOptions {
51
- modalContentConfig: ModalContentConfig<ExtraProps, MS>
52
- }
53
-
54
- export interface ModalUpdateOptions<ExtraProps extends object = Record<string, any>, MS = any> {
55
- contentProps?: ExtraProps
56
- state?: MS
57
- modalContentConfig?: ModalContentConfigIntersection<MS>
58
- }
59
-
60
- export interface ModalCloseOptions {
61
- keepModalContentConfig?: boolean
62
- }
63
- export interface ModalContextState<ExtraProps extends object = any, MS = any> {
64
- isOpen: boolean
65
- open: <P extends ExtraProps, IMS extends MS = any>(options?: ModalOpenOptions<P, IMS> | ModalContentConfig<P, IMS>) => void
66
- close: (options?: ModalCloseOptions) => void
67
- update: (options: ModalUpdateOptions<ExtraProps>) => void
68
- modalState?: MS
69
- setModalState: Dispatch<SetStateAction<MS>>
70
- }
71
-
72
- const initialState: ModalContextState = {
73
- isOpen: true,
74
- open: () => {},
75
- close: () => {},
76
- update: () => {},
77
- modalState: undefined,
78
- setModalState: () => {},
79
- }
80
-
81
- export const ModalContext = createContext<ModalContextState>(initialState)
@@ -1,7 +0,0 @@
1
- export { default as ModalProvider } from './ModalProvider.js'
2
- export { default as EnhancedModalCustomWrapper } from './components/EnhancedModalCustomWrapper.js'
3
- export { default as EnhancedModalFooter } from './components/EnhancedModalFooter.js'
4
- export { default as MinimalModalContent } from './components/MinimalModalContent.js'
5
- export * from './context.js'
6
- export * from './use-enhanced-modal.js'
7
-
@@ -1,7 +0,0 @@
1
- import { useContext, type Context } from 'react'
2
- import type { ModalContextState } from './context.js'
3
- import { ModalContext } from './context.js'
4
-
5
- export const useEnhancedModal = <P extends object = any, MS = any>(): ModalContextState<P, MS> => {
6
- return useContext<ModalContextState<P, MS>>(ModalContext as unknown as Context<ModalContextState<P, MS>>)
7
- }
@@ -1,179 +0,0 @@
1
- // TODO sync this with the one in dump
2
- // remove dump file version
3
- // update all instances using colors
4
-
5
- export const colors = {
6
- /**
7
- * #EFEFF0 Light Gray
8
- */
9
- primary1: '#EFEFF0',
10
-
11
- /**
12
- * #CACACA Gray
13
- */
14
- primary2: '#CACACA',
15
-
16
- /**
17
- * #585858 Dark Gray
18
- */
19
- primary3: '#585858',
20
-
21
- /**
22
- * #191919 Soft Black
23
- */
24
- primary4: '#191919',
25
-
26
- /**
27
- * #E55867 Red
28
- */
29
- accent4: '#E55867',
30
-
31
- /**
32
- * #ADE0EE Light Blue
33
- */
34
- links2: '#ADE0EE',
35
-
36
- /**
37
- * #50C8E8 Blue
38
- */
39
- links: '#50C8E8',
40
-
41
- /**
42
- * #E24657 Red
43
- */
44
- alert4: '#E24657',
45
-
46
- /**
47
- * #E24657 Red
48
- */
49
- danger: '#E24657',
50
-
51
- /**
52
- * #F4B25C Yellow
53
- */
54
- warning4: '#F4B25C',
55
-
56
- /**
57
- * #4FD9C2 Green
58
- */
59
- success4: '#4FD9C2',
60
-
61
- /**
62
- * #4FD9C2 Green
63
- */
64
- green: '#4FD9C2',
65
-
66
- /**
67
- * #3BD5BC Green
68
- */
69
- // green: '#3BD5BC',
70
-
71
- /**
72
- * #000000 Black
73
- */
74
- black: '#000000',
75
-
76
- /**
77
- * #ffffff White
78
- */
79
- white: '#ffffff',
80
-
81
- /**
82
- * #E6E6E6 Light Gray
83
- */
84
- whiteHover: '#E6E6E6',
85
-
86
- /**
87
- * #F4F4F4 Light Gray
88
- */
89
- placeholder: '#F4F4F4',
90
-
91
- /**
92
- * #F9F7D7 Light Yellow
93
- */
94
- highlight: '#F9F7D7',
95
-
96
- primary: {
97
- 25: '#fafafa',
98
- 50: '#d6f5f0',
99
- 100: '#98e6d6',
100
- 200: '#191919',
101
- 300: '#191919',
102
- 400: '#3bd5bb',
103
- 500: '#000000',
104
- 600: '#000000',
105
- 700: '#000000',
106
- 800: '#000000',
107
- 900: '#000000'
108
- },
109
-
110
- // TODO add 25
111
- success: {
112
- 50: '#d8f7f2',
113
- 100: '#98e6d6',
114
- 200: '#3bd5bc',
115
- 300: '#4FD9C2',
116
- 400: '#3bd5bb',
117
- 500: '#3bd5bb',
118
- 600: '#2EA692',
119
- 700: '#00825c',
120
- 800: '#00724d',
121
- 900: '#005530'
122
- },
123
-
124
- // TODO add 25
125
- accent: {
126
- 50: '#fceaee',
127
- 100: '#f8cad3',
128
- 200: '#E55867',
129
- 300: '#E55867',
130
- 400: '#E24657',
131
- 500: '#E24657',
132
- 600: '#d8253f',
133
- 700: '#c61a38',
134
- 800: '#b91231',
135
- 900: '#aa0026'
136
- },
137
-
138
- // TODO add 25
139
- warning: {
140
- 50: '#FDF0DE',
141
- 100: '#F4B25C',
142
- 200: '#F4B25C',
143
- 300: '#F4B25C',
144
- 400: '#F4B25C',
145
- 500: '#F4B25C',
146
- 600: '#BF7F2C',
147
- 700: '#F4B25C',
148
- 800: '#F4B25C',
149
- 900: '#F4B25C'
150
- },
151
-
152
- info: {
153
- 25: '#50C8E81A',
154
- 50: '#CDF1FA',
155
- 100: '#50C8E8',
156
- 200: '#50C8E8',
157
- 300: '#50C8E8',
158
- 400: '#50C8E8',
159
- 500: '#50C8E8',
160
- 600: '#3EA5C0',
161
- 700: '#50C8E8',
162
- 800: '#50C8E8',
163
- 900: '#50C8E8'
164
- },
165
-
166
- // TODO add 25
167
- alert: {
168
- 50: '#E24657',
169
- 100: '#E24657',
170
- 200: '#E24657',
171
- 300: '#E24657',
172
- 400: '#E24657',
173
- 500: '#E24657',
174
- 600: '#E24657',
175
- 700: '#E24657',
176
- 800: '#E24657',
177
- 900: '#E24657',
178
- }
179
- }
@@ -1 +0,0 @@
1
- export * from './colors.js'
@@ -1,3 +0,0 @@
1
- export * from './use-toast-result.js';
2
-
3
- // TODO: Add the ToastBox component here
@@ -1,168 +0,0 @@
1
- import type { Problem, ValidationIssues } from '@driveflux/problem'
2
- import type { StandardResult } from '@driveflux/result'
3
- import merge from 'lodash/merge.js'
4
- import { useCallback } from 'react'
5
- import {
6
- Box,
7
- ListItem,
8
- Text,
9
- UnorderedList,
10
- useToast,
11
- type CreateToastFnReturn,
12
- type ToastId,
13
- type UseToastOptions
14
- } from '../chakra.js'
15
- import { translations } from '../translations.js'
16
- import { accessReactNode, type ReactNodeAccessor } from '../utils/accessors.js'
17
-
18
- export type StatusFn<T> = (data?: T) => UseToastOptions['status']
19
-
20
- const accessStatus = <D,>(s?: UseToastOptions['status'] | StatusFn<D>, data?: D): UseToastOptions['status'] => {
21
- return typeof s === 'function' ? s(data) : s
22
- }
23
-
24
- type CustomUseToastOptions<T> = Omit<UseToastOptions, 'status' | 'title' | 'description'> & {
25
- status?: UseToastOptions['status'] | StatusFn<T>
26
- title?: UseToastOptions['title'] | ReactNodeAccessor<T>
27
- description?: UseToastOptions['description'] | ReactNodeAccessor<T>
28
- }
29
-
30
- type ErrorUseToastOptions<E = Problem> = CustomUseToastOptions<E> & {
31
- showValidationErrors?: boolean
32
- defaultDescription?: string
33
- }
34
-
35
- type UseToastResultOptions<S = any | Problem, E = Problem> = {
36
- defaultOptions?: CustomUseToastOptions<S>
37
- success?: CustomUseToastOptions<S> | boolean | null
38
- error?: ErrorUseToastOptions<E> | boolean | null
39
- }
40
-
41
- type UseToastResult = {
42
- toastProblem: <P extends Problem>(problem: P, providedOptions?: ErrorUseToastOptions<P>) => ToastId
43
- toastSuccess: <T extends any>(providedOptions?: CustomUseToastOptions<T>) => ToastId
44
- toastResult: <T extends unknown, R extends StandardResult<T> = StandardResult<T>>(
45
- result: R,
46
- generalToastOptions?: UseToastResultOptions<T, Problem>
47
- ) => ToastId | undefined
48
- toastError: (providedOptions?: UseToastOptions) => ToastId
49
- toast: CreateToastFnReturn
50
- }
51
-
52
- const defaultUseToastResultOptions = {
53
- success: {
54
- status: 'success',
55
- title: translations.success,
56
- description: translations.successDescription,
57
- isClosable: true
58
- },
59
- error: {
60
- status: 'error',
61
- title: translations.failed,
62
- defaultDescription: translations.failedDescription,
63
- showValidationErrors: true,
64
- isClosable: true
65
- }
66
- } as const satisfies UseToastResultOptions
67
-
68
- export const getValidationErrorsList = (validation: ValidationIssues) => {
69
- return Object.values(validation.fieldErrors)
70
- .map((v) => v.map((vd) => vd.message))
71
- .flat()
72
- }
73
-
74
- const accessOptions = <S,>(options?: CustomUseToastOptions<S>, data?: S): UseToastOptions | undefined => {
75
- if (!options) {
76
- return options
77
- }
78
-
79
- return {
80
- ...options,
81
- status: accessStatus(options.status, data),
82
- title: accessReactNode(options.title, data),
83
- description: accessReactNode(options.description, data)
84
- }
85
- }
86
-
87
- export const useToastResult = (options?: UseToastResultOptions): UseToastResult => {
88
- const originalToast = useToast(accessOptions(options?.defaultOptions))
89
-
90
- const toastProblem: UseToastResult['toastProblem'] = useCallback(
91
- (problem, providedOptions) => {
92
- const { description, defaultDescription, showValidationErrors, ...rest } = merge(
93
- {},
94
- defaultUseToastResultOptions.error,
95
- providedOptions
96
- )
97
- const problemMessage = problem.message || defaultDescription
98
- return originalToast({
99
- ...accessOptions(rest, problem),
100
- description: accessReactNode(description, problem) || (
101
- <Box>
102
- <>
103
- {problemMessage && <Text color={'inherit'}>{problemMessage}</Text>}
104
- {problem.validation && showValidationErrors && (
105
- <UnorderedList color={'inherit'}>
106
- {getValidationErrorsList(problem.validation).map((message, i) => (
107
- <ListItem key={i}>{message}</ListItem>
108
- ))}
109
- </UnorderedList>
110
- )}
111
- </>
112
- </Box>
113
- )
114
- })
115
- },
116
- [originalToast]
117
- )
118
-
119
- const toastError: UseToastResult['toastError'] = useCallback(
120
- (providedOptions) => {
121
- const options = accessOptions(merge({}, defaultUseToastResultOptions.error, providedOptions))
122
- return originalToast({
123
- ...options
124
- })
125
- },
126
- [originalToast]
127
- )
128
-
129
- const toastSuccess: UseToastResult['toastSuccess'] = useCallback(
130
- (providedOptions) => {
131
- const options = accessOptions(merge({}, defaultUseToastResultOptions.success, providedOptions))
132
- return originalToast({
133
- ...options
134
- })
135
- },
136
- [originalToast]
137
- )
138
-
139
- const toastResult: UseToastResult['toastResult'] = useCallback(
140
- (result, generalToastOptions) => {
141
- const options = merge({}, defaultUseToastResultOptions, generalToastOptions)
142
- const toastType = result.ok ? 'success' : 'error'
143
-
144
- const toastOptions = options[toastType]
145
- if (!toastOptions) {
146
- return
147
- }
148
-
149
- const finalToastOptions = {
150
- ...(accessOptions(
151
- typeof toastOptions === 'boolean' ? defaultUseToastResultOptions[toastType] : toastOptions,
152
- result.val
153
- ) as UseToastOptions | ErrorUseToastOptions)
154
- } as UseToastOptions | ErrorUseToastOptions
155
- console.log('finalToastOptions????', finalToastOptions)
156
- return result.ok ? toastSuccess(finalToastOptions) : toastProblem(result.val, finalToastOptions)
157
- },
158
- [originalToast, toastProblem, toastSuccess]
159
- )
160
-
161
- return {
162
- toastProblem,
163
- toastSuccess,
164
- toastResult,
165
- toastError,
166
- toast: originalToast
167
- }
168
- }
@@ -1,25 +0,0 @@
1
- import { singleton } from '@driveflux/singleton'
2
- type Translations = typeof translations
3
-
4
- export const translations = singleton('uiTranslations', {
5
- success: 'Success',
6
- successDescription: 'Operation completed successfully.',
7
- failed: 'Operation Failed',
8
- failedDescription: 'There was a problem while performing this operation.',
9
- cancel: 'Cancel',
10
- confirm: 'Confirm',
11
- close: 'Close',
12
- ok: 'Ok'
13
- })
14
-
15
- export const setTranslations = (ts: Partial<Translations>) => {
16
- for (const key in ts) {
17
- // TODO
18
- // @ts-expect-error
19
- translations[key] = ts[key as keyof Translations]!
20
- }
21
- }
22
-
23
- export const setTranslation = <K extends keyof Translations>(key: K, value: Translations[K]) => {
24
- translations[key] = value
25
- }
package/src/types.ts DELETED
@@ -1,22 +0,0 @@
1
- export type LengthUnits =
2
- | 'cm'
3
- | 'mm'
4
- | 'in'
5
- | 'px'
6
- | 'pt'
7
- | 'pc'
8
- | 'em'
9
- | 'ex'
10
- | 'ch'
11
- | 'vw'
12
- | 'vh'
13
- | 'rem'
14
- | 'vmin'
15
- | 'vmax'
16
- | '%'
17
-
18
- export type StyleUnit = number | `${number}${LengthUnits}`
19
-
20
- export type Sizes = 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'xs' | '3xl' | '4xl' | '5xl' | '6xl' | 'full'
21
-
22
- export type Padding = 'base' | 'md'
@@ -1,64 +0,0 @@
1
- import type { ReactNode } from 'react'
2
-
3
- type AllowedParam = string | number | boolean | Date | undefined | null
4
- type AllowedQueryParams = Record<string, AllowedParam | AllowedParam[]>
5
-
6
- export type GenericAccessor<O, R> = (m: O) => R
7
-
8
- export type SelfAccessor<O, R = any> = GenericAccessor<O, R>
9
- export type StringAccessor<O, R extends string = string> = GenericAccessor<O, R>
10
- export type StringOrNullAccessor<O, R extends string = string> = GenericAccessor<O, R | null>
11
- export type SelfPartialAccessor<O> = GenericAccessor<O, Partial<O>>
12
- export type QueryAccessor<O, R extends AllowedQueryParams = AllowedQueryParams> = GenericAccessor<O, R>
13
- export type ReactNodeAccessor<O> = GenericAccessor<O, ReactNode>
14
- export type BooleanAccessor<O> = GenericAccessor<O, boolean>
15
- export interface FunctionAccessor<O, F extends (...args: any[]) => any> { generateFunction: GenericAccessor<O, F> }
16
-
17
- export type GuaranteedAccessor<AC extends (...args: any[]) => any> = (
18
- arg1: Required<Parameters<AC>>[0],
19
- arg2?: Parameters<AC>[1],
20
- arg3?: Parameters<AC>[2],
21
- arg4?: Parameters<AC>[3],
22
- arg5?: Parameters<AC>[4]
23
- ) => ReturnType<AC>
24
-
25
- export const accessSelf = <D, S, DS = S>(s: S, data?: D, defaultValue?: DS) => {
26
- if (!s) {
27
- return defaultValue
28
- }
29
-
30
- return typeof s === 'function' ? s(data) : s
31
- }
32
-
33
- export const accessBoolean = <D>(s: boolean | BooleanAccessor<D>, data?: D, defaultBoolean?: boolean) =>
34
- accessSelf(s, data, defaultBoolean)
35
-
36
- export const accessString = <D>(s: string | StringAccessor<D>, data?: D, defaultText?: string) =>
37
- accessSelf(s, data, defaultText)
38
-
39
- export const accessStringOrNull = <D>(
40
- s: string | null | StringOrNullAccessor<D>,
41
- data?: D,
42
- defaultText: string | null = null
43
- ) => accessSelf(s, data, defaultText)
44
-
45
- export const accessQuery = <D>(
46
- s: AllowedQueryParams | QueryAccessor<D>,
47
- data?: D,
48
- defaultQuery?: AllowedQueryParams
49
- ) => accessSelf(s, data, defaultQuery)
50
-
51
- export const accessReactNode = <D>(s: ReactNode | ReactNodeAccessor<D>, data?: D, defaultNode?: ReactNode) =>
52
- accessSelf(s, data, defaultNode)
53
-
54
- export const accessFunction = <D, F extends (...args: any[]) => any>(
55
- f: FunctionAccessor<D, F> | F,
56
- data?: D,
57
- defaultFunction?: F
58
- ) => {
59
- if (!f) {
60
- return defaultFunction
61
- }
62
-
63
- return typeof f === 'object' && 'generateFunction' in f ? f.generateFunction(data as D) : f
64
- }
@@ -1,2 +0,0 @@
1
- export * from './accessors.js'
2
- export * from './react.js'
@@ -1,35 +0,0 @@
1
- import { isValidElement, type ComponentType, type ReactElement, type ReactNode } from 'react'
2
-
3
- export function isReactComponent(Component: any): Component is ComponentType<any> {
4
- return (
5
- typeof Component === 'function' &&
6
- // TODO
7
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- React component, it's fine
8
- (Component.prototype instanceof Component || Component.displayName !== undefined)
9
- )
10
- }
11
-
12
- export function isReactElement(element: any): element is ReactElement {
13
- // TODO
14
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- isValidElement is a validation function
15
- return isValidElement(element)
16
- }
17
-
18
- export function isReactNode(node: any): node is ReactNode {
19
- if (
20
- // TODO
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- isValidElement is a validation function
22
- isValidElement(node) || // Check if it's a React element
23
- typeof node === 'string' || // Check if it's a string
24
- typeof node === 'number' // Check if it's a number
25
- ) {
26
- return true
27
- }
28
-
29
- // Check if it's an array of React nodes
30
- if (Array.isArray(node) && node.every((element) => isReactNode(element))) {
31
- return true
32
- }
33
-
34
- return false
35
- }