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

@blockquote-web-components/blockquote-base-style-helpers

v1.3.0

Published

Webcomponent blockquote-base-style-helpers following open-wc recommendations

Downloads

67

Readme

Lit

BlockquoteBaseStyleHelpers offers a set of helper functions for working with CSS.

There are two kinds of helps:

  • Shared styles between components
  • Document-level styles

Demo

Open in StackBlitz

Shared styles between components

Adaptation of the Polymer ideas so that components can share styles, using native JS modules

Using the shared styles is a two-step process:

  • setComponentSharedStyles
  • getComponentSharedStyles

setComponentSharedStyles

Define a shared-style inside a JS module.

The id attribute specifies the name you'll use to reference your shared styles, multiple shared styles can be registered using the same ID. These will be applied to the component in the order they were registered.

shared-styles

import { css } from 'lit';
import { setComponentSharedStyles } from blockquote-base-style-helpers.js;

setComponentSharedStyles('x-foo-shared-styles', css`
:host {
  background-color: red;
}
p {
  color: blue;
}
`);

getComponentSharedStyles

A component can use getComponentSharedStyles for retrieving style blocks and add it to its local styles extending or overriding it.

Component

import { LitElement, html, css } from 'lit';
import { getComponentSharedStyles } from 'blockquote-base-style-helpers';

class XFoo extends LitElement {
  static get styles() {
    return [
      css`...`,
      getComponentSharedStyles('x-foo-shared-styles)
    ];
  }
}

Document-level styles

Adaptation of the Polymer ideas so for defining styles in the main document


Define reusable design tokens

Lit provide a perfect API, adoptStyles & css for Built-in support Theming and managing tokens for a design system.

The last step in the Built-in theme support creation is to provide the CSS variables to be able to inherit, lit.dev theming

But the function adoptStyles does not preserve any existing StyleSheets added via adoptedStyleSheets.


1. From tokens to CSS variables

export const theme = {
  colors: {
    ...tertiary0,
    ...tertiary1,
    ...tertiary2,
    ...neutral,
  },
  fontFace: {
    ...fontFace,
  },
  fonts: {
    main: 'Kaisei HarunoUmi, serif',
  },
};

const THEME = `
:root {
  --red-300: ${theme.colors['--red-300']};
  --red-400: ${theme.colors['--red-400']};
  --red-500: ${theme.colors['--red-500']};
  --red-600: ${theme.colors['--red-600']};
  --red-700: ${theme.colors['--red-700']};

  --green-300: ${theme.colors['--green-300']};
  --green-400: ${theme.colors['--green-400']};
  --green-500: ${theme.colors['--green-500']};
  --green-600: ${theme.colors['--green-600']};
  --green-700: ${theme.colors['--green-700']};

  --blue-300: ${theme.colors['--blue-300']};
  --blue-400: ${theme.colors['--blue-400']};
  --blue-500: ${theme.colors['--blue-500']};
  --blue-600: ${theme.colors['--blue-600']};
  --blue-700: ${theme.colors['--blue-700']};

  --neutral-300: ${theme.colors['--neutral-300']};
  --neutral-400: ${theme.colors['--neutral-400']};
  --neutral-500: ${theme.colors['--neutral-500']};
  --neutral-600: ${theme.colors['--neutral-600']};
  --neutral-700: ${theme.colors['--neutral-700']};

  font: normal medium/1.25 sans-serif;

}`;

2. Styles are injected in document, adoptedStyleSheets, or inside <style> tags in the document's <head>

// Two call (setDocumentStyles) preserves any existing StyleSheets added via adoptedStyleSheets

setDocumentStyles(css`
  ${unsafeCSS(theme.fontFace.root)}
`);

setDocumentStyles(css`
  ${unsafeCSS(THEME)}
`);

3. Themable component

// CSS var fallback from the same theme just a source of truth
import { css, unsafeCSS } from 'lit';
import { theme } from '../theme/theme.js';

export default css`
  :host {
    display: block;
    color: var(--neutral-600, ${unsafeCSS(theme.colors['--neutral-600'])});
  }
`;

Progressive Enhancement:

  • support browsers with native Shadow DOM but without adoptedStyleSheets
  • support browsers with native Shadow DOM and adoptedStyleSheets

src/getComponentSharedStyles.js:

Functions

| Name | Description | Parameters | Return | | -------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------ | ------ | | getComponentSharedStyles | Get styles (as cssResult) already associated to provided ID string (using setComponentSharedStyles helper) and returns them | id: String | |

Exports

| Kind | Name | Declaration | Module | Package | | ---- | -------------------------- | ------------------------ | ------------------------------- | ------- | | js | README | README | src/getComponentSharedStyles.js | | | js | getComponentSharedStyles | getComponentSharedStyles | src/getComponentSharedStyles.js | |

src/index.js:

Exports

| Kind | Name | Declaration | Module | Package | | ---- | -------------------------- | ------------------------ | ----------------------------- | ------- | | js | setDocumentStyles | setDocumentStyles | ./setDocumentStyles.js | | | js | adoptDocumentStyles | adoptDocumentStyles | ./setDocumentStyles.js | | | js | setComponentSharedStyles | setComponentSharedStyles | ./setComponentSharedStyles.js | | | js | getComponentSharedStyles | getComponentSharedStyles | ./getComponentSharedStyles.js | |

src/setComponentSharedStyles.js:

Functions

| Name | Description | Parameters | Return | | -------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------- | ------ | | setComponentSharedStyles | Set styles (as cssResult) associated to provided ID string which can then be retrieved by components | id: String, styles: CSSResult | |

Exports

| Kind | Name | Declaration | Module | Package | | ---- | -------------------------- | ------------------------ | ------------------------------- | ------- | | js | setComponentSharedStyles | setComponentSharedStyles | src/setComponentSharedStyles.js | |

src/setDocumentStyles.js:

Functions

| Name | Description | Parameters | Return | | --------------------- | --------------------------------------------- | ---------------------------------------------------- | ------ | | adoptDocumentStyles | Adopts the given styles into the render root. | renderRoot: Document \| HTMLElement, styles: Array | | | setDocumentStyles | Sets the document styles. | styles: !* | |

Exports

| Kind | Name | Declaration | Module | Package | | ---- | --------------------- | ------------------- | ------------------------ | ------- | | js | adoptDocumentStyles | adoptDocumentStyles | src/setDocumentStyles.js | | | js | setDocumentStyles | setDocumentStyles | src/setDocumentStyles.js | |