@cerberus-design/react 1.0.0-rc.4 → 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 +9 -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,24 +0,0 @@
|
|
|
1
|
-
import { defaultIcons } from './icons/default'
|
|
2
|
-
import type { DefinedIcons, IconType } from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Defines the icons that will be used in Cerberus React components via the
|
|
6
|
-
* CerberusProvider.
|
|
7
|
-
* @param icons The icons that will be used in Cerberus React components.
|
|
8
|
-
* @returns Icons object compatible with the CerberusProvider SystemConfig.
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const icons = defineIcons({
|
|
12
|
-
* accordionIndicator: MyAccordionIndicatorIcon,
|
|
13
|
-
* ...
|
|
14
|
-
* })
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export function defineIcons<T extends IconType>(
|
|
18
|
-
icons: DefinedIcons<T>,
|
|
19
|
-
): Required<DefinedIcons<T>> {
|
|
20
|
-
return {
|
|
21
|
-
...defaultIcons,
|
|
22
|
-
...icons,
|
|
23
|
-
} as Required<DefinedIcons<T>>
|
|
24
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module contains substitute icons for the Checkbox component.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Checkmark icon for Checkbox component
|
|
8
|
-
*/
|
|
9
|
-
export function CheckmarkIcon() {
|
|
10
|
-
return (
|
|
11
|
-
<svg
|
|
12
|
-
aria-hidden="true"
|
|
13
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
14
|
-
fill="none"
|
|
15
|
-
role="img"
|
|
16
|
-
viewBox="0 0 24 24"
|
|
17
|
-
>
|
|
18
|
-
<path
|
|
19
|
-
fill="currentColor"
|
|
20
|
-
d="M9.714 18 4 12.335l1.818-1.764 3.896 3.824L18.181 6 20 7.803 9.714 18Z"
|
|
21
|
-
/>
|
|
22
|
-
</svg>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Indeterminate icon for Checkbox component
|
|
28
|
-
*/
|
|
29
|
-
export function IndeterminateIcon() {
|
|
30
|
-
return (
|
|
31
|
-
<svg
|
|
32
|
-
aria-hidden="true"
|
|
33
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
34
|
-
role="img"
|
|
35
|
-
fill="none"
|
|
36
|
-
viewBox="0 0 24 24"
|
|
37
|
-
>
|
|
38
|
-
<path fill="currentColor" d="M4 11h16v2.667H4z" />
|
|
39
|
-
</svg>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Animated checkmark icon for Clipboard.Indicator component
|
|
45
|
-
*/
|
|
46
|
-
export function AnimatedCheckmarkIcon() {
|
|
47
|
-
return (
|
|
48
|
-
<svg
|
|
49
|
-
aria-hidden="true"
|
|
50
|
-
role="img"
|
|
51
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
52
|
-
viewBox="0 0 24 24"
|
|
53
|
-
>
|
|
54
|
-
<path
|
|
55
|
-
fill="none"
|
|
56
|
-
stroke="currentColor"
|
|
57
|
-
strokeDasharray={24}
|
|
58
|
-
strokeDashoffset={24}
|
|
59
|
-
strokeLinejoin="round"
|
|
60
|
-
strokeWidth={2}
|
|
61
|
-
d="M5 11l6 6l10 -10"
|
|
62
|
-
>
|
|
63
|
-
<animate
|
|
64
|
-
fill="freeze"
|
|
65
|
-
attributeName="stroke-dashoffset"
|
|
66
|
-
dur="0.28s"
|
|
67
|
-
values="24;0"
|
|
68
|
-
></animate>
|
|
69
|
-
</path>
|
|
70
|
-
</svg>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Copy icon for Clipboard.Indicator component
|
|
76
|
-
*/
|
|
77
|
-
export function CopyIcon() {
|
|
78
|
-
return (
|
|
79
|
-
<svg
|
|
80
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
81
|
-
aria-hidden="true"
|
|
82
|
-
role="img"
|
|
83
|
-
viewBox="0 0 32 32"
|
|
84
|
-
>
|
|
85
|
-
<title>copy</title>
|
|
86
|
-
<path
|
|
87
|
-
d="M28 10v18H10V10zm0-2H10a2 2 0 0 0-2 2v18a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V10a2 2 0 0 0-2-2"
|
|
88
|
-
fill="currentColor"
|
|
89
|
-
/>
|
|
90
|
-
<path d="M4 18H2V4a2 2 0 0 1 2-2h14v2H4Z" fill="currentColor" />
|
|
91
|
-
<path
|
|
92
|
-
fill="none"
|
|
93
|
-
d="M0 0h32v32H0z"
|
|
94
|
-
data-name="<Transparent Rectangle>"
|
|
95
|
-
/>
|
|
96
|
-
</svg>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Calendar,
|
|
3
|
-
CaretDown,
|
|
4
|
-
Checkmark,
|
|
5
|
-
CheckmarkOutline,
|
|
6
|
-
ChevronDown,
|
|
7
|
-
ChevronLeft,
|
|
8
|
-
ChevronRight,
|
|
9
|
-
ChevronUp,
|
|
10
|
-
Close,
|
|
11
|
-
CloudUpload,
|
|
12
|
-
Information,
|
|
13
|
-
OverflowMenuVertical,
|
|
14
|
-
Restart,
|
|
15
|
-
TrashCan,
|
|
16
|
-
UserFilled,
|
|
17
|
-
Warning,
|
|
18
|
-
WarningAlt,
|
|
19
|
-
WarningFilled,
|
|
20
|
-
} from '@carbon/icons-react'
|
|
21
|
-
import { AnimatingUploadIcon } from '../../components/AnimatingUploadIcon'
|
|
22
|
-
import { DefinedIcons } from '../types'
|
|
23
|
-
import { CheckmarkIcon, IndeterminateIcon } from './checkbox.icons'
|
|
24
|
-
import {
|
|
25
|
-
PinLeftFilledIcon,
|
|
26
|
-
PinLeftIcon,
|
|
27
|
-
PinRightFilledIcon,
|
|
28
|
-
PinRightIcon,
|
|
29
|
-
} from './pinned.icons'
|
|
30
|
-
import { SortAscIcon, SortDescIcon } from './sort.icons'
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Fallback icons when there is no custom set provided by the user.
|
|
34
|
-
*/
|
|
35
|
-
export const defaultIcons: Required<DefinedIcons> = {
|
|
36
|
-
accordionIndicator: ChevronDown,
|
|
37
|
-
avatar: UserFilled,
|
|
38
|
-
calendar: Calendar,
|
|
39
|
-
calendarPrev: ChevronLeft,
|
|
40
|
-
calendarNext: ChevronRight,
|
|
41
|
-
caretDown: CaretDown,
|
|
42
|
-
checkbox: CheckmarkIcon,
|
|
43
|
-
close: Close,
|
|
44
|
-
confirmModal: Information,
|
|
45
|
-
dangerNotification: WarningFilled,
|
|
46
|
-
decrement: ChevronDown,
|
|
47
|
-
delete: TrashCan,
|
|
48
|
-
fileUploader: AnimatingUploadIcon,
|
|
49
|
-
increment: ChevronUp,
|
|
50
|
-
indeterminate: IndeterminateIcon,
|
|
51
|
-
infoNotification: Information,
|
|
52
|
-
invalid: WarningFilled,
|
|
53
|
-
invalidAlt: Warning,
|
|
54
|
-
moreVertical: OverflowMenuVertical,
|
|
55
|
-
pinLeft: PinLeftIcon,
|
|
56
|
-
pinLeftFilled: PinLeftFilledIcon,
|
|
57
|
-
pinRight: PinRightIcon,
|
|
58
|
-
pinRightFilled: PinRightFilledIcon,
|
|
59
|
-
promptModal: Information,
|
|
60
|
-
redo: Restart,
|
|
61
|
-
selectArrow: ChevronDown,
|
|
62
|
-
selectChecked: Checkmark,
|
|
63
|
-
sortAsc: SortAscIcon,
|
|
64
|
-
sortDesc: SortDescIcon,
|
|
65
|
-
successNotification: CheckmarkOutline,
|
|
66
|
-
toggleChecked: Checkmark,
|
|
67
|
-
waitingFileUploader: CloudUpload,
|
|
68
|
-
warningNotification: WarningAlt,
|
|
69
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { CarbonIconProps, Pin, PinFilled } from '@carbon/icons-react'
|
|
2
|
-
import { PropsWithChildren } from 'react'
|
|
3
|
-
import { Box } from 'styled-system/jsx'
|
|
4
|
-
|
|
5
|
-
export function PinLeftIcon(props: CarbonIconProps) {
|
|
6
|
-
return <Pin {...props} />
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function PinLeftFilledIcon(props: CarbonIconProps) {
|
|
10
|
-
return <PinFilled {...props} />
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function PinRightIcon(props: CarbonIconProps) {
|
|
14
|
-
return (
|
|
15
|
-
<FlippedContainer>
|
|
16
|
-
<Pin {...props} />
|
|
17
|
-
</FlippedContainer>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function PinRightFilledIcon(props: CarbonIconProps) {
|
|
22
|
-
return (
|
|
23
|
-
<FlippedContainer>
|
|
24
|
-
<PinFilled {...props} />
|
|
25
|
-
</FlippedContainer>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function FlippedContainer(props: PropsWithChildren) {
|
|
30
|
-
return <Box transform="scaleX(-1)" {...props} />
|
|
31
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CarbonIconProps, SortAscending } from '@carbon/icons-react'
|
|
2
|
-
import { PropsWithChildren } from 'react'
|
|
3
|
-
import { Box } from 'styled-system/jsx'
|
|
4
|
-
|
|
5
|
-
export function SortAscIcon(props: CarbonIconProps) {
|
|
6
|
-
return <SortAscending {...props} />
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function SortDescIcon(props: CarbonIconProps) {
|
|
10
|
-
return (
|
|
11
|
-
<FlippedContainer>
|
|
12
|
-
<SortAscending {...props} />
|
|
13
|
-
</FlippedContainer>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function FlippedContainer(props: PropsWithChildren) {
|
|
18
|
-
return <Box transform="rotate(180deg)" {...props} />
|
|
19
|
-
}
|
package/src/config/index.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { defaultIcons } from './icons/default'
|
|
2
|
-
import type { SystemConfig } from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a system configuration object to be used on the CerberusProvider.
|
|
6
|
-
* @param options The system configuration options you want to customize.
|
|
7
|
-
* @returns A CerberusProvider-compatible system configuration object.
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* const icons = defineIcons({
|
|
11
|
-
* accordionIndicator: MyAccordionIndicatorIcon,
|
|
12
|
-
* ...
|
|
13
|
-
* })
|
|
14
|
-
* const config = makeSystemConfig({
|
|
15
|
-
* icons,
|
|
16
|
-
* })
|
|
17
|
-
*
|
|
18
|
-
* // In your app
|
|
19
|
-
* <CerberusProvider config={config}>
|
|
20
|
-
* <App />
|
|
21
|
-
* </CerberusProvider>
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function makeSystemConfig(options?: SystemConfig): SystemConfig {
|
|
25
|
-
if (!options) {
|
|
26
|
-
return {
|
|
27
|
-
icons: defaultIcons,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
...options,
|
|
33
|
-
icons: {
|
|
34
|
-
...defaultIcons,
|
|
35
|
-
...options.icons,
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export * from './defineIcons'
|
|
41
|
-
export * from './types'
|
package/src/config/types.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ElementType } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This module contains the types for the Cerberus React configuration.
|
|
5
|
-
* @module config.types
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface SystemConfig {
|
|
9
|
-
/**
|
|
10
|
-
* The icons that will be used in Cerberus React components.
|
|
11
|
-
*/
|
|
12
|
-
icons: Required<DefinedIcons>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface DefinedIcons<T extends IconType = IconType> {
|
|
16
|
-
accordionIndicator?: T
|
|
17
|
-
avatar?: T
|
|
18
|
-
calendar?: T
|
|
19
|
-
calendarPrev?: T
|
|
20
|
-
calendarNext?: T
|
|
21
|
-
caretDown?: T
|
|
22
|
-
checkbox?: T
|
|
23
|
-
close?: T
|
|
24
|
-
confirmModal?: T
|
|
25
|
-
decrement?: T
|
|
26
|
-
delete?: T
|
|
27
|
-
dangerNotification?: T
|
|
28
|
-
fileUploader?: T
|
|
29
|
-
indeterminate?: T
|
|
30
|
-
increment?: T
|
|
31
|
-
infoNotification?: T
|
|
32
|
-
invalid?: T
|
|
33
|
-
invalidAlt?: T
|
|
34
|
-
moreVertical?: T
|
|
35
|
-
pinLeft?: T
|
|
36
|
-
pinLeftFilled?: T
|
|
37
|
-
pinRight?: T
|
|
38
|
-
pinRightFilled?: T
|
|
39
|
-
promptModal?: T
|
|
40
|
-
redo?: T
|
|
41
|
-
selectArrow?: T
|
|
42
|
-
selectChecked?: T
|
|
43
|
-
sortAsc?: T
|
|
44
|
-
sortDesc?: T
|
|
45
|
-
successNotification?: T
|
|
46
|
-
toggleChecked?: T
|
|
47
|
-
waitingFileUploader?: T
|
|
48
|
-
warningNotification?: T
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// types
|
|
52
|
-
|
|
53
|
-
export type IconType = ElementType
|
package/src/context/cerberus.tsx
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useContext,
|
|
6
|
-
useMemo,
|
|
7
|
-
type PropsWithChildren,
|
|
8
|
-
} from 'react'
|
|
9
|
-
import { makeSystemConfig, type SystemConfig } from '../config'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This module contains the Cerberus configuration context and helpers.
|
|
13
|
-
* @module context/cerberus
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
type CerberusContextValue = SystemConfig
|
|
17
|
-
|
|
18
|
-
const CerberusContext = createContext<CerberusContextValue | null>(null)
|
|
19
|
-
|
|
20
|
-
interface CerberusProviderProps {
|
|
21
|
-
config?: SystemConfig
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Cerberus configuration provider.
|
|
26
|
-
* @param props.config The Cerberus configuration created with
|
|
27
|
-
* `makeSystemConfig` helper.
|
|
28
|
-
*/
|
|
29
|
-
export function CerberusProvider(
|
|
30
|
-
props: PropsWithChildren<CerberusProviderProps>,
|
|
31
|
-
) {
|
|
32
|
-
const value = useMemo(() => {
|
|
33
|
-
return props.config || makeSystemConfig()
|
|
34
|
-
}, [props.config])
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<CerberusContext.Provider value={value}>
|
|
38
|
-
{props.children}
|
|
39
|
-
</CerberusContext.Provider>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns the Cerberus configuration context.
|
|
45
|
-
* @returns The Cerberus configuration context.
|
|
46
|
-
*/
|
|
47
|
-
export function useCerberusContext() {
|
|
48
|
-
const context = useContext(CerberusContext)
|
|
49
|
-
if (!context) {
|
|
50
|
-
throw new Error('useCerberus must be used within a CerberusProvider')
|
|
51
|
-
}
|
|
52
|
-
return context
|
|
53
|
-
}
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useMemo,
|
|
8
|
-
useRef,
|
|
9
|
-
useState,
|
|
10
|
-
type MouseEvent,
|
|
11
|
-
type PropsWithChildren,
|
|
12
|
-
type ReactNode,
|
|
13
|
-
} from 'react'
|
|
14
|
-
import { css } from 'styled-system/css'
|
|
15
|
-
import { HStack, VStack } from 'styled-system/jsx'
|
|
16
|
-
import { Button } from '../components/button/button'
|
|
17
|
-
import { Show } from '../components/show/index'
|
|
18
|
-
import { Avatar } from '../components/avatar/avatar'
|
|
19
|
-
import {
|
|
20
|
-
Dialog,
|
|
21
|
-
DialogCloseTrigger,
|
|
22
|
-
DialogDescription,
|
|
23
|
-
DialogHeading,
|
|
24
|
-
DialogProvider,
|
|
25
|
-
type OpenChangeDetails,
|
|
26
|
-
type DialogRootProps,
|
|
27
|
-
} from '../components/dialog'
|
|
28
|
-
import { useCerberusContext } from './cerberus'
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* This module provides a context and hook for the confirm modal.
|
|
32
|
-
* @module
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export interface BaseConfirmOptions {
|
|
36
|
-
/**
|
|
37
|
-
* The heading of the confirm modal.
|
|
38
|
-
*/
|
|
39
|
-
heading: string
|
|
40
|
-
/**
|
|
41
|
-
* The text for the action button.
|
|
42
|
-
*/
|
|
43
|
-
actionText: string
|
|
44
|
-
/**
|
|
45
|
-
* The text for the cancel button.
|
|
46
|
-
*/
|
|
47
|
-
cancelText: string
|
|
48
|
-
/**
|
|
49
|
-
* Whether to show the avatar icon at the top of the modal.
|
|
50
|
-
* @default true
|
|
51
|
-
*/
|
|
52
|
-
showAvatar?: boolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface DestructiveConfirmOptions extends BaseConfirmOptions {
|
|
56
|
-
/**
|
|
57
|
-
* The kind of confirm modal to show.
|
|
58
|
-
*/
|
|
59
|
-
kind?: 'destructive'
|
|
60
|
-
/**
|
|
61
|
-
* The description of the confirm modal. Can only be a string for destructive confirm modals.
|
|
62
|
-
*/
|
|
63
|
-
description?: ReactNode
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface NonDestructiveConfirmModalOptions extends BaseConfirmOptions {
|
|
67
|
-
/**
|
|
68
|
-
* The kind of confirm modal to show.
|
|
69
|
-
* @default 'non-destructive'
|
|
70
|
-
*/
|
|
71
|
-
kind?: 'non-destructive'
|
|
72
|
-
/**
|
|
73
|
-
* The description of the confirm modal. Can be a ReactNode for non-destructive kind if you need to display text links.
|
|
74
|
-
* @example
|
|
75
|
-
* ```tsx
|
|
76
|
-
* description: <>Use a Fragment because we put the content within a Paragraph tag.</>
|
|
77
|
-
*/
|
|
78
|
-
description?: ReactNode
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type ShowConfirmModalOptions =
|
|
82
|
-
| NonDestructiveConfirmModalOptions
|
|
83
|
-
| DestructiveConfirmOptions
|
|
84
|
-
|
|
85
|
-
export type ShowResult = ((value: boolean | null) => void) | null
|
|
86
|
-
|
|
87
|
-
export interface ConfirmModalValue {
|
|
88
|
-
show: (options: ShowConfirmModalOptions) => Promise<boolean | null>
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const ConfirmModalContext = createContext<ConfirmModalValue | null>(null)
|
|
92
|
-
|
|
93
|
-
export type ConfirmModalProviderProps = PropsWithChildren<DialogRootProps>
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Provides a confirm modal to the app.
|
|
97
|
-
* @see https://cerberus.digitalu.design/react/confirm-modal
|
|
98
|
-
* @example
|
|
99
|
-
* ```tsx
|
|
100
|
-
* // Wrap the Provider around the root of the feature.
|
|
101
|
-
* <ConfirmModal>
|
|
102
|
-
* <SomeFeatureSection />
|
|
103
|
-
* </ConfirmModal>
|
|
104
|
-
*
|
|
105
|
-
* // Use the hook to show the confirm modal.
|
|
106
|
-
* const confirm = useConfirmModal()
|
|
107
|
-
*
|
|
108
|
-
* const handleClick = useCallback(async () => {
|
|
109
|
-
* const userConsent = await confirm.show({
|
|
110
|
-
* heading: 'Add new payment method?',
|
|
111
|
-
* description:
|
|
112
|
-
* 'This will add a new payment method to your account to be billed for future purchases.',
|
|
113
|
-
* actionText: 'Yes, add payment method',
|
|
114
|
-
* cancelText: 'No, cancel',
|
|
115
|
-
* })
|
|
116
|
-
* setConsent(userConsent)
|
|
117
|
-
* }, [confirm])
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export function ConfirmModal(
|
|
121
|
-
props: PropsWithChildren<ConfirmModalProviderProps>,
|
|
122
|
-
) {
|
|
123
|
-
const { children, ...rootProps } = props
|
|
124
|
-
const [open, setOpen] = useState<boolean>(false)
|
|
125
|
-
const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)
|
|
126
|
-
|
|
127
|
-
const resolveRef = useRef<ShowResult>(null)
|
|
128
|
-
|
|
129
|
-
const showAvatar = content?.showAvatar ?? true
|
|
130
|
-
const kind = content?.kind ?? 'non-destructive'
|
|
131
|
-
|
|
132
|
-
const { icons } = useCerberusContext()
|
|
133
|
-
const { confirmModal: ConfirmIcon } = icons
|
|
134
|
-
|
|
135
|
-
const palette = useMemo(
|
|
136
|
-
() => (kind === 'destructive' ? 'danger' : 'action'),
|
|
137
|
-
[kind],
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
const handleChoice = useCallback(
|
|
141
|
-
(e: MouseEvent<HTMLButtonElement>) => {
|
|
142
|
-
const target = e.currentTarget as HTMLButtonElement
|
|
143
|
-
if (target.value === 'true') {
|
|
144
|
-
resolveRef.current?.(true)
|
|
145
|
-
}
|
|
146
|
-
resolveRef.current?.(false)
|
|
147
|
-
setOpen(false)
|
|
148
|
-
},
|
|
149
|
-
[setOpen],
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
const handleShow = useCallback(
|
|
153
|
-
(options: ShowConfirmModalOptions) => {
|
|
154
|
-
return new Promise<boolean | null>((resolve) => {
|
|
155
|
-
setContent({ ...options })
|
|
156
|
-
setOpen(true)
|
|
157
|
-
resolveRef.current = resolve
|
|
158
|
-
})
|
|
159
|
-
},
|
|
160
|
-
[setOpen, setContent],
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
const handleOpenChange = useCallback(
|
|
164
|
-
({ open }: OpenChangeDetails) => {
|
|
165
|
-
setOpen(open)
|
|
166
|
-
if (!open) {
|
|
167
|
-
resolveRef.current?.(null)
|
|
168
|
-
resolveRef.current = null
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
[setOpen],
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
const value = useMemo(
|
|
175
|
-
() => ({
|
|
176
|
-
show: handleShow,
|
|
177
|
-
}),
|
|
178
|
-
[handleShow],
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<ConfirmModalContext.Provider value={value}>
|
|
183
|
-
{children}
|
|
184
|
-
|
|
185
|
-
<DialogProvider
|
|
186
|
-
lazyMount
|
|
187
|
-
open={open}
|
|
188
|
-
onOpenChange={handleOpenChange}
|
|
189
|
-
unmountOnExit
|
|
190
|
-
{...rootProps}
|
|
191
|
-
>
|
|
192
|
-
<Dialog
|
|
193
|
-
size="sm"
|
|
194
|
-
style={{
|
|
195
|
-
'--dialog-content-min-h': 'auto',
|
|
196
|
-
}}
|
|
197
|
-
>
|
|
198
|
-
<VStack
|
|
199
|
-
alignItems="flex-start"
|
|
200
|
-
gap="md"
|
|
201
|
-
justify="space-between"
|
|
202
|
-
w="full"
|
|
203
|
-
>
|
|
204
|
-
<Show when={showAvatar}>
|
|
205
|
-
<HStack
|
|
206
|
-
alignSelf="center"
|
|
207
|
-
justify="center"
|
|
208
|
-
paddingBlockEnd="md"
|
|
209
|
-
w="full"
|
|
210
|
-
>
|
|
211
|
-
<Show
|
|
212
|
-
when={palette === 'danger'}
|
|
213
|
-
fallback={
|
|
214
|
-
<Avatar
|
|
215
|
-
gradient="charon-light"
|
|
216
|
-
fallback={<ConfirmIcon size={24} />}
|
|
217
|
-
/>
|
|
218
|
-
}
|
|
219
|
-
>
|
|
220
|
-
<Avatar
|
|
221
|
-
gradient="hades-dark"
|
|
222
|
-
fallback={<ConfirmIcon size={24} />}
|
|
223
|
-
/>
|
|
224
|
-
</Show>
|
|
225
|
-
</HStack>
|
|
226
|
-
</Show>
|
|
227
|
-
|
|
228
|
-
<DialogHeading>{content?.heading}</DialogHeading>
|
|
229
|
-
|
|
230
|
-
<Show when={content?.description}>
|
|
231
|
-
<DialogDescription>{content?.description}</DialogDescription>
|
|
232
|
-
</Show>
|
|
233
|
-
|
|
234
|
-
<HStack gap="md" pt="md" w="full">
|
|
235
|
-
<Button
|
|
236
|
-
autoFocus
|
|
237
|
-
className={css({
|
|
238
|
-
w: '1/2',
|
|
239
|
-
})}
|
|
240
|
-
name="confirm"
|
|
241
|
-
onClick={handleChoice}
|
|
242
|
-
palette={palette}
|
|
243
|
-
value="true"
|
|
244
|
-
>
|
|
245
|
-
{content?.actionText}
|
|
246
|
-
</Button>
|
|
247
|
-
<DialogCloseTrigger asChild>
|
|
248
|
-
<Button
|
|
249
|
-
className={css({
|
|
250
|
-
w: '1/2',
|
|
251
|
-
})}
|
|
252
|
-
name="cancel"
|
|
253
|
-
onClick={handleChoice}
|
|
254
|
-
usage="outlined"
|
|
255
|
-
value="false"
|
|
256
|
-
>
|
|
257
|
-
{content?.cancelText}
|
|
258
|
-
</Button>
|
|
259
|
-
</DialogCloseTrigger>
|
|
260
|
-
</HStack>
|
|
261
|
-
</VStack>
|
|
262
|
-
</Dialog>
|
|
263
|
-
</DialogProvider>
|
|
264
|
-
</ConfirmModalContext.Provider>
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export function useConfirmModal(): ConfirmModalValue {
|
|
269
|
-
const context = useContext(ConfirmModalContext)
|
|
270
|
-
if (context === null) {
|
|
271
|
-
throw new Error(
|
|
272
|
-
'useConfirmModal must be used within a ConfirmModal Provider',
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
return context
|
|
276
|
-
}
|