Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
96 changes: 96 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/components/src/icon-picker-control/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const IconPickerControl = ( {
const response = await getFontAwesomeIcons( searchValue );
if ( ! response ) return;

const result = response?.data?.search.reduce(
const result = response?.data?.searchPaginated?.icons?.reduce(
( iconResults, iconData ) => {
convertResponseToClassnames(
iconData,
Expand Down Expand Up @@ -117,6 +117,7 @@ export const IconPickerControl = ( {
searchFontAwesomeIcons( searchValue );
} }
ref={ setPopoverAnchor }
__nextHasNoMarginBottom
/>

{ displayAsPopover && searchInput && isOpen && (
Expand Down
24 changes: 13 additions & 11 deletions packages/components/src/icon-picker-control/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
*
* @param {string} search - The value to search for icons.
*
* @see https://fontawesome.com/docs/apis/graphql/query-fields#search-icon
* @see https://fontawesome.com/docs/apis/graphql/query-fields#searchpaginated
* @see https://fontawesome.com/docs/apis/graphql/objects#icon
* @see https://fontawesome.com/docs/apis/graphql/objects#familystylesbylicense
* @see https://fontawesome.com/docs/apis/graphql/objects#familystyle
*/
export const getFontAwesomeIcons = async ( search ) => {
const query = `{ search(version: "6.x", first: 100, query: "${ search }")
const query = `{ searchPaginated(version: "7.x", query: "${ search }", pageSize: 50)
{
Comment on lines 11 to 13
id
familyStylesByLicense {
free {
family
style
}
pro {
family
style
icons {
id
familyStylesByLicense {
free {
family
style
}
pro {
family
style
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/deprecated/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"@sentry/browser": "^5.30.0",
"@yardinternet/gutenberg-editor-components": "file:../editor-components",
"classnames": "^2.3.2",
"create-emotion": "^10.0.27",
"debounce-promise": "^3.1.2",
"emotion": "^10.0.27",
"html-react-parser": "^1.4.3",
"invariant": "^2.2.4",
"lodash": "^4.17.21",
"react-select": "^4.3.1",
"react-sortable-hoc": "^2.0.0",
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import './assets/scss/all.min.scss';
import './assets/scss/all.min.css';

const IconPickerControl = ( { onChange, icon } ) => {
const [ isOpen, setOpen ] = useState( false );
Expand All @@ -34,7 +34,7 @@ const IconPickerControl = ( { onChange, icon } ) => {
if ( ! response ) return;
if ( response.errors ) return showErrorNotice();

const result = response.data.search.reduce(
const result = response.data.searchPaginated.icons.reduce(
( iconResults, iconData ) => {
convertResponseToClassnames( iconData ).forEach( ( value ) => {
iconResults.push( value );
Expand All @@ -51,7 +51,23 @@ const IconPickerControl = ( { onChange, icon } ) => {
};

const getFontAwesomeIcons = ( search ) => {
const query = `{ search(version: "6.x", first: 100, query: "${ search }") { id styles } }`;
const query = `{ searchPaginated(version: "7.x", pageSize: 50, query: "${ search }")
{
icons {
Comment on lines 53 to +56
id
familyStylesByLicense {
free {
family
style
}
pro {
family
style
}
}
}
}
}`;

return fetch( 'https://api.fontawesome.com', {
method: 'POST',
Expand All @@ -66,9 +82,35 @@ const IconPickerControl = ( { onChange, icon } ) => {
};

const convertResponseToClassnames = ( response ) => {
return response.styles
.filter( ( style ) => allowedStyles.includes( style ) ?? false )
.map( ( style ) => `fa-${ style } fa-${ response.id }` );
const { free, pro } = response.familyStylesByLicense;
const seen = new Set();
const familyStyles = [ ...free, ...pro ].filter( ( style ) => {
const key = `${ style.family }:${ style.style }`;
Comment on lines 84 to +88
if ( seen.has( key ) ) return false;
seen.add( key );
return true;
} );

// Convert allowed styles to the same format as the API response
const mappedAllowedStyles = allowedStyles.map( ( style ) => {
if ( style === 'duotone' ) {
return { family: 'duotone', style: 'solid' };
}
return { family: 'classic', style };
} );

return familyStyles
.filter( ( style ) =>
mappedAllowedStyles.some(
( allowedStyle ) =>
allowedStyle.family === style.family &&
allowedStyle.style === style.style
)
)
.map(
( style ) =>
`fa-${ style.family } fa-${ style.style } fa-${ response.id }`
);
};

const showErrorNotice = () => {
Expand Down
Loading