Source

atoms/layout/layout.tsx

  1. import React, { Fragment } from "react";
  2. import { Layout as LayoutTypes } from "./types";
  3. import { Theme } from "../../context/theme";
  4. import { StoryProvider } from "../../context/story/story-context";
  5. import { ConfigProvider } from "../../context/config/config-context";
  6. import { getTokensFromAMPConfig } from "../../utils/theme";
  7. import styled from "styled-components";
  8. const Container = styled.div`
  9. font-family: ${(props) => props.theme.font.family.primary};
  10. position: relative;
  11. `;
  12. /**
  13. *
  14. * Layout component is a wrapper and provider of story, config and theme context. Therefore, most library components that consome context need to be wrapped with layout
  15. *
  16. * ```js
  17. * <Layout story={textStory} config={config}>
  18. * <Navbar />
  19. * <div>
  20. * <TopAd />
  21. * <Spacer token="s" />
  22. * <HeaderCard />
  23. * </div>
  24. * </Layout>
  25. * ```
  26. *
  27. * @param {Object} params object containing parameters passed to the render prop
  28. * @param {Story} params.story story object
  29. * @param {Config} params.config config object
  30. * @param {Object} params.children child components
  31. *
  32. * @category Atoms
  33. * @component
  34. *
  35. */
  36. export const Layout = ({ children, story, config }: LayoutTypes) => {
  37. const tokens = getTokensFromAMPConfig(config.ampConfig);
  38. return (
  39. <Fragment>
  40. <ConfigProvider value={config}>
  41. <StoryProvider value={story}>
  42. <Theme tokens={tokens}>
  43. <Container>{children}</Container>
  44. </Theme>
  45. </StoryProvider>
  46. </ConfigProvider>
  47. </Fragment>
  48. );
  49. };