npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@d24/ui-checkout-lib

v1.3.0

Published

This guide explains how to integrate and use the theme in your project using `ThemeProvider` and `styled-components`. By following this approach, your components will be able to dynamically adapt to theme changes.

Downloads

235

Readme

D24 Checkout components

This guide explains how to integrate and use the theme in your project using ThemeProvider and styled-components. By following this approach, your components will be able to dynamically adapt to theme changes.

Prerequisites

  • Ensure you have styled-components installed in your project.
  • Ensure you have the ThemeProvider from styled-components.

Setup

1. Define Your Theme

First, define your theme object. This object contains all the styles and properties you want to use across your project.

You can find the theme definition in the checkoutTheme.js file. Link to checkoutTheme.js

2. Set Up ThemeProvider

Wrap your application with ThemeProvider and pass the theme object as a prop.

// ./index.js

import { ThemeProvider } from 'styled-components';
import { checkoutTheme } from '@d24/ui-checkout-lib';

ReactDOM.render(
  <ThemeProvider theme={checkoutTheme}>
    <Provider store={store}>
      <App />
    </Provider>
  </ThemeProvider>,
  document.getElementById('root')
);

3. Use Theme in Styled Components

Use the theme in your styled-components by accessing the theme prop. Here's some examples:

export const StyledTitle = styled.h2`
  ${({ theme }) => theme.font.body.title.default};
  ...
`;
const buttonTypeStyles = {
  primary: css`
    background-color: ${({ theme }) => theme.color.button.primary.background.default};
    color: ${({ theme }) => theme.color.button.primary.text.color.default};

    &:hover:not(:disabled) {
      background-color: ${({ theme }) => theme.color.button.primary.background.hover};
    }

    &:active:not(:disabled) {
      background-color: ${({ theme }) => theme.color.button.primary.background.active};
    }
  `,
  secondary: css`
    background-color: ${({ theme }) => theme.color.button.secondary.background.default};
    color: ${({ theme }) => theme.color.button.secondary.text.color.default};
    border: 1px solid ${({ theme }) => theme.color.button.secondary.border.color.default};

    &:hover:not(:disabled) {
      border: 2px solid ${({ theme }) => theme.color.button.secondary.border.color.default};
    }

    &:active:not(:disabled) {
      background-color: ${({ theme }) => theme.color.button.secondary.background.active};
      color: ${({ theme }) => theme.color.button.secondary.text.color.active};
      border: 2px solid ${({ theme }) => theme.color.button.secondary.border.color.default};
    }

    &:disabled {
      background-color: ${({ theme }) => theme.color.button.secondary.background.default};
      color: ${({ theme }) => theme.color.button.secondary.text.color.disabled};
      border: 1px solid ${({ theme }) => theme.color.button.secondary.border.color.disabled};
    }
  `,
  link: css`
    color: ${({ theme }) => theme.color.button.tertiary.text.color.default};
    font-size: ${({ theme }) => theme.font.body.paragraphXxs.default.fontSize};
  `,
};

By following this setup, your components will adapt to the theme changes provided by the ThemeProvider.

4. Using the Render Function in Tests Wrapped with Theme

In your .test files, make sure to use the render function as demonstrated below. This will wrap the components with the ThemeProvider, allowing them to receive the theme prop correctly.

import { CheckoutThemeWrapper, createRenderFunction } from './test.utils';

const render = createRenderFunction(CheckoutThemeWrapper);

Integrating the Library into Other Projects

To integrate this library into another project, follow these steps:

1. Install the Library

Install the library using npm or yarn.

npm i @d24/ui-checkout-lib
# or
yarn add @d24/ui-checkout-lib

2. Import and Wrap Your Application

Import the ThemeProvider and your theme from the library, then wrap your application with ThemeProvider and pass the theme object as a prop.

// ./index.js

import { ThemeProvider } from 'styled-components';
import { checkoutTheme } from '@d24/ui-checkout-lib';

ReactDOM.render(
  <ThemeProvider theme={checkoutTheme}>
    <Provider store={store}>
      <App />
    </Provider>
  </ThemeProvider>,
  document.getElementById('root')
);