|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { FC } from 'react';
|
|
|
+import React, { FC, memo } from 'react';
|
|
|
import { TagCloud } from 'react-tagcloud';
|
|
|
import { ITagCountHasId } from '~/interfaces/tag';
|
|
|
|
|
|
@@ -6,27 +6,46 @@ type Props = {
|
|
|
tags:ITagCountHasId[],
|
|
|
minSize?: number,
|
|
|
maxSize?: number,
|
|
|
-}
|
|
|
+ maxTagTextLength?: number,
|
|
|
+ isDisableRandomColor?: boolean,
|
|
|
+};
|
|
|
+
|
|
|
+const defaultProps = {
|
|
|
+ isDisableRandomColor: true,
|
|
|
+};
|
|
|
|
|
|
-const MIN_FONT_SIZE = 12;
|
|
|
-const MAX_FONT_SIZE = 36;
|
|
|
+const MIN_FONT_SIZE = 10;
|
|
|
+const MAX_FONT_SIZE = 24;
|
|
|
+const MAX_TAG_TEXT_LENGTH = 8;
|
|
|
+
|
|
|
+const TagCloudBox: FC<Props> = memo((props:(Props & typeof defaultProps)) => {
|
|
|
+ const {
|
|
|
+ tags, minSize, maxSize, isDisableRandomColor,
|
|
|
+ } = props;
|
|
|
+ const maxTagTextLength: number = props.maxTagTextLength ?? MAX_TAG_TEXT_LENGTH;
|
|
|
|
|
|
-const TagCloudBox: FC<Props> = (props:Props) => {
|
|
|
return (
|
|
|
<>
|
|
|
<TagCloud
|
|
|
- minSize={props.minSize || MIN_FONT_SIZE}
|
|
|
- maxSize={props.maxSize || MAX_FONT_SIZE}
|
|
|
- tags={props.tags.map((tag) => {
|
|
|
- return { value: tag.name, count: tag.count };
|
|
|
+ minSize={minSize ?? MIN_FONT_SIZE}
|
|
|
+ maxSize={maxSize ?? MAX_FONT_SIZE}
|
|
|
+ tags={tags.map((tag:ITagCountHasId) => {
|
|
|
+ return {
|
|
|
+ // text truncation
|
|
|
+ value: (tag.name).length > maxTagTextLength ? `${(tag.name).slice(0, maxTagTextLength)}...` : tag.name,
|
|
|
+ count: tag.count,
|
|
|
+ };
|
|
|
})}
|
|
|
+ disableRandomColor={isDisableRandomColor}
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
- className="simple-cloud"
|
|
|
+ className="simple-cloud text-secondary"
|
|
|
onClick={(target) => { window.location.href = `/_search?q=tag:${encodeURIComponent(target.value)}` }}
|
|
|
/>
|
|
|
</>
|
|
|
);
|
|
|
|
|
|
-};
|
|
|
+});
|
|
|
+
|
|
|
+TagCloudBox.defaultProps = defaultProps;
|
|
|
|
|
|
export default TagCloudBox;
|