-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/wysiwyg dynamic values #71
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ import { | |
| Description | ||
| } from '../../../base' | ||
|
|
||
| import { BaseWrapper } from '../../../dynamic/' | ||
|
|
||
| const Editor = props => { | ||
|
|
||
| const [value, setValue] = useState(props.value) | ||
|
|
@@ -27,19 +29,27 @@ const Editor = props => { | |
| props.onChange && props.onChange(value) | ||
| }, [value]) | ||
|
|
||
| const insertDynamicValue = token => setValue(prev => (prev ?? '') + token) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like there is a small issue currently If I insert a dynamic value, the state will update but it won't show up in the ProseMirror editor It might be easier to fix if we move the wrapper inside the child component (as suggested in my other comment) |
||
|
|
||
| return ( | ||
| <div className="tf-editor"> | ||
| { props.label && | ||
| <Label labelProps={ labelProps } parent={ props }> | ||
| { props.label } | ||
| </Label> } | ||
| <input { ...inputProps } type="hidden" name={ props.name } value={ value } /> | ||
| <ProseMirror | ||
| ref={ editorRef } | ||
| value={ value } | ||
| onChange={ setValue } | ||
| rawView={ props.rawView ?? true } | ||
| /> | ||
| <BaseWrapper | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to move the BaseWrapper here into the child component (ProseMirror.tsx) Currently the layout would look like this:
By moving it into ProseMirror.tsx, it could look like this instead, which will keep all our action button in the same place:
+import { BaseWrapper } from '../../../dynamic/'
// ...
const ProseMirror = forwardRef(({
rawView = true,
+ dynamic = false,
...props
}, ref) => {
// ...
return <div className="tf-editor-content">
- { rawView && <div className="tf-editor-view-toggle">
- <ButtonGroup
- label={ 'Switch view' }
- labelVisuallyHidden={ true }
- value={ view }
- onChange={ view => {
- setView(view)
- if ( view === 'raw' ) ref.current = null
- }}
- choices={{
- visual : 'Visual',
- raw : 'Raw'
- }}
- />
+ { ( rawView || dynamic ) &&
+ <div className="tf-editor-view-toggle">
+ { dynamic &&
+ <BaseWrapper
+ config={ dynamic ?? false }
+ onValueSelection={ dynamic => {
+ setValue( value + dynamic )
+ setMountKey(k => k + 1)
+ } }
+ buttonType="outside"
+ /> }
+ { rawView &&
+ <ButtonGroup
+ label={ 'Switch view' }
+ labelVisuallyHidden={ true }
+ value={ view }
+ onChange={ view => {
+ setView(view)
+ if ( view === 'raw' ) ref.current = null
+ }}
+ choices={{
+ visual : 'Visual',
+ raw : 'Raw'
+ }}
+ /> }
// ...
})
export default ProseMirrorWhich will also require to pass a dynamic props on <ProseMirror
ref={ editorRef }
value={ value }
onChange={ setValue }
rawView={ props.rawView ?? true }
+ dynamic={ props.dynamic ?? false }
/> |
||
| config={ props.dynamic ?? false } | ||
| onValueSelection={ insertDynamicValue } | ||
| buttonType="outside" | ||
| > | ||
| <input { ...inputProps } type="hidden" name={ props.name } value={ value } /> | ||
| <ProseMirror | ||
| ref={ editorRef } | ||
| value={ value } | ||
| onChange={ setValue } | ||
| rawView={ props.rawView ?? true } | ||
| /> | ||
| </BaseWrapper> | ||
| { props.description && | ||
| <Description descriptionProps={ descriptionProps } parent={ props }> | ||
| { props.description } | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't think we can add this line here, it prevent the debounced delay to be applied. Did you encounter some issues with it while testing?
If for a reason or another you have a specific case and want the result request to be sent right away you can pass a
debounceTimeprop and set it to 0