mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25:44 +01:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
|
|
import React, {useState} from "react";
|
||
|
|
import { storiesOf } from "@storybook/react";
|
||
|
|
import styled from "styled-components";
|
||
|
|
import Textarea from "./Textarea";
|
||
|
|
|
||
|
|
const Spacing = styled.div`
|
||
|
|
padding: 2em;
|
||
|
|
`;
|
||
|
|
|
||
|
|
const OnChangeTextarea = () => {
|
||
|
|
const [value, setValue] = useState("Start typing");
|
||
|
|
return (
|
||
|
|
<Spacing>
|
||
|
|
<Textarea value={value} onChange={v => setValue(v)} />
|
||
|
|
<hr />
|
||
|
|
<p>{value}</p>
|
||
|
|
</Spacing>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
const OnSubmitTextare = () => {
|
||
|
|
const [value, setValue] = useState("Use the ctrl/command + Enter to submit the textarea");
|
||
|
|
const [submitted, setSubmitted] = useState("");
|
||
|
|
|
||
|
|
const submit = () => {
|
||
|
|
setSubmitted(value);
|
||
|
|
setValue("");
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Spacing>
|
||
|
|
<Textarea value={value} onChange={v => setValue(v)} onSubmit={submit} />
|
||
|
|
<hr />
|
||
|
|
<p>{submitted}</p>
|
||
|
|
</Spacing>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
const OnCancelTextare = () => {
|
||
|
|
const [value, setValue] = useState("Use the escape key to clear the textarea");
|
||
|
|
|
||
|
|
const cancel = () => {
|
||
|
|
setValue("");
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Spacing>
|
||
|
|
<Textarea value={value} onChange={v => setValue(v)} onCancel={cancel} />
|
||
|
|
</Spacing>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
storiesOf("Forms|Textarea", module)
|
||
|
|
.add("OnChange", () => <OnChangeTextarea />)
|
||
|
|
.add("OnSubmit", () => <OnSubmitTextare />)
|
||
|
|
.add("OnCancel", () => <OnCancelTextare />);
|