1.0.3 • Published 3 years ago

react-khatra-placeholder v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Khatra Placeholder

Status License: MIT

A react component library for creating skeleton placeholders

Installation

  npm install react-khatra-placeholder

Documentation

React Khatra Placeholder Documentation

Requirement

Quick Start

After installation

Import KhatraPlaceholder component from the react-khatra-placeholder.

import { KhatraPlaceholder } from "react-khatra-placeholder";
export const YourContentPage = () => {
  // your content loading logic.
  const [isLoading, setIsLoading] = useState(false);
  return (
    <>
      <KhatraPlaceholder
        isLoading={isLoading}
        type={"ParagraphPlaceholder"}
        delay={300}
        animateWave
      >
        <div>Your Beautiful content.</div>
      </KhatraPlaceholder>
    </>
  );
};

For Creating CustomPlaceholders import necessary components from the react-khatra-placeholder.

import {
  KhatraPlaceholder,
  PCardContainer,
  PCard,
  PBlock,
  PInlineContainer,
  PLine,
} from "react-khatra-placeholder";
const CustomPlaceholder = () => {
  return (
    <>
      {/* to hold more than one PCard. */}
      <PCardContainer>
        {/* base component of placeholder, control animation of placeholder from here.*/}
        <PCard w="400px" h="400px" animateWave>
          {/* creates rectangular block of given height and border radius.*/}
          <PBlock h="50%" br="8px" />
          {/* base component for creating paragraph lines.*/}
          <PInLineContainer gap="0.1rem" br="3px">
            <PLine h="0.8rem" /> {/* creates lines, just like in paragraphs.*/}
            <PLine w="70%" h="0.8rem" />
            <PLine w="80%" h="0.8rem" />
          </PInLineContainer>
          <PBlock w="30%" h="2rem" br="3px" />
        </PCard>
      </PCardContainer>
    </>
  );
};

export const YourContentPage = () => {
  // your content loading logic.
  const [isLoading, setIsLoading] = useState(false);
  return (
    <>
      <KhatraPlaceholder
        isLoading={isLoading}
        customPlaceholder={<CustomPlaceholder />}
        delay={300}
        animateWave
      >
        <div>Your Beautiful content.</div>
      </KhatraPlaceholder>
    </>
  );
};

Components

KhatraPlaceholder

KhatraPlaceholder is the base container to hold your content, maintain your loading state of your content , place custom placeholders and change animations.

<KhatraPlaceholder>YourContent</KhatraPlaceholder>
PropertyTypeRequiredDefault valueDescription
isLoadingBooleannofalsestate to either hide or show content
delayNumberno0to add delay in between changing state from loading to loaded.(Use to omit fast flicker in faster network devices.)
customPlaceholderReact Componentnonullplaceholder to show when content is loading
typeStringnonulltype of builtin placeholders provided by the library either of "ListMediaPlaceholder","ProductPlaceholder","ImagePlaceholder","ParagraphPlaceholder"
animateWaveBooleannonullto trigger shrimmer animation on placeholders
animateGlowBooleannonullto trigger glow animation on placeholders
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

PCardContainer

PCardContainer is container to hold one or more PCard.

<PCardContainer>{...children}<PCardContainer>
PropertyTypeRequiredDefault valueDescription
classNameStringnonullfor custom css class names

PCard

PCard is base container for creating card placeholders. Only place to control animations, either animateWave or animateGlow.

<PCard>{...children}</PCard>
PropertyTypeRequiredDefault valueDescription
wStringyesnullwidth of PCard
hStringyesnullheight of PCard
brStringno"0.75rem"borderRadius of PCard
gapStringnonullgap between children
animateWaveBooleannonullto trigger shrimmer animation on childrens
animateGlowBooleannonullto trigger glow animation on childrens
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

Note: using both animateWave and animateGlow stops animation.

PBlock

PBlock is used for creating placeholders for titles ,images and badges.

<PBlock />
PropertyTypeRequiredDefault valueDescription
wStringno"100%"width of PBlock
hStringno"100%"height of PBlock
brStringno"0.75rem"borderRadius of PBlock
alignStringnonullto align-self inside PCard, takes either of values flex-start,flex-end & center
roundedBooleannonullto create cicles
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

PInlineContainer

PInlineContainer is parent container to hold PLine component. Without PInlineContainer, PLine cannot be rendered.

<PInlineContainer>{...children}</PInlineContainer>
PropertyTypeRequiredDefault valueDescription
wStringno"100%"width of PInlineContainer
hStringno"fit-content"height of PInlineContainer
brStringno"5px"borderRadius for each children
gapStringno"0.5rem"gap between chilrens PInlineContainer
justifyStringnonullto justify PLines,PBlock inside PInlineContainer takes either of space-between, space-around, space-evenly & centerr
rowsNumbernonullto create given number of rows of PLines
rowsWidthStringnonullto specify width for given number of 'rows'
rowsHeightStringnonullto specify height for given number of 'rows'
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

PLine

PLine is used to create placeholders for texts. Used with parent PInLineContainer

