diff --git a/contributing.md b/contributing.md index e53b6efaea3..085c8d11939 100644 --- a/contributing.md +++ b/contributing.md @@ -350,7 +350,7 @@ function foo() {} Стоит избегать общих слов, таких как "change". Вместо этого опишите в чем конкретно произошло изменение. Примеры: - - validationsRemoveExtraSpans - Избавиться от обертки span в ValidationContainer, ValidationWrapper и ValidationText + - validationsDivWrapper - Поменять обертку span на div c 'display: inline' чтобы соответсвовать w3c стандарту в ValidationContainer, ValidationWrapper и ValidationText - tokenInputRemoveWhitespaceFromDefaultDelimiters - В TokenInput изменили разделитель по умолчанию 2) Добавьте флаг в ReactUIFeatureFlags в файл ReactUIFeatureFlagsContext.tsx и в документацию FEATUREFLAGSCONTEXT.md diff --git a/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsContext.md b/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsContext.md index 66799207c0d..52a24742d3f 100644 --- a/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsContext.md +++ b/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsContext.md @@ -3,7 +3,7 @@ ## Доступные флаги export interface ValidationsFeatureFlags { - validationsRemoveExtraSpans?: boolean; + validationsDivWrapper?: boolean; fixedValidationTextColors?: boolean; darkTheme?: boolean; } @@ -14,16 +14,16 @@ import { ValidationsFeatureFlagsContext } from '@skbkontur/react-ui-validations' - {/* ... */}; + {/* ... */}; ## Использование -### validationsRemoveExtraSpans +### validationsDivWrapper В ValidationContainer, ValidationWrapper и ValidationText из корня удалён лишний span. В Validations 2.0 фича будет применена по умолчанию. - !!DemoWithCode!!FeatureFlagsExamplevalidationsRemoveExtraSpans + !!DemoWithCode!!FeatureFlagsExampleValidationsRemoveDivWrapper ### fixedValidationTextColors diff --git a/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveExtraSpans.demo.tsx b/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveDivWrapper.demo.tsx similarity index 90% rename from packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveExtraSpans.demo.tsx rename to packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveDivWrapper.demo.tsx index 15db394f1e7..919e290cd97 100644 --- a/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveExtraSpans.demo.tsx +++ b/packages/react-ui-validations/docs/Pages/Displaying/FeatureFlags/FeatureFlagsExampleValidationsRemoveDivWrapper.demo.tsx @@ -13,7 +13,7 @@ interface CheckboxState { checked: boolean; } -export default class FeatureFlagsExampleValidationsWrapperAndContainerRemoveExtraSpan extends React.Component { +export default class FeatureFlagsExampleValidationsWrapperAndContainerDivWrapper extends React.Component { public state: CheckboxState = { checked: false, }; @@ -31,9 +31,7 @@ export default class FeatureFlagsExampleValidationsWrapperAndContainerRemoveExtr render() { return ( - + { - if (flags.validationsRemoveExtraSpans) { - return this.props.children; + if (flags.validationsDivWrapper) { + return {this.props.children}; } return {this.props.children}; diff --git a/packages/react-ui-validations/src/ValidationText.tsx b/packages/react-ui-validations/src/ValidationText.tsx index be3f283d48d..efa622c6623 100644 --- a/packages/react-ui-validations/src/ValidationText.tsx +++ b/packages/react-ui-validations/src/ValidationText.tsx @@ -20,19 +20,13 @@ export const ValidationText = ({ pos, children, validation, 'data-tid': dataTid : '#d43517'; if (pos === 'right') { - const childrenAndValidationText = ( - <> + return ( + {children} {(validation && validation.message) || ''} - - ); - - return featureFlags.validationsRemoveExtraSpans ? ( - childrenAndValidationText - ) : ( - {childrenAndValidationText} + ); } @@ -53,12 +47,7 @@ export const ValidationText = ({ pos, children, validation, 'data-tid': dataTid ); - return featureFlags.validationsRemoveExtraSpans ? ( - <> - {children} - {validationText} - - ) : ( + return ( {children} {validationText} diff --git a/packages/react-ui-validations/src/ValidationTooltip.tsx b/packages/react-ui-validations/src/ValidationTooltip.tsx index 0d78675eee4..bf462de8bb9 100644 --- a/packages/react-ui-validations/src/ValidationTooltip.tsx +++ b/packages/react-ui-validations/src/ValidationTooltip.tsx @@ -1,10 +1,5 @@ import React from 'react'; -import { - ValidationsFeatureFlags, - ValidationsFeatureFlagsContext, - getFullValidationsFlagsContext, -} from './utils/featureFlagsContext'; import { ReactUiDetection, Tooltip } from './ReactUiDetection'; export type TooltipPosition = @@ -33,31 +28,22 @@ export class ValidationTooltip extends React.Component { public static __KONTUR_REACT_UI__ = 'ValidationTooltip'; public static displayName = 'ValidationTooltip'; - private featureFlags!: ValidationsFeatureFlags; public render() { const { children, pos, error, render, ...rest } = this.props; const onlyChild = React.Children.only(children); const child = onlyChild && onlyChild.props ? onlyChild.props.children : null; - return ( - - {(flags) => { - this.featureFlags = getFullValidationsFlagsContext(flags); - return !this.featureFlags.validationsRemoveExtraSpans && - (ReactUiDetection.isRadioGroup(child) || - ReactUiDetection.isTokenInput(child) || - ReactUiDetection.isSwitcher(child)) ? ( - - {child} - - ) : ( - - {children} - - ); - }} - + return ReactUiDetection.isRadioGroup(child) || + ReactUiDetection.isTokenInput(child) || + ReactUiDetection.isSwitcher(child) ? ( + + {child} + + ) : ( + + {children} + ); } } diff --git a/packages/react-ui-validations/src/ValidationWrapperInternal.tsx b/packages/react-ui-validations/src/ValidationWrapperInternal.tsx index 7e1ffd01003..1d1ff85d3ae 100644 --- a/packages/react-ui-validations/src/ValidationWrapperInternal.tsx +++ b/packages/react-ui-validations/src/ValidationWrapperInternal.tsx @@ -3,11 +3,6 @@ import warning from 'warning'; import { Nullable } from '../typings/Types'; -import { - ValidationsFeatureFlags, - ValidationsFeatureFlagsContext, - getFullValidationsFlagsContext, -} from './utils/featureFlagsContext'; import { getRootNode } from './utils/getRootNode'; import { isBrowser } from './utils/utils'; import { smoothScrollIntoView } from './smoothScrollIntoView'; @@ -70,8 +65,6 @@ export class ValidationWrapperInternal extends React.Component< public static contextType = ValidationContext; public context: ValidationContextType = this.context; - private featureFlags!: ValidationsFeatureFlags; - public componentDidMount() { warning( this.context, @@ -150,23 +143,9 @@ export class ValidationWrapperInternal extends React.Component< }); } - return ( - - {(flags) => { - this.featureFlags = getFullValidationsFlagsContext(flags); - return React.cloneElement( - this.props.errorMessage( - this.featureFlags.validationsRemoveExtraSpans ? clonedChild : {clonedChild}, - !!validation, - validation, - ), - { - 'data-tid': dataTid, - }, - ); - }} - - ); + return React.cloneElement(this.props.errorMessage(clonedChild, !!validation, validation), { + 'data-tid': dataTid, + }); } private customRef = (instance: Nullable) => { diff --git a/packages/react-ui-validations/src/utils/InlineDiv.tsx b/packages/react-ui-validations/src/utils/InlineDiv.tsx new file mode 100644 index 00000000000..b57ecf8dbf1 --- /dev/null +++ b/packages/react-ui-validations/src/utils/InlineDiv.tsx @@ -0,0 +1,8 @@ +import React from 'react'; +import type { FC, PropsWithChildren } from 'react'; + +export const InlineDiv: FC>> = ({ children, ...rest }) => ( +
+ {children} +
+); diff --git a/packages/react-ui-validations/src/utils/featureFlagsContext/ValidationsFeatureFlagsContext.tsx b/packages/react-ui-validations/src/utils/featureFlagsContext/ValidationsFeatureFlagsContext.tsx index 4d6c0151b61..79ae11a5145 100644 --- a/packages/react-ui-validations/src/utils/featureFlagsContext/ValidationsFeatureFlagsContext.tsx +++ b/packages/react-ui-validations/src/utils/featureFlagsContext/ValidationsFeatureFlagsContext.tsx @@ -5,7 +5,7 @@ export type FeatureFlags = 'validationsRemoveExtraSpans' | 'fixedValidationTextC export type ValidationsFeatureFlags = Partial>; export const validationsFeatureFlagsDefault: ValidationsFeatureFlags = { - validationsRemoveExtraSpans: false, + validationsDivWrapper: false, fixedValidationTextColors: false, }; diff --git a/packages/react-ui-validations/stories/Checkbox.stories.tsx b/packages/react-ui-validations/stories/Checkbox.stories.tsx index dbf49a66cab..42a34078075 100644 --- a/packages/react-ui-validations/stories/Checkbox.stories.tsx +++ b/packages/react-ui-validations/stories/Checkbox.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { Button } from '@skbkontur/react-ui/components/Button'; import { Checkbox } from '@skbkontur/react-ui/components/Checkbox/Checkbox'; -import { ValidationContainer, ValidationInfo, ValidationWrapper, ValidationsFeatureFlagsContext } from '../src'; +import { ValidationContainer, ValidationInfo, ValidationWrapper } from '../src'; import { Nullable } from '../typings/Types'; export default { @@ -22,19 +22,17 @@ export const Required = () => { }; return ( - -
- - - - Checkbox - - -
- -
-
-
-
+
+ + + + Checkbox + + +
+ +
+
+
); }; diff --git a/packages/react-ui-validations/stories/Input.stories.tsx b/packages/react-ui-validations/stories/Input.stories.tsx index 19a04debfae..583b801eaa0 100644 --- a/packages/react-ui-validations/stories/Input.stories.tsx +++ b/packages/react-ui-validations/stories/Input.stories.tsx @@ -5,15 +5,7 @@ import { Input } from '@skbkontur/react-ui/components/Input'; import { Select } from '@skbkontur/react-ui/components/Select'; import { Gapped } from '@skbkontur/react-ui'; -import { - text, - tooltip, - ValidationBehaviour, - ValidationContainer, - ValidationInfo, - ValidationWrapper, - ValidationsFeatureFlagsContext, -} from '../src'; +import { text, tooltip, ValidationBehaviour, ValidationContainer, ValidationInfo, ValidationWrapper } from '../src'; import { Nullable } from '../typings/Types'; export default { @@ -178,23 +170,21 @@ export const Example_6 = () => { }; return ( - - -
-
- - - -
-
- - - -
+ +
+
+ + +
- - - +
+ + + +
+
+ +
); }; @@ -381,21 +371,19 @@ export const Example_11 = () => { refContainer.current?.submit(); }} > - - - - - -
-
- - - -
-
+ + + + +
+
+ + + +



