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 option to pass description to display on hover of properties #6718

Open
wants to merge 3 commits into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const ConditionBlock = (props: ConditionBlockProps) => {
);
};

const { icon, type, config, label }: Property = getCurrentConfig(
const { icon, type, config, label, description }: Property = getCurrentConfig(
property
) as Property;

Expand Down Expand Up @@ -277,8 +277,6 @@ const ConditionBlock = (props: ConditionBlockProps) => {
</ConditionBuilderItem>
)}

{/* <div className={`${blockClass}__block`}> */}

<ConditionBuilderItem
label={label ?? condition?.property}
title={propertyText}
Expand All @@ -287,6 +285,7 @@ const ConditionBlock = (props: ConditionBlockProps) => {
data-name="propertyField"
condition={condition}
type={type}
description={description}
onChange={onPropertyChangeHandler}
>
<ItemOption
Expand Down Expand Up @@ -347,7 +346,6 @@ const ConditionBlock = (props: ConditionBlockProps) => {
wrapperClassName={`${blockClass}__close-condition-wrapper`}
/>
</span>
{/* </div> */}
{manageActionButtons(conditionIndex, group.conditions) && (
<ConditionBuilderAdd
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ ConditionBuilder.propTypes = {
'time',
'custom',
]).isRequired,
description: PropTypes.string, //will be displayed on hover of property field
config: PropTypes.shape({
options: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export type Property = {
id: string;
label: string;
icon?: CarbonIconType;
description?: string;
} & (
| PropertyConfig['option']
| PropertyConfig['text']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, { useEffect, useState } from 'react';
import cx from 'classnames';

import PropTypes from 'prop-types';
Expand All @@ -30,6 +30,7 @@
isInvalid?: boolean;
wrapperClassName?: string;
tabIndex?: number;
description?: string;
}

export const ConditionBuilderButton = ({
Expand All @@ -48,8 +49,19 @@
isInvalid,
wrapperClassName,
tabIndex,
description,
...rest
}: ConditionBuilderButtonProps) => {
const [tooltipText, setTooltipText] = useState(label);
amal-k-joy marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
if (description) {
setTooltipText(description as string);

Check warning on line 59 in packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.tsx#L59

Added line #L59 was not covered by tests
} else {
setTooltipText(label);
}
}, [description, label]);

const carbonPrefix = usePrefix();
const Button = () => {
const dataName = rest['data-name'] ?? '';
Expand Down Expand Up @@ -81,9 +93,9 @@
);
};

return hideLabel || showToolTip ? (
return hideLabel || showToolTip || description ? (
<Tooltip
label={label}
label={tooltipText}
align={tooltipAlign}
className={`${wrapperClassName} ${blockClass}__tooltip ${carbonPrefix}--icon-tooltip`}
{...wrapperProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ ConditionBuilderProvider.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
icon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
description: PropTypes.string,
type: PropTypes.oneOf([
'text',
'textarea',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface ConditionBuilderItemProps extends PropsWithChildren {
showToolTip?: boolean;
popOverClassName?: string;
type?: string;
description?: string;
condition?: Action & Condition;
config?: PropertyConfig;
renderChildren?: (ref: RefObject<HTMLDivElement>) => ReactNode;
Expand All @@ -65,6 +66,7 @@ export const ConditionBuilderItem = ({
config,
renderChildren,
onChange,
description,
...rest
}: ConditionBuilderItemProps) => {
const popoverRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -236,6 +238,7 @@ export const ConditionBuilderItem = ({
}
showToolTip={showToolTip}
isInvalid={isInvalid}
description={description}
{...rest}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ export const inputData = {
label: 'Continent',
icon: Earth,
type: 'option',
description: 'description for continent',
config: {
options: [
{
Expand Down
Loading