Skip to content

Commit

Permalink
Merge pull request #35 from episerver/feature/AFORM-3563-Add-submit-b…
Browse files Browse the repository at this point in the history
…utton-react-component

Add submit button react component
  • Loading branch information
hungoptimizely authored Nov 16, 2023
2 parents 83443bb + 96e1ff5 commit 752c64e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions samples/sample-react-app/src/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.App {
text-align: left;
padding: 20px;
width: 60%;
}

.App-logo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactNode } from "react";

export interface ElementWrapperProps{
className: string
className?: string
isVisible: boolean,
children: ReactNode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ChoiceElementBlock = (props: ChoiceElementBlockProps) => {
<ElementWrapper className={`FormChoice ${validatorClasses}`} isVisible={checkVisible()}>
<fieldset aria-describedby={`${element.key}_desc`}>

{isNullOrEmpty(element.properties.label) &&
{!isNullOrEmpty(element.properties.label) &&
<legend className="Form__Element__Caption">{element.properties.label}</legend>
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { SubmitButton, isNullOrEmpty } from "@optimizely/forms-sdk";
import React from "react";
import { useElement } from "../../hooks/useElement";
import ElementWrapper from "../ElementWrapper";

interface SubmitButtonElementBlockProps{
element: SubmitButton
}

export const SubmitButtonElementBlock = (props: SubmitButtonElementBlockProps) => {
const { element } = props;
const { validatorClasses, extraAttr, checkVisible } = useElement(element);
//TODO: Need to get submittable status from API
const buttonDisableState = false;

return (
<ElementWrapper isVisible={checkVisible()}>
<button id={element.key}
name="submit"
type="submit"
value={element.key}
{...extraAttr}
disabled={buttonDisableState}
className={isNullOrEmpty(element.properties.image)
? `Form__Element FormExcludeDataRebind FormSubmitButton ${validatorClasses}`
: `Form__Element FormExcludeDataRebind FormSubmitButton FormImageSubmitButton ${validatorClasses}`
}
>
{isNullOrEmpty(element.properties.image) ? element.properties.label : (
<img src={element.properties.image} alt={element.properties.label} />
)}
</button>
</ElementWrapper>
);
}
4 changes: 3 additions & 1 deletion src/@optimizely/forms-react/src/components/elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UrlElementBlock } from "./UrlElementBlock";
import { ImageChoiceElementBlock } from "./ImageChoiceElementBlock";
import { FileUploadElementBlock } from "./FileUploadElementBlock";
import { ResetButtonElementBlock } from "./ResetButtonElementBlock";
import { SubmitButtonElementBlock } from "./SubmitButtonElementBlock";

export const components: Record<string, any> = {
TextboxElementBlock,
Expand All @@ -23,5 +24,6 @@ export const components: Record<string, any> = {
UrlElementBlock,
ImageChoiceElementBlock,
FileUploadElementBlock,
ResetButtonElementBlock
ResetButtonElementBlock,
SubmitButtonElementBlock
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface SubmitButton extends ButtonBase {
}

export interface SubmitButtonProperties extends ButtonBaseProperties, ConditionProperties {

finalizeForm: boolean;
image: string;
}

0 comments on commit 752c64e

Please sign in to comment.