Skip to content

Commit

Permalink
front: ui-core input tooltip status messages
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Dec 19, 2024
1 parent ab0f830 commit 7932979
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
1 change: 1 addition & 0 deletions ui-core/src/components/inputs/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
disabled={disabled}
required={required}
small={small}
statusIconPosition="before-status-message"
className={cx('input-field-wrapper', inputFieldWrapperClassname)}
>
<div
Expand Down
13 changes: 11 additions & 2 deletions ui-core/src/components/inputs/StatusMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import cx from 'classnames';
import InputStatusIcon from './InputStatusIcon';

export type Status = 'success' | 'info' | 'error' | 'warning' | 'loading';
export type TooltipType = 'left' | 'right';

export type StatusWithMessage = {
tooltip?: TooltipType;
status: Status;
message?: string;
};
Expand All @@ -18,11 +20,18 @@ export type StatusMessageProps = {
};

const StatusMessage = ({ statusWithMessage, showIcon, small }: StatusMessageProps) => {
const { status, message } = statusWithMessage;
const { tooltip, status, message } = statusWithMessage;
if (message === undefined) return null;

return (
<div className="status-message-wrapper">
<div
className={cx({
'status-message-wrapper': !tooltip,
'status-message-wrapper-tooltip': tooltip,
'tooltip-left': tooltip === 'left',
'tooltip-right': tooltip === 'right',
})}
>
{showIcon && <InputStatusIcon status={status} small={small} />}
<span className={cx('status-message', { [status]: status })}>{message}</span>
</div>
Expand Down
34 changes: 34 additions & 0 deletions ui-core/src/stories/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,40 @@ export const ErrorInput: Story = {
},
},
};
export const TooltipErrorInput: Story = {
decorators: [
(Story) => (
<div style={{ display: 'flex', flexDirection: 'row', gap: '20px' }}>
<Story
args={{
label: 'Name',
type: 'text',
value: 'Michel Sardou',
statusWithMessage: {
tooltip: 'left',
status: 'error',
message: 'Michel Sardou can’t be used',
},
statusIconPosition: 'before-status-message',
}}
/>
<Story
args={{
label: 'Name',
type: 'text',
value: 'Jean-Michel Halleurt',
statusWithMessage: {
tooltip: 'right',
status: 'error',
message: 'Jean-Michel Halleurt can’t be used with a very very very very very very very very very long message',

Check warning on line 200 in ui-core/src/stories/Input.stories.tsx

View workflow job for this annotation

GitHub Actions / build

Insert `⏎···············`
},
statusIconPosition: 'before-status-message',
}}
/>
</div>
),
],
};

export const ErrorWithoutMessageInput: Story = {
args: {
Expand Down
56 changes: 53 additions & 3 deletions ui-core/src/styles/inputs/fieldWrapper.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
:root {
--tooltip-transition-duration: 0.2s;
}

.feed-back {
border-radius: 0.5rem;
position: relative;
padding: 0.625rem 0.813rem 1rem 1rem;

&.info {
&.info:not(:has(.status-message-wrapper-tooltip)) {
@apply bg-info-5;
}

&.warning {
&.warning:not(:has(.status-message-wrapper-tooltip)) {
@apply bg-warning-5;
}

&.error {
&.error:not(:has(.status-message-wrapper-tooltip)) {
@apply bg-error-5;
}

.custom-field {
display: flex;
flex-direction: column;
position: relative;

.field-and-status-icon,
.field-wrapper-status-message {
Expand All @@ -28,5 +33,50 @@
margin-left: 0.563rem;
}
}

input:focus:has(.status-message-wrapper-tooltip) .status-message-wrapper-tooltip {
z-index: 2;
}

.status-message-wrapper-tooltip {
position: absolute;
display: flex;
align-items: center;
top: 60px;
gap: 12px;
border-radius: 8px;
box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.2), 0px 1px 0px rgba(255, 255, 255, 0.6) inset;
background-color: rgba(255, 238, 237, 1);
opacity: 1;
padding: 8px 12px;
min-height: 64px;
width: 320px;
z-index: 10;
transition: var(--tooltip-transition-duration) ease;

.status-message {
opacity: 1;
color: theme('colors.error.60');
font-size: 16px;
font-weight: 600;
font-style: SemiBold;
letter-spacing: 0px;
text-align: left;
line-height: 24px;
}
}
.tooltip-left {
left: -20px;
}

.tooltip-right {
right: -20px;
}
}
}

@media (prefers-reduced-motion: reduce) {
:root {
--tooltip-transition-duration: 0s;
}
}

0 comments on commit 7932979

Please sign in to comment.