Skip to content

Commit

Permalink
Import wordpress base styles
Browse files Browse the repository at this point in the history
Change Multiselect parent classname base
  • Loading branch information
rmorse committed Oct 23, 2022
1 parent 787fc9d commit 75956a9
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 73 deletions.
8 changes: 8 additions & 0 deletions components/base-styles/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Import WordPress base styles */
@import '../../node_modules/@wordpress/base-styles/colors';
@import '../../node_modules/@wordpress/base-styles/variables';
@import '../../node_modules/@wordpress/base-styles/mixins';
@import '../../node_modules/@wordpress/base-styles/breakpoints';
@import '../../node_modules/@wordpress/base-styles/animations';
@import '../../node_modules/@wordpress/base-styles/z-index';
@import '../../node_modules/@wordpress/base-styles/default-custom-properties';
82 changes: 33 additions & 49 deletions components/multiselect-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import TokenInput from './token-input';
import SuggestionsList from './suggestions-list';
// import { StyledLabel } from '../base-control/styles/base-control-styles';

const identity = ( value ) => value;
// Styles
import "./style.scss"

function getMatch( optionLabel, options = [] ) {
if ( optionLabel === '' ) {
Expand Down Expand Up @@ -57,7 +58,6 @@ export function MultiselectControl( props ) {
options = [],
maxSuggestions = 100,
value = [],
displayTransform = identity,
onChange = () => {},
onInputChange = () => {},
onFocus = undefined,
Expand All @@ -71,11 +71,9 @@ export function MultiselectControl( props ) {
__experimentalInvalid: __( 'Invalid item' ),
},
__experimentalRenderItem,
__experimentalExpandOnFocus = false,
__experimentalAutoSelectFirstMatch = true,
__experimentalValidateInput = () => true,
__experimentalShowHowTo = true,
__next36pxDefaultSize = false,
__experimentalAutoSelectFirstMatch = false,
} = props;

const instanceId = useInstanceId( MultiselectControl );
Expand Down Expand Up @@ -124,11 +122,6 @@ export function MultiselectControl( props ) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ incompleteTokenValue ] );

useEffect( () => {
updateSuggestions();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ __experimentalAutoSelectFirstMatch ] );

