1.1.0-alpha.4 • Published 2 years ago

@salesforce-ux/sds-styling-hooks v1.1.0-alpha.4

Weekly downloads
-
License
SEE LICENSE IN RE...
Repository
-
Last release
2 years ago

@salesforce-ux/sds-styling-hooks

About

Global Styling hooks use CSS custom properties which make it easy to customize application-wide styling.

Table of Contents

Relevant links (external)

Installation

Use npm to install the SDS Global Styling Hooks:

npm install --save-dev @salesforce-ux/sds-styling-hooks

Add SDS Global Hooks in HTML

You can use the HTML <link> to link to SDS Global Styling Hooks as an external resource.

<html>
  <head>
    <link rel="stylesheet" href="/node_modules/@salesforce-ux/sds-styling-hooks/dist/hooks.custom-props.css">
    <!-- Your application's stylesheets go below -->
    <link rel="stylesheet" href="...">
  </head>
  <body>
    <!-- Your application -->
  </body>
</html>

Add SDS Global Hooks in CSS

You can use CSS @imports to pull in SDS Global Styling Hooks.

:root {
  @import "@salesforce-ux/sds-styling-hooks/dist/hooks.custom-props.css";
}

body {
  /* Directly reference SDS Styling Hook */
  background: var(--sds-g-color-neutral-base-50);
}

File Formats

SDS Styling Hooks have 6 different file formats for consumption. All files are located in /dist/.

JSON (*.json)

{
  "PROP_NAME": "PROP_VALUE"
}

Raw JSON (*.raw.json)

{
  "props": {
    "PROP_NAME": {
      "value": "PROP_VALUE",
      "type": "PROP_TYPE",
      "category": "PROP_CATEGORY",
      /* additional metadata */
    }
  }
}

Common JS (*.js)

module.exports = {
  propName: "PROP_VALUE"
};

ES Module (*.js)

export const propName = "PROP_VALUE";

Custom Properties scoped to :root (*.css)

:root {
  --prop-name: PROP_VALUE;
}

Custom Property Registration using CSS Properties and Values API (*.js)

Experimental

This is an experimental technology

Check the Browser compatibility table carefully before using this in production.

For more information, see CSS Properties and Values API Level 1.

if (CSS.registerProperty) {
  CSS.registerProperty({
    name: "--prop-name",
    syntax: "PROP_SYNTAX",
    inherits: false,
    initialValue: "PROP_VALUE",
  });
}

Usage Guidelines

Color

The Salesforce Design System comes with a robust color system and relationships to ensure our UIs meet WCAG 2.1 contrast ratios of 4.5:1. The semantic relationships allow for easy theme switching to handle features such as dark mode or high contrast mode.

Additionally, we generate sets of vibrant color palettes to use as accents in your designs. These values are generated in the HCL color space, which are designed to accord with human perception of color.

Using Color Relationships for UIs

The Salesforce Design System offers a set of neutral and brand color relationships. These two sets are intended to be used on your UI elements to define properties such as backgrounds, borders and text.

Each set, neutral and brand, have 13 color values. The base group defaults to "light" UI elements.

View all system colors →

Neutral

--sds-g-color-neutral-base-100
--sds-g-color-neutral-base-95
--sds-g-color-neutral-base-90
--sds-g-color-neutral-base-80
--sds-g-color-neutral-base-70
--sds-g-color-neutral-base-65
--sds-g-color-neutral-base-60
--sds-g-color-neutral-base-50
--sds-g-color-neutral-base-40
--sds-g-color-neutral-base-30
--sds-g-color-neutral-base-20
--sds-g-color-neutral-base-15
--sds-g-color-neutral-base-10

Brand

--sds-g-color-brand-base-100
--sds-g-color-brand-base-95
--sds-g-color-brand-base-90
--sds-g-color-brand-base-80
--sds-g-color-brand-base-70
--sds-g-color-brand-base-65
--sds-g-color-brand-base-60
--sds-g-color-brand-base-50
--sds-g-color-brand-base-40
--sds-g-color-brand-base-30
--sds-g-color-brand-base-20
--sds-g-color-brand-base-15
--sds-g-color-brand-base-10

Golden Rule for Relationships

Regardless of the set, neutral or brand, there is a golden rule to ensure the color relationships are retained;

Each palette contains a relationship of base and contrasting values. Whatever is the predominate color accent you are trying to achieve WCAG 2.1 color contrast for, you will start in that color palette.

The color system is meant to provide valid color relationships for background to foreground color values. This includes text and non-text glyphs.

The green lines highlight the relationships that pass AAA color contrast requirements and the yellow lines are designated for AA.

If a design crosses into another color palette, it is up to the designer to find the corresponding color value that passes color contrast requirements.

An image showing the neutral color UI relationships

Reference Palettes

View all reference colors →

The Salesforce Design System provide reference color palettes to use in your designs. These values are generated in the HCL color space, which are designed to accord with human perception of color.

Important usage note

If you use a color from these palettes on a UI element, you are responsible to ensure proper contrast ratio between the background and text. Additionally, the color cannot be programmically alter if your application requires different themes such as dark mode or high contrast mode.

Typography

Font Family

View Font Families →

The Salesforce Design System defaults to use system fonts, this improves performance and legibility on the content based on the device being used. We provide two styling hooks for font families, one of the body text content and one for the heading text of your document.

Body Text Content

--sds-g-font-family

Heading Text Content

--sds-s-heading-font-family

Font Stack

font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';

Font Sizes

View Font Sizes →

The Salesforce Design System offers a robust palette of font sizes. Our font sizes are independent of semantics so they are intended to be used for visual hierarchy. The sizes are based off a major second scale, 8:9 scale ratio with the base font size starting at 1rem or 16px. The scale offers 10 font sizes larger than the base and 4 font sizes smaller than the base.

1.1.0-alpha.3

2 years ago

1.1.0-alpha.4

2 years ago

1.1.0-alpha.2

3 years ago

1.1.0-alpha.1

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.1.0-alpha.0

3 years ago

1.0.0-alpha.1

3 years ago

1.0.0-alpha.0

3 years ago

0.7.1

3 years ago

0.7.0

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.4-alpha.0

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago