diff --git a/packages/dnb-design-system-portal/src/docs/uilib/usage/customisation/theming/theme/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/usage/customisation/theming/theme/info.mdx index 62c1332fb26..5caa49b10b0 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/usage/customisation/theming/theme/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/usage/customisation/theming/theme/info.mdx @@ -25,6 +25,8 @@ render( ) ``` +**NB:** If no context is given, the hook will return `null`. + From CSS you can use it as so: - `.eufemia-theme__sbanken` diff --git a/packages/dnb-eufemia/src/shared/useTheme.tsx b/packages/dnb-eufemia/src/shared/useTheme.tsx index 4a874436d03..e0bbce95fdb 100644 --- a/packages/dnb-eufemia/src/shared/useTheme.tsx +++ b/packages/dnb-eufemia/src/shared/useTheme.tsx @@ -3,16 +3,25 @@ * */ -import React from 'react' +import { useContext } from 'react' import Context from './Context' +import type { ThemeProps } from './Theme' -export default function useTheme() { - const context = React.useContext(Context) +export type UseThemeReturn = + | (ThemeProps & { + isUi: boolean + isSbanken: boolean + isEiendom: boolean + }) + | null - if (context?.theme) { - const { name } = context.theme +export default function useTheme(): UseThemeReturn { + const { theme } = useContext(Context) || {} + + if (theme) { + const { name } = theme return { - ...context.theme, + ...theme, isUi: name === 'ui', isSbanken: name === 'sbanken', isEiendom: name === 'eiendom',