Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDS-702] TextField [v5] #638

Merged
merged 10 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 4 additions & 4 deletions src/components/DatePicker/DatePickInput/DatePickInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ const DatePickInput = React.forwardRef<HTMLInputElement, DatePickInputProps>(
onKeyDown={handleClear}
dataTestId={dataTestId}
onChange={ON_CHANGE_MOCK}
placeholder="Date (start) - Date (end)"
label="Date (start) - Date (end)"
value={selectedDay.from ? `${formattedFrom} - ${formattedTo}` : ''}
suffix={<Icon name={'calendarEmpty'} color={'#676767'} />}
suffix={'calendarEmpty'}
/>
);
}
Expand All @@ -120,9 +120,9 @@ const DatePickInput = React.forwardRef<HTMLInputElement, DatePickInputProps>(
onKeyDown={handleClear}
dataTestId={dataTestId}
onChange={ON_CHANGE_MOCK}
placeholder="Select date"
label="Select date"
value={selectedDay.to ? formattedFrom : ''}
suffix={<Icon name={'calendarEmpty'} color={'#676767'} />}
suffix={'calendarEmpty'}
/>
);
};
Expand Down
6 changes: 1 addition & 5 deletions src/components/Filter/Filter.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from './utils';
import { Theme } from '../../theme';
import { getFocus, getHover, getPressed } from '../../theme/states';
import { textInputConfig } from 'components/TextInputBase/config';

