1
0
mirror of synced 2026-04-05 07:48:35 +08:00

feat(vue-components,react-components): 增加点击事件,使用组件状态hook

This commit is contained in:
roymondchen
2025-03-06 20:29:38 +08:00
parent 8d0040da53
commit 0736646c63
60 changed files with 594 additions and 378 deletions

View File

@@ -18,8 +18,9 @@
import React from 'react';
import type { Id, MComponent } from '@tmagic/core';
import { COMMON_EVENT_PREFIX } from '@tmagic/core';
import { useApp } from '@tmagic/react-runtime-help';
import type { Id, MComponent } from '@tmagic/schema';
interface TextSchema extends Omit<MComponent, 'id'> {
id?: Id;
@@ -46,18 +47,25 @@ const Text: React.FC<TextProps> = ({
iteratorIndex,
iteratorContainerId,
}) => {
const { app } = useApp({ config, iteratorIndex, iteratorContainerId });
const { app, node } = useApp({ config, iteratorIndex, iteratorContainerId });
if (!app) return null;
const clickHandler = () => {
if (node && app) {
app.emit(`${COMMON_EVENT_PREFIX}click`, node);
}
};
return (
<p
className={className}
style={style}
data-tmagic-id={id}
data-tmagic-id={`${id || config.id || ''}`}
data-tmagic-container-index={containerIndex}
data-tmagic-iterator-index={iteratorIndex}
data-tmagic-iterator-container-id={iteratorContainerId}
onClick={clickHandler}
>
{config.text}
</p>