Skip to content

Commit 2066d28

Browse files
committed
Change to accept tooltips in some components that do not use FormElement internally
1 parent 772046e commit 2066d28

File tree

4 files changed

+91
-16
lines changed

4 files changed

+91
-16
lines changed

src/scripts/CheckboxGroup.tsx

Lines changed: 19 additions & 8 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_,
@@ -111,14 +117,19 @@ export const CheckboxGroup = createFC<
111117
{...rprops}
112118
onChange={onChange}
113119
>
114-
<legend className='slds-form-element__label'>
115-
{required ? (
116-
<abbr className='slds-required' title='required'>
117-
*
118-
</abbr>
119-
) : undefined}
120-
{label}
121-
</legend>
120+
<div className='slds-grid slds-grid_vertical-align-center'>
121+
<legend className='slds-form-element__label'>
122+
{required ? (
123+
<abbr className='slds-required' title='required'>
124+
*
125+
</abbr>
126+
) : undefined}
127+
{label}
128+
</legend>
129+
{tooltip ? (
130+
<TooltipContent icon={tooltipIcon}>{tooltip}</TooltipContent>
131+
) : null}
132+
</div>
122133
<div className='slds-form-element__control' ref={controlElRef}>
123134
<CheckboxGroupContext.Provider value={grpCtx}>
124135
{children}

src/scripts/RadioGroup.tsx

Lines changed: 19 additions & 8 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
@@ -89,14 +95,19 @@ export const RadioGroup = createFC<RadioGroupProps, { isFormElement: boolean }>(
8995
style={grpStyles}
9096
{...rprops}
9197
>
92-
<legend className='slds-form-element__label'>
93-
{required ? (
94-
<abbr className='slds-required' title='required'>
95-
*
96-
</abbr>
97-
) : undefined}
98-
{label}
99-
</legend>
98+
<div className='slds-grid slds-grid_vertical-align-center'>
99+
<legend className='slds-form-element__label'>
100+
{required ? (
101+
<abbr className='slds-required' title='required'>
102+
*
103+
</abbr>
104+
) : undefined}
105+
{label}
106+
</legend>
107+
{tooltip ? (
108+
<TooltipContent icon={tooltipIcon}>{tooltip}</TooltipContent>
109+
) : null}
110+
</div>
100111
<div className='slds-form-element__control'>
101112
<RadioGroupContext.Provider value={grpCtx}>
102113
{children}

stories/Checkbox.stories.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,33 @@ export const Disabled: StoryObj<StoryProps> = {
176176
},
177177
},
178178
};
179+
180+
/**
181+
*
182+
*/
183+
export const WithTooltip: StoryObj<StoryProps> = {
184+
render: ({ checkbox1, checkbox2, ...args }) => (
185+
<CheckboxGroup {...args}>
186+
<Checkbox {...checkbox1} />
187+
<Checkbox {...checkbox2} />
188+
</CheckboxGroup>
189+
),
190+
name: 'With tooltip',
191+
args: {
192+
label: 'Checkbox Group Label',
193+
tooltip: 'Tooltip Text',
194+
checkbox1: {
195+
label: 'Checkbox Label One',
196+
value: '1',
197+
},
198+
checkbox2: {
199+
label: 'Checkbox Label Two',
200+
value: '2',
201+
},
202+
},
203+
parameters: {
204+
docs: {
205+
storyDescription: 'Checkbox group with tooltip',
206+
},
207+
},
208+
};

stories/Radio.stories.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,26 @@ export const Disabled: StoryObj<StoryProps> = {
136136
},
137137
},
138138
};
139+
140+
/**
141+
*
142+
*/
143+
export const WithTooltip: StoryObj<StoryProps> = {
144+
render: (args) => (
145+
<RadioGroup {...args}>
146+
<Radio label='Radio Label One' value='1' />
147+
<Radio label='Radio Label Two' value='2' />
148+
</RadioGroup>
149+
),
150+
args: {
151+
label: 'Radio Group Label',
152+
tooltip: 'Tooltip Text',
153+
},
154+
parameters: {
155+
docs: {
156+
description: {
157+
story: 'Radio Group control with tooltip',
158+
},
159+
},
160+
},
161+
};

0 commit comments

Comments
 (0)