Skip to content

Commit

Permalink
feat(Tabs): Add Tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed Dec 26, 2022
1 parent de4adf3 commit 090040b
Show file tree
Hide file tree
Showing 40 changed files with 323 additions and 68 deletions.
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@radix-ui/react-portal": "^1.0.1",
"@radix-ui/react-roving-focus": "^1.0.1",
"@radix-ui/react-select": "^1.1.2",
"@radix-ui/react-tabs": "^1.0.1",
"@radix-ui/react-toggle": "^1.0.1",
"@radix-ui/react-toggle-group": "^1.0.1",
"@radix-ui/react-tooltip": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/action-group/action-group.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.action-group-item--no-gap {
Expand Down
16 changes: 1 addition & 15 deletions src/lib/button/button.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.button {
Expand Down Expand Up @@ -147,7 +147,6 @@
} */

.variant--flat {
border-color: transparent;
background-color: transparent;
color: theme('colors.on-surface');

Expand All @@ -160,7 +159,6 @@
}

&:where(:active, [data-state='open']) {
border-color: theme('colors.outline/0.15');
background-color: theme('colors.on-surface/0.15');
}

Expand All @@ -171,18 +169,6 @@
&:where(.intent--danger) {
color: theme('colors.error');
}

/* ToggleButton */
&:where([data-state='on']) {
border-color: theme('colors.primary/0.4');
background-color: theme('colors.primary/0.1');
color: theme('colors.primary');

&:where(:hover, :focus, :active) {
border-color: theme('colors.primary/0.5');
background-color: theme('colors.primary/0.15');
}
}
}

.variant--link {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/checkbox/checkbox.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, defaults;
@import '../root.css';

@layer lib {
.field {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/chip/chip.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.chip {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/collapsible/collapsible.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.content {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dialog/dialog.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.overlay {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/flex/flex.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.display--flex {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/form-field/form-field.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.form-field {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/heading/heading.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.heading {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/icon/icon.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.icon {
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { Portal } from './portal';
export { Section } from './section';
export { Spinner } from './spinner';
export { Switch } from './switch';
export { Tabs } from './tabs';
export { Text } from './text';
export { TextArea } from './text-area';
export { TextField } from './text-field';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/menu-list/menu-list.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.menu-list {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/menu/menu.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.separator {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/picker/picker.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.scroll-direction-arrow {
Expand Down
1 change: 1 addition & 0 deletions src/lib/root.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@layer lib, utils;
2 changes: 1 addition & 1 deletion src/lib/section/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Section = ({ title, children, cross = 'stretch', flow = 'column', gap = 'm
const id = useId(propId);
return (
<Flex cross={cross} flow={flow} gap={gap} {...props}>
<Text id={id} textStyle="overline" tone="light" className="pr-2">
<Text id={id} textStyle="overline" tone="light">
{title}
</Text>
<div role="group" aria-labelledby={id}>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/floating-list.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.floating-list {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/list-item.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.list-item {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/popover.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.popover {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/spinner/spinner.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.spinner {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/switch/switch.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.label {
Expand Down
1 change: 1 addition & 0 deletions src/lib/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Tabs } from './tabs';
87 changes: 87 additions & 0 deletions src/lib/tabs/tabs.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@import '../root.css';

@layer lib {
.list {
display: inline-flex;
&[data-orientation='vertical'] {
flex-flow: column;
border-inline-end: 2px solid theme('colors.outline/0.2');
}
&[data-orientation='horizontal'] {
flex-flow: row;
border-block-end: 2px solid theme('colors.outline/0.2');
}
}

.trigger {
padding: theme('spacing[1.5]');
outline: none;
position: relative;
transition: background-color 0.24s ease-in-out;
border-start-end-radius: theme('borderRadius.md');
border-start-start-radius: theme('borderRadius.md');

&::after {
--scale: 0.4;
position: absolute;
display: block;
content: '';
background-color: transparent;
transition: 0.14s ease-in-out;
}

&[data-orientation='horizontal']:after {
inset-inline-start: 0;
inset-block-end: 0;
transform-origin: bottom;
width: 100%;
height: 2px;
scale: var(--scale) 1;
translate: 0 100%;
}
&[data-orientation='vertical']:after {
inset-block-end: 0;
inset-inline-end: 0;
width: 2px;
height: 100%;
transform-origin: end;
scale: 1 calc(var(--scale) * 0.8);
translate: 100% 0;
}

&:where(:not([aria-selected='true'])) {
&:hover {
& > .trigger-inner {
background-color: theme('colors.on-surface/0.1');
}
}
}
&:where([aria-selected='true']) {
color: theme('colors.primary');
& > .trigger-inner {
background-color: theme('colors.primary/0.1');
}
&:after {
--scale: 0.6;
background-color: theme('colors.primary');
}
&:where(:hover, :focus) {
& > .trigger-inner {
background-color: theme('colors.primary/0.15');
}
}
}
}

.trigger-inner {
padding-inline: theme('spacing.3');
border-radius: theme('borderRadius.md');
transition: background-color 0.14s ease-in-out;
font-size: theme('fontSize.sm');
line-height: theme('lineHeight.xl');
}

.content {
flex: 2;
}
}
70 changes: 70 additions & 0 deletions src/lib/tabs/tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as RdxTabs from '@radix-ui/react-tabs';
import { clsx } from 'clsx';
import { Flex, FlexVariants } from '../flex/flex';

import styles from './tabs.module.css';

interface TabsProps extends Omit<RdxTabs.TabsProps, 'orientation'>, FlexVariants {}

const orientationMap = {
'column': 'horizontal',
'column-reverse': 'horizontal',
'row': 'vertical',
'row-reverse': 'vertical',
} satisfies Record<NonNullable<FlexVariants['flow']>, NonNullable<RdxTabs.TabsProps['orientation']>>;

const Tabs = ({
children,
defaultValue,
value,
onValueChange,
dir,
activationMode,
flow = 'column',
gap = 'sm',
...props
}: TabsProps) => {
return (
<RdxTabs.Root
defaultValue={defaultValue}
value={value}
onValueChange={onValueChange}
orientation={orientationMap[flow]}
dir={dir}
activationMode={activationMode}
asChild
>
<Flex {...props} flow={flow} gap={gap}>
{children}
</Flex>
</RdxTabs.Root>
);
};

interface TabsListProps extends RdxTabs.TabsListProps {}

const TabsList = (props: TabsListProps) => {
return <RdxTabs.List {...props} className={clsx(styles.list, props.className)} />;
};

interface TabsTriggerProps extends RdxTabs.TabsTriggerProps {}

const Trigger = ({ children, className, ...props }: TabsTriggerProps) => {
return (
<RdxTabs.Trigger {...props} className={clsx(styles.trigger, className)}>
<div className={styles['trigger-inner']}>{children}</div>
</RdxTabs.Trigger>
);
};

interface TabsContentProps extends RdxTabs.TabsContentProps {}

const Content = (props: TabsContentProps) => {
return <RdxTabs.Content {...props} className={clsx(styles.content, props.className)} />;
};

Tabs.List = TabsList;
Tabs.Trigger = Trigger;
Tabs.Content = Content;

export { Tabs };
2 changes: 1 addition & 1 deletion src/lib/text-area/text-area.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@layer lib, utils;
@import '../root.css';

@layer lib {
.text-area {
Expand Down
Loading

0 comments on commit 090040b

Please sign in to comment.