generated from voxgig/model-vue
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BasicEntityCheckBoxField component and add BasicEntityRating…
…Field
- Loading branch information
1 parent
9049caf
commit 3e6fead
Showing
7 changed files
with
546 additions
and
362 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
declare function BasicEntityCheckBoxField(props: any): import("react/jsx-runtime").JSX.Element; | ||
export { BasicEntityCheckBoxField }; | ||
declare function BasicEntityCheckboxField(props: any): import("react/jsx-runtime").JSX.Element; | ||
export { BasicEntityCheckboxField }; |
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,2 @@ | ||
declare function BasicEntityRatingField(props: any): import("react/jsx-runtime").JSX.Element; | ||
export { BasicEntityRatingField }; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { useEffect, forwardRef } from "react"; | ||
|
||
import { | ||
FormControlLabel, | ||
Checkbox, | ||
Box, | ||
Rating, | ||
FormLabel, | ||
} from "@mui/material"; | ||
import { Controller } from "react-hook-form"; | ||
|
||
import type { Spec } from "./basic-types"; | ||
|
||
import { Default, Exact, Gubu, Skip } from "gubu"; | ||
const CMPNAME = "BasicEntitySliderField"; | ||
|
||
const { Open } = Gubu; | ||
const BasicEntityRatingFieldSpecShape = Gubu( | ||
Open({ | ||
field: Open({ | ||
id: String, | ||
name: String, | ||
kind: Skip(String), | ||
label: Default("", String), | ||
ux: Open({ | ||
kind: Exact("Rating"), | ||
edit: Default(true), | ||
precision: 1, | ||
props: Open({}), | ||
}), | ||
}), | ||
}), | ||
{ name: CMPNAME } | ||
); | ||
|
||
function BasicEntityRatingField(props: any) { | ||
const { spec } = props; | ||
|
||
const basicEntityRatingField: Spec = BasicEntityRatingFieldSpecShape(spec); | ||
const { control, field, getValues } = basicEntityRatingField; | ||
const val = getValues(field.name); | ||
|
||
// console.log("BasicEntityRatingField", "val", val); | ||
|
||
return ( | ||
<div key={`${field.id}-div`}> | ||
<FormLabel component="legend">{field.label}</FormLabel> | ||
<Controller | ||
key={`${field.id}-controller`} | ||
name={field.name} | ||
control={control} | ||
defaultValue={!!val || 0} | ||
render={({ field: { onChange, value } }) => ( | ||
<Rating | ||
name={field.name} | ||
value={value} | ||
precision={field.ux.precision} | ||
onChange={(_, newValue) => onChange(newValue)} | ||
{...field.ux.props} | ||
/> | ||
)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export { BasicEntityRatingField }; |