Skip to content

Commit 480cf95

Browse files
Adds bold prop to RadioGroup (#1928)
* WIP * update generated stories * test chromatic --------- Co-authored-by: Adam Thompson <[email protected]>
1 parent ba59cff commit 480cf95

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

.changeset/lemon-phones-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/radio-group': minor
3+
---
4+
5+
Adds `bold` prop to RadioGroup, such that you can change whether the label is displayed with a bold font weight.

packages/radio-group/src/Radio/Radio.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const meta: StoryMetaType<typeof Radio> = {
1717
checked: [false, true],
1818
size: Object.values(Size),
1919
disabled: [false, true],
20+
bold: [false, true],
2021
},
2122
args: {
2223
children: 'Radio',

packages/radio-group/src/Radio/Radio.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import { css, cx } from '@leafygreen-ui/emotion';
55
import { useIdAllocator } from '@leafygreen-ui/hooks';
66
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
7+
import { fontWeights } from '@leafygreen-ui/tokens';
78
import { Description, Label } from '@leafygreen-ui/typography';
89

910
import { Size } from '../types';
@@ -55,6 +56,7 @@ function Radio({
5556
checked,
5657
size = Size.Default,
5758
description,
59+
bold,
5860
...rest
5961
}: RadioProps) {
6062
const { darkMode } = useDarkMode(darkModeProp);
@@ -75,6 +77,9 @@ function Radio({
7577
[css`
7678
font-size: 12px;
7779
`]: size === Size.XSmall, // TODO: keeping this style until XS is deprecated
80+
[css`
81+
font-weight: ${fontWeights.regular};
82+
`]: !bold,
7883
},
7984
className,
8085
)}

packages/radio-group/src/Radio/Radio.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RadioGroupProps } from '..';
44

55
export interface RadioProps
66
extends Omit<HTMLElementProps<'input'>, 'size'>,
7-
Pick<RadioGroupProps, 'darkMode' | 'size'> {
7+
Pick<RadioGroupProps, 'darkMode' | 'size' | 'bold'> {
88
/**
99
* Used to determine what Radio is active.
1010
*/

packages/radio-group/src/RadioGroup.story.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const meta: StoryMetaType<typeof RadioGroup> = {
2020
generate: {
2121
combineArgs: {
2222
darkMode: [false, true],
23+
bold: [false, true],
2324
size: Object.values(Size),
2425
},
2526
},
@@ -41,6 +42,7 @@ const meta: StoryMetaType<typeof RadioGroup> = {
4142
},
4243
argTypes: {
4344
children: { control: false },
45+
bold: { control: 'boolean' },
4446
darkMode: storybookArgTypes.darkMode,
4547
size: {
4648
control: 'radio',
@@ -50,23 +52,50 @@ const meta: StoryMetaType<typeof RadioGroup> = {
5052
};
5153
export default meta;
5254

53-
export const LiveExample: StoryFn<RadioGroupProps> = (
54-
args: RadioGroupProps,
55-
) => <RadioGroup name="radio-group-default" {...args} />;
55+
export const LiveExample: StoryFn<RadioGroupProps> = ({
56+
children,
57+
...args
58+
}: RadioGroupProps) => (
59+
<RadioGroup name="radio-group-default" {...args}>
60+
<Radio value="1">Radio Input 1</Radio>
61+
<Radio default value="2" description="This is a description">
62+
Radio Input 2
63+
</Radio>
64+
<Radio disabled value="Selection-4">
65+
Disabled Option
66+
</Radio>
67+
</RadioGroup>
68+
);
5669
LiveExample.parameters = {
5770
chromatic: {
5871
disableSnapshot: true,
5972
},
6073
};
6174

6275
export const Controlled: StoryFn<RadioGroupProps> = (args: RadioGroupProps) => {
63-
const [activeRadio, setActiveRadio] = useState<string>('test1');
76+
const [activeRadio, setActiveRadio] = useState<string>('1');
6477

6578
const handleChange = (e: React.ChangeEvent) => {
6679
setActiveRadio((e.target as HTMLInputElement).value);
6780
};
6881

69-
return <RadioGroup {...args} onChange={handleChange} value={activeRadio} />;
82+
return (
83+
<RadioGroup {...args} onChange={handleChange} value={activeRadio}>
84+
<Radio checked={activeRadio === '1'} value="1">
85+
Radio Input 1
86+
</Radio>
87+
<Radio
88+
checked={activeRadio === '2'}
89+
value="2"
90+
description="This is a description"
91+
>
92+
Radio Input 2
93+
</Radio>
94+
<Radio checked={activeRadio === '3'} disabled value="3">
95+
Disabled Option
96+
</Radio>
97+
</RadioGroup>
98+
);
7099
};
71100
Controlled.parameters = {
72101
chromatic: {

packages/radio-group/src/RadioGroup/RadioGroup.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function RadioGroup({
3737
children,
3838
value: controlledValue,
3939
name: nameProp,
40+
bold = true,
4041
...rest
4142
}: RadioGroupProps) {
4243
let isControlled = controlledValue != null ? true : false,
@@ -87,6 +88,7 @@ function RadioGroup({
8788
darkMode,
8889
name,
8990
size,
91+
bold,
9092
});
9193
});
9294

packages/radio-group/src/RadioGroup/RadioGroup.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ export interface RadioGroupProps extends HTMLElementProps<'div'> {
4141
* @default default
4242
*/
4343
size?: Size;
44+
45+
/**
46+
* Whether the label's font-weight is bold or regular.
47+
* If left `undefined` this prop will default to `true` if a description is provided,
48+
* otherwise defaults to `false`
49+
*/
50+
bold?: boolean;
4451
}

0 commit comments

Comments
 (0)