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

Update icon placement in LabeledInput/LabeledTextarea #1544

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-vans-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': major
---

Removed `iconDisplayStyle` prop from `LabeledInput` and `LabeledTextarea` components. `svgIcon` is now added inline. Users must use `StatusMessage` to add custom icon to the message.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions apps/storybook/src/LabeledInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SvgPlaceholder } from '@itwin/itwinui-icons-react';
import SvgCamera from '@itwin/itwinui-icons-react/cjs/icons/Camera';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { LabeledInput } from '@itwin/itwinui-react';
import { LabeledInput, StatusMessage } from '@itwin/itwinui-react';

type LabeledInputProps = React.ComponentProps<typeof LabeledInput>;

Expand Down Expand Up @@ -125,8 +125,11 @@ export const WithCustomIcon: Story<LabeledInputProps> = (args) => {
<LabeledInput
placeholder='Enter text here...'
label='This is a label'
message='⬅ This is a custom icon'
svgIcon={<SvgCamera />}
message={
<StatusMessage startIcon={<SvgCamera />}>
⬅ This is a custom icon
</StatusMessage>
}
{...args}
/>
);
Expand Down Expand Up @@ -157,14 +160,12 @@ export const HybridLayout: Story<LabeledInputProps> = (args) => {
label='This is a label'
svgIcon={<SvgPlaceholder />}
message='Block layout with inline icon'
iconDisplayStyle='inline'
{...args}
/>
</>
);
};

HybridLayout.args = {
iconDisplayStyle: 'inline',
message: 'Block layout with inline icon',
};
9 changes: 6 additions & 3 deletions apps/storybook/src/LabeledTextarea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import SvgCamera from '@itwin/itwinui-icons-react/cjs/icons/Camera';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { LabeledTextarea } from '@itwin/itwinui-react';
import { LabeledTextarea, StatusMessage } from '@itwin/itwinui-react';

type LabeledTextareaProps = React.ComponentProps<typeof LabeledTextarea>;

Expand Down Expand Up @@ -102,12 +102,15 @@ Negative.args = {
};

export const WithCustomIcon: Story<Partial<LabeledTextareaProps>> = (args) => {
const { message: textMessage, ...rest } = args;
return (
<LabeledTextarea
placeholder='Enter text here'
label='This is a label'
svgIcon={<SvgCamera />}
{...args}
message={
<StatusMessage startIcon={<SvgCamera />}>{textMessage}</StatusMessage>
}
{...rest}
/>
);
};
Expand Down
21 changes: 4 additions & 17 deletions packages/itwinui-react/src/core/LabeledInput/LabeledInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Input } from '../Input/Input.js';
import { StatusIconMap, useId, Icon } from '../utils/index.js';
import { useId, Icon } from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import { InputGrid } from '../InputGrid/index.js';
import { InputWithDecorations } from '../InputWithDecorations/index.js';
Expand Down Expand Up @@ -40,15 +40,6 @@ export type LabeledInputProps = {
* @default 'default'
*/
displayStyle?: 'default' | 'inline';
/**
* Set display style of icon.
* Supported values:
* - 'block' - icon appears below input.
* - 'inline' - icon appears inside input (at the end).
*
* Defaults to 'block' if `displayStyle` is `default`, else 'inline'.
*/
iconDisplayStyle?: 'block' | 'inline';
/**
* Passes properties for message content.
*/
Expand Down Expand Up @@ -90,14 +81,11 @@ export const LabeledInput = React.forwardRef((props, ref) => {
iconProps,
inputWrapperProps,
displayStyle = 'default',
iconDisplayStyle = displayStyle === 'default' ? 'block' : 'inline',
required = false,
id = uid,
...rest
} = props;

const icon = svgIcon ?? (status && StatusIconMap[status]());
mayank99 marked this conversation as resolved.
Show resolved Hide resolved

return (
<InputGrid labelPlacement={displayStyle} {...wrapperProps}>
{label && (
Expand All @@ -124,17 +112,16 @@ export const LabeledInput = React.forwardRef((props, ref) => {
ref={ref}
{...rest}
/>
{icon && iconDisplayStyle === 'inline' && (
<Icon fill={!svgIcon ? status : undefined} padded {...iconProps}>
{icon}
{svgIcon && (
<Icon padded {...iconProps}>
{svgIcon}
</Icon>
)}
</InputWithDecorations>

{typeof message === 'string' ? (
<StatusMessage
status={status}
startIcon={displayStyle === 'default' ? icon : undefined}
iconProps={iconProps}
contentProps={messageContentProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type LabeledTextareaProps = {
* Passes properties for svgIcon.
*/
iconProps?: React.ComponentProps<typeof Icon>;
} & Pick<LabeledInputProps, 'svgIcon' | 'displayStyle' | 'iconDisplayStyle'>;
} & Pick<LabeledInputProps, 'svgIcon' | 'displayStyle'>;

/**
* Textarea wrapper that allows for additional styling and labelling
Expand Down