Secretmapper / react-image-annotation

An infinitely customizable image annotation library built on React
https://secretmapper.github.io/react-image-annotation/
MIT License
325 stars 135 forks source link

Annotate with fixed tags #15

Closed wynn5a closed 5 years ago

wynn5a commented 5 years ago

Awesome library!

Wondering if there is a prop or workaround for annotating image with fixed declared tags?

Thanks for your help!

Secretmapper commented 5 years ago

@wynn5a Do you mean an element that is already existing in the dom? i.e. an <img />?

If so this is not possible right now. There are too many possibilities with existing elements that it would be tricky to implement. There might be a way to do it by ensuring the child/element has a certain interface but I'll have to look into it.

I'm curious, would you be able to share the use case for this?

wynn5a commented 5 years ago

I mean using select instead of input when creating annotation, and I did this by renderEditor method already. Thanks all the same.

ChunxuYang commented 3 years ago

I mean using select instead of input when creating annotation, and I did this by renderEditor method already. Thanks all the same.

May I ask how you did it? Thanks!

wynn5a commented 3 years ago

@ChunxuYang

Finally I find the code, hope this may help 😃

Rewrite TextEditor to something like this

function TextEditor(props) {
  const tags = props.tags;
  return (
    <React.Fragment>
      <Inner>{
        tags && tags.length > 0 ?
          <Select
            defaultValue={props.annotation.data ? props.annotation.data.text : 'please select'}
            style={{ width: '200px' }}
            placeholder="select..."
            onChange={e => props.onChange({
              ...props.annotation,
              data: {
                ...props.annotation.data,
                text: e,
              },
            })}
          >
            {
              [
                tags.map(e => <Option key={e} value={e}>{e}</Option>),
              ]
            }
          </Select>
          :
          <textarea
            placeholder='Write description'
            onFocus={props.onFocus}
            onBlur={props.onBlur}
            onChange={e => props.onChange({
              ...props.annotation,
              data: {
                ...props.annotation.data,
                text: e.target.value,
              },
            })}
            value={props.value}
          />

      }
        {props.value && (
          <span style={{ marginLeft: '10px' }}>
            <Button
              type="primary"
              onClick={props.onSubmit}
            >
           Submit
            </Button>
            <Button
              type="default"
              onClick={props.onCancel}
            >
           Cancel
            </Button>
          </span>
        )}
      </Inner>
    </React.Fragment>
  );
}
ChunxuYang commented 3 years ago

That's very helpful. Thanks a lot.

2020-11-09 14:52:22"Wenming Fu" notifications@github.com写道:

@ChunxuYang

Finally I find the code, hope this may help 😃

Rewrite TextEditor to something like this

function TextEditor(props) {

const tags = props.tags;

return (

<React.Fragment>

  <Inner>{

    tags && tags.length > 0 ?

      <Select

        defaultValue={props.annotation.data ? props.annotation.data.text : 'please select'}

        style={{ width: '200px' }}

        placeholder="select..."

        onChange={e => props.onChange({

          ...props.annotation,

          data: {

            ...props.annotation.data,

            text: e,

          },

        })}

      >

        {

          [

            tags.map(e => <Option key={e} value={e}>{e}</Option>),

          ]

        }

      </Select>

      :

      <textarea

        placeholder='Write description'

        onFocus={props.onFocus}

        onBlur={props.onBlur}

        onChange={e => props.onChange({

          ...props.annotation,

          data: {

            ...props.annotation.data,

            text: e.target.value,

          },

        })}

        value={props.value}

      />

  }

    {props.value && (

      <span style={{ marginLeft: '10px' }}>

        <Button

          type="primary"

          onClick={props.onSubmit}

        >

       Submit

        </Button>

        <Button

          type="default"

          onClick={props.onCancel}

        >

       Cancel

        </Button>

      </span>

    )}

  </Inner>

</React.Fragment>

);

}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.