Skip to content

Commit 3bb77da

Browse files
committed
Remove duplicate 'name' from transform menu
1 parent d6ad7ae commit 3bb77da

File tree

1 file changed

+18
-0
lines changed
  • projects/packages/forms/src/blocks/field-name

1 file changed

+18
-0
lines changed

projects/packages/forms/src/blocks/field-name/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@ import { Path } from '@wordpress/components';
22
import { __ } from '@wordpress/i18n';
33
import renderMaterialIcon from '../shared/components/render-material-icon';
44
import defaultSettings from '../shared/settings';
5+
import transformsSource from '../shared/settings/transforms';
56
import { getIconColor } from '../shared/util/block-icons';
67
import deprecated from './deprecated';
78
import edit from './edit';
89
import save from './save';
910
import variations from './variations';
1011

1112
const name = 'field-name';
13+
14+
// We define variations for Name, First name, and Last name.
15+
// For this block only, override transforms to remove the generic self-transform
16+
// to `jetpack/field-name`, so the Transform menu doesn’t show duplicate “Name”.
17+
// Other blocks still use the shared transforms (and can transform to Name/its variations).
18+
function notSelfNameTransform( transform ) {
19+
return ! (
20+
Array.isArray( transform.blocks ) && transform.blocks.includes( 'jetpack/field-name' )
21+
);
22+
}
23+
24+
const transforms = {
25+
...transformsSource,
26+
to: transformsSource.to.filter( notSelfNameTransform ),
27+
};
28+
1229
const settings = {
1330
...defaultSettings,
1431
title: __( 'Name field', 'jetpack-forms' ),
@@ -19,6 +36,7 @@ const settings = {
1936
<Path d="M8.25 11.5C9.63071 11.5 10.75 10.3807 10.75 9C10.75 7.61929 9.63071 6.5 8.25 6.5C6.86929 6.5 5.75 7.61929 5.75 9C5.75 10.3807 6.86929 11.5 8.25 11.5ZM8.25 10C8.80228 10 9.25 9.55228 9.25 9C9.25 8.44772 8.80228 8 8.25 8C7.69772 8 7.25 8.44772 7.25 9C7.25 9.55228 7.69772 10 8.25 10ZM13 15.5V17.5H11.5V15.5C11.5 14.8096 10.9404 14.25 10.25 14.25H6.25C5.55964 14.25 5 14.8096 5 15.5V17.5H3.5V15.5C3.5 13.9812 4.73122 12.75 6.25 12.75H10.25C11.7688 12.75 13 13.9812 13 15.5ZM20.5 11H14.5V9.5H20.5V11ZM20.5 14.5H14.5V13H20.5V14.5Z" />
2037
),
2138
},
39+
transforms,
2240
variations,
2341
edit,
2442
deprecated,

0 commit comments

Comments
 (0)