Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.6 KB
Raw Blame
import { createStaticStyles, cssVar, Flexbox, Icon, Text } from '@lobehub/ui';
import { LockIcon } from 'lucide-react';
import { memo, type ReactNode } from 'react';

import KnowledgeIcon from '@/components/KnowledgeIcon';
import { densityVars } from '@/styles/densityVars';
import { type KnowledgeItem } from '@/types/knowledgeBase';

import Actions from './Action';

const styles = createStaticStyles(({ css, cssVar }) => ({
  card: css`
    cursor: pointer;

    position: relative;

    overflow: hidden;

    padding: ${densityVars.contentGap};
    border: 1px solid ${cssVar.colorBorderSecondary};
    border-radius: ${cssVar.borderRadiusLG};

    background: ${cssVar.colorBgContainer};

    transition: all ${cssVar.motionDurationMid};

    &:hover {
      border-color: ${cssVar.colorPrimary};
      box-shadow: ${cssVar.boxShadowTertiary};
    }
  `,
  desc: css`
    margin: 0 !important;
    font-size: 12px;
    line-height: 1.4;
    color: ${cssVar.colorTextDescription};
  `,
  title: css`
    margin: 0 !important;
    font-size: ${densityVars.fontSize};
    font-weight: 500;
    line-height: 1.4;
  `,
}));

interface MasonryItemProps extends KnowledgeItem {
  action?: ReactNode;
}

const MasonryItem = memo<MasonryItemProps>(
  ({ action, id, fileType, name, type, description, enabled, memberRestricted, visibility }) => {
    return (
      <div className={styles.card}>
        <Flexbox gap={12} style={{ position: 'relative' }}>
          <Flexbox horizontal align={'center'} gap={12}>
            <KnowledgeIcon
              fileType={fileType}
              locked={memberRestricted}
              name={name}
              size={{ file: 48, repo: 48 }}
              type={type}
            />
            <Flexbox flex={1} gap={6} style={{ overflow: 'hidden', position: 'relative' }}>
              <Flexbox horizontal align={'center'} gap={6}>
                {visibility === 'private' && (
                  <Icon color={cssVar.colorTextDescription} icon={LockIcon} size={12} />
                )}
                <Text className={styles.title} ellipsis={{ rows: 2 }}>
                  {name}
                </Text>
              </Flexbox>
            </Flexbox>
          </Flexbox>
          {description && (
            <Text className={styles.desc} ellipsis={{ rows: 3 }}>
              {description}
            </Text>
          )}
          <Flexbox align={'center'} justify={'flex-end'}>
            {action === undefined ? <Actions enabled={enabled} id={id} type={type} /> : action}
          </Flexbox>
        </Flexbox>
      </div>
    );
  },
);

MasonryItem.displayName = 'MasonryItem';

export default MasonryItem;