Skip to content

Commit

Permalink
feat(go-tabs, go-tablist): separate tablist logic into go-tablist
Browse files Browse the repository at this point in the history
separate tablist logic into go-tablist
- go-tabs, go-tablist: add `fill` prop
- go-tabs, go-tablist: change `manual` to `auto`
- go-tablist with `icon` and `icon-active` slots
  • Loading branch information
seanwuapps committed Feb 25, 2024
1 parent 8f4d80c commit 913d42e
Show file tree
Hide file tree
Showing 22 changed files with 1,664 additions and 1,996 deletions.
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@
"@commitlint/cli": "^13.2.1",
"@commitlint/config-conventional": "^13.2.0",
"@release-it/conventional-changelog": "^5.1.1",
"@stencil/core": "^4.5.0",
"@stencil/postcss": "^2.1.0",
"@stencil-community/postcss": "^2.2.0",
"@stencil/core": "^4.12.2",
"@stencil/react-output-target": "^0.5.3",
"@stencil/sass": "^3.0.4",
"@stencil/vue-output-target": "^0.8.6",
"@types/jest": "^26.0.24",
"@types/jest": "^29.5.12",
"@types/markdown-it": "^12.2.3",
"@types/node": "^18.11.18",
"@types/node": "^20.11.19",
"autoprefixer": "^10.4.13",
"axe-core": "^4.6.2",
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
"concurrently": "^6.5.1",
"cssnano": "^5.1.14",
"esm": "^3.2.25",
"jest": "^26.6.3",
"jest-circus": "^29.5.0",
"jest-cli": "^26.6.3",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"jest-cli": "^29.7.0",
"lodash": "^4.17.21",
"lodash.camelcase": "^4.3.0",
"minimist": "^1.2.7",
Expand Down
296 changes: 287 additions & 9 deletions packages/core/src/components.d.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/core/src/components/go-tabs/go-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ go-tab {
&.active {
display: block;
}

&:focus-visible {
outline-offset: 0.5rem;
}
}
18 changes: 16 additions & 2 deletions packages/core/src/components/go-tabs/go-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Component, h, Prop, Element, Host } from '@stencil/core';
import { Component, h, Prop, Element, Host, Method } from '@stencil/core';
import { TabIconPosition } from './tabs.type';

/**
* @slot icon - Slot for the tab icon (only 1 element allowed)
* @slot icon-active - Slot for the tab icon (only 1 element allowed)
*/
@Component({
tag: 'go-tab',
styleUrl: 'go-tab.scss',
})
export class GoTab {
@Element() el: HTMLElement;

/**
* Label displayed on the tab
*/
@Prop() label: string;

/**
Expand All @@ -26,7 +35,12 @@ export class GoTab {
*/
@Prop({ mutable: true }) panelId?: string;

componentWillLoad() {}
@Prop() iconPosition?: TabIconPosition = 'before';

@Method()
async setActive(active: boolean) {
this.active = active;
}

render() {
const { panelId, tabId, active } = this;
Expand Down
205 changes: 205 additions & 0 deletions packages/core/src/components/go-tabs/go-tablist.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
go-tablist {
/**
@prop --tab-padding:
Padding for tabs
- default: 0.75rem 1.25rem
*/
--tab-padding: 0.5rem 1rem;
/**
@prop --tab-bg-color:
Background color for tabs
- default: transparent
*/
--tab-bg-color: transparent;
/**
@prop --tab-hover-bg-color:
Background color for tabs on hover
- default: var(--go-color-neutral-200)
*/
--tab-hover-bg-color: var(--go-color-neutral-200);

/**
@prop --tab-text-color:
Text color for tabs
- default: var(--go-color-neutral-800)
*/
--tab-text-color: var(--go-color-neutral-800);

/**
@prop --tab-hover-text-color:
Text color for tabs on hover
- default: var(--go-color-neutral-900)
*/
--tab-hover-text-color: var(--go-color-neutral-900);

/**
@prop --tab-focus-color:
Focus outline color for tabs
- default: var(--go-color-primary-600)
*/
--tab-focus-color: var(--go-color-primary-600);
/**
@prop --tab-active-color:
Text color for active tab
- default: var(--go-color-primary-800)
*/
--tab-active-color: var(--go-color-primary-600);
/**
@prop --tab-active-bg-color:
Background color for active tab
- default: transparent
*/
--tab-active-bg-color: transparent;
/**
@prop --tab-border-width:
Border width for tabs
- default: 0.2em
*/
--tab-border-width: 0.2em;
/**
@prop --tab-active-indicator-color:
Color of the active tab indicator
- default: var(--tab-active-color)
*/
--tab-active-indicator-color: var(--tab-active-color);
/**
@prop --tabs-active-indicator-width:
Width of the active tab indicator
- default: 0
*/
--tabs-active-indicator-width: 0;

/**
@prop --tabs-active-indicator-height:
Height of the active tab indicator
- default: 0.2em
*/
--tabs-active-indicator-height: 0.2em;
/**
@prop --tabs-active-indicator-color:
Color of the active tab indicator
- default: var(--tab-active-color)
*/
--tabs-active-indicator-color: var(--tab-active-color);

/**
@prop --tab-icon-gap:
Gap between tab icons
- default: 0.5rem
*/
--tab-icon-gap: 0.5rem;

[role='tablist'] {
overflow: auto;
display: flex;
flex-wrap: nowrap;
width: 100%;
position: relative;
}
[role='tab'] {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: var(--tab-icon-gap);
@include tablet() {
flex-direction: row;
}

padding: var(--tab-padding);
border: var(--tab-border-width) solid transparent;
white-space: nowrap;
background: var(--tab-bg-color);
color: var(--tab-text-color);
font-weight: 500;
@include transition(background-color, color);
.go-tab-icon-slot {
svg,
img {
display: block;
}
}
.go-tab-icon-active {
display: none;
}
&:hover,
&:focus {
color: var(--tab-hover-text-color);
background: var(--tab-hover-bg-color);
}
&:not(.active) {
cursor: pointer;
}
&[aria-selected='true'] {
background: var(--tab-active-bg-color);
color: var(--tab-active-color);
text-decoration: none;
&.has-active-icon {
.go-tab-icon {
display: none;
}
}
.go-tab-icon-active {
display: block;
}
}
}

.tabs-active-indicator-track {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
right: 0;
.tabs-active-indicator {
@include transition(transform, width, height);

transform: translateX(var(--tabs-active-indicator-left));
width: var(--tabs-active-indicator-width);
height: var(--tabs-active-indicator-height);
border-radius: var(--radius-round);
background: var(--tabs-active-indicator-color);
}
}
&.vertical {
flex-direction: row;
[role='tablist'] {
flex-direction: column;
.tabs-active-indicator-track {
width: auto;
top: 0;
left: auto;
.tabs-active-indicator {
--tabs-active-indicator-width: 4px;

transform: translateY(var(--tabs-active-indicator-top));
}
}
}
[role='tab'] {
text-align: start;
white-space: normal;
&:focus-visible {
border-top-color: transparent;
border-left-color: var(--tab-focus-color);
}
}
}

&.fill {
[role='tablist'] {
width: 100%;
}
[role='tab'] {
flex: 1;
}
}
}

@include theme-dark() {
go-tablist {
--tab-text-color: var(--go-color-neutral-700);
--tab-hover-text-color: var(--go-color-neutral-900);
--tab-active-color: var(--go-color-primary-800);
}
}
Loading

0 comments on commit 913d42e

Please sign in to comment.