0.0.1 • Published 7 months ago

@pebblely/react v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

@pebblely/react

Building and linking the package

  1. Ensure @pebblely/pebblely-js and @pebblely/shared have been linked.
  2. Build and link @pebblely/react
npm link @pebblely/pebblely-js @pebblely/shared
npm run build
npm link

Getting started

Ensure you have the Pebblely API key inside your .env file

PEBBLELY_API_KEY=YOUR_API_KEY

CreateBackground component

import { CreateBackground } from "@pebblely/react"

export default function Example() {
  return (
    <CreateBackground />
  )
}

Props

  1. buttonClassName: Optional. Style 'Create background' button.
  2. containerClassName: Optional. Style component container.
  3. imageInputLabel: Optional. Label for file input field.
  4. inputClassName: Optional. Style custom description input field.
  5. inputDescriptionLabel: Optional. Label for custom description field.
  6. selectThemeLabel: Optional. Label for theme selection component.
  7. styleColorLabel: Optional. Label for style color picker.
  8. styleImageLabel: Optional. Label for style image upload field.
  9. useCustomDescription: Optional. Choose between custom description or theme. Defaults to false.
  10. useCustomDimesion: Optional. Choose whether to display custom dimension input fields. Defaults to false.
  11. useStyleColor: Optional. Show color input. Defaults to false.
  12. useStyleImage: Optional. Allow style image uploads. Defaults to false.

PebblelyBasicContainer

This component gives a more flexible option to the developer for designing the experience around background creation. The following components are needed to successfully create a background:

  • Input image (name = 'inputImage')
  • Theme selector (name = 'theme') or custom description input field (name = 'description')
  • Style color (optional) (name = 'styleColor')
  • Style image (optional) (name = 'styleImage')
  • Output image dimensions' field (optional) (name = 'width' and name = 'height')
  • Image position input (use transformPosition and setTransformPosition parameters)

The package offers several components which can be used directly. But developers have the freedom to develop their own components as well. They just need to use the mentioned name attribute along with the corresponding input field.

import { 
  CreateBackground, 
  ImageDimensionInput, 
  ImageDragDrop, 
  PebblelyBasicContainer, 
  SelectThemeCombobox,
  StyleColorSelector,
} from "@pebblely/react"
import { TransformTemplates } from "@pebblely/pebblely-js"

export default function Home() {
  return (
    <main className="flex min-h-screen flex-col items-center justify-start p-24">
      <h1 className="text-xl mb-5">Create background component</h1>
      <CreateBackground 
        styleColorLabel="Style color"
        transformLabel="Product position"
        useCustomDimension={true}
        useStyleColor={true}
        useStyleImage={true}
        useTransform={true}
      />

      <PebblelyBasicContainer className="w-full space-y-4">
        {({ generatedImageSrc, isLoading, setTransformPosition, transformPosition }) => (
          <>
            {/* Input image field */}
            <ImageDragDrop />

            {/* Style image field */}
            <ImageDragDrop 
              styleImage={true}
            />

            {/* Theme selection autocomplete combobox */}
            <SelectThemeCombobox />

            {/* Output image dimension fields */}
            <ImageDimensionInput
              containerClassName="flex space-x-4 items-center"
              widthLabel="W"
              heightLabel="H"
              inputClassName="w-20 rounded-md py-1.5 px-3 text-gray-900"
            />

            {/* Input style color */}
            <div className="flex space-x-4 items-center">
              <label className="text-sm">
                Select style color
              </label>
              <StyleColorSelector 
                className="rounded-md px-1"
              />
            </div>

            {/* Select product position */}
            <div className='flex space-x-3 items-center'>
              <label className="text-sm">
                Product position
              </label>
              {Object.values(TransformTemplates).map(val => (
                <div
                  onClick={() => setTransformPosition(val)}
                  className={`${val === transformPosition ? 'bg-neutral-800' : ''} px-3 py-1.5 rounded text-sm border border-neutral-600 hover:bg-neutral-800 cursor-pointer`}
                  key={val}
                >
                  {val.toUpperCase()}
                </div>
              ))}
            </div>

            {/* Submit button */}
            <button
              className='px-5 py-1.5 w-full rounded-md bg-white text-black hover:bg-white/90 hover:shadow-xl shadow-white/40'
              type="submit"
            >
              Create background
            </button>

            {/* Show generated background */}
            {generatedImageSrc ? (
              <div className='w-full'>
                <img
                  src={generatedImageSrc}
                  alt="Generated image"
                />
              </div>
            ) : null}
          </>
        )}
      </PebblelyBasicContainer>
    </main>
  )
}