diff --git a/packages/design/components/AutoFolder/index.stories.tsx b/packages/design/components/AutoFolder/index.stories.tsx new file mode 100644 index 00000000..61cbdb04 --- /dev/null +++ b/packages/design/components/AutoFolder/index.stories.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { ComponentStory, ComponentMeta } from '@storybook/react'; + +import { AutoFolder } from '.'; + +export default { + title: 'Tailchat/AutoFolder', + component: AutoFolder, + argTypes: {}, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ( + +); + +export const Default = Template.bind({}); +Default.args = { + maxHeight: 100, + children: ( +
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
foooooo
+
+ ), +}; diff --git a/packages/design/components/AutoFolder/index.tsx b/packages/design/components/AutoFolder/index.tsx new file mode 100644 index 00000000..5d0f1c69 --- /dev/null +++ b/packages/design/components/AutoFolder/index.tsx @@ -0,0 +1,57 @@ +import React, { useEffect, useRef, useState } from 'react'; + +interface AutoFolderProps { + maxHeight: number; + showFullText?: string; + backgroundColor?: string; +} +export const AutoFolder: React.FC = React.memo((props) => { + const { + maxHeight, + showFullText = 'More', + backgroundColor = 'rgba(0,0,0,0)', + } = props; + const [isShowFull, setIsShowFull] = useState(false); + const contentRef = useRef(); + + useEffect(() => { + if (contentRef.current) { + if (contentRef.current.scrollHeight > maxHeight) { + setIsShowFull(false); + } else { + setIsShowFull(true); + } + } + }, [props.maxHeight]); + + return ( +
+
{props.children}
+ + {!isShowFull && ( +
setIsShowFull(true)} + > + {showFullText} +
+ )} +
+ ); +}); +AutoFolder.displayName = 'AutoFolder';