-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libs/form-builder): remove previous button and actions wrapper (#42
- Loading branch information
Showing
28 changed files
with
258 additions
and
155 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
36 changes: 36 additions & 0 deletions
36
apps/demo/src/app/examples/with-material-ui/atoms/previous-context.component.tsx
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 { | ||
setPreviousStep, | ||
useFormsDispatch, | ||
useFormsState, | ||
getCurrentStepIndex | ||
} from '@bedrockstreaming/form-context'; | ||
import { Button } from '@mui/material'; | ||
|
||
export const Previous = ({ | ||
label, | ||
formId, | ||
...props | ||
}: { | ||
label: string; | ||
formId: string; | ||
}) => { | ||
const dispatch = useFormsDispatch(); | ||
const state = useFormsState(); | ||
const shouldDisplayPrevious = getCurrentStepIndex(formId)(state) !== 0; | ||
|
||
const handlePreviousStep = () => { | ||
dispatch(setPreviousStep(formId)); | ||
}; | ||
|
||
return shouldDisplayPrevious ? ( | ||
<Button | ||
onClick={handlePreviousStep} | ||
variant="outlined" | ||
sx={{ margin: 1 }} | ||
type="button" | ||
{...props} | ||
> | ||
{label} | ||
</Button> | ||
) : null; | ||
}; |
35 changes: 35 additions & 0 deletions
35
apps/demo/src/app/examples/with-material-ui/atoms/previous-redux.component.tsx
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,35 @@ | ||
import { Button } from '@mui/material'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { | ||
setPreviousStep, | ||
getCurrentStepIndex | ||
} from '@bedrockstreaming/form-redux'; | ||
|
||
export const Previous = ({ | ||
label, | ||
formId, | ||
...props | ||
}: { | ||
label: string; | ||
formId: string; | ||
}) => { | ||
const dispatch = useDispatch(); | ||
|
||
const shouldDisplayPrevious = useSelector(getCurrentStepIndex(formId)) !== 0; | ||
|
||
const handlePreviousStep = () => { | ||
dispatch(setPreviousStep(formId)); | ||
}; | ||
|
||
return shouldDisplayPrevious ? ( | ||
<Button | ||
onClick={handlePreviousStep} | ||
variant="outlined" | ||
sx={{ margin: 1 }} | ||
type="button" | ||
{...props} | ||
> | ||
{label} | ||
</Button> | ||
) : null; | ||
}; |
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,17 +1,30 @@ | ||
import { Text } from './dictionary/text.component'; | ||
import { Password } from './dictionary/password.component'; | ||
import { DateInput } from './dictionary/date.component'; | ||
import { Submit } from './dictionary/submit.component'; | ||
import { Select } from './dictionary/select.component'; | ||
import { Previous } from './dictionary/previous.component'; | ||
import { Checkbox } from './dictionary/checkBox.component'; | ||
import { Submit as SubmitRedux } from './dictionary/submit-redux.component'; | ||
import { Submit as SubmitContext } from './dictionary/submit-context.component'; | ||
|
||
export const dictionary = { | ||
/** | ||
* Here we expose different dictionaries to demonstrate different stores management. | ||
* The base dictionary is not exported since it contains no submit field. | ||
*/ | ||
|
||
const DICTIONARY = { | ||
text: Text, | ||
password: Password, | ||
date: DateInput, | ||
select: Select, | ||
checkbox: Checkbox, | ||
submit: Submit, | ||
previous: Previous | ||
checkbox: Checkbox | ||
}; | ||
|
||
export const REDUX_DICTIONARY = { | ||
...DICTIONARY, | ||
submit: SubmitRedux | ||
}; | ||
|
||
export const CONTEXT_DICTIONARY = { | ||
...DICTIONARY, | ||
submit: SubmitContext | ||
}; |
9 changes: 0 additions & 9 deletions
9
apps/demo/src/app/examples/with-material-ui/dictionary/previous.component.tsx
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
apps/demo/src/app/examples/with-material-ui/dictionary/submit-context.component.tsx
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,20 @@ | ||
import { Button, Box } from '@mui/material'; | ||
import { Previous } from '../atoms/previous-context.component'; | ||
|
||
export const Submit = ({ | ||
label, | ||
formId, | ||
...props | ||
}: { | ||
label: string; | ||
formId: string; | ||
}) => { | ||
return ( | ||
<Box display="flex" justifyContent="center" width="100%"> | ||
<Previous label="Previous" formId={formId} /> | ||
<Button variant="contained" sx={{ margin: 1 }} type="submit" {...props}> | ||
{label} | ||
</Button> | ||
</Box> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
apps/demo/src/app/examples/with-material-ui/dictionary/submit-redux.component.tsx
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,20 @@ | ||
import { Button, Box } from '@mui/material'; | ||
import { Previous } from '../atoms/previous-redux.component'; | ||
|
||
export const Submit = ({ | ||
label, | ||
formId, | ||
...props | ||
}: { | ||
label: string; | ||
formId: string; | ||
}) => { | ||
return ( | ||
<Box display="flex" justifyContent="center" width="100%"> | ||
<Previous label="Previous" formId={formId} /> | ||
<Button variant="contained" sx={{ margin: 1 }} type="submit" {...props}> | ||
{label} | ||
</Button> | ||
</Box> | ||
); | ||
}; |
9 changes: 0 additions & 9 deletions
9
apps/demo/src/app/examples/with-material-ui/dictionary/submit.component.tsx
This file was deleted.
Oops, something went wrong.
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
7 changes: 0 additions & 7 deletions
7
apps/demo/src/app/examples/with-styled-components/dictionary/previous.component.tsx
This file was deleted.
Oops, something went wrong.
55 changes: 51 additions & 4 deletions
55
apps/demo/src/app/examples/with-styled-components/dictionary/submit.component.tsx
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,7 +1,54 @@ | ||
export const Submit = ({ label, ...props }: { label: string }) => { | ||
import styled from 'styled-components'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { | ||
getCurrentStepIndex, | ||
setPreviousStep | ||
} from '@bedrockstreaming/form-redux'; | ||
|
||
const ActionsWrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
width: 100%; | ||
`; | ||
|
||
const SubmitButton = styled.button` | ||
padding: 8px 16px; | ||
background: rgba(150, 100, 255); | ||
`; | ||
|
||
const PreviousButton = styled.button` | ||
padding: 8px 16px; | ||
color: rgba(150, 100, 255); | ||
background: white | ||
border: 1px solid rgba(150, 100, 255); | ||
`; | ||
|
||
export const Submit = ({ | ||
label, | ||
formId, | ||
...props | ||
}: { | ||
label: string; | ||
formId: string; | ||
}) => { | ||
const dispatch = useDispatch(); | ||
|
||
const shouldDisplayPrevious = useSelector(getCurrentStepIndex(formId)) !== 0; | ||
|
||
const handlePreviousStep = () => { | ||
dispatch(setPreviousStep(formId)); | ||
}; | ||
|
||
return ( | ||
<button type="submit" {...props}> | ||
{label} | ||
</button> | ||
<ActionsWrapper> | ||
{shouldDisplayPrevious && ( | ||
<PreviousButton onClick={handlePreviousStep} type="button"> | ||
Previous | ||
</PreviousButton> | ||
)} | ||
<SubmitButton type="submit" {...props}> | ||
{label} | ||
</SubmitButton> | ||
</ActionsWrapper> | ||
); | ||
}; |
Oops, something went wrong.