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

fix: "RequiredProps" unions in TextField & TextArea #1593

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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.
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.
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.
2,715 changes: 748 additions & 1,967 deletions packages/plasma-b2c/api/plasma-b2c.api.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ describe('plasma-b2c: TextArea', () => {

const cases = [
{ required: true, labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'outer' },
{ required: true, labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'inner' },
];

sizes.forEach((size) => {
Expand Down Expand Up @@ -334,9 +334,9 @@ describe('plasma-b2c: TextArea', () => {

const cases = [
{ required: true, labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'outer' },
{ required: true, labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'inner' },
];

sizes.forEach((size) => {
Expand Down
49 changes: 6 additions & 43 deletions packages/plasma-b2c/src/components/TextArea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,11 @@ import type { TextAreaProps as TextAreaPropsBase } from '@salutejs/plasma-hope';
import type { PopoverPlacement, PopoverPlacementBasic } from '@salutejs/plasma-new-hope';
import type { ReactNode } from 'react';

export { TextArea } from './TextArea';
import { TextArea } from './TextArea';

type RequiredProps =
| {
/**
* Флаг обязательности поля
*/
required: true;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: false;
}
| {
/**
* Флаг необязательности поля
*/
optional?: true;
/**
* Флаг обязательности поля
*/
required?: false;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: never;
};
export { TextArea };

type newHopeTextAreaProps = React.ComponentProps<typeof TextArea>;

type HintProps =
| {
Expand Down Expand Up @@ -122,16 +94,7 @@ type ClearProps =
hasDivider?: never;
};

export type TextAreaProps = TextAreaPropsBase & {
/**
* @deprecated не используется в компоненте
*/
resize?: 'none' | 'both' | 'horizontal' | 'vertical';
/**
* Метка-подпись к элементу справа.
*/
titleCaption?: ReactNode;
} & RequiredProps &
export type TextAreaProps = TextAreaPropsBase &
Pick<newHopeTextAreaProps, 'title' | 'titleCaption' | 'required' | 'requiredPlacement' | 'optional'> &
ClearProps &
RequiredProps &
HintProps;
36 changes: 3 additions & 33 deletions packages/plasma-b2c/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,6 @@ export const TextFieldComponent = component(mergedConfig);

type newHopeTextFieldProps = ComponentProps<typeof TextFieldComponent>;

export type RequiredProps =
| {
/**
* Флаг обязательности поля
*/
required: true;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: false;
}
| {
/**
* Флаг обязательности поля
*/
required?: false;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: never;
/**
* Флаг необязательности поля
*/
optional?: boolean;
};

type ClearProps =
| {
/**
Expand Down Expand Up @@ -133,8 +101,10 @@ export type CustomTextFieldProps = (TextFieldProps &
| 'titleCaption'
| 'labelPlacement'
| 'keepPlaceholder'
| 'required'
| 'requiredPlacement'
| 'optional'
>) &
RequiredProps &
ClearProps &
HintProps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ describe('plasma-core: TextArea', () => {

const cases = [
{ required: true, labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'outer' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'outer' },
{ required: true, labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'right', labelPlacement: 'inner' },
{ required: true, requiredPlacement: 'left', labelPlacement: 'inner' },
];

sizes.forEach((size) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,21 @@ export type TextAreaDimensionsProps = OneOf<
ClearProps
>;

type RequiredProps =
| {
/**
* Флаг обязательности поля
*/
required: true;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: false;
}
| {
/**
* Флаг необязательности поля
*/
optional?: true;
/**
* Флаг обязательности поля
*/
required?: false;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: never;
};
type RequiredProps = {
/**
* Флаг обязательности поля
*/
required?: boolean;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: boolean;
};

type HintProps =
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,21 @@ type TextFieldChipProps =
chipType?: 'default' | 'text';
};

export type RequiredProps =
| {
/**
* Флаг обязательности поля
*/
required: true;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: false;
}
| {
/**
* Флаг обязательности поля
*/
required?: false;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: never;
/**
* Флаг необязательности поля
*/
optional?: boolean;
};
export type RequiredProps = {
/**
* Флаг обязательности поля
*/
required?: boolean;
/**
* Задает выравнивание индикатора обязательности поля
* @default right
*/
requiredPlacement?: 'left' | 'right';
/**
* Флаг необязательности поля
*/
optional?: boolean;
};

type ClearProps =
| {
Expand Down
Loading