nomadro/apps/miniprogram/h5/src/components/H5Box.tsx
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

76 lines
1.5 KiB
TypeScript

import type { CSSProperties, ReactNode } from 'react'
import { View, Text } from '@tarojs/components'
const isH5 = process.env.TARO_ENV === 'h5'
type BoxProps = {
className?: string
id?: string
children?: ReactNode
onClick?: () => void
html?: string
style?: CSSProperties
'aria-hidden'?: boolean
'aria-label'?: string
'data-theme'?: string
}
/** H5 uses native div (taro-view-core defaults to inline and breaks grid/absolute). */
export function H5Box({
className,
id,
children,
onClick,
html,
style,
'aria-hidden': ariaHidden,
'aria-label': ariaLabel,
'data-theme': dataTheme,
}: BoxProps) {
if (isH5) {
return (
<div
id={id}
className={className}
style={style}
onClick={onClick}
aria-hidden={ariaHidden}
aria-label={ariaLabel}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</div>
)
}
return (
<View
id={id}
className={className}
style={style}
onClick={onClick}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</View>
)
}
export function H5Txt({
className,
id,
children,
}: {
className?: string
id?: string
children?: ReactNode
}) {
if (isH5) return <span id={id} className={className}>{children}</span>
return (
<Text id={id} className={className}>
{children}
</Text>
)
}