<PLine />
PropertyTypeRequiredDefault valueDescription
wStringno"100%"width of PLine
hStringno"1rem"height of PLine
brStringnonullborderRadius
alignStringnonullto align-self inside PInlineContainer, takes either of values flex-start,flex-end & center
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

Builtin Types

type: ParagraphPlaceholder

<ParagraphPlaceholder />
PropertyTypeRequiredDefault valueDescription
wStringno"80%"width of placeholder.
hStringno"20%"height of placeholder
brStringno"0.25rem"borderRadius
animateWaveBooleannonullto trigger shrimmer animation on childrens
animateGlowBooleannonullto trigger glow animation on childrens
rowsNumberno7total rows of lines in paragraph
rowsHeightStringno"0.75rem"height of lines in paragraph.
rowsWidthStringno"100%"width of lines in paragraph.
styleObjectnonullfor custom css styling
classNameStringnonullfor custom css class names

type: ProductPlaceholder

<ProductPlaceholder />
PropertyTypeRequiredDefault valueDescription
wStringno"20rem"width of placeholder.
hStringno"25rem"height of placeholder
brStringno"0.25rem"borderRadius
styleObjectnonullfor custom css styling
animateWaveBooleannonullto trigger shrimmer animation on childrens
animateGlowBooleannonullto trigger glow animation on childrens
classNameStringnonullfor custom css class names

type: ImagePlaceholder

<ImagePlaceholder />
PropertyTypeRequiredDefault valueDescription
wStringno"25rem"width of placeholder.
hStringno"25rem"height of placeholder
brStringno"0.25rem"borderRadius
styleObjectnonullfor custom css styling
animateWaveBooleannonullto trigger shrimmer animation on childrens
animateGlowBooleannonullto trigger glow animation on childrens
classNameStringnonullfor custom css class names

type: ListMediaPlaceholder

<ListMediaPlaceholder />
PropertyTypeRequiredDefault valueDescription
wStringno"50%"width of placeholder.
hStringno"20%"height of placeholder
brStringno"0.75rem"borderRadius
styleObjectnonullfor custom css styling
animateWaveBooleannonullto trigger shrimmer animation on childrens
animateGlowBooleannonullto trigger glow animation on childrens
classNameStringnonullfor custom css class names

Themes

PThemeProvider

PThemeProvider is the component to pass your theme colors and state. Maintains own theme state with boolean state : darkTheme and handler:handleTheme and defaults to light theme. Access darkTheme, handleTheme via useTheme()

//for providing darkTheme state and handler globally
import { PThemeProvider } from "react-khatra-placeholder";

return (
  <PThemeProvider
    lightModeBackground="orange"
    lightModeColor="brown"
    darkModeBackground="lightgreen"
    darkModeColor="green"
    darkModeShine="lightblue"
  >
    <YourTopParentComponentPage />
  </PThemeProvider>
);
PropertyTypeRequiredDefault valueDescription
lightModeColorStringnoDEFAULT_LIGHTMODE_LINE_COLORlight mode color of placeholder lines and blocks.
darkModeColorStringnoDEFAULT_DARKMODE_LINE_COLORdark mode color of placeholder lines and blocks.
lightModeBackgroundStringnoDEFAULT_LIGHTMODE_BG_COLORlight mode background color of placeholder cards.
darkModeBackgroundStringnoDEFAULT_DARKMODE_BG_COLORlight mode background color of placeholder cards.
lightModeShineStringnoDEFAULT_LIGTHMODE_SHINElight mode shine color of placeholder lines and blocks.
darkModeShineStringnoDEFAULT_DARKMODE_SHINElight mode shine color of placeholder lines and blocks.

DEFAULT_LIGHTMODE_LINE_COLOR = "#d7d7d7" DEFAULT_DARKMODE_LINE_COLOR = "#383838" DEFAULT_LIGHTMODE_BG_COLOR = "#ffffff" DEFAULT_DARKMODE_BG_COLOR = "#121212" DEFAULT_LIGTHMODE_SHINE = "#eeeeee" DEFAULT_DARKMODE_SHINE = "#6d6c6c"

useTheme()

For accessing useTheme() hook:

import { useTheme } from "react-khatra-placeholder";

const { darkTheme, handleTheme } = useTheme();
return <button onClick={() => handleTheme(!darkTheme)}>Toggle Theme</button>;

Custom Cards used in Demo

Profile Card :

<PCard w="400px" h="500px" br="12px" animateWave>
  <PBlock w="100%" h="150px" br="12px" align="center" />
  <PInLineContainer justify="center">
    <PBlock
      w="100px"
      h="100px"
      rounded
      align="center"
      style={{
        position: "relative",
        top: "-5rem",
        marginBottom: "-5rem",
        border: "2px solid grey",
      }}
    />
    <PBlock w="75%" h="1rem" align="center" />
    <PBlock w="60%" h="0.8rem" align="center" />
    <PBlock w="60%" h="0.8rem" align="center" />
  </PInLineContainer>
  <PInLineContainer justify="center">
    <PBlock w="40%" h="2rem" />
    <PBlock w="40%" h="2rem" />
    <PBlock w="10%" h="2rem" />
  </PInLineContainer>
  <PInLineContainer gap="0.8rem" justify="center">
    <PLine w="20%" h="100px" />
    <PLine w="20%" h="100px" />
    <PLine w="20%" h="100px" />
    <PLine w="20%" h="100px" />
  </PInLineContainer>
