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

@fractal-components/random-gif-pair

v1.1.2

Published

A sample UI component built using `fractal-component`

Downloads

24

Readme

A Sample RandomGifPair UI Component

npm version unpkg npm bundle size (minified + gzip)

Overview

This is a sample UI Component built by re-using two RandomGif components. Its internal structure is simply as below:

<div className={classes.table}>
    <div className={classes.cell}>RandomGif Pair</div>
    <div className={`${classes.cell}`}>
        <div>
            <RandomGif
                showButton={false}
                apiKey={this.props.apiKey}
                namespacePrefix={`${
                    this.componentManager.fullPath
                }/Gifs`}
            />
        </div>
        <div>
            <RandomGif
                showButton={false}
                apiKey={this.props.apiKey}
                namespacePrefix={`${
                    this.componentManager.fullPath
                }/Gifs`}
            />
        </div>
    </div>
    {this.props.showButton && (
        <div className={`${classes.cell} `}>
            <button
                onClick={() => {
                    this.componentManager.dispatch(
                        actions.requestNewPair()
                    );
                }}
                disabled={this.state.isLoading}
            >
                {this.state.isLoading
                    ? "Loading..."
                    : "Get Gif Pair"}
            </button>
        </div>
    )}
    {/**
        * Use ActionForwarder to throw NEW_GIF out of RandomGifPair container
        * Set namespace to `${this.componentManager.fullPath}/Gifs` in order to listen to
        * all `out of box` actions from two `RandomGif` components
        */}
    <ActionForwarder
        namespacePrefix={`${this.componentManager.fullPath}/Gifs`}
        pattern={RandomGifActionTypes.NEW_GIF}
        relativeDispatchPath="../../../../*"
    />

    {/**
        * Use ActionForwarder to forward LOADING_START & LOADING_COMPLETE actions from `RandomGif`
        * to current component (`RandomGifPair`)'s namespace.
        * i.e. from `${this.componentManager.fullPath}/Gifs` to `${this.componentManager.fullPath}`
        * Thus, `relativeDispatchPath` should be ".."
        */}
    <ActionForwarder
        namespacePrefix={`${this.componentManager.fullPath}/Gifs`}
        pattern={action =>
            action.type === RandomGifActionTypes.LOADING_START ||
            action.type === RandomGifActionTypes.LOADING_COMPLETE
        }
        relativeDispatchPath=".."
    />
</div>

Quick Start

To try it out, simply create a HTML file with the following content (also available on CodePen):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>RandomGifPair Demo</title>
        <!--
            Load `babel-standalone` to support JSX in script tag
        -->
        <script src="https://unpkg.com/@babel/standalone@^7.0.0/babel.min.js"></script>
        <script src="https://unpkg.com/react@~16.8.0/umd/react.production.min.js"></script>
        <script src="https://unpkg.com/prop-types@~15.6.2/prop-types.min.js"></script>
        <script src="https://unpkg.com/react-dom@~16.8.0/umd/react-dom.production.min.js"></script>
        <script src="https://unpkg.com/redux-saga@~1.0.0/dist/redux-saga.umd.min.js"></script>
        <script src="https://unpkg.com/fractal-component@latest/dist/fractal-component.min.umd.js"></script>
        <script src="https://unpkg.com/[email protected]/dist/jss.min.js"></script>
        <script src="https://unpkg.com/[email protected]/dist/jss-preset-default.min.js"></script>
        <script src="https://unpkg.com/@fractal-components/random-gif@latest/dist/@fractal-components/random-gif.min.umd.js"></script>
        <script src="https://unpkg.com/@fractal-components/random-gif-pair@latest/dist/@fractal-components/random-gif-pair.umd.js"></script>
    </head>
    <body>
        <div id="app_root"></div>
        <script type="text/babel">
            const appContainer = new FractalComponent.AppContainer({
                reduxDevToolsDevOnly: false
            });
            ReactDOM.render(
                <FractalComponent.AppContainerContext.Provider
                    value={appContainer}
                >
                    <RandomGifPair.default />
                </FractalComponent.AppContainerContext.Provider>,
                document.getElementById("app_root")
            );
        </script>
    </body>
</html>

You can also use it as ES6 module:

import "@babel/polyfill";

import React from "react";
import ReactDOM from "react-dom";

import { AppContainer, AppContainerContext } from "fractal-component";
import RandomGifPair, { actions, actionTypes } from "@fractal-components/random-gif-pair";

const appContainer = new AppContainer({
    reduxDevToolsDevOnly: false
});

ReactDOM.render(
    <AppContainerContext.Provider value={appContainer}>
        <RandomGifPair />
    </AppContainerContext.Provider>,
    document.getElementById("root")
);

API / Interface

Component Properties

  • namespacePrefix: String. Optional. Used to extend component's namespace (without impact component's internal namespace) so that two components' namespaces have a common part. It will impact the action multicast dispatch.
  • apiKey: Giphy.com API key. If not set, default one will be used
  • showButton: Boolean. Whether a click button should be shown. You will want to hide the button when you reuse this component to create a new component. e.g. RandomGifPairPair
  • styles: Can used to replace the built-in styling. Accepts JSS styling object

Action Interface

Outgoing Actions

  • NEW_GIF: Send out when a new gif url has been retrieved from Giphy.com
  • LOADING_START: Send out when loading is started
  • LOADING_COMPLETE: Send out when loading is completed

Accepted Actions

  • REQUEST_NEW_PAIR: Will attempt to get a pair of random Gifs from Giphy.com when receive this action

Giphy.com API key

This comes with a testing Giphy.com API key in order to retrieve random Gifs from https://giphy.com/. The api key is limted to 40 requests per hour.

You can create your own API key from https://developers.giphy.com/ and set the API key by api property. e.g.

<RandomPair apiKey="xxxxxxxx" />