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

@k8slens/lds-tips

v0.35.3

Published

Lens Design System – React Tips component

Downloads

356

Readme

Lens Design System – React Tips component

Documentation

Browse the documentation at lensapp.github.io/lens-design-system.

Usage in React apps

  • run npm i -s @k8slens/lds @k8slens/lds-tokens @k8slens/lds-tips
  • import @k8slens/lds-tokens/lib/es/font-imports.css in your React app to include fonts
  • import @k8slens/lds/lib/es/index.css in your React app to include core styles
  • import @k8slens/lds-tips/lib/es/index.css in your React app to include Tips styles
  • Use in a component:
import { Tips } from "@k8slens/lds-tips";

import tipStore from "./path-to-my/tip-store";

export const Component = () => (
  <Tips
    tours={tipStore.tours}
    setNextStepNumber={tipStore.setNextStepNumber}
    getActiveStep={tipStore.getActiveStep}
    setSkipAll={tipStore.setSkipAll}
    skipped={tipStore.skipAll}
  />
);

Example using MobX

Tours

// tours.ts
import type { Tour } from "@k8slens/lds-tips/lib/es/Tips/Tips";

export default const tours: Array<Tour> = [
  {
    id: "tour-1",
    steps: [
      {
        id: "first-tip",
        selector: "#target-element-1",
        theme: "important",
        content: (
          <>
            <h3>This is the first tip</h3>
            <p>Tip Contents</p>
          </>
        ),
      },
      {
        id: "second-tip",
        selector: "#target-element-2",
        theme: "important",
        content: (
          <>
            <h3>This is the second tip</h3>
            <p>Another content</p>
          </>
        ),
      },
    ],
  }
]

TipStore

// tips-store.ts
import { action, makeObservable, observable, toJS } from "mobx";

import type { Tour, TipsProps } from "@k8slens/lds-tips/lib/es/Tips/Tips";

import tours from "./tours";

type ActiveSteps = { [key: string]: number };

type TipStoreModel = {
  skipAll: TipsProps["skipAll"];
  activeSteps: ActiveSteps;
};

export class TipStore {
  @observable
  store: TipStoreModel = {
    skipAll: false,
    activeSteps: {}
  };
  tours: Array<Tour> = tours;

  constructor() {
    super();

    makeObservable(this);
  }

  @action
  setSkipAll: TipsProps["setSkipAll"] = () => {
    this.store.skipAll = true;
  };

  @action
  setNextStepNumber: TipsProps["setNextStepNumber"] = (tourId: string) => {
    let nextStep = 1;
    if (typeof this.store.activeSteps[tourId] === "number") {
      nextStep += this.store.activeSteps[tourId];
    };

    this.store.activeSteps = {
      ...this.store.activeSteps,
      [tourId]: nextStep
    };

    return nextStep;
  };

  getActiveStep: TipsProps["getActiveStep"] = (tourId: string) => {
    return this.store.activeSteps[tourId] || 0;
  };
}

Component

// Component.tsx
import React from "react";
import { observer } from "mobx-react";

import { Tips } from "@k8slens/lds-tips";

import { TipStore } from "./TipStore";

interface Props {
  tipStore: TipStore | null;
}

export const Component = observer(({ tipStore }: Props) => {

  if (!tipStore) {
    return null;
  }

  return (
    <Tips
      tours={tipStore.tours}
      setNextStepNumber={tipStore.setNextStepNumber}
      getActiveStep={tipStore.getActiveStep}
      setSkipAll={tipStore.setSkipAll}
      skipped={tipStore.store.skipAll}
    />
  );
});