</PCard>

Product Card :

<PCard w="320px" h="400px" animateWave>
  <PBlock h="50%" br="12px" />
  <PInLineContainer justify="space-between">
    <PBlock w="30%" h="1.5rem" />
    <PBlock w="20%" h="1.5rem" />
  </PInLineContainer>
  <PInLineContainer gap="0.3rem" br="3px">
    <PLine h="0.8rem" />
    <PLine w="70%" h="0.8rem" />
    <PLine w="80%" h="0.8rem" />
  </PInLineContainer>
  <PBlock w="30%" h="1.8rem" />
</PCard>

List Card :

<PCard w="400px" h="400px" animateWave>
  <PInLineContainer gap="1rem">
    <PBlock w="80px" h="80px" br="12px" />
    <PInLineContainer w="60%" style={{ marginTop: "0.5rem" }}>
      <PLine w="100%" h="0.8rem" />
      <PLine w="60%" h="0.8rem" />
    </PInLineContainer>
  </PInLineContainer>
  <PInLineContainer gap="1rem">
    <PBlock w="80px" h="80px" br="12px" />
    <PInLineContainer w="60%" style={{ marginTop: "0.5rem" }}>
      <PLine w="100%" h="0.8rem" />
      <PLine w="60%" h="0.8rem" />
    </PInLineContainer>
  </PInLineContainer>
  <PInLineContainer gap="1rem">
    <PBlock w="80px" h="80px" br="12px" />
    <PInLineContainer w="60%" style={{ marginTop: "0.5rem" }}>
      <PLine w="100%" h="0.8rem" />
      <PLine w="60%" h="0.8rem" />
    </PInLineContainer>
  </PInLineContainer>
  <PInLineContainer gap="1rem">
    <PBlock w="80px" h="80px" br="12px" />
    <PInLineContainer w="60%" style={{ marginTop: "0.5rem" }}>
      <PLine w="100%" h="0.8rem" />
      <PLine w="60%" h="0.8rem" />
    </PInLineContainer>
  </PInLineContainer>
</PCard>

Mobile View :

<PCard w="400px" h="720px" animateGlow>
  <PInLineContainer justify="space-between">
    <PBlock w="40%" h="2rem" />
    <PInLineContainer w="20%">
      <PBlock w="2rem" h="2rem" rounded />
      <PBlock w="2rem" h="2rem" rounded />
    </PInLineContainer>
  </PInLineContainer>

  <PInLineContainer justify="space-between">
    <PBlock w="4rem" h="2rem" />
    <PBlock w="4rem" h="2rem" />
    <PBlock w="4rem" h="2rem" />
    <PBlock w="4rem" h="2rem" />
    <PBlock w="4rem" h="2rem" />
  </PInLineContainer>

  <PInLineContainer>
    <PBlock w="2rem" h="2rem" rounded />
    <PLine w="85%" h="2rem" br="18px" />
  </PInLineContainer>

  <PInLineContainer gap="0.8rem">
    <PLine w="22%" h="120px" />
    <PLine w="22%" h="120px" />
    <PLine w="22%" h="120px" />
    <PLine w="22%" h="120px" />
  </PInLineContainer>

  <PInLineContainer>
    <PBlock w="2rem" h="2rem" rounded />
    <PInLineContainer w="50%">
      <PLine w="60%" h="0.8rem" br="3px" />
      <PLine w="40%" h="0.5rem" br="3px" />
      <PBlock w="0.5rem" h="0.5rem" rounded />
    </PInLineContainer>
    <PBlock h="300px" />
  </PInLineContainer>
</PCard>

Details Card :

<PCard w="800px" h="400px" gap="1rem" animateGlow>
  <PBlock h="100%" br="12px" />
  <PInLineContainer align="space-between">
    <PBlock w="50%" h="3rem" />
    <PInLineContainer w="30%">
      <PBlock w="3rem" h="3rem" rounded />
      <PBlock w="3rem" h="3rem" rounded />
      <PBlock w="3rem" h="3rem" rounded />
      <PBlock w="3rem" h="3rem" rounded />
    </PInLineContainer>
  </PInLineContainer>
  <PInLineContainer gap="0.8rem" br="3px">
    <PLine h="1rem" />
    <PLine w="70%" h="1rem" />
    <PLine w="80%" h="1rem" />
  </PInLineContainer>
</PCard>

Description Card :

<PCard w="400px" h="400px" animateGlow>
  <PBlock h="50%" br="8px" />
  <PInLineContainer gap="0.5rem" br="3px">
    <PLine h="0.8rem" />
    <PLine w="70%" h="0.8rem" />
    <PLine w="80%" h="0.8rem" />
  </PInLineContainer>
  <PBlock w="30%" h="1.8rem" br="3px" />
</PCard>

Authors

Contribution

Feel free to contribute. Happy Coding!