Skip to content

Receive color values #4

@adelhult

Description

@adelhult

It would be great if the component could inform its parent about what color it is, very useful for use-cases like this: digitalungdom-se/digitalungdom.se#125

I think it should work like this:

import { useState } from 'react';
import HashedBotIdenticon from '@digitalungdom/bot-identicon';

function Example() {
   const [color, setColor] = useState();
   return <HashedBotIdenticon identifier="Ada Lovelace" setColor={setColor}>;
}

I tried to implement it, However, I'm not used to writing typescript at all and I don't seem to be able to test if my code works in my local env. However, something along these lines might work:

...

export interface HashedBotIdenticonProps extends BotIdenticonProps {
  identifier?: string | number,
  setColor?: (color: [number, number, number] | undefined) => null,
}

export function HashedBotIdenticon({
  identifier,
  face,
  color,
  setColor,
  ...props
}: HashedBotIdenticonProps) {
  let hashedColor: [number, number, number] | undefined = color
  if (setColor != undefined) setColor(hashedColor)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions