Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioGroup: Add flexible width to legend element to fill available space #2405

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-rocks-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-form": patch
---

Adds `width: 100%` to `legend` element to allow expanding it to fill the available space
34 changes: 33 additions & 1 deletion __docs__/wonder-blocks-form/radio-group.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as React from "react";
import {StyleSheet} from "aphrodite";
import type {Meta, StoryObj} from "@storybook/react";

import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
import {View} from "@khanacademy/wonder-blocks-core";
import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens";
import {LabelLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography";

import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
import packageConfig from "../../packages/wonder-blocks-form/package.json";
Expand Down Expand Up @@ -226,6 +228,36 @@ FiltersOutFalsyChildren.parameters = {
},
};

/**
* There are specific situations where you might want to use a custom label
* component instead of using the default `LabelMedium` component. This example
* demonstrates how to use a custom label component that can be passed in as a
* prop to the `RadioGroup` component.
*/
export const CustomLabel: StoryComponentType = {
...Default,
args: {
style: {
// Adding an arbitrary width to the radio group to demonstrate how
// the custom label component expands to fill the available space.
width: 400,
},
label: (
<View
style={{
border: `1px dashed ${semanticColor.border.strong}`,
padding: spacing.medium_16,
flexDirection: "row",
justifyContent: "space-between",
}}
>
<LabelLarge>Pokemon</LabelLarge>
<LabelMedium>(optional)</LabelMedium>
</View>
),
},
};

const styles = StyleSheet.create({
choice: {
margin: 0,
Expand Down
2 changes: 2 additions & 0 deletions packages/wonder-blocks-form/src/components/group-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const styles: StyleDeclaration = StyleSheet.create({

legend: {
padding: 0,
// Let the legend use the size defined by the parent.
width: "100%",
},

description: {
Expand Down
Loading