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

chore(fuselage): Button size #1144

Merged
merged 10 commits into from
Aug 28, 2023
4 changes: 4 additions & 0 deletions packages/fuselage/.jest/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { toHaveNoViolations } from 'jest-axe';

const cssInJsClassRegex = /^rcx-css-[a-z0-9]+$/;

expect.extend({
Expand Down Expand Up @@ -28,3 +30,5 @@ expect.extend({
};
},
});

expect.extend(toHaveNoViolations);
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './Accordion.stories';

const { Default } = composeStories(stories);
expect.extend(toHaveNoViolations);

describe('[Accordion Component]', () => {
it('renders without crashing', () => {
Expand Down
38 changes: 38 additions & 0 deletions packages/fuselage/src/components/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './Button.stories';
import * as iconButtonStories from './IconButton.stories';

const { Default, AsIconButton } = composeStories(stories);
const { _IconButton, _IconButtonInfo, _IconButtonSuccess } =
composeStories(iconButtonStories);

describe('[Button Component]', () => {
it('renders Button without crashing', () => {
Expand All @@ -14,4 +18,38 @@ describe('[Button Component]', () => {
it('renders ActionButton without crashing', () => {
render(<AsIconButton />);
});

it('should have no a11y violations', async () => {
const { container } = render(<Default />);

const results = await axe(container);
expect(results).toHaveNoViolations();
});
});

describe('[IconButton Component]', () => {
it('renders IconButton without crashing', () => {
render(<AsIconButton />);
});

it('IconButton default should have no a11y violations', async () => {
const { container } = render(<_IconButton />);

const results = await axe(container);
expect(results).toHaveNoViolations();
});

it('IconButtonInfo should have no a11y violations', async () => {
const { container } = render(<_IconButtonInfo />);

const results = await axe(container);
expect(results).toHaveNoViolations();
});

it('IconButtonSuccess should have no a11y violations', async () => {
const { container } = render(<_IconButtonSuccess />);

const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
51 changes: 15 additions & 36 deletions packages/fuselage/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import type { ComponentStory, ComponentMeta } from '@storybook/react';
import React from 'react';

import { Button, ButtonGroup, Icon, IconButton, Margins } from '../..';
import { Button, ButtonGroup, IconButton, Margins } from '../..';
import { PropsVariationSection } from '../../../.storybook/helpers';

export default {
Expand Down Expand Up @@ -40,12 +40,6 @@ export const Default: ComponentStory<typeof Button> = () => (
<Button onClick={action('click')}>Button</Button>
);

export const Square: ComponentStory<typeof Button> = () => (
<Button square>
<Icon name='plus' size='x20' />
</Button>
);

export const Variants: ComponentStory<typeof Button> = () => (
<Margins all='x8'>
<ButtonGroup>
Expand Down Expand Up @@ -74,27 +68,11 @@ export const Variants: ComponentStory<typeof Button> = () => (
);

export const Sizes: ComponentStory<typeof ButtonGroup> = () => (
<>
<ButtonGroup marginBlockEnd={12}>
<Button small>Small</Button>
<Button medium>Medium</Button>
<Button>Default</Button>
</ButtonGroup>
<ButtonGroup>
<Button mini square>
<Icon name='circled-arrow-down' size='x16' />
</Button>
<Button tiny square>
<Icon name='circled-arrow-down' size='x20' />
</Button>
<Button small square>
<Icon name='circled-arrow-down' size='x24' />
</Button>
<Button square>
<Icon name='circled-arrow-down' size='x32' />
</Button>
</ButtonGroup>
</>
<ButtonGroup marginBlockEnd={12}>
<Button small>Small</Button>
<Button medium>Medium</Button>
<Button>Default</Button>
</ButtonGroup>
);

export const AsLink: ComponentStory<typeof Button> = () => (
Expand All @@ -116,10 +94,6 @@ export const States = () => (
disabled: { disabled: true },
}}
yAxis={{
'square + icon': {
square: true,
children: <Icon name='circled-arrow-down' size='x20' />,
},
'icon + text': {
children: 'Button',
icon: 'baloon-text',
Expand Down Expand Up @@ -178,10 +152,6 @@ export const States = () => (
disabled: { disabled: true },
}}
yAxis={{
'square + icon': {
square: true,
children: <Icon name='circled-arrow-down' size='x20' />,
},
'icon + text': {
children: 'Button',
icon: 'baloon-text',
Expand Down Expand Up @@ -232,3 +202,12 @@ export const States = () => (
export const AsIconButton: ComponentStory<typeof IconButton> = (args) => (
<IconButton {...args} icon='arrow-back' onClick={action('click')} />
);

AsIconButton.parameters = {
docs: {
description: {
story:
'See full IconButton documentation [here](../?path=/docs/inputs-iconbutton)',
},
},
};
1 change: 1 addition & 0 deletions packages/fuselage/src/components/Button/Button.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.rcx-button {
@mixin with-rectangular-size($height, $padding-x, $line-height) {
min-width: calc(lengths.size($height) * 2);
height: lengths.size($height);
padding: calc((lengths.padding($height) - $line-height) / 2 - 2px)
calc(lengths.padding($padding-x) - 2px);
padding-block: calc((lengths.padding($height) - $line-height) / 2 - 2px);
Expand Down
9 changes: 6 additions & 3 deletions packages/fuselage/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentProps, Ref } from 'react';
import type { AllHTMLAttributes, ComponentProps, Ref } from 'react';
import React, { forwardRef, useMemo } from 'react';

import Box from '../Box';
Expand All @@ -19,7 +19,10 @@ export type ButtonProps = ComponentProps<typeof Box> & {
square?: boolean;
external?: boolean;
icon?: ComponentProps<typeof Icon>['name'];
};
} & Omit<
AllHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>,
'is' | 'className' | 'size'
>;

export const Button = forwardRef(function Button(
{
Expand All @@ -41,7 +44,7 @@ export const Button = forwardRef(function Button(
children,
...props
}: ButtonProps,
ref: Ref<HTMLElement>
ref: Ref<HTMLButtonElement | HTMLAnchorElement>
) {
const extraProps =
(is === 'a' && {
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage/src/components/Button/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const IconButton = forwardRef(
{...getSizeClass()}
rcx-button--icon-pressed={pressed}
ref={ref}
aria-label={props['aria-label'] || icon}
{...props}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './ButtonGroup.stories';
Expand All @@ -10,4 +11,11 @@ describe('[ButtonGroup Component]', () => {
it('renders without crashing', () => {
render(<Default />);
});

it('should have no a11y violations', async () => {
const { container } = render(<Default />);

const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
4 changes: 1 addition & 3 deletions packages/fuselage/src/components/CheckBox/CheckBox.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { composeStories } from '@storybook/testing-react';
import { fireEvent, getByRole, render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './CheckBox.stories';

const { Default, Indeterminate, Disabled, DefaultChecked } =
composeStories(stories);

expect.extend(toHaveNoViolations);

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
Expand Down
4 changes: 1 addition & 3 deletions packages/fuselage/src/components/Field/Field.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './Field.stories';

expect.extend(toHaveNoViolations);

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
Expand Down
4 changes: 1 addition & 3 deletions packages/fuselage/src/components/Label/Label.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import * as stories from './Label.stories';

expect.extend(toHaveNoViolations);

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
Expand Down
3 changes: 1 addition & 2 deletions packages/fuselage/src/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import { Table, TableRow, TableHead, TableBody, TableCell, TableFoot } from '.';
import * as stories from './Table.stories';

const { Default, Selected } = composeStories(stories);
expect.extend(toHaveNoViolations);

describe('[Table Component]', () => {
it('renders Table without crashing', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/fuselage/src/components/ToastBar/ToastBar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { axe } from 'jest-axe';
import React from 'react';

import { ToastBar } from '.';

expect.extend(toHaveNoViolations);

describe('[ToastBar Component]', () => {
it('renders without crashing', () => {
render(<ToastBar />);
Expand Down
Loading