Skip to content

Commit

Permalink
feat(new-hope): hide placeholder in textarea if default value in reac…
Browse files Browse the repository at this point in the history
…t hook form
  • Loading branch information
iljs committed Dec 19, 2024
1 parent 9023754 commit 4dac713
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 144 deletions.
18 changes: 0 additions & 18 deletions packages/plasma-b2c/src/components/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ const meta: Meta<TextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
defaultValue: 'm',
Expand Down Expand Up @@ -137,10 +131,6 @@ const meta: Meta<TextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
Expand All @@ -153,14 +143,6 @@ const meta: Meta<TextAreaProps> = {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ const meta: Meta<TextFieldProps> = {
},
if: { arg: 'clear', truthy: true },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
control: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useState, createRef, useCallback, useRef, MouseEventHandler } from 'react';
import React, { forwardRef, useState, createRef, useCallback, useRef, MouseEventHandler, useLayoutEffect } from 'react';
import { css } from '@linaria/core';
import { useForkRef, useResizeObserver } from '@salutejs/plasma-core';

Expand Down Expand Up @@ -199,6 +199,12 @@ export const textAreaRoot = (Root: RootProps<HTMLTextAreaElement, TextAreaRootPr
}
};

useLayoutEffect(() => {
if (outerRef.current) {
setUncontrolledValue(outerRef.current.value);
}
}, [outerRef]);

useResizeObserver(outerRef, (currentElement) => {
const { width: inlineWidth } = currentElement.style;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { config } from './TextArea.config';
import { TextArea } from './TextArea';

const labelPlacements = ['inner', 'outer'];
const sizes = ['xs', 's', 'm', 'l'];
const hintViews = ['default'];
const hintSizes = ['m', 's'];
const hintTriggers = ['hover', 'click'];
Expand Down Expand Up @@ -67,22 +68,17 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
rows: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
cols: {
size: {
options: sizes,
defaultValue: 'm',
control: {
type: 'number',
type: 'select',
},
if: { arg: 'clear', truthy: false },
},
labelPlacement: {
options: labelPlacements,
options: ['inner', 'outer'],
control: {
type: 'inline-radio',
type: 'select',
},
},
hasDivider: {
Expand All @@ -91,6 +87,18 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'clear', truthy: true },
},
cols: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
rows: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
hintText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
Expand Down Expand Up @@ -132,7 +140,43 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
...disableProps(['leftHelperPlacement']),
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
},
width: {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
height: {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
'contentRight',
'autoComplete',
'autoFocus',
'dirName',
'form',
'minLength',
'maxLength',
'name',
'value',
'wrap',
'theme',
'as',
'forwardedAs',
'onChange',
'onFocus',
'onBlur',
'leftHelperPlacement',
'status',
'hintTargetIcon',
'hintOffset',
'hintContentLeft',
]),
},
args: {
id: 'example-textarea',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { config } from './TextArea.config';
import { TextArea } from './TextArea';

const labelPlacements = ['inner', 'outer'];
const sizes = ['xs', 's', 'm', 'l'];
const hintViews = ['default'];
const hintSizes = ['m', 's'];
const hintTriggers = ['hover', 'click'];
Expand Down Expand Up @@ -67,20 +68,15 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
rows: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
cols: {
size: {
options: sizes,
defaultValue: 'm',
control: {
type: 'number',
type: 'select',
},
if: { arg: 'clear', truthy: false },
},
labelPlacement: {
options: labelPlacements,
options: ['inner', 'outer'],
control: {
type: 'select',
},
Expand All @@ -91,6 +87,18 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'clear', truthy: true },
},
cols: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
rows: {
control: {
type: 'number',
},
if: { arg: 'clear', truthy: false },
},
hintText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
Expand Down Expand Up @@ -132,7 +140,43 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
...disableProps(['leftHelperPlacement']),
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
},
width: {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
height: {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
'contentRight',
'autoComplete',
'autoFocus',
'dirName',
'form',
'minLength',
'maxLength',
'name',
'value',
'wrap',
'theme',
'as',
'forwardedAs',
'onChange',
'onFocus',
'onBlur',
'leftHelperPlacement',
'status',
'hintTargetIcon',
'hintOffset',
'hintContentLeft',
]),
},
args: {
id: 'example-textarea',
Expand Down
18 changes: 0 additions & 18 deletions packages/plasma-web/src/components/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ const meta: Meta<TextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
defaultValue: 'm',
Expand Down Expand Up @@ -138,10 +132,6 @@ const meta: Meta<TextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
Expand All @@ -154,14 +144,6 @@ const meta: Meta<TextAreaProps> = {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ const meta: Meta<TextFieldProps> = {
},
if: { arg: 'clear', truthy: true },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
control: {
Expand Down
18 changes: 0 additions & 18 deletions packages/sdds-dfa/src/components/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
defaultValue: 'm',
Expand Down Expand Up @@ -143,10 +137,6 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
Expand All @@ -159,14 +149,6 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
defaultValue: 'm',
Expand Down Expand Up @@ -143,10 +137,6 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
helperText: {
control: { type: 'text' },
if: { arg: 'helperText', truthy: true },
Expand All @@ -159,14 +149,6 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'width', truthy: true },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
...disableProps([
'helperBlock',
'$isFocused',
Expand Down
Loading

0 comments on commit 4dac713

Please sign in to comment.