From 6050c4090b52f21b4ad0b52d9f97754e7d034d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aappo=20=C3=85lander?= Date: Tue, 19 Jan 2021 14:06:40 +0200 Subject: [PATCH] Add style wrapper for SearchInput. --- .../SearchInput/SearchInput.baseStyles.tsx | 7 +- src/core/Form/SearchInput/SearchInput.tsx | 122 +++++++------- .../__snapshots__/SearchInput.test.tsx.snap | 155 +++++++++--------- 3 files changed, 152 insertions(+), 132 deletions(-) diff --git a/src/core/Form/SearchInput/SearchInput.baseStyles.tsx b/src/core/Form/SearchInput/SearchInput.baseStyles.tsx index 84fa1dbf51..d0302e45b1 100644 --- a/src/core/Form/SearchInput/SearchInput.baseStyles.tsx +++ b/src/core/Form/SearchInput/SearchInput.baseStyles.tsx @@ -7,11 +7,16 @@ export const baseStyles = withSuomifiTheme( ({ theme }: TokensAndTheme) => css` &.fi-search-input { ${font({ theme })('bodyText')} - display: inline-block; width: 290px; } & .fi-search-input { + &_wrapper { + width: 100%; + min-width: 105px; + display: inline-block; + } + &_functionality-container { position: relative; } diff --git a/src/core/Form/SearchInput/SearchInput.tsx b/src/core/Form/SearchInput/SearchInput.tsx index 2c26b8bed7..6e1fe24adb 100644 --- a/src/core/Form/SearchInput/SearchInput.tsx +++ b/src/core/Form/SearchInput/SearchInput.tsx @@ -4,6 +4,7 @@ import classnames from 'classnames'; import { HtmlInputWithRef, HtmlInputProps, + HtmlSpan, HtmlDiv, HtmlDivProps, HtmlButton, @@ -85,6 +86,7 @@ const searchInputClassNames = { fullWidth: `${baseClassName}--full-width`, error: `${baseClassName}--error`, notEmpty: `${baseClassName}--not-empty`, + styleWrapper: `${baseClassName}_wrapper`, inputElement: `${baseClassName}_input`, inputElementContainer: `${baseClassName}_input-element-container`, functionalityContainer: `${baseClassName}_functionality-container`, @@ -208,66 +210,70 @@ class BaseSearchInput extends Component { [searchInputClassNames.fullWidth]: fullWidth, })} > - - {labelText} - - - {(debouncer: Function, cancelDebounce: Function) => ( - - - ) => { - const eventValue = event.currentTarget.value; - conditionalSetState(eventValue); - if (propOnChange) { - debouncer(propOnChange, eventValue); - } + + + {labelText} + + + {(debouncer: Function, cancelDebounce: Function) => ( + + + ) => { + const eventValue = event.currentTarget.value; + conditionalSetState(eventValue); + if (propOnChange) { + debouncer(propOnChange, eventValue); + } + }} + onKeyPress={onKeyPress} + onKeyDown={onKeyDown} + /> + + { + onClear(); + cancelDebounce(); }} - onKeyPress={onKeyPress} - onKeyDown={onKeyDown} - /> + > + {clearButtonLabel} + + + + {searchButtonLabel} + + - { - onClear(); - cancelDebounce(); - }} - > - {clearButtonLabel} - - - - {searchButtonLabel} - - - - )} - - - {statusText} - + )} + + + {statusText} + + ); } diff --git a/src/core/Form/SearchInput/__snapshots__/SearchInput.test.tsx.snap b/src/core/Form/SearchInput/__snapshots__/SearchInput.test.tsx.snap index f87d5a741d..4f28359844 100644 --- a/src/core/Form/SearchInput/__snapshots__/SearchInput.test.tsx.snap +++ b/src/core/Form/SearchInput/__snapshots__/SearchInput.test.tsx.snap @@ -116,7 +116,7 @@ exports[`snapshot should have matching default structure 1`] = ` box-sizing: border-box; } -.c3 { +.c2 { line-height: 1.15; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; @@ -140,8 +140,8 @@ exports[`snapshot should have matching default structure 1`] = ` white-space: normal; } -.c3::before, -.c3::after { +.c2::before, +.c2::after { box-sizing: border-box; } @@ -157,7 +157,7 @@ exports[`snapshot should have matching default structure 1`] = ` overflow: hidden; } -.c2.fi-label-text .fi-label-text_label-span { +.c3.fi-label-text .fi-label-text_label-span { -webkit-letter-spacing: 0; -moz-letter-spacing: 0; -ms-letter-spacing: 0; @@ -176,7 +176,7 @@ exports[`snapshot should have matching default structure 1`] = ` color: hsl(0,0%,16%); } -.c2.fi-label-text .fi-label-text_label-span .fi-label-text_optionalText { +.c3.fi-label-text .fi-label-text_label-span .fi-label-text_optionalText { font-family: 'Source Sans Pro','Helvetica Neue','Arial',sans-serif; font-size: 16px; line-height: 1.5; @@ -202,10 +202,15 @@ exports[`snapshot should have matching default structure 1`] = ` font-size: 18px; line-height: 1.5; font-weight: 400; - display: inline-block; width: 290px; } +.c1 .fi-search-input_wrapper { + width: 100%; + min-width: 105px; + display: inline-block; +} + .c1 .fi-search-input_functionality-container { position: relative; } @@ -460,82 +465,86 @@ exports[`snapshot should have matching default structure 1`] = `
- -
-
- -
- - + -
+ + Search + + + +
+ `;