-
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.
chore: Boilerplate for new component
- Loading branch information
1 parent
4631d0f
commit 323af7f
Showing
13 changed files
with
100 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; | ||
import { useFormik } from "formik"; | ||
import React from "react"; | ||
import { FeaturePlaceholder } from "ui/editor/FeaturePlaceholder"; | ||
|
||
import { EditorProps } from "../ui"; | ||
import { List, parseContent } from "./model"; | ||
|
||
type Props = EditorProps<TYPES.List, List>; | ||
|
||
function ListComponent(props: Props) { | ||
const formik = useFormik({ | ||
initialValues: parseContent(props.node?.data), | ||
onSubmit: (newValues) => { | ||
props.handleSubmit?.({ | ||
type: TYPES.List, | ||
data: newValues, | ||
}); | ||
}, | ||
}); | ||
|
||
return ( | ||
<form onSubmit={formik.handleSubmit} id="modal"> | ||
<FeaturePlaceholder title="Under development" /> | ||
</form> | ||
); | ||
} | ||
|
||
export default ListComponent; |
10 changes: 10 additions & 0 deletions
10
editor.planx.uk/src/@planx/components/List/Public.test.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,10 @@ | ||
import React from "react"; | ||
import { axe, setup } from "testUtils"; | ||
|
||
import ListComponent from "./Editor"; | ||
|
||
it("should not have any accessibility violations", async () => { | ||
const { container } = setup(<ListComponent />); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); |
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 { PublicProps } from "@planx/components/ui"; | ||
import { hasFeatureFlag } from "lib/featureFlags"; | ||
import React from "react"; | ||
import { FeaturePlaceholder } from "ui/editor/FeaturePlaceholder"; | ||
|
||
import Card from "../shared/Preview/Card"; | ||
import QuestionHeader from "../shared/Preview/QuestionHeader"; | ||
import { List } from "./model"; | ||
|
||
type Props = PublicProps<List>; | ||
|
||
function ListComponent(props: Props) { | ||
if (!hasFeatureFlag("LIST_COMPONENT")) return null; | ||
|
||
return ( | ||
<Card handleSubmit={props.handleSubmit} isValid> | ||
<QuestionHeader | ||
info={props.info} | ||
policyRef={props.policyRef} | ||
howMeasured={props.howMeasured} | ||
/> | ||
<FeaturePlaceholder title="Under development" /> | ||
</Card> | ||
); | ||
} | ||
|
||
export default ListComponent; |
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,10 @@ | ||
import { MoreInformation, parseMoreInformation } from "../shared"; | ||
|
||
export interface List extends MoreInformation { | ||
fn: string; | ||
} | ||
|
||
export const parseContent = (data: Record<string, any> | undefined): List => ({ | ||
fn: data?.fn || "", | ||
...parseMoreInformation(data), | ||
}); |
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
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
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