@driveflux/ui 1.0.13 → 1.1.0

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 (85) 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/use-enhanced-modal.d.ts.map +1 -1
  21. package/dist/theme/colors.d.ts.map +1 -1
  22. package/dist/theme/colors.js +36 -36
  23. package/dist/toast/index.d.ts.map +1 -1
  24. package/dist/translations.d.ts.map +1 -1
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/utils/accessors.d.ts.map +1 -1
  27. package/dist/utils/react.d.ts.map +1 -1
  28. package/package.json +30 -29
  29. package/.eslintrc.json +0 -3
  30. package/.swcrc +0 -14
  31. package/.turbo/turbo-build.log +0 -11
  32. package/CHANGELOG.md +0 -150
  33. package/dist/cjs/chakra.js +0 -18
  34. package/dist/cjs/index.js +0 -20
  35. package/dist/cjs/modal/ModalProvider.js +0 -255
  36. package/dist/cjs/modal/components/EnhancedModalCustomWrapper.js +0 -139
  37. package/dist/cjs/modal/components/EnhancedModalFooter.js +0 -163
  38. package/dist/cjs/modal/components/MinimalModalContent.js +0 -94
  39. package/dist/cjs/modal/components/StandardModalContent.js +0 -359
  40. package/dist/cjs/modal/context.js +0 -20
  41. package/dist/cjs/modal/index.js +0 -48
  42. package/dist/cjs/modal/use-enhanced-modal.js +0 -15
  43. package/dist/cjs/theme/colors.js +0 -147
  44. package/dist/cjs/theme/index.js +0 -18
  45. package/dist/cjs/toast/index.js +0 -19
  46. package/dist/cjs/toast/use-toast-result.js +0 -210
  47. package/dist/cjs/translations.js +0 -42
  48. package/dist/cjs/types.js +0 -4
  49. package/dist/cjs/utils/accessors.js +0 -65
  50. package/dist/cjs/utils/index.js +0 -19
  51. package/dist/cjs/utils/react.js +0 -56
  52. package/dist/index.js +0 -3
  53. package/index.cjs +0 -1
  54. package/index.d.ts +0 -1
  55. package/modal.cjs +0 -1
  56. package/modal.d.ts +0 -1
  57. package/src/chakra.ts +0 -2
  58. package/src/index.ts +0 -4
  59. package/src/modal/ModalProvider.tsx +0 -143
  60. package/src/modal/components/EnhancedModalCustomWrapper.tsx +0 -39
  61. package/src/modal/components/EnhancedModalFooter.tsx +0 -51
  62. package/src/modal/components/MinimalModalContent.tsx +0 -24
  63. package/src/modal/components/StandardModalContent.tsx +0 -65
  64. package/src/modal/context.tsx +0 -81
  65. package/src/modal/index.ts +0 -7
  66. package/src/modal/use-enhanced-modal.ts +0 -7
  67. package/src/theme/colors.ts +0 -179
  68. package/src/theme/index.ts +0 -1
  69. package/src/toast/index.ts +0 -3
  70. package/src/toast/use-toast-result.tsx +0 -168
  71. package/src/translations.ts +0 -25
  72. package/src/types.ts +0 -22
  73. package/src/utils/accessors.ts +0 -64
  74. package/src/utils/index.ts +0 -2
  75. package/src/utils/react.ts +0 -35
  76. package/theme.cjs +0 -1
  77. package/theme.d.ts +0 -1
  78. package/toast.cjs +0 -1
  79. package/toast.d.ts +0 -1
  80. package/translations.cjs +0 -1
  81. package/translations.d.ts +0 -1
  82. package/tsconfig.json +0 -14
  83. package/tsconfig.tsbuildinfo +0 -1
  84. package/utils.cjs +0 -1
  85. package/utils.d.ts +0 -1
@@ -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
- }
package/theme.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/cjs/theme/index.js')
package/theme.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/theme/index'
package/toast.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/cjs/toast/index.js')
package/toast.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/toast/index'
package/translations.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/cjs/translations.js')
package/translations.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/translations'
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@driveflux/tsconfig/frontend.json",
4
- "compilerOptions": {
5
- "declaration": true,
6
- "rootDir": "src",
7
- "outDir": "./dist"
8
- },
9
- "include": [
10
- "src/**/*.ts",
11
- "src/**/*.tsx"
12
- ],
13
- "exclude": ["node_modules"]
14
- }