0.38.0 • Published 4 months ago

@clds/blender v0.38.0

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

@clds/blender


npm version

This is Cloudinary Design System color blending tool.

In Cloudinary Design System, we explicitly define styles of any surface. A surface consists of background color, foreground color, and typography type.

If you implement some design, and you can't decide which defined surface style to use, probably we have design issue where not allowed mix of foreground, background and typography was used.

This tool allows you to generate valid colors and typography for all existing derived states for all design system components.

Base colors come from palette (primary, secondary, surface, ...) but we allow to mix them using special restricting rules.

Input parameters you can put into the blender:

  • blend variant - the color name from palette which implies the color theme (error, warning, primary...)
  • blend mode, where you define how background and foreground are mixed together
    • plainSolid - no background, solid foreground (same as variant)
    • plainContrast - no background, contrastHigh foreground
    • surfaceSolid - surface background, solid foreground (same as variant)
    • surfaceContrast - surface background, contrastHigh foreground
    • solidContrast - solid background (same as variant), contrastInvert foreground (contrasting to solid background)
  • blend intensity, which imitates interaction states - designers decide how to map state to the intensity individually per component
    • sm - ie. for button it is used for hover states
    • md - ie. for button it is used usually for normal states
    • lg - ie. for button it is used usually for selected states
    • xl - ie. for button it is used usually for hover+selected states

Output parameters you get from the blender:

  • background color
  • foreground color
  • typography type

Blending rule

Single component's surface should be build using only methods from blender. In case of plain backgrounds (plainSolid, plainContrast) we shouldn't use them to create layers inside component. This means specifically, that we can't create two overlaying div elements with plain background to achieve new surface. However, two independent components could be used in the way, where plain surface of one component overlays the other one. For example: subtle alert (surfaceSolid, sm) can consist of plain button in hover state (plainSolid, sm), creating new surface which is not achievable from blender.

API

blenderBackground()

Styled component mixin you can use for background colors in your blender-supporting component.

blenderForeground()

Styled component mixin you can use for foreground colors in your blender-supporting component.

getBlenderTypographyType()

function that returns you proper typography type for your state.

Usage

Easiest way to consume blender is to create styled components and use getBlenderTypographyType together with <Typography/> component:

import {
  blenderBackground,
  blenderForeground,
  getBlenderTypographyType,
} from '@clds/blender';
// other imports

const Root = styled.div`
  background-color: ${blenderBackground};
`;

const Icon = styled.svg`
  fill: ${blenderForeground};
`;

const Example = (props) => (
  <Root {...props}>
    <Icon {...props} path="..." />
    <Typography
      as="span"
      size="sm"
      type={getBlenderTypographyType(props.mode, props.variant)}
    >
      This is just the demo
    </Typography>
  </Root>
);

Example.defaultProps = {
  variant: 'error',
  mode: 'plainSolid',
  intensity: 'lg',
};

blenderCss

This an accompanying solution that allows to communicate about blender surface through CSS variables.

populateVariables()

Creates a styled mixin that will provide all necessary blender variables based on blender props passed as an argument.

backgroundFromCssVariables

Styled mixin that reads blender background from CSS variable

foregroundFromCssVariables

Styled mixin that reads blender foreground from CSS variable

typographyFromCssVariables()

Creates styled mixin that, for specific typography size, defines all typography-related properties from CSS variables.

Example

This is an example of creating a surface that establishes blender css variables based on pseudo selectors.

import styled from 'styled-components';
import { blenderCss } from '@clds/blender';

const Button = styled.button`
  ${blenderCss.populateVariables({
    mode: 'plainContrast',
    variant: 'primary',
    intensity: 'md',
  })};

  &:hover,
  &:focus-visible {
    ${blenderCss.populateVariables({
      mode: 'solidContrast',
      variant: 'primary',
      intensity: 'lg',
    })};
  }

  &:active {
    ${blenderCss.populateVariables({
      mode: 'solidContrast',
      variant: 'primary',
      intensity: 'xl',
    })};
  }

  background-color: ${blenderCss.backgroundFromCssVariables};
  border: 1px solid ${blenderCss.borderColorFromCssVariables};
`;

const LogoIcon = styled.div`
  background: ${blenderCss.foregroundFromCssVariables};
`;

const Text = styled.p`
  ${blenderCss.typographyFromCssVariables('xs')};
`;

export const Example = () => (
  <Button>
    <LogoIcon />
    <Text>Hello</Text>
  </Button>
);

Versioning

This library follows Semantic Versioning.

License

See LICENSE

0.38.0

4 months ago

0.37.0

5 months ago

0.36.3

6 months ago

0.36.2

6 months ago

0.36.1

6 months ago

0.36.0

7 months ago

0.32.4

10 months ago

0.34.0

9 months ago

0.33.10

9 months ago

0.33.7

9 months ago

0.33.6

9 months ago

0.35.3

8 months ago

0.33.5

10 months ago

0.35.2

8 months ago

0.35.1

8 months ago

0.33.3

10 months ago

0.35.0

8 months ago

0.33.2

10 months ago

0.33.1

10 months ago

0.33.0

10 months ago

0.33.9

9 months ago

0.33.8

9 months ago

0.32.3

11 months ago

0.32.2

11 months ago

0.32.1

11 months ago

0.32.0

12 months ago

0.30.1

12 months ago

0.30.0

12 months ago

0.29.0

12 months ago

0.27.0

12 months ago

0.23.4

1 year ago

0.23.3

1 year ago

0.25.0

1 year ago

0.23.2

1 year ago

0.23.1

1 year ago

0.23.0

1 year ago

0.21.0

1 year ago

0.31.1

12 months ago

0.31.0

12 months ago

0.28.1

12 months ago

0.28.0

12 months ago

0.26.1

12 months ago

0.26.0

12 months ago

0.24.1

1 year ago

0.24.0

1 year ago

0.20.3

1 year ago

0.22.0

1 year ago

0.20.1

1 year ago

0.20.0

1 year ago

0.19.0

1 year ago

0.19.1

1 year ago

0.17.0

1 year ago

0.18.0

1 year ago

0.20.2

1 year ago

0.16.0

1 year ago

0.15.0

1 year ago

0.14.5

1 year ago

0.14.6

1 year ago

0.13.0

1 year ago

0.12.1

1 year ago

0.14.0

1 year ago

0.13.1

1 year ago

0.12.2

1 year ago

0.14.1

1 year ago

0.12.3

1 year ago

0.14.2

1 year ago

0.14.3

1 year ago

0.14.4

1 year ago

0.8.8

2 years ago

0.8.5

2 years ago

0.7.6

2 years ago

0.8.4

2 years ago

0.7.5

2 years ago

0.8.7

2 years ago

0.11.0

1 year ago

0.10.0

1 year ago

0.9.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago