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 17, 2024
1 parent 9023754 commit 69ca1e1
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 72 deletions.
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
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,55 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
...disableProps(['leftHelperPlacement']),
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
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 },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', 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,55 @@ const meta: Meta<StoryTextAreaProps> = {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
...disableProps(['leftHelperPlacement']),
helperText: {
control: { type: 'text' },
if: { arg: 'hasHint', truthy: true },
},
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 },
},
rows: {
control: { type: 'text' },
if: { arg: 'number', truthy: true },
},
cols: {
control: { type: 'text' },
if: { arg: 'number', 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 @@ -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
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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ const meta: Meta<StoryTextAreaProps> = {
},
if: { arg: 'required', truthy: false },
},
status: {
options: statuses,
control: {
type: 'select',
},
},
size: {
options: sizes,
defaultValue: 'm',
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

0 comments on commit 69ca1e1

Please sign in to comment.