Skip to content

Commit

Permalink
feat(radiotile): update to use radio button icon (#15786)
Browse files Browse the repository at this point in the history
* feat(radiotile): update to use radio button icon

* feat(radiotile): place radio button icon behind feature flag

* chore: revert changes to tile story

* test(radiotile): verify unselected radio  without 'defaultSelected'

* chore: tilegroup jest test description

---------

Co-authored-by: Taylor Jones <[email protected]>
Co-authored-by: Andrea N. Cardona <[email protected]>
  • Loading branch information
3 people authored Mar 1, 2024
1 parent 8305c53 commit ef9501b
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/feature-flags/feature-flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ feature-flags:
description: >
Enable rendering of default icons in the tile components
enabled: false
- name: enable-v12-tile-radio-icons
description: >
Enable rendering of radio icons in the RadioTile component
enabled: false
- name: enable-v12-overflowmenu
description: >
Enable the use of the v12 OverflowMenu leveraging the Menu subcomponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ components with all feature flags turned on.
| `enable-experimental-tile-contrast` | Enable the improved styling for tiles that provides better contrast | `false` | ||
| `enable-v12-tile-default-icons` | Enable default icons for Tile components | `false` || |
| `enable-v12-overflowmenu` | Enable the use of the v12 OverflowMenu leveraging the Menu subcomponents | `false` || |
| `enable-v12-tile-radio-icons` | Enable rendering of default icons in the tile components | `false` |||
| `enable-treeview-controllable` | Enable the new TreeView controllable API | `false` || |


## Turning on feature flags in Javascript/react

Use the FeatureFlag component to turn on a feature flag for a portion of your
Expand Down
23 changes: 19 additions & 4 deletions packages/react/src/components/RadioTile/RadioTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import { CheckmarkFilled } from '@carbon/icons-react';
import {
RadioButtonChecked,
RadioButton,
CheckmarkFilled,
} from '@carbon/icons-react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
Expand All @@ -15,6 +19,7 @@ import { usePrefix } from '../../internal/usePrefix';
import deprecate from '../../prop-types/deprecate';
import { noopFn } from '../../internal/noopFn';
import { Text } from '../Text';
import { useFeatureFlag } from '../FeatureFlags';

const RadioTile = React.forwardRef(function RadioTile(
{
Expand Down Expand Up @@ -45,6 +50,18 @@ const RadioTile = React.forwardRef(function RadioTile(
[`${prefix}--tile--disabled`]: disabled,
}
);
const v12TileRadioIcons = useFeatureFlag('enable-v12-tile-radio-icons');
function icon() {
if (v12TileRadioIcons) {
if (checked) {
return <RadioButtonChecked />;
} else {
return <RadioButton />;
}
} else {
return <CheckmarkFilled />;
}
}

function handleOnChange(evt) {
onChange(value, name, evt);
Expand Down Expand Up @@ -73,9 +90,7 @@ const RadioTile = React.forwardRef(function RadioTile(
ref={ref}
/>
<label {...rest} htmlFor={inputId} className={className}>
<span className={`${prefix}--tile__checkmark`}>
<CheckmarkFilled />
</span>
<span className={`${prefix}--tile__checkmark`}>{icon()}</span>
<Text className={`${prefix}--tile-content`}>{children}</Text>
</label>
</div>
Expand Down
18 changes: 8 additions & 10 deletions packages/react/src/components/Tile/Tile.featureflag.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,22 @@ MultiSelect.argTypes = {
export const Radio = (args) => {
return (
<div className={experimentalClassname}>
<TileGroup
defaultSelected="default-selected"
legend="Radio Tile Group"
name="radio tile group">
<TileGroup legend="Radio Tile Group" name="radio tile group">
<RadioTile
id="radio-tile-1"
value="standard"
value="radio-tile-1"
style={{ marginBottom: '.5rem' }}
{...args}>
Option 1
</RadioTile>
<RadioTile
id="radio-tile-2"
value="default-selected"
value="radio-tile-2"
style={{ marginBottom: '.5rem' }}
{...args}>
Option 2
</RadioTile>
<RadioTile id="radio-tile-3" value="selected" {...args}>
<RadioTile id="radio-tile-3" value="radio-tile-3" {...args} disabled>
Option 3
</RadioTile>
</TileGroup>
Expand All @@ -199,16 +196,17 @@ export const RadioWithLayer = () => {
{(layer) => (
<div className={experimentalClassname}>
<TileGroup
defaultSelected="default-selected"
legend="Radio Tile Group"
name={`radio-tile-group-${layer}`}>
<RadioTile
id={`radio-tile-${layer}-1`}
value="standard"
value={`radio-tile-${layer}-1`}
style={{ marginBottom: '.5rem' }}>
Option 1
</RadioTile>
<RadioTile id={`radio-tile-${layer}-2`} value="default-selected">
<RadioTile
id={`radio-tile-${layer}-2`}
value={`radio-tile-${layer}-2`}>
Option 2
</RadioTile>
</TileGroup>
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/components/Tile/tile-story.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
@use '@carbon/react/scss/type';

.experimental-tile {
@include tile.tile($enable-experimental-tile-contrast: true);
@include tile.tile(
$enable-experimental-tile-contrast: true,
$enable-v12-tile-radio-icons: true
);
}

div .cds--tile--selectable:not(:last-child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TileGroup from '../TileGroup';
import RadioTile from '../../RadioTile/RadioTile';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { FeatureFlags } from '../../FeatureFlags';

describe('PasswordInput', () => {
describe('renders as expected - Component API', () => {
Expand Down Expand Up @@ -120,6 +121,39 @@ describe('PasswordInput', () => {
);
});

//Feature flag : enable-v12-tile-radio-icons
it('should keep radio unselected if no `defaultSelected` is provided', () => {
render(
<FeatureFlags
flags={{
'enable-v12-tile-radio-icons': true,
}}>
<TileGroup legend="TestGroup" name="test">
<RadioTile id="test-1" value="test-1">
Option 1
</RadioTile>
<RadioTile id="test-2" value="test-2">
Option 2
</RadioTile>
</TileGroup>
</FeatureFlags>
);

expect(screen.getByDisplayValue('test-1')).toEqual(
screen.getByRole('radio', {
checked: false,
name: 'Option 1',
})
);

expect(screen.getByDisplayValue('test-2')).toEqual(
screen.getByRole('radio', {
checked: false,
name: 'Option 2',
})
);
});

it('should support `valueSelected` as a way to select a radio button', () => {
const { rerender } = render(
<TileGroup
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ FeatureFlags.merge({
'enable-css-grid': true,
'enable-v11-release': true,
'enable-experimental-tile-contrast': false,
'enable-v12-tile-radio-icons': false,
});
1 change: 1 addition & 0 deletions packages/styles/scss/_feature-flags.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'enable-css-grid': true,
'enable-v11-release': true,
'enable-experimental-tile-contrast': false,
'enable-v12-tile-radio-icons': false,
)
!default
);
15 changes: 13 additions & 2 deletions packages/styles/scss/components/tile/_tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ $-icon-container-size: calc(#{layout.density('padding-inline')} * 2 + 1rem);
/// Tile styles
/// @access public
/// @group tile
@mixin tile($enable-experimental-tile-contrast: false) {
@mixin tile(
$enable-experimental-tile-contrast: false,
$enable-v12-tile-radio-icons: false
) {
.#{$prefix}--tile-group {
@include reset;
}
Expand Down Expand Up @@ -163,9 +166,17 @@ $-icon-container-size: calc(#{layout.density('padding-inline')} * 2 + 1rem);
block-size: 1rem;
inset-block-start: layout.density('padding-inline');
inset-inline-end: layout.density('padding-inline');
opacity: 0;
transition: $duration-fast-02 motion(standard, productive);

@if (
enabled('enable-v12-tile-radio-icons') or
$enable-experimental-tile-contrast
) {
opacity: 1;
} @else {
opacity: 0;
}

svg {
border-radius: 50%;
fill: $icon-secondary;
Expand Down

0 comments on commit ef9501b

Please sign in to comment.