-
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: project funding stream dropdown
- Loading branch information
AlexZorkin
committed
Dec 15, 2021
1 parent
2c2d6ee
commit aaac8fd
Showing
7 changed files
with
209 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { WidgetProps } from "@rjsf/core"; | ||
import Dropdown from "@button-inc/bcgov-theme/Dropdown"; | ||
import getRequiredLabel from "../utils/getRequiredLabel"; | ||
|
||
const SelectWidget: React.FunctionComponent<WidgetProps> = (props) => { | ||
const { id, onChange, options, placeholder, label, required, uiSchema } = props; | ||
console.log(props) | ||
return ( | ||
<> | ||
<label htmlFor={`funding-stream-dropdown-${props.id}`}> | ||
{getRequiredLabel(label, required)} | ||
</label> | ||
<Dropdown | ||
id={id} | ||
onChange={(e) => onChange(e.target.value || undefined)} | ||
placeholder={placeholder} | ||
size={(uiSchema && uiSchema["bcgov:size"]) || "large"} | ||
required={required} | ||
> | ||
{options.enumOptions.map((opt) => { | ||
return ( | ||
<option key={opt.value} value={opt.value}> | ||
{opt.label} | ||
</option> | ||
); | ||
})} | ||
</Dropdown> | ||
<style jsx> | ||
{` | ||
:global(input) { | ||
width: 100%; | ||
} | ||
`} | ||
</style> | ||
</> | ||
); | ||
}; | ||
|
||
export default SelectWidget; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from "react"; | ||
import SelectWidget from "lib/theme/widgets/SelectWidget"; | ||
|
||
import { render } from "@testing-library/react"; | ||
|
||
describe("The SelectWidget Widget", () => { | ||
it("Matches the snapshot with no default value set", () => { | ||
const props: any = { | ||
id: "1", | ||
placeholder: "test placeholder", | ||
onChange: jest.fn(), | ||
label: "Search", | ||
value: undefined, | ||
required: false, | ||
schema: { | ||
anyOf: [ | ||
{ value: 1, enum: [1], type: "number", title: "Option 1" }, | ||
{ value: 2, enum: [2], type: "number", title: "Option 2" }, | ||
], | ||
}, | ||
}; | ||
|
||
const componentUnderTest = render(<SelectWidget {...props} />); | ||
|
||
expect(componentUnderTest.container).toMatchSnapshot(); | ||
}); | ||
|
||
it("Matches the snapshot with a default value set", () => { | ||
const props: any = { | ||
id: "1", | ||
placeholder: "test placeholder", | ||
onChange: jest.fn(), | ||
label: "Search", | ||
value: 1, | ||
required: false, | ||
schema: { | ||
anyOf: [ | ||
{ value: 1, enum: [1], type: "number", title: "Option 1" }, | ||
{ value: 2, enum: [2], type: "number", title: "Option 2" }, | ||
], | ||
}, | ||
}; | ||
|
||
const componentUnderTest = render(<SelectWidget {...props} />); | ||
|
||
expect(componentUnderTest.container).toMatchSnapshot(); | ||
}); | ||
}); |