@@ -10,6 +10,7 @@ import {
10
10
DOMElements ,
11
11
} from '@chakra-ui/vue-system'
12
12
import { SystemStyleObject } from '@chakra-ui/styled-system'
13
+ import { createContext } from '@chakra-ui/vue-utils/src'
13
14
import { CIcon } from '@chakra-ui/c-icon'
14
15
15
16
const STATUSES = {
@@ -34,10 +35,16 @@ const STATUSES = {
34
35
type AlertStatus = keyof typeof STATUSES
35
36
export type AlertVariant = 'solid' | 'subtle' | 'left-accent' | 'top-accent'
36
37
37
- interface AlertState {
38
+ interface AlertContext {
38
39
status : AlertStatus
39
40
}
40
41
42
+ const [ AlertProvider , useAlertContext ] = createContext < AlertContext > ( {
43
+ name : 'AlertContext' ,
44
+ errorMessage :
45
+ 'useAlertContext: `context` is undefined. Seems you forgot to wrap alert components in `<c-alert />`' ,
46
+ } )
47
+
41
48
/**
42
49
* CAlert component
43
50
*
@@ -85,7 +92,7 @@ export const CAlert = defineComponent({
85
92
}
86
93
87
94
provideComponentStyles ( 'Alert' , styles . value )
88
- provide ( '$AlertState' , { status : props . status } as AlertState )
95
+ AlertProvider ( { status : props . status } )
89
96
90
97
return ( ) =>
91
98
h (
@@ -157,8 +164,8 @@ export const CAlertIcon = defineComponent({
157
164
} ,
158
165
} ,
159
166
setup ( props , { attrs } ) {
160
- const alertState = inject < AlertState > ( '$AlertState' )
161
- const { icon } = STATUSES [ alertState ?. status as AlertStatus ]
167
+ const { status } = useAlertContext ( )
168
+ const { icon } = STATUSES [ status ]
162
169
const styles = useComponentStyles ( 'Alert' )
163
170
164
171
const alertIcon = computed ( ( ) => props . icon || icon )
0 commit comments