import React, { useEffect, useState } from "react"; import { storiesOf } from "@storybook/react"; import Diff from "./Diff"; // @ts-ignore import parser from "gitdiff-parser"; import simpleDiff from "../__resources__/Diff.simple"; import hunksDiff from "../__resources__/Diff.hunks"; import binaryDiff from "../__resources__/Diff.binary"; import { DiffEventContext, File } from "./DiffTypes"; import Toast from "../toast/Toast"; import { getPath } from "./diffs"; import DiffButton from "./DiffButton"; import styled from "styled-components"; const diffFiles = parser.parse(simpleDiff); const Container = styled.div` padding: 2rem 6rem; `; storiesOf("Diff", module) .addDecorator(storyFn => {storyFn()}) .add("Default", () => ) .add("Side-By-Side", () => ) .add("Collapsed", () => ) .add("File Controls", () => ( ( alert("Arrrgggghhhh ...")} /> )} /> )) .add("File Annotation", () => ( [

Custom File annotation for {file.newPath}

]} /> )) .add("Line Annotation", () => ( { return { N2:

Line Annotation

}; }} /> )) .add("OnClick", () => { const OnClickDemo = () => { const [changeId, setChangeId] = useState(); useEffect(() => { const interval = setInterval(() => setChangeId(undefined), 2000); return () => clearInterval(interval); }); const onClick = (context: DiffEventContext) => setChangeId(context.changeId); return ( <> {changeId && } ); }; return ; }) .add("Hunks", () => { const hunkDiffFiles = parser.parse(hunksDiff); return ; }) .add("Binaries", () => { const binaryDiffFiles = parser.parse(binaryDiff); return ; }) .add("SyntaxHighlighting", () => { const filesWithLanguage = diffFiles.map((file: File) => { const ext = getPath(file).split(".")[1]; if (ext === "tsx") { file.language = "typescript"; } else { file.language = ext; } return file; }); return ; }) .add("CollapsingWithFunction", () => ( oldPath.endsWith(".java")} /> ));