Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event for data communicate #62

Merged
merged 6 commits into from
Dec 23, 2024
Merged

feat: add event for data communicate #62

merged 6 commits into from
Dec 23, 2024

Conversation

lvisei
Copy link
Member

@lvisei lvisei commented Dec 23, 2024

import { GPTVisLite, useEventPublish, withChartCode } from '@antv/gpt-vis';
import React from 'react';

/**
 * 自定义代码块渲染器
 */
const MyUIRendere = ({ children }) => {
  const eventPublish = useEventPublish();
  return (
    <div style={{ backgroundColor: '#f0f0f0', padding: '10px' }}>
      <p>{children}</p>
      <button
        onClick={() => {
          eventPublish('xxxclick', {});
        }}
        type="button"
      >
        click
      </button>
    </div>
  );
};
const customRenderers = { 'my-ui': MyUIRenderer };
const components = {
  code: withChartCode({
    languageRenderers: customRenderers,
    components: {},
  }),
};

const content = `
\`\`\`my-ui
my ui data ...
\`\`\`
`;
export default () => {
  const onClick = (data: any) => {
    console.log('data: ', data);
    // do something
  };

  return (
      <GPTVisLite eventSubs={{ xxxclick: onClick }} components={components}>
        {content}
      </GPTVisLite>
  );
};

Copy link

changeset-bot bot commented Dec 23, 2024

🦋 Changeset detected

Latest commit: a8a1424

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@antv/gpt-vis Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 23, 2024

😭 Deploy PR Preview a8a1424 failed. Build logs

🤖 By surge-preview

@lvisei lvisei requested a review from hustcc December 23, 2024 04:00
@lvisei
Copy link
Member Author

lvisei commented Dec 23, 2024

#61

@lvisei lvisei merged commit e333060 into main Dec 23, 2024
5 checks passed
@lvisei lvisei deleted the chore/event branch December 23, 2024 06:11
@github-actions github-actions bot mentioned this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant