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

Adds Radio and RadioGroup as new web components #27113

Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
7f9af9e
radio init
brianchristopherbrady Mar 3, 2023
70c55e0
styles radio
brianchristopherbrady Mar 3, 2023
f3cb7f4
Merge branch 'microsoft:web-components-v3' into web-components-v3
brianchristopherbrady Mar 3, 2023
a72d10f
reverts branch
brianchristopherbrady Mar 3, 2023
2941fa7
Merge branch 'web-components-v3' of https://github.com/brianchristoph…
brianchristopherbrady Mar 3, 2023
9b350fc
Merge branch 'microsoft:web-components-v3' into web-components-v3
brianchristopherbrady Mar 20, 2023
2cf59ce
input spec init
brianchristopherbrady Mar 20, 2023
79b6bff
cleans up spec
brianchristopherbrady Mar 20, 2023
5558b93
formatting
brianchristopherbrady Mar 20, 2023
3c045c3
updates component name to text input
brianchristopherbrady Mar 20, 2023
2370967
updates component name in spec
brianchristopherbrady Mar 20, 2023
c3d414b
radio init
brianchristopherbrady Mar 3, 2023
f9d2722
styles radio
brianchristopherbrady Mar 3, 2023
9cdce0a
adds radio and radio group to index rollup
brianchristopherbrady Mar 6, 2023
69191b8
merge
brianchristopherbrady Mar 7, 2023
92621d4
cherry-pick
brianchristopherbrady Mar 7, 2023
b819408
fixes arguments passed to slottedRadioButtonsChanged
brianchristopherbrady Mar 7, 2023
9eac6e8
yarn changew
brianchristopherbrady Mar 7, 2023
9948aa4
updates radio group logic
brianchristopherbrady Mar 7, 2023
ee1afd4
cherry-pick
brianchristopherbrady Mar 7, 2023
7fb992d
updates styles
brianchristopherbrady Mar 7, 2023
80de0f1
cherry-pick
brianchristopherbrady Mar 7, 2023
9bed712
merge
brianchristopherbrady Mar 7, 2023
5eb76ea
adds radio group attributes
brianchristopherbrady Mar 7, 2023
6a03c6d
removes console logs
brianchristopherbrady Mar 7, 2023
de938a4
updates styles
brianchristopherbrady Mar 7, 2023
4ee0e0b
updates RadioGroup readme
brianchristopherbrady Mar 7, 2023
48c4d8a
fixes jsdoc
brianchristopherbrady Mar 7, 2023
923a696
updats radio and radio group stories
brianchristopherbrady Mar 7, 2023
22f2a82
formats radio group story markup
brianchristopherbrady Mar 7, 2023
6729fad
removes redundant attribute on RadioGroup story
brianchristopherbrady Mar 7, 2023
88f874f
removes dead code
brianchristopherbrady Mar 8, 2023
62649a1
updates radio styles
brianchristopherbrady Mar 9, 2023
2de1087
updates radio group styles
brianchristopherbrady Mar 9, 2023
40843d7
removes redundant attribute on radio group
brianchristopherbrady Mar 9, 2023
be9d76a
merge
brianchristopherbrady Mar 10, 2023
da17886
styles radio and radio group
brianchristopherbrady Mar 13, 2023
cad6469
removes dead code
brianchristopherbrady Mar 14, 2023
daa81a8
updates css value to token
brianchristopherbrady Mar 15, 2023
af2f4ab
exports RadioGroupOrientation namespaced type
brianchristopherbrady Mar 15, 2023
fea6a0d
updates styles per design review
brianchristopherbrady Mar 15, 2023
7e68029
updates focus styles
brianchristopherbrady Mar 15, 2023
48e4acc
reverts file
brianchristopherbrady Mar 21, 2023
7ef442a
reverts file
brianchristopherbrady Mar 21, 2023
ca1f966
mege
brianchristopherbrady Mar 7, 2023
0e7de1a
adds back story args
brianchristopherbrady Mar 7, 2023
d1cc79d
re exports RadioGroupOrientation from FAST
brianchristopherbrady Mar 22, 2023
58a9094
removes redundant stack attribute
brianchristopherbrady Mar 23, 2023
8057376
testing local tokens for disabled styling
brianchristopherbrady Mar 23, 2023
522147e
radio: updates styles per review
brianchristopherbrady Mar 27, 2023
d132f2e
radio: updates design tokens & styles
brianchristopherbrady Mar 27, 2023
611c3c9
radio: adds storybook content
brianchristopherbrady Mar 27, 2023
9c4eb6b
Merge branch 'microsoft:web-components-v3' into web-components-v3
brianchristopherbrady Mar 27, 2023
267e655
radio init
brianchristopherbrady Mar 3, 2023
3c39bfe
styles radio
brianchristopherbrady Mar 3, 2023
bd3d0c4
radio: merge
brianchristopherbrady Mar 27, 2023
15c2d3a
merge
brianchristopherbrady Mar 7, 2023
f818800
cherry-pick
brianchristopherbrady Mar 7, 2023
0234822
fixes arguments passed to slottedRadioButtonsChanged
brianchristopherbrady Mar 7, 2023
7cb1d5b
yarn changew
brianchristopherbrady Mar 7, 2023
87f36b2
updates radio group logic
brianchristopherbrady Mar 7, 2023
added85
cherry-pick
brianchristopherbrady Mar 7, 2023
3ae6f81
updates styles
brianchristopherbrady Mar 7, 2023
127eb13
cherry-pick
brianchristopherbrady Mar 7, 2023
cd063a2
merge
brianchristopherbrady Mar 7, 2023
c9b9249
adds radio group attributes
brianchristopherbrady Mar 7, 2023
97a5a5e
removes console logs
brianchristopherbrady Mar 7, 2023
86fb9c5
updates styles
brianchristopherbrady Mar 7, 2023
790f1a8
updates RadioGroup readme
brianchristopherbrady Mar 7, 2023
d947e13
fixes jsdoc
brianchristopherbrady Mar 7, 2023
3c0f692
updats radio and radio group stories
brianchristopherbrady Mar 7, 2023
bca6add
formats radio group story markup
brianchristopherbrady Mar 7, 2023
bf7bee3
removes redundant attribute on RadioGroup story
brianchristopherbrady Mar 7, 2023
1230bc0
removes dead code
brianchristopherbrady Mar 8, 2023
19002da
updates radio styles
brianchristopherbrady Mar 9, 2023
f09a49f
updates radio group styles
brianchristopherbrady Mar 9, 2023
e1f6473
removes redundant attribute on radio group
brianchristopherbrady Mar 9, 2023
f273e93
merge
brianchristopherbrady Mar 10, 2023
8c0eae2
styles radio and radio group
brianchristopherbrady Mar 13, 2023
8fd62c0
removes dead code
brianchristopherbrady Mar 14, 2023
6d32614
updates css value to token
brianchristopherbrady Mar 15, 2023
b4646b7
exports RadioGroupOrientation namespaced type
brianchristopherbrady Mar 15, 2023
09d8c95
updates styles per design review
brianchristopherbrady Mar 15, 2023
74bb90a
updates focus styles
brianchristopherbrady Mar 15, 2023
b4fec61
reverts file
brianchristopherbrady Mar 21, 2023
6518c80
reverts file
brianchristopherbrady Mar 21, 2023
1dda4d5
mege
brianchristopherbrady Mar 7, 2023
4495bf7
adds back story args
brianchristopherbrady Mar 7, 2023
831e720
re exports RadioGroupOrientation from FAST
brianchristopherbrady Mar 22, 2023
c058a2e
removes redundant stack attribute
brianchristopherbrady Mar 23, 2023
0f0d7ec
testing local tokens for disabled styling
brianchristopherbrady Mar 23, 2023
9984b79
radio: updates styles per review
brianchristopherbrady Mar 27, 2023
8e9a8bd
radio: updates design tokens & styles
brianchristopherbrady Mar 27, 2023
197010c
radio: adds storybook content
brianchristopherbrady Mar 27, 2023
444f8c3
rebase
brianchristopherbrady Mar 27, 2023
e4601a0
radio: initiates css variables in css
brianchristopherbrady Mar 28, 2023
52901ab
leverage css grid for spacing and remove js application for padding
chrisdholt Mar 28, 2023
b05729e
Merge pull request #1 from chrisdholt/users/chhol/leverage-grid-inste…
brianchristopherbrady Mar 28, 2023
d4ffc45
radio: adds export to root json
brianchristopherbrady Mar 28, 2023
12de504
radio: changes per review
brianchristopherbrady Mar 28, 2023
612877b
radio: removes pointer events from disabled radio item
brianchristopherbrady Mar 28, 2023
664a698
radio: updates styling
brianchristopherbrady Mar 28, 2023
4087145
radio: styles formatting
brianchristopherbrady Mar 28, 2023
e46a081
radio: updates styles
brianchristopherbrady Mar 28, 2023
9f97980
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Mar 28, 2023
2778e3a
Update change/@fluentui-web-components-94ca1c7a-1462-4aa5-9458-41a54f…
brianchristopherbrady Mar 28, 2023
b059373
removes redundant style
brianchristopherbrady Mar 29, 2023
82c2a85
radio: addresses pr feedback
brianchristopherbrady Mar 31, 2023
6921a19
radio: updates disabled styles
brianchristopherbrady Mar 31, 2023
02b9cff
Update packages/web-components/src/radio/radio.stories.ts
brianchristopherbrady Mar 31, 2023
30d7c05
radio: swaps args table value for const
brianchristopherbrady Mar 31, 2023
d89294e
Merge branch 'user/brianbrady/web-component-radio-radio-group' of htt…
brianchristopherbrady Mar 31, 2023
96a50f3
radio: removes duplicate style
brianchristopherbrady Mar 31, 2023
592421e
radio: optimizes styles
brianchristopherbrady Apr 4, 2023
5392798
radio: swaps js for css disabled styling solution
brianchristopherbrady Apr 4, 2023
7619086
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Apr 6, 2023
e865390
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Apr 11, 2023
9a68e6e
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Apr 11, 2023
c1d3458
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Apr 13, 2023
a7b2a11
radiogroup, radio: updates based on feedback
brianchristopherbrady Apr 20, 2023
c7cc45f
radiogroup, radio: updates storybook content and README
brianchristopherbrady Apr 20, 2023
b5c84d8
radiogroup, radio: updates docs
brianchristopherbrady Apr 20, 2023
329bd37
radiogroup, radio: removes label-position from docs
brianchristopherbrady Apr 20, 2023
fae698a
radiogroup, radio: updates docs
brianchristopherbrady Apr 20, 2023
e475e21
Update packages/web-components/src/radio/README.md
brianchristopherbrady Apr 24, 2023
81c5095
radiogroup, radio: addresses feedback
brianchristopherbrady Apr 24, 2023
4d56030
radiogroup, radio: updates docs
brianchristopherbrady Apr 26, 2023
163def9
radiogroup, radio: addresses feedback
brianchristopherbrady Apr 26, 2023
9e554eb
radiogroup, radio: updates styles
brianchristopherbrady Apr 26, 2023
3a45ff2
Merge branch 'web-components-v3' into user/brianbrady/web-component-r…
brianchristopherbrady Apr 27, 2023
8e61ff1
radiogroup, radio: removes whitespace
brianchristopherbrady Apr 27, 2023
01887bf
Merge branch 'user/brianbrady/web-component-radio-radio-group' of htt…
brianchristopherbrady Apr 27, 2023
5423421
radiogroup, radio: updates styles per review
brianchristopherbrady May 2, 2023
42b2a13
radiogroup, radio: formats files
brianchristopherbrady May 4, 2023
596c031
radiogroup, radio: format document
brianchristopherbrady May 4, 2023
9a6705f
radiogroup, radio: fixes import
brianchristopherbrady May 5, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat(radio): add radio and radio-group web components",
"packageName": "@fluentui/web-components",
"email": "brianbrady@microsoft.com",
"dependentChangeType": "patch"
}
8 changes: 8 additions & 0 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
"types": "./dist/esm/progress-bar/define.d.ts",
"default": "./dist/esm/progress-bar/define.js"
},
"./radio": {
"types": "./dist/esm/radio/define.d.ts",
"default": "./dist/esm/radio/define.js"
},
"./radio-group": {
"types": "./dist/esm/radio-group/define.d.ts",
"default": "./dist/esm/radio-group/define.js"
},
"./slider": {
"types": "./dist/esm/slider/define.d.ts",
"default": "./dist/esm/slider/define.js"
Expand Down
2 changes: 2 additions & 0 deletions packages/web-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export * from './menu-button/index.js';
export * from './menu-item/index.js';
export * from './menu-list/index.js';
export * from './progress-bar/index.js';
export * from './radio/index.js';
export * from './radio-group/index.js';
export * from './slider/index.js';
export * from './spinner/index.js';
export * from './switch/index.js';
Expand Down
36 changes: 19 additions & 17 deletions packages/web-components/src/radio-group/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme mentions changed callback. We should document the args passed to the callbacks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also cover them by stories. In a separate work item.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added information to the Events table in the README and created a storybook example in the RadioGroup story. Let me know what you think.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Radio Group

> RadioGroup lets people select a single option from two or more Radio items. Use RadioGroup to present all available choices if there's enough space..
> RadioGroup lets users select a single option from two or more Radio items. Use RadioGroup to present all available choices if there's enough space..

<br />

Expand Down Expand Up @@ -36,13 +36,14 @@ Used anywhere an author might group a list of radio options.

### **Fields**

| Name | Privacy | Type | Default | Description |
| ------------- | ------- | ------------------------ | ------------ | ----------------------------------------------------------------------------------------------------- |
| `disabled` | public | `boolean` | `false` | Disables the radio group and child radios. |
| `name` | public | `string` | | The name of the radio group. Setting this value will set the name value for all child radio elements. |
| `value` | public | `string` | | The value of the checked radio. |
| `orientation` | public | `horizontal \| vertical` | `horizontal` | The orientation of the group |
| default slot | public | `HTMLElement[]` | | The default slot expecting Radio items |
| Name | Privacy | Type | Default | Description |
| ------------- | ------- | ------------------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `disabled` | public | `boolean` | `false` | Disables the radio group and child radios. |
| `name` | public | `string` | | The name of the radio group. Setting this value will set the name value for all child radio elements. |
| `value` | public | `string` | | The value of the checked radio. |
| `orientation` | public | `horizontal \| vertical` | `horizontal` | Determines whether radios in a radio group are rendered in a horizontal row or a vertical column. The default value is horizontal, which will render radios in a horizontal row with labels appearing inline. Setting orientation to vertical will render radios in a vertical column with labels appearing inline. |
| `stacked` | public | `boolean` | `false` | Determines whether the labels for radios appear inline or stacked when orientation is set to horizontal. The default value is false, which will display the labels inline. If stacked is set to true, the labels will appear under each radio in a horizontal row. |
| default slot | public | `HTMLElement[]` | | The default slot expecting Radio items. |

<br />

Expand All @@ -57,9 +58,9 @@ Used anywhere an author might group a list of radio options.

### **Events**

| Name | Type | Description |
| -------- | ---- | ---------------------------------------------------- |
| `change` | | Fires a custom 'change' event when the value changes |
| Name | Event Type | Target | Arguments | Description |
| -------- | ------------- | ---------------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `change` | `CustomEvent` | `FASTRadioGroup` | none | Fired when the value of the RadioGroup changes (i.e., when a different radio button within the group is selected) |

<br />

Expand Down Expand Up @@ -97,9 +98,10 @@ Used anywhere an author might group a list of radio options.

### **WAI-ARIA Roles, States, and Properties**

| Attributes | value | Description |
| ----------------- | ----- | ---------------------------------------- |
| `aria-labelledby` | | used to associate a label with the group |
| Attributes | value | Description |
| ----------------- | -------------- | ---------------------------------------- |
| `aria-labelledby` | | used to associate a label with the group |
| `role` | `"radiogroup"` | used to define a group of radio buttons |

<br />
<hr />
Expand All @@ -122,6 +124,6 @@ Used anywhere an author might group a list of radio options.
<br />

**Property Mapping**
| Fluent UI React 9 | Fluent Web Components 3 | Description of difference |
|-------------------|------------------------ |---------------------------|
| `layout` | `orientation` | React implementation requires user to pass either `"horizontal"` or `"horizontal-stacked"` through `layout` prop. <br /> WC3 implementation requires user to either pass `"vertical"` or "`horizontal"` through `orientation` attribute.
| Fluent UI React 9 | Fluent Web Components | Description of difference |
|-------------------|-------------------------- |---------------------------|
| `layout` | `orientation` + `stacked` | React implementation requires user to pass either `"horizontal"` or `"horizontal-stacked"` through `layout` prop. <br /> WC3 implementation requires user to either pass `"vertical"` or "`horizontal"` through `orientation` attribute. Additionally, adding the `boolean` attribute `stacked` when the orientation is set to `horizontal` will create the `horizontal-stacked` layout available in FUIR9.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand, whats the difference between horizontal-stacked and orientation="vertical"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brianchristopherbrady updated the description. Is that more clear?

4 changes: 4 additions & 0 deletions packages/web-components/src/radio-group/define.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { definition } from './radio-group.definition.js';

definition.define(FluentDesignSystem.registry);
5 changes: 5 additions & 0 deletions packages/web-components/src/radio-group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './radio-group.js';
export { definition as RadioGroupDefinition } from './radio-group.definition.js';
export { styles as RadioGroupStyles } from './radio-group.styles.js';
export { template as RadioGroupTemplate } from './radio-group.template.js';
brianchristopherbrady marked this conversation as resolved.
Show resolved Hide resolved
export { RadioGroupOrientation } from '@microsoft/fast-foundation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { RadioGroup } from './radio-group.js';
import { styles } from './radio-group.styles.js';
import { template } from './radio-group.template.js';

/**
* The Fluent RadioGroup Element.
*
*
* @public
* @remarks
* HTML Element: \<fluent-radio-group\>
*/
export const definition = RadioGroup.compose({
name: `${FluentDesignSystem.prefix}-radio-group`,
template,
styles,
});
213 changes: 213 additions & 0 deletions packages/web-components/src/radio-group/radio-group.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
import { html } from '@microsoft/fast-element';
import type { Args, Meta } from '@storybook/html';
import { RadioGroupOrientation } from '@microsoft/fast-foundation';
import { renderComponent } from '../helpers.stories.js';
import { RadioGroup as FluentRadioGroup } from './radio-group.js';
import './define.js';
import '../radio/define.js';

type RadioGroupStoryArgs = Args & FluentRadioGroup;
type RadioGroupStoryMeta = Meta<RadioGroupStoryArgs>;

const storyTemplate = html<RadioGroupStoryArgs>`
<fluent-radio-group
aria-labelledby="label-1"
?disabled=${x => x.disabled}
?stacked=${x => x.stacked}
orientation=${x => x.orientation}
name="radio-story"
>
<span id="label-1" slot="label">Favorite Fruit</span>
<fluent-radio ?checked="${x => x.checked}" value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`;

export default {
title: 'Components/RadioGroup',
args: {
disabled: false,
orientation: RadioGroupOrientation.horizontal,
},
argTypes: {
disabled: {
control: {
type: 'boolean',
},
table: {
type: {
summary: 'Sets disabled state on radio',
},
defaultValue: {
summary: 'false',
},
},
},
checked: {
control: {
type: 'boolean',
},
table: {
type: {
summary: 'Sets checked state on radio',
},
defaultValue: {
summary: 'false',
},
},
},
stacked: {
control: {
type: 'boolean',
},
table: {
type: {
summary: 'Creates a stacked layout for horizontal radio buttons',
},
defaultValue: {
summary: 'false',
},
},
},
orientation: {
control: {
type: 'select',
options: Object.values(RadioGroupOrientation),
},
defaultValue: RadioGroupOrientation.horizontal,
table: {
type: {
summary: 'Sets orientation of radio group',
},
defaultValue: {
summary: RadioGroupOrientation.horizontal,
},
},
},
change: {
action: 'change',
table: {
type: {
summary: 'Event that is fired when the selected radio button changes',
},
defaultValue: {
summary: null,
},
},
},
},
} as RadioGroupStoryMeta;

export const RadioGroup = renderComponent(storyTemplate).bind({});

export const RadioGroupLabelledby = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group aria-labelledby="label-2" name="radio-story">
<span id="label-2" slot="label">Favorite Fruit</span>
<fluent-radio value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupLayoutVertical = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group aria-labelledby="label-3" orientation="vertical" name="radio-story">
<span id="label-3" slot="label">Favorite Fruit</span>
<fluent-radio value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupLayoutHorizontal = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group aria-labelledby="label-4" orientation="horizontal" name="radio-story">
<span id="label-4" slot="label">Favorite Fruit</span>
<fluent-radio value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupLayoutHorizontalStacked = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group stacked aria-labelledby="label-5" orientation="horizontal" name="radio-story">
<span id="label-5" slot="label">Favorite Fruit</span>
<fluent-radio value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupDefaultChecked = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group aria-labelledby="label-6" orientation="horizontal" name="radio-story">
<span id="label-6" slot="label">Favorite Fruit</span>
<fluent-radio value="apple">Apple</fluent-radio>
<fluent-radio checked value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupDisabled = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group disabled aria-labelledby="label-7" name="radio-story">
<span id="label-7" slot="label">Favorite Fruit</span>
<fluent-radio checked value="apple">Apple</fluent-radio>
<fluent-radio checked value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

export const RadioGroupDisabledItem = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group aria-labelledby="label-8" name="radio-story">
<span id="label-8" slot="label">Favorite Fruit</span>
<fluent-radio id="baby" checked value="apple">Apple</fluent-radio>
<fluent-radio disabled value="pear">Pear</fluent-radio>
<fluent-radio value="banana">Banana</fluent-radio>
<fluent-radio value="orange">Orange</fluent-radio>
</fluent-radio-group>
`);

const getLabelContent = (): string | undefined => {
const radioGroup = document.querySelector('#radio-group-fruit') as FluentRadioGroup;

if (!radioGroup) return; // add a check to make sure radioGroup exists
const selectedRadio = radioGroup.value as string;
if (selectedRadio) {
return `Favorite fruit: ${selectedRadio.charAt(0).toUpperCase() + selectedRadio.slice(1)}`;
} else {
return 'Please select your favorite fruit';
}
};

const handleChange = (event: CustomEvent) => {
const radioGroup = document.querySelector('#radio-group-fruit') as FluentRadioGroup;

if (!radioGroup) return; // add a check to make sure radioGroup exists

const selectedRadio = radioGroup.value as string;
const labelElement = radioGroup.querySelector('[slot="label"]') as HTMLSpanElement;
if (selectedRadio) {
const labelContent = selectedRadio.charAt(0).toUpperCase() + selectedRadio.slice(1);
labelElement.textContent = `Favorite fruit: ${labelContent}`;
}
};

export const RadioGroupChangeEvent = renderComponent(html<RadioGroupStoryArgs>`
<fluent-radio-group
id="radio-group-fruit"
aria-labelledby="label-8"
name="radio-story"
@change="${(event: CustomEvent) => handleChange(event)}"
>
<span id="label-8" slot="label">${getLabelContent}</span>
<fluent-radio checked value="apple">Apple</fluent-radio>
<fluent-radio value="pear">Pear</fluent-radio>
<fluent-radio value="Banana">Banana</fluent-radio>
<fluent-radio value="Orange">Orange</fluent-radio>
</fluent-radio-group>
`);
Loading