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

PLASMA-3868: Add error and success status to Datepicker and Range #1727

Merged
merged 5 commits into from
Feb 4, 2025
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.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentProps, useEffect, useRef, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';

import { IconButton } from '../IconButton/IconButton';

Expand Down Expand Up @@ -65,6 +65,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/plasma-b2c/src/components/Range/Range.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent, ComponentProps, Dispatch, SetStateAction, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { IconSearch, IconSber, IconArrowRight } from '@salutejs/plasma-icons';

import { IconButton } from '../IconButton/IconButton';
Expand Down Expand Up @@ -46,6 +46,7 @@ const meta: Meta<typeof Range> = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentProps, useEffect, useRef, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';

import { IconButton } from '../IconButton';

Expand Down Expand Up @@ -65,6 +65,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/plasma-giga/src/components/Range/Range.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent, ComponentProps, Dispatch, SetStateAction, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { IconSearch, IconSber, IconArrowRight } from '@salutejs/plasma-icons';

import { IconButton } from '../IconButton';
Expand Down Expand Up @@ -46,6 +46,7 @@ const meta: Meta<typeof Range> = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const tokens = {

/** Токены вспомогательного текста */
leftHelperColor: '--plasma-date-picker__left-helper-color',
leftHelperColorError: '--plasma-date-picker__left-helper-color-error',
leftHelperColorSuccess: '--plasma-date-picker__left-helper-color-success',
leftHelperColorReadOnly: '--plasma-date-picker__left-helper-color-readonly',
leftHelperOffset: '--plasma-date-picker__left-helper-offset',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from '@linaria/core';

import { component, mergeConfig } from '../../../engines';
import { rangeConfig, rangeTokens } from '../../Range';
import { tokens } from '../DatePicker.tokens';
import { classes, tokens } from '../DatePicker.tokens';
import { popoverConfig } from '../../Popover';

const mergedRangeConfig = mergeConfig(rangeConfig);
Expand Down Expand Up @@ -120,4 +120,14 @@ export const base = css`
display: inline-block;
`;

export const LeftHelper = styled.div``;
export const LeftHelper = styled.div`
color: var(${tokens.leftHelperColor});

&.${classes.datePickerError} {
color: var(${tokens.leftHelperColorError});
}

&.${classes.datePickerSuccess} {
color: var(${tokens.leftHelperColorSuccess});
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export const datePickerRangeRoot = (

const [secondTextFieldClicked, setSecondTextFieldClicked] = useState(false);

const rangeErrorClass = firstValueError || secondValueError ? classes.datePickerError : undefined;
const rangeSuccessClass = firstValueSuccess || secondValueSuccess ? classes.datePickerSuccess : undefined;

const setFirstInputValue = (value: React.SetStateAction<string>) => {
setInputFirstValue(value);

Expand Down Expand Up @@ -474,7 +477,9 @@ export const datePickerRangeRoot = (
onChangeStartOfRange={handleChangeStartOfRange}
onChangeValue={handleChangeCalendarValue}
/>
{leftHelper && <LeftHelper>{leftHelper}</LeftHelper>}
{leftHelper && (
<LeftHelper className={cx(rangeErrorClass, rangeSuccessClass)}>{leftHelper}</LeftHelper>
)}
<InputHidden
name={name}
type="hidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ export const base = css`
}
`;

export const LeftHelper = styled.div``;
export const LeftHelper = styled.div`
color: var(${tokens.leftHelperColor});

&.${classes.datePickerError} {
color: var(${tokens.leftHelperColorError});
}

