Skip to content

Commit 8e183bc

Browse files
authored
Merge pull request #455 from mashmatrix/accept-tooltip-in-components-use-formelement
Changed to accept tooltips in components that use FormElement internally
2 parents 7b1ef61 + 994ce6a commit 8e183bc

17 files changed

+276
-6
lines changed

src/scripts/Checkbox.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { FC, InputHTMLAttributes, Ref, useContext } from 'react';
1+
import React, {
2+
FC,
3+
InputHTMLAttributes,
4+
Ref,
5+
useContext,
6+
ReactNode,
7+
} from 'react';
28
import classnames from 'classnames';
39
import { FormElement, FormElementProps } from './FormElement';
410
import { CheckboxGroupContext, CheckboxValueType } from './CheckboxGroup';
@@ -15,6 +21,8 @@ export type CheckboxProps = {
1521
value?: CheckboxValueType;
1622
checked?: boolean;
1723
defaultChecked?: boolean;
24+
tooltip?: ReactNode;
25+
tooltipIcon?: string;
1826
elementRef?: Ref<HTMLDivElement>;
1927
inputRef?: Ref<HTMLInputElement>;
2028
} & InputHTMLAttributes<HTMLInputElement>;
@@ -30,13 +38,22 @@ export const Checkbox: FC<CheckboxProps> = (props) => {
3038
required,
3139
error,
3240
cols,
41+
tooltip,
42+
tooltipIcon,
3343
elementRef,
3444
inputRef,
3545
children,
3646
...rprops
3747
} = props;
3848
const { grouped } = useContext(CheckboxGroupContext);
39-
const formElemProps = { required, error, cols, elementRef };
49+
const formElemProps = {
50+
required,
51+
error,
52+
cols,
53+
tooltip,
54+
tooltipIcon,
55+
elementRef,
56+
};
4057
const checkClassNames = classnames(className, 'slds-checkbox');
4158
const check = (
4259
<label className={checkClassNames}>

src/scripts/CheckboxGroup.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import React, {
55
useContext,
66
useMemo,
77
useRef,
8+
ReactNode,
89
} from 'react';
910
import classnames from 'classnames';
1011
import { FormElementProps } from './FormElement';
1112
import { FieldSetColumnContext } from './FieldSet';
13+
import { TooltipContent } from './TooltipContent';
1214
import { useEventCallback } from './hooks';
1315
import { createFC } from './common';
1416
import { Bivariant } from './typeUtils';
@@ -32,6 +34,8 @@ export type CheckboxGroupProps = {
3234
error?: FormElementProps['error'];
3335
name?: string;
3436
cols?: number;
37+
tooltip?: ReactNode;
38+
tooltipIcon?: string;
3539
elementRef?: Ref<HTMLFieldSetElement>;
3640
onValueChange?: Bivariant<(values: CheckboxValueType[]) => void>;
3741
} & FieldsetHTMLAttributes<HTMLFieldSetElement>;
@@ -51,6 +55,8 @@ export const CheckboxGroup = createFC<
5155
style,
5256
required,
5357
error,
58+
tooltip,
59+
tooltipIcon,
5460
elementRef,
5561
onValueChange,
5662
onChange: onChange_,
@@ -118,6 +124,11 @@ export const CheckboxGroup = createFC<
118124
</abbr>
119125
) : undefined}
120126
{label}
127+
{tooltip ? (
128+
<span className='slds-m-left_x-small'>
129+
<TooltipContent icon={tooltipIcon}>{tooltip}</TooltipContent>
130+
</span>
131+
) : null}
121132
</legend>
122133
<div className='slds-form-element__control' ref={controlElRef}>
123134
<CheckboxGroupContext.Provider value={grpCtx}>

src/scripts/DateInput.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, {
88
useRef,
99
useState,
1010
useContext,
11+
ReactNode,
1112
} from 'react';
1213
import classnames from 'classnames';
1314
import dayjs from 'dayjs';
@@ -118,6 +119,8 @@ export type DateInputProps = {
118119
minDate?: string;
119120
maxDate?: string;
120121
menuAlign?: 'left' | 'right';
122+
tooltip?: ReactNode;
123+
tooltipIcon?: string;
121124
elementRef?: Ref<HTMLDivElement>;
122125
datepickerRef?: Ref<HTMLDivElement>;
123126
onBlur?: () => void;
@@ -149,6 +152,8 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
149152
minDate,
150153
maxDate,
151154
extensionRenderer,
155+
tooltip,
156+
tooltipIcon,
152157
elementRef: elementRef_,
153158
inputRef: inputRef_,
154159
datepickerRef: datepickerRef_,
@@ -316,7 +321,16 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
316321
}
317322
});
318323

