Skip to content

Commit 47193c2

Browse files
committed
feat(tabs): add position option to tabs
Add a position variant to tabs. Uses grid to move positions about so the order tabs lins and content appears is not important. fix #205
1 parent b146945 commit 47193c2

File tree

3 files changed

+114
-25
lines changed

3 files changed

+114
-25
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
"*.{ts,tsx,md,json,mdx}": "prettier --write",
127127
"*.{ts,tsx}": [
128128
"eslint --cache --fix",
129-
"git add",
130129
"jest --bail --findRelatedTests"
131130
]
132131
},

src/components/Tabs/Tabs.stories.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,28 @@ Large.args = {
8484
defaultValue: 'tab3',
8585
size: 'large',
8686
}
87+
88+
export const Left = Template.bind({})
89+
Left.args = {
90+
defaultValue: 'tab1',
91+
variant: 'primary',
92+
position: 'left',
93+
}
94+
export const Right = Template.bind({})
95+
Right.args = {
96+
defaultValue: 'tab1',
97+
variant: 'secondary',
98+
position: 'right',
99+
}
100+
export const Top = Template.bind({})
101+
Top.args = {
102+
defaultValue: 'tab1',
103+
variant: 'tertiary',
104+
position: 'top',
105+
}
106+
export const Bottom = Template.bind({})
107+
Bottom.args = {
108+
defaultValue: 'tab1',
109+
variant: 'brand',
110+
position: 'bottom',
111+
}

src/components/Tabs/Tabs.tsx

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ export const Tab = forwardRef((props, forwardedRef) => (
2323
)) as TabComponent
2424
Tab.toString = () => `.${StyledTab.className}`
2525

26+
export const TabsList = styled(List, {
27+
display: 'flex',
28+
gridArea: 'tabs',
29+
borderBottom: '1px solid $grey4',
30+
})
31+
2632
export const TabsRoot = styled(Root, {
2733
$$indicatorSize: '2px',
34+
35+
display: 'grid',
36+
gap: '0px 0px',
37+
2838
[`& ${Tab}`]: {
2939
...buttonBaseStyle,
3040
cursor: 'pointer',
@@ -33,23 +43,96 @@ export const TabsRoot = styled(Root, {
3343
border: 'none',
3444

3545
'&[data-state="active"]': {
36-
boxShadow: 'inset 0 -$$indicatorSize 0 0 currentColor',
3746
cursor: 'auto',
3847
},
3948
},
4049
variants: {
50+
size: {
51+
small: {
52+
$$indicatorSize: '1px',
53+
[`& ${Tab}`]: sizeVariants.small,
54+
},
55+
default: {
56+
$$indicatorSize: '2px',
57+
[`& ${Tab}`]: sizeVariants.default,
58+
},
59+
large: {
60+
$$indicatorSize: '4px',
61+
[`& ${Tab}`]: sizeVariants.large,
62+
},
63+
},
64+
position: {
65+
top: {
66+
gridTemplateColumns: '1fr',
67+
gridTemplateRows: 'auto 1fr',
68+
gridTemplateAreas: `"tabs" "content"`,
69+
[`& ${Tab}`]: {
70+
'&[data-state="active"]': {
71+
boxShadow: 'inset 0 -$$indicatorSize 0 0 currentColor',
72+
},
73+
},
74+
[`& ${TabsList}`]: {
75+
flexDirection: 'row',
76+
},
77+
},
78+
bottom: {
79+
gridTemplateColumns: '1fr',
80+
gridTemplateRows: '1fr auto',
81+
gridTemplateAreas: `"content" "tabs"`,
82+
[`& ${Tab}`]: {
83+
'&[data-state="active"]': {
84+
boxShadow: 'inset 0 $$indicatorSize 0 0 currentColor',
85+
},
86+
},
87+
[`& ${TabsList}`]: {
88+
flexDirection: 'row',
89+
},
90+
},
91+
left: {
92+
gridTemplateColumns: 'auto 1fr',
93+
gridTemplateRows: '1fr',
94+
gridTemplateAreas: `"tabs content"`,
95+
[`& ${Tab}`]: {
96+
'&[data-state="active"]': {
97+
boxShadow: 'inset -$$indicatorSize 0 0 0 currentColor',
98+
},
99+
},
100+
[`& ${TabsList}`]: {
101+
flexDirection: 'column',
102+
},
103+
},
104+
right: {
105+
gridTemplateColumns: '1fr auto',
106+
gridTemplateRows: '1fr',
107+
gridTemplateAreas: `"content tabs"`,
108+
[`& ${Tab}`]: {
109+
'&[data-state="active"]': {
110+
boxShadow: 'inset $$indicatorSize 0 0 0 currentColor',
111+
},
112+
},
113+
[`& ${TabsList}`]: {
114+
flexDirection: 'column',
115+
},
116+
},
117+
},
41118
variant: {
42119
brand: {
43120
[`& ${Tab}`]: buttonVariants.brand,
121+
[`& ${TabsList}`]: {
122+
backgroundColor: '$brand',
123+
},
44124
},
45125
primary: {
46126
[`& ${Tab}`]: buttonVariants.primary,
127+
[`& ${TabsList}`]: {
128+
backgroundColor: '$primary',
129+
},
47130
},
48131
secondary: {
49132
[`& ${Tab}`]: {
50133
...buttonVariants.secondary,
51134
'&[data-state="active"]': {
52-
boxShadow: 'none',
135+
boxShadow: 'none !important',
53136
backgroundColor: '$$active',
54137
textDecoration: 'underline',
55138
},
@@ -59,33 +142,15 @@ export const TabsRoot = styled(Root, {
59142
[`& ${Tab}`]: buttonVariants.tertiary,
60143
},
61144
},
62-
size: {
63-
small: {
64-
$$indicatorSize: '1px',
65-
[`& ${Tab}`]: sizeVariants.small,
66-
},
67-
default: {
68-
$$indicatorSize: '2px',
69-
[`& ${Tab}`]: sizeVariants.default,
70-
},
71-
large: {
72-
$$indicatorSize: '4px',
73-
[`& ${Tab}`]: sizeVariants.large,
74-
},
75-
},
76145
},
77146
defaultVariants: {
78147
variant: 'tertiary',
79148
size: 'default',
149+
position: 'top',
80150
},
81151
})
82152

83-
export const TabsList = styled(List, {
84-
display: 'flex',
85-
borderBottom: '1px solid $grey4',
86-
'& *:not(:first-child)': {
87-
borderLeft: 'none!important',
88-
},
153+
export const TabContent = styled(Content, {
154+
padding: '$3',
155+
gridArea: 'content',
89156
})
90-
91-
export const TabContent = styled(Content, { padding: '$3' })

0 commit comments

Comments
 (0)