@@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
22import classnames from 'classnames'
33import { __ , _x } from '@wordpress/i18n'
44import Select from 'react-select'
5+ import type { FormatOptionLabelContext } from 'react-select'
56import { useSnippetForm } from '../../../hooks/useSnippetForm'
67import { SNIPPET_TYPE_SCOPES } from '../../../types/Snippet'
78import { isLicensed } from '../../../utils/screen'
@@ -31,14 +32,21 @@ const OPTIONS: SelectOption<SnippetType>[] = [
3132 { value : 'cond' , label : __ ( 'Conditions' , 'code-snippets' ) }
3233]
3334
34- const SnippetTypeOption : React . FC < SelectOption < SnippetType > > = ( { label, value } ) =>
35+ interface SnippetTypeOptionProps {
36+ option : SelectOption < SnippetType >
37+ context : FormatOptionLabelContext
38+ }
39+
40+ const SnippetTypeOption : React . FC < SnippetTypeOptionProps > = ( { option : { value, label } , context } ) =>
3541 < div className = { classnames ( 'snippet-type-option' , { 'inverted-badges' : isProType ( value ) && ! isLicensed ( ) } ) } >
36- < div >
37- { label }
38- { isProType ( value ) && ! isLicensed ( )
39- ? < span className = "badge pro-badge small-badge" > { _x ( 'Pro' , 'Upgrade to Pro' , 'code-snippets' ) } </ span >
40- : null }
41- </ div >
42+ { 'menu' === context
43+ ? < div >
44+ { label }
45+ { isProType ( value ) && ! isLicensed ( )
46+ ? < Badge name = "pro" small > { _x ( 'Pro' , 'Upgrade to Pro' , 'code-snippets' ) } </ Badge >
47+ : null }
48+ </ div >
49+ : null }
4250 < Badge name = { value } />
4351 </ div >
4452
@@ -69,12 +77,19 @@ export const SnippetTypeInput: React.FC<SnippetTypeInputProps> = ({ setIsUpgrade
6977 className = "code-snippets-select"
7078 isDisabled = { isReadOnly }
7179 options = { 0 === snippet . id ? OPTIONS : OPTIONS . filter ( option => 'cond' !== option . value ) }
80+ menuPlacement = "bottom"
7281 styles = { {
73- menu : provided => ( { ...provided , zIndex : 9999 } ) ,
82+ menu : provided => ( {
83+ ...provided ,
84+ zIndex : 9999 ,
85+ width : 'max-content' ,
86+ minWidth : '100%'
87+ } ) ,
7488 input : provided => ( { ...provided , boxShadow : 'none' } )
7589 } }
7690 value = { OPTIONS . find ( option => option . value === snippetType ) }
77- formatOptionLabel = { SnippetTypeOption }
91+ formatOptionLabel = { ( data , meta ) =>
92+ < SnippetTypeOption option = { data } context = { meta . context } /> }
7893 onChange = { option => {
7994 if ( option && isProType ( option . value ) && ! isLicensed ( ) ) {
8095 setIsUpgradeDialogOpen ( true )
0 commit comments