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

@crowdstrike/ember-toucan-styles

v3.0.1

Published

The styles for the CrowdStrike Toucan Design System

Downloads

388

Readme

@crowdstrike/ember-toucan-styles

Ember integration for CrowdStrike's design system: Toucan.

Includes:

  • Base CSS and Tailwind configuration automatically integrated into the Ember build pipeline
  • Color variables automatically pulled from Figma
  • Color utilities at @crowdstrike/ember-toucan-styles/utils/colors
  • A base ThemeManager service, for managing the current style theme from JavaScript -- not included by default, but may be extended
  • Testing utilities for qunit tests that affect the current theme.

Setup

Usage

Install

ember install @crowdstrike/ember-toucan-styles @crowdstrike/tailwind-toucan-base

Compatibility

  • ember-source 3.24+
  • ember-auto-import 2+
  • typecsript 4.5+
  • embroider max-compat and max-strict
  • @glimmer/tracking 1.1.2+

Setup

Tailwind 3

  1. Create an ember app. You don't have to start with a fresh ember app!

  2. Add tailwind however you like. An easy approach is

# In your terminal
npx ember-apply tailwind
  1. Install this library.
# In your terminal
pnpm add @crowdstrike/ember-toucan-styles @crowdstrike/tailwind-toucan-base
  1. Add the toucan-base plugin to your tailwind config's plugin list.
// config/tailwind/tailwind.config.js
'use strict';

const path = require('path');

const appRoot = path.join(__dirname, '../../');
const appEntry = path.join(appRoot, 'app');
const relevantFilesGlob = '**/*.{html,js,ts,hbs,gjs,gts}';

module.exports = {
  content: [path.join(appEntry, relevantFilesGlob)],
  theme: {
    extend: {},
  },
  presets: [
    require('@crowdstrike/tailwind-toucan-base')
  ],
  safelist: [
    'theme-dark',
    'theme-light',
  ]
};
  1. Create a button to toggle the theme.
# In your terminal
ember g component theme-toggle -gc
  1. Add code to theme-toggle to toggle the theme (and to observe that the theme is toggling). Today, Toucan only supports light and dark mode, so this toggle will flip between the light theme and dark theme.
// app/components/theme-toggle.js
import Component from '@glimmer/component';
import { service } from '@ember/service';

export default class DemoComponent extends Component {
  @service themeManager;

  toggle = () => this.themeManager.toggleTheme();
}
{{! app/components/theme-toggle.hbs }}
<button
  class="
    flex whitespace-nowrap bg-surface-base type-md-tight text-titles-and-attributes
    focus:outline-none p-2 rounded"
  {{on 'click' this.toggle}}
>
  toggle
</button>

More of our colors and tailwind classes can be found here: https://tailwind-toucan-base.pages.dev/

  1. Invoke <ThemeToggle> in app/templates/application.hbs.
<ThemeToggle />
  1. Start both the ember dev server and the tailwind build.
# in terminal 1
pnpm start
# in terminal 2
pnpm tailwind:watch
  1. A local server will boot at http://localhosts:4200 and clicking the rendered button will toggle the background color.

Note that if you're using embroider + webpack, you also have the option to follow the popular guides on setting up tailwind with webpack

Tailwind 2

To configure an Ember App, modify:

  • ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

const { configureTailwind } = require('@crowdstrike/ember-toucan-styles/ember-cli');

const tailwindConfig = require('./tailwind.config');

module.exports = function (defaults) {
  let app = new EmberApp(defaults, {
    ...configureTailwind({ tailwindConfig }),
  });

  return app.toTree();
};
  • app/styles/app.css
@tailwind base;
@tailwind components;
@tailwind utilities;

NOTE: if you're also using css-modules, you'll want to import the css-modules output before @tailwind base;

// ember-cli-build.js

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

const { configureTailwind } = require('@crowdstrike/ember-toucan-styles/ember-cli');

const tailwindConfig = require('./tailwind.config');

