Skip to content

Commit

Permalink
feat(select): new label behavior (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-gevak authored Aug 7, 2023
1 parent 6fd833f commit f98bfab
Show file tree
Hide file tree
Showing 26 changed files with 203 additions and 171 deletions.
6 changes: 6 additions & 0 deletions .changeset/five-years-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components-input-autocomplete': minor
'@alfalab/core-components-select': minor
---

Поведение плейсхолдера и лейбла изменено на стандартное. Теперь, в дефолтном состоянии, в инпутах с внутренним положением лейбла отображается лейбл, а не плейсхолдер.
16 changes: 8 additions & 8 deletions packages/input-autocomplete/src/Component.modal.mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ export const InputAutocompleteModalMobile = React.forwardRef<
<React.Fragment>
<Button
block={true}
view='primary'
view='secondary'
size='s'
onClick={handleApply}
{...continueButtonProps}
onClick={handleCancel}
{...cancelButtonProps}
>
Продолжить
Отмена
</Button>
<Button
block={true}
view='secondary'
view='primary'
size='s'
onClick={handleCancel}
{...cancelButtonProps}
onClick={handleApply}
{...continueButtonProps}
>
Отмена
Продолжить
</Button>
</React.Fragment>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ export type AutocompleteMobileFieldProps = FormControlProps &
export const AutocompleteMobileField = ({
size = 'm',
open,
error,
hint,
disabled,
label,
labelView = 'inner',
placeholder,
value,
innerProps,
dataTestId,
fieldClassName,
labelView = 'inner',
placeholder,
Arrow,
valueRenderer,
toggleMenu,
Expand All @@ -39,7 +36,7 @@ export const AutocompleteMobileField = ({
const [focusVisible] = useFocus(wrapperRef, 'keyboard');

const filled = Boolean(value);
const showLabel = !!label && (filled || !placeholder || labelView === 'outer');
const showPlaceholder = placeholder && !filled && labelView === 'outer';

return (
<div
Expand All @@ -58,19 +55,14 @@ export const AutocompleteMobileField = ({
focused={focused}
disabled={disabled}
filled={filled}
label={showLabel && label}
labelView={labelView}
error={error}
hint={hint}
rightAddons={Arrow}
data-test-id={dataTestId}
{...restProps}
{...innerProps}
>
<div className={styles.contentWrapper}>
{placeholder && !filled && (
<span className={styles.placeholder}>{placeholder}</span>
)}
{showPlaceholder && <span className={styles.placeholder}>{placeholder}</span>}
{filled && <div className={styles.value}>{value}</div>}
</div>
</FormControl>
Expand Down
27 changes: 24 additions & 3 deletions packages/input-autocomplete/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,36 @@ describe('InputAutocompleteModalMobile | interactions', () => {
try {
await page.click('[role="combobox"]');

await matchHtml({ context, page, expect });
await matchHtml({
context,
page,
expect,
screenshotOpts: {
fullPage: true,
},
});

await page.fill('input', 'Nep');

await matchHtml({ context, page, expect });
await matchHtml({
context,
page,
expect,
screenshotOpts: {
fullPage: true,
},
});

await page.click('button[data-test-id="continue"]');

await matchHtml({ context, page, expect });
await matchHtml({
context,
page,
expect,
screenshotOpts: {
fullPage: true,
},
});
} catch (error) {
// eslint-disable-next-line no-console
console.error((error as Error).message);
Expand Down
164 changes: 58 additions & 106 deletions packages/input-autocomplete/src/docs/description.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,24 @@ render(() => {
block={true}
options={getFilteredOptions()}
label='Инпут с автокомплитом'
placeholder='Начните вводить название'
onChange={handleChange}
onInput={handleInput}
value={value}
Arrow={shownChevron ? Arrow : undefined}
multiple={multiple}
allowUnselect={true}
Option={BaseOption}
{...(shownChevron
? {
showEmptyOptionsList: true,
optionsListProps: {
emptyPlaceholder: (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography.Text view='component'>
Ничего не нашлось
</Typography.Text>
</div>
),
},
}
: null)}
showEmptyOptionsList={true}
optionsListProps={{
emptyPlaceholder: (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography.Text view='component'>
Ничего не нашлось
</Typography.Text>
</div>
),
}}
/>
</div>
<Gap size='xl' />
Expand All @@ -122,6 +119,7 @@ render(() => {
//MOBILE
render(() => {
const [shownChevron, setShownChevron] = React.useState(false);
const [showInModal, setShowInModal] = React.useState(false);
const [multiple, setMultiple] = React.useState(false);
const [value, setValue] = React.useState('');
const [filter, setFilter] = React.useState('');
Expand Down Expand Up @@ -186,28 +184,17 @@ render(() => {
);
});

const emptyPlaceholder = (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography.Text view='component'>Ничего не нашлось</Typography.Text>
</div>
);

const Component = showInModal ? InputAutocompleteModalMobile : InputAutocompleteMobile;

return (
<div style={{ width: document.body.clientWidth < 450 ? '100%' : 320 }}>
<InputAutocompleteMobile
size='m'
block={true}
value={value}
Arrow={shownChevron ? Arrow : undefined}
filter={filter}
options={filteredOptions}
label='Инпут с автокомплитом'
placeholder='Начните вводить название'
multiple={multiple}
selected={selected}
closeOnSelect={!multiple}
allowUnselect={true}
onChange={handleChange}
onFilter={handleFilter}
onClearFilter={() => setFilter('')}
onCancel={() => setFilter(value)}
/>
<Gap size='m' />
<InputAutocompleteModalMobile
<Component
size='m'
block={true}
value={value}
Expand All @@ -216,6 +203,7 @@ render(() => {
options={filteredOptions}
label='Инпут с автокомплитом'
placeholder='Начните вводить название'
Option={BaseOption}
multiple={multiple}
selected={selected}
closeOnSelect={!multiple}
Expand All @@ -224,6 +212,8 @@ render(() => {
onFilter={handleFilter}
onClearFilter={() => setFilter('')}
onCancel={() => setFilter(value)}
showEmptyOptionsList={true}
optionsListProps={{ emptyPlaceholder }}
/>
<Gap size='xl' />

Expand All @@ -241,57 +231,11 @@ render(() => {
setValue('');
}}
/>
</div>
);
});
```

## Пустой список

Когда по запросу пользователя не находится соответствия в списке, рекомендуется использовать такой шаблон.

```jsx live
render(() => {
return (
<div style={{ width: document.body.clientWidth < 450 ? '100%' : 320 }}>
<InputAutocompleteDesktop
size='m'
block={true}
options={[]}
label='Пустой список'
showEmptyOptionsList={true}
optionsListProps={{
emptyPlaceholder: (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography.Text view='component'>Ничего не нашлось</Typography.Text>
</div>
),
}}
Option={BaseOption}
/>
</div>
);
});
//MOBILE
render(() => {
return (
<div style={{ width: document.body.clientWidth < 450 ? '100%' : 320 }}>
<InputAutocompleteMobile
size='m'
block={true}
options={[]}
onChange={() => {}}
label='Инпут с автокомплитом'
placeholder='Начните вводить название'
showEmptyOptionsList={true}
optionsListProps={{
emptyPlaceholder: (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Typography.Text view='component'>Ничего не нашлось</Typography.Text>
</div>
),
}}
Option={BaseOption}
<Gap size='m' />
<Switch
checked={showInModal}
label='Открывать в модалке'
onChange={() => setShowInModal((prevState) => !prevState)}
/>
</div>
);
Expand Down Expand Up @@ -355,9 +299,11 @@ render(() => {
const CardOption = (props) => (
<BaseOption {...props}>
<div style={{ padding: 'var(--gap-s)' }}>
{props.option.key}
<br />
<sub>{props.option.content}</sub>
<Typography.Text view='component'>{props.option.content}</Typography.Text>
<Gap size='2xs' />
<Typography.Text view='primary-small' color='secondary'>
{props.option.key}
</Typography.Text>
</div>
</BaseOption>
);
Expand All @@ -382,21 +328,25 @@ render(() => {
const filteredOptions = cards.filter((option) => matchOption(option, value));

return (
<InputAutocompleteDesktop
size='m'
options={filteredOptions}
selected={[]}
label='Маскированный ввод счёта'
onInput={handleInput}
onChange={handleChange}
value={value}
Option={CardOption}
Input={MaskedInput}
inputProps={{
ref: inputRef,
mask,
}}
/>
<div style={{ width: 320 }}>
<InputAutocompleteDesktop
size='m'
options={filteredOptions}
selected={[]}
label='Счёт'
placeholder='Маскированный ввод счёта'
onInput={handleInput}
onChange={handleChange}
value={value}
Option={CardOption}
Input={MaskedInput}
block={true}
inputProps={{
ref: inputRef,
mask,
}}
/>
</div>
);
});
//MOBILE
Expand Down Expand Up @@ -455,9 +405,11 @@ render(() => {
const CardOption = (props) => (
<BaseOption {...props}>
<div style={{ padding: 'var(--gap-s) var(--gap-m)' }}>
{props.option.key}
<br />
<sub>{props.option.content}</sub>
<Typography.Text view='component'>{props.option.content}</Typography.Text>
<Gap size='2xs' />
<Typography.Text view='primary-small' color='secondary'>
{props.option.key}
</Typography.Text>
</div>
</BaseOption>
);
Expand Down
Loading

0 comments on commit f98bfab

Please sign in to comment.