Skip to content

Commit

Permalink
Add margin-bottom lint rules for FocalPointPicker, TextareaControl, T…
Browse files Browse the repository at this point in the history
…reeSelect (WordPress#63633)

* Add margin-bottom lint rules for FocalPointPicker, TextareaControl, TreeSelect

* Exclude stories and tests

* Fixup

* Fixup again

Co-authored-by: mirka <[email protected]>
Co-authored-by: ciampo <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Jul 18, 2024
1 parent 16704bd commit b0868e8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,31 @@ module.exports = {
],
},
},
{
// Temporary rules until we're ready to officially deprecate the bottom margins.
files: [ 'packages/*/src/**/*.[tj]s?(x)' ],
excludedFiles: [
'packages/components/src/**/@(test|stories)/**',
'**/*.@(native|ios|android).js',
],
rules: {
'no-restricted-syntax': [
'error',
...restrictedSyntax,
...restrictedSyntaxComponents,
...[
'FocalPointPicker',
'TextareaControl',
'TreeSelect',
].map( ( componentName ) => ( {
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__nextHasNoMarginBottom"]))`,
message:
componentName +
' should have the `__nextHasNoMarginBottom` prop to opt-in to the new margin-free styles.',
} ) ),
],
},
},
{
files: [
// Components package.
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/focal-point-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Example = () => {
return (
<>
<FocalPointPicker
__nextHasNoMarginBottom
url={ url }
value={ focalPoint }
onDragStart={ setFocalPoint }
Expand Down Expand Up @@ -98,3 +99,11 @@ Callback which is called at the start of drag operations.
- Required: No

Function which is called before internal updates to the value state. It receives the upcoming value and may return a modified one.

#### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version.

- Type: `Boolean`
- Required: No
- Default: `false`
1 change: 1 addition & 0 deletions packages/components/src/focal-point-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const GRID_OVERLAY_TIMEOUT = 600;
* return (
* <>
* <FocalPointPicker
* __nextHasNoMarginBottom
* url={ url }
* value={ focalPoint }
* onDragStart={ setFocalPoint }
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/textarea-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const MyTextareaControl = () => {

return (
<TextareaControl
__nextHasNoMarginBottom
label="Text"
help="Enter some text"
value={ text }
Expand Down Expand Up @@ -131,6 +132,13 @@ The current value of the textarea.

- Required: Yes

#### `__nextHasNoMarginBottom`: `Boolean`

Start opting into the new margin-free styles that will become the default in a future version.

- Required: No
- Default: `false`

## Related components

- For a field where users only enter one line of text, use the `TextControl` component.
1 change: 1 addition & 0 deletions packages/components/src/textarea-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function UnforwardedTextareaControl(
*
* return (
* <TextareaControl
* __nextHasNoMarginBottom
* label="Text"
* help="Enter some text"
* value={ text }
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/tree-select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MyTreeSelect = () => {

return (
<TreeSelect
__nextHasNoMarginBottom
label="Parent page"
noOptionLabel="No parent page"
onChange={ ( newPage ) => setPage( newPage ) }
Expand Down Expand Up @@ -89,3 +90,11 @@ An array containing the tree objects with the possible nodes the user can select

- Type: `Object[]`
- Required: No

#### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version.

- Type: `Boolean`
- Required: No
- Default: `false`
1 change: 1 addition & 0 deletions packages/components/src/tree-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function getSelectOptions(
*
* return (
* <TreeSelect
* __nextHasNoMarginBottom
* label="Parent page"
* noOptionLabel="No parent page"
* onChange={ ( newPage ) => setPage( newPage ) }
Expand Down

0 comments on commit b0868e8

Please sign in to comment.