Hey
@609405399950688258
Are you sure an array or array-like structure is the optimal data structure for this format?
I don't think an array is even what you're looking for. A color is defined by three distinct components, an R, a G, and a B
I think you should use a
groupfield
With three subfields, one for each component
The array assumes every user or consumer of your application defines the color component consistently as [R, G, B], a group does not make this assumption
Instead of accessing your color as
color[0]for red, you would go
color.ror
color.redhey
@654031862146007055
I was moving
https://www.reactbits.dev/backgrounds/threadscomponent into a block to understand better fields in payload and exploit the potential of Blocks.
since the component had already defined the prop color as
color?: [number, number, number], I took it from there and tried to connect to payloadCMS
I agree, an array allows n elements, I was forcing it using maxRows, but felt wierd.
currently, I do:
fields: [
{
name: 'R',
type: 'number',
min: 0,
max: 255,
},
{
name: 'G',
type: 'number',
min: 0,
max: 255,
},
{
name: 'B',
type: 'number',
min: 0,
max: 255,
},
]and in the compont I map them:
import { Threads } from './Component.client'
export type ThreadsBlockProps = {
R: number
G: number
B: number
amplitude: number
distance: number
enableMouseInteraction: boolean
blockType: 'threads'
}
type Props = ThreadsBlockProps & {
className?: string
}
export const ThreadsBlock: React.FC<Props> = ({
R,
G,
B,
amplitude,
distance,
enableMouseInteraction,
}) => {
const color: [number, number, number] = [R, G, B]
return (
<div className="w-full h-96 relative">
<Threads
color={color}
amplitude={amplitude}
distance={distance}
enableMouseInteraction={enableMouseInteraction}
/>
</div>
)
}Ah, I see. You're constrained to use the format dictated by this library. In that case, you may have some luck with a custom component that imitates a Number hasMany field, but internally maps it to your three "real" fields that you can just hide from the ui
sounds good idea, since the library is already open source I thought would be nice to adapt it to blocks and share them with the community 🙂
This is a super cool library
I think that's a great idea
Star
Discord
online
Get dedicated engineering support directly from the Payload team.