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

themis-ts-framework

v1.1.0

Published

Theming and Styling Framework for TypeScript

Downloads

22

Readme

ThemisTS

Theming and Styling Framework for TypeScript

This is a powerful and flexible framework for managing themes and styles in TypeScript applications. Leveraging the full capabilities of TypeScript's advanced type system, it provides a robust and type-safe solution for defining, composing, and applying styles across your application.

Key Features

  • Strong Typing: Extensive use of TypeScript's advanced type system ensures type safety and catches errors at compile-time, providing a solid foundation for large-scale and collaborative development.

  • Extensibility: Easily extend the theme structure with custom properties beyond colors, fonts, utilities, etc, tailoring the theme to your application's specific needs.

  • Theming and Style Management: Comprehensive support for managing themes, styles, and CSS variables, enabling consistent styling and easier style updates and overrides.

  • Overriders: Granular control over overriding specific styles or theme properties at different levels or for different components.

Theme Creation Example

import { ThemeManager } from "./theme-manager";

// Define your theme interface
export let myTheme: ThemeInterface<{
  colors: "primary" | "secondary" | "background";
  fonts: "body" | "heading";
  componentStyle: "spacing";
  overriders: {
    componentOverriders: "compact" | "spacious";
    colorOverriders: "light" | "dark";
  };
}> = {
  themeCreator: {
    themeType: "dark",
    colors: {
      primary: "#212121",
      secondary: "#424242",
      background: "black",
    },
    fonts: {
      body: {
        size: "16px",
        weight: "400",
      },
      heading: {
        size: "24px",
        weight: "600",
      },
    },
    componentStyle: {
      spacing: "16px",
    },
    overriders: {
      componentOverriders: {
        compact: {
          componentStyle: {
            spacing: "8px",
          },
        },
        spacious: {
          componentStyle: {
            spacing: "24px",
          },
        },
      },
      colorOverriders: {
        light: {
          themeType: "light",
          colors: {
            primary: "#ffffff",
            secondary: "#f0f0f0",
            background: "#f5f5f5",
          },
        },
      },
    },
  },
};

Populate the theme

// Populate the theme
ThemeManager.shared.populateTheme(myTheme);

Usage Example

import React from 'react';
import { myTheme } from './theme';

const MyComponent = () => {
  const primaryColor = myTheme.vars?.colors.primary.normal._100;
  const bodyFont = `${myTheme.vars?.fonts.body.size} ${myTheme.vars?.fonts.body.weight}`;
  const spacing = myTheme.vars?.utils.spacing;

  return (
    <div style={{ color: primaryColor, fontFamily: bodyFont, padding: spacing }}>
      <h1 className={`${myTheme.vars?.fonts.heading.class}`}>
        Welcome to My Component
      </h1>
      <p>This component uses the theme variables for colors, fonts, and spacing.</p>

      <div id="compact-container">
        <h2>Compact Container</h2>
        <p>This container uses the compact layout overrider.</p>
      </div>
    </div>
  );
};

export default MyComponent;

Overriders showcase

// Apply the light color overrider to the body to change the colors of the web application.
myTheme.vars?.overriders.colorOverriders.light.apply();

// You can set the element where you apply the overrider, by default it is the document.body
....apply(document.body);

// Apply the compact layout overrider to change the spacing on the specific component
myTheme.vars?.overriders.componentOverriders.compact.apply();

// Or change it to spacious in case you need it.
myTheme.vars?.overriders.componentOverriders.spacious.apply();

When we then apply the compact layout overrider using myTheme.vars?.overriders.componentOverriders.compact.apply();.

The compact layout overrider changes the spacing utility value to 8px, which will affect the padding and margins of elements that use the spacing var changing the MyComponent padding and margings. This showcases how you can selectively apply layout overriders to specific parts of your application while keeping the rest of the app unaffected.

By combining the color overrider applied to the document.body and the layout overrider, you can see how this framework allows you to easily override both color and layout styles or any overrider you create at different levels, chaining overridders to accomplis a strucured and flexible theme at viewport or component level, providing granular control over the theming and styling of your application.