ThemeProvider.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from 'react';
  2. type DefaultThemeAsObject<T = object> = Record<keyof T, any>;
  3. /**
  4. * Override DefaultTheme to get accurate typings for your project.
  5. *
  6. * ```
  7. * // create styled-components.d.ts in your project source
  8. * // if it isn't being picked up, check tsconfig compilerOptions.types
  9. * import type { CSSProp } from "styled-components";
  10. * import Theme from './theme';
  11. *
  12. * type ThemeType = typeof Theme;
  13. *
  14. * declare module "styled-components" {
  15. * export interface DefaultTheme extends ThemeType {}
  16. * }
  17. *
  18. * declare module "react" {
  19. * interface DOMAttributes<T> {
  20. * css?: CSSProp;
  21. * }
  22. * }
  23. * ```
  24. */
  25. export interface DefaultTheme extends DefaultThemeAsObject {
  26. }
  27. type ThemeFn = (outerTheme?: DefaultTheme | undefined) => DefaultTheme;
  28. type ThemeArgument = DefaultTheme | ThemeFn;
  29. type Props = {
  30. children?: React.ReactNode;
  31. theme: ThemeArgument;
  32. };
  33. export declare const ThemeContext: React.Context<DefaultTheme | undefined>;
  34. export declare const ThemeConsumer: React.Consumer<DefaultTheme | undefined>;
  35. /**
  36. * Returns the current theme (as provided by the closest ancestor `ThemeProvider`.)
  37. *
  38. * If no `ThemeProvider` is found, the function will error. If you need access to the theme in an
  39. * uncertain composition scenario, `React.useContext(ThemeContext)` will not emit an error if there
  40. * is no `ThemeProvider` ancestor.
  41. */
  42. export declare function useTheme(): DefaultTheme;
  43. /**
  44. * Provide a theme to an entire react component tree via context
  45. */
  46. export default function ThemeProvider(props: Props): React.JSX.Element | null;
  47. export {};