@cerberus-design/react 1.0.0-rc.5 → 1.0.0-rc.6
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/dist/panda.buildinfo.json +23 -0
- package/package.json +6 -4
- package/src/components/AnimatingUploadIcon.tsx +0 -83
- package/src/components/accordion/index.ts +0 -3
- package/src/components/accordion/item-group.tsx +0 -70
- package/src/components/accordion/item-indicator.tsx +0 -27
- package/src/components/accordion/parts.ts +0 -53
- package/src/components/accordion/primitives.tsx +0 -86
- package/src/components/admonition/admonition.tsx +0 -62
- package/src/components/admonition/index.ts +0 -3
- package/src/components/admonition/match-avatar.tsx +0 -52
- package/src/components/admonition/parts.ts +0 -53
- package/src/components/admonition/primitives.tsx +0 -77
- package/src/components/avatar/avatar.tsx +0 -51
- package/src/components/avatar/index.ts +0 -5
- package/src/components/avatar/parts.ts +0 -37
- package/src/components/avatar/primitives.tsx +0 -38
- package/src/components/button/button.tsx +0 -62
- package/src/components/button/index.ts +0 -3
- package/src/components/button/parts.ts +0 -32
- package/src/components/button/primitives.tsx +0 -41
- package/src/components/carousel/carousel.tsx +0 -55
- package/src/components/carousel/index.ts +0 -3
- package/src/components/carousel/parts.ts +0 -71
- package/src/components/carousel/primitives.ts +0 -58
- package/src/components/checkbox/checkbox-icon.tsx +0 -39
- package/src/components/checkbox/checkbox.tsx +0 -42
- package/src/components/checkbox/index.ts +0 -3
- package/src/components/checkbox/parts.ts +0 -59
- package/src/components/checkbox/primitives.tsx +0 -77
- package/src/components/circular-progress/circular-progress.tsx +0 -49
- package/src/components/circular-progress/index.ts +0 -2
- package/src/components/circular-progress/primitives.ts +0 -80
- package/src/components/clipboard/copy-indicator.tsx +0 -22
- package/src/components/clipboard/copy-text.tsx +0 -13
- package/src/components/clipboard/index.ts +0 -2
- package/src/components/clipboard/parts.ts +0 -74
- package/src/components/clipboard/primitives.ts +0 -56
- package/src/components/clipboard/trigger.tsx +0 -14
- package/src/components/collapsible/index.ts +0 -2
- package/src/components/collapsible/parts.ts +0 -53
- package/src/components/collapsible/primitives.tsx +0 -53
- package/src/components/combobox/combobox.tsx +0 -67
- package/src/components/combobox/index.ts +0 -6
- package/src/components/combobox/item-group.tsx +0 -19
- package/src/components/combobox/item.tsx +0 -30
- package/src/components/combobox/parts.ts +0 -101
- package/src/components/combobox/primitives.tsx +0 -146
- package/src/components/combobox/use-stateful-collection.ts +0 -65
- package/src/components/cta-dialog/context.tsx +0 -38
- package/src/components/cta-dialog/index.ts +0 -2
- package/src/components/cta-dialog/provider.tsx +0 -186
- package/src/components/cta-dialog/trigger-item.tsx +0 -54
- package/src/components/cta-dialog/utils.ts +0 -57
- package/src/components/date-picker/calendar.tsx +0 -47
- package/src/components/date-picker/content.tsx +0 -21
- package/src/components/date-picker/date-picker.tsx +0 -20
- package/src/components/date-picker/day-view.tsx +0 -82
- package/src/components/date-picker/index.ts +0 -16
- package/src/components/date-picker/input.tsx +0 -26
- package/src/components/date-picker/month-view.tsx +0 -49
- package/src/components/date-picker/parts.ts +0 -167
- package/src/components/date-picker/primitives.tsx +0 -235
- package/src/components/date-picker/range-input.tsx +0 -38
- package/src/components/date-picker/trigger.tsx +0 -28
- package/src/components/date-picker/view-control-group.tsx +0 -54
- package/src/components/date-picker/year-view.tsx +0 -47
- package/src/components/dialog/close-icon-trigger.tsx +0 -36
- package/src/components/dialog/dialog.tsx +0 -42
- package/src/components/dialog/index.ts +0 -8
- package/src/components/dialog/parts.ts +0 -71
- package/src/components/dialog/primitives.tsx +0 -83
- package/src/components/feature-flag/feature-flag.tsx +0 -21
- package/src/components/feature-flag/index.ts +0 -1
- package/src/components/field/error-text.tsx +0 -19
- package/src/components/field/field.tsx +0 -93
- package/src/components/field/helper-text.tsx +0 -20
- package/src/components/field/index.ts +0 -7
- package/src/components/field/input.tsx +0 -47
- package/src/components/field/parts.ts +0 -77
- package/src/components/field/primitives.tsx +0 -135
- package/src/components/field/start-indicator.tsx +0 -23
- package/src/components/field/status-indicator.tsx +0 -58
- package/src/components/fieldset/fieldset.tsx +0 -54
- package/src/components/fieldset/index.ts +0 -3
- package/src/components/fieldset/parts.ts +0 -47
- package/src/components/fieldset/primitives.tsx +0 -48
- package/src/components/file-upload/file-status.tsx +0 -271
- package/src/components/file-upload/file-uploader.tsx +0 -60
- package/src/components/file-upload/helpers.ts +0 -28
- package/src/components/file-upload/img-preview.tsx +0 -41
- package/src/components/file-upload/index.ts +0 -6
- package/src/components/file-upload/parts.tsx +0 -132
- package/src/components/file-upload/primitives.ts +0 -161
- package/src/components/file-upload/utils.ts +0 -20
- package/src/components/for/for.tsx +0 -38
- package/src/components/for/index.ts +0 -1
- package/src/components/group/index.ts +0 -1
- package/src/components/group/primitives.ts +0 -7
- package/src/components/icon-button/button.tsx +0 -41
- package/src/components/icon-button/index.tsx +0 -2
- package/src/components/icon-button/primitives.ts +0 -19
- package/src/components/menu/index.ts +0 -2
- package/src/components/menu/menu.tsx +0 -144
- package/src/components/menu/primitives.ts +0 -84
- package/src/components/notifications/center.tsx +0 -88
- package/src/components/notifications/close-trigger.tsx +0 -21
- package/src/components/notifications/index.ts +0 -5
- package/src/components/notifications/match-icon.tsx +0 -41
- package/src/components/notifications/parts.ts +0 -53
- package/src/components/notifications/primitives.tsx +0 -66
- package/src/components/notifications/toaster.ts +0 -13
- package/src/components/notifications/types.ts +0 -44
- package/src/components/number-input/decrement-trigger.tsx +0 -16
- package/src/components/number-input/increment-trigger.tsx +0 -16
- package/src/components/number-input/index.ts +0 -3
- package/src/components/number-input/input.tsx +0 -33
- package/src/components/number-input/parts.ts +0 -65
- package/src/components/number-input/primitives.tsx +0 -74
- package/src/components/pagination/compact.tsx +0 -25
- package/src/components/pagination/index.ts +0 -6
- package/src/components/pagination/item-list.tsx +0 -34
- package/src/components/pagination/item.tsx +0 -6
- package/src/components/pagination/pagination.tsx +0 -53
- package/src/components/pagination/parts.ts +0 -65
- package/src/components/pagination/primitives.ts +0 -41
- package/src/components/pagination/triggers.tsx +0 -55
- package/src/components/pin-input/index.ts +0 -3
- package/src/components/pin-input/input.tsx +0 -22
- package/src/components/pin-input/parts.ts +0 -53
- package/src/components/pin-input/primitives.tsx +0 -46
- package/src/components/portal/index.ts +0 -1
- package/src/components/portal/portal.tsx +0 -28
- package/src/components/progress/index.ts +0 -2
- package/src/components/progress/primitives.ts +0 -37
- package/src/components/progress/progress-bar.tsx +0 -80
- package/src/components/radio/index.ts +0 -3
- package/src/components/radio/parts.ts +0 -65
- package/src/components/radio/primitives.tsx +0 -92
- package/src/components/radio/radio.tsx +0 -35
- package/src/components/rating/index.ts +0 -8
- package/src/components/rating/parts.tsx +0 -65
- package/src/components/rating/primitives.tsx +0 -64
- package/src/components/rating/rating.tsx +0 -75
- package/src/components/select/index.ts +0 -5
- package/src/components/select/option-group.tsx +0 -32
- package/src/components/select/option.tsx +0 -42
- package/src/components/select/parts.ts +0 -113
- package/src/components/select/primitives.tsx +0 -147
- package/src/components/select/select.tsx +0 -110
- package/src/components/show/index.ts +0 -1
- package/src/components/show/show.tsx +0 -48
- package/src/components/spinner/index.ts +0 -1
- package/src/components/spinner/spinner.tsx +0 -81
- package/src/components/split-button/button.tsx +0 -63
- package/src/components/split-button/index.tsx +0 -1
- package/src/components/switch/index.ts +0 -3
- package/src/components/switch/parts.ts +0 -53
- package/src/components/switch/primitives.tsx +0 -51
- package/src/components/switch/switch-indicator.tsx +0 -9
- package/src/components/switch/switch.tsx +0 -27
- package/src/components/table/index.ts +0 -3
- package/src/components/table/parts.ts +0 -83
- package/src/components/table/primitives.tsx +0 -115
- package/src/components/table/table.tsx +0 -73
- package/src/components/tabs/index.ts +0 -3
- package/src/components/tabs/parts.ts +0 -53
- package/src/components/tabs/primitives.tsx +0 -47
- package/src/components/tabs/tabs.tsx +0 -48
- package/src/components/tag/closable.tsx +0 -47
- package/src/components/tag/index.ts +0 -2
- package/src/components/tag/primitives.ts +0 -19
- package/src/components/tag/tag.tsx +0 -39
- package/src/components/text/index.ts +0 -1
- package/src/components/text/text.tsx +0 -55
- package/src/components/theme/index.ts +0 -1
- package/src/components/theme/theme.tsx +0 -34
- package/src/components/toggle/index.ts +0 -2
- package/src/components/toggle/parts.ts +0 -32
- package/src/components/toggle/primitives.tsx +0 -27
- package/src/components/tooltip/index.ts +0 -3
- package/src/components/tooltip/parts.ts +0 -59
- package/src/components/tooltip/primitives.ts +0 -56
- package/src/components/tooltip/tooltip.tsx +0 -46
- package/src/config/defineIcons.ts +0 -24
- package/src/config/icons/checkbox.icons.tsx +0 -98
- package/src/config/icons/default.ts +0 -69
- package/src/config/icons/pinned.icons.tsx +0 -31
- package/src/config/icons/sort.icons.tsx +0 -19
- package/src/config/index.ts +0 -41
- package/src/config/types.ts +0 -53
- package/src/context/cerberus.tsx +0 -53
- package/src/context/confirm-modal.tsx +0 -276
- package/src/context/feature-flags.tsx +0 -63
- package/src/context/field.tsx +0 -70
- package/src/context/navMenu.tsx +0 -89
- package/src/context/prompt-modal.tsx +0 -315
- package/src/context/theme.tsx +0 -83
- package/src/hooks/useModal.ts +0 -63
- package/src/hooks/useRootColors.ts +0 -72
- package/src/hooks/useTheme.ts +0 -121
- package/src/index.client.ts +0 -30
- package/src/index.ts +0 -76
- package/src/system/factory.ts +0 -32
- package/src/system/index.ts +0 -47
- package/src/system/primitive-factory.tsx +0 -180
- package/src/system/types.ts +0 -88
- package/src/types.ts +0 -23
- package/src/utils/index.ts +0 -51
- package/src/utils/localStorage.ts +0 -28
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, type PropsWithChildren } from 'react'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This module provides a context and hook for feature flags.
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export interface FeatureFlagValue {
|
|
11
|
-
[key: string]: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const FeatureFlagContext = createContext<FeatureFlagValue | null>(null)
|
|
15
|
-
|
|
16
|
-
export interface FeatureFlagProviderProps {
|
|
17
|
-
flags: FeatureFlagValue
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Provides feature flags to the application.
|
|
22
|
-
* @see https://cerberus.digitalu.design/react/feature-flags
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* // This should be a JSON file or a server response.
|
|
26
|
-
* const flags = {
|
|
27
|
-
* featureOne: true,
|
|
28
|
-
* featureTwo: false
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* // Wrap the Provider around the root of your application.
|
|
32
|
-
* <FeatureFlags flags={flags}>
|
|
33
|
-
* <FeatureFlag flag="featureOne">
|
|
34
|
-
* This is visible.
|
|
35
|
-
* </FeatureFlag>
|
|
36
|
-
* <FeatureFlag flag="featureTwo">
|
|
37
|
-
* This is hidden.
|
|
38
|
-
* </FeatureFlag>
|
|
39
|
-
* </FeatureFlags>
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export function FeatureFlags(
|
|
43
|
-
props: PropsWithChildren<FeatureFlagProviderProps>,
|
|
44
|
-
) {
|
|
45
|
-
return (
|
|
46
|
-
<FeatureFlagContext.Provider value={props.flags}>
|
|
47
|
-
{props.children}
|
|
48
|
-
</FeatureFlagContext.Provider>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Used to retrieve the context of the FeatureFlags provider.
|
|
54
|
-
*/
|
|
55
|
-
export function useFeatureFlags(key: string): boolean {
|
|
56
|
-
const context = useContext(FeatureFlagContext)
|
|
57
|
-
if (context === null) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
'useFeatureFlag must be used within a FeatureFlags Provider',
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
return context[key] ?? false
|
|
63
|
-
}
|
package/src/context/field.tsx
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import type { FieldRootProps } from '@ark-ui/react/field'
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useContext,
|
|
7
|
-
useMemo,
|
|
8
|
-
type PropsWithChildren,
|
|
9
|
-
} from 'react'
|
|
10
|
-
import { FieldRoot } from '../components/field/primitives'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This module provides a context and hook for the field.
|
|
14
|
-
* @module Field
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export interface FieldContextValue {
|
|
18
|
-
/**
|
|
19
|
-
* Whether the field is disabled.
|
|
20
|
-
* @description [Moz Input Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes)
|
|
21
|
-
*/
|
|
22
|
-
disabled?: boolean
|
|
23
|
-
/**
|
|
24
|
-
* Whether the field is read-only.
|
|
25
|
-
*/
|
|
26
|
-
readOnly?: boolean
|
|
27
|
-
/**
|
|
28
|
-
* Whether the field is required.
|
|
29
|
-
*/
|
|
30
|
-
required?: boolean
|
|
31
|
-
/**
|
|
32
|
-
* Whether the field is invalid.
|
|
33
|
-
*/
|
|
34
|
-
invalid?: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const FieldContext = createContext<FieldContextValue | null>(null)
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated use FieldRoot or FieldParts instead
|
|
41
|
-
*/
|
|
42
|
-
export function FieldProvider(props: PropsWithChildren<FieldRootProps>) {
|
|
43
|
-
const value = useMemo(
|
|
44
|
-
() => ({
|
|
45
|
-
disabled: props.disabled,
|
|
46
|
-
readOnly: props.readOnly,
|
|
47
|
-
required: props.required,
|
|
48
|
-
invalid: props.invalid,
|
|
49
|
-
}),
|
|
50
|
-
[props.disabled, props.readOnly, props.required, props.invalid],
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<FieldContext.Provider value={value}>
|
|
55
|
-
<FieldRoot {...props} />
|
|
56
|
-
</FieldContext.Provider>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Used to access the field context.
|
|
62
|
-
* @returns The field context.
|
|
63
|
-
*/
|
|
64
|
-
export function useFieldContext(): FieldContextValue {
|
|
65
|
-
const context = useContext(FieldContext)
|
|
66
|
-
if (!context) {
|
|
67
|
-
throw new Error('useFieldContext must be used within a Field Provider.')
|
|
68
|
-
}
|
|
69
|
-
return context
|
|
70
|
-
}
|
package/src/context/navMenu.tsx
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { css } from 'styled-system/css'
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useCallback,
|
|
7
|
-
useContext,
|
|
8
|
-
useMemo,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
type PropsWithChildren,
|
|
12
|
-
type RefObject,
|
|
13
|
-
} from 'react'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This module provides a context and hook for the nav menu.
|
|
17
|
-
* @module NavMenu
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
export type NavTriggerRef = RefObject<HTMLButtonElement | null>
|
|
21
|
-
export type NavMenuRef = RefObject<HTMLUListElement | null>
|
|
22
|
-
|
|
23
|
-
export interface NavMenuContextValue {
|
|
24
|
-
/**
|
|
25
|
-
* The ref for the trigger button.
|
|
26
|
-
*/
|
|
27
|
-
triggerRef: NavTriggerRef
|
|
28
|
-
/**
|
|
29
|
-
* The ref for the menu.
|
|
30
|
-
*/
|
|
31
|
-
menuRef: NavMenuRef
|
|
32
|
-
/**
|
|
33
|
-
* Whether the menu is expanded.
|
|
34
|
-
*/
|
|
35
|
-
expanded: boolean
|
|
36
|
-
/**
|
|
37
|
-
* Called when the menu button is clicked.
|
|
38
|
-
*/
|
|
39
|
-
onToggle: () => void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const NavMenuContext = createContext<NavMenuContextValue | null>(null)
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated use the {@link Menu} family instead
|
|
46
|
-
*/
|
|
47
|
-
export function NavMenu(props: PropsWithChildren) {
|
|
48
|
-
const triggerRef = useRef<HTMLButtonElement | null>(null)
|
|
49
|
-
const menuRef = useRef<HTMLUListElement | null>(null)
|
|
50
|
-
const [expanded, setExpanded] = useState<boolean>(false)
|
|
51
|
-
|
|
52
|
-
const handleToggle = useCallback(() => {
|
|
53
|
-
setExpanded((prev) => !prev)
|
|
54
|
-
}, [])
|
|
55
|
-
|
|
56
|
-
const value = useMemo(
|
|
57
|
-
() => ({
|
|
58
|
-
triggerRef,
|
|
59
|
-
menuRef,
|
|
60
|
-
expanded,
|
|
61
|
-
onToggle: handleToggle,
|
|
62
|
-
}),
|
|
63
|
-
[expanded, handleToggle],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<NavMenuContext.Provider value={value}>
|
|
68
|
-
<nav
|
|
69
|
-
className={css({
|
|
70
|
-
position: 'relative',
|
|
71
|
-
})}
|
|
72
|
-
>
|
|
73
|
-
{props.children}
|
|
74
|
-
</nav>
|
|
75
|
-
</NavMenuContext.Provider>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Used to access the nav menu context.
|
|
81
|
-
* @returns The nav menu context.
|
|
82
|
-
*/
|
|
83
|
-
export function useNavMenuContext(): NavMenuContextValue {
|
|
84
|
-
const context = useContext(NavMenuContext)
|
|
85
|
-
if (!context) {
|
|
86
|
-
throw new Error('useNavMenuContext must be used within a NavMenu.')
|
|
87
|
-
}
|
|
88
|
-
return context
|
|
89
|
-
}
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
type ChangeEvent,
|
|
11
|
-
type MouseEvent,
|
|
12
|
-
type PropsWithChildren,
|
|
13
|
-
} from 'react'
|
|
14
|
-
import { DialogCloseTrigger } from '@ark-ui/react/dialog'
|
|
15
|
-
import { HStack, VStack } from 'styled-system/jsx'
|
|
16
|
-
import { css } from 'styled-system/css'
|
|
17
|
-
import { hstack } from 'styled-system/patterns'
|
|
18
|
-
import { FieldLabel, FieldRoot, Input } from '../components/field/index'
|
|
19
|
-
import { Button } from '../components/button/button'
|
|
20
|
-
import { Clipboard } from '../components/clipboard/index'
|
|
21
|
-
import { Show } from '../components/show/index'
|
|
22
|
-
import { Avatar } from '../components/avatar/avatar'
|
|
23
|
-
import { Text } from '../components/text/index'
|
|
24
|
-
import { IconButton } from '../components/icon-button/index'
|
|
25
|
-
import {
|
|
26
|
-
Dialog,
|
|
27
|
-
DialogDescription,
|
|
28
|
-
DialogHeading,
|
|
29
|
-
DialogProvider,
|
|
30
|
-
DialogRootProps,
|
|
31
|
-
} from '../components/dialog/index'
|
|
32
|
-
import { useCerberusContext } from './cerberus'
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* This module provides a context and hook for the prompt modal.
|
|
36
|
-
* @module PromptModal
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export interface ShowPromptModalOptions {
|
|
40
|
-
/**
|
|
41
|
-
* The kind of prompt modal to show.
|
|
42
|
-
* @default 'non-destructive'
|
|
43
|
-
*/
|
|
44
|
-
kind?: 'destructive' | 'non-destructive'
|
|
45
|
-
/**
|
|
46
|
-
* The heading of the prompt modal.
|
|
47
|
-
*/
|
|
48
|
-
heading: string
|
|
49
|
-
/**
|
|
50
|
-
* The description of the prompt modal.
|
|
51
|
-
*/
|
|
52
|
-
description?: string
|
|
53
|
-
/**
|
|
54
|
-
* The key to confirm the action.
|
|
55
|
-
*/
|
|
56
|
-
key: string
|
|
57
|
-
/**
|
|
58
|
-
* The text for the action button.
|
|
59
|
-
*/
|
|
60
|
-
actionText: string
|
|
61
|
-
/**
|
|
62
|
-
* The text for the cancel button.
|
|
63
|
-
*/
|
|
64
|
-
cancelText: string
|
|
65
|
-
}
|
|
66
|
-
export type PromptShowResult =
|
|
67
|
-
| ((value: string | PromiseLike<string>) => void)
|
|
68
|
-
| null
|
|
69
|
-
|
|
70
|
-
export interface PromptModalValue {
|
|
71
|
-
/**
|
|
72
|
-
* The method to trigger the prompt modal.
|
|
73
|
-
* @returns the value of the key if the action is confirmed.
|
|
74
|
-
* @example
|
|
75
|
-
* ```tsx
|
|
76
|
-
* const accepted = await prompt.show({
|
|
77
|
-
* kind: 'destructive',
|
|
78
|
-
* heading: 'Delete channel?',
|
|
79
|
-
* description:
|
|
80
|
-
* 'This will permanently delete a channel on your account. There is no going back.',
|
|
81
|
-
* key: CHANNEL_NAME,
|
|
82
|
-
* actionText: 'Yes, delete channel',
|
|
83
|
-
* cancelText: 'No, cancel',
|
|
84
|
-
* })
|
|
85
|
-
*/
|
|
86
|
-
show: (options: ShowPromptModalOptions) => Promise<string>
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const PromptModalContext = createContext<PromptModalValue | null>(null)
|
|
90
|
-
|
|
91
|
-
export type PromptModalProviderProps = PropsWithChildren<DialogRootProps>
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Provides a prompt modal to the app.
|
|
95
|
-
* @see https://cerberus.digitalu.design/react/prompt-modal
|
|
96
|
-
* @example
|
|
97
|
-
* ```tsx
|
|
98
|
-
* // Wrap the Provider around the root of the feature.
|
|
99
|
-
* <PromptModal>
|
|
100
|
-
* <SomeFeatureSection />
|
|
101
|
-
* </PromptModal>
|
|
102
|
-
*
|
|
103
|
-
* // Use the hook to show the prompt modal.
|
|
104
|
-
* const prompt = usePromptModal()
|
|
105
|
-
*
|
|
106
|
-
* const handleClick = useCallback(async () => {
|
|
107
|
-
* const accepted = await prompt.show({
|
|
108
|
-
* kind: 'destructive',
|
|
109
|
-
* heading: 'Delete channel?',
|
|
110
|
-
* description:
|
|
111
|
-
* 'This will permanently delete a channel on your account. There is no going back.',
|
|
112
|
-
* key: CHANNEL_NAME,
|
|
113
|
-
* actionText: 'Yes, delete channel',
|
|
114
|
-
* cancelText: 'No, cancel',
|
|
115
|
-
* })
|
|
116
|
-
* // do something with accepted
|
|
117
|
-
* }, [prompt])
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export function PromptModal(
|
|
121
|
-
props: PropsWithChildren<PromptModalProviderProps>,
|
|
122
|
-
) {
|
|
123
|
-
const { children, ...rootProps } = props
|
|
124
|
-
|
|
125
|
-
const [open, setOpen] = useState<boolean>(false)
|
|
126
|
-
const [content, setContent] = useState<ShowPromptModalOptions | null>(null)
|
|
127
|
-
const [inputValue, setInputValue] = useState<string>('')
|
|
128
|
-
|
|
129
|
-
const resolveRef = useRef<PromptShowResult>(null)
|
|
130
|
-
|
|
131
|
-
const { icons } = useCerberusContext()
|
|
132
|
-
const { promptModal: PromptIcon } = icons
|
|
133
|
-
|
|
134
|
-
const isValid = useMemo(
|
|
135
|
-
() => inputValue === content?.key,
|
|
136
|
-
[inputValue, content],
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
const palette = useMemo(
|
|
140
|
-
() => (content?.kind === 'destructive' ? 'danger' : 'action'),
|
|
141
|
-
[content],
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
const handleChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
|
145
|
-
setInputValue(e.currentTarget.value)
|
|
146
|
-
}, [])
|
|
147
|
-
|
|
148
|
-
const handleChoice = useCallback(
|
|
149
|
-
(e: MouseEvent<HTMLButtonElement>) => {
|
|
150
|
-
const target = e.currentTarget as HTMLButtonElement
|
|
151
|
-
if (target.value === 'true') {
|
|
152
|
-
resolveRef.current?.(inputValue)
|
|
153
|
-
}
|
|
154
|
-
setOpen(false)
|
|
155
|
-
},
|
|
156
|
-
[inputValue, setOpen],
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
const handleShow = useCallback(
|
|
160
|
-
(options: ShowPromptModalOptions) => {
|
|
161
|
-
return new Promise<string>((resolve) => {
|
|
162
|
-
setContent({ ...options, kind: options.kind || 'non-destructive' })
|
|
163
|
-
setOpen(true)
|
|
164
|
-
resolveRef.current = resolve
|
|
165
|
-
})
|
|
166
|
-
},
|
|
167
|
-
[setOpen],
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
const value = useMemo(
|
|
171
|
-
() => ({
|
|
172
|
-
show: handleShow,
|
|
173
|
-
}),
|
|
174
|
-
[handleShow],
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<PromptModalContext.Provider value={value}>
|
|
179
|
-
{children}
|
|
180
|
-
|
|
181
|
-
<DialogProvider
|
|
182
|
-
lazyMount
|
|
183
|
-
open={open}
|
|
184
|
-
onOpenChange={(e) => setOpen(e.open)}
|
|
185
|
-
unmountOnExit
|
|
186
|
-
{...rootProps}
|
|
187
|
-
>
|
|
188
|
-
<Dialog
|
|
189
|
-
size="sm"
|
|
190
|
-
style={{
|
|
191
|
-
'--dialog-content-min-h': 'auto',
|
|
192
|
-
}}
|
|
193
|
-
>
|
|
194
|
-
<VStack
|
|
195
|
-
alignItems="flex-start"
|
|
196
|
-
h="full"
|
|
197
|
-
justify="space-between"
|
|
198
|
-
w="full"
|
|
199
|
-
>
|
|
200
|
-
<HStack
|
|
201
|
-
alignSelf="center"
|
|
202
|
-
justify="center"
|
|
203
|
-
paddingBlockEnd="md"
|
|
204
|
-
w="full"
|
|
205
|
-
>
|
|
206
|
-
<Show
|
|
207
|
-
when={palette === 'danger'}
|
|
208
|
-
fallback={
|
|
209
|
-
<Avatar
|
|
210
|
-
gradient="charon-light"
|
|
211
|
-
fallback={<PromptIcon size={24} />}
|
|
212
|
-
/>
|
|
213
|
-
}
|
|
214
|
-
>
|
|
215
|
-
<Avatar
|
|
216
|
-
gradient="hades-dark"
|
|
217
|
-
fallback={<PromptIcon size={24} />}
|
|
218
|
-
/>
|
|
219
|
-
</Show>
|
|
220
|
-
</HStack>
|
|
221
|
-
|
|
222
|
-
<DialogHeading>{content?.heading}</DialogHeading>
|
|
223
|
-
<DialogDescription>{content?.description}</DialogDescription>
|
|
224
|
-
|
|
225
|
-
<VStack
|
|
226
|
-
alignItems="flex-start"
|
|
227
|
-
marginBlockStart="md"
|
|
228
|
-
marginBlockEnd="lg"
|
|
229
|
-
w="full"
|
|
230
|
-
>
|
|
231
|
-
<FieldRoot invalid={!isValid}>
|
|
232
|
-
<FieldLabel
|
|
233
|
-
className={hstack({
|
|
234
|
-
gap: 'xs',
|
|
235
|
-
justify: 'flex-start',
|
|
236
|
-
marginBlockEnd: 'xs',
|
|
237
|
-
textStyle: 'label-md',
|
|
238
|
-
w: 'initial',
|
|
239
|
-
})}
|
|
240
|
-
>
|
|
241
|
-
Type
|
|
242
|
-
<Clipboard.Root value={content?.key || ''}>
|
|
243
|
-
<Clipboard.Control asChild>
|
|
244
|
-
<HStack gap="xs" w="full">
|
|
245
|
-
<Clipboard.Label asChild>
|
|
246
|
-
<Text as="strong" userSelect="text">
|
|
247
|
-
{content?.key}
|
|
248
|
-
</Text>
|
|
249
|
-
</Clipboard.Label>
|
|
250
|
-
|
|
251
|
-
<Clipboard.Trigger asChild>
|
|
252
|
-
<IconButton
|
|
253
|
-
clipboard
|
|
254
|
-
shape="square"
|
|
255
|
-
size="sm"
|
|
256
|
-
rounded="xs"
|
|
257
|
-
>
|
|
258
|
-
<Clipboard.Indicator />
|
|
259
|
-
</IconButton>
|
|
260
|
-
</Clipboard.Trigger>
|
|
261
|
-
</HStack>
|
|
262
|
-
</Clipboard.Control>
|
|
263
|
-
</Clipboard.Root>
|
|
264
|
-
to confirm
|
|
265
|
-
</FieldLabel>
|
|
266
|
-
<Input name="confirm" onChange={handleChange} type="text" />
|
|
267
|
-
</FieldRoot>
|
|
268
|
-
</VStack>
|
|
269
|
-
|
|
270
|
-
<HStack gap="md" justify="stretch" w="full">
|
|
271
|
-
<Button
|
|
272
|
-
autoFocus
|
|
273
|
-
className={css({
|
|
274
|
-
w: '1/2',
|
|
275
|
-
})}
|
|
276
|
-
disabled={!isValid}
|
|
277
|
-
name="confirm"
|
|
278
|
-
onClick={handleChoice}
|
|
279
|
-
palette={palette}
|
|
280
|
-
value="true"
|
|
281
|
-
>
|
|
282
|
-
{content?.actionText}
|
|
283
|
-
</Button>
|
|
284
|
-
|
|
285
|
-
<DialogCloseTrigger asChild>
|
|
286
|
-
<Button
|
|
287
|
-
className={css({
|
|
288
|
-
w: '1/2',
|
|
289
|
-
})}
|
|
290
|
-
name="cancel"
|
|
291
|
-
onClick={handleChoice}
|
|
292
|
-
usage="outlined"
|
|
293
|
-
value="false"
|
|
294
|
-
>
|
|
295
|
-
{content?.cancelText}
|
|
296
|
-
</Button>
|
|
297
|
-
</DialogCloseTrigger>
|
|
298
|
-
</HStack>
|
|
299
|
-
</VStack>
|
|
300
|
-
</Dialog>
|
|
301
|
-
</DialogProvider>
|
|
302
|
-
</PromptModalContext.Provider>
|
|
303
|
-
)
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Used to retrieve the context of the PromptModal provider.
|
|
308
|
-
*/
|
|
309
|
-
export function usePromptModal(): PromptModalValue {
|
|
310
|
-
const context = useContext(PromptModalContext)
|
|
311
|
-
if (context === null) {
|
|
312
|
-
throw new Error('usePromptModal must be used within a PromptModal Provider')
|
|
313
|
-
}
|
|
314
|
-
return context
|
|
315
|
-
}
|
package/src/context/theme.tsx
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext, type PropsWithChildren } from 'react'
|
|
4
|
-
import { useTheme, type UseThemeOptions } from '../hooks/useTheme'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This module provides a context and hook for the theme.
|
|
8
|
-
* @module Theme
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export type DefaultThemes = 'cerberus' | 'acheron' | 'elysium'
|
|
12
|
-
export type CustomThemes<K extends string = DefaultThemes> = 'cerberus' | K
|
|
13
|
-
export type ColorModes = 'light' | 'dark' | 'system'
|
|
14
|
-
|
|
15
|
-
export interface ThemeContextValue<T extends string = DefaultThemes> {
|
|
16
|
-
/**
|
|
17
|
-
* The current theme.
|
|
18
|
-
*/
|
|
19
|
-
theme: CustomThemes<T>
|
|
20
|
-
/**
|
|
21
|
-
* The current color mode.
|
|
22
|
-
*/
|
|
23
|
-
mode: ColorModes
|
|
24
|
-
/**
|
|
25
|
-
* Called when the theme is updated.
|
|
26
|
-
*/
|
|
27
|
-
updateTheme: (theme: T) => void
|
|
28
|
-
/**
|
|
29
|
-
* Called when the color mode is updated.
|
|
30
|
-
*/
|
|
31
|
-
updateMode: (mode: ColorModes) => void
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ThemeContext = createContext<ThemeContextValue<DefaultThemes> | null>(
|
|
35
|
-
null,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
export interface ThemeProviderProps extends UseThemeOptions {
|
|
39
|
-
/**
|
|
40
|
-
* The default theme.
|
|
41
|
-
*/
|
|
42
|
-
defaultTheme?: DefaultThemes
|
|
43
|
-
/**
|
|
44
|
-
* The default color mode.
|
|
45
|
-
*/
|
|
46
|
-
defaultColorMode?: ColorModes
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A context provider that allows the user to set the theme and mode of the
|
|
51
|
-
* application.
|
|
52
|
-
* @see https://cerberus.digitalu.design/react/use-theme-context
|
|
53
|
-
* @example
|
|
54
|
-
* ```tsx
|
|
55
|
-
* <ThemeProvider>
|
|
56
|
-
* <App />
|
|
57
|
-
* </ThemeProvider>
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export function ThemeProvider(props: PropsWithChildren<ThemeProviderProps>) {
|
|
61
|
-
const state = useTheme(props.defaultTheme, props.defaultColorMode, {
|
|
62
|
-
cache: props.cache,
|
|
63
|
-
updateMode: props.updateMode,
|
|
64
|
-
updateTheme: props.updateTheme,
|
|
65
|
-
}) as ThemeContextValue<DefaultThemes>
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<ThemeContext.Provider value={state}>
|
|
69
|
-
{props.children}
|
|
70
|
-
</ThemeContext.Provider>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Used to access the theme context.
|
|
76
|
-
*/
|
|
77
|
-
export function useThemeContext(): ThemeContextValue<DefaultThemes> {
|
|
78
|
-
const context = useContext(ThemeContext)
|
|
79
|
-
if (!context) {
|
|
80
|
-
throw new Error('useThemeContext must be used within a ThemeProvider')
|
|
81
|
-
}
|
|
82
|
-
return context
|
|
83
|
-
}
|
package/src/hooks/useModal.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { useCallback, useMemo, useRef, useState, type RefObject } from 'react'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This module provides a hook for using a custom modal.
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export interface UseModalReturnValue {
|
|
11
|
-
/**
|
|
12
|
-
* The ref for the modal.
|
|
13
|
-
*/
|
|
14
|
-
modalRef: RefObject<HTMLDialogElement | null>
|
|
15
|
-
/**
|
|
16
|
-
* Shows the modal.
|
|
17
|
-
*/
|
|
18
|
-
show: () => void
|
|
19
|
-
/**
|
|
20
|
-
* Closes the modal.
|
|
21
|
-
*/
|
|
22
|
-
close: () => void
|
|
23
|
-
/**
|
|
24
|
-
* Whether the modal is open based on the show and close methods.
|
|
25
|
-
*/
|
|
26
|
-
isOpen: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Provides a hook for using a custom modal via the native dialog element
|
|
31
|
-
* methods.
|
|
32
|
-
*
|
|
33
|
-
* Cerberus modals use the native dialog element. This hook
|
|
34
|
-
* does not control the modal via React state but rather by calling the
|
|
35
|
-
* native dialog element's `showModal` and `close` methods.
|
|
36
|
-
*
|
|
37
|
-
* @memberof module:Modal
|
|
38
|
-
* @see https://cerberus.digitalu.design/react/modal
|
|
39
|
-
* @description [Moz Dev Dialog Docs](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)
|
|
40
|
-
*/
|
|
41
|
-
export function useModal(): UseModalReturnValue {
|
|
42
|
-
const modalRef = useRef<HTMLDialogElement | null>(null)
|
|
43
|
-
const [isOpen, setIsOpen] = useState<boolean>(false)
|
|
44
|
-
|
|
45
|
-
const show = useCallback(() => {
|
|
46
|
-
modalRef.current?.showModal()
|
|
47
|
-
setIsOpen(true)
|
|
48
|
-
}, [])
|
|
49
|
-
|
|
50
|
-
const close = useCallback(() => {
|
|
51
|
-
modalRef.current?.close()
|
|
52
|
-
setIsOpen(false)
|
|
53
|
-
}, [])
|
|
54
|
-
|
|
55
|
-
return useMemo(() => {
|
|
56
|
-
return {
|
|
57
|
-
modalRef,
|
|
58
|
-
show,
|
|
59
|
-
close,
|
|
60
|
-
isOpen,
|
|
61
|
-
}
|
|
62
|
-
}, [modalRef, show, close, isOpen])
|
|
63
|
-
}
|