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

@imohammad/feature-flags-client

v1.0.8

Published

UI Library for react feature flags

Downloads

206

Readme

@imohammad/@imohammad/feature-flags-client

UI Library for react feature flags

NPM JavaScript Style Guide

Install

npm install --save @imohammad/feature-flags-client

Usage

Navbar & List:

import React, { useState, useCallback } from 'react'

// import the components where ever you wish to show the dashboard
import { Navbar, List } from '@imohammad/feature-flags-client'

// import the base styles into your main app root file
import '@imohammad/feature-flags-client/dist/index.css'

declare type TFeature = {
  name: string
  id: number
  description: string
  status: 'on' | 'off' | 'pilot'
  createdAt?: string
}

const data: TFeature[] = [
  {
    id: 1,
    name: 'MULTI_STORE_POPOVER',
    description: 'Enable Multi Store Popover View',
    status: 'on',
    createdAt: '1675071198226'
  },
  {
    id: 2,
    name: 'SPONSORED_ADS_IN_SEARCH',
    description: 'Display sponsored section Ads on the search results page',
    status: 'off',
    createdAt: '1675163406439'
  },
  {
    id: 3,
    name: 'TELKOM_ADS_IN_SEARCH',
    description: 'Display Telkom Ads on search results page',
    status: 'on',
    createdAt: '1674477471197'
  }
]

const Example = () => {
  const [searchTerm, setSearchTerm] = useState('')

  const getFlags = useCallback(
    (flags: TFeature[]) => {
      if (!flags || !flags.length) {
        return []
      }
      if (searchTerm) {
        return flags.filter((each: TFeature) =>
          each.name.toLowerCase().includes(searchTerm.toLowerCase())
        )
      }
      return flags
    },
    [searchTerm]
  )

  return (
    <>
      {/* Renders the FeatureFlag Navbar */}
      <Navbar
        rootClassName='container'
        logo='' // brand-logo
        showButton={true} // to show and hide create-Feature button
        showSearch={true} // to show and hide search-input
        searchTerm={searchTerm} // search input value
        onSearch={setSearchTerm}
        // triggered when someone types in the search-input-field
        createFeature={() => {
          // triggered when someone clicks create-feature button
        }}
      />
      {/* Renders the list of features */}
      <List
        rootClassName='container'
        data={getFlags(data)}
        onEdit={(name) => {
          // triggered when someone clicks on the Edit button
          console.log(name)
        }}
        onDelete={(name) => {
          // triggered when someone clicks on the delete button
          console.log(name)
        }}
      />
    </>
  )
}

export default Example

Card:

import React, { Component } from 'react';
import { Card } from '@imohammad/feature-flags-client';

class Example extends Component {
  render() {
    return (
      // This component renders the Feature Card
      <Card
        name="MULTI_STORE_POPOVER"
        id={1}
        description="Enable Multi Store Popover View"
        status="pilot"
        onDelete={(title) => {
          // triggered when someone clicks on the Edit button
        }}
        onEdit={(title) => {
          // triggered when someone clicks on the delete button
        }}
      />
    );
  }
}

export default Example

Edit  & create Form:

import React, { useState } from 'react'
import '@imohammad/feature-flags-client/dist/index.css'
import { Form, TFormData } from '@imohammad/feature-flags-client'


const Example = () => {
  const [formData, setFormData] = useState<TFormData>({
    name: '',
    description: '',
    status: 'on',
    pilotType: 'Custom',
    pilotIds: []
  })

  const onChangeInput = (key: string, value: any) => {
    setFormData({ ...formData, [key]: value })
  }
  return (
    // This component is used to Edit and Create New Feature
    <Form
      disableNameEdit={false} // make this true in case of edit feature to disable feature name edit
      formData={formData}
      onChange={(Key, value) => {
        onChangeInput(Key, value)
      }}
      onSubmit={(formData) => {
        // triggered when someone clicks on the submit button on featureFrom
        console.log(formData)
      }}
      pilotOptions={['[email protected] (11111)']}
    />
  )
}

export default Example

PopUp:

import React, { Component } from 'react'
import  { PopUp } from '@imohammad/feature-flags-client'

class Example extends Component {
  render() {
   return (
       // This component is used to show popUp on success | error | warning
       <PopUp 
         title="Are you sure?"
         text="You won't be able to revert this!"
         type={"success" | "error" | "warning"}
         primaryButton="Yes, delete it!"
         onCancel={() => {
           // triggered when someone clicks on the cancel-button on pop-up 
         }} 
         onDelete={() => {
           // triggered when someone clicks on the delete-button on pop-up 
         }}
       />
    )}
  }
  
  export default Example

Styles C.S.S

To style components class are given below:

Navbar

  • fcc-root-feature-navbar
  • fcc-left-feature-navbar
  • fcc-search-feature-navbar
  • fcc-create-button-feature-navbar

List

  • fcc-root-feature-list

Card

  • fcc-root-feature-card
  • fcc-upper-feature-card
  • fcc-up-right-feature-card
  • fcc-up-left-feature-card

Form

  • fcc-root-feature-form
  • fcc-input-feature-form
  • fcc-status-feature-form
  • fcc-radio-feature-form
  • fcc-submit-button-feature-form

AutoComplete

  • fcc-input-box-autocomplete
  • fcc-tag-autocomplete
  • fcc-suggestions-autocomplete
  • fcc-options-autocomplete
  • fcc-option-autocomplete

PopUp

  • fcc-root-popup
  • fcc-root-content-popup
  • fcc-button-container-popup
  • fcc-primary-button-popup
  • fcc-cancel-button-popup
  • fcc-close-btn

License

MIT © LFI