if ( disabled && isActive ) {
setIsActive( false );
setIncompleteTokenValue( '' );
Expand Down Expand Up @@ -433,7 +426,7 @@ export function MultiselectControl( props ) {
setIncompleteTokenValue( '' );
setSelectedSuggestionIndex( -1 );
setSelectedSuggestionScroll( false );
setIsExpanded( ! __experimentalExpandOnFocus );
setIsExpanded( true );

if ( isActive ) {
focus();
Expand Down Expand Up @@ -512,16 +505,9 @@ export function MultiselectControl( props ) {
getMatchingSuggestions( incompleteTokenValue );
const hasMatchingSuggestions = matchingSuggestions.length > 0;

const shouldExpandIfFocuses = hasFocus() && __experimentalExpandOnFocus;
setIsExpanded(
shouldExpandIfFocuses ||
( inputHasMinimumChars && hasMatchingSuggestions && hasFocus() )
);

if ( resetSelectedSuggestion ) {
if (
__experimentalAutoSelectFirstMatch &&
inputHasMinimumChars &&
hasMatchingSuggestions
) {
setSelectedSuggestionIndex( 0 );
Expand All @@ -531,22 +517,27 @@ export function MultiselectControl( props ) {
setSelectedSuggestionScroll( false );
}
}

// if ( inputHasMinimumChars ) {
const message = hasMatchingSuggestions
? sprintf(
/* translators: %d: number of results. */
_n(
'%d result found, use up and down arrow keys to navigate.',
'%d results found, use up and down arrow keys to navigate.',
matchingSuggestions.length
),

setIsExpanded(
hasFocus() ||
( inputHasMinimumChars && hasMatchingSuggestions && hasFocus() )
);

setSelectedSuggestionIndex( 0 );

const message = hasMatchingSuggestions
? sprintf(
/* translators: %d: number of results. */
_n(
'%d result found, use up and down arrow keys to navigate.',
'%d results found, use up and down arrow keys to navigate.',
matchingSuggestions.length
)
: __( 'No results.' );
),
matchingSuggestions.length
)
: __( 'No results.' );

debouncedSpeak( message, 'assertive' );
// }
debouncedSpeak( message, 'assertive' );
}
function getOptionFromValue( optionValue ) {
const foundOption = options.find(
Expand Down Expand Up @@ -599,6 +590,9 @@ export function MultiselectControl( props ) {
onBlur,
isExpanded,
selectedSuggestionIndex,
style: {
lineHeight: '24px',
}
};

return (
Expand All @@ -616,15 +610,15 @@ export function MultiselectControl( props ) {

const classes = classnames(
className,
'components-form-token-field__input-container',
'codeamp-components-multiselect-control__input-container',
{
'is-active': isActive,
'is-disabled': disabled,
}
);

let tokenFieldProps = {
className: 'components-base-control components-form-token-field',
className: 'components-base-control codeamp-components-multiselect-control',
tabIndex: -1,
};
const matchingSuggestions = getMatchingSuggestions();
Expand All @@ -645,7 +639,7 @@ export function MultiselectControl( props ) {
<div { ...tokenFieldProps }>
<label
htmlFor={ `components-form-token-input-${ instanceId }` }
className="components-form-token-field__label"
className="codeamp-components-multiselect-control__label"
>
{ label }
</label>
Expand All @@ -657,9 +651,10 @@ export function MultiselectControl( props ) {
onTouchStart={ onContainerTouched }
>
<Flex
className={ 'codeamp-components-multiselect-control__tokens-container' }
justify="flex-start"
align="center"
gap={ 1 }
align="flex-start"
gap="4px"
wrap={ true }
__next36pxDefaultSize={ __next36pxDefaultSize }
hasTokens={ !! value.length }
Expand All @@ -680,18 +675,7 @@ export function MultiselectControl( props ) {
/>
) }
</div>
{ __experimentalShowHowTo && (
<p
id={ `components-form-token-suggestions-howto-${ instanceId }` }
className="components-form-token-field__help"
>
{ tokenizeOnSpace
? __(
'Separate with commas, spaces, or the Enter key.'
)
: __( 'Separate with commas or the Enter key.' ) }
</p>
) }

</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
Expand Down
192 changes: 192 additions & 0 deletions components/multiselect-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
@import '../base-styles/style.scss';
// TODO - needs renaming for layouts + templates (some sort of base class?)

.codeamp-components-multiselect-control {
&__label {
display: inline-block;
margin-bottom: 4px;
}

&__input_container {
font-size: 13px;
line-height: normal;
}
}


.codeamp-components-multiselect-control__input-container {
@include input-control();
width: 100%;
margin: 0 0 $grid-unit-10 0;
padding: 0;
cursor: text;

&.is-disabled {
background: $gray-300;
border-color: $gray-300;
}

&.is-active {
@include input-style__focus();
}
// Token input
input[type="text"].codeamp-components-multiselect-control__input {
display: inline-block;
flex: 1;
font-family: inherit;
font-size: 16px;
width: 100%;
max-width: 100%;
margin-left: 4px;
padding: 0;
min-height: 24px;
min-width: 50px;
background: inherit;
border: 0;
color: $gray-900;
box-shadow: none;

// Resolves Zooming on iOS devices
// https://github.com/WordPress/gutenberg/issues/27405
@include break-small() {
font-size: 13px;
}

&:focus,
.codeamp-components-multiselect-control.is-active & {
outline: none;
box-shadow: none;
}
}
.codeamp-components-multiselect-control__token + input[type="text"].codeamp-components-multiselect-control__input {
width: auto;
}
}

.codeamp-components-multiselect-control__help {
font-size: $helptext-font-size;
font-style: normal;
color: $gray-700;
}


// Tokens
.codeamp-components-multiselect-control__tokens-container {
padding: 4px;
}

.codeamp-components-multiselect-control__token {
font-size: $default-font-size;
display: flex;
color: $gray-900;
max-width: 100%;

&.is-borderless {
position: relative;
padding: 0 24px 0 0;

.codeamp-components-multiselect-control__token-text {
background: transparent;
color: var(--wp-admin-theme-color);
}

.codeamp-components-multiselect-control__remove-token {
background: transparent;
color: $gray-700;
position: absolute;
top: 1px;
right: 0;
padding: 0;
}

&.is-success {
.codeamp-components-multiselect-control__token-text {
color: $alert-green;
}
}

&.is-error {
.codeamp-components-multiselect-control__token-text {
color: $alert-red;
border-radius: 4px 0 0 4px;
padding: 0 4px 0 6px;
}
}

&.is-validating {
.codeamp-components-multiselect-control__token-text {
color: $gray-900;
}
}
}

&.is-disabled {
.codeamp-components-multiselect-control__remove-token {
cursor: default;
}
}
}

.codeamp-components-multiselect-control__token-text,
.codeamp-components-multiselect-control__remove-token.components-button {
display: inline-block;
line-height: 24px;
height: auto;
background: $gray-300;
min-width: unset;
transition: all 0.2s cubic-bezier(0.4, 1, 0.4, 1);
@include reduce-motion;
}

.codeamp-components-multiselect-control__token-text {
border-radius: 2px 0 0 2px;
padding: 0 0 0 8px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.codeamp-components-multiselect-control__remove-token.components-button {
cursor: pointer;
border-radius: 0 2px 2px 0;
padding: 0 2px;
color: $gray-900;
line-height: 10px;
overflow: initial;

&:hover {
color: $gray-900;
}
}

// Suggestion list
.codeamp-components-multiselect-control__suggestions-list {
flex: 1 0 100%;
min-width: 100%;
max-height: 9em;
overflow-y: auto;
transition: all 0.15s ease-in-out;
@include reduce-motion("transition");
list-style: none;
border-top: $border-width solid $gray-700;
margin: 0;
padding: 0;
}

.codeamp-components-multiselect-control__suggestion {
color: $gray-700;
display: block;
font-size: $default-font-size;
padding: 4px 8px;
margin: 0;
cursor: pointer;

&.is-selected {
background: var(--wp-admin-theme-color);
color: $white;
}
}

.codeamp-components-multiselect-control__suggestion-match {
text-decoration: underline;
}
Loading

0 comments on commit 75956a9

Please sign in to comment.