Skip to content
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

Remove: defaultProps & propTypes definitions from remaining components #331

Merged
merged 20 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d517b75
fix refactor Repeater away from prop types
fabiankaegy Jun 11, 2024
2bf3f6e
fix move defaultProps to inline default values in ClipboardButton com…
fabiankaegy Jun 11, 2024
4e268c7
fix remove propTypes & defaultProps from RichTextCharacterLimit compo…
fabiankaegy Jun 11, 2024
49bcc31
fix remove propTypes & defaultProps from ListItem component
fabiankaegy Jun 11, 2024
7d268db
fix remove propTypes & defaultProps from CustomBlockAppender component
fabiankaegy Jun 11, 2024
0eb8729
fix remove defaultProps & propTypes from Image component
fabiankaegy Jun 11, 2024
26967ac
remove defaultProps & propTypes from InnerBlockSlider component
fabiankaegy Jun 11, 2024
b315bcf
remove prop types eslint rule
fabiankaegy Jun 11, 2024
0d0fca1
remove defaultProps & propTypes from PostCategoryList
fabiankaegy Jun 11, 2024
83c8b9e
remove defaultProps & propTypes from Link Component
fabiankaegy Jun 11, 2024
eeb1f48
remove defaultProps & propTypes from PostExcerpt component
fabiankaegy Jun 11, 2024
5fd28fe
remove defaultProps & propTypes from PostContext component
fabiankaegy Jun 11, 2024
397572b
remove defaultProps & propTypes from PostPrimaryCategory
fabiankaegy Jun 11, 2024
3502023
remove defaultProps & propTypes from PostPrimaryTerm component
fabiankaegy Jun 11, 2024
e2db8e1
remove defaultProps & propTypes from ContentPicker component
fabiankaegy Jun 11, 2024
06f02c3
remove defaultProps & propTypes from PickedItem Component
fabiankaegy Jun 11, 2024
9cbdfd3
remove defaultProps & propTypes from SortableList component
fabiankaegy Jun 11, 2024
fdfec62
remove defaultProps & propTypes from PostTermList component
fabiankaegy Jun 11, 2024
d6fdad1
remove no longer needed eslint ignore statements
fabiankaegy Jun 11, 2024
5ba1128
uninstall prop-types
fabiankaegy Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"import/no-extraneous-dependencies": 0,
"react/jsx-props-no-spreading": 0,
"jsdoc/check-tag-names": 0,
"import/extensions": 0
"import/extensions": 0,
"react/prop-types": 0
}
}
1 change: 0 additions & 1 deletion api/register-block-extension/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/prop-types */
/* eslint-disable react/jsx-props-no-spreading */

import { addFilter } from '@wordpress/hooks';
Expand Down Expand Up @@ -53,19 +52,19 @@
*
* @param {object} settings block settings
* @param {string} name block name
* @returns {Array}

Check failure on line 55 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Generic type 'Array<T>' requires 1 type argument(s).

Check failure on line 55 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Generic type 'Array<T>' requires 1 type argument(s).

