-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Merl 1149] Add TextControl field (#1560)
* Feat: (editor-utils) EditorForm component. * Refactor: Removed unused code in Edit.tsx * Testing: Add unit tests. * Feat:(editor-utils) Text Control. * Chore: Changeset * Style: Border set in EditorForm only. * Tests:(block-editor-utils) Update snapshots.
- Loading branch information
Showing
11 changed files
with
57 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@faustwp/block-editor-utils': patch | ||
--- | ||
|
||
Feat: Handle TextControl fields in block-editor-utils. |
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,4 +1,5 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
browser: true, | ||
es6: true, | ||
|
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,6 @@ | ||
module.exports = { | ||
"rules": { | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off" | ||
} | ||
}; |
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,21 @@ | ||
import * as React from 'react'; | ||
import { TextControl } from '@wordpress/components'; | ||
import { ControlProps } from '../types/index.js'; | ||
|
||
function Text<T extends Record<string, any>>({ | ||
config, | ||
props, | ||
}: ControlProps<T>) { | ||
const onChange = (newContent: string) => { | ||
props.setAttributes({ [config.name]: newContent }); | ||
}; | ||
return ( | ||
<TextControl | ||
label={config.label} | ||
value={props.attributes[config.name]} | ||
onChange={onChange} | ||
/> | ||
); | ||
} | ||
|
||
export default Text; |
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,4 @@ | ||
import registerControl from '../helpers/registerControl.js'; | ||
import Text from './Text.js'; | ||
|
||
registerControl('text', Text); |
16 changes: 16 additions & 0 deletions
16
packages/block-editor-utils/src/helpers/registerControl.ts
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,16 @@ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { Control, FieldControl } from '../types/index.js'; | ||
|
||
function registerControl(name: FieldControl, control: Control) { | ||
addFilter( | ||
'faustBlockEditorUtils.controls', | ||
'faust-block-editor-utils', | ||
(controls: { [key: string]: Control }) => { | ||
// eslint-disable-next-line no-param-reassign | ||
controls[name] = control; | ||
return controls; | ||
}, | ||
); | ||
} | ||
|
||
export default registerControl; |
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
db848c4
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.
Check out the recent updates to your Atlas environment:
Learn more about building on Atlas in our documentation.