Skip to content

Commit

Permalink
ComboboxControl: Add flag for larger default size
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Jun 17, 2022
1 parent 94878bf commit 2514e59
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import { closeSmall } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { InputWrapperFlex } from './styles';
import TokenInput from '../form-token-field/token-input';
import SuggestionsList from '../form-token-field/suggestions-list';
import BaseControl from '../base-control';
import Button from '../button';
import { Flex, FlexBlock, FlexItem } from '../flex';
import { FlexBlock, FlexItem } from '../flex';
import withFocusOutside from '../higher-order/with-focus-outside';

const noop = () => {};
Expand All @@ -44,6 +45,7 @@ const DetectOutside = withFocusOutside(
);

function ComboboxControl( {
__next36pxDefaultSize,
value,
label,
options,
Expand Down Expand Up @@ -225,7 +227,9 @@ function ComboboxControl( {
tabIndex="-1"
onKeyDown={ onKeyDown }
>
<Flex>
<InputWrapperFlex
__next36pxDefaultSize={ __next36pxDefaultSize }
>
<FlexBlock>
<TokenInput
className="components-combobox-control__input"
Expand Down Expand Up @@ -257,7 +261,7 @@ function ComboboxControl( {
/>
</FlexItem>
) }
</Flex>
</InputWrapperFlex>
{ isExpanded && (
<SuggestionsList
instanceId={ instanceId }
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/combobox-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,24 @@ const mapCountryOption = ( country ) => ( {

const countryOptions = countries.map( mapCountryOption );

function CountryCodeComboboxControl( { allowReset } ) {
function CountryCodeComboboxControl( args ) {
const [ value, setValue ] = useState( null );

return (
<>
<ComboboxControl
{ ...args }
value={ value }
onChange={ setValue }
label="Select a country"
options={ countryOptions }
allowReset={ allowReset }
/>
<p>Value: { value }</p>
</>
);
}
export const _default = CountryCodeComboboxControl.bind( {} );
_default.args = {
__next36pxDefaultSize: false,
allowReset: false,
};
2 changes: 1 addition & 1 deletion packages/components/src/combobox-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ input.components-combobox-control__input[type="text"] {
align-items: flex-start;
width: 100%;
margin: 0 0 $grid-unit-10 0;
padding: $grid-unit-05;
padding: 0;

&:focus-within {
@include input-style__focus();
Expand Down
27 changes: 27 additions & 0 deletions packages/components/src/combobox-control/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
import styled from '@emotion/styled';
import { css } from '@emotion/react';

/**
* Internal dependencies
*/
import { Flex } from '../flex';
import { space } from '../ui/utils/space';

const deprecatedDefaultSize = ( { __next36pxDefaultSize } ) =>
! __next36pxDefaultSize &&
css`
height: 30px;
padding-left: ${ space( 1 ) };
padding-right: ${ space( 1 ) };
`;

export const InputWrapperFlex = styled( Flex )`
height: 36px;
padding-left: ${ space( 2 ) };
padding-right: ${ space( 2 ) };
${ deprecatedDefaultSize }
`;

0 comments on commit 2514e59

Please sign in to comment.