refactor hidden

This commit is contained in:
Bowen Tan 2021-08-24 17:42:42 +08:00
parent ba37d56b45
commit f50d201b0d
3 changed files with 11 additions and 13 deletions

View File

@ -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>;
}

View File

@ -60,7 +60,6 @@ export type TraitImplementation<T = any> = (
}
) => {
props: any;
component?: React.FC;
};
class Registry {

View File

@ -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,
},
};
};