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

@kelysty/system

v0.1.0

Published

This is a pack of Kelysty React UI system components

Downloads

1

Readme

@kelysty/system · npm package CI storybook

This npm package can help you with providing pre-configured React Context API that contains:

  1. Device context
  2. Authorization context
  3. Language context
  4. Theme context

Each context can be applied separatelly and supported by custom hooks;

Installation

Using npm:

npm install @kelysty/system

Using yarn:

yarn add @kelysty/system

Usage

How to lift off as fast as possible?

Import KelystyProvider into your workspace:

import {KelystyProvider} from '@kelysty/system';

Then you need to simply wrap your application in it:

<KelystyProvider
  mobileMaxWidth={450}
  tabletMaxWidth={900}
  defaultIsAuth={false}
  defaultLanguage='english'
  languages={[...]}
  defaultTheme='light'
>
  <App/>
</KelystyProvider>

It's done and ready to use. You can proceed with reading hooks section or stay with us and learn about props thoroughly.

Props

NOTE: All props are guarded by default fallbacks. So they are optional, means they are not required. In order to customize your setup you obviously need to pass them.

mobileMaxWidth

  • type: number
  • defaultValue: 766
  • restriction: value must be less than 'tabletMaxWidth' prop

The mobile's maximum value of the screen width. Once screen width becomes more than that it is no longer a 'mobile' device - it is a 'tablet'; Metric system is pixels;

tabletMaxWidth

  • type: number
  • defaultValue: 1199
  • restriction: value must be greater than 'mobileMaxWidth' prop

The mobile's maximum value of the screen width. Once screen width becomes more than that it is no longer a 'tablet' device - it is a 'desktop'; Metric system is pixels;

defaultIsAuth

  • type: boolean
  • defaultValue: false
  • restriction: none

This prop provides auth status to start with.

defaultLanguage

  • type: string
  • defaultValue: english
  • restriction: to be successfully applied it must correlate with the 'languages' prop

The language of the app to start with. It has to be one of the available languages. If you provide languages prop - list of available languages throughout the app - without english (or any other passed defaultLanguage) in it, then defaultLanguage prop will be configured as a first item of the languages;

languages

  • type: Array<{name: string, code: string}>
  • defaultValue: [{name: 'english', code: 'en'}]
  • restriction: if provided, it must contain at least one item

Array of the languages in the app. By default there is only english language. If the prop is being passed, it overrides defaultValue. If you want to pass more languages beside the english one, make sure english language is in your list.

defaultTheme

  • type: 'system' | 'light' | 'dark' | 'alternative'
  • defaultValue: 'system'
  • restriction: TEMPORARY: there is no styling system yet that goes alongside with it

Default theme of the app. Right now it just contains a value of the active theme, but generating and applying styling system is up to you. The good news is we are working on it)

Hooks

There are 4 hooks right now:

// You can access all hooks via common gateway:
import {useDevice, useAuth, useLanguage, useTheme} from '@kelysty/system';

// and destructurize them as objects, what gives you power
// to choose only those items that you actualy need
const {...} = useDevice();

Now lets talk about each of them closely

useDevice()

With KelystyProvider you don't need and you cannot control the current active device. Using 'useDevice()' hook you can get automatically calculated device state. Doing so, you subscribe your component onto Device context.

// importing
import {useDevice} from '@kelysty/system';

// full destructurization
const {device, isDesktop, isTablet, isMobile} = useDevice();

// usage
  • args: none
  • device: current device as a string (desktop, tablet or mobile)
  • isDesktop: semantic helper, true when device === 'desktop', false otherwise
  • isTablet: the same logic but for tablet
  • isMobile: the same logic but for mobile
  • restriction: subscriber must be nested into either 'KelystyProvider' or 'DeviceProvider' component

useAuth()

'useAuth()' hook allows you to get and to control authorization state. Doing so, you subscribe your component onto Auth context.

// importing
import {useAuth} from '@kelysty/system';

// full destructurization
const {isAuth, login, logout, setIsAuth} = useAuth();

// usage
  • args: none
  • isAuth: current state as a boolean (true or false)
  • login(): calling this method switches isAuth to true
  • logout(): calling this method switches isAuth to false
  • setIsAuth(bool): renews isAuth with provided value
  • restriction: subscriber must be nested into either 'KelystyProvider' or 'AuthProvider' component

useLanguage()

'useLanguage()' hook allows you to get language state and control it. Doing so, you subscribe your component onto Language context.

// importing
import {useLanguage} from '@kelysty/system';

// full destructurization
const {language, availableLanguages, setLanguage} = useLanguage();

// further usage...
  • args: none
  • language: current language state as an object, ex {name: 'english', code: 'en'}
  • availableLanguages: array of all available langs in the app (Language[])
  • setLanguage(string): renews active language accepting language name
  • restriction: subscriber must be nested into either 'KelystyProvider' or 'LanguageProvider' component

useTheme()

'useTheme()' hook allows you to get and to control language state. Doing so, you subscribe your component onto Language context.

// importing
import {useTheme} from '@kelysty/system';

// full destructurization
const {theme, toggleTheme, setTheme} = useTheme();

// usage
  • args: none
  • theme: current active theme as string (system, light, dark or alternative)
  • toggleTheme(): calling this method toggles theme between light and dark (swithes to light from system or alternative ones)
  • setTheme(Theme): renews active theme with provided value
  • restriction: subscriber must be nested into either 'KelystyProvider' or 'ThemeProvider' component

Precise usage

KelystyProvider is a very convenient way to provide whole bunch of the context in a minute. But, you might not need so much of context.

Is there a way to apply them precisely?! Absolutely!

This is the example we provided at the very beginning of this page:

import {KelystyProvider} from '@kelysty/system'
// ...

<KelystyProvider
  mobileMaxWidth={450}
  tabletMaxWidth={900}
  defaultIsAuth={false}
  defaultLanguage='english'
  languages={[...]}
  defaultTheme='light'
>
  <App/>
</KelystyProvider>

Now, guess what, it was a HOC for

import {
  DeviceProvider,
  AuthProvider,
  LanguageProvider,
  ThemeProvider
} from '@kelysty/system';
// ...

<DeviceProvider
  mobileMaxWidth={450}
  tabletMaxWidth={900}
>
  <AuthProvider defaultIsAuth={false}>
    <LanguageProvider
      defaultLanguage='english'
      languages={[...]}
    >
      <ThemeProvider defaultTheme='light'>
        <App/>
      </ThemeProvider>
    </LanguageProvider>
  </AuthProvider>
</DeviceProvider>

As you can see, KelystyProvider is an abstraction that renders all nested providers underneath; The truth is:

  • all props are the same
  • all fallbacks (defaultValues) are the same
  • each hook is linked to it's provider

Just pick providers you need and use them separately!

We hope you enjoy using this library!