-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extend reusable components Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Add missing hook Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Update .gitignore Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Fix missing helper method Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Add missing files Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Bump dependency version Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Remove SA component Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Fix imports Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Update package.json Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Fix import Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Update ci Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Bump versions Signed-off-by: Terence Lim <terencelimxp@gmail.com> * Add lint dependency to publish ui step Signed-off-by: Terence Lim <terencelimxp@gmail.com>
- Loading branch information
1 parent
dbc8178
commit 7d46703
Showing
69 changed files
with
2,104 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# VSCode | ||
.vscode | ||
.bloop | ||
.metals | ||
*.code-workspace | ||
|
||
# Binary directory | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
ui/packages/lib/src/components/accordion_form/AccordionForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useRef } from "react"; | ||
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from "@elastic/eui"; | ||
import { StepActions } from "../multi_steps_form/StepActions"; | ||
import { Sticky, StickyContainer } from "react-sticky"; | ||
import FormValidationContext from "../form/validation/context"; | ||
import { MultiSectionFormValidationContextProvider } from "../form/validation/multi_section_provider"; | ||
import { | ||
AccordionFormScrollController, | ||
AccordionFormSection, | ||
AccordionFormSideNav | ||
} from "."; | ||
|
||
import "./AccordionForm.scss"; | ||
import { useDimension } from "../../hooks"; | ||
import { isEmpty } from "../../utils/object"; | ||
|
||
export const isSectionInvalid = errors => !isEmpty(errors); | ||
|
||
export const AccordionForm = ({ | ||
name, | ||
sections, | ||
onCancel, | ||
onSubmit, | ||
submitLabel, | ||
renderTitle | ||
}) => { | ||
const lastSectionRef = useRef(null); | ||
const { height: lastSectionHeight } = useDimension(lastSectionRef); | ||
|
||
return ( | ||
<StickyContainer className="container"> | ||
<EuiFlexGroup direction="row" gutterSize="none" className="accordionForm"> | ||
<EuiFlexItem grow={false} className="accordionForm--sideNavContainer"> | ||
<Sticky> | ||
{({ style, isSticky }) => ( | ||
<span style={style}> | ||
{isSticky && <EuiSpacer size="m" />} | ||
<AccordionFormSideNav name={name} sections={sections} /> | ||
</span> | ||
)} | ||
</Sticky> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true} className="accordionForm--content"> | ||
<MultiSectionFormValidationContextProvider | ||
onSubmit={onSubmit} | ||
schemas={sections.map(s => s.validationSchema)} | ||
contexts={sections.map(s => s.validationContext)}> | ||
<FormValidationContext.Consumer> | ||
{({ errors, onSubmit, isSubmitting }) => ( | ||
<EuiFlexGroup | ||
direction="column" | ||
gutterSize="none" | ||
alignItems="center"> | ||
<AccordionFormScrollController sections={sections} /> | ||
|
||
{sections.map((section, idx) => ( | ||
<EuiFlexItem key={idx}> | ||
<span | ||
ref={ | ||
idx === sections.length - 1 | ||
? lastSectionRef | ||
: undefined | ||
}> | ||
<AccordionFormSection | ||
section={section} | ||
errors={errors[idx]} | ||
renderTitle={renderTitle} | ||
/> | ||
</span> | ||
</EuiFlexItem> | ||
))} | ||
|
||
<EuiSpacer size="l" /> | ||
|
||
<EuiFlexItem | ||
// set the minHeight dynamically, based on the height of the last section | ||
style={{ | ||
minHeight: `calc(100vh - ${lastSectionHeight + | ||
24 + | ||
16}px)` | ||
}}> | ||
<StepActions | ||
submitLabel={submitLabel} | ||
onCancel={onCancel} | ||
onSubmit={onSubmit} | ||
isSubmitting={isSubmitting} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</FormValidationContext.Consumer> | ||
</MultiSectionFormValidationContextProvider> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</StickyContainer> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
ui/packages/lib/src/components/accordion_form/AccordionForm.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@import "~@elastic/eui/src/global_styling/variables/index"; | ||
|
||
.accordionForm { | ||
.accordionForm--sideNavContainer { | ||
padding: $euiSize $euiSizeL; | ||
border-right: 1px solid #d3dae6; | ||
width: 216px; | ||
} | ||
|
||
.accordionForm--content { | ||
> .euiFlexGroup > .euiFlexItem { | ||
width: 90%; | ||
} | ||
} | ||
.euiAccordionForm__button:hover, | ||
.euiAccordion__button:focus { | ||
text-decoration: none !important; | ||
} | ||
|
||
// https://github.com/elastic/eui/issues/3548 | ||
.euiAccordion__childWrapper { | ||
transform: none; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
ui/packages/lib/src/components/accordion_form/AccordionFormScrollController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { FormValidationContext } from "../form/validation"; | ||
import { slugify } from "@gojek/mlp-ui"; | ||
import { scroller } from "react-scroll"; | ||
import { animatedScrollConfig } from "./scroll"; | ||
import { isSectionInvalid } from "./AccordionForm"; | ||
|
||
export const AccordionFormScrollController = ({ sections }) => { | ||
const [isFormSubmissionInProgress, setFormSubmissionInProgress] = useState( | ||
false | ||
); | ||
const { isSubmitting, errors } = useContext(FormValidationContext); | ||
|
||
useEffect(() => { | ||
!!isSubmitting && setFormSubmissionInProgress(true); | ||
}, [isSubmitting]); | ||
|
||
useEffect(() => { | ||
// after submission is completed, scroll to the first section that has errors | ||
if (isFormSubmissionInProgress && !isSubmitting) { | ||
const errorSectionIdx = errors.findIndex(isSectionInvalid); | ||
if (errorSectionIdx !== -1) | ||
scroller.scrollTo( | ||
`${slugify(sections[errorSectionIdx].title)}`, | ||
animatedScrollConfig | ||
); | ||
setFormSubmissionInProgress(false); | ||
} | ||
}, [errors, sections, isFormSubmissionInProgress, isSubmitting]); | ||
|
||
return null; | ||
}; |
27 changes: 27 additions & 0 deletions
27
ui/packages/lib/src/components/accordion_form/AccordionFormSection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import { Element } from "react-scroll"; | ||
import { EuiAccordion } from "@elastic/eui"; | ||
import { slugify } from "@gojek/mlp-ui"; | ||
import { FormValidationContext } from "../form/validation"; | ||
import { isSectionInvalid } from "./AccordionForm"; | ||
|
||
export const AccordionFormSection = ({ section, errors, renderTitle }) => ( | ||
<Element name={slugify(section.title)}> | ||
<FormValidationContext.Provider value={{ errors }}> | ||
<EuiAccordion | ||
id={`accordion-form-${slugify(section.title)}`} | ||
initialIsOpen={true} | ||
forceState={isSectionInvalid(errors) ? "open" : undefined} | ||
buttonClassName="euiAccordionForm__button" | ||
buttonContent={ | ||
renderTitle | ||
? renderTitle(section.title, section.iconType) | ||
: section.title | ||
} | ||
extraAction={section.extraAction} | ||
paddingSize="s"> | ||
{section.children} | ||
</EuiAccordion> | ||
</FormValidationContext.Provider> | ||
</Element> | ||
); |
41 changes: 41 additions & 0 deletions
41
ui/packages/lib/src/components/accordion_form/AccordionFormSideNav.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from "react"; | ||
import { slugify } from "@gojek/mlp-ui"; | ||
import { EuiIcon, EuiSideNav } from "@elastic/eui"; | ||
import { Link } from "react-scroll"; | ||
import { animatedScrollConfig } from "./scroll"; | ||
|
||
export const AccordionFormSideNav = ({ name, sections }) => { | ||
const sideNav = [ | ||
{ | ||
name: name, | ||
id: 0, | ||
items: sections.map((section, idx) => ({ | ||
id: idx, | ||
name: section.title, | ||
renderItem: () => <AccordionFormSideNavItem section={section} /> | ||
})) | ||
} | ||
]; | ||
|
||
return <EuiSideNav items={sideNav} />; | ||
}; | ||
|
||
const AccordionFormSideNavItem = ({ section }) => ( | ||
<Link | ||
className="euiSideNavItemButton euiSideNavItemButton--isClickable" | ||
activeClass="euiSideNavItemButton-isSelected" | ||
to={`${slugify(section.title)}`} | ||
spy={true} | ||
{...animatedScrollConfig}> | ||
<span className="euiSideNavItemButton__content"> | ||
{section.iconType && ( | ||
<EuiIcon | ||
type={section.iconType} | ||
className="euiSideNavItemButton__icon" | ||
size="m" | ||
/> | ||
)} | ||
<span className="euiSideNavItemButton__label">{section.title}</span> | ||
</span> | ||
</Link> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./AccordionForm"; | ||
export * from "./AccordionFormSection"; | ||
export * from "./AccordionFormSideNav"; | ||
export * from "./AccordionFormScrollController"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const animatedScrollConfig = { | ||
smooth: true, | ||
offset: 0, | ||
delay: 50, | ||
duration: 300 | ||
}; |
36 changes: 36 additions & 0 deletions
36
ui/packages/lib/src/components/confirmation_modal/ConfirmationModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { Fragment } from "react"; | ||
import { useToggle } from "@gojek/mlp-ui"; | ||
import { EuiOverlayMask, EuiConfirmModal, EuiProgress } from "@elastic/eui"; | ||
|
||
export const ConfirmationModal = ({ | ||
title, | ||
content, | ||
onConfirm, | ||
confirmButtonText, | ||
confirmButtonColor, | ||
isLoading, | ||
...props | ||
}) => { | ||
const [isModalVisible, toggleModalVisible] = useToggle(); | ||
|
||
return ( | ||
<Fragment> | ||
{props.children(toggleModalVisible)} | ||
|
||
{isModalVisible && ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
title={title} | ||
onCancel={toggleModalVisible} | ||
onConfirm={onConfirm} | ||
cancelButtonText="Cancel" | ||
confirmButtonText={confirmButtonText} | ||
buttonColor={confirmButtonColor}> | ||
{content} | ||
{isLoading && <EuiProgress size="xs" color="accent" />} | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
)} | ||
</Fragment> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ConfirmationModal"; |
Oops, something went wrong.