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 Bubble component #1263

Merged
merged 18 commits into from
Jan 17, 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/ninety-turkeys-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": minor
---

feat(fuselage): new `Bubble` component
31 changes: 31 additions & 0 deletions packages/fuselage/src/components/Bubble/Bubble.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 './Bubble.stories';

const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
]);

describe('[Bubble Rendering]', () => {
test.each(testCases)(
`renders %s without crashing`,
async (_storyname, Story) => {
const tree = render(<Story />);
expect(tree.baseElement).toMatchSnapshot();
}
);

test.each(testCases)(
'%s should have no a11y violations',
async (_storyname, Story) => {
const { container } = render(<Story />);

const results = await axe(container);
expect(results).toHaveNoViolations();
}
);
});
33 changes: 33 additions & 0 deletions packages/fuselage/src/components/Bubble/Bubble.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { action } from '@storybook/addon-actions';
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import React from 'react';

import { Bubble } from '../..';

export default {
title: 'Data Display/Bubble',
component: Bubble,
} as ComponentMeta<typeof Bubble>;

const Template: ComponentStory<typeof Bubble> = (args) => <Bubble {...args} />;

export const IconAndLabel = Template.bind({});
IconAndLabel.args = {
children: 'New messages',
onClick: action('click'),
icon: 'arrow-down',
};

export const Dismissable = Template.bind({});
Dismissable.args = {
children: 'New messages',
icon: 'arrow-down',
onClick: action('click'),
onDismiss: action('dismiss'),
};

export const LabelOnly = Template.bind({});
LabelOnly.args = {
children: 'See new messages',
onClick: action('click'),
};
43 changes: 43 additions & 0 deletions packages/fuselage/src/components/Bubble/Bubble.styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@use '../../styles/colors.scss';
@use '../../styles/lengths.scss';
@use '../../styles/typography.scss';

@use '../../styles/variables/buttons.scss' as buttonColors;
@use '../../styles/primitives/button.scss';
@use '../../styles/mixins/interactivity.scss';

.rcx-bubble {
display: flex;
align-items: center;

&__content,
&__dismiss {
@include typography.use-font-scale(c2);
@include button.kind-variant(buttonColors.$primary);
@include clickable;
@include click-animation;

display: flex;
justify-content: center;
align-items: center;

height: lengths.size(28);

padding-inline-start: lengths.padding(12);
padding-inline-end: lengths.padding(16);

border-radius: lengths.border-radius(extra-large);
}

&__group {
:first-child {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

:last-child {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
}
46 changes: 46 additions & 0 deletions packages/fuselage/src/components/Bubble/Bubble.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Keys as IconName } from '@rocket.chat/icons';
import type { AllHTMLAttributes, ButtonHTMLAttributes, ReactNode } from 'react';
import React from 'react';

import { Icon } from '../Icon';

type BubbleProps = {
children: ReactNode;
onClick: () => void;
icon?: IconName;
onDismiss?: () => void;
contentProps?: ButtonHTMLAttributes<HTMLButtonElement>;
dismissProps?: ButtonHTMLAttributes<HTMLButtonElement>;
} & AllHTMLAttributes<HTMLDivElement>;

export const Bubble = ({
children,
onClick,
icon,
onDismiss,
contentProps,
dismissProps,
...props
}: BubbleProps) => (
<div
className={`rcx-bubble rcx-box rcx-box--full ${
onDismiss ? 'rcx-bubble__group' : ''
}`}
{...props}
>
<button className='rcx-bubble__content' onClick={onClick} {...contentProps}>
{icon && <Icon name={icon} size='x16' mie={8} />}
<span>{children}</span>
</button>
{onDismiss && (
<button
aria-label={`Dismiss ${children}`}
juliajforesti marked this conversation as resolved.
Show resolved Hide resolved
className='rcx-bubble__dismiss'
onClick={onDismiss}
{...dismissProps}
>
<Icon name='cross-small' size='x16' />
</button>
)}
</div>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`[Bubble Rendering] renders Dismissable without crashing 1`] = `
<body>
<div>
<div
class="rcx-bubble rcx-box rcx-box--full rcx-bubble__group"
>
<button
class="rcx-bubble__content"
>
<i
aria-hidden="true"
class="rcx-box rcx-box--full rcx-icon--name-arrow-down rcx-icon rcx-css-gcnmf8"
>
</i>
<span>
New messages
</span>
</button>
<button
aria-label="Dismiss New messages"
class="rcx-bubble__dismiss"
>
<i
aria-hidden="true"
class="rcx-box rcx-box--full rcx-icon--name-cross-small rcx-icon rcx-css-1g87xs3"
>
</i>
</button>
</div>
</div>
</body>
`;

exports[`[Bubble Rendering] renders IconAndLabel without crashing 1`] = `
<body>
<div>
<div
class="rcx-bubble rcx-box rcx-box--full "
>
<button
class="rcx-bubble__content"
>
<i
aria-hidden="true"
class="rcx-box rcx-box--full rcx-icon--name-arrow-down rcx-icon rcx-css-gcnmf8"
>
</i>
<span>
New messages
</span>
</button>
</div>
</div>
</body>
`;

exports[`[Bubble Rendering] renders LabelOnly without crashing 1`] = `
<body>
<div>
<div
class="rcx-bubble rcx-box rcx-box--full "
>
<button
class="rcx-bubble__content"
>
<span>
See new messages
</span>
</button>
</div>
</div>
</body>
`;
1 change: 1 addition & 0 deletions packages/fuselage/src/components/Bubble/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Bubble';
13 changes: 3 additions & 10 deletions packages/fuselage/src/components/Button/Button.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@use '../../styles/variables/buttons.scss' as colors;
@use '../../styles/primitives/button.scss';
@use '../../styles/mixins/size.scss';
@use '../../styles/mixins/interactivity.scss';
@import '../../styles/mixins/states.scss';

.rcx-button {
Expand Down Expand Up @@ -33,21 +34,13 @@
}
}

@mixin click-animation() {
@include on-active {
> *:not(div[role='status']) {
transform: translateY(1px);
}
}
}

display: inline-block;

text-align: center;
white-space: nowrap;
text-decoration: none;

@include click-animation();
@include click-animation($excludeRole: 'status');

.rcx-button--content {
display: inline-block;
Expand Down Expand Up @@ -111,7 +104,7 @@

&--icon {
@include button.kind-variant(colors.$icon);
@include click-animation();
@include click-animation('status');

padding: 0;

Expand Down
1 change: 1 addition & 0 deletions packages/fuselage/src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import './Badge/Badge.styles.scss';
@import './Box/Box.styles.scss';
@import './Button/Button.styles.scss';
@import './Bubble/Bubble.styles.scss';
@import './ButtonGroup/ButtonGroup.styles.scss';
@import './Callout/Callout.styles.scss';
@import './Card/Card.styles.scss';
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { default as Banner } from './Banner';
export { default as Box } from './Box';
export { useArrayLikeClassNameProp } from '../hooks/useArrayLikeClassNameProp';
export { default as Button, ActionButton, IconButton } from './Button';
export * from './Bubble';
export * from './ButtonGroup';
export * from './Callout';
export * from './Card';
Expand Down
12 changes: 11 additions & 1 deletion packages/fuselage/src/styles/lengths.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,24 @@ $border-radius-sizes: (
'small': 2,
'medium': 4,
'large': 8,
'extra-large': 20,
);

@function border-radius($value) {
@if $value == 'none' {
@return 0;
} @else if $value == 'full' {
@return 9999px;
} @else if $value == 'small' or $value == 'medium' or $value == 'large' {
} @else if
$value ==
'small' or
$value ==
'medium' or
$value ==
'large' or
$value ==
'extra-large'
{
@return functions.theme(
'border-radius-#{$value}',
functions.to-rem(map.get($border-radius-sizes, $value))
Expand Down
8 changes: 8 additions & 0 deletions packages/fuselage/src/styles/mixins/interactivity.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
cursor: not-allowed;
}
}

@mixin click-animation($excludeRole: false) {
juliajforesti marked this conversation as resolved.
Show resolved Hide resolved
@include on-active {
> *:not([role='#{$excludeRole}']) {
transform: translateY(1px);
}
}
}
Loading