Skip to content

Commit

Permalink
Revert RadioGroup changes, in favor of #151
Browse files Browse the repository at this point in the history
  • Loading branch information
nighto committed Feb 17, 2025
1 parent 9622b97 commit b50e445
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 56 deletions.
25 changes: 8 additions & 17 deletions src/components/forms/fields/RadioGroup/RadioGroup.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@
@layer baklava.components {
.bk-radio-group {
@include bk.component-base(bk-radio-group);
// unfortunately `<fieldset>` can't be display:flex, it would ignore a gap, that's why the legend has a margin-bottom.
display: flex;

.bk-radio-group__legend {
@include bk.font(bk.$font-family-body, bk.$font-weight-semibold, bk.$font-size-m);
margin-block-end: bk.$spacing-3;
&.bk-radio-group--vertical {
flex-direction: column;
row-gap: 20px;
}

.bk-radio-group__control {
display: flex;

&.bk-radio-group__control--vertical {
flex-direction: column;
row-gap: 20px;
}

&.bk-radio-group__control--horizontal {
flex-direction: row;
column-gap: bk.$spacing-7;
}

&.bk-radio-group--horizontal {
flex-direction: row;
column-gap: bk.$spacing-7;
}
}
}
13 changes: 0 additions & 13 deletions src/components/forms/fields/RadioGroup/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,3 @@ export const RadioGroupHorizontal: Story = {
direction: 'horizontal',
},
};

export const RadioGroupVerticalWithLegend: Story = {
args: {
legend: 'Legend',
},
};

export const RadioGroupHorizontalWithLegend: Story = {
args: {
direction: 'horizontal',
legend: 'Legend',
},
};
34 changes: 9 additions & 25 deletions src/components/forms/fields/RadioGroup/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { classNames as cx, type ComponentProps } from '../../../../util/componentUtil.ts';
import { classNames as cx } from '../../../../util/componentUtil.ts';
import * as React from 'react';

import cl from './RadioGroup.module.scss';
Expand All @@ -13,39 +13,23 @@ import { RadioField } from '../RadioField/RadioField.tsx';
export { cl as RadioGroupClassNames };

export type RadioGroupProps = React.PropsWithChildren<{
/** Direction of the radio elements, defaults as vertical. */
direction?: undefined | "vertical" | "horizontal",

/** Legend for the group of radio buttons. */
legend?: undefined | React.ReactNode,

/** Props for the `<legend>` element, if `legend` is defined. */
legendProps?: undefined | ComponentProps<'legend'>,
}>;

/**
* Radio group component, wrapping multiple RadioField components vertically or horizontally.
*/
export const RadioGroup = Object.assign(
(props: RadioGroupProps) => {
const { children, legend, direction = 'vertical', legendProps = {} } = props;
const { children, direction = 'vertical' } = props;
return (
<div className={cx('bk', cl['bk-radio-group'])}>
{legend &&
<legend
{...legendProps}
className={cx(cl['bk-radio-group__legend'], legendProps.className)}
>
{legend}
</legend>
}
<div className={cx(
cl['bk-radio-group__control'],
{ [cl['bk-radio-group__control--horizontal']]: direction === 'horizontal' },
{ [cl['bk-radio-group__control--vertical']]: direction === 'vertical' },
)}>
{children}
</div>
<div className={cx(
'bk',
cl['bk-radio-group'],
{ [cl['bk-radio-group--horizontal']]: direction === 'horizontal' },
{ [cl['bk-radio-group--vertical']]: direction === 'vertical' },
)}>
{children}
</div>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const DialogModalControlledPattern1 = (props: React.ComponentProps<typeof Dialog
<p>
<Form>
<FormLayout>
<RadioGroup direction="horizontal" legend="Label">
<RadioGroup direction="horizontal">
{radioOptions.map(radioOption =>
<RadioGroup.RadioField
key={radioOption}
Expand Down

0 comments on commit b50e445

Please sign in to comment.