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

feat: Add tooltip to text area #535

Merged
merged 1 commit into from
May 3, 2024
Merged
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
5 changes: 5 additions & 0 deletions src/components/TextAreaField/TextAreaField.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
font-family: var(--font-family);
color: var(--secondary-text);
display: flex;
align-items: center;
}

.dcl.text-area > .title > .dui-info-tooltip__trigger {
margin-left: 7px;
}

.dcl.text-area > .title > .maxLength {
Expand Down
13 changes: 13 additions & 0 deletions src/components/TextAreaField/TextAreaField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ storiesOf('TextArea', module)
cols="50"
/>
))
.add('With tooltip', () => (
<TextAreaField
value={textAreaValue}
label="Description"
rows="10"
cols="50"
maxLength={300}
tooltip={{
content: 'This is a tooltip',
position: 'top center'
}}
/>
))
.add('Without label and max length', () => (
<TextAreaField maxLength={300} value={textAreaValue} rows="10" cols="50" />
))
Expand Down
5 changes: 5 additions & 0 deletions src/components/TextAreaField/TextAreaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TextArea, {
} from 'semantic-ui-react/dist/commonjs/addons/TextArea/TextArea'
import Icon from 'semantic-ui-react/dist/commonjs/elements/Icon/Icon'
import { getInputValueLength } from '../../lib/input'
import { InfoTooltip, InfoTooltipProps } from '../InfoTooltip'
import './TextAreaField.css'

export type TextAreaFieldProps = TextAreaProps & {
Expand All @@ -13,6 +14,7 @@ export type TextAreaFieldProps = TextAreaProps & {
error?: string
warning?: string
info?: string
tooltip?: InfoTooltipProps
}

function renderMessage(props: TextAreaFieldProps) {
Expand Down Expand Up @@ -58,6 +60,9 @@ export const TextAreaField = (props: TextAreaFieldProps): JSX.Element => {
{props.label || props.maxLength !== undefined ? (
<div className="title">
{props.label ? <label>{props.label}</label> : null}
{props.label && props.tooltip ? (
<InfoTooltip {...props.tooltip} />
) : null}
{props.maxLength ? (
<span className="maxLength">
{getInputValueLength(props.value)}/{props.maxLength}
Expand Down
Loading