module.exports = function (defaults) {
  let app = new EmberAddon(defaults, {
    ...configureTailwind({ tailwindConfig }),
  });

  return app.toTree();
};
/* tests/dummy/app/styles/app.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Add ember-cli-postcss to your devDependencies

And lastly, for tests in your addon to have colors, you'll need to set either theme-light or theme-dark on the body class.

It is recommended to avoid CSS-Modules, as Tailwind is very flexible -- it may require a different approach to achieve the stylistic goal though.

Follow these steps:

  • remove ember-cli-postcss from your addon

  • install ember-css-modules

  • change ember-cli-build.js

    -const { configureTailwind } = require('@crowdstrike/ember-toucan-styles/ember-cli');
    +const { configureCSSModules } = require('@crowdstrike/ember-toucan-styles/ember-cli');

    To use this in an addon, you'll want to apply these to the options object of the v1 addon's index.js. V2 Addons do not support app-build modifications, so the app would need to configure css-modules support.

Usage

Components may be written following the tailwind documentation. Common CSS classes provided by the Toucan preset for Tailwind can be viewed here ( Source Code here ).

Example:

<button
  class="
    flex whitespace-nowrap bg-transparent type-md-tight text-titles-and-attributes
    focus:outline-none"
  type="button"
>
  A Button!
</button>

Scrollbar Styles

To get toucan-themed scrollbars in browsers that support scrollbar customization

/* some CSS file */
@import '@crowdstrike/ember-toucan-styles/scollbar.css'

or if you have a bundling environment that supports adding CSS as part of the module graph,

// some JavaScript or TypeScript file
import '@crowdstrike/ember-toucan-styles/scrollbar.css';

Using a Custom Theme Manager

Setup

Create an {app,addon}/services/my-theme-manager.js file, and at a minimum,

import { ThemeManager } from '@crowdstrike/ember-toucan-styles';

export default class MyThemeManager extends ThemeManager {
  // your modifications here
}

NOTE: If you are developing an addon and you want your custom theme-manager to also be called theme-manager, in your package.json, you'll need to specify that your addon runs "after" @crowdstrike/ember-toucan-styles

"ember-addon": {
  "after": [
    "@crowdstrike/ember-toucan-styles"
  ]
}

Setting the Default Theme

Somewhere in the consuming app or addon, run

import { inject as service } from '@ember/service';
import { THEMES } from '@crowdstrike/ember-toucan-styles';

class MyClass {
  @service themeManager;
  // or @service('my-theme-manager') themeManager;

  setup() {
    // using a default theme (THEMES.LIGHT)
    this.themeManager.setup();

    // or with a custom default theme
    this.themeManager.setup(THEMES.DARK);
  }
}

This will first checkout the current-theme key in local storage and if that doesn't exist, the the argument passed to setup() will be used as the default.

Responding to Theme Changes

It is possible to apply certain behaviors when a theme switch occurs, for example:

import { action } from '@ember/object';
import { inject as service } from '@ember/service';

import { THEMES, ThemeManager } from '@crowdstrike/ember-toucan-styles';

import { EVENTS } from '@crowdstrike/ui/analytics/ui';

export default class MyThemeManager extends ThemeManager {
  @service externalGraphics;
  @service analytics;

  @action
  onUpdateTheme(currentTheme, wasSaved = true) {
    let key = trackingKey(currentTheme);

    if (wasSaved) {
      this.analytics.trackEvent(this, key);
    }

    this.externalGraphics.updateTheme(currentTheme);
  }
}

function trackingKey(themeName) {
  switch (themeName) {
    case THEMES.DARK:
      return EVENTS.THEME.DARK;
    case THEMES.LIGHT:
      return EVENTS.THEME.LIGHT;
    default:
      throw new Error(`Theme not recognized: ${themeName}`);
  }
}

Using your own Tailwind Plugins

Add them to your .tailwind.config.js, as normal in https://tailwindcss.com/docs/plugins