&.${classes.datePickerSuccess} {
color: var(${tokens.leftHelperColorSuccess});
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ export const datePickerRoot = (
/>
</Root>
</StyledPopover>
{leftHelper && <LeftHelper>{leftHelper}</LeftHelper>}
{leftHelper && (
<LeftHelper className={cx(datePickerErrorClass, datePickerSuccessClass)}>
{leftHelper}
</LeftHelper>
)}
<InputHidden
type="hidden"
datatype="datepicker-single"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const tokens = {
leftHelperColor: '--plasma-range__left-helper-color',
leftHelperColorReadOnly: '--plasma-range__left-helper-color-readonly',
leftHelperOffset: '--plasma-range__left-helper-offset',
leftHelperColorError: '--plasma-range__left-helper-color-error',
leftHelperColorSuccess: '--plasma-range__left-helper-color-success',

leftHelperFontFamily: '--plasma-range__left-helper-font-family',
leftHelperFontStyle: '--plasma-range__left-helper-font-style',
Expand Down
17 changes: 16 additions & 1 deletion packages/plasma-new-hope/src/components/Range/Range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ export const rangeRoot = (Root: RootProps<HTMLDivElement, RangeProps>) =>
const requiredPlacementClass = requiredPlacement === 'right' ? classes.requiredAlignRight : undefined;

const rangeErrorClass = firstValueError && secondValueError ? classes.rangeError : undefined;

const firstValueErrorClass = !rangeErrorClass && firstValueError ? classes.rangeValueError : undefined;
const secondValueErrorClass = !rangeErrorClass && secondValueError ? classes.rangeValueError : undefined;

const rangeSuccessClass = firstValueSuccess && secondValueSuccess ? classes.rangeSuccess : undefined;
const firstValueSuccessClass =
!rangeSuccessClass && firstValueSuccess ? classes.rangeValueSuccess : undefined;
Expand Down Expand Up @@ -178,7 +180,20 @@ export const rangeRoot = (Root: RootProps<HTMLDivElement, RangeProps>) =>
/>
{contentRight && <StyledContentRight>{contentRight}</StyledContentRight>}
</ContentWrapper>
{leftHelper && <LeftHelper>{leftHelper}</LeftHelper>}
{leftHelper && (
<LeftHelper
className={cx(
rangeErrorClass,
firstValueErrorClass,
secondValueErrorClass,
rangeSuccessClass,
firstValueSuccessClass,
secondValueSuccessClass,
)}
>
{leftHelper}
</LeftHelper>
)}
</Root>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ export const base = css`

${LeftHelper} {
color: var(${tokens.leftHelperColor});

&.${classes.rangeError}, &.${classes.rangeValueError} {
color: var(${tokens.leftHelperColorError});
}

&.${classes.rangeSuccess}, &.${classes.rangeValueSuccess} {
color: var(${tokens.leftHelperColorSuccess});
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const meta: Meta<typeof Range> = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const meta: Meta<typeof Range> = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentProps, useEffect, useRef, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';

import { IconButton } from '../IconButton/IconButton';

Expand Down Expand Up @@ -65,6 +65,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/plasma-web/src/components/Range/Range.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.indicatorColor}: var(--surface-negative);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent, ComponentProps, Dispatch, SetStateAction, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { IconSearch, IconSber, IconArrowRight } from '@salutejs/plasma-icons';

import { IconButton } from '../IconButton/IconButton';
Expand Down Expand Up @@ -46,6 +46,7 @@ const meta: Meta<typeof Range> = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.textFieldColor}: var(--text-primary);
${tokens.textFieldPlaceholderColor}: var(--text-secondary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentProps, useRef, useState } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { disableProps, IconPlaceholder, InSpacingDecorator } from '@salutejs/plasma-sb-utils';
import { IconPlasma, IconCalendarOutline } from '@salutejs/plasma-icons';

import { IconButton } from '../IconButton/IconButton';
Expand Down Expand Up @@ -66,6 +66,7 @@ const meta: Meta = {
},
if: { arg: 'required', truthy: true },
},
...disableProps(['view']),
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/sdds-cs/src/components/Range/Range.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const config = {
${tokens.dividerColor}: var(--text-primary);
${tokens.labelColor}: var(--text-primary);
${tokens.leftHelperColor}: var(--text-secondary);
${tokens.leftHelperColorError}: var(--text-negative);
${tokens.leftHelperColorSuccess}: var(--text-positive);

${tokens.indicatorColor}: var(--surface-negative);

Expand Down
Loading