Skip to content

Commit 772046e

Browse files
committed
Changed to accept tooltips in components that use FormElement internally
1 parent 7b1ef61 commit 772046e

File tree

13 files changed

+201
-6
lines changed

13 files changed

+201
-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/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/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;

stories/DateInput.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,21 @@ export const IncludeTimeData: ComponentStoryObj<typeof DateInput> = {
175175
},
176176
},
177177
};
178+
179+
/**
180+
*
181+
*/
182+
export const WithTooltip: ComponentStoryObj<typeof DateInput> = {
183+
name: 'With tooltip',
184+
args: {
185+
label: 'Date Input Label',
186+
tooltip: 'Tooltip Text',
187+
},
188+
parameters: {
189+
docs: {
190+
description: {
191+
story: 'Date input control with tooltip',
192+
},
193+
},
194+
},
195+
};

stories/Input.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,20 @@ export const ReadOnlyWithFixedText: ComponentStoryObj<typeof Input> = {
253253
},
254254
},
255255
};
256+
257+
/**
258+
*
259+
*/
260+
export const WithTooltip: ComponentStoryObj<typeof Input> = {
261+
name: 'With tooltip',
262+
args: {
263+
label: 'Input Label',
264+
placeholder: 'Placeholder Text',
265+
tooltip: 'Tooltip Text',
266+
},
267+
parameters: {
268+
docs: {
269+
storyDescription: 'Input control with tooltip',
270+
},
271+
},
272+
};

stories/Lookup.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,22 @@ export const UncontrolledWithMultiScope: ComponentStoryObj<typeof Lookup> = {
654654
},
655655
},
656656
};
657+
658+
/**
659+
*
660+
*/
661+
export const WithTooltip: ComponentStoryObj<typeof Lookup> = {
662+
name: 'With tooltip',
663+
args: {
664+
label: 'Lookup Label',
665+
tooltip: 'Tooltip Text',
666+
},
667+
parameters: {
668+
docs: {
669+
description: {
670+
story: 'Lookup component with tooltip',
671+
},
672+
iframeHeight: 120,
673+
},
674+
},
675+
};

0 commit comments

Comments
 (0)