Check failure on line 55 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Generic type 'Array<T>' requires 1 type argument(s).
*/
const addAttributesToBlock = (settings, name) => {
// return early from the block modification
if (!shouldApplyBlockExtension(name)) {
return settings;

Check failure on line 60 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Type '{}' is missing the following properties from type 'any[]': length, pop, push, concat, and 35 more.

Check failure on line 60 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Type '{}' is missing the following properties from type 'any[]': length, pop, push, concat, and 35 more.

Check failure on line 60 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Type '{}' is missing the following properties from type 'any[]': length, pop, push, concat, and 35 more.
}

// modify block registration object
return {
...settings,
attributes: {

Check failure on line 66 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Object literal may only specify known properties, and 'attributes' does not exist in type 'any[]'.

Check failure on line 66 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'attributes' does not exist in type 'any[]'.

Check failure on line 66 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'attributes' does not exist in type 'any[]'.
...settings.attributes,

Check failure on line 67 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Property 'attributes' does not exist on type 'object'.

Check failure on line 67 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'attributes' does not exist on type 'object'.

Check failure on line 67 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'attributes' does not exist on type 'object'.
...attributes,
},
};
Expand Down Expand Up @@ -96,10 +95,10 @@

return (
<>
{shouldRenderBefore && <Edit {...props} />}

Check failure on line 98 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

'Edit' cannot be used as a JSX component.

Check failure on line 98 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.

Check failure on line 98 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.
<BlockEdit {...props} />
{shouldRenderAfter && <Edit {...props} />}

Check failure on line 100 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

'Edit' cannot be used as a JSX component.

Check failure on line 100 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.

Check failure on line 100 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.
{shouldRenderFallback && <Edit {...props} />}

Check failure on line 101 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

'Edit' cannot be used as a JSX component.

Check failure on line 101 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.

Check failure on line 101 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

'Edit' cannot be used as a JSX component.
</>
);
};
Expand Down Expand Up @@ -162,10 +161,10 @@
* @returns {object}
*/
const addAdditionalPropertiesToSavedMarkup = (props, block, attributes) => {
const { className, style } = props;

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Property 'className' does not exist on type '{}'.

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Property 'style' does not exist on type '{}'.

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'className' does not exist on type '{}'.

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'style' does not exist on type '{}'.

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'className' does not exist on type '{}'.

Check failure on line 164 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'style' does not exist on type '{}'.

// return early from the block modification
if (!shouldApplyBlockExtension(block.name)) {

Check failure on line 167 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / Cypress

Property 'name' does not exist on type 'object'.

Check failure on line 167 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'name' does not exist on type 'object'.

Check failure on line 167 in api/register-block-extension/index.js

View workflow job for this annotation

GitHub Actions / build

Property 'name' does not exist on type 'object'.
return props;
}

Expand Down
15 changes: 4 additions & 11 deletions components/clipboard-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ interface ButtonLabels {
}

export const ClipboardButton: React.FC<ClipboardButtonProps> = ({
text,
disabled,
onSuccess,
labels,
text = '',
disabled = false,
onSuccess = () => {},
labels = {},
}) => {
const [hasCopied, setHasCopied] = useState(false);
const copy = labels.copy ? labels.copy : __('Copy');
Expand Down Expand Up @@ -84,10 +84,3 @@ export const ClipboardButton: React.FC<ClipboardButtonProps> = ({
</Button>
);
};

ClipboardButton.defaultProps = {
text: '',
disabled: false,
onSuccess: () => {},
labels: {},
};
15 changes: 1 addition & 14 deletions components/content-picker/PickedItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
Expand Down Expand Up @@ -51,7 +50,7 @@ function getType(mode) {
* @param {number|string} props.id id of the item
* @returns {*} React JSX
*/
const PickedItem = ({ item, isOrderable, handleItemDelete, mode, id }) => {
const PickedItem = ({ item, isOrderable = false, handleItemDelete, mode, id }) => {
const type = getType(mode);

const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({
Expand Down Expand Up @@ -140,16 +139,4 @@ const PickedItem = ({ item, isOrderable, handleItemDelete, mode, id }) => {
);
};

PickedItem.defaultProps = {
isOrderable: false,
};

PickedItem.propTypes = {
item: PropTypes.object.isRequired,
isOrderable: PropTypes.bool,
handleItemDelete: PropTypes.func.isRequired,
mode: PropTypes.string.isRequired,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
};

export default PickedItem;
22 changes: 7 additions & 15 deletions components/content-picker/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import {
useSensors,
} from '@dnd-kit/core';
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
import PropTypes from 'prop-types';
import PickedItem from './PickedItem';

const SortableList = ({ posts, isOrderable, handleItemDelete, mode, setPosts }) => {
const SortableList = ({
posts,
isOrderable = false,
handleItemDelete,
mode = 'post',
setPosts,
}) => {
const hasMultiplePosts = posts.length > 1;

const items = posts.map((item) => item.uuid);
Expand Down Expand Up @@ -45,17 +50,4 @@ const SortableList = ({ posts, isOrderable, handleItemDelete, mode, setPosts })
);
};

SortableList.defaultProps = {
isOrderable: false,
mode: 'post',
};

SortableList.propTypes = {
posts: PropTypes.array.isRequired,
isOrderable: PropTypes.bool,
handleItemDelete: PropTypes.func.isRequired,
mode: PropTypes.string,
setPosts: PropTypes.func.isRequired,
};

export default SortableList;
91 changes: 23 additions & 68 deletions components/content-picker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { select } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
Expand Down Expand Up @@ -43,7 +42,7 @@ const ContentPickerWrapper = styled.div`
* @param {Array} props.contentTypes array of content types to filter by
* @param {string} props.placeholder placeholder text for the search input
* @param {Function} props.onPickChange callback for when the picker changes
* @param {Function} props.queryFilter callback that allows to modify the query
* @param {?Function} props.queryFilter callback that allows to modify the query
* @param {number} props.maxContentItems max number of items to show in the picker
* @param {boolean} props.isOrderable whether or not the picker is sortable
* @param {string} props.singlePickedLabel label for the single picked item
Expand All @@ -54,28 +53,30 @@ const ContentPickerWrapper = styled.div`
* @param {number} props.perPage number of items to show per page
* @param {boolean} props.fetchInitialResults whether or not to fetch initial results on mount
* @param {Function} props.renderItemType callback to render the item type
* @param {Function} props.renderItem react component to render the search result item
* @param {?Function} props.renderItem react component to render the search result item
* @returns {*} React JSX
*/
const ContentPicker = ({
label,
hideLabelFromVision,
mode,
contentTypes,
placeholder,
onPickChange,
queryFilter,
maxContentItems,
isOrderable,
singlePickedLabel,
multiPickedLabel,
content,
uniqueContentItems,
excludeCurrentPost,
perPage,
fetchInitialResults,
renderItemType,
renderItem,
export const ContentPicker = ({
label = '',
hideLabelFromVision = true,
mode = 'post',
contentTypes = ['post', 'page'],
placeholder = '',
onPickChange = (ids) => {
console.log('Content picker list change', ids); // eslint-disable-line no-console
},
queryFilter = null,
maxContentItems = 1,
isOrderable = false,
singlePickedLabel = __('You have selected the following item:', '10up-block-components'),
multiPickedLabel = __('You have selected the following items:', '10up-block-components'),
content = [],
uniqueContentItems = true,
excludeCurrentPost = true,
perPage = 20,
fetchInitialResults = false,
renderItemType = defaultRenderItemType,
renderItem = null,
}) => {
const currentPostId = select('core/editor')?.getCurrentPostId();

Expand Down Expand Up @@ -187,49 +188,3 @@ const ContentPicker = ({
</StyledComponentContext>
);
};

ContentPicker.defaultProps = {
label: '',
hideLabelFromVision: true,
mode: 'post',
onPickChange: (ids) => {
console.log('Content picker list change', ids); // eslint-disable-line no-console
},
queryFilter: undefined,
contentTypes: ['post', 'page'],
placeholder: '',
content: [],
perPage: 20,
maxContentItems: 1,
uniqueContentItems: true,
isOrderable: false,
excludeCurrentPost: true,
multiPickedLabel: __('You have selected the following items:', '10up-block-components'),
singlePickedLabel: __('You have selected the following item:', '10up-block-components'),
fetchInitialResults: false,
renderItemType: defaultRenderItemType,
renderItem: undefined,
};

ContentPicker.propTypes = {
contentTypes: PropTypes.array,
content: PropTypes.array,
placeholder: PropTypes.string,
mode: PropTypes.oneOf(['post', 'user', 'term']),
label: PropTypes.string,
hideLabelFromVision: PropTypes.bool,
multiPickedLabel: PropTypes.string,
singlePickedLabel: PropTypes.string,
isOrderable: PropTypes.bool,
onPickChange: PropTypes.func,
queryFilter: PropTypes.func,
uniqueContentItems: PropTypes.bool,
excludeCurrentPost: PropTypes.bool,
maxContentItems: PropTypes.number,
perPage: PropTypes.number,
fetchInitialResults: PropTypes.bool,
renderItemType: PropTypes.func,
renderItem: PropTypes.func,
};

export { ContentPicker };
28 changes: 2 additions & 26 deletions components/custom-block-appender/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/* eslint-disable react/jsx-props-no-spreading */
/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { Inserter } from '@wordpress/block-editor';
import { Button } from '@wordpress/components';

Expand All @@ -25,8 +16,8 @@ import { Button } from '@wordpress/components';
*/
const CustomBlockAppender = ({
rootClientId,
buttonText,
icon,
buttonText = '',
icon = 'plus',
className = 'custom-block-appender',
...buttonProps
}) => {
Expand All @@ -49,19 +40,4 @@ const CustomBlockAppender = ({
);
};

CustomBlockAppender.propTypes = {
rootClientId: PropTypes.string.isRequired,
buttonText: PropTypes.string,
label: PropTypes.string,
icon: PropTypes.string,
className: PropTypes.string,
};

CustomBlockAppender.defaultProps = {
buttonText: '',
label: '',
icon: 'plus',
className: 'custom-block-appender',
};

export { CustomBlockAppender };
33 changes: 2 additions & 31 deletions components/image/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { MediaPlaceholder, InspectorControls } from '@wordpress/block-editor';
import { Spinner, FocalPointPicker, PanelBody, Placeholder } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';

import { useMedia } from '../../hooks/use-media';

const Image = (props) => {
export const Image = (props) => {
const {
id,
size = 'full',
onSelect,
focalPoint = { x: 0.5, y: 0.5 },
onChangeFocalPoint,
onChangeFocalPoint = undefined,
labels = {},
canEditImage = true,
allowedTypes = ['image'],
Expand Down Expand Up @@ -75,31 +74,3 @@ const Image = (props) => {
</>
);
};

export { Image };

Image.defaultProps = {
size: 'large',
focalPoint: { x: 0.5, y: 0.5 },
onChangeFocalPoint: undefined,
labels: {},
canEditImage: true,
allowedTypes: ['image'],
};

Image.propTypes = {
id: PropTypes.number.isRequired,
size: PropTypes.string,
onSelect: PropTypes.func.isRequired,
onChangeFocalPoint: PropTypes.func,
allowedTypes: PropTypes.array,
focalPoint: PropTypes.shape({
x: PropTypes.string,
y: PropTypes.string,
}),
labels: PropTypes.shape({
title: PropTypes.string,
instructions: PropTypes.string,
}),
canEditImage: PropTypes.bool,
};
27 changes: 4 additions & 23 deletions components/inner-block-slider/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/* eslint-disable */
// @ts-nocheck
// eslint-disable-file
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useState, useRef } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';
import { useInnerBlocksProps } from '@wordpress/block-editor';
import deprecated from '@wordpress/deprecated';
import PropTypes from 'prop-types';
/** @jsx jsx */
// eslint-disable-next-line no-unused-vars
import { jsx, css } from '@emotion/react';
import { ChevronLeft, ChevronRight } from './icons';

const InnerBlockSlider = ({
export const InnerBlockSlider = ({
parentBlockId,
slidesPerPage,
slidesPerPage = 1,
allowedBlock,
template,
slideHeight,
template = null,
slideHeight = null,
}) => {
const [currentPage, setCurrentPage] = useState(1);

Expand Down Expand Up @@ -173,19 +170,3 @@ const InnerBlockSlider = ({
</div>
);
};

InnerBlockSlider.defaultProps = {
slidesPerPage: 1,
template: null,
slideHeight: null,
};

InnerBlockSlider.propTypes = {
slidesPerPage: PropTypes.number,
parentBlockId: PropTypes.string.isRequired,
allowedBlock: PropTypes.string.isRequired,
template: PropTypes.array,
slideHeight: PropTypes.string,
};

export { InnerBlockSlider };
Loading
Loading