Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@twilio-paste/color-contrast-utils

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twilio-paste/color-contrast-utils

Shared utilities for checking color contrast in Paste

  • 5.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by31.1%
Maintainers
4
Weekly downloads
 
Created
Source

Utils

Design Tokens provides a number of utility methods that you can use to determine the accessibility of a given theme of Design Tokens.

Here, as an example, you can inspect the current theme of the application you are in by grabbing the theme context, converting it to Design Tokens and passing it through the utils.

import {generateTokensFromTheme, useTheme} from '@twilio-paste/core/theme';
import {
  getContrastRatingsOfTokensWithTextContrastRequirements,
  getContrastRatingsOfTokensWithUIControlContrastRequirements,
  getNumberOfTextFailures,
  getNumberOfUIControlFailures,
} from '@twilio-paste/design-tokens/dist/contrast-rating/utils';

const SomewhereInYourApp = () => {
  const theme = useTheme();
  const designTokens = generateTokensFromTheme(theme);

  const textContrastRating = getContrastRatingsOfTokensWithTextContrastRequirements(designTokens);
  const uiControlContrastRating = getContrastRatingsOfTokensWithUIControlContrastRequirements(designTokens);

  const numberOfTextFailures = getNumberOfTextFailures(textContrastRating);
  const numberOfUIControlFailures = getNumberOfUIControlFailures(uiControlContrastRating);

  return <div />;
};

When used as a child of the Paste Theme or Customization provider, these utilities will enable you to rate each foreground / background design token pairing for it's accessibility.

import {CustomizationProvider} from '@twilio-paste/core/customization';

const App = () => {
  return (
    <CustomizationProvider theme={{}}>
      <SomewhereInYourApp />
    </CustomizationProvider>
  );
};

FAQs

Package last updated on 11 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc