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

feat(fuselage): new InputBox small variant #1377

Merged
merged 5 commits into from
May 10, 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/early-eels-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": minor
---

feat(fuselage): new `InputBox` small variant
11 changes: 10 additions & 1 deletion packages/fuselage/src/components/EmailInput/EmailInput.spec.tsx
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 './EmailInput.stories';
Expand All @@ -8,6 +9,14 @@ const { Default } = composeStories(stories);

describe('[EmailInput Component]', () => {
it('renders without crashing', () => {
render(<Default />);
const tree = render(<Default />);
expect(tree.baseElement).toMatchSnapshot();
});

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

const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
78 changes: 52 additions & 26 deletions packages/fuselage/src/components/EmailInput/EmailInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export default {
} as ComponentMeta<typeof EmailInput>;

const Template: ComponentStory<typeof EmailInput> = (args) => (
<EmailInput {...args} />
<EmailInput aria-label='email' {...args} />
);

export const Default: ComponentStory<typeof EmailInput> = Template.bind({});

export const WithIconAddon: ComponentStory<typeof EmailInput> = () => (
<EmailInput addon={<Icon name='send' size='x20' />} />
<EmailInput aria-label='email' addon={<Icon name='send' size='x20' />} />
);

export const Invalid: ComponentStory<typeof EmailInput> = Template.bind({});
Expand All @@ -59,28 +59,54 @@ WithValue.args = {
};

export const States: ComponentStory<typeof EmailInput> = () => (
<PropsVariationSection
component={EmailInput}
common={{ onChange: () => {} }}
xAxis={{
'default': {},
'with placeholder': { placeholder: 'Placeholder' },
'with value': { value: '[email protected]' },
'with icon': {
addon: <Icon name='at' size='x20' />,
value: '[email protected]',
},
}}
yAxis={{
'default': {},
'hover': { className: 'hover' },
'active': { className: 'active' },
'focus': { className: 'focus' },
'disabled': { disabled: true },
'errored': { error: 'Error' },
'errored + hover': { className: 'hover', error: 'Error' },
'errored + active': { className: 'active', error: 'Error' },
'errored + focus': { className: 'focus', error: 'Error' },
}}
/>
<>
<PropsVariationSection
component={EmailInput}
common={{ 'onChange': () => {}, 'aria-label': 'email' }}
xAxis={{
'default': {},
'with placeholder': { placeholder: 'Placeholder' },
'with value': { value: '[email protected]' },
'with icon': {
addon: <Icon name='at' size='x20' />,
value: '[email protected]',
},
}}
yAxis={{
'default': {},
'hover': { className: 'hover' },
'active': { className: 'active' },
'focus': { className: 'focus' },
'disabled': { disabled: true },
'errored': { error: 'Error' },
'errored + hover': { className: 'hover', error: 'Error' },
'errored + active': { className: 'active', error: 'Error' },
'errored + focus': { className: 'focus', error: 'Error' },
}}
/>
<PropsVariationSection
component={EmailInput}
common={{ 'onChange': () => {}, 'small': true, 'aria-label': 'email' }}
xAxis={{
'small': {},
'with placeholder': { placeholder: 'Placeholder' },
'with value': { value: '[email protected]' },
'with icon': {
addon: <Icon name='at' size='x20' />,
value: '[email protected]',
},
}}
yAxis={{
'small': {},
'hover': { className: 'hover' },
'active': { className: 'active' },
'focus': { className: 'focus' },
'disabled': { disabled: true },
'errored': { error: 'Error' },
'errored + hover': { className: 'hover', error: 'Error' },
'errored + active': { className: 'active', error: 'Error' },
'errored + focus': { className: 'focus', error: 'Error' },
}}
/>
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`[EmailInput Component] renders without crashing 1`] = `
<body>
<div>
<input
aria-label="email"
class="rcx-box rcx-box--full rcx-box--animated rcx-input-box--type-email rcx-input-box"
size="1"
type="email"
/>
</div>
</body>
`;
18 changes: 13 additions & 5 deletions packages/fuselage/src/components/InputBox/InputBox.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import { InputBox } from '.';
import * as stories from './InputBox.stories';

const { Default } = composeStories(stories);

describe('[InputBox Component]', () => {
it('renders InputBox without crashing', () => {
render(<InputBox type='text' />);
it('renders without crashing', () => {
const tree = render(<Default />);
expect(tree.baseElement).toMatchSnapshot();
});

it('renders InputBox.Skeleton without crashing', () => {
render(<InputBox.Skeleton />);
it('%s should have no a11y violations', async () => {
const { container } = render(<Default />);

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

import { Icon, InputBox } from '../..';
import { Icon, InputBox, Box } from '../..';

export default {
title: 'Inputs/InputBox',
Expand All @@ -34,7 +34,7 @@ export default {
} as ComponentMeta<typeof Icon>;

const Template: ComponentStory<typeof InputBox> = (args) => (
<InputBox {...args} />
<InputBox aria-label='Value' {...args} />
);

export const Default: ComponentStory<typeof InputBox> = Template.bind({});
Expand Down Expand Up @@ -87,3 +87,26 @@ export const Skeleton: ComponentStory<typeof InputBox> = () => (
<InputBox.Skeleton />
);
Skeleton.storyName = 'InputBox.Skeleton';

export const SmallVariants: ComponentStory<typeof InputBox> = () => (
<Box
display='flex'
flexDirection='column'
alignItems='flex-start'
style={{ gap: '8px' }}
>
<InputBox type='text' small placeholder='Name' aria-label='Name' />
<InputBox
type='text'
small
placeholder='Search'
addon={<Icon name='magnifier' size='x20' />}
aria-label='Search'
/>
</Box>
);
SmallVariants.args = {
placeholder: 'Search',
small: true,
onChange: action('change'),
};
29 changes: 29 additions & 0 deletions packages/fuselage/src/components/InputBox/InputBox.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@
}
}

&__wrapper:has(.rcx-input-box--small) {
align-items: center;

min-width: lengths.size(112);
max-height: lengths.size(28);
padding: lengths.padding(4) lengths.padding(16);
}

&--small {
@include typography.use-font-scale(c1);

&:not(.rcx-input-box--undecorated) {
@extend %input;
min-width: lengths.size(112);

min-height: lengths.size(28);
padding: lengths.padding(4) lengths.padding(16);

&:invalid,
&.invalid {
@extend %input--invalid;
}
}
}

@include with-colors(
$color: $input-colors-color,
$placeholder-color: $input-colors-placeholder-color,
Expand Down Expand Up @@ -241,6 +266,10 @@
.rcx-input-box__wrapper > & {
width: lengths.size(none);
min-width: lengths.size(none);

&--small {
padding: lengths.padding(none);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/fuselage/src/components/InputBox/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type InputBoxProps = ComponentProps<typeof Box> & {
error?: string;
placeholder?: string;
placeholderVisible?: boolean;
small?: boolean;
type:
| 'button'
| 'checkbox'
Expand Down Expand Up @@ -69,6 +70,7 @@ export const InputBox = forwardRef(function InputBox(
multiple,
placeholderVisible,
type = 'text',
small,
onChange,
...props
}: InputBoxProps,
Expand Down Expand Up @@ -140,6 +142,7 @@ export const InputBox = forwardRef(function InputBox(
rcx-input-box--multiple={multiple}
rcx-input-box--placeholder-visible={placeholderVisible}
rcx-input-box--type={type}
rcx-input-box--small={small}
{...props}
/>
);
Expand Down Expand Up @@ -173,6 +176,7 @@ export const InputBox = forwardRef(function InputBox(
rcx-input-box--placeholder-visible={placeholderVisible}
rcx-input-box--type={type}
rcx-input-box--undecorated
rcx-input-box--small={small}
{...props}
/>
<Addon children={addon} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`[InputBox Component] renders without crashing 1`] = `
<body>
<div>
<input
aria-label="Value"
class="rcx-box rcx-box--full rcx-box--animated rcx-input-box--type-text rcx-input-box"
size="1"
type="text"
value="Value"
/>
</div>
</body>
`;
16 changes: 14 additions & 2 deletions packages/fuselage/src/components/NumberInput/NumberInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import { NumberInput } from '.';
import * as stories from './NumberInput.stories';

const { Default } = composeStories(stories);

describe('[NumberInput Component]', () => {
it('renders without crashing', () => {
render(<NumberInput />);
const tree = render(<Default />);
expect(tree.baseElement).toMatchSnapshot();
});

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

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