Skip to content

Commit 38ad447

Browse files
tassoevanggazzo
authored andcommitted
feat: Add prototype of Tabs component (#101)
* Add prototype of Tabs component * Improve markup
1 parent 948d0ea commit 38ad447

16 files changed

+105
-170
lines changed
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
3+
import { createStyledComponent } from '../../styles';
4+
5+
const Container = createStyledComponent('rcx-tabs', 'div');
6+
const ItemsWrapper = createStyledComponent('rcx-tabs__wrapper', 'div');
7+
const ItemContainer = createStyledComponent('rcx-tabs__item', 'button');
8+
9+
export const Tabs = React.forwardRef(function Tabs({
10+
children,
11+
...props
12+
}, ref) {
13+
return <Container ref={ref} {...props}>
14+
<ItemsWrapper children={children} role='tablist' />
15+
</Container>;
16+
});
17+
18+
Tabs.displayName = 'Tabs';
19+
20+
export const TabsItem = React.forwardRef(function TabsItem({
21+
active,
22+
...props
23+
}, ref) {
24+
return <ItemContainer
25+
aria-selected={active ? 'true' : 'false'}
26+
mod-active={active}
27+
ref={ref}
28+
role='tab'
29+
{...props}
30+
/>;
31+
});
32+
33+
Tabs.Item = TabsItem;

packages/fuselage/src/components/_Tabs/spec.js.disabled packages/fuselage/src/components/Tabs/spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33

4-
import { Tabs } from './index';
5-
4+
import { Tabs } from '../..';
65

76
it('renders without crashing', () => {
87
const div = document.createElement('div');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks';
2+
3+
import { Tabs } from '../..';
4+
5+
<Meta title='Misc|Tabs' parameters={{ jest: ['Tabs/spec'] }} />
6+
7+
# Tabs
8+
9+
<Preview>
10+
<Story name='Default'>
11+
<Tabs>
12+
<Tabs.Item active>Tab text 1</Tabs.Item>
13+
<Tabs.Item>Tab text 2</Tabs.Item>
14+
<Tabs.Item>Tab text 3</Tabs.Item>
15+
</Tabs>
16+
</Story>
17+
</Preview>
18+
19+
### Tabs
20+
21+
<Props of={Tabs} />
22+
23+
### Tabs.Item
24+
25+
<Props of={Tabs.Item} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.rcx-tabs {
2+
@include box;
3+
4+
margin-block-end: $spaces-x8;
5+
6+
border-bottom: #{ $borders-width-x1 } solid #{ map-get($colors, dark400) };
7+
}
8+
9+
.rcx-tabs__wrapper {
10+
display: flex;
11+
flex: 1 1 0;
12+
13+
width: 100%;
14+
margin-inline: calc(-1 * #{ $spaces-x8 });
15+
margin-block-end: calc(-1 * #{ $borders-width-x1 });
16+
}
17+
18+
.rcx-tabs__item {
19+
@include box;
20+
21+
flex: 0 0 auto;
22+
23+
margin-inline: $spaces-x8;
24+
padding-block: $spaces-x8;
25+
padding-inline: $spaces-x32;
26+
27+
color: map-get($colors, dark600);
28+
border-style: solid;
29+
border-color: transparent;
30+
31+
background-color: transparent;
32+
border-block-end-width: $borders-width-x4;
33+
34+
@include clickable;
35+
@include subtitle;
36+
@include subtitle-bold;
37+
38+
&--active {
39+
color: map-get($colors, blue500);
40+
border-block-end-color: map-get($colors, blue500);
41+
}
42+
}

packages/fuselage/src/components/_Tab/index.js.disabled

-15
This file was deleted.

packages/fuselage/src/components/_Tab/spec.js.disabled

-11
This file was deleted.

packages/fuselage/src/components/_Tab/stories.js.disabled

-26
This file was deleted.

packages/fuselage/src/components/_Tab/styles.scss.disabled

-47
This file was deleted.

packages/fuselage/src/components/_Tabs/index.js.disabled

-20
This file was deleted.

packages/fuselage/src/components/_Tabs/stories.js.disabled

-20
This file was deleted.

packages/fuselage/src/components/_Tabs/styles.scss.disabled

-29
This file was deleted.

packages/fuselage/src/components/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from './Scrollable';
2020
export * from './SearchInput';
2121
export * from './SelectInput';
2222
export * from './Subtitle';
23+
export * from './Tabs';
2324
export * from './TelephoneInput';
2425
export * from './Text';
2526
export * from './TextAreaInput';

packages/fuselage/src/components/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@import './Subtitle/styles.scss';
1616
@import './RadioButton/styles.scss';
1717
@import './Scrollable/styles.scss';
18+
@import './Tabs/styles.scss';
1819
@import './Text/styles.scss';
1920
@import './Tile/styles.scss';
2021
@import './ToggleSwitch/styles.scss';
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import '~@rocket.chat/fuselage-tokens/borders.scss';
22

3+
$borders-width-x1: theme('borders-width-x1', to-rem(1));
34
$borders-width-x2: theme('borders-width-x2', to-rem(get-map-value($borders, widths, 1)));
5+
$borders-width-x4: theme('borders-width-x1', to-rem(4));
46

57
$borders-radius-x2: theme('borders-radius-x2', to-rem(get-map-value($borders, radii, 1)));
68
$borders-radius-full: 9999px;

0 commit comments

Comments
 (0)