@pebblely/react
v0.0.1
Published
## Building and linking the package 1. Ensure `@pebblely/pebblely-js` and `@pebblely/shared` have been linked. 2. Build and link `@pebblely/react` ```bash npm link @pebblely/pebblely-js @pebblely/shared npm run build npm link ```
Downloads
2
Readme
@pebblely/react
Building and linking the package
- Ensure
@pebblely/pebblely-js
and@pebblely/shared
have been linked. - 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
buttonClassName
: Optional. Style 'Create background' button.containerClassName
: Optional. Style component container.imageInputLabel
: Optional. Label for file input field.inputClassName
: Optional. Style custom description input field.inputDescriptionLabel
: Optional. Label for custom description field.selectThemeLabel
: Optional. Label for theme selection component.styleColorLabel
: Optional. Label for style color picker.styleImageLabel
: Optional. Label for style image upload field.useCustomDescription
: Optional. Choose between custom description or theme. Defaults tofalse
.useCustomDimesion
: Optional. Choose whether to display custom dimension input fields. Defaults tofalse
.useStyleColor
: Optional. Show color input. Defaults tofalse
.useStyleImage
: Optional. Allow style image uploads. Defaults tofalse
.
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'
andname = 'height'
) - Image position input (use
transformPosition
andsetTransformPosition
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>
)
}