export const wrapperStyle = () => () => {
return {
Expand Down Expand Up @@ -241,14 +240,11 @@ export const valueSpanStyle = () => css`
`;

export const menuStyle = () => (theme: Theme) => {
const borderConfig = textInputConfig.types[theme.colorScheme].outlined.border;

return css`
position: absolute;
left: 0;
height: auto;
border: ${rem(borderConfig.width)} solid
${theme.utils.getColor(borderConfig.color.default.name, borderConfig.color.default.shade)};
border: ${rem(1)} solid ${theme.utils.getColor('lightGrey', 200)};
border-radius: ${theme.globals.spacing.get('3')};
background-color: ${theme.globals.colors.white};
box-shadow: ${theme.globals.elevation['02']};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { css } from '@emotion/react';
import { Theme } from 'theme';
import { rem } from 'theme/utils';

import { textInputConfig } from 'components/TextInputBase/config';

export const textFieldWrapper = () =>
css`
& > div > div {
Expand All @@ -13,17 +11,12 @@ export const textFieldWrapper = () =>
`;

export const optionsWrapper = () => (theme: Theme) => {
const borderConfig = textInputConfig.types[theme.colorScheme].outlined.border;

return css`
& > div {
box-shadow: 0 0 0 ${rem(borderConfig.width)}
${theme.utils.getColor(borderConfig.color.default.name, borderConfig.color.default.shade)};
box-shadow: 0 0 0 ${rem(1)} ${theme.utils.getColor('lightGrey', 200)};
border: none;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
`;
};


Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const MultiFilter: React.FC<Props> = ({
onClearAllOptions={onClearAllOptions}
isInteractive={false}
value={searchValue}
placeholder="Search"
label="Search"
isResponsive
isLoading={isLoading}
ref={filterInputRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SearchInput = ({ onChange, value, dataTestId, isLoading }: SearchInputProp
onChange={onChange}
data-testid={generateTestDataId('filter-input', dataTestId)}
status={{ type: 'normal' }}
placeholder="Search"
label="Search"
value={value}
suffix={suffix}
/>
Expand Down
8 changes: 3 additions & 5 deletions src/components/MultiTextFieldBase/MultiTextFieldBase.style.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { css, SerializedStyles } from '@emotion/react';
import { rem } from 'polished';
import { Theme } from 'theme';
import { getTextFieldSize } from 'utils/size-utils';

import { LABEL_TRANSFORM_LEFT_SPACING } from 'components/Label/Label.style';
import { MULTI_MIN_WIDTH } from 'components/TextInputBase/config';

export const chipContent =
({ maxWidth }: { maxWidth?: number }) =>
Expand Down Expand Up @@ -108,10 +108,8 @@ export const textInputBaseOverrides =
padding: isLoading
? `${rem(paddingTop)} ${rem(80)} ${rem(paddingBottom)} ${theme.globals.spacing.get('6')}`
: `${rem(paddingTop)} ${rem(40)} ${rem(paddingBottom)} ${theme.globals.spacing.get('6')}`,
...(isResponsive
? { width: 'max-content', minWidth: getTextFieldSize(true, 'md').minWidth }
: {}),
...(isTextfield ? { width: getTextFieldSize(true, 'md', true).width } : {}),
...(isResponsive ? { width: 'max-content', minWidth: rem(MULTI_MIN_WIDTH) } : {}),
...(isTextfield ? { minWidth: rem(MULTI_MIN_WIDTH), width: '100%' } : {}),
},
};
};
Expand Down
1 change: 1 addition & 0 deletions src/components/MultiTextFieldBase/MultiTextFieldBase.tsx
panvourtsis marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const MultiTextFieldBase = React.forwardRef<HTMLInputElement, Props & InputProps
required={isRequired}
id={id}
disabled={isDisabled || isLocked}
data-testid={rest.dataTestId ? `input_${rest.dataTestId}` : 'input'}
{...omit(rest, 'dataTestId')}
value={value}
ref={ref}
Expand Down
8 changes: 6 additions & 2 deletions src/components/MultiTextFieldBase/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ const useMultiTextFieldBaseUtils = ({
const hasLabel = Boolean(label);

const inputPlaceholder = useMemo(() => {
if (!label && placeholder && !hasValue) {
if (!hasValue && placeholder) {
return isRequired ? `${placeholder} *` : placeholder;
}

return label;
if (!hasValue) {
return label;
}

return undefined;
}, [hasValue, label, placeholder, isRequired]);

const iconName = useMemo(() => {
Expand Down
15 changes: 5 additions & 10 deletions src/components/SearchField/SearchField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import useTheme from 'hooks/useTheme';
import React from 'react';
import isEqual from 'react-fast-compare';
import { getTextFieldHeight } from 'utils/size-utils';

import { rem } from '../../theme/utils';
import { TestProps } from '../../utils/types';
Expand All @@ -10,6 +9,7 @@ import { IconWrapper } from '../TextField/components/commons';
import { TextFieldProps } from 'components/TextField/TextField';
import TextInputBase from 'components/TextInputBase';
import { inputStyle } from 'components/TextInputBase/TextInputBase.style';
import { getTextInputBaseTokens } from 'components/TextInputBase/TextInputBase.tokens';

export type SearchFieldProps = {
/** A callback that's called when the user clicks the 'clear' icon */
Expand All @@ -22,24 +22,19 @@ const SearchField = React.forwardRef<HTMLInputElement, SearchFieldProps>((props,

const theme = useTheme();

const tokens = getTextInputBaseTokens(theme);

const isClearVisible = (value as string).length > 0;
const sx = {
wrapper: {
borderRadius: rem(100),
// @TODO this is a unique case for the SearchField where we dont need to use the sm height of the TextField, will change in v5
height: getTextFieldHeight('md'),
height: tokens('container'),
},
};

return (
<React.Fragment>
<TextInputBase
dataTestId={dataTestId}
isDisabled={isDisabled}
prefix={'search'}
suffix={'close'}
sx={sx}
>
<TextInputBase dataTestId={dataTestId} isDisabled={isDisabled} sx={sx}>
<IconWrapper iconPosition={'left'}>
<Icon name={'search'} size={20} color={theme.utils.getColor('lightGrey', 650)} />
</IconWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports[`Storyshots Design System/SearchField Search Field 1`] = `
user-select: none;
opacity: 1;
cursor: text;
height: 2.875rem;
height: 3.25rem;
min-width: 8.75rem;
background-color: #ffffff;
}
Expand Down Expand Up @@ -155,10 +155,6 @@ exports[`Storyshots Design System/SearchField Search Field 1`] = `
font-size: 0.9375rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9::-webkit-input-placeholder {
font-family: Roboto;
font-weight: 400;
Expand Down Expand Up @@ -191,6 +187,26 @@ exports[`Storyshots Design System/SearchField Search Field 1`] = `
letter-spacing: 0.015625rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9:focus::-webkit-input-placeholder {
color: #54587f;
}

.emotion-9:focus::-moz-placeholder {
color: #54587f;
}

.emotion-9:focus:-ms-input-placeholder {
color: #54587f;
}

.emotion-9:focus::placeholder {
color: #54587f;
}

.emotion-9:not(:focus):placeholder-shown+label {
font-weight: normal;
}
Expand Down Expand Up @@ -314,7 +330,7 @@ exports[`Storyshots Design System/SearchField Search Field disabled 1`] = `
user-select: none;
opacity: 50%;
cursor: not-allowed;
height: 2.875rem;
height: 3.25rem;
min-width: 8.75rem;
background-color: #ffffff;
}
Expand Down Expand Up @@ -414,10 +430,6 @@ exports[`Storyshots Design System/SearchField Search Field disabled 1`] = `
font-size: 0.9375rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9::-webkit-input-placeholder {
font-family: Roboto;
font-weight: 400;
Expand Down Expand Up @@ -450,6 +462,26 @@ exports[`Storyshots Design System/SearchField Search Field disabled 1`] = `
letter-spacing: 0.015625rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9:focus::-webkit-input-placeholder {
color: #54587f;
}

.emotion-9:focus::-moz-placeholder {
color: #54587f;
}

.emotion-9:focus:-ms-input-placeholder {
color: #54587f;
}

.emotion-9:focus::placeholder {
color: #54587f;
}

.emotion-9:not(:focus):placeholder-shown+label {
font-weight: normal;
}
Expand Down Expand Up @@ -574,7 +606,7 @@ exports[`Storyshots Design System/SearchField Search Field with placeholder 1`]
user-select: none;
opacity: 1;
cursor: text;
height: 2.875rem;
height: 3.25rem;
min-width: 8.75rem;
background-color: #ffffff;
}
Expand Down Expand Up @@ -679,10 +711,6 @@ exports[`Storyshots Design System/SearchField Search Field with placeholder 1`]
font-size: 0.9375rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9::-webkit-input-placeholder {
font-family: Roboto;
font-weight: 400;
Expand Down Expand Up @@ -715,6 +743,26 @@ exports[`Storyshots Design System/SearchField Search Field with placeholder 1`]
letter-spacing: 0.015625rem;
}

.emotion-9:focus {
outline: none;
}

.emotion-9:focus::-webkit-input-placeholder {
color: #54587f;
}

.emotion-9:focus::-moz-placeholder {
color: #54587f;
}

.emotion-9:focus:-ms-input-placeholder {
color: #54587f;
}

.emotion-9:focus::placeholder {
color: #54587f;
}

.emotion-9:not(:focus):placeholder-shown+label {
font-weight: normal;
}
Expand Down
41 changes: 2 additions & 39 deletions src/components/Select/Select.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,42 +131,13 @@ Simple select component with clearable data and searchable input
</Story>
</Preview>

### Select with prefix/suffix
### Select with suffix

Select with prefix and suffix options
Select with suffix options

<Preview>
<Story name="Select with icon and size">
<Stack>
<Select
label={'Flavour'}
options={options}
defaultValue={defaultValue}
handleSelectedOption={handleSelectedOption}
size={'md'}
prefix={
<img
style={{ background: 'red' }}
src="https://brandmark.io/logo-rank/random/pepsi.png"
width="16"
height="16"
/>
}
/>
<Select
label={'Flavour'}
options={options}
defaultValue={defaultValue}
handleSelectedOption={handleSelectedOption}
suffix={
<img
style={{ background: 'red' }}
src="https://brandmark.io/logo-rank/random/pepsi.png"
width="16"
height="16"
/>
}
/>
<Select
label={'Flavour'}
options={options}
Expand All @@ -180,14 +151,6 @@ Select with prefix and suffix options
height="16"
/>
}
prefix={
<img
style={{ background: 'red' }}
src="https://brandmark.io/logo-rank/random/pepsi.png"
width="16"
height="16"
/>
}
/>
</Stack>
</Story>
Expand Down
Loading