319-
const formElemProps = { id, cols, label, required, error, elementRef };
324+
const formElemProps = {
325+
id,
326+
cols,
327+
label,
328+
required,
329+
error,
330+
tooltip,
331+
tooltipIcon,
332+
elementRef,
333+
};
320334
return (
321335
<FormElement {...formElemProps}>
322336
<div className={classnames(className, 'slds-dropdown-trigger')}>

src/scripts/Input.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
useContext,
88
Ref,
99
useRef,
10+
ReactNode,
1011
} from 'react';
1112
import classnames from 'classnames';
1213
import keycoder from 'keycoder';
@@ -92,6 +93,8 @@ export type InputProps = {
9293
iconRight?: string | JSX.Element;
9394
addonLeft?: string;
9495
addonRight?: string;
96+
tooltip?: ReactNode;
97+
tooltipIcon?: string;
9598
elementRef?: Ref<HTMLDivElement>;
9699
inputRef?: Ref<HTMLInputElement>;
97100
onValueChange?: (value: string, prevValue?: string) => void;
@@ -120,6 +123,8 @@ export const Input = createFC<InputProps, { isFormElement: boolean }>(
120123
addonLeft,
121124
addonRight,
122125
symbolPattern,
126+
tooltip,
127+
tooltipIcon,
123128
elementRef,
124129
inputRef,
125130
onKeyDown: onKeyDown_,
@@ -207,6 +212,8 @@ export const Input = createFC<InputProps, { isFormElement: boolean }>(
207212
error,
208213
readOnly,
209214
cols,
215+
tooltip,
216+
tooltipIcon,
210217
elementRef,
211218
};
212219
return <FormElement {...formElemProps}>{contentElem}</FormElement>;

src/scripts/Lookup.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import React, {
1111
useState,
1212
useEffect,
1313
EventHandler,
14+
ReactNode,
1415
} from 'react';
1516
import classnames from 'classnames';
1617
import { AutoAlign, AutoAlignInjectedProps, AutoAlignProps } from './AutoAlign';
@@ -571,6 +572,8 @@ export type LookupProps = {
571572
targetScope?: string;
572573
defaultTargetScope?: string;
573574
cols?: number;
575+
tooltip?: ReactNode;
576+
tooltipIcon?: string;
574577

575578
elementRef?: Ref<HTMLDivElement>;
576579
inputRef?: Ref<HTMLDivElement>;
@@ -619,6 +622,8 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
619622
listFooter,
620623
data,
621624
scopes,
625+
tooltip,
626+
tooltipIcon,
622627
onSelect: onSelect_,
623628
onScopeMenuClick: onScopeMenuClick_,
624629
onScopeSelect: onScopeSelect_,
@@ -763,7 +768,15 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
763768
{ 'slds-has-selection': selected },
764769
className
765770
);
766-
const formElemProps = { id, cols, label, required, error };
771+
const formElemProps = {
772+
id,
773+
cols,
774+
label,
775+
required,
776+
error,
777+
tooltip,
778+
tooltipIcon,
779+
};
767780
return (
768781
<FormElement {...formElemProps}>
769782
<div

src/scripts/Picklist.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {
55
useContext,
66
useRef,
77
Ref,
8+
ReactNode,
89
} from 'react';
910
import classnames from 'classnames';
1011
import { FormElement, FormElementProps } from './FormElement';
@@ -57,6 +58,8 @@ export type PicklistProps<MultiSelect extends boolean | undefined> = {
5758
disabled?: boolean;
5859
menuSize?: DropdownMenuProps['size'];
5960
menuStyle?: CSSProperties;
61+
tooltip?: ReactNode;
62+
tooltipIcon?: string;
6063
elementRef?: Ref<HTMLDivElement>;
6164
dropdownRef?: Ref<HTMLDivElement>;
6265
onValueChange?: Bivariant<
@@ -98,6 +101,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
98101
required,
99102
error,
100103
cols,
104+
tooltip,
105+
tooltipIcon,
101106
elementRef: elementRef_,
102107
buttonRef: buttonRef_,
103108
dropdownRef: dropdownRef_,
@@ -294,6 +299,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
294299
required,
295300
error,
296301
cols,
302+
tooltip,
303+
tooltipIcon,
297304
elementRef,
298305
};
299306
return (

src/scripts/RadioGroup.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import React, {
44
createContext,
55
useContext,
66
useMemo,
7+
ReactNode,
78
} from 'react';
89
import classnames from 'classnames';
910
import { FieldSetColumnContext } from './FieldSet';
11+
import { TooltipContent } from './TooltipContent';
1012
import { createFC } from './common';
1113
import { Bivariant } from './typeUtils';
1214

@@ -32,6 +34,8 @@ export type RadioGroupProps = {
3234
error?: boolean | string | { message: string };
3335
name?: string;
3436
cols?: number;
37+
tooltip?: ReactNode;
38+
tooltipIcon?: string;
3539
elementRef?: Ref<HTMLFieldSetElement>;
3640
onValueChange?: Bivariant<(value: RadioValueType) => void>;
3741
} & HTMLAttributes<HTMLFieldSetElement>;
@@ -50,6 +54,8 @@ export const RadioGroup = createFC<RadioGroupProps, { isFormElement: boolean }>(
5054
style,
5155
children,
5256
name,
57+
tooltip,
58+
tooltipIcon,
5359
elementRef,
5460
onValueChange,
5561
...rprops
@@ -96,6 +102,11 @@ export const RadioGroup = createFC<RadioGroupProps, { isFormElement: boolean }>(
96102
</abbr>
97103
) : undefined}
98104
{label}
105+
{tooltip ? (
106+
<span className='slds-m-left_x-small'>
107+
<TooltipContent icon={tooltipIcon}>{tooltip}</TooltipContent>
108+
</span>
109+
) : null}
99110
</legend>
100111
<div className='slds-form-element__control'>
101112
<RadioGroupContext.Provider value={grpCtx}>

src/scripts/Select.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, {
66
useRef,
77
ChangeEvent,
88
FC,
9+
ReactNode,
910
} from 'react';
1011
import classnames from 'classnames';
1112
import { FormElement, FormElementProps } from './FormElement';
@@ -21,6 +22,8 @@ export type SelectProps = {
2122
required?: boolean;
2223
cols?: number;
2324
error?: FormElementProps['error'];
25+
tooltip?: ReactNode;
26+
tooltipIcon?: string;
2427
elementRef?: Ref<HTMLDivElement>;
2528
selectRef?: Ref<HTMLSelectElement>;
2629
onValueChange?: (value: string, prevValue?: string) => void;
@@ -38,6 +41,8 @@ export const Select = createFC<SelectProps, { isFormElement: boolean }>(
3841
required,
3942
error,
4043
cols,
44+
tooltip,
45+
tooltipIcon,
4146
elementRef,
4247
selectRef,
4348
children,
@@ -65,7 +70,16 @@ export const Select = createFC<SelectProps, { isFormElement: boolean }>(
6570
</select>
6671
);
6772
if (isFieldSetColumn || label || required || error || cols) {
68-
const formElemProps = { id, label, required, error, cols, elementRef };
73+
const formElemProps = {
74+
id,
75+
label,
76+
required,
77+
error,
78+
cols,
79+
tooltip,
80+
tooltipIcon,
81+
elementRef,
82+
};
6983
return <FormElement {...formElemProps}>{selectElem}</FormElement>;
7084
}
7185
return selectElem;

src/scripts/Textarea.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {
22
ChangeEvent,
3+
ReactNode,
34
Ref,
45
TextareaHTMLAttributes,
56
useContext,
@@ -19,6 +20,8 @@ export type TextareaProps = {
1920
required?: boolean;
2021
error?: FormElementProps['error'];
2122
cols?: number;
23+
tooltip?: ReactNode;
24+
tooltipIcon?: string;
2225
elementRef?: Ref<HTMLDivElement>;
2326
textareaRef?: Ref<HTMLTextAreaElement>;
2427
onValueChange?: (value: string, prevValue?: string) => void;
@@ -36,6 +39,8 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
3639
required,
3740
error,
3841
cols,
42+
tooltip,
43+
tooltipIcon,
3944
elementRef,
4045
textareaRef,
4146
onChange: onChange_,
@@ -60,7 +65,16 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
6065
/>
6166
);
6267
if (isFieldSetColumn || label || required || error || cols) {
63-
const formElemProps = { id, label, required, error, cols, elementRef };
68+
const formElemProps = {
69+
id,
70+
label,
71+
required,
72+
error,
73+
cols,
74+
tooltip,
75+
tooltipIcon,
76+
elementRef,
77+
};
6478
return <FormElement {...formElemProps}>{textareaElem}</FormElement>;
6579
}
6680
return textareaElem;

0 commit comments

Comments
 (0)