import { css } from "@emotion/react"; import type { ReactNode } from "react"; import { useEffect, useState } from "react"; import { Colors, LineHeight, Typography, Weight, getSpace, } from "../lib/variables"; import { MaterialSymbol } from "./MaterialSymbol"; interface Props { secret: boolean; modified: boolean; organizationUrlName: string | null; published: boolean; errorMessages: string[]; qiitaItemUrl: string | null; slide: boolean; isOlderThanRemote: boolean; } export const ArticleInfo = ({ secret, modified, organizationUrlName, published, errorMessages, qiitaItemUrl, slide, isOlderThanRemote, }: Props) => { const [isOpen, setIsOpen] = useState( localStorage.getItem("openInfoState") === "true" ? true : false, ); const toggleAccordion = (event: React.MouseEvent) => { event.preventDefault(); setIsOpen((prev) => !prev); }; useEffect(() => { localStorage.setItem("openInfoState", JSON.stringify(isOpen)); }, [isOpen]); return ( <>
記事情報 {secret ? ( <> lock {" "} 限定共有 ) : ( <> public {" "} 全体 )} {published ? ( qiitaItemUrl ? ( 投稿済み ) : ( "投稿済み" ) ) : ( "未投稿" )} {modified ? "あり" : "なし"} {organizationUrlName || "紐付けなし"} {slide ? "ON" : "OFF"}
{isOlderThanRemote && (

error { "この記事ファイルの内容は、Qiita上の記事より古い可能性があります。" }

)} {errorMessages.length > 0 && (
{errorMessages.map((errorMessage, index) => (

error {errorMessage}

))}
)} ); }; const infoStyle = css({ backgroundColor: Colors.gray10, borderRadius: 8, display: "flex", flexDirection: "column", padding: `${getSpace(3 / 2)}px ${getSpace(2)}px`, width: "100%", "& > summary::after": { fontFamily: "Material Symbols Outlined", content: "'expand_less'", }, "&[open] > summary::after": { content: "'expand_more'", }, }); const infoSummaryStyle = css({ alignItems: "center", display: "flex", cursor: "pointer", "&::-webkit-details-marker": { display: "none", }, }); interface InfoItemProps { children?: ReactNode; title: string; } const InfoItem = ({ children, title }: InfoItemProps) => { return (

{title}

{children}

); }; const infoListStyle = css({ display: "grid", gridTemplateColumns: "100px minmax(0, 1fr)", gap: getSpace(3 / 2), "& + &": { marginTop: getSpace(1 / 2), }, }); const titleStyle = css({ color: Colors.disabled, fontSize: Typography.body2, fontWeight: Weight.bold, }); const bodyStyle = css({ display: "flex", alignItems: "center", gap: ` 0 ${getSpace(1 / 2)}px`, fontSize: Typography.body2, lineHeight: LineHeight.bodyDense, wordBreak: "break-word", }); const exclamationIconStyle = css({ color: Colors.yellow60, }); const errorContentsStyle = css({ marginTop: getSpace(3), }); const errorStyle = css({ alignItems: "center", display: "flex", fontSize: Typography.body2, lineHeight: LineHeight.bodyDense, gap: getSpace(1 / 2), "& + &": { marginTop: getSpace(3 / 2), }, });