-
Notifications
You must be signed in to change notification settings - Fork 0
feat: collapsible terrasetupform with opt-in prop (#921) #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ort/components/ExportToTerra/components/TerraSetUpForm/components/Button/button.styles.ts
This file contains hidden or 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,7 @@ | ||
| import styled from "@emotion/styled"; | ||
| import { Button } from "@mui/material"; | ||
|
|
||
| export const StyledButton = styled(Button)` | ||
| align-self: center; | ||
| text-transform: none; | ||
| `; |
26 changes: 26 additions & 0 deletions
26
...ts/Export/components/ExportToTerra/components/TerraSetUpForm/components/Button/button.tsx
This file contains hidden or 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,26 @@ | ||
| import { JSX } from "react"; | ||
| import { BUTTON_PROPS } from "../../../../../../../../styles/common/mui/button"; | ||
| import { useTerraSetUpUI } from "../../../../../../../../terra/setUpUI/provider/hook"; | ||
| import { STEPS_REGION_ID } from "../../constants"; | ||
| import { StyledButton } from "./button.styles"; | ||
| import { ButtonProps } from "./types"; | ||
|
|
||
| export const Button = ({ | ||
| collapsible = false, | ||
| }: ButtonProps): JSX.Element | null => { | ||
| const { isOpen, onChange } = useTerraSetUpUI(); | ||
|
|
||
| if (!collapsible) return null; | ||
|
|
||
| return ( | ||
| <StyledButton | ||
| aria-controls={STEPS_REGION_ID} | ||
| aria-expanded={isOpen} | ||
| color={isOpen ? BUTTON_PROPS.COLOR.SECONDARY : BUTTON_PROPS.COLOR.PRIMARY} | ||
| onClick={onChange} | ||
| variant={BUTTON_PROPS.VARIANT.CONTAINED} | ||
| > | ||
| {isOpen ? "Save & continue later" : "Continue"} | ||
| </StyledButton> | ||
| ); | ||
| }; | ||
3 changes: 3 additions & 0 deletions
3
...ents/Export/components/ExportToTerra/components/TerraSetUpForm/components/Button/types.ts
This file contains hidden or 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,3 @@ | ||
| export interface ButtonProps { | ||
| collapsible?: boolean; | ||
| } |
22 changes: 20 additions & 2 deletions
22
...components/ExportToTerra/components/TerraSetUpForm/components/FormStep/formStep.styles.ts
This file contains hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
src/components/Export/components/ExportToTerra/components/TerraSetUpForm/constants.ts
This file contains hidden or 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 @@ | ||
| /** | ||
| * DOM id of the collapsible steps region. Used by the toggle button's | ||
| * `aria-controls` so assistive tech can associate the toggle with the | ||
| * region it expands/collapses. | ||
| */ | ||
| export const STEPS_REGION_ID = "terra-set-up-form-steps"; |
45 changes: 45 additions & 0 deletions
45
src/components/Export/components/ExportToTerra/components/TerraSetUpForm/stories/args.ts
This file contains hidden or 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,45 @@ | ||
| import { ComponentProps } from "react"; | ||
| import { AUTH_STATUS, AuthState } from "../../../../../../../auth/types/auth"; | ||
| import { REQUEST_STATUS } from "../../../../../../../terra/types/common"; | ||
| import { TerraProfileContextProps } from "../../../../../../../terra/types/context"; | ||
| import { TerraSetUpForm } from "../terraSetUpForm"; | ||
|
|
||
| /** | ||
| * Authenticated, settled auth state — used so `TerraSetUpForm` doesn't bail | ||
| * early on its `isAuthenticated` / status guards. | ||
| */ | ||
| export const MOCK_AUTH_STATE: AuthState = { | ||
| isAuthenticated: true, | ||
| status: AUTH_STATUS.SETTLED, | ||
| }; | ||
|
|
||
| /** | ||
| * Terra profile statuses where every onboarding step is supported but not yet | ||
| * complete — produces three incomplete steps in the rendered form. | ||
| */ | ||
| export const MOCK_TERRA_PROFILE_INCOMPLETE: TerraProfileContextProps = { | ||
| terraNIHProfileLoginStatus: { | ||
| isSuccess: false, | ||
| isSupported: true, | ||
| requestStatus: REQUEST_STATUS.COMPLETED, | ||
| response: undefined, | ||
| }, | ||
| terraProfileLoginStatus: { | ||
| isSuccess: false, | ||
| isSupported: true, | ||
| requestStatus: REQUEST_STATUS.COMPLETED, | ||
| response: undefined, | ||
| }, | ||
| terraTOSLoginStatus: { | ||
| isSuccess: false, | ||
| isSupported: true, | ||
| requestStatus: REQUEST_STATUS.COMPLETED, | ||
| response: undefined, | ||
| }, | ||
| }; | ||
|
|
||
| export const DEFAULT_TERRA_SET_UP_FORM_ARGS: ComponentProps< | ||
| typeof TerraSetUpForm | ||
| > = { | ||
| collapsible: true, | ||
| }; |
5 changes: 5 additions & 0 deletions
5
...components/Export/components/ExportToTerra/components/TerraSetUpForm/stories/constants.ts
This file contains hidden or 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,5 @@ | ||
| import { ComponentProps } from "react"; | ||
| import { TerraSetUpForm } from "../terraSetUpForm"; | ||
|
|
||
| export const BOOLEAN_CONTROLS: (keyof ComponentProps<typeof TerraSetUpForm>)[] = | ||
| ["collapsible"]; |
59 changes: 59 additions & 0 deletions
59
...ort/components/ExportToTerra/components/TerraSetUpForm/stories/terraSetUpForm.stories.tsx
This file contains hidden or 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,59 @@ | ||
| import { Box } from "@mui/material"; | ||
| import type { Meta, StoryObj } from "@storybook/nextjs-vite"; | ||
| import { ComponentProps, JSX } from "react"; | ||
| import { AuthContext } from "../../../../../../../auth/contexts/auth"; | ||
| import { CONTROL_TYPE } from "../../../../../../../storybook/controls/types"; | ||
| import { configureControls } from "../../../../../../../storybook/controls/utils"; | ||
| import { TerraProfileContext } from "../../../../../../../terra/context"; | ||
| import { TerraSetUpUIProvider } from "../../../../../../../terra/setUpUI/provider/provider"; | ||
| import { TerraSetUpForm } from "../terraSetUpForm"; | ||
| import { | ||
| DEFAULT_TERRA_SET_UP_FORM_ARGS, | ||
| MOCK_AUTH_STATE, | ||
| MOCK_TERRA_PROFILE_INCOMPLETE, | ||
| } from "./args"; | ||
| import { BOOLEAN_CONTROLS } from "./constants"; | ||
|
|
||
| const meta: Meta<typeof TerraSetUpForm> = { | ||
| argTypes: { | ||
| ...configureControls<ComponentProps<typeof TerraSetUpForm>>( | ||
| BOOLEAN_CONTROLS, | ||
| CONTROL_TYPE.BOOLEAN, | ||
| ), | ||
| }, | ||
| component: TerraSetUpForm, | ||
| decorators: [ | ||
| (Story): JSX.Element => ( | ||
| <AuthContext.Provider | ||
| value={{ | ||
| authDispatch: null, | ||
| authState: MOCK_AUTH_STATE, | ||
| service: undefined, | ||
| }} | ||
| > | ||
| <TerraProfileContext.Provider value={MOCK_TERRA_PROFILE_INCOMPLETE}> | ||
| <TerraSetUpUIProvider> | ||
| <Box m={8}> | ||
| <Story /> | ||
| </Box> | ||
| </TerraSetUpUIProvider> | ||
| </TerraProfileContext.Provider> | ||
| </AuthContext.Provider> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| layout: "fullscreen", | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: DEFAULT_TERRA_SET_UP_FORM_ARGS, | ||
| }; | ||
|
|
||
| export const NotCollapsible: Story = { | ||
| args: { ...DEFAULT_TERRA_SET_UP_FORM_ARGS, collapsible: false }, | ||
| }; |
21 changes: 6 additions & 15 deletions
21
...onents/Export/components/ExportToTerra/components/TerraSetUpForm/terraSetUpForm.styles.ts
This file contains hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
src/components/Export/components/ExportToTerra/components/TerraSetUpForm/types.ts
This file contains hidden or 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,3 @@ | ||
| export interface TerraSetUpFormProps { | ||
| collapsible?: boolean; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| import { createContext } from "react"; | ||
| import { CollapseContextProps } from "./types"; | ||
|
|
||
| /** | ||
| * Collapse context. Tracks an in/out boolean and a toggle callback for any | ||
| * collapsible UI surface that opts in via `CollapseProvider`. | ||
| */ | ||
| export const CollapseContext = createContext<CollapseContextProps>({ | ||
| isIn: false, | ||
| onChange: () => undefined, | ||
| }); |
This file contains hidden or 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,11 @@ | ||
| import { useContext } from "react"; | ||
| import { CollapseContext } from "./context"; | ||
| import { CollapseContextProps } from "./types"; | ||
|
|
||
| /** | ||
| * Returns collapse context. | ||
| * @returns collapse context. | ||
| */ | ||
| export const useCollapse = (): CollapseContextProps => { | ||
| return useContext(CollapseContext); | ||
| }; |
This file contains hidden or 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,28 @@ | ||
| import { JSX, useCallback, useState } from "react"; | ||
| import { CollapseContext } from "./context"; | ||
| import { CollapseProviderProps } from "./types"; | ||
|
|
||
| /** | ||
| * Holds in-memory collapse state for any UI that opts in. Exposes `isIn` | ||
| * and a toggle callback to descendants via `CollapseContext`. Accepts a | ||
| * render-prop child so the value can be passed to a sibling context without | ||
| * an extra hook consumer. | ||
| * @param props - Provider props. | ||
| * @param props.children - React children or a render function receiving the context value. | ||
| * @param props.initialState - Initial value for `isIn` (defaults to `false`). | ||
| * @returns Collapse provider component. | ||
| */ | ||
| export function CollapseProvider({ | ||
| children, | ||
| initialState = false, | ||
| }: CollapseProviderProps): JSX.Element { | ||
|
frano-m marked this conversation as resolved.
|
||
| const [isIn, setIsIn] = useState<boolean>(initialState); | ||
|
|
||
| const onChange = useCallback(() => setIsIn((prev) => !prev), []); | ||
|
|
||
| return ( | ||
| <CollapseContext.Provider value={{ isIn, onChange }}> | ||
| {typeof children === "function" ? children({ isIn, onChange }) : children} | ||
| </CollapseContext.Provider> | ||
| ); | ||
| } | ||
This file contains hidden or 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,11 @@ | ||
| import { ReactNode } from "react"; | ||
|
|
||
| export type CollapseContextProps = { | ||
| isIn: boolean; | ||
| onChange: () => void; | ||
| }; | ||
|
|
||
| export type CollapseProviderProps = { | ||
| children: ReactNode | ((props: CollapseContextProps) => ReactNode); | ||
| initialState?: boolean; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.