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

@twicpics/react

v0.3.0

Published

TwicPics components library for React.js

Downloads

11

Readme

@twicpics/react

npm version npm downloads License

TwicPics integration with React.

Setup

  1. Add @twicpics/react dependency to your project
yarn add @twicpics/react
# or npm install @twicpics/react
  1. Setup
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

import { TwicPics } from "@twicpics/react";

TwicPics({
  domain: "https://demo.twic.pics",
  anticipation: 0.5,
  maxDPR: 2,
  step: 100,
});

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

Options

domain (required)

This is your very own TwicPics domain.

anticipation

  • Default value: 0.2 (any value that is not a number will be ignored)

TwicPics will lazy-load images by default. To avoid too abrupt a transition with elements appearing into view and then images very obviously loading afterwards, TwicPics will "anticipate" lazy loading by a factor of the actual viewport. This behavior is controlled by this setting.

maxDPR

  • Default value: 2 (any value that is not a number will be ignored)

TwicPics will take the Device Pixel Ratio of the current device into consideration when determining the sizes of images to load. By default, it will not take a DPR greater than 2 into consideration. If the DPR of the device is higher than 2, TwicPics will assume it to be 2. So you can lower it to 1 or be more permissive (for instance by setting it to 3 or 4).

step

  • Default value: 10 (any value that is not a number will be ignored)

To avoid requesting too may variants of the same image, TwicPics will round the width of images to the closest multiple of step. The height will then be computed in order to respect the original aspect ratio.

Usage

TwicImg component

<TwicImg 
  src="<image-path>"
  width="<integer>"
  height="<integer>"
  placeholder="<none|preview|meancolor|maincolor>"
  mode="<contain|cover>"
  position="<css position>"
  ratio="<ratio>"
  step="<integer>"
  focus="<auto|coordinates>"
  transition="<boolean>"
/>

| Name | Description | Type | Default | Required | |------|-------------|------|---------|----------| | src | Absolute or relative path to an image. | String | | true | | width | See ratio. | Integer | | false | | height | See ratio. | Integer | | false | | ratio | Unitless width/height value pair. You can either use ratio or width and height to set the aspect-ratio of the area your image will be in. If both are used, ratio win. A squared area will be created by default. | String | 1/1 | false | | placeholder | Can be preview, meancolor, maincolor or none. | String | preview | false | | mode | Can be contain or cover and determines if the image fills the area and is cropped accordingly (cover) or if the image will sit inside the area with no cropping (contain). | String | cover | false | | position | Only useful in contain mode. Locates the image inside the area. Syntax is the same as for CSS position properties like background-position or object-position. Useful values are top, bottom, left, right, left top, left bottom and so on. | String | center | false | | step | See TwicPics documentation for details. | Integer | 10 | false | | focus | Only useful in cover mode. Can be auto or coordinates - see TwicPics documentation for details. | String | 10 | false | | transition | Whether or not to load images with a fade in effect. | Boolean | true | false | | transitionDuration | Duration of the transition effect. | String | 400ms | false | | transitionTimingFunction | CSS timing function applied to the transition effect. | String | ease | false | | transitionDelay | Transition delay of the transition effect. | String | 0ms | false | | alt | alt attribute content | String | Image name without extention | false |

Example

import TwicImg from "@twicpics/react";
import "@twicpics/react/build/twicpics.css";

function App() {
  return (
    <main>
      <TwicImg
        src="/my-image.jpg"
        ratio="16/9"
        step="100"
        focus="auto"
        placeholder="preview"
      />
    </main>
  );
}

export default App;

Demo

Edit TwicPics React

License

MIT License

Copyright (c) TwicPics