2021-07-04 22:06:28 +03:00
|
|
|
<script>
|
2021-07-10 19:16:10 +00:00
|
|
|
import { CodeSnippet } from "carbon-components-svelte";
|
|
|
|
|
import marked from "marked";
|
2021-07-04 22:06:28 +03:00
|
|
|
import PrimaryButton from "../../PrimaryButton/index.svelte";
|
|
|
|
|
import { VARIANTS } from "../../PrimaryButton/constants";
|
|
|
|
|
import TextArea from "../../Form/TextArea.svelte";
|
|
|
|
|
|
|
|
|
|
export let title = "";
|
|
|
|
|
export let code;
|
|
|
|
|
export let name = "";
|
|
|
|
|
export let onSubmit = () => {};
|
|
|
|
|
export let onPrevious = () => {};
|
|
|
|
|
export let defaultValue = "";
|
|
|
|
|
export let disablePreviousButton = false;
|
|
|
|
|
export let isLast = false;
|
|
|
|
|
export let isPreview = false;
|
2021-07-06 08:39:17 +03:00
|
|
|
export let disabled = false;
|
2021-07-04 22:06:28 +03:00
|
|
|
|
|
|
|
|
function handleFormSubmit(event) {
|
|
|
|
|
if (isPreview) return;
|
|
|
|
|
|
|
|
|
|
onSubmit(name, defaultValue);
|
2021-07-06 08:39:17 +03:00
|
|
|
// event.target.reset();
|
2021-07-04 22:06:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handlePrevious(event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
onPrevious();
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<form on:submit|preventDefault={handleFormSubmit}>
|
|
|
|
|
<h2>{title}</h2>
|
|
|
|
|
|
|
|
|
|
{#if code}
|
2021-07-10 19:16:10 +00:00
|
|
|
<CodeSnippet {code} type="multi" />
|
2021-07-04 22:06:28 +03:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<div class="ml-4">
|
2021-07-06 08:39:17 +03:00
|
|
|
{#if disabled}
|
2021-07-10 19:16:10 +00:00
|
|
|
<div class="bg-gray-200 p-5 rounded-md mb-3">
|
|
|
|
|
{@html marked(defaultValue)}
|
|
|
|
|
</div>
|
2021-07-06 08:39:17 +03:00
|
|
|
{:else}
|
|
|
|
|
<TextArea
|
|
|
|
|
bind:value={defaultValue}
|
|
|
|
|
rows="5"
|
|
|
|
|
placeholder="Write your answer here"
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2021-07-04 22:06:28 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if !isPreview}
|
|
|
|
|
<div class="mt-3 flex items-center justify-between w-full">
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
variant={VARIANTS.OUTLINED}
|
|
|
|
|
onClick={handlePrevious}
|
|
|
|
|
label="Previous"
|
|
|
|
|
isDisabled={disablePreviousButton}
|
|
|
|
|
/>
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
variant={VARIANTS.OUTLINED}
|
|
|
|
|
type="submit"
|
|
|
|
|
label={isLast ? "Finish" : "Next"}
|
|
|
|
|
{name}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</form>
|