From 89ca31cfe03449df8430ef8c0b687aab2bb24d94 Mon Sep 17 00:00:00 2001 From: Sergey Terpugov Date: Sun, 13 Oct 2024 20:14:35 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=20label=20?= =?UTF-8?q?=D0=B8=20errorText=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D1=8B=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/ui/errorText/errorText.module.css | 8 +++++ src/shared/ui/errorText/errorText.stories.tsx | 35 +++++++++++++++++++ src/shared/ui/errorText/index.tsx | 13 +++++++ src/shared/ui/form-input-phone/index.tsx | 5 +-- .../ui/form-input-phone/styles.module.css | 5 --- src/shared/ui/form-input/index.tsx | 5 +-- src/shared/ui/form-input/styles.module.css | 5 --- src/shared/ui/index.ts | 2 ++ src/shared/ui/input-phone/index.tsx | 10 +++--- .../ui/input-phone/input-phone.stories.ts | 2 +- src/shared/ui/input-phone/styles.module.css | 24 +------------ src/shared/ui/input/index.tsx | 10 +++--- src/shared/ui/input/styles.module.css | 13 ------- src/shared/ui/label/index.tsx | 16 +++++++++ src/shared/ui/label/label.module.css | 16 +++++++++ src/shared/ui/label/label.stories.ts | 35 +++++++++++++++++++ src/shared/ui/post-form/post-form.stories.tsx | 6 ++-- src/shared/ui/radio-button/index.tsx | 7 ++-- src/shared/ui/select/index.tsx | 5 +-- src/shared/ui/select/styles.module.css | 9 ----- src/shared/ui/text-area/index.tsx | 5 +-- src/shared/ui/text-area/styles.module.css | 9 ----- 22 files changed, 157 insertions(+), 88 deletions(-) create mode 100644 src/shared/ui/errorText/errorText.module.css create mode 100644 src/shared/ui/errorText/errorText.stories.tsx create mode 100644 src/shared/ui/errorText/index.tsx create mode 100644 src/shared/ui/label/index.tsx create mode 100644 src/shared/ui/label/label.module.css create mode 100644 src/shared/ui/label/label.stories.ts diff --git a/src/shared/ui/errorText/errorText.module.css b/src/shared/ui/errorText/errorText.module.css new file mode 100644 index 000000000..8387eef66 --- /dev/null +++ b/src/shared/ui/errorText/errorText.module.css @@ -0,0 +1,8 @@ +.error { + font-family: 'Golos', sans-serif; + margin-top: 8px; + font-size: var(--font-size-small); + line-height: var(--line-height-xs); + font-weight: var(--font-weight-regular); + color: var(--colors-interface-orange); + } \ No newline at end of file diff --git a/src/shared/ui/errorText/errorText.stories.tsx b/src/shared/ui/errorText/errorText.stories.tsx new file mode 100644 index 000000000..d2d8eca21 --- /dev/null +++ b/src/shared/ui/errorText/errorText.stories.tsx @@ -0,0 +1,35 @@ +import { Meta, StoryObj } from "@storybook/react/*"; +import { ErrorText } from "."; + +const meta = { + title: 'uikit/FormElements/ErrorText', + component: ErrorText, + tags: ['autodocs'], + argTypes: { + className: { + table: { + disable: true, + } + }, + extClassName: { + table: { + disable: true, + } + }, + htmlFor: { + table: { + disable: true, + } + } + } +} as Meta + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: { + error: 'Test' + } +} diff --git a/src/shared/ui/errorText/index.tsx b/src/shared/ui/errorText/index.tsx new file mode 100644 index 000000000..13009c335 --- /dev/null +++ b/src/shared/ui/errorText/index.tsx @@ -0,0 +1,13 @@ +import cn from 'classnames' +import styles from './errorText.module.css' + +export interface ErrorTextProp { + error?: string; + extClassName?: string; +} + +export const ErrorText: React.FC = ({ error }) => ( + + {error === ' ' ?   : error} + +) diff --git a/src/shared/ui/form-input-phone/index.tsx b/src/shared/ui/form-input-phone/index.tsx index f0e89c6ea..e476ca496 100644 --- a/src/shared/ui/form-input-phone/index.tsx +++ b/src/shared/ui/form-input-phone/index.tsx @@ -10,6 +10,7 @@ import { } from 'react-hook-form'; import styles from './styles.module.css'; +import { Label } from '../label'; const DEFAULT_MASK = [ '+', @@ -61,9 +62,9 @@ export const FormInputPhone = ({ return (
{label && ( - )}
extends InputHTMLAttributes { @@ -47,9 +48,9 @@ export const FormInput = ({ return (
{label && ( - )}
{ name: string; @@ -53,9 +55,9 @@ export const InputPhone = forwardRef( return (
{label && ( - )}
( ]} onChange={onChange} /> - - {errorText === ' ' ?   : errorText} - + {errorText && }
{customIcon}
diff --git a/src/shared/ui/input-phone/input-phone.stories.ts b/src/shared/ui/input-phone/input-phone.stories.ts index fab6329b4..9e96e5e45 100644 --- a/src/shared/ui/input-phone/input-phone.stories.ts +++ b/src/shared/ui/input-phone/input-phone.stories.ts @@ -22,7 +22,7 @@ export const Default: Story = { name: 'phone', label: 'Телефон', error: false, - errorText: 'Некорректный номер телефона', + placeholder: '+7 000 000000', }, }; diff --git a/src/shared/ui/input-phone/styles.module.css b/src/shared/ui/input-phone/styles.module.css index c2a1b8432..4edf7607f 100644 --- a/src/shared/ui/input-phone/styles.module.css +++ b/src/shared/ui/input-phone/styles.module.css @@ -33,23 +33,6 @@ border-color: var(--colors-interface-blue-navy); } -.label { - display: inline-block; - font-size: var(--font-size-small); - line-height: var(--line-height-middle); - font-weight: var(--font-weight-regular); - color: var(--colors-interface-black); - margin-bottom: 8px; -} - -.error { - margin-top: 8px; - font-size: var(--font-size-small); - line-height: var(--line-height-xs); - font-weight: var(--font-weight-regular); - color: var(--colors-interface-orange); -} - .for_storybook { width: 350px; } @@ -75,11 +58,6 @@ } @media screen and (max-width: 550px) { - .label { - font-size: var(--font-size-small); - line-height: var(--line-height-xs); - } - .input { font-size: var(--font-size-small); line-height: var(--line-height-xs); @@ -95,4 +73,4 @@ .icon:hover, .icon:active { opacity: 0.6; -} +} \ No newline at end of file diff --git a/src/shared/ui/input/index.tsx b/src/shared/ui/input/index.tsx index e739eb6aa..5ba20982b 100644 --- a/src/shared/ui/input/index.tsx +++ b/src/shared/ui/input/index.tsx @@ -5,6 +5,8 @@ import cn from 'classnames'; import { nanoid } from 'nanoid'; import styles from './styles.module.css'; +import { Label } from '../label'; +import { ErrorText } from '../errorText'; export interface InputProps extends InputHTMLAttributes { name: string; @@ -49,9 +51,9 @@ export const Input = forwardRef( return (
{label && ( - )}
( id={id} {...props} /> - - {errorText === ' ' ?   : errorText} - +
{customIcon}
diff --git a/src/shared/ui/input/styles.module.css b/src/shared/ui/input/styles.module.css index d219badf8..f3a91d864 100644 --- a/src/shared/ui/input/styles.module.css +++ b/src/shared/ui/input/styles.module.css @@ -36,14 +36,6 @@ border-color: var(--colors-interface-blue-navy); } -.label { - display: inline-block; - font-size: var(--font-size-small); - line-height: var(--line-height-middle); - font-weight: var(--font-weight-regular); - color: var(--colors-interface-black); - margin-bottom: 6px; -} .error { margin-top: 8px; font-size: var(--font-size-small); @@ -75,11 +67,6 @@ } @media screen and (max-width: 550px) { - .label { - font-size: var(--font-size-small); - line-height: var(--line-height-xs); - } - .input { font-size: var(--font-size-small); line-height: var(--line-height-xs); diff --git a/src/shared/ui/label/index.tsx b/src/shared/ui/label/index.tsx new file mode 100644 index 000000000..fa3caa995 --- /dev/null +++ b/src/shared/ui/label/index.tsx @@ -0,0 +1,16 @@ +import React, { LabelHTMLAttributes } from 'react'; +import styles from './label.module.css' +import classnames from 'classnames'; + +export interface LabelProps extends LabelHTMLAttributes { + extClassName?: string; + htmlFor?: string; +} + +export const Label: React.FC = ({ extClassName, children, htmlFor, ...props }) => { + return ( + + ) +}; diff --git a/src/shared/ui/label/label.module.css b/src/shared/ui/label/label.module.css new file mode 100644 index 000000000..3280e44d6 --- /dev/null +++ b/src/shared/ui/label/label.module.css @@ -0,0 +1,16 @@ +.label { + font-family: 'Golos', sans-serif; + display: inline-block; + font-size: var(--font-size-small); + line-height: var(--line-height-middle); + font-weight: var(--font-weight-regular); + color: var(--colors-interface-black); + margin-bottom: 8px; +} + +@media screen and (max-width: 550px) { + .label { + font-size: var(--font-size-small); + line-height: var(--line-height-xs); + } +} \ No newline at end of file diff --git a/src/shared/ui/label/label.stories.ts b/src/shared/ui/label/label.stories.ts new file mode 100644 index 000000000..635eda9f8 --- /dev/null +++ b/src/shared/ui/label/label.stories.ts @@ -0,0 +1,35 @@ +import { Meta, StoryObj } from "@storybook/react/*"; +import { Label } from "."; + +const meta = { + title: 'uikit/FormElements/Label', + component: Label, + tags: ['autodocs'], + argTypes: { + className: { + table: { + disable: true, + } + }, + extClassName: { + table: { + disable: true, + } + }, + htmlFor: { + table: { + disable: true, + } + } + } +} as Meta + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: { + children: 'Test' + } +} \ No newline at end of file diff --git a/src/shared/ui/post-form/post-form.stories.tsx b/src/shared/ui/post-form/post-form.stories.tsx index aff83bfc6..5539bd21c 100644 --- a/src/shared/ui/post-form/post-form.stories.tsx +++ b/src/shared/ui/post-form/post-form.stories.tsx @@ -3,14 +3,16 @@ import { useArgs } from '@storybook/preview-api'; import { PostForm } from './PostForm'; import { nanoid } from 'nanoid'; import { ChangeEvent } from 'react'; +import { Provider } from 'react-redux'; +import { store } from 'app/store'; const meta: Meta = { component: PostForm, decorators: [ (Story) => ( -
+ -
+ ), function Component(Story, ctx) { const [args, setArgs] = useArgs(); diff --git a/src/shared/ui/radio-button/index.tsx b/src/shared/ui/radio-button/index.tsx index 2c3d5c08f..810507add 100644 --- a/src/shared/ui/radio-button/index.tsx +++ b/src/shared/ui/radio-button/index.tsx @@ -2,6 +2,7 @@ import { InputHTMLAttributes } from 'react'; import classnames from 'classnames'; import styles from './style.module.css'; +import { Label } from '../label'; interface RadioButtonProps extends InputHTMLAttributes { label: string; @@ -25,9 +26,9 @@ const RadioButton = ({ className={styles.radiobutton} {...props} /> - + ); diff --git a/src/shared/ui/select/index.tsx b/src/shared/ui/select/index.tsx index 4cfb50447..05a45e255 100644 --- a/src/shared/ui/select/index.tsx +++ b/src/shared/ui/select/index.tsx @@ -4,6 +4,7 @@ import { nanoid } from 'nanoid'; import styles from './styles.module.css'; import { AccordionIconArrow } from '../icons/accordion-arrow'; +import { Label } from '../label'; interface Props extends SelectHTMLAttributes { options: Array<{ value: string; label: string }>; @@ -37,9 +38,9 @@ export const Select = forwardRef( return (
{label && ( - )}