-
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.
Refactor to use BaseOptionseditor instead
- Loading branch information
Showing
6 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
editor.planx.uk/src/@planx/components/Checklist/Editor/OptionEditor.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,46 @@ | ||
import { | ||
BaseOptionEditor, | ||
BaseOptionEditorProps, | ||
} from "@planx/components/shared/BaseOptionsEditor"; | ||
import React from "react"; | ||
import SimpleMenu from "ui/editor/SimpleMenu"; | ||
|
||
export type ChecklistOptionEditorProps = BaseOptionEditorProps & { | ||
index: number; | ||
groupIndex?: number; | ||
groups?: Array<string>; | ||
onMoveToGroup?: (itemIndex: number, groupIndex: number) => void; | ||
showValueField?: boolean; | ||
}; | ||
|
||
const ChecklistOptionEditor: React.FC<ChecklistOptionEditorProps> = ({ | ||
value, | ||
onChange, | ||
showValueField = false, | ||
groups, | ||
onMoveToGroup, | ||
index, | ||
}) => { | ||
return ( | ||
<BaseOptionEditor | ||
value={value} | ||
onChange={onChange} | ||
showValueField={showValueField} | ||
> | ||
{typeof index !== "undefined" && groups && onMoveToGroup && ( | ||
<SimpleMenu | ||
items={groups.map((group, groupIndex) => ({ | ||
label: `Move to ${group || `group ${groupIndex}`}`, | ||
onClick: () => { | ||
if (onMoveToGroup && typeof index === "number") | ||
onMoveToGroup(index, groupIndex); | ||
}, | ||
disabled: groupIndex === groupIndex, | ||
}))} | ||
/> | ||
)} | ||
</BaseOptionEditor> | ||
); | ||
}; | ||
|
||
export default ChecklistOptionEditor; |
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
38 changes: 38 additions & 0 deletions
38
editor.planx.uk/src/@planx/components/Question/OptionEditor.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,38 @@ | ||
import React from "react"; | ||
import Input from "ui/shared/Input/Input"; | ||
|
||
import { | ||
BaseOptionEditor, | ||
BaseOptionEditorProps, | ||
} from "../shared/BaseOptionsEditor"; | ||
|
||
const QuestionOptionEditor: React.FC<BaseOptionEditorProps> = ({ | ||
value, | ||
onChange, | ||
showValueField = false, | ||
}) => { | ||
return ( | ||
<BaseOptionEditor | ||
value={value} | ||
onChange={onChange} | ||
showValueField={showValueField} | ||
> | ||
<Input | ||
value={value.data.description || ""} | ||
placeholder="Description" | ||
multiline | ||
onChange={(ev) => | ||
onChange({ | ||
...value, | ||
data: { | ||
...value.data, | ||
description: ev.target.value, | ||
}, | ||
}) | ||
} | ||
/> | ||
</BaseOptionEditor> | ||
); | ||
}; | ||
|
||
export default QuestionOptionEditor; |
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