| 1 |
import React, { createContext, useContext } from "react"; |
| 2 |
|
| 3 |
export const GENERAL_TAXONOMY = "betterdocs_faq_category"; |
| 4 |
export const PRODUCT_TAXONOMY = "betterdocs_product_faq_category"; |
| 5 |
|
| 6 |
// Default scope is the General FAQ taxonomy, so every existing FAQ Builder |
| 7 |
// component keeps its current behavior even when rendered outside a provider. |
| 8 |
const FAQScopeContext = createContext({ |
| 9 |
taxonomy: GENERAL_TAXONOMY, |
| 10 |
isProduct: false, |
| 11 |
}); |
| 12 |
|
| 13 |
export const FAQScopeProvider = ({ taxonomy = GENERAL_TAXONOMY, children }) => { |
| 14 |
const value = { |
| 15 |
taxonomy, |
| 16 |
isProduct: taxonomy === PRODUCT_TAXONOMY, |
| 17 |
}; |
| 18 |
return ( |
| 19 |
<FAQScopeContext.Provider value={value}> |
| 20 |
{children} |
| 21 |
</FAQScopeContext.Provider> |
| 22 |
); |
| 23 |
}; |
| 24 |
|
| 25 |
export const useFAQScope = () => useContext(FAQScopeContext); |
| 26 |
|