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

@nativescript-community/css-theme

v1.2.13

Published

Nativescript ExtendedInfo plugin.

Downloads

12

Readme

npm npm GitHub forks GitHub stars

Installation

  • tns plugin add @nativescript-community/css-theme

Be sure to run a new build after adding plugins to avoid any issues.

Usage

The theme will style your application using Element selectors - you don't need to add CSS classes on every element you need to style.

import "@nativescript-community/css-theme";

This JS takes care of updating several classes on the app root elements, something that got included in @nativescript/core in {N} 6.1.

Setting Dark or Light mode

Setting the theme mode from light to dark is now easier - instead of loading a new file, just find the root view and set .ns-dark class to it - this will change all colorization to dark tones. For instance, if your page root is RadSideDrawer, just add a class to it, like this:

<drawer:RadSideDrawer class="ns-dark" xmlns:drawer="nativescript-ui-sidedrawer">
    ...
</drawer:RadSideDrawer>

If your root is a frame, you can do this

<Frame class="ns-dark" defaultPage="root"></Frame>

For Angular, if your root is a page-router-outlet, you can set the .ns-dark class on it - it will pass it down to the Frame it renders.

Setting Dark or Light mode from JavaScript

Setting the theme mode from JavaScript is also much easier now - just import the theme and call Theme.setMode() with your preferred mode - either Theme.Light or Theme.Dark, like this:

import Theme from "@nativescript-community/css-theme";

Theme.setMode(Theme.Dark); // Or Theme.Light

Keep in mind that in {N} 6.2 these changes will override the default system mode. To restore it, use Theme.Auto (available since Theme 2.3.0):

import Theme from "@nativescript-community/css-theme";

Theme.setMode(Theme.Auto);

Additionally there is another helper method - toggleMode, which can be used without parameters to just toggle the mode or with a boolean parameter to ensure light or dark mode is set:

import Theme from "@nativescript-community/css-theme";

Theme.toggleDarkMode(); // to toggle between the modes

// or

Theme.toggleDarkMode(true);  // to ensure dark mode
Theme.toggleDarkMode(false); // to ensure light mode
A note of warning

Due to limitation in Playground the JS Theme API cannot be imported like an ES6 module in a TS/Angular projects. You'll have to resort to requiring it:

const Theme = require("@nativescript-community/css-theme");

Theme.setMode(Theme.Dark); // Or Theme.Light

More root classes

In addition to .ns-light and .ns-dark classes, the theme's little JavaScript file introduces .ns-root on the root element, .ns-android/.ns-ios depending on the current platform (which the theme extensively uses) and additionally .ns-portrait/.ns-landscape and .ns-phone/.ns-tablet, which should be self-explanatory. Of course .ns-portrait/.ns-landscape get updated on orientation change, so you can use it to show a two pane layout in landscape, for instance.

Using Theme variables

There are several functions and mixins in the core theme, that can be used in your projects, as long as you're using SASS/SCSS.

If you need to access specific theme variables like simple colors or sizes, do it through the const function:

Button {
    background-color: const(forest);
    height: const(btn-height);
}

You can get light/dark colors:

Button {
    color: light(primary);

    .ns-dark & {
        color: dark(primary);
    }
}