import * as React from 'react'; import styled from 'styled-components'; import { rem, zIndex } from '../../style/function.style'; import { imgResize } from '../../utils/imgResize'; import { PostCardConfig, PostDetail, AllDetail } from '../type'; import { FlexItem, PostErrorTip, skeletonOneLine, skeletonTwoLine, skeletonImage } from '../index.style'; import { formatDescription, formatVideoDuration, isEventFromLink } from './utils'; import { LofterPostAuthor } from './Author'; import { LofterPostLike } from './Like'; const COVER_SIZE = { 1: { width: 335, height: 188 }, 2: { width: 197, height: 267 } } export const Container = styled.div<{ size: number }>` display: block; width: ${({ size }) => rem(COVER_SIZE[size].width)}; margin-bottom: ${rem(32)}; position: relative; ${({ size }) => ( size === 2 ? ` &:not(:nth-child(3n+1)) { margin-left: ${rem(47.5)}; } ` : ` &:not(:nth-child(2n+1)) { margin-left: ${rem(16)}; } ` )} `; export const Cover = styled.div<{ src: string, size: number, skeleton?: boolean }>` display: block; width: ${({ size }) => rem(COVER_SIZE[size].width)}; height: ${({ size }) => rem(COVER_SIZE[size].height)}; border-radius: ${({ size }) => (size === 2 ? rem(16) : rem(24))}; background-image: url(${({ src }) => src}); background-repeat: no-repeat; background-size: cover; ${({ skeleton }) => ( skeleton ? skeletonImage : '' )} `; export const CoverBox = styled.div` position: relative; `; export const VideoCoverIconSvg = styled.svg` position: absolute; left: 0; right: 0; top: 0; bottom: 0; margin: auto; `; export const VideoCoverIcon = () => ( ); export const VideoDuration = styled.div` position: absolute; right: ${rem(16)}; bottom: ${rem(16)}; padding: ${rem(3)} ${rem(13)}; border-radius: ${rem(20)}; font-size: ${rem(24)}; line-height: ${rem(34)}; color: #fff; background: rgba(0, 0, 0, 0.2); `; export const Title = styled.div<{ skeleton?: boolean }>` margin-top: ${rem(16)}; height: ${rem(40)}; font-size: ${rem(28)}; line-height: ${rem(40)}; color: #2e2e2e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; ${({ skeleton }) => ( skeleton ? skeletonOneLine : '' )} .nw-dark-mode &{ color: #ccc; } `; export const Description = styled.div<{ skeleton?: boolean }>` margin-top: ${rem(8)}; height: ${rem(34)}; font-size: ${rem(24)}; line-height: ${rem(34)}; color: #b3b3b3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; ${({ skeleton }) => ( skeleton ? skeletonOneLine : '' )} .nw-dark-mode &{ color: #888; } `; export const MoreInfo = styled.div` margin-top: ${rem(12)}; display: flex; flex-direction: row; `; export class LofterPostColumnCard extends React.Component<{ postCardConfig: PostCardConfig, size?: 1 | 2, showAuthor?: boolean, showLike?: boolean, post?: false | AllDetail, }> { render() { const { post, postCardConfig, showAuthor, showLike, size = 1 } = this.props; const { cover, title, description } = postCardConfig; const skeleton = !post; const customCover = cover && cover.url; const resizedCover = imgResize( customCover || (post && post.firstImage && post.firstImage.orign) || '', COVER_SIZE[size].width, COVER_SIZE[size].height, 1 ); return ( { if ( post && !isEventFromLink(event) ) { window.location.href = post.postPageUrl; } }} > { post && post.videoPostView && (
{formatVideoDuration(post.videoPostView.videoInfo.duration)}
) }
{title || (post && post.title)} { (showAuthor || showLike) && ( { showAuthor && ( ) } { showLike && post && ( ) } ) } { post === false && ( 文章状态异常 ) } { (!postCardConfig.postId) && ( 未指定文章/合集/推集 ) }
) } }