diff --git a/packages/react-ui-validations/stories/ValidationContainer.stories.tsx b/packages/react-ui-validations/stories/ValidationContainer.stories.tsx index d8896d0f9e5..d1e832d7a57 100644 --- a/packages/react-ui-validations/stories/ValidationContainer.stories.tsx +++ b/packages/react-ui-validations/stories/ValidationContainer.stories.tsx @@ -2,7 +2,14 @@ import React from 'react'; import { Meta } from '@storybook/react'; import { Button, Gapped, Input } from '@skbkontur/react-ui'; -import { text, ValidationContainer, ValidationInfo, ValidationsFeatureFlagsContext, ValidationWrapper } from '../src'; +import { + text, + tooltip, + ValidationContainer, + ValidationInfo, + ValidationsFeatureFlagsContext, + ValidationWrapper, +} from '../src'; export default { title: 'ValidationContainer', @@ -70,32 +77,87 @@ export const WithWrapperError = () => ( ); -export const WithWrapperErrorWithoutSpan = () => ( - - +export const WithWrapperErrorWithDivWrapper = () => ( + + -
- - - - -
+ +
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + +
TEXT
+
+
+
+ + + TOOLTIP + +
+
+
+); - - -
- +export const DarkTheme = () => { + return ( + + + - + -
-
-
-
-); + + + + + + + + + + + + + + + + + + ); +}; diff --git a/packages/react-ui-validations/tests/ValidationContainer.test.tsx b/packages/react-ui-validations/tests/ValidationContainer.test.tsx index b90947bbbba..d611930ade0 100644 --- a/packages/react-ui-validations/tests/ValidationContainer.test.tsx +++ b/packages/react-ui-validations/tests/ValidationContainer.test.tsx @@ -33,9 +33,9 @@ describe('ValidationContainer', () => { expect(screen.getByTestId('passed-container')).toBeInTheDocument(); }); - it('renders passed data-tid on container when validationsRemoveExtraSpans enabled', () => { + it('renders passed data-tid on container when validationsDivWrapper enabled', () => { render( - +
@@ -45,9 +45,9 @@ describe('ValidationContainer', () => { expect(screen.getByTestId('passed-container')).toBeInTheDocument(); }); - it('not renders passed data-tid on container when validationsRemoveExtraSpans enabled', () => { + it('renders passed data-tid on container when validationsDivWrapper enabled', () => { render( - +
@@ -55,7 +55,7 @@ describe('ValidationContainer', () => { , ); - expect(screen.queryByTestId('passed-container')).toBeNull(); + expect(screen.queryByTestId('passed-container')).toBeInTheDocument(); }); it('renders passed children', () => {