mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-27 08:39:59 +08:00
refactor hidden
This commit is contained in:
parent
ba37d56b45
commit
f50d201b0d
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import React, { CSSProperties } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ComponentImplementation } from '../../registry';
|
||||
|
||||
export const TextPropertySchema = Type.Object({
|
||||
raw: Type.String(),
|
||||
@ -15,9 +14,10 @@ export const TextPropertySchema = Type.Object({
|
||||
|
||||
export type TextProps = {
|
||||
value: Static<typeof TextPropertySchema>;
|
||||
style?: CSSProperties;
|
||||
};
|
||||
|
||||
const Text: ComponentImplementation<TextProps> = ({ value, style }) => {
|
||||
const Text: React.FC<TextProps> = ({ value, style }) => {
|
||||
if (value.format === 'md') {
|
||||
return <ReactMarkdown>{value.raw}</ReactMarkdown>;
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ export type TraitImplementation<T = any> = (
|
||||
}
|
||||
) => {
|
||||
props: any;
|
||||
component?: React.FC;
|
||||
};
|
||||
|
||||
class Registry {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { createTrait } from '@meta-ui/core';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { TraitImplementation } from '../../registry';
|
||||
@ -7,16 +7,15 @@ type HiddenProps = {
|
||||
hidden: Static<typeof HiddenPropertySchema>;
|
||||
};
|
||||
|
||||
const Hidden: React.FC<HiddenProps> = ({ hidden, children }) => {
|
||||
if (hidden) {
|
||||
return null;
|
||||
}
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
const useHiddenTrait: TraitImplementation<HiddenProps> = ({ hidden }) => {
|
||||
const style: CSSProperties = {};
|
||||
if (hidden) {
|
||||
style.display = 'none';
|
||||
}
|
||||
return {
|
||||
props: null,
|
||||
props: {
|
||||
style,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user