Skip to content

Commit

Permalink
fix(fuselage): className prop drilling improvements on CheckBox, `T…
Browse files Browse the repository at this point in the history
…oggleSwitch` and `RadioButton` (#1178)

Co-authored-by: Douglas Fabris <[email protected]>
  • Loading branch information
juliajforesti and dougfabris authored Sep 22, 2023
1 parent dfe3676 commit 0a104a0
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 90 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-deers-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": patch
---

fix(fuselage): className prop drilling improvements on `CheckBox`, `ToggleSwitch` and `RadioButton`
2 changes: 1 addition & 1 deletion packages/fuselage/.storybook/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function PropsVariationSection<TComponent extends ComponentType<any>>({
>
<Box is='thead'>
<Box is='tr'>
<Box is='th' />
<Box is='td' aria-hidden />
{Object.keys(xAxis).map((xVariation, key) => (
<Box key={key} is='th' color='hint' fontScale='c1'>
{xVariation}
Expand Down
41 changes: 28 additions & 13 deletions packages/fuselage/src/components/CheckBox/CheckBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ import { action } from '@storybook/addon-actions';
import type { ComponentStory, ComponentMeta } from '@storybook/react';
import React from 'react';

import { CheckBox, Label } from '../..';
import { DECORATOR_ID, DECORATOR_LABEL } from '../../../.storybook/helpers';
import { CheckBox } from '../..';
import {
DECORATOR_LABEL,
PropsVariationSection,
} from '../../../.storybook/helpers';

export default {
title: 'Inputs/CheckBox',
component: CheckBox,
decorators: [
(Story) => (
<>
<Story />
<Label mis='x4' htmlFor={DECORATOR_ID}>
{DECORATOR_LABEL}
</Label>
</>
),
],
} as ComponentMeta<typeof CheckBox>;

const Template: ComponentStory<typeof CheckBox> = (args) => (
<CheckBox {...args} id={DECORATOR_ID} onChange={action('change')} />
<CheckBox
{...args}
aria-label={DECORATOR_LABEL}
onChange={action('change')}
/>
);

export const Default = Template.bind({});
Expand All @@ -44,3 +41,21 @@ export const DefaultChecked = Template.bind({});
DefaultChecked.args = {
defaultChecked: true,
};

export const States: ComponentStory<typeof CheckBox> = () => (
<PropsVariationSection
component={CheckBox}
common={{ 'onChange': action('change'), 'aria-label': DECORATOR_LABEL }}
xAxis={{
checked: { checked: true },
unchecked: { checked: false },
}}
yAxis={{
default: {},
hover: { className: 'is-hovered' },
active: { className: 'is-active' },
focus: { className: 'is-focused' },
disabled: { disabled: true },
}}
/>
);
4 changes: 2 additions & 2 deletions packages/fuselage/src/components/CheckBox/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CheckBoxProps = ComponentProps<typeof Box> & {
} & AllHTMLAttributes<HTMLInputElement>;

export const CheckBox = forwardRef(function CheckBox(
{ indeterminate, onChange, ...props }: CheckBoxProps,
{ indeterminate, onChange, className, ...props }: CheckBoxProps,
ref: Ref<HTMLInputElement>
) {
const innerRef = useRef<HTMLInputElement>(null);
Expand All @@ -33,7 +33,7 @@ export const CheckBox = forwardRef(function CheckBox(
);

return (
<Box is={Label} rcx-check-box>
<Box is={Label} className={className} rcx-check-box>
<Box
is='input'
type='checkbox'
Expand Down
Loading

0 comments on commit 0a104a0

Please sign in to comment.