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

front: ui-core input tooltip status messages #776

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui-core/src/components/inputs/FieldWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const FieldWrapper = ({
{/* STATUS MESSAGE */}
{statusWithMessage && (
<StatusMessage
small={small}
statusWithMessage={statusWithMessage}
showIcon={statusIconPosition === 'before-status-message'}
/>
Expand Down
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={statusWithMessage?.tooltip ? 'before-status-message' : undefined}
className={cx('input-field-wrapper', inputFieldWrapperClassname)}
>
<div
Expand Down
2 changes: 1 addition & 1 deletion ui-core/src/components/inputs/InputStatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Gear, CheckCircle, Info, Alert, Blocked } from '@osrd-project/ui-icons';

Check warning on line 3 in ui-core/src/components/inputs/InputStatusIcon.tsx

View workflow job for this annotation

GitHub Actions / build

Unable to resolve path to module '@osrd-project/ui-icons'
import cx from 'classnames';

export type status = 'success' | 'info' | 'error' | 'warning' | 'loading';
Expand All @@ -16,7 +16,7 @@
return (
<span className={cx('status-icon', className, status)}>
{status === 'loading' && <Gear size={size} />}
{status === 'info' && <Info size={size} />}
{status === 'info' && <Info variant="fill" size={size} />}
{status === 'success' && <CheckCircle variant="fill" size={size} />}
{status === 'warning' && <Alert variant="fill" size={size} />}
{status === 'error' && <Blocked variant="fill" size={size} />}
Expand Down
14 changes: 12 additions & 2 deletions ui-core/src/components/inputs/StatusMessage.tsx
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
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,19 @@ 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',
[status]: status,
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
})}
>
{showIcon && <InputStatusIcon status={status} small={small} />}
<span className={cx('status-message', { [status]: status })}>{message}</span>
</div>
Expand Down
47 changes: 47 additions & 0 deletions ui-core/src/stories/Input.stories.tsx
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,53 @@ export const ErrorInput: Story = {
},
};

export const TooltipErrorInput: Story = {
args: {
label: 'Name',
type: 'text',
required: true,
value: 'Michel Sardou',
statusWithMessage: {
tooltip: 'right',
status: 'error',
message: '“Michel Sardou” can’t be used',
},
},
};

export const TwoTooltipErrorInput: 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',
},
}}
/>
<Story
args={{
label: 'Name',
type: 'text',
value: 'Jean-Michel Halleurt',
statusWithMessage: {
tooltip: 'right',
status: 'error',
message: 'Jean-Michel Halleurt can’t be used',
},
}}
/>
</div>
),
],
};

export const ErrorWithoutMessageInput: Story = {
args: {
label: 'Name',
Expand Down
14 changes: 11 additions & 3 deletions ui-core/src/styles/inputs/fieldWrapper.css
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
.feed-back {
--input-wrapper-padding: 3px;
--field-wrapper-padding-bottom: 16px;
--status-message-wrapper-tooltip--offset: 4px;

border-radius: 0.5rem;
position: relative;
padding: 0.625rem 0.813rem 1rem 1rem;

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

&.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;
}

Expand Down
63 changes: 63 additions & 0 deletions ui-core/src/styles/inputs/statusMessage.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,66 @@
}
}
}

.status-message-wrapper-tooltip {
position: absolute;
display: flex;
align-items: center;
width: 320px;
top: calc(
100% - var(--input-wrapper-padding) - var(--field-wrapper-padding-bottom) -
var(--status-message-wrapper-tooltip--offset)
);
gap: 12px;
border-radius: 8px;
box-shadow:
0 10px 20px 0 rgba(0, 0, 0, 0.2),
0 1px 0 rgba(255, 255, 255, 0.6) inset;
padding: 6px 12px 10px;
min-height: 64px;
z-index: 10;

&.success {
background-color: theme('colors.success.5');
}

&.error {
background-color: theme('colors.error.5');
}

&.info {
background-color: theme('colors.info.5');
}

&.warning {
background-color: theme('colors.warning.5');
}

SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
&.tooltip-left {
left: 8px;
}

&.tooltip-right {
right: 8px;
}

.status-message {
font-weight: 600;

&.success {
color: theme('colors.success.60');
}

&.error {
color: theme('colors.error.60');
}

&.info {
color: theme('colors.info.60');
}

&.warning {
color: theme('colors.warning.60');
}
}
}
Loading